aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorisiv <isiv@yandex-team.ru>2022-02-10 16:47:54 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:54 +0300
commit40aa65b121746185908e51e32dca11ccee70140b (patch)
treec0748b5dcbade83af788c0abfa89c0383d6b779c
parentf20e3f1949626df2ef9d81d7618ec367b0c34f6b (diff)
downloadydb-40aa65b121746185908e51e32dca11ccee70140b.tar.gz
Restoring authorship annotation for <isiv@yandex-team.ru>. Commit 2 of 2.
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3.hpp110
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3.inl8
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3baserecognizer.hpp700
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3baserecognizer.inl1042
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3bitset.hpp248
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3bitset.inl410
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3collections.hpp162
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3collections.inl698
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3commontoken.hpp164
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3commontoken.inl258
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3commontree.hpp182
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3commontree.inl760
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3commontreeadaptor.hpp386
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3commontreeadaptor.inl1346
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3commontreenodestream.hpp338
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3commontreenodestream.inl590
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3convertutf.hpp68
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3cyclicdfa.hpp74
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3cyclicdfa.inl338
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3debugeventlistener.hpp646
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3defs.hpp94
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3errors.hpp16
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3exception.hpp150
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3exception.inl444
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3filestream.hpp44
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3filestream.inl98
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3input.hpp254
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3input.inl318
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3interfaces.hpp132
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3intstream.hpp374
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3intstream.inl1192
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3lexer.hpp232
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3lexer.inl488
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3memory.hpp266
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3parser.hpp220
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3parser.inl508
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3recognizersharedstate.hpp214
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3recognizersharedstate.inl158
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3rewriterulesubtreestream.hpp246
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3rewriterulesubtreestream.inl488
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3rewriteruletokenstream.hpp262
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3rewriteruletokenstream.inl448
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3rewritestreams.hpp310
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3rewritestreams.inl482
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3tokenstream.hpp328
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3tokenstream.inl680
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3traits.hpp646
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3treeparser.hpp74
-rw-r--r--contrib/libs/antlr3_cpp_runtime/include/antlr3treeparser.inl248
-rw-r--r--library/cpp/scheme/scheme.h2
-rw-r--r--library/cpp/scheme/scimpl_protobuf.cpp90
-rw-r--r--library/cpp/scheme/tests/ut/scheme_proto_ut.cpp90
-rw-r--r--library/cpp/scheme/tests/ut/scheme_ut.proto8
-rw-r--r--ydb/core/client/minikql_compile/yql_expr_minikql.cpp4
-rw-r--r--ydb/core/engine/kikimr_program_builder_ut.cpp10
-rw-r--r--ydb/core/engine/minikql/flat_local_tx_minikql.h4
-rw-r--r--ydb/core/engine/mkql_engine_flat.cpp34
-rw-r--r--ydb/core/engine/mkql_engine_flat_extfunc.cpp66
-rw-r--r--ydb/core/kqp/host/kqp_host.cpp2
-rw-r--r--ydb/core/kqp/host/kqp_run_prepared.cpp2
-rw-r--r--ydb/core/kqp/provider/yql_kikimr_datasource.cpp2
-rw-r--r--ydb/core/kqp/provider/yql_kikimr_type_ann.cpp2
-rw-r--r--ydb/core/testlib/minikql_compile.h2
-rw-r--r--ydb/library/yql/ast/yql_ast.cpp6
-rw-r--r--ydb/library/yql/ast/yql_ast.h2
-rw-r--r--ydb/library/yql/ast/yql_ast_ut.cpp8
-rw-r--r--ydb/library/yql/ast/yql_expr.cpp44
-rw-r--r--ydb/library/yql/ast/yql_expr.h10
-rw-r--r--ydb/library/yql/ast/yql_expr_ut.cpp2
-rw-r--r--ydb/library/yql/ast/yql_type_string_ut.cpp8
-rw-r--r--ydb/library/yql/core/expr_nodes/yql_expr_nodes.json24
-rw-r--r--ydb/library/yql/core/facade/yql_facade.cpp64
-rw-r--r--ydb/library/yql/core/facade/yql_facade.h8
-rw-r--r--ydb/library/yql/core/issue/protos/issue_id.proto14
-rw-r--r--ydb/library/yql/core/issue/yql_issue.txt38
-rw-r--r--ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp18
-rw-r--r--ydb/library/yql/core/type_ann/type_ann_core.cpp1070
-rw-r--r--ydb/library/yql/core/type_ann/type_ann_expr.cpp2
-rw-r--r--ydb/library/yql/core/type_ann/type_ann_list.cpp582
-rw-r--r--ydb/library/yql/core/type_ann/type_ann_list.h18
-rw-r--r--ydb/library/yql/core/ya.make4
-rw-r--r--ydb/library/yql/core/yql_execution.cpp18
-rw-r--r--ydb/library/yql/core/yql_expr_type_annotation.cpp34
-rw-r--r--ydb/library/yql/core/yql_expr_type_annotation.h2
-rw-r--r--ydb/library/yql/core/yql_graph_transformer.cpp4
-rw-r--r--ydb/library/yql/core/yql_library_compiler.cpp2
-rw-r--r--ydb/library/yql/core/yql_opt_utils.cpp10
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_addmember.cpp12
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_aggrcount.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_append.cpp10
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_apply.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_callable.cpp18
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_chain1_map.cpp110
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_chain1_map.h16
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_chain_map.cpp96
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_chain_map.h16
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_coalesce.cpp2
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_collect.cpp4
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_combine.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_condense.cpp10
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_condense1.cpp10
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_contains.cpp10
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_dictitems.cpp24
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_discard.cpp2
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_ensure.cpp2
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_enumerate.cpp20
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_extend.cpp4
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_factory.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_filter.cpp16
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_flatmap.cpp32
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_fold.cpp16
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_fold1.cpp16
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_frombytes.cpp16
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_fromstring.cpp4
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_fromyson.cpp66
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_fromyson.h18
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_group.cpp20
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_guess.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_hasitems.cpp8
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_hopping.cpp50
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_if.cpp4
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_ifpresent.cpp2
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_iterator.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_join.cpp36
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_join_dict.cpp4
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_length.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_listfromrange.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_logical.cpp28
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_lookup.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_map.cpp16
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_now.cpp14
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_pickle.cpp32
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_prepend.cpp10
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_queue.cpp472
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_queue.h30
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_random.cpp40
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_reduce.cpp20
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_removemember.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_replicate.cpp10
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_reverse.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_safe_circular_buffer.cpp2
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_safe_circular_buffer.h112
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_size.cpp8
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_skip.cpp4
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_sort.cpp14
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_squeeze_state.cpp8
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_switch.cpp12
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_take.cpp4
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_todict.cpp50
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_toindexdict.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_tooptional.cpp2
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_tostring.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_udf.cpp8
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_unwrap.cpp8
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_visitall.cpp10
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_way.cpp6
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_weakmember.cpp138
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_weakmember.h18
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_while.cpp24
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_zip.cpp14
-rw-r--r--ydb/library/yql/minikql/comp_nodes/ut/mkql_combine_ut.cpp22
-rw-r--r--ydb/library/yql/minikql/comp_nodes/ut/mkql_computation_node_ut.cpp26
-rw-r--r--ydb/library/yql/minikql/comp_nodes/ut/mkql_safe_circular_buffer_ut.cpp134
-rw-r--r--ydb/library/yql/minikql/comp_nodes/ut/ya.make2
-rw-r--r--ydb/library/yql/minikql/comp_nodes/ya.make16
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node.cpp28
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node.h166
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node_codegen.cpp30
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node_codegen.h10
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node_graph.cpp414
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node_graph_saveload_ut.cpp14
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node_holders.cpp48
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node_holders.h42
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node_impl.cpp18
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node_impl.h48
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node_pack.cpp16
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node_pack.h12
-rw-r--r--ydb/library/yql/minikql/computation/mkql_computation_node_pack_ut.cpp2
-rw-r--r--ydb/library/yql/minikql/computation/mkql_validate.cpp624
-rw-r--r--ydb/library/yql/minikql/computation/mkql_validate.h48
-rw-r--r--ydb/library/yql/minikql/computation/mkql_validate_impl.h90
-rw-r--r--ydb/library/yql/minikql/computation/mkql_validate_ut.cpp1256
-rw-r--r--ydb/library/yql/minikql/computation/mkql_value_builder.cpp4
-rw-r--r--ydb/library/yql/minikql/computation/ya.make4
-rw-r--r--ydb/library/yql/minikql/mkql_alloc.h124
-rw-r--r--ydb/library/yql/minikql/mkql_node.cpp12
-rw-r--r--ydb/library/yql/minikql/mkql_node.h20
-rw-r--r--ydb/library/yql/minikql/mkql_node_serialization.cpp42
-rw-r--r--ydb/library/yql/minikql/mkql_program_builder.cpp190
-rw-r--r--ydb/library/yql/minikql/mkql_program_builder.h12
-rw-r--r--ydb/library/yql/minikql/mkql_type_ops.cpp124
-rw-r--r--ydb/library/yql/mount/lib/yql/window.yql850
-rw-r--r--ydb/library/yql/parser/proto_ast/proto_ast.h2
-rw-r--r--ydb/library/yql/providers/common/mkql/yql_provider_mkql.cpp22
-rw-r--r--ydb/library/yql/providers/common/provider/yql_provider_names.h4
-rw-r--r--ydb/library/yql/providers/config/yql_config_provider.cpp4
-rw-r--r--ydb/library/yql/public/issue/ya.make2
-rw-r--r--ydb/library/yql/public/issue/yql_issue_manager.cpp8
-rw-r--r--ydb/library/yql/public/udf/udf_helpers.h50
-rw-r--r--ydb/library/yql/sql/v0/SQL.g704
-rw-r--r--ydb/library/yql/sql/v0/aggregation.cpp170
-rw-r--r--ydb/library/yql/sql/v0/builtin.cpp722
-rw-r--r--ydb/library/yql/sql/v0/context.cpp288
-rw-r--r--ydb/library/yql/sql/v0/context.h80
-rw-r--r--ydb/library/yql/sql/v0/insert.cpp324
-rw-r--r--ydb/library/yql/sql/v0/join.cpp422
-rw-r--r--ydb/library/yql/sql/v0/list_builtin.h144
-rw-r--r--ydb/library/yql/sql/v0/node.cpp2386
-rw-r--r--ydb/library/yql/sql/v0/node.h780
-rw-r--r--ydb/library/yql/sql/v0/query.cpp264
-rw-r--r--ydb/library/yql/sql/v0/select.cpp1712
-rw-r--r--ydb/library/yql/sql/v0/sql.cpp3734
-rw-r--r--ydb/library/yql/sql/v0/sql.h2
-rw-r--r--ydb/library/yql/sql/v0/sql_ut.cpp1000
-rw-r--r--ydb/library/yql/sql/v0/ya.make4
-rw-r--r--ydb/library/yql/sql/v1/SQLv1.g.in526
-rw-r--r--ydb/library/yql/sql/v1/aggregation.cpp42
-rw-r--r--ydb/library/yql/sql/v1/builtin.cpp652
-rw-r--r--ydb/library/yql/sql/v1/context.cpp110
-rw-r--r--ydb/library/yql/sql/v1/context.h48
-rw-r--r--ydb/library/yql/sql/v1/insert.cpp310
-rw-r--r--ydb/library/yql/sql/v1/join.cpp406
-rw-r--r--ydb/library/yql/sql/v1/list_builtin.h56
-rw-r--r--ydb/library/yql/sql/v1/node.cpp1818
-rw-r--r--ydb/library/yql/sql/v1/node.h720
-rw-r--r--ydb/library/yql/sql/v1/query.cpp216
-rw-r--r--ydb/library/yql/sql/v1/select.cpp1352
-rw-r--r--ydb/library/yql/sql/v1/sql.cpp2836
-rw-r--r--ydb/library/yql/sql/v1/sql.h2
-rw-r--r--ydb/library/yql/sql/v1/sql_ut.cpp952
-rw-r--r--ydb/library/yql/sql/v1/ya.make2
-rw-r--r--ydb/library/yql/udfs/common/digest/digest_udf.cpp2
-rw-r--r--ydb/library/yql/udfs/common/histogram/histogram_udf.cpp10
-rw-r--r--ydb/library/yql/udfs/common/re2/re2_udf.cpp2
234 files changed, 24728 insertions, 24728 deletions
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3.hpp
index 200ad9cf00..d8cccb4aac 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3.hpp
@@ -1,5 +1,5 @@
-#ifndef _ANTLR3_HPP
-#define _ANTLR3_HPP
+#ifndef _ANTLR3_HPP
+#define _ANTLR3_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -28,62 +28,62 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include <cassert>
-#include <cstddef> // ptrdiff_t
-#include <cstdint> // uint32_t, ...
-#include <cstdio> // stderr (TODO remove fprintf(stderr)
-#include <cstdlib> // malloc, calloc
-#include <cstring>
-
-#include <algorithm>
-#include <deque>
-#include <exception>
-#include <iostream>
-#include <limits>
-#include <map>
-#include <memory>
-#include <new>
-#include <set>
-#include <sstream>
+#include <cassert>
+#include <cstddef> // ptrdiff_t
+#include <cstdint> // uint32_t, ...
+#include <cstdio> // stderr (TODO remove fprintf(stderr)
+#include <cstdlib> // malloc, calloc
+#include <cstring>
+
+#include <algorithm>
+#include <deque>
+#include <exception>
+#include <iostream>
+#include <limits>
+#include <map>
+#include <memory>
+#include <new>
+#include <set>
+#include <sstream>
#include <string>
-#include <vector>
+#include <vector>
+
+#include "antlr3defs.hpp"
-#include "antlr3defs.hpp"
+/* Pre declare the typedefs for all the interfaces, then
+ * they can be inter-dependant and we will let the linker
+ * sort it out for us.
+ */
+#include "antlr3interfaces.hpp"
+
+// Include the unicode.org conversion library header.
+//
+#include "antlr3convertutf.hpp"
-/* Pre declare the typedefs for all the interfaces, then
- * they can be inter-dependant and we will let the linker
- * sort it out for us.
- */
-#include "antlr3interfaces.hpp"
+#include "antlr3errors.hpp"
+#include "antlr3memory.hpp"
-// Include the unicode.org conversion library header.
-//
-#include "antlr3convertutf.hpp"
+#include "antlr3collections.hpp"
+#include "antlr3recognizersharedstate.hpp"
+#include "antlr3baserecognizer.hpp"
+#include "antlr3bitset.hpp"
+#include "antlr3commontoken.hpp"
+#include "antlr3commontree.hpp"
+#include "antlr3commontreeadaptor.hpp"
+#include "antlr3cyclicdfa.hpp"
+#include "antlr3debugeventlistener.hpp"
+#include "antlr3exception.hpp"
+#include "antlr3filestream.hpp"
+#include "antlr3intstream.hpp"
+#include "antlr3input.hpp"
+#include "antlr3tokenstream.hpp"
+#include "antlr3commontreenodestream.hpp"
+#include "antlr3lexer.hpp"
+#include "antlr3parser.hpp"
+//#include "antlr3rewritestreams.hpp"
+#include "antlr3rewriteruletokenstream.hpp"
+#include "antlr3rewriterulesubtreestream.hpp"
+#include "antlr3traits.hpp"
+#include "antlr3treeparser.hpp"
-#include "antlr3errors.hpp"
-#include "antlr3memory.hpp"
-
-#include "antlr3collections.hpp"
-#include "antlr3recognizersharedstate.hpp"
-#include "antlr3baserecognizer.hpp"
-#include "antlr3bitset.hpp"
-#include "antlr3commontoken.hpp"
-#include "antlr3commontree.hpp"
-#include "antlr3commontreeadaptor.hpp"
-#include "antlr3cyclicdfa.hpp"
-#include "antlr3debugeventlistener.hpp"
-#include "antlr3exception.hpp"
-#include "antlr3filestream.hpp"
-#include "antlr3intstream.hpp"
-#include "antlr3input.hpp"
-#include "antlr3tokenstream.hpp"
-#include "antlr3commontreenodestream.hpp"
-#include "antlr3lexer.hpp"
-#include "antlr3parser.hpp"
-//#include "antlr3rewritestreams.hpp"
-#include "antlr3rewriteruletokenstream.hpp"
-#include "antlr3rewriterulesubtreestream.hpp"
-#include "antlr3traits.hpp"
-#include "antlr3treeparser.hpp"
-
#endif
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3.inl
index 5be9b7cd1b..b2d223398d 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3.inl
@@ -1,9 +1,9 @@
-namespace antlr3 {
+namespace antlr3 {
-//static
+//static
ANTLR_INLINE void GenericStream::displayRecognitionError( const StringType& str )
{
- fprintf(stderr, str.c_str() );
+ fprintf(stderr, str.c_str() );
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3baserecognizer.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3baserecognizer.hpp
index e44893c82a..0374b3a1ea 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3baserecognizer.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3baserecognizer.hpp
@@ -4,8 +4,8 @@
* \addtogroup BaseRecognizer
* @{
*/
-#ifndef _ANTLR3_BASERECOGNIZER_HPP
-#define _ANTLR3_BASERECOGNIZER_HPP
+#ifndef _ANTLR3_BASERECOGNIZER_HPP
+#define _ANTLR3_BASERECOGNIZER_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -35,7 +35,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
/** \brief Base tracking context structure for all types of
* recognizers.
@@ -44,435 +44,435 @@ template< class ImplTraits, class StreamType >
class BaseRecognizer : public ImplTraits::AllocPolicyType
{
public:
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename StreamType::IntStreamType IntStreamType;
- typedef typename ComponentTypeFinder<ImplTraits, StreamType>::ComponentType SuperType;
- typedef typename StreamType::UnitType UnitType;
- typedef typename ImplTraits::template ExceptionBaseType<StreamType> ExceptionBaseType;
- typedef typename ImplTraits::BitsetType BitsetType;
- typedef typename ImplTraits::BitsetListType BitsetListType;
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::template RecognizerSharedStateType<StreamType> RecognizerSharedStateType;
- typedef typename ImplTraits::DebugEventListenerType DebugEventListenerType;
- typedef typename ImplTraits::LexerType LexerType;
- typedef typename ImplTraits::ParserType ParserType;
- typedef typename ImplTraits::TreeParserType TreeParserType;
-
- typedef typename AllocPolicyType::template StackType<StringType> StringStackType;
- typedef typename AllocPolicyType::template ListType<StringType> StringListType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename StreamType::IntStreamType IntStreamType;
+ typedef typename ComponentTypeFinder<ImplTraits, StreamType>::ComponentType SuperType;
+ typedef typename StreamType::UnitType UnitType;
+ typedef typename ImplTraits::template ExceptionBaseType<StreamType> ExceptionBaseType;
+ typedef typename ImplTraits::BitsetType BitsetType;
+ typedef typename ImplTraits::BitsetListType BitsetListType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::template RecognizerSharedStateType<StreamType> RecognizerSharedStateType;
+ typedef typename ImplTraits::DebugEventListenerType DebugEventListenerType;
+ typedef typename ImplTraits::LexerType LexerType;
+ typedef typename ImplTraits::ParserType ParserType;
+ typedef typename ImplTraits::TreeParserType TreeParserType;
+
+ typedef typename AllocPolicyType::template StackType<StringType> StringStackType;
+ typedef typename AllocPolicyType::template ListType<StringType> StringListType;
private:
- /// A pointer to the shared recognizer state, such that multiple
- /// recognizers can use the same inputs streams and so on (in
- /// the case of grammar inheritance for instance.
- ///
- RecognizerSharedStateType* m_state;
+ /// A pointer to the shared recognizer state, such that multiple
+ /// recognizers can use the same inputs streams and so on (in
+ /// the case of grammar inheritance for instance.
+ ///
+ RecognizerSharedStateType* m_state;
- /// If set to something other than NULL, then this structure is
- /// points to an instance of the debugger interface. In general, the
- /// debugger is only referenced internally in recovery/error operations
- /// so that it does not cause overhead by having to check this pointer
- /// in every function/method
- ///
- DebugEventListenerType* m_debugger;
+ /// If set to something other than NULL, then this structure is
+ /// points to an instance of the debugger interface. In general, the
+ /// debugger is only referenced internally in recovery/error operations
+ /// so that it does not cause overhead by having to check this pointer
+ /// in every function/method
+ ///
+ DebugEventListenerType* m_debugger;
public:
- BaseRecognizer(ANTLR_UINT32 sizeHint, RecognizerSharedStateType* state);
+ BaseRecognizer(ANTLR_UINT32 sizeHint, RecognizerSharedStateType* state);
- SuperType* get_super();
- RecognizerSharedStateType* get_state() const;
- DebugEventListenerType* get_debugger() const;
- void set_state( RecognizerSharedStateType* state );
- void set_debugger( DebugEventListenerType* debugger );
+ SuperType* get_super();
+ RecognizerSharedStateType* get_state() const;
+ DebugEventListenerType* get_debugger() const;
+ void set_state( RecognizerSharedStateType* state );
+ void set_debugger( DebugEventListenerType* debugger );
/// Match current input symbol against ttype. Upon error, do one token
- /// insertion or deletion if possible.
- /// To turn off single token insertion or deletion error
- /// recovery, override mismatchRecover() and have it call
- /// plain mismatch(), which does not recover. Then any error
- /// in a rule will cause an exception and immediate exit from
- /// rule. Rule would recover by resynchronizing to the set of
- /// symbols that can follow rule ref.
- ///
- const UnitType* match(ANTLR_UINT32 ttype, BitsetListType* follow);
-
- /// Consumes the next token, whatever it is, and resets the recognizer state
- /// so that it is not in error.
- ///
- /// \param recognizer
- /// Recognizer context pointer
- ///
- void matchAny();
-
- /// function that decides if the token ahead of the current one is the
- /// one we were loking for, in which case the curernt one is very likely extraneous
- /// and can be reported that way.
- ///
- bool mismatchIsUnwantedToken(IntStreamType* input, ANTLR_UINT32 ttype);
-
- /// function that decides if the current token is one that can logically
- /// follow the one we were looking for, in which case the one we were looking for is
- /// probably missing from the input.
- ///
- bool mismatchIsMissingToken(IntStreamType* input, BitsetListType* follow);
+ /// insertion or deletion if possible.
+ /// To turn off single token insertion or deletion error
+ /// recovery, override mismatchRecover() and have it call
+ /// plain mismatch(), which does not recover. Then any error
+ /// in a rule will cause an exception and immediate exit from
+ /// rule. Rule would recover by resynchronizing to the set of
+ /// symbols that can follow rule ref.
+ ///
+ const UnitType* match(ANTLR_UINT32 ttype, BitsetListType* follow);
+
+ /// Consumes the next token, whatever it is, and resets the recognizer state
+ /// so that it is not in error.
+ ///
+ /// \param recognizer
+ /// Recognizer context pointer
+ ///
+ void matchAny();
+
+ /// function that decides if the token ahead of the current one is the
+ /// one we were loking for, in which case the curernt one is very likely extraneous
+ /// and can be reported that way.
+ ///
+ bool mismatchIsUnwantedToken(IntStreamType* input, ANTLR_UINT32 ttype);
+
+ /// function that decides if the current token is one that can logically
+ /// follow the one we were looking for, in which case the one we were looking for is
+ /// probably missing from the input.
+ ///
+ bool mismatchIsMissingToken(IntStreamType* input, BitsetListType* follow);
/// Factor out what to do upon token mismatch so tree parsers can behave
- /// differently. Override and call mismatchRecover(input, ttype, follow)
- /// to get single token insertion and deletion. Use this to turn off
- /// single token insertion and deletion. Override mismatchRecover
- /// to call this instead.
- ///
- /// \remark mismatch only works for parsers and must be overridden for anything else.
- ///
+ /// differently. Override and call mismatchRecover(input, ttype, follow)
+ /// to get single token insertion and deletion. Use this to turn off
+ /// single token insertion and deletion. Override mismatchRecover
+ /// to call this instead.
+ ///
+ /// \remark mismatch only works for parsers and must be overridden for anything else.
+ ///
void mismatch(ANTLR_UINT32 ttype, BitsetListType* follow);
/// Report a recognition problem.
- ///
- /// This method sets errorRecovery to indicate the parser is recovering
- /// not parsing. Once in recovery mode, no errors are generated.
- /// To get out of recovery mode, the parser must successfully match
- /// a token (after a resync). So it will go:
- ///
- /// 1. error occurs
- /// 2. enter recovery mode, report error
- /// 3. consume until token found in resynch set
- /// 4. try to resume parsing
- /// 5. next match() will reset errorRecovery mode
- ///
- /// If you override, make sure to update errorCount if you care about that.
- ///
- void reportError();
- void reportError( ClassForwarder<LexerType> );
- template<typename CompType>
- void reportError( ClassForwarder<CompType> );
+ ///
+ /// This method sets errorRecovery to indicate the parser is recovering
+ /// not parsing. Once in recovery mode, no errors are generated.
+ /// To get out of recovery mode, the parser must successfully match
+ /// a token (after a resync). So it will go:
+ ///
+ /// 1. error occurs
+ /// 2. enter recovery mode, report error
+ /// 3. consume until token found in resynch set
+ /// 4. try to resume parsing
+ /// 5. next match() will reset errorRecovery mode
+ ///
+ /// If you override, make sure to update errorCount if you care about that.
+ ///
+ void reportError();
+ void reportError( ClassForwarder<LexerType> );
+ template<typename CompType>
+ void reportError( ClassForwarder<CompType> );
/** Function that is called to display a recognition error message. You may
* override this function independently of (*reportError)() above as that function calls
* this one to do the actual exception printing.
*/
- void displayRecognitionError(ANTLR_UINT8** tokenNames);
+ void displayRecognitionError(ANTLR_UINT8** tokenNames);
- /// Get number of recognition errors (lexer, parser, tree parser). Each
- /// recognizer tracks its own number. So parser and lexer each have
- /// separate count. Does not count the spurious errors found between
- /// an error and next valid token match
- ///
- /// \see reportError()
- ///
- ANTLR_UINT32 getNumberOfSyntaxErrors();
+ /// Get number of recognition errors (lexer, parser, tree parser). Each
+ /// recognizer tracks its own number. So parser and lexer each have
+ /// separate count. Does not count the spurious errors found between
+ /// an error and next valid token match
+ ///
+ /// \see reportError()
+ ///
+ ANTLR_UINT32 getNumberOfSyntaxErrors();
/** Function that recovers from an error found in the input stream.
* Generally, this will be a #ANTLR3_EXCEPTION_NOVIABLE_ALT but it could also
* be from a mismatched token that the (*match)() could not recover from.
*/
- void recover();
+ void recover();
/** function that is a hook to listen to token consumption during error recovery.
* This is mainly used by the debug parser to send events to the listener.
*/
- void beginResync();
+ void beginResync();
/** function that is a hook to listen to token consumption during error recovery.
* This is mainly used by the debug parser to send events to the listener.
*/
- void endResync();
+ void endResync();
- /** function that is a hook to listen to token consumption during error recovery.
+ /** function that is a hook to listen to token consumption during error recovery.
* This is mainly used by the debug parser to send events to the listener.
*/
- void beginBacktrack(ANTLR_UINT32 level);
+ void beginBacktrack(ANTLR_UINT32 level);
/** function that is a hook to listen to token consumption during error recovery.
* This is mainly used by the debug parser to send events to the listener.
*/
- void endBacktrack(ANTLR_UINT32 level, bool successful);
+ void endBacktrack(ANTLR_UINT32 level, bool successful);
/// Compute the error recovery set for the current rule.
- /// Documentation below is from the Java implementation.
- ///
- /// During rule invocation, the parser pushes the set of tokens that can
- /// follow that rule reference on the stack; this amounts to
- /// computing FIRST of what follows the rule reference in the
- /// enclosing rule. This local follow set only includes tokens
- /// from within the rule; i.e., the FIRST computation done by
- /// ANTLR stops at the end of a rule.
- //
- /// EXAMPLE
- //
- /// When you find a "no viable alt exception", the input is not
- /// consistent with any of the alternatives for rule r. The best
- /// thing to do is to consume tokens until you see something that
- /// can legally follow a call to r *or* any rule that called r.
- /// You don't want the exact set of viable next tokens because the
- /// input might just be missing a token--you might consume the
- /// rest of the input looking for one of the missing tokens.
- ///
- /// Consider grammar:
- ///
- /// a : '[' b ']'
- /// | '(' b ')'
- /// ;
- /// b : c '^' INT ;
- /// c : ID
- /// | INT
- /// ;
- ///
- /// At each rule invocation, the set of tokens that could follow
- /// that rule is pushed on a stack. Here are the various "local"
- /// follow sets:
- ///
- /// FOLLOW(b1_in_a) = FIRST(']') = ']'
- /// FOLLOW(b2_in_a) = FIRST(')') = ')'
- /// FOLLOW(c_in_b) = FIRST('^') = '^'
- ///
- /// Upon erroneous input "[]", the call chain is
- ///
- /// a -> b -> c
- ///
- /// and, hence, the follow context stack is:
- ///
- /// depth local follow set after call to rule
- /// 0 <EOF> a (from main())
- /// 1 ']' b
- /// 3 '^' c
- ///
- /// Notice that ')' is not included, because b would have to have
- /// been called from a different context in rule a for ')' to be
- /// included.
- ///
- /// For error recovery, we cannot consider FOLLOW(c)
- /// (context-sensitive or otherwise). We need the combined set of
- /// all context-sensitive FOLLOW sets--the set of all tokens that
- /// could follow any reference in the call chain. We need to
- /// resync to one of those tokens. Note that FOLLOW(c)='^' and if
- /// we resync'd to that token, we'd consume until EOF. We need to
- /// sync to context-sensitive FOLLOWs for a, b, and c: {']','^'}.
- /// In this case, for input "[]", LA(1) is in this set so we would
- /// not consume anything and after printing an error rule c would
- /// return normally. It would not find the required '^' though.
- /// At this point, it gets a mismatched token error and throws an
- /// exception (since LA(1) is not in the viable following token
- /// set). The rule exception handler tries to recover, but finds
- /// the same recovery set and doesn't consume anything. Rule b
- /// exits normally returning to rule a. Now it finds the ']' (and
- /// with the successful match exits errorRecovery mode).
- ///
- /// So, you can see that the parser walks up call chain looking
- /// for the token that was a member of the recovery set.
- ///
- /// Errors are not generated in errorRecovery mode.
- ///
- /// ANTLR's error recovery mechanism is based upon original ideas:
- ///
- /// "Algorithms + Data Structures = Programs" by Niklaus Wirth
- ///
- /// and
- ///
- /// "A note on error recovery in recursive descent parsers":
- /// http://portal.acm.org/citation.cfm?id=947902.947905
- ///
- /// Later, Josef Grosch had some good ideas:
- ///
- /// "Efficient and Comfortable Error Recovery in Recursive Descent
- /// Parsers":
- /// ftp://www.cocolab.com/products/cocktail/doca4.ps/ell.ps.zip
- ///
- /// Like Grosch I implemented local FOLLOW sets that are combined
- /// at run-time upon error to avoid overhead during parsing.
- ///
- BitsetType* computeErrorRecoverySet();
+ /// Documentation below is from the Java implementation.
+ ///
+ /// During rule invocation, the parser pushes the set of tokens that can
+ /// follow that rule reference on the stack; this amounts to
+ /// computing FIRST of what follows the rule reference in the
+ /// enclosing rule. This local follow set only includes tokens
+ /// from within the rule; i.e., the FIRST computation done by
+ /// ANTLR stops at the end of a rule.
+ //
+ /// EXAMPLE
+ //
+ /// When you find a "no viable alt exception", the input is not
+ /// consistent with any of the alternatives for rule r. The best
+ /// thing to do is to consume tokens until you see something that
+ /// can legally follow a call to r *or* any rule that called r.
+ /// You don't want the exact set of viable next tokens because the
+ /// input might just be missing a token--you might consume the
+ /// rest of the input looking for one of the missing tokens.
+ ///
+ /// Consider grammar:
+ ///
+ /// a : '[' b ']'
+ /// | '(' b ')'
+ /// ;
+ /// b : c '^' INT ;
+ /// c : ID
+ /// | INT
+ /// ;
+ ///
+ /// At each rule invocation, the set of tokens that could follow
+ /// that rule is pushed on a stack. Here are the various "local"
+ /// follow sets:
+ ///
+ /// FOLLOW(b1_in_a) = FIRST(']') = ']'
+ /// FOLLOW(b2_in_a) = FIRST(')') = ')'
+ /// FOLLOW(c_in_b) = FIRST('^') = '^'
+ ///
+ /// Upon erroneous input "[]", the call chain is
+ ///
+ /// a -> b -> c
+ ///
+ /// and, hence, the follow context stack is:
+ ///
+ /// depth local follow set after call to rule
+ /// 0 <EOF> a (from main())
+ /// 1 ']' b
+ /// 3 '^' c
+ ///
+ /// Notice that ')' is not included, because b would have to have
+ /// been called from a different context in rule a for ')' to be
+ /// included.
+ ///
+ /// For error recovery, we cannot consider FOLLOW(c)
+ /// (context-sensitive or otherwise). We need the combined set of
+ /// all context-sensitive FOLLOW sets--the set of all tokens that
+ /// could follow any reference in the call chain. We need to
+ /// resync to one of those tokens. Note that FOLLOW(c)='^' and if
+ /// we resync'd to that token, we'd consume until EOF. We need to
+ /// sync to context-sensitive FOLLOWs for a, b, and c: {']','^'}.
+ /// In this case, for input "[]", LA(1) is in this set so we would
+ /// not consume anything and after printing an error rule c would
+ /// return normally. It would not find the required '^' though.
+ /// At this point, it gets a mismatched token error and throws an
+ /// exception (since LA(1) is not in the viable following token
+ /// set). The rule exception handler tries to recover, but finds
+ /// the same recovery set and doesn't consume anything. Rule b
+ /// exits normally returning to rule a. Now it finds the ']' (and
+ /// with the successful match exits errorRecovery mode).
+ ///
+ /// So, you can see that the parser walks up call chain looking
+ /// for the token that was a member of the recovery set.
+ ///
+ /// Errors are not generated in errorRecovery mode.
+ ///
+ /// ANTLR's error recovery mechanism is based upon original ideas:
+ ///
+ /// "Algorithms + Data Structures = Programs" by Niklaus Wirth
+ ///
+ /// and
+ ///
+ /// "A note on error recovery in recursive descent parsers":
+ /// http://portal.acm.org/citation.cfm?id=947902.947905
+ ///
+ /// Later, Josef Grosch had some good ideas:
+ ///
+ /// "Efficient and Comfortable Error Recovery in Recursive Descent
+ /// Parsers":
+ /// ftp://www.cocolab.com/products/cocktail/doca4.ps/ell.ps.zip
+ ///
+ /// Like Grosch I implemented local FOLLOW sets that are combined
+ /// at run-time upon error to avoid overhead during parsing.
+ ///
+ BitsetType* computeErrorRecoverySet();
/// Compute the context-sensitive FOLLOW set for current rule.
- /// Documentation below is from the Java runtime.
- ///
- /// This is the set of token types that can follow a specific rule
- /// reference given a specific call chain. You get the set of
- /// viable tokens that can possibly come next (look ahead depth 1)
- /// given the current call chain. Contrast this with the
- /// definition of plain FOLLOW for rule r:
- ///
- /// FOLLOW(r)={x | S=>*alpha r beta in G and x in FIRST(beta)}
- ///
- /// where x in T* and alpha, beta in V*; T is set of terminals and
- /// V is the set of terminals and non terminals. In other words,
- /// FOLLOW(r) is the set of all tokens that can possibly follow
- /// references to r in///any* sentential form (context). At
- /// runtime, however, we know precisely which context applies as
- /// we have the call chain. We may compute the exact (rather
- /// than covering superset) set of following tokens.
- ///
- /// For example, consider grammar:
- ///
- /// stat : ID '=' expr ';' // FOLLOW(stat)=={EOF}
- /// | "return" expr '.'
- /// ;
- /// expr : atom ('+' atom)* ; // FOLLOW(expr)=={';','.',')'}
- /// atom : INT // FOLLOW(atom)=={'+',')',';','.'}
- /// | '(' expr ')'
- /// ;
- ///
- /// The FOLLOW sets are all inclusive whereas context-sensitive
- /// FOLLOW sets are precisely what could follow a rule reference.
- /// For input input "i=(3);", here is the derivation:
- ///
- /// stat => ID '=' expr ';'
- /// => ID '=' atom ('+' atom)* ';'
- /// => ID '=' '(' expr ')' ('+' atom)* ';'
- /// => ID '=' '(' atom ')' ('+' atom)* ';'
- /// => ID '=' '(' INT ')' ('+' atom)* ';'
- /// => ID '=' '(' INT ')' ';'
- ///
- /// At the "3" token, you'd have a call chain of
- ///
- /// stat -> expr -> atom -> expr -> atom
- ///
- /// What can follow that specific nested ref to atom? Exactly ')'
- /// as you can see by looking at the derivation of this specific
- /// input. Contrast this with the FOLLOW(atom)={'+',')',';','.'}.
- ///
- /// You want the exact viable token set when recovering from a
- /// token mismatch. Upon token mismatch, if LA(1) is member of
- /// the viable next token set, then you know there is most likely
- /// a missing token in the input stream. "Insert" one by just not
- /// throwing an exception.
- ///
- BitsetType* computeCSRuleFollow();
+ /// Documentation below is from the Java runtime.
+ ///
+ /// This is the set of token types that can follow a specific rule
+ /// reference given a specific call chain. You get the set of
+ /// viable tokens that can possibly come next (look ahead depth 1)
+ /// given the current call chain. Contrast this with the
+ /// definition of plain FOLLOW for rule r:
+ ///
+ /// FOLLOW(r)={x | S=>*alpha r beta in G and x in FIRST(beta)}
+ ///
+ /// where x in T* and alpha, beta in V*; T is set of terminals and
+ /// V is the set of terminals and non terminals. In other words,
+ /// FOLLOW(r) is the set of all tokens that can possibly follow
+ /// references to r in///any* sentential form (context). At
+ /// runtime, however, we know precisely which context applies as
+ /// we have the call chain. We may compute the exact (rather
+ /// than covering superset) set of following tokens.
+ ///
+ /// For example, consider grammar:
+ ///
+ /// stat : ID '=' expr ';' // FOLLOW(stat)=={EOF}
+ /// | "return" expr '.'
+ /// ;
+ /// expr : atom ('+' atom)* ; // FOLLOW(expr)=={';','.',')'}
+ /// atom : INT // FOLLOW(atom)=={'+',')',';','.'}
+ /// | '(' expr ')'
+ /// ;
+ ///
+ /// The FOLLOW sets are all inclusive whereas context-sensitive
+ /// FOLLOW sets are precisely what could follow a rule reference.
+ /// For input input "i=(3);", here is the derivation:
+ ///
+ /// stat => ID '=' expr ';'
+ /// => ID '=' atom ('+' atom)* ';'
+ /// => ID '=' '(' expr ')' ('+' atom)* ';'
+ /// => ID '=' '(' atom ')' ('+' atom)* ';'
+ /// => ID '=' '(' INT ')' ('+' atom)* ';'
+ /// => ID '=' '(' INT ')' ';'
+ ///
+ /// At the "3" token, you'd have a call chain of
+ ///
+ /// stat -> expr -> atom -> expr -> atom
+ ///
+ /// What can follow that specific nested ref to atom? Exactly ')'
+ /// as you can see by looking at the derivation of this specific
+ /// input. Contrast this with the FOLLOW(atom)={'+',')',';','.'}.
+ ///
+ /// You want the exact viable token set when recovering from a
+ /// token mismatch. Upon token mismatch, if LA(1) is member of
+ /// the viable next token set, then you know there is most likely
+ /// a missing token in the input stream. "Insert" one by just not
+ /// throwing an exception.
+ ///
+ BitsetType* computeCSRuleFollow();
/// Compute the current followset for the input stream.
- ///
- BitsetType* combineFollows(bool exact);
+ ///
+ BitsetType* combineFollows(bool exact);
/// Attempt to recover from a single missing or extra token.
- ///
- /// EXTRA TOKEN
- ///
- /// LA(1) is not what we are looking for. If LA(2) has the right token,
- /// however, then assume LA(1) is some extra spurious token. Delete it
- /// and LA(2) as if we were doing a normal match(), which advances the
- /// input.
- ///
- /// MISSING TOKEN
- ///
- /// If current token is consistent with what could come after
- /// ttype then it is ok to "insert" the missing token, else throw
- /// exception For example, Input "i=(3;" is clearly missing the
- /// ')'. When the parser returns from the nested call to expr, it
- /// will have call chain:
- ///
- /// stat -> expr -> atom
- ///
- /// and it will be trying to match the ')' at this point in the
- /// derivation:
- ///
- /// => ID '=' '(' INT ')' ('+' atom)* ';'
- /// ^
- /// match() will see that ';' doesn't match ')' and report a
- /// mismatched token error. To recover, it sees that LA(1)==';'
- /// is in the set of tokens that can follow the ')' token
- /// reference in rule atom. It can assume that you forgot the ')'.
- ///
- /// The exception that was passed in, in the java implementation is
- /// sorted in the recognizer exception stack in the C version. To 'throw' it we set the
- /// error flag and rules cascade back when this is set.
- ///
- const UnitType* recoverFromMismatchedToken( ANTLR_UINT32 ttype, BitsetListType* follow);
+ ///
+ /// EXTRA TOKEN
+ ///
+ /// LA(1) is not what we are looking for. If LA(2) has the right token,
+ /// however, then assume LA(1) is some extra spurious token. Delete it
+ /// and LA(2) as if we were doing a normal match(), which advances the
+ /// input.
+ ///
+ /// MISSING TOKEN
+ ///
+ /// If current token is consistent with what could come after
+ /// ttype then it is ok to "insert" the missing token, else throw
+ /// exception For example, Input "i=(3;" is clearly missing the
+ /// ')'. When the parser returns from the nested call to expr, it
+ /// will have call chain:
+ ///
+ /// stat -> expr -> atom
+ ///
+ /// and it will be trying to match the ')' at this point in the
+ /// derivation:
+ ///
+ /// => ID '=' '(' INT ')' ('+' atom)* ';'
+ /// ^
+ /// match() will see that ';' doesn't match ')' and report a
+ /// mismatched token error. To recover, it sees that LA(1)==';'
+ /// is in the set of tokens that can follow the ')' token
+ /// reference in rule atom. It can assume that you forgot the ')'.
+ ///
+ /// The exception that was passed in, in the java implementation is
+ /// sorted in the recognizer exception stack in the C version. To 'throw' it we set the
+ /// error flag and rules cascade back when this is set.
+ ///
+ const UnitType* recoverFromMismatchedToken( ANTLR_UINT32 ttype, BitsetListType* follow);
/** Function that recovers from a mismatched set in the token stream, in a similar manner
* to (*recoverFromMismatchedToken)
*/
- const UnitType* recoverFromMismatchedSet(BitsetListType* follow);
+ const UnitType* recoverFromMismatchedSet(BitsetListType* follow);
/** common routine to handle single token insertion for recovery functions.
*/
- /// This code is factored out from mismatched token and mismatched set
- /// recovery. It handles "single token insertion" error recovery for
- /// both. No tokens are consumed to recover from insertions. Return
- /// true if recovery was possible else return false.
- ///
- bool recoverFromMismatchedElement(BitsetListType* follow);
+ /// This code is factored out from mismatched token and mismatched set
+ /// recovery. It handles "single token insertion" error recovery for
+ /// both. No tokens are consumed to recover from insertions. Return
+ /// true if recovery was possible else return false.
+ ///
+ bool recoverFromMismatchedElement(BitsetListType* follow);
/** function that consumes input until the next token matches
* the given token.
*/
- void consumeUntil(ANTLR_UINT32 tokenType);
+ void consumeUntil(ANTLR_UINT32 tokenType);
/** function that consumes input until the next token matches
* one in the given set.
*/
- void consumeUntilSet(BitsetType* set);
+ void consumeUntilSet(BitsetType* set);
/** function that returns an ANTLR3_LIST of the strings that identify
* the rules in the parser that got you to this point. Can be overridden by installing your
- * own function set.
+ * own function set.
*
* \todo Document how to override invocation stack functions.
*/
- StringStackType getRuleInvocationStack();
- StringStackType getRuleInvocationStackNamed(ANTLR_UINT8* name);
+ StringStackType getRuleInvocationStack();
+ StringStackType getRuleInvocationStackNamed(ANTLR_UINT8* name);
/** function that converts an ANLR3_LIST of tokens to an ANTLR3_LIST of
* string token names. As this is mostly used in string template processing it may not be useful
* in the C runtime.
*/
- StringListType toStrings( const StringListType& );
+ StringListType toStrings( const StringListType& );
/** function to return whether the rule has parsed input starting at the supplied
* start index before. If the rule has not parsed input starting from the supplied start index,
* then it will return ANTLR3_MEMO_RULE_UNKNOWN. If it has parsed from the suppled start point
* then it will return the point where it last stopped parsing after that start point.
*/
- ANTLR_MARKER getRuleMemoization( ANTLR_INTKEY ruleIndex,
- ANTLR_MARKER ruleParseStart);
+ ANTLR_MARKER getRuleMemoization( ANTLR_INTKEY ruleIndex,
+ ANTLR_MARKER ruleParseStart);
/** function that determines whether the rule has parsed input at the current index
* in the input stream
*/
- bool alreadyParsedRule(ANTLR_MARKER ruleIndex);
+ bool alreadyParsedRule(ANTLR_MARKER ruleIndex);
/** Function that records whether the rule has parsed the input at a
* current position successfully or not.
*/
- void memoize(ANTLR_MARKER ruleIndex,
- ANTLR_MARKER ruleParseStart);
+ void memoize(ANTLR_MARKER ruleIndex,
+ ANTLR_MARKER ruleParseStart);
- /// Function that returns the current input symbol.
+ /// Function that returns the current input symbol.
/// The is placed into any label for the associated token ref; e.g., x=ID. Token
- /// and tree parsers need to return different objects. Rather than test
- /// for input stream type or change the IntStream interface, I use
- /// a simple method to ask the recognizer to tell me what the current
- /// input symbol is.
- ///
- /// This is ignored for lexers and the lexer implementation of this
- /// function should return NULL.
- ///
- const UnitType* getCurrentInputSymbol(IntStreamType* istream);
- const UnitType* getCurrentInputSymbol(IntStreamType* istream, ClassForwarder<LexerType>);
- const UnitType* getCurrentInputSymbol(IntStreamType* istream, ClassForwarder<ParserType>);
- const UnitType* getCurrentInputSymbol(IntStreamType* istream, ClassForwarder<TreeParserType>);
-
- /// Conjure up a missing token during error recovery.
- ///
- /// The recognizer attempts to recover from single missing
- /// symbols. But, actions might refer to that missing symbol.
- /// For example, x=ID {f($x);}. The action clearly assumes
- /// that there has been an identifier matched previously and that
- /// $x points at that token. If that token is missing, but
- /// the next token in the stream is what we want we assume that
- /// this token is missing and we keep going. Because we
- /// have to return some token to replace the missing token,
- /// we have to conjure one up. This method gives the user control
- /// over the tokens returned for missing tokens. Mostly,
- /// you will want to create something special for identifier
- /// tokens. For literals such as '{' and ',', the default
- /// action in the parser or tree parser works. It simply creates
- /// a CommonToken of the appropriate type. The text will be the token.
- /// If you change what tokens must be created by the lexer,
- /// override this method to create the appropriate tokens.
- ///
- UnitType* getMissingSymbol( IntStreamType* istream, ExceptionBaseType* e,
- ANTLR_UINT32 expectedTokenType,
- BitsetListType* follow);
+ /// and tree parsers need to return different objects. Rather than test
+ /// for input stream type or change the IntStream interface, I use
+ /// a simple method to ask the recognizer to tell me what the current
+ /// input symbol is.
+ ///
+ /// This is ignored for lexers and the lexer implementation of this
+ /// function should return NULL.
+ ///
+ const UnitType* getCurrentInputSymbol(IntStreamType* istream);
+ const UnitType* getCurrentInputSymbol(IntStreamType* istream, ClassForwarder<LexerType>);
+ const UnitType* getCurrentInputSymbol(IntStreamType* istream, ClassForwarder<ParserType>);
+ const UnitType* getCurrentInputSymbol(IntStreamType* istream, ClassForwarder<TreeParserType>);
+
+ /// Conjure up a missing token during error recovery.
+ ///
+ /// The recognizer attempts to recover from single missing
+ /// symbols. But, actions might refer to that missing symbol.
+ /// For example, x=ID {f($x);}. The action clearly assumes
+ /// that there has been an identifier matched previously and that
+ /// $x points at that token. If that token is missing, but
+ /// the next token in the stream is what we want we assume that
+ /// this token is missing and we keep going. Because we
+ /// have to return some token to replace the missing token,
+ /// we have to conjure one up. This method gives the user control
+ /// over the tokens returned for missing tokens. Mostly,
+ /// you will want to create something special for identifier
+ /// tokens. For literals such as '{' and ',', the default
+ /// action in the parser or tree parser works. It simply creates
+ /// a CommonToken of the appropriate type. The text will be the token.
+ /// If you change what tokens must be created by the lexer,
+ /// override this method to create the appropriate tokens.
+ ///
+ UnitType* getMissingSymbol( IntStreamType* istream, ExceptionBaseType* e,
+ ANTLR_UINT32 expectedTokenType,
+ BitsetListType* follow);
/** Function that returns whether the supplied grammar function
* will parse the current input stream or not. This is the way that syntactic
@@ -480,30 +480,30 @@ public:
* via a pointer to a function (hence that's what all the ANTLR3 C interfaces
* do.
*/
- template<typename Predicate>
+ template<typename Predicate>
bool synpred( ClassForwarder<Predicate> );
- //In place of exConstruct, just directly instantiate the Exception Object
+ //In place of exConstruct, just directly instantiate the Exception Object
/** Reset the recognizer
*/
void reset();
- void reset( ClassForwarder<LexerType> );
- template<typename CompType>
- void reset( ClassForwarder<CompType> );
+ void reset( ClassForwarder<LexerType> );
+ template<typename CompType>
+ void reset( ClassForwarder<CompType> );
- void exConstruct();
+ void exConstruct();
~BaseRecognizer();
};
-}
+}
#include "antlr3baserecognizer.inl"
/// @}
///
-#endif /* _ANTLR3_BASERECOGNIZER_H */
+#endif /* _ANTLR3_BASERECOGNIZER_H */
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3baserecognizer.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3baserecognizer.inl
index 2a02474035..b0c3fe8d51 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3baserecognizer.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3baserecognizer.inl
@@ -1,94 +1,94 @@
-namespace antlr3 {
+namespace antlr3 {
template< class ImplTraits, class StreamType >
BaseRecognizer<ImplTraits, StreamType>::BaseRecognizer(ANTLR_UINT32 sizeHint,
- RecognizerSharedStateType* state)
+ RecognizerSharedStateType* state)
{
- m_debugger = NULL;
+ m_debugger = NULL;
- // If we have been supplied with a pre-existing recognizer state
- // then we just install it, otherwise we must create one from scratch
- //
- if (state == NULL)
- {
- m_state = new RecognizerSharedStateType();
- m_state->set_sizeHint( sizeHint );
- }
- else
- {
- // Install the one we were given, and do not reset it here
- // as it will either already have been initialized or will
- // be in a state that needs to be preserved.
- //
- m_state = state;
- }
+ // If we have been supplied with a pre-existing recognizer state
+ // then we just install it, otherwise we must create one from scratch
+ //
+ if (state == NULL)
+ {
+ m_state = new RecognizerSharedStateType();
+ m_state->set_sizeHint( sizeHint );
+ }
+ else
+ {
+ // Install the one we were given, and do not reset it here
+ // as it will either already have been initialized or will
+ // be in a state that needs to be preserved.
+ //
+ m_state = state;
+ }
}
template< class ImplTraits, class StreamType >
ANTLR_INLINE typename BaseRecognizer<ImplTraits, StreamType>::SuperType* BaseRecognizer<ImplTraits, StreamType>::get_super()
{
- return static_cast<SuperType*>(this);
+ return static_cast<SuperType*>(this);
}
template< class ImplTraits, class StreamType >
ANTLR_INLINE typename BaseRecognizer<ImplTraits, StreamType>::RecognizerSharedStateType* BaseRecognizer<ImplTraits, StreamType>::get_state() const
{
- return m_state;
+ return m_state;
}
template< class ImplTraits, class StreamType >
ANTLR_INLINE typename BaseRecognizer<ImplTraits, StreamType>::DebugEventListenerType* BaseRecognizer<ImplTraits, StreamType>::get_debugger() const
{
- return m_debugger;
+ return m_debugger;
}
template< class ImplTraits, class StreamType >
ANTLR_INLINE void BaseRecognizer<ImplTraits, StreamType>::set_state( RecognizerSharedStateType* state )
{
- m_state = state;
+ m_state = state;
}
template< class ImplTraits, class StreamType >
ANTLR_INLINE void BaseRecognizer<ImplTraits, StreamType>::set_debugger( DebugEventListenerType* debugger )
{
- m_debugger = debugger;
+ m_debugger = debugger;
}
template< class ImplTraits, class StreamType >
-const typename BaseRecognizer<ImplTraits, StreamType>::UnitType*
+const typename BaseRecognizer<ImplTraits, StreamType>::UnitType*
BaseRecognizer<ImplTraits, StreamType>::match(ANTLR_UINT32 ttype, BitsetListType* follow)
{
- SuperType* super = static_cast<SuperType*>(this);
- IntStreamType* is = super->get_istream();
+ SuperType* super = static_cast<SuperType*>(this);
+ IntStreamType* is = super->get_istream();
- // Pick up the current input token/node for assignment to labels
- //
- const UnitType* matchedSymbol = this->getCurrentInputSymbol(is);
+ // Pick up the current input token/node for assignment to labels
+ //
+ const UnitType* matchedSymbol = this->getCurrentInputSymbol(is);
- //if (is->LA(1) == ttype)
- if (matchedSymbol->get_type() == ttype)
- {
- // The token was the one we were told to expect
- //
- is->consume(); // Consume that token from the stream
- m_state->set_errorRecovery(false); // Not in error recovery now (if we were)
- m_state->set_failed(false); // The match was a success
- return matchedSymbol; // We are done
- }
+ //if (is->LA(1) == ttype)
+ if (matchedSymbol->get_type() == ttype)
+ {
+ // The token was the one we were told to expect
+ //
+ is->consume(); // Consume that token from the stream
+ m_state->set_errorRecovery(false); // Not in error recovery now (if we were)
+ m_state->set_failed(false); // The match was a success
+ return matchedSymbol; // We are done
+ }
// We did not find the expected token type, if we are backtracking then
// we just set the failed flag and return.
//
- if ( m_state->get_backtracking() > 0)
+ if ( m_state->get_backtracking() > 0)
{
- // Backtracking is going on
- //
- m_state->set_failed(true);
- return matchedSymbol;
- }
+ // Backtracking is going on
+ //
+ m_state->set_failed(true);
+ return matchedSymbol;
+ }
// We did not find the expected token and there is no backtracking
// going on, so we mismatch, which creates an exception in the recognizer exception
// stack.
//
- matchedSymbol = this->recoverFromMismatchedToken(ttype, follow);
+ matchedSymbol = this->recoverFromMismatchedToken(ttype, follow);
return matchedSymbol;
}
@@ -96,194 +96,194 @@ BaseRecognizer<ImplTraits, StreamType>::match(ANTLR_UINT32 ttype, BitsetListType
template< class ImplTraits, class StreamType >
void BaseRecognizer<ImplTraits, StreamType>::matchAny()
{
- SuperType* super = static_cast<SuperType*>(this);
- IntStreamType* is = super->get_istream();
+ SuperType* super = static_cast<SuperType*>(this);
+ IntStreamType* is = super->get_istream();
- is->consume();
- m_state->set_errorRecovery(false);
- m_state->set_failed(false);
+ is->consume();
+ m_state->set_errorRecovery(false);
+ m_state->set_failed(false);
return;
}
template< class ImplTraits, class StreamType >
bool BaseRecognizer<ImplTraits, StreamType>::mismatchIsUnwantedToken(IntStreamType* is, ANTLR_UINT32 ttype)
{
- ANTLR_UINT32 nextt = is->LA(2);
+ ANTLR_UINT32 nextt = is->LA(2);
- if (nextt == ttype)
- {
- if(m_state->get_exception() != NULL)
- m_state->get_exception()->set_expecting(nextt);
- return true; // This token is unknown, but the next one is the one we wanted
- }
- else
- return false; // Neither this token, nor the one following is the one we wanted
+ if (nextt == ttype)
+ {
+ if(m_state->get_exception() != NULL)
+ m_state->get_exception()->set_expecting(nextt);
+ return true; // This token is unknown, but the next one is the one we wanted
+ }
+ else
+ return false; // Neither this token, nor the one following is the one we wanted
}
template< class ImplTraits, class StreamType >
bool BaseRecognizer<ImplTraits, StreamType>::mismatchIsMissingToken(IntStreamType* is, BitsetListType* follow)
{
- bool retcode;
- BitsetType* followClone;
- BitsetType* viableTokensFollowingThisRule;
-
- if (follow == NULL)
- {
- // There is no information about the tokens that can follow the last one
- // hence we must say that the current one we found is not a member of the
- // follow set and does not indicate a missing token. We will just consume this
- // single token and see if the parser works it out from there.
- //
- return false;
- }
-
- followClone = NULL;
- viableTokensFollowingThisRule = NULL;
-
- // The C bitset maps are laid down at compile time by the
- // C code generation. Hence we cannot remove things from them
- // and so on. So, in order to remove EOR (if we need to) then
- // we clone the static bitset.
- //
- followClone = follow->bitsetLoad();
- if (followClone == NULL)
- return false;
-
- // Compute what can follow this grammar reference
- //
- if (followClone->isMember( ImplTraits::CommonTokenType::EOR_TOKEN_TYPE))
- {
- // EOR can follow, but if we are not the start symbol, we
- // need to remove it.
- //
- followClone->remove(ImplTraits::CommonTokenType::EOR_TOKEN_TYPE);
-
- // Now compute the visiable tokens that can follow this rule, according to context
- // and make them part of the follow set.
- //
- viableTokensFollowingThisRule = this->computeCSRuleFollow();
- followClone->borInPlace(viableTokensFollowingThisRule);
- }
-
- /// if current token is consistent with what could come after set
- /// then we know we're missing a token; error recovery is free to
- /// "insert" the missing token
- ///
- /// BitSet cannot handle negative numbers like -1 (EOF) so I leave EOR
- /// in follow set to indicate that the fall of the start symbol is
- /// in the set (EOF can follow).
- ///
- if ( followClone->isMember(is->LA(1))
- || followClone->isMember(ImplTraits::CommonTokenType::EOR_TOKEN_TYPE)
- )
- {
- retcode = true;
- }
- else
- {
- retcode = false;
- }
-
- if (viableTokensFollowingThisRule != NULL)
- {
- delete viableTokensFollowingThisRule;
- }
- if (followClone != NULL)
- {
- delete followClone;
- }
-
- return retcode;
+ bool retcode;
+ BitsetType* followClone;
+ BitsetType* viableTokensFollowingThisRule;
+
+ if (follow == NULL)
+ {
+ // There is no information about the tokens that can follow the last one
+ // hence we must say that the current one we found is not a member of the
+ // follow set and does not indicate a missing token. We will just consume this
+ // single token and see if the parser works it out from there.
+ //
+ return false;
+ }
+
+ followClone = NULL;
+ viableTokensFollowingThisRule = NULL;
+
+ // The C bitset maps are laid down at compile time by the
+ // C code generation. Hence we cannot remove things from them
+ // and so on. So, in order to remove EOR (if we need to) then
+ // we clone the static bitset.
+ //
+ followClone = follow->bitsetLoad();
+ if (followClone == NULL)
+ return false;
+
+ // Compute what can follow this grammar reference
+ //
+ if (followClone->isMember( ImplTraits::CommonTokenType::EOR_TOKEN_TYPE))
+ {
+ // EOR can follow, but if we are not the start symbol, we
+ // need to remove it.
+ //
+ followClone->remove(ImplTraits::CommonTokenType::EOR_TOKEN_TYPE);
+
+ // Now compute the visiable tokens that can follow this rule, according to context
+ // and make them part of the follow set.
+ //
+ viableTokensFollowingThisRule = this->computeCSRuleFollow();
+ followClone->borInPlace(viableTokensFollowingThisRule);
+ }
+
+ /// if current token is consistent with what could come after set
+ /// then we know we're missing a token; error recovery is free to
+ /// "insert" the missing token
+ ///
+ /// BitSet cannot handle negative numbers like -1 (EOF) so I leave EOR
+ /// in follow set to indicate that the fall of the start symbol is
+ /// in the set (EOF can follow).
+ ///
+ if ( followClone->isMember(is->LA(1))
+ || followClone->isMember(ImplTraits::CommonTokenType::EOR_TOKEN_TYPE)
+ )
+ {
+ retcode = true;
+ }
+ else
+ {
+ retcode = false;
+ }
+
+ if (viableTokensFollowingThisRule != NULL)
+ {
+ delete viableTokensFollowingThisRule;
+ }
+ if (followClone != NULL)
+ {
+ delete followClone;
+ }
+
+ return retcode;
}
template< class ImplTraits, class StreamType >
void BaseRecognizer<ImplTraits, StreamType>::mismatch(ANTLR_UINT32 ttype, BitsetListType* follow)
{
- this->get_super()->mismatch( ttype, follow );
+ this->get_super()->mismatch( ttype, follow );
}
template< class ImplTraits, class StreamType >
-void BaseRecognizer<ImplTraits, StreamType>::reportError()
+void BaseRecognizer<ImplTraits, StreamType>::reportError()
{
- this->reportError( ClassForwarder<SuperType>() );
+ this->reportError( ClassForwarder<SuperType>() );
}
template< class ImplTraits, class StreamType >
-void BaseRecognizer<ImplTraits, StreamType>::reportError( ClassForwarder<LexerType> )
+void BaseRecognizer<ImplTraits, StreamType>::reportError( ClassForwarder<LexerType> )
{
- // Indicate this recognizer had an error while processing.
- //
- m_state->inc_errorCount();
+ // Indicate this recognizer had an error while processing.
+ //
+ m_state->inc_errorCount();
this->displayRecognitionError(m_state->get_tokenNames());
}
template< class ImplTraits, class StreamType >
template<typename CompType>
-void BaseRecognizer<ImplTraits, StreamType>::reportError(ClassForwarder<CompType> )
+void BaseRecognizer<ImplTraits, StreamType>::reportError(ClassForwarder<CompType> )
{
- // Invoke the debugger event if there is a debugger listening to us
- //
- if ( m_debugger != NULL)
- {
- m_debugger->recognitionException( m_state->get_exception() );
- }
+ // Invoke the debugger event if there is a debugger listening to us
+ //
+ if ( m_debugger != NULL)
+ {
+ m_debugger->recognitionException( m_state->get_exception() );
+ }
- if ( m_state->get_errorRecovery() == true)
+ if ( m_state->get_errorRecovery() == true)
{
- // Already in error recovery so don't display another error while doing so
- //
- return;
+ // Already in error recovery so don't display another error while doing so
+ //
+ return;
}
// Signal we are in error recovery now
//
m_state->set_errorRecovery(true);
- // Indicate this recognizer had an error while processing.
- //
- m_state->inc_errorCount();
+ // Indicate this recognizer had an error while processing.
+ //
+ m_state->inc_errorCount();
- // Call the error display routine
- //
+ // Call the error display routine
+ //
this->displayRecognitionError( m_state->get_tokenNames() );
}
template< class ImplTraits, class StreamType >
-void BaseRecognizer<ImplTraits, StreamType>::displayRecognitionError(ANTLR_UINT8** tokenNames)
+void BaseRecognizer<ImplTraits, StreamType>::displayRecognitionError(ANTLR_UINT8** tokenNames)
{
- // Retrieve some info for easy reading.
- //
- ExceptionBaseType* ex = m_state->get_exception();
- StringType ttext;
+ // Retrieve some info for easy reading.
+ //
+ ExceptionBaseType* ex = m_state->get_exception();
+ StringType ttext;
- // See if there is a 'filename' we can use
- //
- SuperType* super = static_cast<SuperType*>(this);
- super->displayRecognitionError(tokenNames, ex);
+ // See if there is a 'filename' we can use
+ //
+ SuperType* super = static_cast<SuperType*>(this);
+ super->displayRecognitionError(tokenNames, ex);
}
template< class ImplTraits, class StreamType >
ANTLR_UINT32 BaseRecognizer<ImplTraits, StreamType>::getNumberOfSyntaxErrors()
{
- return m_state->get_errorCount();
+ return m_state->get_errorCount();
}
template< class ImplTraits, class StreamType >
-void BaseRecognizer<ImplTraits, StreamType>::recover()
+void BaseRecognizer<ImplTraits, StreamType>::recover()
{
- SuperType* super = static_cast<SuperType*>(this);
- IntStreamType* is = super->get_parser_istream();
- // Are we about to repeat the same error?
- //
- if ( m_state->get_lastErrorIndex() == is->index())
+ SuperType* super = static_cast<SuperType*>(this);
+ IntStreamType* is = super->get_parser_istream();
+ // Are we about to repeat the same error?
+ //
+ if ( m_state->get_lastErrorIndex() == is->index())
{
- // The last error was at the same token index point. This must be a case
- // where LT(1) is in the recovery token set so nothing is
- // consumed. Consume a single token so at least to prevent
- // an infinite loop; this is a failsafe.
- //
- is->consume();
+ // The last error was at the same token index point. This must be a case
+ // where LT(1) is in the recovery token set so nothing is
+ // consumed. Consume a single token so at least to prevent
+ // an infinite loop; this is a failsafe.
+ //
+ is->consume();
}
// Record error index position
@@ -292,7 +292,7 @@ void BaseRecognizer<ImplTraits, StreamType>::recover()
// Work out the follows set for error recovery
//
- BitsetType* followSet = this->computeErrorRecoverySet();
+ BitsetType* followSet = this->computeErrorRecoverySet();
// Call resync hook (for debuggers and so on)
//
@@ -317,262 +317,262 @@ void BaseRecognizer<ImplTraits, StreamType>::recover()
}
template< class ImplTraits, class StreamType >
-void BaseRecognizer<ImplTraits, StreamType>::beginResync()
+void BaseRecognizer<ImplTraits, StreamType>::beginResync()
{
- if (m_debugger != NULL)
- {
- m_debugger->beginResync();
- }
+ if (m_debugger != NULL)
+ {
+ m_debugger->beginResync();
+ }
}
template< class ImplTraits, class StreamType >
-void BaseRecognizer<ImplTraits, StreamType>::endResync()
+void BaseRecognizer<ImplTraits, StreamType>::endResync()
{
- if (m_debugger != NULL)
- {
- m_debugger->endResync();
- }
+ if (m_debugger != NULL)
+ {
+ m_debugger->endResync();
+ }
}
template< class ImplTraits, class StreamType >
-void BaseRecognizer<ImplTraits, StreamType>::beginBacktrack(ANTLR_UINT32 level)
+void BaseRecognizer<ImplTraits, StreamType>::beginBacktrack(ANTLR_UINT32 level)
{
- if (m_debugger != NULL)
- {
- m_debugger->beginBacktrack(level);
- }
+ if (m_debugger != NULL)
+ {
+ m_debugger->beginBacktrack(level);
+ }
}
template< class ImplTraits, class StreamType >
-void BaseRecognizer<ImplTraits, StreamType>::endBacktrack(ANTLR_UINT32 level, bool /*successful*/)
+void BaseRecognizer<ImplTraits, StreamType>::endBacktrack(ANTLR_UINT32 level, bool /*successful*/)
{
- if (m_debugger != NULL)
- {
- m_debugger->endBacktrack(level);
- }
+ if (m_debugger != NULL)
+ {
+ m_debugger->endBacktrack(level);
+ }
}
template< class ImplTraits, class StreamType >
-typename BaseRecognizer<ImplTraits, StreamType>::BitsetType* BaseRecognizer<ImplTraits, StreamType>::computeErrorRecoverySet()
+typename BaseRecognizer<ImplTraits, StreamType>::BitsetType* BaseRecognizer<ImplTraits, StreamType>::computeErrorRecoverySet()
{
- return this->combineFollows(false);
+ return this->combineFollows(false);
}
template< class ImplTraits, class StreamType >
-typename BaseRecognizer<ImplTraits, StreamType>::BitsetType* BaseRecognizer<ImplTraits, StreamType>::computeCSRuleFollow()
+typename BaseRecognizer<ImplTraits, StreamType>::BitsetType* BaseRecognizer<ImplTraits, StreamType>::computeCSRuleFollow()
{
- return this->combineFollows(false);
+ return this->combineFollows(false);
}
template< class ImplTraits, class StreamType >
-typename BaseRecognizer<ImplTraits, StreamType>::BitsetType* BaseRecognizer<ImplTraits, StreamType>::combineFollows(bool exact)
+typename BaseRecognizer<ImplTraits, StreamType>::BitsetType* BaseRecognizer<ImplTraits, StreamType>::combineFollows(bool exact)
{
- BitsetType* followSet;
- BitsetType* localFollowSet;
- ANTLR_UINT32 top;
- ANTLR_UINT32 i;
+ BitsetType* followSet;
+ BitsetType* localFollowSet;
+ ANTLR_UINT32 top;
+ ANTLR_UINT32 i;
- top = static_cast<ANTLR_UINT32>( m_state->get_following().size() );
+ top = static_cast<ANTLR_UINT32>( m_state->get_following().size() );
- followSet = new BitsetType(0);
- localFollowSet = NULL;
+ followSet = new BitsetType(0);
+ localFollowSet = NULL;
for (i = top; i>0; i--)
{
- localFollowSet = m_state->get_following().at(i-1).bitsetLoad();
-
- if (localFollowSet != NULL)
- {
- followSet->borInPlace(localFollowSet);
-
- if (exact == true)
- {
- if (localFollowSet->isMember( ImplTraits::CommonTokenType::EOR_TOKEN_TYPE) == false)
- {
- // Only leave EOR in the set if at top (start rule); this lets us know
- // if we have to include the follow(start rule); I.E., EOF
- //
- if (i>1)
- {
- followSet->remove(ImplTraits::CommonTokenType::EOR_TOKEN_TYPE);
- }
- }
- else
- {
- break; // Cannot see End Of Rule from here, just drop out
- }
- }
- delete localFollowSet;
- localFollowSet = NULL;
- }
+ localFollowSet = m_state->get_following().at(i-1).bitsetLoad();
+
+ if (localFollowSet != NULL)
+ {
+ followSet->borInPlace(localFollowSet);
+
+ if (exact == true)
+ {
+ if (localFollowSet->isMember( ImplTraits::CommonTokenType::EOR_TOKEN_TYPE) == false)
+ {
+ // Only leave EOR in the set if at top (start rule); this lets us know
+ // if we have to include the follow(start rule); I.E., EOF
+ //
+ if (i>1)
+ {
+ followSet->remove(ImplTraits::CommonTokenType::EOR_TOKEN_TYPE);
+ }
+ }
+ else
+ {
+ break; // Cannot see End Of Rule from here, just drop out
+ }
+ }
+ delete localFollowSet;
+ localFollowSet = NULL;
+ }
}
- if (localFollowSet != NULL)
- {
- delete localFollowSet;
- }
+ if (localFollowSet != NULL)
+ {
+ delete localFollowSet;
+ }
return followSet;
}
template< class ImplTraits, class StreamType >
-const typename BaseRecognizer<ImplTraits, StreamType>::UnitType*
-BaseRecognizer<ImplTraits, StreamType>::recoverFromMismatchedToken( ANTLR_UINT32 ttype, BitsetListType* follow)
-{
- SuperType* super = static_cast<SuperType*>(this);
- IntStreamType* is = super->get_parser_istream();
- const UnitType* matchedSymbol;
-
- // If the next token after the one we are looking at in the input stream
- // is what we are looking for then we remove the one we have discovered
- // from the stream by consuming it, then consume this next one along too as
- // if nothing had happened.
- //
- if ( this->mismatchIsUnwantedToken( is, ttype) == true)
- {
- // Create an exception if we need one
- //
- new ANTLR_Exception<ImplTraits, UNWANTED_TOKEN_EXCEPTION, StreamType>(this, "");
-
- // Call resync hook (for debuggers and so on)
- //
- if (m_debugger != NULL)
- {
- m_debugger->beginResync();
- }
-
- // "delete" the extra token
- //
- this->beginResync();
- is->consume();
- this->endResync();
- // End resync hook
- //
- if (m_debugger != NULL)
- {
- m_debugger->endResync();
- }
-
- // Print out the error after we consume so that ANTLRWorks sees the
- // token in the exception.
- //
- this->reportError();
-
- // Return the token we are actually matching
- //
- matchedSymbol = this->getCurrentInputSymbol(is);
-
- // Consume the token that the rule actually expected to get as if everything
- // was hunky dory.
- //
- is->consume();
-
- m_state->set_error(false); // Exception is not outstanding any more
-
- return matchedSymbol;
- }
-
- // Single token deletion (Unwanted above) did not work
- // so we see if we can insert a token instead by calculating which
- // token would be missing
- //
- if ( this->mismatchIsMissingToken(is, follow))
- {
- // We can fake the missing token and proceed
- //
- new ANTLR_Exception<ImplTraits, MISSING_TOKEN_EXCEPTION, StreamType>(this, "");
- matchedSymbol = this->getMissingSymbol( is, m_state->get_exception(), ttype, follow);
- m_state->get_exception()->set_token( matchedSymbol );
- m_state->get_exception()->set_expecting(ttype);
-
- // Print out the error after we insert so that ANTLRWorks sees the
- // token in the exception.
- //
- this->reportError();
-
- m_state->set_error(false); // Exception is not outstanding any more
-
- return matchedSymbol;
- }
-
- // Create an exception if we need one
- //
- new ANTLR_Exception<ImplTraits, RECOGNITION_EXCEPTION, StreamType>(this, "");
-
- // Neither deleting nor inserting tokens allows recovery
- // must just report the exception.
- //
- m_state->set_error(true);
- return NULL;
-}
-
-template< class ImplTraits, class StreamType >
-const typename BaseRecognizer<ImplTraits, StreamType>::UnitType*
-BaseRecognizer<ImplTraits, StreamType>::recoverFromMismatchedSet(BitsetListType* follow)
-{
- SuperType* super = static_cast<SuperType*>(this);
- IntStreamType* is = super->get_parser_istream();
- const UnitType* matchedSymbol;
-
- if (this->mismatchIsMissingToken(is, follow) == true)
- {
- // We can fake the missing token and proceed
- //
- new ANTLR_Exception<ImplTraits, MISSING_TOKEN_EXCEPTION, StreamType>(this);
- matchedSymbol = this->getMissingSymbol(is, m_state->get_exception(), follow);
- m_state->get_exception()->set_token(matchedSymbol);
-
- // Print out the error after we insert so that ANTLRWorks sees the
- // token in the exception.
- //
- this->reportError();
-
- m_state->set_error(false); // Exception is not outstanding any more
-
- return matchedSymbol;
- }
+const typename BaseRecognizer<ImplTraits, StreamType>::UnitType*
+BaseRecognizer<ImplTraits, StreamType>::recoverFromMismatchedToken( ANTLR_UINT32 ttype, BitsetListType* follow)
+{
+ SuperType* super = static_cast<SuperType*>(this);
+ IntStreamType* is = super->get_parser_istream();
+ const UnitType* matchedSymbol;
+
+ // If the next token after the one we are looking at in the input stream
+ // is what we are looking for then we remove the one we have discovered
+ // from the stream by consuming it, then consume this next one along too as
+ // if nothing had happened.
+ //
+ if ( this->mismatchIsUnwantedToken( is, ttype) == true)
+ {
+ // Create an exception if we need one
+ //
+ new ANTLR_Exception<ImplTraits, UNWANTED_TOKEN_EXCEPTION, StreamType>(this, "");
+
+ // Call resync hook (for debuggers and so on)
+ //
+ if (m_debugger != NULL)
+ {
+ m_debugger->beginResync();
+ }
+
+ // "delete" the extra token
+ //
+ this->beginResync();
+ is->consume();
+ this->endResync();
+ // End resync hook
+ //
+ if (m_debugger != NULL)
+ {
+ m_debugger->endResync();
+ }
+
+ // Print out the error after we consume so that ANTLRWorks sees the
+ // token in the exception.
+ //
+ this->reportError();
+
+ // Return the token we are actually matching
+ //
+ matchedSymbol = this->getCurrentInputSymbol(is);
+
+ // Consume the token that the rule actually expected to get as if everything
+ // was hunky dory.
+ //
+ is->consume();
+
+ m_state->set_error(false); // Exception is not outstanding any more
+
+ return matchedSymbol;
+ }
+
+ // Single token deletion (Unwanted above) did not work
+ // so we see if we can insert a token instead by calculating which
+ // token would be missing
+ //
+ if ( this->mismatchIsMissingToken(is, follow))
+ {
+ // We can fake the missing token and proceed
+ //
+ new ANTLR_Exception<ImplTraits, MISSING_TOKEN_EXCEPTION, StreamType>(this, "");
+ matchedSymbol = this->getMissingSymbol( is, m_state->get_exception(), ttype, follow);
+ m_state->get_exception()->set_token( matchedSymbol );
+ m_state->get_exception()->set_expecting(ttype);
+
+ // Print out the error after we insert so that ANTLRWorks sees the
+ // token in the exception.
+ //
+ this->reportError();
+
+ m_state->set_error(false); // Exception is not outstanding any more
+
+ return matchedSymbol;
+ }
+
+ // Create an exception if we need one
+ //
+ new ANTLR_Exception<ImplTraits, RECOGNITION_EXCEPTION, StreamType>(this, "");
+
+ // Neither deleting nor inserting tokens allows recovery
+ // must just report the exception.
+ //
+ m_state->set_error(true);
+ return NULL;
+}
+
+template< class ImplTraits, class StreamType >
+const typename BaseRecognizer<ImplTraits, StreamType>::UnitType*
+BaseRecognizer<ImplTraits, StreamType>::recoverFromMismatchedSet(BitsetListType* follow)
+{
+ SuperType* super = static_cast<SuperType*>(this);
+ IntStreamType* is = super->get_parser_istream();
+ const UnitType* matchedSymbol;
+
+ if (this->mismatchIsMissingToken(is, follow) == true)
+ {
+ // We can fake the missing token and proceed
+ //
+ new ANTLR_Exception<ImplTraits, MISSING_TOKEN_EXCEPTION, StreamType>(this);
+ matchedSymbol = this->getMissingSymbol(is, m_state->get_exception(), follow);
+ m_state->get_exception()->set_token(matchedSymbol);
+
+ // Print out the error after we insert so that ANTLRWorks sees the
+ // token in the exception.
+ //
+ this->reportError();
+
+ m_state->set_error(false); // Exception is not outstanding any more
+
+ return matchedSymbol;
+ }
// TODO - Single token deletion like in recoverFromMismatchedToken()
//
m_state->set_error(true);
- m_state->set_failed(true);
- return NULL;
+ m_state->set_failed(true);
+ return NULL;
}
template< class ImplTraits, class StreamType >
-bool BaseRecognizer<ImplTraits, StreamType>::recoverFromMismatchedElement(BitsetListType* followBits)
+bool BaseRecognizer<ImplTraits, StreamType>::recoverFromMismatchedElement(BitsetListType* followBits)
{
- SuperType* super = static_cast<SuperType*>(this);
- IntStreamType* is = super->get_parser_istream();
+ SuperType* super = static_cast<SuperType*>(this);
+ IntStreamType* is = super->get_parser_istream();
- BitsetType* follow = followBits->load();
- BitsetType* viableToksFollowingRule;
+ BitsetType* follow = followBits->load();
+ BitsetType* viableToksFollowingRule;
- if (follow == NULL)
+ if (follow == NULL)
{
- /* The follow set is NULL, which means we don't know what can come
- * next, so we "hit and hope" by just signifying that we cannot
- * recover, which will just cause the next token to be consumed,
- * which might dig us out.
- */
- return false;
+ /* The follow set is NULL, which means we don't know what can come
+ * next, so we "hit and hope" by just signifying that we cannot
+ * recover, which will just cause the next token to be consumed,
+ * which might dig us out.
+ */
+ return false;
}
/* We have a bitmap for the follow set, hence we can compute
* what can follow this grammar element reference.
*/
- if (follow->isMember( ImplTraits::CommonTokenType::EOR_TOKEN_TYPE) == true)
+ if (follow->isMember( ImplTraits::CommonTokenType::EOR_TOKEN_TYPE) == true)
{
- /* First we need to know which of the available tokens are viable
- * to follow this reference.
- */
- viableToksFollowingRule = this->computeCSRuleFollow();
-
- /* Remove the EOR token, which we do not wish to compute with
- */
- follow->remove( ImplTraits::CommonTokenType::EOR_TOKEN_TYPE);
- delete viableToksFollowingRule;
- /* We now have the computed set of what can follow the current token
- */
+ /* First we need to know which of the available tokens are viable
+ * to follow this reference.
+ */
+ viableToksFollowingRule = this->computeCSRuleFollow();
+
+ /* Remove the EOR token, which we do not wish to compute with
+ */
+ follow->remove( ImplTraits::CommonTokenType::EOR_TOKEN_TYPE);
+ delete viableToksFollowingRule;
+ /* We now have the computed set of what can follow the current token
+ */
}
/* We can now see if the current token works with the set of tokens
@@ -580,23 +580,23 @@ bool BaseRecognizer<ImplTraits, StreamType>::recoverFromMismatchedElement(Bitse
* is consistent, then we can "insert" that token by not throwing
* an exception and assuming that we saw it.
*/
- if ( follow->isMember(is->LA(1)) == true)
+ if ( follow->isMember(is->LA(1)) == true)
{
- /* report the error, but don't cause any rules to abort and stuff
- */
- this->reportError();
- if (follow != NULL)
- {
- delete follow;
- }
- m_state->set_error(false);
- m_state->set_failed(false);
- return true; /* Success in recovery */
+ /* report the error, but don't cause any rules to abort and stuff
+ */
+ this->reportError();
+ if (follow != NULL)
+ {
+ delete follow;
+ }
+ m_state->set_error(false);
+ m_state->set_failed(false);
+ return true; /* Success in recovery */
}
- if (follow != NULL)
+ if (follow != NULL)
{
- delete follow;
+ delete follow;
}
/* We could not find anything viable to do, so this is going to
@@ -606,119 +606,119 @@ bool BaseRecognizer<ImplTraits, StreamType>::recoverFromMismatchedElement(Bitse
}
template< class ImplTraits, class StreamType >
-void BaseRecognizer<ImplTraits, StreamType>::consumeUntil(ANTLR_UINT32 tokenType)
+void BaseRecognizer<ImplTraits, StreamType>::consumeUntil(ANTLR_UINT32 tokenType)
{
- SuperType* super = static_cast<SuperType*>(this);
- IntStreamType* is = super->get_parser_istream();
+ SuperType* super = static_cast<SuperType*>(this);
+ IntStreamType* is = super->get_parser_istream();
- // What do have at the moment?
+ // What do have at the moment?
//
- ANTLR_UINT32 ttype = is->LA(1);
+ ANTLR_UINT32 ttype = is->LA(1);
// Start eating tokens until we get to the one we want.
//
while (ttype != ImplTraits::CommonTokenType::TOKEN_EOF && ttype != tokenType)
{
- is->consume();
- ttype = is->LA(1);
+ is->consume();
+ ttype = is->LA(1);
}
}
template< class ImplTraits, class StreamType >
-void BaseRecognizer<ImplTraits, StreamType>::consumeUntilSet(BitsetType* set)
+void BaseRecognizer<ImplTraits, StreamType>::consumeUntilSet(BitsetType* set)
{
- ANTLR_UINT32 ttype;
- SuperType* super = static_cast<SuperType*>(this);
- IntStreamType* is = super->get_parser_istream();
+ ANTLR_UINT32 ttype;
+ SuperType* super = static_cast<SuperType*>(this);
+ IntStreamType* is = super->get_parser_istream();
// What do have at the moment?
//
- ttype = is->LA(1);
+ ttype = is->LA(1);
// Start eating tokens until we get to one we want.
//
while (ttype != ImplTraits::CommonTokenType::TOKEN_EOF && set->isMember(ttype) == false)
{
- is->consume();
- ttype = is->LA(1);
+ is->consume();
+ ttype = is->LA(1);
}
}
template< class ImplTraits, class StreamType >
-ANTLR_MARKER BaseRecognizer<ImplTraits, StreamType>::getRuleMemoization( ANTLR_INTKEY ruleIndex, ANTLR_MARKER ruleParseStart)
+ANTLR_MARKER BaseRecognizer<ImplTraits, StreamType>::getRuleMemoization( ANTLR_INTKEY ruleIndex, ANTLR_MARKER ruleParseStart)
{
- /* The rule memos are an ANTLR3_LIST of ANTLR3_LIST.
+ /* The rule memos are an ANTLR3_LIST of ANTLR3_LIST.
*/
- typedef IntTrie<ImplTraits, ANTLR_MARKER> RuleListType;
+ typedef IntTrie<ImplTraits, ANTLR_MARKER> RuleListType;
typedef TrieEntry<ImplTraits, std::shared_ptr<RuleListType>> EntryType;
- typedef TrieEntry<ImplTraits, ANTLR_MARKER> SubEntryType;
- ANTLR_MARKER stopIndex;
- EntryType* entry;
+ typedef TrieEntry<ImplTraits, ANTLR_MARKER> SubEntryType;
+ ANTLR_MARKER stopIndex;
+ EntryType* entry;
/* See if we have a list in the ruleMemos for this rule, and if not, then create one
* as we will need it eventually if we are being asked for the memo here.
*/
- entry = m_state->get_ruleMemo()->get(ruleIndex);
+ entry = m_state->get_ruleMemo()->get(ruleIndex);
- if (entry == NULL)
+ if (entry == NULL)
{
- /* Did not find it, so create a new one for it, with a bit depth based on the
- * size of the input stream. We need the bit depth to incorporate the number if
- * bits required to represent the largest possible stop index in the input, which is the
- * last character. An int stream is free to return the largest 64 bit offset if it has
- * no idea of the size, but you should remember that this will cause the leftmost
- * bit match algorithm to run to 63 bits, which will be the whole time spent in the trie ;-)
- */
+ /* Did not find it, so create a new one for it, with a bit depth based on the
+ * size of the input stream. We need the bit depth to incorporate the number if
+ * bits required to represent the largest possible stop index in the input, which is the
+ * last character. An int stream is free to return the largest 64 bit offset if it has
+ * no idea of the size, but you should remember that this will cause the leftmost
+ * bit match algorithm to run to 63 bits, which will be the whole time spent in the trie ;-)
+ */
m_state->get_ruleMemo()->add( ruleIndex, std::make_shared<RuleListType>(63) );
- /* We cannot have a stopIndex in a trie we have just created of course
- */
- return MEMO_RULE_UNKNOWN;
+ /* We cannot have a stopIndex in a trie we have just created of course
+ */
+ return MEMO_RULE_UNKNOWN;
}
std::shared_ptr<RuleListType> ruleList = entry->get_data();
/* See if there is a stop index associated with the supplied start index.
*/
- stopIndex = 0;
+ stopIndex = 0;
SubEntryType* sub_entry = ruleList->get(ruleParseStart);
if (sub_entry != NULL)
{
- stopIndex = sub_entry->get_data();
+ stopIndex = sub_entry->get_data();
}
- if (stopIndex == 0)
+ if (stopIndex == 0)
{
- return MEMO_RULE_UNKNOWN;
+ return MEMO_RULE_UNKNOWN;
}
return stopIndex;
}
template< class ImplTraits, class StreamType >
-bool BaseRecognizer<ImplTraits, StreamType>::alreadyParsedRule(ANTLR_MARKER ruleIndex)
+bool BaseRecognizer<ImplTraits, StreamType>::alreadyParsedRule(ANTLR_MARKER ruleIndex)
{
- SuperType* super = static_cast<SuperType*>(this);
- IntStreamType* is = super->get_istream();
+ SuperType* super = static_cast<SuperType*>(this);
+ IntStreamType* is = super->get_istream();
/* See if we have a memo marker for this.
*/
- ANTLR_MARKER stopIndex = this->getRuleMemoization( ruleIndex, is->index() );
+ ANTLR_MARKER stopIndex = this->getRuleMemoization( ruleIndex, is->index() );
- if (stopIndex == MEMO_RULE_UNKNOWN)
+ if (stopIndex == MEMO_RULE_UNKNOWN)
{
- return false;
+ return false;
}
- if (stopIndex == MEMO_RULE_FAILED)
+ if (stopIndex == MEMO_RULE_FAILED)
{
- m_state->set_failed(true);
+ m_state->set_failed(true);
}
else
{
- is->seek(stopIndex+1);
+ is->seek(stopIndex+1);
}
/* If here then the rule was executed for this input already
@@ -727,30 +727,30 @@ bool BaseRecognizer<ImplTraits, StreamType>::alreadyParsedRule(ANTLR_MARKER rule
}
template< class ImplTraits, class StreamType >
-void BaseRecognizer<ImplTraits, StreamType>::memoize(ANTLR_MARKER ruleIndex, ANTLR_MARKER ruleParseStart)
+void BaseRecognizer<ImplTraits, StreamType>::memoize(ANTLR_MARKER ruleIndex, ANTLR_MARKER ruleParseStart)
{
/* The rule memos are an ANTLR3_LIST of ANTLR3_LIST.
*/
- typedef IntTrie<ImplTraits, ANTLR_MARKER> RuleListType;
+ typedef IntTrie<ImplTraits, ANTLR_MARKER> RuleListType;
typedef TrieEntry<ImplTraits, std::shared_ptr<RuleListType>> EntryType;
- EntryType* entry;
- ANTLR_MARKER stopIndex;
- SuperType* super = static_cast<SuperType*>(this);
- IntStreamType* is = super->get_istream();
+ EntryType* entry;
+ ANTLR_MARKER stopIndex;
+ SuperType* super = static_cast<SuperType*>(this);
+ IntStreamType* is = super->get_istream();
- stopIndex = (m_state->get_failed() == true) ? MEMO_RULE_FAILED : is->index() - 1;
+ stopIndex = (m_state->get_failed() == true) ? MEMO_RULE_FAILED : is->index() - 1;
- entry = m_state->get_ruleMemo()->get(ruleIndex);
+ entry = m_state->get_ruleMemo()->get(ruleIndex);
- if (entry != NULL)
+ if (entry != NULL)
{
std::shared_ptr<RuleListType> ruleList = entry->get_data();
- /* If we don't already have this entry, append it. The memoize trie does not
- * accept duplicates so it won't add it if already there and we just ignore the
- * return code as we don't care if it is there already.
- */
- ruleList->add(ruleParseStart, stopIndex);
+ /* If we don't already have this entry, append it. The memoize trie does not
+ * accept duplicates so it won't add it if already there and we just ignore the
+ * return code as we don't care if it is there already.
+ */
+ ruleList->add(ruleParseStart, stopIndex);
}
}
@@ -758,52 +758,52 @@ template< class ImplTraits, class StreamType >
const typename BaseRecognizer<ImplTraits, StreamType>::UnitType*
BaseRecognizer<ImplTraits, StreamType>::getCurrentInputSymbol( IntStreamType* istream )
{
- return this->getCurrentInputSymbol( istream, ClassForwarder<SuperType>() );
+ return this->getCurrentInputSymbol( istream, ClassForwarder<SuperType>() );
}
template< class ImplTraits, class StreamType >
const typename BaseRecognizer<ImplTraits, StreamType>::UnitType*
-BaseRecognizer<ImplTraits, StreamType>::getCurrentInputSymbol(IntStreamType* /*istream*/, ClassForwarder<LexerType>)
+BaseRecognizer<ImplTraits, StreamType>::getCurrentInputSymbol(IntStreamType* /*istream*/, ClassForwarder<LexerType>)
{
- return NULL;
+ return NULL;
}
template< class ImplTraits, class StreamType >
const typename BaseRecognizer<ImplTraits, StreamType>::UnitType*
BaseRecognizer<ImplTraits, StreamType>::getCurrentInputSymbol(IntStreamType* istream, ClassForwarder<ParserType>)
{
- typedef typename ImplTraits::TokenStreamType TokenStreamType;
- TokenStreamType* token_stream = static_cast<TokenStreamType*>(istream);
- return token_stream->LT(1);
+ typedef typename ImplTraits::TokenStreamType TokenStreamType;
+ TokenStreamType* token_stream = static_cast<TokenStreamType*>(istream);
+ return token_stream->LT(1);
}
template< class ImplTraits, class StreamType >
const typename BaseRecognizer<ImplTraits, StreamType>::UnitType*
BaseRecognizer<ImplTraits, StreamType>::getCurrentInputSymbol(IntStreamType* istream, ClassForwarder<TreeParserType>)
{
- typedef typename ImplTraits::TreeNodeStreamType TreeNodeStreamType;
- TreeNodeStreamType* ctns = static_cast<TreeNodeStreamType*>(istream);
- return ctns->LT(1);
+ typedef typename ImplTraits::TreeNodeStreamType TreeNodeStreamType;
+ TreeNodeStreamType* ctns = static_cast<TreeNodeStreamType*>(istream);
+ return ctns->LT(1);
}
template< class ImplTraits, class StreamType >
-typename BaseRecognizer<ImplTraits, StreamType>::UnitType* BaseRecognizer<ImplTraits, StreamType>::getMissingSymbol( IntStreamType* istream,
- ExceptionBaseType* e,
- ANTLR_UINT32 expectedTokenType,
- BitsetListType* follow)
+typename BaseRecognizer<ImplTraits, StreamType>::UnitType* BaseRecognizer<ImplTraits, StreamType>::getMissingSymbol( IntStreamType* istream,
+ ExceptionBaseType* e,
+ ANTLR_UINT32 expectedTokenType,
+ BitsetListType* follow)
{
- return this->get_super()->getMissingSymbol( istream, e, expectedTokenType, follow );
+ return this->get_super()->getMissingSymbol( istream, e, expectedTokenType, follow );
}
template< class ImplTraits, class StreamType >
- template<typename Predicate>
+ template<typename Predicate>
bool BaseRecognizer<ImplTraits, StreamType>::synpred(ClassForwarder<Predicate> pred)
{
- ANTLR_MARKER start;
+ ANTLR_MARKER start;
SuperType* super = static_cast<SuperType*>(this);
- IntStreamType* is = super->get_istream();
+ IntStreamType* is = super->get_istream();
/* Begin backtracking so we can get back to where we started after trying out
* the syntactic predicate.
@@ -820,60 +820,60 @@ bool BaseRecognizer<ImplTraits, StreamType>::synpred(ClassForwarder<Predicate>
is->rewind(start);
m_state->dec_backtracking();
- if ( m_state->get_failed() == true)
+ if ( m_state->get_failed() == true)
{
- /* Predicate failed
- */
- m_state->set_failed(false);
- return false;
+ /* Predicate failed
+ */
+ m_state->set_failed(false);
+ return false;
}
else
{
- /* Predicate was successful
- */
- m_state->set_failed(false);
- return true;
+ /* Predicate was successful
+ */
+ m_state->set_failed(false);
+ return true;
}
}
template< class ImplTraits, class StreamType >
void BaseRecognizer<ImplTraits, StreamType>::exConstruct()
{
- this->get_super()->exConstruct();
+ this->get_super()->exConstruct();
}
template< class ImplTraits, class StreamType >
void BaseRecognizer<ImplTraits, StreamType>::reset()
{
- this->reset( ClassForwarder<SuperType>() );
+ this->reset( ClassForwarder<SuperType>() );
}
template< class ImplTraits, class StreamType >
template< typename CompType >
void BaseRecognizer<ImplTraits, StreamType>::reset( ClassForwarder<CompType> )
{
- typedef typename RecognizerSharedStateType::RuleMemoType RuleMemoType;
- m_state->get_following().clear();
+ typedef typename RecognizerSharedStateType::RuleMemoType RuleMemoType;
+ m_state->get_following().clear();
- // Reset the state flags
- //
- m_state->set_errorRecovery(false);
- m_state->set_lastErrorIndex(-1);
- m_state->set_failed(false);
- m_state->set_errorCount(0);
- m_state->set_backtracking(0);
+ // Reset the state flags
+ //
+ m_state->set_errorRecovery(false);
+ m_state->set_lastErrorIndex(-1);
+ m_state->set_failed(false);
+ m_state->set_errorCount(0);
+ m_state->set_backtracking(0);
- if (m_state->get_ruleMemo() != NULL)
- {
- delete m_state->get_ruleMemo();
- m_state->set_ruleMemo( new RuleMemoType(15) ); /* 16 bit depth is enough for 32768 rules! */
- }
+ if (m_state->get_ruleMemo() != NULL)
+ {
+ delete m_state->get_ruleMemo();
+ m_state->set_ruleMemo( new RuleMemoType(15) ); /* 16 bit depth is enough for 32768 rules! */
+ }
}
template< class ImplTraits, class StreamType >
void BaseRecognizer<ImplTraits, StreamType>::reset( ClassForwarder<LexerType> )
{
- m_state->set_token_present( false );
+ m_state->set_token_present( false );
m_state->set_type( ImplTraits::CommonTokenType::TOKEN_INVALID );
m_state->set_channel( TOKEN_DEFAULT_CHANNEL );
m_state->set_tokenStartCharIndex( -1 );
@@ -885,36 +885,36 @@ void BaseRecognizer<ImplTraits, StreamType>::reset( ClassForwarder<LexerType> )
template< class ImplTraits, class StreamType >
BaseRecognizer<ImplTraits, StreamType>::~BaseRecognizer()
{
- // Did we have a state allocated?
- //
- if (m_state != NULL)
- {
- // Free any rule memoization we set up
- //
- if (m_state->get_ruleMemo() != NULL)
- {
- delete m_state->get_ruleMemo();
- m_state->set_ruleMemo(NULL);
- }
+ // Did we have a state allocated?
+ //
+ if (m_state != NULL)
+ {
+ // Free any rule memoization we set up
+ //
+ if (m_state->get_ruleMemo() != NULL)
+ {
+ delete m_state->get_ruleMemo();
+ m_state->set_ruleMemo(NULL);
+ }
- // Free any exception space we have left around
- //
- ExceptionBaseType* thisE = m_state->get_exception();
- if (thisE != NULL)
- {
- delete thisE;
- }
+ // Free any exception space we have left around
+ //
+ ExceptionBaseType* thisE = m_state->get_exception();
+ if (thisE != NULL)
+ {
+ delete thisE;
+ }
- // Free the shared state memory
- //
- delete m_state;
- }
+ // Free the shared state memory
+ //
+ delete m_state;
+ }
- // Free the actual recognizer space
- //
+ // Free the actual recognizer space
+ //
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3bitset.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3bitset.hpp
index f72a54f834..68eab69568 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3bitset.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3bitset.hpp
@@ -1,12 +1,12 @@
/**
* \file
- * Defines the basic structures of an ANTLR3 bitset. this is a C version of the
+ * Defines the basic structures of an ANTLR3 bitset. this is a C version of the
* cut down Bitset class provided with the java version of antlr 3.
- *
- *
+ *
+ *
*/
-#ifndef _ANTLR3_BITSET_HPP
-#define _ANTLR3_BITSET_HPP
+#ifndef _ANTLR3_BITSET_HPP
+#define _ANTLR3_BITSET_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -36,45 +36,45 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
/** How many bits in the elements
*/
-static const ANTLR_UINT32 ANTLR_BITSET_BITS = 64;
+static const ANTLR_UINT32 ANTLR_BITSET_BITS = 64;
/** How many bits in a nible of bits
*/
-static const ANTLR_UINT32 ANTLR_BITSET_NIBBLE = 4;
+static const ANTLR_UINT32 ANTLR_BITSET_NIBBLE = 4;
/** log2 of ANTLR3_BITSET_BITS 2^ANTLR3_BITSET_LOG_BITS = ANTLR3_BITSET_BITS
*/
-static const ANTLR_UINT32 ANTLR_BITSET_LOG_BITS = 6;
+static const ANTLR_UINT32 ANTLR_BITSET_LOG_BITS = 6;
/** We will often need to do a mod operator (i mod nbits).
* For powers of two, this mod operation is the
* same as:
- * - (i & (nbits-1)).
+ * - (i & (nbits-1)).
*
* Since mod is relatively slow, we use an easily
* precomputed mod mask to do the mod instead.
*/
-static const ANTLR_UINT32 ANTLR_BITSET_MOD_MASK = ANTLR_BITSET_BITS - 1;
+static const ANTLR_UINT32 ANTLR_BITSET_MOD_MASK = ANTLR_BITSET_BITS - 1;
template <class ImplTraits>
class BitsetList : public ImplTraits::AllocPolicyType
{
public:
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename ImplTraits::BitsetType BitsetType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::BitsetType BitsetType;
private:
- /// Pointer to the allocated array of bits for this bit set, which
- /// is an array of 64 bit elements (of the architecture). If we find a
+ /// Pointer to the allocated array of bits for this bit set, which
+ /// is an array of 64 bit elements (of the architecture). If we find a
/// machine/C compiler that does not know anything about 64 bit values
- /// then it should be easy enough to produce a 32 bit (or less) version
+ /// then it should be easy enough to produce a 32 bit (or less) version
/// of the bitset code. Note that the pointer here may be static if laid down
- /// by the code generation, and it must be copied if it is to be manipulated
- /// to perform followset calculations.
+ /// by the code generation, and it must be copied if it is to be manipulated
+ /// to perform followset calculations.
///
ANTLR_BITWORD* m_bits;
@@ -83,38 +83,38 @@ private:
ANTLR_UINT32 m_length;
public:
- BitsetList();
- BitsetList( ANTLR_BITWORD* bits, ANTLR_UINT32 length );
-
- ANTLR_BITWORD* get_bits() const;
- ANTLR_UINT32 get_length() const;
- void set_bits( ANTLR_BITWORD* bits );
- void set_length( ANTLR_UINT32 length );
-
- ///
- /// \brief
- /// Creates a new bitset with at least one 64 bit bset of bits, but as
- /// many 64 bit sets as are required.
+ BitsetList();
+ BitsetList( ANTLR_BITWORD* bits, ANTLR_UINT32 length );
+
+ ANTLR_BITWORD* get_bits() const;
+ ANTLR_UINT32 get_length() const;
+ void set_bits( ANTLR_BITWORD* bits );
+ void set_length( ANTLR_UINT32 length );
+
+ ///
+ /// \brief
+ /// Creates a new bitset with at least one 64 bit bset of bits, but as
+ /// many 64 bit sets as are required.
+ ///
+ /// \param[in] bset
+ /// A variable number of bits to add to the set, ending in -1 (impossible bit).
///
- /// \param[in] bset
- /// A variable number of bits to add to the set, ending in -1 (impossible bit).
- ///
- /// \returns
- /// A new bit set with all of the specified bitmaps in it and the API
- /// initialized.
- ///
- /// Call as:
- /// - pANTLR3_BITSET = antlrBitsetLoad(bset, bset11, ..., -1);
- /// - pANTLR3_BITSET = antlrBitsetOf(-1); Create empty bitset
+ /// \returns
+ /// A new bit set with all of the specified bitmaps in it and the API
+ /// initialized.
///
- /// \remarks
- /// Stdargs function - must supply -1 as last paremeter, which is NOT
- /// added to the set.
- ///
+ /// Call as:
+ /// - pANTLR3_BITSET = antlrBitsetLoad(bset, bset11, ..., -1);
+ /// - pANTLR3_BITSET = antlrBitsetOf(-1); Create empty bitset
+ ///
+ /// \remarks
+ /// Stdargs function - must supply -1 as last paremeter, which is NOT
+ /// added to the set.
///
- BitsetType* bitsetLoad();
+ ///
+ BitsetType* bitsetLoad();
- BitsetType* bitsetCopy();
+ BitsetType* bitsetCopy();
};
@@ -122,99 +122,99 @@ template <class ImplTraits>
class Bitset : public ImplTraits::AllocPolicyType
{
public:
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename AllocPolicyType::template ListType<ANTLR_UINT32> IntListType;
- typedef typename ImplTraits::BitsetListType BitsetListType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename AllocPolicyType::template ListType<ANTLR_UINT32> IntListType;
+ typedef typename ImplTraits::BitsetListType BitsetListType;
private:
- /// The actual bits themselves
- ///
- BitsetListType m_blist;
+ /// The actual bits themselves
+ ///
+ BitsetListType m_blist;
public:
- Bitset( ANTLR_UINT32 nbits=0 );
- Bitset( const Bitset& bitset );
+ Bitset( ANTLR_UINT32 nbits=0 );
+ Bitset( const Bitset& bitset );
Bitset* clone() const;
- Bitset* bor(Bitset* bitset2);
-
- BitsetListType& get_blist();
- void borInPlace(Bitset* bitset2);
- ANTLR_UINT32 size() const;
- void add(ANTLR_INT32 bit);
- void grow(ANTLR_INT32 newSize);
- bool equals(Bitset* bitset2) const;
- bool isMember(ANTLR_UINT32 bit) const;
- ANTLR_UINT32 numBits() const;
- void remove(ANTLR_UINT32 bit);
- bool isNilNode() const;
-
- /** Produce an integer list of all the bits that are turned on
- * in this bitset. Used for error processing in the main as the bitset
- * reresents a number of integer tokens which we use for follow sets
- * and so on.
- *
- * The first entry is the number of elements following in the list.
- */
- ANTLR_INT32* toIntList() const;
-
+ Bitset* bor(Bitset* bitset2);
+
+ BitsetListType& get_blist();
+ void borInPlace(Bitset* bitset2);
+ ANTLR_UINT32 size() const;
+ void add(ANTLR_INT32 bit);
+ void grow(ANTLR_INT32 newSize);
+ bool equals(Bitset* bitset2) const;
+ bool isMember(ANTLR_UINT32 bit) const;
+ ANTLR_UINT32 numBits() const;
+ void remove(ANTLR_UINT32 bit);
+ bool isNilNode() const;
+
+ /** Produce an integer list of all the bits that are turned on
+ * in this bitset. Used for error processing in the main as the bitset
+ * reresents a number of integer tokens which we use for follow sets
+ * and so on.
+ *
+ * The first entry is the number of elements following in the list.
+ */
+ ANTLR_INT32* toIntList() const;
+
+ ///
+ /// \brief
+ /// Creates a new bitset with at least one element, but as
+ /// many elements are required.
+ ///
+ /// \param[in] bit
+ /// A variable number of bits to add to the set, ending in -1 (impossible bit).
///
- /// \brief
- /// Creates a new bitset with at least one element, but as
- /// many elements are required.
- ///
- /// \param[in] bit
- /// A variable number of bits to add to the set, ending in -1 (impossible bit).
- ///
- /// \returns
- /// A new bit set with all of the specified elements added into it.
- ///
- /// Call as:
- /// - pANTLR3_BITSET = antlrBitsetOf(n, n1, n2, -1);
- /// - pANTLR3_BITSET = antlrBitsetOf(-1); Create empty bitset
+ /// \returns
+ /// A new bit set with all of the specified elements added into it.
///
- /// \remarks
- /// Stdargs function - must supply -1 as last paremeter, which is NOT
- /// added to the set.
- ///
+ /// Call as:
+ /// - pANTLR3_BITSET = antlrBitsetOf(n, n1, n2, -1);
+ /// - pANTLR3_BITSET = antlrBitsetOf(-1); Create empty bitset
+ ///
+ /// \remarks
+ /// Stdargs function - must supply -1 as last paremeter, which is NOT
+ /// added to the set.
///
- //C++ doesn't like variable length arguments. so use function overloading
- static Bitset* BitsetOf(ANTLR_INT32 bit);
- static Bitset* BitsetOf(ANTLR_INT32 bit1, ANTLR_INT32 bit2);
-
+ ///
+ //C++ doesn't like variable length arguments. so use function overloading
+ static Bitset* BitsetOf(ANTLR_INT32 bit);
+ static Bitset* BitsetOf(ANTLR_INT32 bit1, ANTLR_INT32 bit2);
+
+ ///
+ /// \brief
+ /// Creates a new bitset with at least one 64 bit bset of bits, but as
+ /// many 64 bit sets as are required.
+ ///
+ /// \param[in] bset
+ /// A variable number of bits to add to the set, ending in -1 (impossible bit).
///
- /// \brief
- /// Creates a new bitset with at least one 64 bit bset of bits, but as
- /// many 64 bit sets as are required.
+ /// \returns
+ /// A new bit set with all of the specified bitmaps in it and the API
+ /// initialized.
///
- /// \param[in] bset
- /// A variable number of bits to add to the set, ending in -1 (impossible bit).
- ///
- /// \returns
- /// A new bit set with all of the specified bitmaps in it and the API
- /// initialized.
- ///
- /// Call as:
- /// - pANTLR3_BITSET = antlrBitsetLoad(bset, bset11, ..., -1);
- /// - pANTLR3_BITSET = antlrBitsetOf(-1); Create empty bitset
+ /// Call as:
+ /// - pANTLR3_BITSET = antlrBitsetLoad(bset, bset11, ..., -1);
+ /// - pANTLR3_BITSET = antlrBitsetOf(-1); Create empty bitset
+ ///
+ /// \remarks
+ /// Stdargs function - must supply -1 as last paremeter, which is NOT
+ /// added to the set.
///
- /// \remarks
- /// Stdargs function - must supply -1 as last paremeter, which is NOT
- /// added to the set.
- ///
- ///antlr3BitsetList
- static Bitset* BitsetFromList(const IntListType& list);
- ~Bitset();
+ ///antlr3BitsetList
+ static Bitset* BitsetFromList(const IntListType& list);
+ ~Bitset();
private:
- void growToInclude(ANTLR_INT32 bit);
- static ANTLR_UINT64 BitMask(ANTLR_UINT32 bitNumber);
- static ANTLR_UINT32 NumWordsToHold(ANTLR_UINT32 bit);
- static ANTLR_UINT32 WordNumber(ANTLR_UINT32 bit);
- void bitsetORInPlace(Bitset* bitset2);
-
+ void growToInclude(ANTLR_INT32 bit);
+ static ANTLR_UINT64 BitMask(ANTLR_UINT32 bitNumber);
+ static ANTLR_UINT32 NumWordsToHold(ANTLR_UINT32 bit);
+ static ANTLR_UINT32 WordNumber(ANTLR_UINT32 bit);
+ void bitsetORInPlace(Bitset* bitset2);
+
};
-}
+}
#include "antlr3bitset.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3bitset.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3bitset.inl
index 9d49a317dd..64318ea0ea 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3bitset.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3bitset.inl
@@ -1,92 +1,92 @@
-namespace antlr3 {
+namespace antlr3 {
template <class ImplTraits>
ANTLR_INLINE BitsetList<ImplTraits>::BitsetList()
{
- m_bits = NULL;
- m_length = 0;
+ m_bits = NULL;
+ m_length = 0;
}
template <class ImplTraits>
ANTLR_INLINE BitsetList<ImplTraits>::BitsetList( ANTLR_BITWORD* bits, ANTLR_UINT32 length )
{
- m_bits = bits;
- m_length = length;
+ m_bits = bits;
+ m_length = length;
}
template <class ImplTraits>
ANTLR_INLINE ANTLR_BITWORD* BitsetList<ImplTraits>::get_bits() const
{
- return m_bits;
+ return m_bits;
}
template <class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 BitsetList<ImplTraits>::get_length() const
{
- return m_length;
+ return m_length;
}
template <class ImplTraits>
ANTLR_INLINE void BitsetList<ImplTraits>::set_bits( ANTLR_BITWORD* bits )
{
- m_bits = bits;
+ m_bits = bits;
}
template <class ImplTraits>
ANTLR_INLINE void BitsetList<ImplTraits>::set_length( ANTLR_UINT32 length )
{
- m_length = length;
+ m_length = length;
}
template <class ImplTraits>
typename BitsetList<ImplTraits>::BitsetType* BitsetList<ImplTraits>::bitsetLoad()
{
- // Allocate memory for the bitset structure itself
- // the input parameter is the bit number (0 based)
- // to include in the bitset, so we need at at least
- // bit + 1 bits. If any arguments indicate a
- // a bit higher than the default number of bits (0 means default size)
- // then Add() will take care
- // of it.
- //
- BitsetType* bitset = new BitsetType();
-
- if (this != NULL)
- {
- // Now we can add the element bits into the set
- //
- ANTLR_UINT32 count=0;
- while (count < m_length)
- {
- if( bitset->get_blist().get_length() <= count)
- bitset->grow(count+1);
-
- typename ImplTraits::BitsetListType& blist = bitset->get_blist();
- blist.m_bits[count] = *(m_bits+count);
- count++;
- }
- }
-
- // return the new bitset
- //
- return bitset;
+ // Allocate memory for the bitset structure itself
+ // the input parameter is the bit number (0 based)
+ // to include in the bitset, so we need at at least
+ // bit + 1 bits. If any arguments indicate a
+ // a bit higher than the default number of bits (0 means default size)
+ // then Add() will take care
+ // of it.
+ //
+ BitsetType* bitset = new BitsetType();
+
+ if (this != NULL)
+ {
+ // Now we can add the element bits into the set
+ //
+ ANTLR_UINT32 count=0;
+ while (count < m_length)
+ {
+ if( bitset->get_blist().get_length() <= count)
+ bitset->grow(count+1);
+
+ typename ImplTraits::BitsetListType& blist = bitset->get_blist();
+ blist.m_bits[count] = *(m_bits+count);
+ count++;
+ }
+ }
+
+ // return the new bitset
+ //
+ return bitset;
}
template <class ImplTraits>
typename BitsetList<ImplTraits>::BitsetType* BitsetList<ImplTraits>::bitsetCopy()
{
- BitsetType* bitset;
- ANTLR_UINT32 numElements = m_length;
+ BitsetType* bitset;
+ ANTLR_UINT32 numElements = m_length;
// Avoid memory thrashing at the expense of a few more bytes
//
- if (numElements < 8)
- numElements = 8;
+ if (numElements < 8)
+ numElements = 8;
// Allocate memory for the bitset structure itself
//
bitset = new Bitset<ImplTraits>(numElements);
- memcpy(bitset->get_blist().get_bits(), m_bits, numElements * sizeof(ANTLR_BITWORD));
+ memcpy(bitset->get_blist().get_bits(), m_bits, numElements * sizeof(ANTLR_BITWORD));
// All seems good
//
@@ -96,30 +96,30 @@ typename BitsetList<ImplTraits>::BitsetType* BitsetList<ImplTraits>::bitsetCopy(
template <class ImplTraits>
Bitset<ImplTraits>::Bitset( ANTLR_UINT32 numBits )
{
- // Avoid memory thrashing at the up front expense of a few bytes
- if (numBits < (8 * ANTLR_BITSET_BITS))
- numBits = 8 * ANTLR_BITSET_BITS;
+ // Avoid memory thrashing at the up front expense of a few bytes
+ if (numBits < (8 * ANTLR_BITSET_BITS))
+ numBits = 8 * ANTLR_BITSET_BITS;
- // No we need to allocate the memory for the number of bits asked for
- // in multiples of ANTLR3_UINT64.
- //
- ANTLR_UINT32 numelements = ((numBits -1) >> ANTLR_BITSET_LOG_BITS) + 1;
+ // No we need to allocate the memory for the number of bits asked for
+ // in multiples of ANTLR3_UINT64.
+ //
+ ANTLR_UINT32 numelements = ((numBits -1) >> ANTLR_BITSET_LOG_BITS) + 1;
- m_blist.set_bits( (ANTLR_BITWORD*) AllocPolicyType::alloc0(numelements * sizeof(ANTLR_BITWORD)));
+ m_blist.set_bits( (ANTLR_BITWORD*) AllocPolicyType::alloc0(numelements * sizeof(ANTLR_BITWORD)));
- m_blist.set_length( numelements );
+ m_blist.set_length( numelements );
}
template <class ImplTraits>
Bitset<ImplTraits>::Bitset( const Bitset& bitset )
- :m_blist(bitset.m_blist)
+ :m_blist(bitset.m_blist)
{
}
template <class ImplTraits>
ANTLR_INLINE Bitset<ImplTraits>* Bitset<ImplTraits>::clone() const
{
- Bitset* bitset;
+ Bitset* bitset;
// Allocate memory for the bitset structure itself
//
@@ -127,8 +127,8 @@ ANTLR_INLINE Bitset<ImplTraits>* Bitset<ImplTraits>::clone() const
// Install the actual bits in the source set
//
- memcpy(bitset->m_blist.get_bits(), m_blist.get_bits(),
- m_blist.get_length() * sizeof(ANTLR_BITWORD) );
+ memcpy(bitset->m_blist.get_bits(), m_blist.get_bits(),
+ m_blist.get_length() * sizeof(ANTLR_BITWORD) );
// All seems good
//
@@ -138,13 +138,13 @@ ANTLR_INLINE Bitset<ImplTraits>* Bitset<ImplTraits>::clone() const
template <class ImplTraits>
Bitset<ImplTraits>* Bitset<ImplTraits>::bor(Bitset* bitset2)
{
- Bitset* bitset;
+ Bitset* bitset;
- if (this == NULL)
- return bitset2->clone();
+ if (this == NULL)
+ return bitset2->clone();
- if (bitset2 == NULL)
- return this->clone();
+ if (bitset2 == NULL)
+ return this->clone();
// Allocate memory for the newly ordered bitset structure itself.
//
@@ -154,30 +154,30 @@ Bitset<ImplTraits>* Bitset<ImplTraits>::bor(Bitset* bitset2)
}
template <class ImplTraits>
-void Bitset<ImplTraits>::borInPlace(Bitset* bitset2)
+void Bitset<ImplTraits>::borInPlace(Bitset* bitset2)
{
- ANTLR_UINT32 minimum;
+ ANTLR_UINT32 minimum;
- if (bitset2 == NULL)
- return;
+ if (bitset2 == NULL)
+ return;
- // First make sure that the target bitset is big enough
+ // First make sure that the target bitset is big enough
// for the new bits to be ored in.
//
- if ( m_blist.get_length() < bitset2->m_blist.get_length() )
- this->growToInclude( bitset2->m_blist.get_length() * sizeof(ANTLR_BITWORD) );
-
+ if ( m_blist.get_length() < bitset2->m_blist.get_length() )
+ this->growToInclude( bitset2->m_blist.get_length() * sizeof(ANTLR_BITWORD) );
+
// Or the miniimum number of bits after any resizing went on
//
- if ( m_blist.get_length() < bitset2->m_blist.get_length() )
- minimum = m_blist.get_length();
- else
- minimum = bitset2->m_blist.get_length();
+ if ( m_blist.get_length() < bitset2->m_blist.get_length() )
+ minimum = m_blist.get_length();
+ else
+ minimum = bitset2->m_blist.get_length();
- ANTLR_BITWORD* bits1 = m_blist.get_bits();
- ANTLR_BITWORD* bits2 = bitset2->m_blist.get_bits();
- for (ANTLR_UINT32 i = minimum; i > 0; i--)
- bits1[i-1] |= bits2[i-1];
+ ANTLR_BITWORD* bits1 = m_blist.get_bits();
+ ANTLR_BITWORD* bits2 = bitset2->m_blist.get_bits();
+ for (ANTLR_UINT32 i = minimum; i > 0; i--)
+ bits1[i-1] |= bits2[i-1];
}
template <class ImplTraits>
@@ -186,60 +186,60 @@ ANTLR_UINT32 Bitset<ImplTraits>::size() const
ANTLR_UINT32 degree;
ANTLR_INT32 i;
ANTLR_INT8 bit;
-
+
// TODO: Come back to this, it may be faster to & with 0x01
// then shift right a copy of the 4 bits, than shift left a constant of 1.
// But then again, the optimizer might just work this out
// anyway.
//
degree = 0;
- ANTLR_BITWORD* bits = m_blist.get_bits();
- for (i = m_blist.get_length() - 1; i>= 0; i--)
+ ANTLR_BITWORD* bits = m_blist.get_bits();
+ for (i = m_blist.get_length() - 1; i>= 0; i--)
{
- if (bits[i] != 0)
- {
- for(bit = ANTLR_BITSET_BITS - 1; bit >= 0; bit--)
- {
- if((bits[i] & (((ANTLR_BITWORD)1) << bit)) != 0)
- {
- degree++;
- }
- }
- }
+ if (bits[i] != 0)
+ {
+ for(bit = ANTLR_BITSET_BITS - 1; bit >= 0; bit--)
+ {
+ if((bits[i] & (((ANTLR_BITWORD)1) << bit)) != 0)
+ {
+ degree++;
+ }
+ }
+ }
}
return degree;
}
template <class ImplTraits>
-ANTLR_INLINE void Bitset<ImplTraits>::add(ANTLR_INT32 bit)
+ANTLR_INLINE void Bitset<ImplTraits>::add(ANTLR_INT32 bit)
{
- ANTLR_UINT32 word = Bitset::WordNumber(bit);
+ ANTLR_UINT32 word = Bitset::WordNumber(bit);
- if (word >= m_blist.get_length() )
- this->growToInclude(bit);
-
- ANTLR_BITWORD* bits = m_blist.get_bits();
- bits[word] |= Bitset::BitMask(bit);
+ if (word >= m_blist.get_length() )
+ this->growToInclude(bit);
+
+ ANTLR_BITWORD* bits = m_blist.get_bits();
+ bits[word] |= Bitset::BitMask(bit);
}
template <class ImplTraits>
-void Bitset<ImplTraits>::grow(ANTLR_INT32 newSize)
+void Bitset<ImplTraits>::grow(ANTLR_INT32 newSize)
{
- ANTLR_BITWORD* newBits;
+ ANTLR_BITWORD* newBits;
// Space for newly sized bitset - TODO: come back to this and use realloc?, it may
// be more efficient...
//
newBits = (ANTLR_BITWORD*) AllocPolicyType::alloc0(newSize * sizeof(ANTLR_BITWORD) );
- if ( m_blist.get_bits() != NULL)
+ if ( m_blist.get_bits() != NULL)
{
- // Copy existing bits
- //
- memcpy( newBits, m_blist.get_bits(), m_blist.get_length() * sizeof(ANTLR_BITWORD) );
+ // Copy existing bits
+ //
+ memcpy( newBits, m_blist.get_bits(), m_blist.get_length() * sizeof(ANTLR_BITWORD) );
- // Out with the old bits... de de de derrr
- //
- AllocPolicyType::free( m_blist.get_bits() );
+ // Out with the old bits... de de de derrr
+ //
+ AllocPolicyType::free( m_blist.get_bits() );
}
// In with the new bits... keerrrang.
@@ -249,81 +249,81 @@ void Bitset<ImplTraits>::grow(ANTLR_INT32 newSize)
}
template <class ImplTraits>
-bool Bitset<ImplTraits>::equals(Bitset* bitset2) const
+bool Bitset<ImplTraits>::equals(Bitset* bitset2) const
{
ANTLR_UINT32 minimum;
ANTLR_UINT32 i;
- if (this == NULL || bitset2 == NULL)
- return false;
+ if (this == NULL || bitset2 == NULL)
+ return false;
// Work out the minimum comparison set
//
- if ( m_blist.get_length() < bitset2->m_blist.get_length() )
- minimum = m_blist.get_length();
+ if ( m_blist.get_length() < bitset2->m_blist.get_length() )
+ minimum = m_blist.get_length();
else
- minimum = bitset2->m_blist.get_length();
+ minimum = bitset2->m_blist.get_length();
// Make sure explict in common bits are equal
//
- for (i = minimum - 1; i < minimum ; i--)
+ for (i = minimum - 1; i < minimum ; i--)
{
- ANTLR_BITWORD* bits1 = m_blist.get_bits();
- ANTLR_BITWORD* bits2 = bitset2->m_blist.get_bits();
- if ( bits1[i] != bits2[i])
- return false;
+ ANTLR_BITWORD* bits1 = m_blist.get_bits();
+ ANTLR_BITWORD* bits2 = bitset2->m_blist.get_bits();
+ if ( bits1[i] != bits2[i])
+ return false;
}
// Now make sure the bits of the larger set are all turned
// off.
//
- if ( m_blist.get_length() > minimum)
+ if ( m_blist.get_length() > minimum)
{
- for (i = minimum ; i < m_blist.get_length(); i++)
- {
- ANTLR_BITWORD* bits = m_blist.get_bits();
- if(bits[i] != 0)
- return false;
- }
+ for (i = minimum ; i < m_blist.get_length(); i++)
+ {
+ ANTLR_BITWORD* bits = m_blist.get_bits();
+ if(bits[i] != 0)
+ return false;
+ }
}
else if (bitset2->m_blist.get_length() > minimum)
{
- ANTLR_BITWORD* bits = m_blist.get_bits();
- for (i = minimum; i < bitset2->m_blist.get_length(); i++)
- {
- if ( bits[i] != 0 )
- return false;
- }
+ ANTLR_BITWORD* bits = m_blist.get_bits();
+ for (i = minimum; i < bitset2->m_blist.get_length(); i++)
+ {
+ if ( bits[i] != 0 )
+ return false;
+ }
}
return true;
}
template <class ImplTraits>
-bool Bitset<ImplTraits>::isMember(ANTLR_UINT32 bit) const
+bool Bitset<ImplTraits>::isMember(ANTLR_UINT32 bit) const
{
ANTLR_UINT32 wordNo = Bitset::WordNumber(bit);
- if (wordNo >= m_blist.get_length())
- return false;
-
- ANTLR_BITWORD* bits = m_blist.get_bits();
- if ( (bits[wordNo] & Bitset::BitMask(bit)) == 0)
- return false;
+ if (wordNo >= m_blist.get_length())
+ return false;
+
+ ANTLR_BITWORD* bits = m_blist.get_bits();
+ if ( (bits[wordNo] & Bitset::BitMask(bit)) == 0)
+ return false;
else
- return true;
+ return true;
}
template <class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 Bitset<ImplTraits>::numBits() const
{
- return m_blist.get_length() << ANTLR_BITSET_LOG_BITS;
+ return m_blist.get_length() << ANTLR_BITSET_LOG_BITS;
}
template <class ImplTraits>
ANTLR_INLINE typename ImplTraits::BitsetListType& Bitset<ImplTraits>::get_blist()
{
- return m_blist;
+ return m_blist;
}
template <class ImplTraits>
@@ -331,31 +331,31 @@ ANTLR_INLINE void Bitset<ImplTraits>::remove(ANTLR_UINT32 bit)
{
ANTLR_UINT32 wordNo = Bitset::WordNumber(bit);
- if (wordNo < m_blist.get_length())
- {
- ANTLR_BITWORD* bits = m_blist.get_bits();
- bits[wordNo] &= ~(Bitset::BitMask(bit));
- }
+ if (wordNo < m_blist.get_length())
+ {
+ ANTLR_BITWORD* bits = m_blist.get_bits();
+ bits[wordNo] &= ~(Bitset::BitMask(bit));
+ }
}
template <class ImplTraits>
ANTLR_INLINE bool Bitset<ImplTraits>::isNilNode() const
{
- ANTLR_UINT32 i;
- ANTLR_BITWORD* bits = m_blist.get_bits();
- for (i = m_blist.get_length() -1 ; i < m_blist.get_length(); i--)
- {
- if(bits[i] != 0)
- return false;
- }
- return true;
+ ANTLR_UINT32 i;
+ ANTLR_BITWORD* bits = m_blist.get_bits();
+ for (i = m_blist.get_length() -1 ; i < m_blist.get_length(); i--)
+ {
+ if(bits[i] != 0)
+ return false;
+ }
+ return true;
}
template <class ImplTraits>
ANTLR_INT32* Bitset<ImplTraits>::toIntList() const
{
- ANTLR_UINT32 numInts; // How many integers we will need
- ANTLR_UINT32 numBits; // How many bits are in the set
+ ANTLR_UINT32 numInts; // How many integers we will need
+ ANTLR_UINT32 numBits; // How many bits are in the set
ANTLR_UINT32 i;
ANTLR_UINT32 index;
@@ -363,17 +363,17 @@ ANTLR_INT32* Bitset<ImplTraits>::toIntList() const
numInts = this->size() + 1;
numBits = this->numBits();
-
+
intList = (ANTLR_INT32*) AllocPolicyType::alloc(numInts * sizeof(ANTLR_INT32));
-
+
intList[0] = numInts;
// Enumerate the bits that are turned on
//
- for (i = 0, index = 1; i<numBits; i++)
+ for (i = 0, index = 1; i<numBits; i++)
{
- if (this->isMember(i) == true)
- intList[index++] = i;
+ if (this->isMember(i) == true)
+ intList[index++] = i;
}
// Result set
@@ -384,109 +384,109 @@ ANTLR_INT32* Bitset<ImplTraits>::toIntList() const
template <class ImplTraits>
ANTLR_INLINE Bitset<ImplTraits>::~Bitset()
{
- if (m_blist.get_bits() != NULL)
- AllocPolicyType::free(m_blist.get_bits());
+ if (m_blist.get_bits() != NULL)
+ AllocPolicyType::free(m_blist.get_bits());
return;
}
template <class ImplTraits>
-void Bitset<ImplTraits>::growToInclude(ANTLR_INT32 bit)
+void Bitset<ImplTraits>::growToInclude(ANTLR_INT32 bit)
{
- ANTLR_UINT32 bl;
- ANTLR_UINT32 nw;
+ ANTLR_UINT32 bl;
+ ANTLR_UINT32 nw;
- bl = (m_blist.get_length() << 1);
- nw = Bitset::NumWordsToHold(bit);
+ bl = (m_blist.get_length() << 1);
+ nw = Bitset::NumWordsToHold(bit);
- if (bl > nw)
- this->grow(bl);
- else
- this->grow(nw);
+ if (bl > nw)
+ this->grow(bl);
+ else
+ this->grow(nw);
}
template <class ImplTraits>
-ANTLR_INLINE ANTLR_UINT64 Bitset<ImplTraits>::BitMask(ANTLR_UINT32 bitNumber)
+ANTLR_INLINE ANTLR_UINT64 Bitset<ImplTraits>::BitMask(ANTLR_UINT32 bitNumber)
{
- return ((ANTLR_UINT64)1) << (bitNumber & (ANTLR_BITSET_MOD_MASK));
+ return ((ANTLR_UINT64)1) << (bitNumber & (ANTLR_BITSET_MOD_MASK));
}
template <class ImplTraits>
-ANTLR_INLINE ANTLR_UINT32 Bitset<ImplTraits>::NumWordsToHold(ANTLR_UINT32 bit)
+ANTLR_INLINE ANTLR_UINT32 Bitset<ImplTraits>::NumWordsToHold(ANTLR_UINT32 bit)
{
- return (bit >> ANTLR_BITSET_LOG_BITS) + 1;
+ return (bit >> ANTLR_BITSET_LOG_BITS) + 1;
}
template <class ImplTraits>
-ANTLR_INLINE ANTLR_UINT32 Bitset<ImplTraits>::WordNumber(ANTLR_UINT32 bit)
+ANTLR_INLINE ANTLR_UINT32 Bitset<ImplTraits>::WordNumber(ANTLR_UINT32 bit)
{
- return bit >> ANTLR_BITSET_LOG_BITS;
+ return bit >> ANTLR_BITSET_LOG_BITS;
}
template <class ImplTraits>
void Bitset<ImplTraits>::bitsetORInPlace(Bitset* bitset2)
{
- ANTLR_UINT32 minimum;
+ ANTLR_UINT32 minimum;
ANTLR_UINT32 i;
- if (bitset2 == NULL)
- return;
+ if (bitset2 == NULL)
+ return;
// First make sure that the target bitset is big enough
// for the new bits to be ored in.
//
- if ( m_blist.get_length() < bitset2->m_blist.get_length() )
- this->growToInclude( bitset2->m_blist.get_length() * sizeof(ANTLR_BITWORD) );
-
+ if ( m_blist.get_length() < bitset2->m_blist.get_length() )
+ this->growToInclude( bitset2->m_blist.get_length() * sizeof(ANTLR_BITWORD) );
+
// Or the miniimum number of bits after any resizing went on
//
- if ( m_blist.get_length() < bitset2->m_blist.get_length() )
- minimum = m_blist.get_length();
- else
- minimum = bitset2->m_blist.get_length();
+ if ( m_blist.get_length() < bitset2->m_blist.get_length() )
+ minimum = m_blist.get_length();
+ else
+ minimum = bitset2->m_blist.get_length();
- ANTLR_BITWORD* bits1 = m_blist.get_bits();
- ANTLR_BITWORD* bits2 = bitset2->m_blist.get_bits();
- for (i = minimum; i > 0; i--)
- bits1[i-1] |= bits2[i-1];
+ ANTLR_BITWORD* bits1 = m_blist.get_bits();
+ ANTLR_BITWORD* bits2 = bitset2->m_blist.get_bits();
+ for (i = minimum; i > 0; i--)
+ bits1[i-1] |= bits2[i-1];
}
template <class ImplTraits>
Bitset<ImplTraits>* Bitset<ImplTraits>::BitsetOf(ANTLR_INT32 bit)
{
- // Allocate memory for the bitset structure itself
+ // Allocate memory for the bitset structure itself
// the input parameter is the bit number (0 based)
// to include in the bitset, so we need at at least
- // bit + 1 bits. If any arguments indicate a
+ // bit + 1 bits. If any arguments indicate a
// a bit higher than the default number of bits (0 menas default size)
// then Add() will take care
// of it.
//
- Bitset<ImplTraits>* bitset = new Bitset<ImplTraits>(0);
- bitset->add(bit);
- return bitset;
+ Bitset<ImplTraits>* bitset = new Bitset<ImplTraits>(0);
+ bitset->add(bit);
+ return bitset;
}
template <class ImplTraits>
Bitset<ImplTraits>* Bitset<ImplTraits>::BitsetOf(ANTLR_INT32 bit1, ANTLR_INT32 bit2)
{
- Bitset<ImplTraits>* bitset = Bitset<ImplTraits>::BitsetOf(bit1);
- bitset->add(bit2);
- return bitset;
+ Bitset<ImplTraits>* bitset = Bitset<ImplTraits>::BitsetOf(bit1);
+ bitset->add(bit2);
+ return bitset;
}
-//static
+//static
template <class ImplTraits>
Bitset<ImplTraits>* Bitset<ImplTraits>::BitsetFromList(const IntListType& list)
{
- // We have no idea what exactly is in the list
+ // We have no idea what exactly is in the list
// so create a default bitset and then just add stuff
// as we enumerate.
//
Bitset<ImplTraits>* bitset = new Bitset<ImplTraits>(0);
- for( int i = 0; i < list.size(); ++i )
- bitset->add( list[i] );
+ for( int i = 0; i < list.size(); ++i )
+ bitset->add( list[i] );
- return bitset;
+ return bitset;
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3collections.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3collections.hpp
index 310bf2144a..7551c243d0 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3collections.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3collections.hpp
@@ -1,5 +1,5 @@
-#ifndef ANTLR3COLLECTIONS_HPP
-#define ANTLR3COLLECTIONS_HPP
+#ifndef ANTLR3COLLECTIONS_HPP
+#define ANTLR3COLLECTIONS_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -29,7 +29,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
/* -------------- TRIE Interfaces ---------------- */
@@ -39,18 +39,18 @@ template< class ImplTraits, class DataType >
class TrieEntry : public ImplTraits::AllocPolicyType
{
public:
- typedef typename ImplTraits::AllocPolicyType AllocPolicy;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicy;
private:
- DataType m_data;
- TrieEntry* m_next; /* Allows duplicate entries for same key in insertion order */
+ DataType m_data;
+ TrieEntry* m_next; /* Allows duplicate entries for same key in insertion order */
public:
- TrieEntry(const DataType& data, TrieEntry* next);
- DataType& get_data();
- const DataType& get_data() const;
- TrieEntry* get_next() const;
- void set_next( TrieEntry* next );
+ TrieEntry(const DataType& data, TrieEntry* next);
+ DataType& get_data();
+ const DataType& get_data() const;
+ TrieEntry* get_next() const;
+ void set_next( TrieEntry* next );
};
/** Structure that defines an element/node in an ANTLR_INT_TRIE
@@ -59,32 +59,32 @@ template< class ImplTraits, class DataType >
class IntTrieNode : public ImplTraits::AllocPolicyType
{
public:
- typedef TrieEntry<ImplTraits, DataType> TrieEntryType;
- typedef TrieEntryType BucketsType;
-
+ typedef TrieEntry<ImplTraits, DataType> TrieEntryType;
+ typedef TrieEntryType BucketsType;
+
private:
- ANTLR_UINT32 m_bitNum; /**< This is the left/right bit index for traversal along the nodes */
- ANTLR_INTKEY m_key; /**< This is the actual key that the entry represents if it is a terminal node */
- BucketsType* m_buckets; /**< This is the data bucket(s) that the key indexes, which may be NULL */
- IntTrieNode* m_leftN; /**< Pointer to the left node from here when sKey & bitNum = 0 */
- IntTrieNode* m_rightN; /**< Pointer to the right node from here when sKey & bitNum, = 1 */
+ ANTLR_UINT32 m_bitNum; /**< This is the left/right bit index for traversal along the nodes */
+ ANTLR_INTKEY m_key; /**< This is the actual key that the entry represents if it is a terminal node */
+ BucketsType* m_buckets; /**< This is the data bucket(s) that the key indexes, which may be NULL */
+ IntTrieNode* m_leftN; /**< Pointer to the left node from here when sKey & bitNum = 0 */
+ IntTrieNode* m_rightN; /**< Pointer to the right node from here when sKey & bitNum, = 1 */
public:
- IntTrieNode();
- ~IntTrieNode();
+ IntTrieNode();
+ ~IntTrieNode();
- ANTLR_UINT32 get_bitNum() const;
- ANTLR_INTKEY get_key() const;
- BucketsType* get_buckets() const;
- IntTrieNode* get_leftN() const;
- IntTrieNode* get_rightN() const;
- void set_bitNum( ANTLR_UINT32 bitNum );
- void set_key( ANTLR_INTKEY key );
- void set_buckets( BucketsType* buckets );
- void set_leftN( IntTrieNode* leftN );
- void set_rightN( IntTrieNode* rightN );
+ ANTLR_UINT32 get_bitNum() const;
+ ANTLR_INTKEY get_key() const;
+ BucketsType* get_buckets() const;
+ IntTrieNode* get_leftN() const;
+ IntTrieNode* get_rightN() const;
+ void set_bitNum( ANTLR_UINT32 bitNum );
+ void set_key( ANTLR_INTKEY key );
+ void set_buckets( BucketsType* buckets );
+ void set_leftN( IntTrieNode* leftN );
+ void set_rightN( IntTrieNode* rightN );
};
-
+
/** Structure that defines an ANTLR3_INT_TRIE. For this particular implementation,
* as you might expect, the key is turned into a "string" by looking at bit(key, depth)
* of the integer key. Using 64 bit keys gives us a depth limit of 64 (or bit 0..63)
@@ -94,57 +94,57 @@ public:
*
* If you find this code useful, please feel free to 'steal' it for any purpose
* as covered by the BSD license under which ANTLR is issued. You can cut the code
- * but as the ANTLR library is only about 50K (Windows Vista), you might find it
+ * but as the ANTLR library is only about 50K (Windows Vista), you might find it
* easier to just link the library. Please keep all comments and licenses and so on
* in any version of this you create of course.
*
* Jim Idle.
- *
+ *
*/
class IntTrieBase
{
public:
- static const ANTLR_UINT8* get_bitIndex();
- static const ANTLR_UINT64* get_bitMask();
+ static const ANTLR_UINT8* get_bitIndex();
+ static const ANTLR_UINT64* get_bitMask();
};
-
+
template< class ImplTraits, class DataType >
class IntTrie : public ImplTraits::AllocPolicyType, public IntTrieBase
{
public:
- typedef TrieEntry<ImplTraits, DataType> TrieEntryType;
- typedef IntTrieNode<ImplTraits, DataType> IntTrieNodeType;
-
+ typedef TrieEntry<ImplTraits, DataType> TrieEntryType;
+ typedef IntTrieNode<ImplTraits, DataType> IntTrieNodeType;
+
private:
- IntTrieNodeType* m_root; /* Root node of this integer trie */
- IntTrieNodeType* m_current; /* Used to traverse the TRIE with the next() method */
- ANTLR_UINT32 m_count; /* Current entry count */
- bool m_allowDups; /* Whether this trie accepts duplicate keys */
+ IntTrieNodeType* m_root; /* Root node of this integer trie */
+ IntTrieNodeType* m_current; /* Used to traverse the TRIE with the next() method */
+ ANTLR_UINT32 m_count; /* Current entry count */
+ bool m_allowDups; /* Whether this trie accepts duplicate keys */
public:
- /* INT TRIE Implementation of depth 64 bits, being the number of bits
- * in a 64 bit integer.
- */
+ /* INT TRIE Implementation of depth 64 bits, being the number of bits
+ * in a 64 bit integer.
+ */
IntTrie( ANTLR_UINT32 depth );
- /** Search the int Trie and return a pointer to the first bucket indexed
- * by the key if it is contained in the trie, otherwise NULL.
- */
- TrieEntryType* get( ANTLR_INTKEY key);
- bool del( ANTLR_INTKEY key);
+ /** Search the int Trie and return a pointer to the first bucket indexed
+ * by the key if it is contained in the trie, otherwise NULL.
+ */
+ TrieEntryType* get( ANTLR_INTKEY key);
+ bool del( ANTLR_INTKEY key);
- /** Add an entry into the INT trie.
- * Basically we descend the trie as we do when searching it, which will
- * locate the only node in the trie that can be reached by the bit pattern of the
- * key. If the key is actually at that node, then if the trie accepts duplicates
- * we add the supplied data in a new chained bucket to that data node. If it does
- * not accept duplicates then we merely return FALSE in case the caller wants to know
- * whether the key was already in the trie.
- * If the node we locate is not the key we are looking to add, then we insert a new node
- * into the trie with a bit index of the leftmost differing bit and the left or right
- * node pointing to itself or the data node we are inserting 'before'.
- */
- bool add( ANTLR_INTKEY key, const DataType& data );
+ /** Add an entry into the INT trie.
+ * Basically we descend the trie as we do when searching it, which will
+ * locate the only node in the trie that can be reached by the bit pattern of the
+ * key. If the key is actually at that node, then if the trie accepts duplicates
+ * we add the supplied data in a new chained bucket to that data node. If it does
+ * not accept duplicates then we merely return FALSE in case the caller wants to know
+ * whether the key was already in the trie.
+ * If the node we locate is not the key we are looking to add, then we insert a new node
+ * into the trie with a bit index of the leftmost differing bit and the left or right
+ * node pointing to itself or the data node we are inserting 'before'.
+ */
+ bool add( ANTLR_INTKEY key, const DataType& data );
~IntTrie();
};
@@ -167,8 +167,8 @@ template<class ImplTraits>
class Topo : public ImplTraits::AllocPolicyType
{
public:
- typedef typename ImplTraits::BitsetType BitsetType;
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::BitsetType BitsetType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
private:
/**
@@ -177,14 +177,14 @@ private:
* contains a bitset, which has a bit index set for each node upon which the
* entry node depends.
*/
- BitsetType** m_edges;
+ BitsetType** m_edges;
/**
* A vector used to build up the sorted output order. Note that
* as the vector contains UINT32 then the maximum node index is
* 'limited' to 2^32, as nodes should be zero based.
*/
- ANTLR_UINT32* m_sorted;
+ ANTLR_UINT32* m_sorted;
/**
* A vector used to detect cycles in the edge dependecies. It is used
@@ -195,7 +195,7 @@ private:
* descnding from it as we remove it from the stack as we exit from
* descending its dependencies
*/
- ANTLR_UINT32* m_cycle;
+ ANTLR_UINT32* m_cycle;
/**
* A flag that indicates the algorithm found a cycle in the edges
@@ -204,7 +204,7 @@ private:
* then the detected cycle will be contained in the cycle array and
* cycleLimit will point to the one after the last entry in the cycle.
*/
- bool m_hasCycle;
+ bool m_hasCycle;
/**
* A watermark used to accumulate potential cycles in the cycle array.
@@ -212,21 +212,21 @@ private:
* of the sort methods and if it is true then you can find the cycle
* in cycle[0]...cycle[cycleMark-1]
*/
- ANTLR_UINT32 m_cycleMark;
-
+ ANTLR_UINT32 m_cycleMark;
+
/**
* One more than the largest node index that is contained in edges/sorted.
*/
- ANTLR_UINT32 m_limit;
+ ANTLR_UINT32 m_limit;
/**
* The set of visited nodes as determined by a set entry in
* the bitmap.
*/
- BitsetType* m_visited;
+ BitsetType* m_visited;
public:
- Topo();
+ Topo();
/**
* A method that adds an edge from one node to another. An edge
* of n -> m indicates that node n is dependent on node m. Note that
@@ -259,25 +259,25 @@ public:
*/
ANTLR_UINT32* sortToArray();
- /**
+ /**
* A method that sorts the supplied ANTLR3_VECTOR in place based
* on the previously supplied edge data.
*/
- template<typename DataType>
+ template<typename DataType>
void sortVector( typename ImplTraits::template VectorType<DataType>& v);
- void DFS(ANTLR_UINT32 node);
+ void DFS(ANTLR_UINT32 node);
/**
* A method to free this structure and any associated memory.
*/
- ~Topo();
+ ~Topo();
};
-}
+}
#include "antlr3collections.inl"
-
+
#endif
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3collections.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3collections.inl
index 502cb23e85..3a2d06c9c3 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3collections.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3collections.inl
@@ -1,165 +1,165 @@
-namespace antlr3 {
+namespace antlr3 {
template< class ImplTraits, class DataType >
ANTLR_INLINE TrieEntry<ImplTraits, DataType>::TrieEntry(const DataType& data, TrieEntry* next)
- :m_data(data)
+ :m_data(data)
{
- m_next = next;
+ m_next = next;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE DataType& TrieEntry<ImplTraits, DataType>::get_data()
{
- return m_data;
+ return m_data;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE const DataType& TrieEntry<ImplTraits, DataType>::get_data() const
{
- return m_data;
+ return m_data;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE TrieEntry<ImplTraits, DataType>* TrieEntry<ImplTraits, DataType>::get_next() const
{
- return m_next;
+ return m_next;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE void TrieEntry<ImplTraits, DataType>::set_next( TrieEntry* next )
{
- m_next = next;
+ m_next = next;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE ANTLR_UINT32 IntTrieNode<ImplTraits, DataType>::get_bitNum() const
{
- return m_bitNum;
+ return m_bitNum;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE ANTLR_INTKEY IntTrieNode<ImplTraits, DataType>::get_key() const
{
- return m_key;
+ return m_key;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE typename IntTrieNode<ImplTraits, DataType>::BucketsType* IntTrieNode<ImplTraits, DataType>::get_buckets() const
{
- return m_buckets;
+ return m_buckets;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE IntTrieNode<ImplTraits, DataType>* IntTrieNode<ImplTraits, DataType>::get_leftN() const
{
- return m_leftN;
+ return m_leftN;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE IntTrieNode<ImplTraits, DataType>* IntTrieNode<ImplTraits, DataType>::get_rightN() const
{
- return m_rightN;
+ return m_rightN;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE void IntTrieNode<ImplTraits, DataType>::set_bitNum( ANTLR_UINT32 bitNum )
{
- m_bitNum = bitNum;
+ m_bitNum = bitNum;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE void IntTrieNode<ImplTraits, DataType>::set_key( ANTLR_INTKEY key )
{
- m_key = key;
+ m_key = key;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE void IntTrieNode<ImplTraits, DataType>::set_buckets( BucketsType* buckets )
{
- m_buckets = buckets;
+ m_buckets = buckets;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE void IntTrieNode<ImplTraits, DataType>::set_leftN( IntTrieNode* leftN )
{
- m_leftN = leftN;
+ m_leftN = leftN;
}
template< class ImplTraits, class DataType >
ANTLR_INLINE void IntTrieNode<ImplTraits, DataType>::set_rightN( IntTrieNode* rightN )
{
- m_rightN = rightN;
+ m_rightN = rightN;
}
ANTLR_INLINE const ANTLR_UINT8* IntTrieBase::get_bitIndex()
{
- static ANTLR_UINT8 bitIndex[256] =
- {
- 0, // 0 - Just for padding
- 0, // 1
- 1, 1, // 2..3
- 2, 2, 2, 2, // 4..7
- 3, 3, 3, 3, 3, 3, 3, 3, // 8+
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 16+
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, // 32+
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, // 64+
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ static ANTLR_UINT8 bitIndex[256] =
+ {
+ 0, // 0 - Just for padding
+ 0, // 1
+ 1, 1, // 2..3
+ 2, 2, 2, 2, // 4..7
+ 3, 3, 3, 3, 3, 3, 3, 3, // 8+
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 16+
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, // 32+
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, // 64+
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 128+
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 128+
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
- };
- return bitIndex;
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
+ };
+ return bitIndex;
}
ANTLR_INLINE const ANTLR_UINT64* IntTrieBase::get_bitMask()
{
- static ANTLR_UINT64 bitMask[64] =
- {
- 0x0000000000000001ULL, 0x0000000000000002ULL, 0x0000000000000004ULL, 0x0000000000000008ULL,
- 0x0000000000000010ULL, 0x0000000000000020ULL, 0x0000000000000040ULL, 0x0000000000000080ULL,
- 0x0000000000000100ULL, 0x0000000000000200ULL, 0x0000000000000400ULL, 0x0000000000000800ULL,
- 0x0000000000001000ULL, 0x0000000000002000ULL, 0x0000000000004000ULL, 0x0000000000008000ULL,
- 0x0000000000010000ULL, 0x0000000000020000ULL, 0x0000000000040000ULL, 0x0000000000080000ULL,
- 0x0000000000100000ULL, 0x0000000000200000ULL, 0x0000000000400000ULL, 0x0000000000800000ULL,
- 0x0000000001000000ULL, 0x0000000002000000ULL, 0x0000000004000000ULL, 0x0000000008000000ULL,
- 0x0000000010000000ULL, 0x0000000020000000ULL, 0x0000000040000000ULL, 0x0000000080000000ULL,
- 0x0000000100000000ULL, 0x0000000200000000ULL, 0x0000000400000000ULL, 0x0000000800000000ULL,
- 0x0000001000000000ULL, 0x0000002000000000ULL, 0x0000004000000000ULL, 0x0000008000000000ULL,
- 0x0000010000000000ULL, 0x0000020000000000ULL, 0x0000040000000000ULL, 0x0000080000000000ULL,
- 0x0000100000000000ULL, 0x0000200000000000ULL, 0x0000400000000000ULL, 0x0000800000000000ULL,
- 0x0001000000000000ULL, 0x0002000000000000ULL, 0x0004000000000000ULL, 0x0008000000000000ULL,
- 0x0010000000000000ULL, 0x0020000000000000ULL, 0x0040000000000000ULL, 0x0080000000000000ULL,
- 0x0100000000000000ULL, 0x0200000000000000ULL, 0x0400000000000000ULL, 0x0800000000000000ULL,
- 0x1000000000000000ULL, 0x2000000000000000ULL, 0x4000000000000000ULL, 0x8000000000000000ULL
- };
-
- return bitMask;
+ static ANTLR_UINT64 bitMask[64] =
+ {
+ 0x0000000000000001ULL, 0x0000000000000002ULL, 0x0000000000000004ULL, 0x0000000000000008ULL,
+ 0x0000000000000010ULL, 0x0000000000000020ULL, 0x0000000000000040ULL, 0x0000000000000080ULL,
+ 0x0000000000000100ULL, 0x0000000000000200ULL, 0x0000000000000400ULL, 0x0000000000000800ULL,
+ 0x0000000000001000ULL, 0x0000000000002000ULL, 0x0000000000004000ULL, 0x0000000000008000ULL,
+ 0x0000000000010000ULL, 0x0000000000020000ULL, 0x0000000000040000ULL, 0x0000000000080000ULL,
+ 0x0000000000100000ULL, 0x0000000000200000ULL, 0x0000000000400000ULL, 0x0000000000800000ULL,
+ 0x0000000001000000ULL, 0x0000000002000000ULL, 0x0000000004000000ULL, 0x0000000008000000ULL,
+ 0x0000000010000000ULL, 0x0000000020000000ULL, 0x0000000040000000ULL, 0x0000000080000000ULL,
+ 0x0000000100000000ULL, 0x0000000200000000ULL, 0x0000000400000000ULL, 0x0000000800000000ULL,
+ 0x0000001000000000ULL, 0x0000002000000000ULL, 0x0000004000000000ULL, 0x0000008000000000ULL,
+ 0x0000010000000000ULL, 0x0000020000000000ULL, 0x0000040000000000ULL, 0x0000080000000000ULL,
+ 0x0000100000000000ULL, 0x0000200000000000ULL, 0x0000400000000000ULL, 0x0000800000000000ULL,
+ 0x0001000000000000ULL, 0x0002000000000000ULL, 0x0004000000000000ULL, 0x0008000000000000ULL,
+ 0x0010000000000000ULL, 0x0020000000000000ULL, 0x0040000000000000ULL, 0x0080000000000000ULL,
+ 0x0100000000000000ULL, 0x0200000000000000ULL, 0x0400000000000000ULL, 0x0800000000000000ULL,
+ 0x1000000000000000ULL, 0x2000000000000000ULL, 0x4000000000000000ULL, 0x8000000000000000ULL
+ };
+
+ return bitMask;
}
template< class ImplTraits, class DataType >
IntTrie<ImplTraits, DataType>::IntTrie( ANTLR_UINT32 depth )
{
- /* Now we need to allocate the root node. This makes it easier
- * to use the tree as we don't have to do anything special
- * for the root node.
- */
- m_root = new IntTrieNodeType;
-
- /* Now we seed the root node with the index being the
- * highest left most bit we want to test, which limits the
- * keys in the trie. This is the trie 'depth'. The limit for
- * this implementation is 63 (bits 0..63).
- */
- m_root->set_bitNum( depth );
-
- /* And as we have nothing in here yet, we set both child pointers
- * of the root node to point back to itself.
- */
- m_root->set_leftN( m_root );
- m_root->set_rightN( m_root );
- m_count = 0;
-
- /* Finally, note that the key for this root node is 0 because
- * we use calloc() to initialise it.
- */
- m_allowDups = false;
- m_current = NULL;
+ /* Now we need to allocate the root node. This makes it easier
+ * to use the tree as we don't have to do anything special
+ * for the root node.
+ */
+ m_root = new IntTrieNodeType;
+
+ /* Now we seed the root node with the index being the
+ * highest left most bit we want to test, which limits the
+ * keys in the trie. This is the trie 'depth'. The limit for
+ * this implementation is 63 (bits 0..63).
+ */
+ m_root->set_bitNum( depth );
+
+ /* And as we have nothing in here yet, we set both child pointers
+ * of the root node to point back to itself.
+ */
+ m_root->set_leftN( m_root );
+ m_root->set_rightN( m_root );
+ m_count = 0;
+
+ /* Finally, note that the key for this root node is 0 because
+ * we use calloc() to initialise it.
+ */
+ m_allowDups = false;
+ m_current = NULL;
}
template< class ImplTraits, class DataType >
@@ -175,228 +175,228 @@ IntTrie<ImplTraits, DataType>::~IntTrie()
}
template< class ImplTraits, class DataType >
-typename IntTrie<ImplTraits, DataType>::TrieEntryType* IntTrie<ImplTraits, DataType>::get( ANTLR_INTKEY key)
+typename IntTrie<ImplTraits, DataType>::TrieEntryType* IntTrie<ImplTraits, DataType>::get( ANTLR_INTKEY key)
{
- IntTrieNodeType* thisNode;
- IntTrieNodeType* nextNode;
-
- if (m_count == 0)
- return NULL; /* Nothing in this trie yet */
-
- /* Starting at the root node in the trie, compare the bit index
- * of the current node with its next child node (starts left from root).
- * When the bit index of the child node is greater than the bit index of the current node
- * then by definition (as the bit index decreases as we descent the trie)
- * we have reached a 'backward' pointer. A backward pointer means we
- * have reached the only node that can be reached by the bits given us so far
- * and it must either be the key we are looking for, or if not then it
- * means the entry was not in the trie, and we return NULL. A backward pointer
- * points back in to the tree structure rather than down (deeper) within the
- * tree branches.
- */
- thisNode = m_root; /* Start at the root node */
- nextNode = thisNode->get_leftN(); /* Examine the left node from the root */
-
- /* While we are descending the tree nodes...
- */
- const ANTLR_UINT64* bitMask = this->get_bitMask();
- while( thisNode->get_bitNum() > nextNode->get_bitNum() )
- {
- /* Next node now becomes the new 'current' node
- */
- thisNode = nextNode;
-
- /* We now test the bit indicated by the bitmap in the next node
- * in the key we are searching for. The new next node is the
- * right node if that bit is set and the left node it is not.
- */
- if (key & bitMask[nextNode->get_bitNum()])
- {
- nextNode = nextNode->get_rightN(); /* 1 is right */
- }
- else
- {
- nextNode = nextNode->get_leftN(); /* 0 is left */
- }
- }
-
- /* Here we have reached a node where the bitMap index is lower than
- * its parent. This means it is pointing backward in the tree and
- * must therefore be a terminal node, being the only point than can
- * be reached with the bits seen so far. It is either the actual key
- * we wanted, or if that key is not in the trie it is another key
- * that is currently the only one that can be reached by those bits.
- * That situation would obviously change if the key was to be added
- * to the trie.
- *
- * Hence it only remains to test whether this is actually the key or not.
- */
- if (nextNode->get_key() == key)
- {
- /* This was the key, so return the entry pointer
- */
- return nextNode->get_buckets();
- }
- else
- {
- return NULL; /* That key is not in the trie (note that we set the pointer to -1 if no payload) */
- }
+ IntTrieNodeType* thisNode;
+ IntTrieNodeType* nextNode;
+
+ if (m_count == 0)
+ return NULL; /* Nothing in this trie yet */
+
+ /* Starting at the root node in the trie, compare the bit index
+ * of the current node with its next child node (starts left from root).
+ * When the bit index of the child node is greater than the bit index of the current node
+ * then by definition (as the bit index decreases as we descent the trie)
+ * we have reached a 'backward' pointer. A backward pointer means we
+ * have reached the only node that can be reached by the bits given us so far
+ * and it must either be the key we are looking for, or if not then it
+ * means the entry was not in the trie, and we return NULL. A backward pointer
+ * points back in to the tree structure rather than down (deeper) within the
+ * tree branches.
+ */
+ thisNode = m_root; /* Start at the root node */
+ nextNode = thisNode->get_leftN(); /* Examine the left node from the root */
+
+ /* While we are descending the tree nodes...
+ */
+ const ANTLR_UINT64* bitMask = this->get_bitMask();
+ while( thisNode->get_bitNum() > nextNode->get_bitNum() )
+ {
+ /* Next node now becomes the new 'current' node
+ */
+ thisNode = nextNode;
+
+ /* We now test the bit indicated by the bitmap in the next node
+ * in the key we are searching for. The new next node is the
+ * right node if that bit is set and the left node it is not.
+ */
+ if (key & bitMask[nextNode->get_bitNum()])
+ {
+ nextNode = nextNode->get_rightN(); /* 1 is right */
+ }
+ else
+ {
+ nextNode = nextNode->get_leftN(); /* 0 is left */
+ }
+ }
+
+ /* Here we have reached a node where the bitMap index is lower than
+ * its parent. This means it is pointing backward in the tree and
+ * must therefore be a terminal node, being the only point than can
+ * be reached with the bits seen so far. It is either the actual key
+ * we wanted, or if that key is not in the trie it is another key
+ * that is currently the only one that can be reached by those bits.
+ * That situation would obviously change if the key was to be added
+ * to the trie.
+ *
+ * Hence it only remains to test whether this is actually the key or not.
+ */
+ if (nextNode->get_key() == key)
+ {
+ /* This was the key, so return the entry pointer
+ */
+ return nextNode->get_buckets();
+ }
+ else
+ {
+ return NULL; /* That key is not in the trie (note that we set the pointer to -1 if no payload) */
+ }
}
template< class ImplTraits, class DataType >
-bool IntTrie<ImplTraits, DataType>::del( ANTLR_INTKEY /*key*/)
+bool IntTrie<ImplTraits, DataType>::del( ANTLR_INTKEY /*key*/)
{
IntTrieNodeType* p;
p = m_root;
-
+
return false;
}
template< class ImplTraits, class DataType >
-bool IntTrie<ImplTraits, DataType>::add( ANTLR_INTKEY key, const DataType& data )
+bool IntTrie<ImplTraits, DataType>::add( ANTLR_INTKEY key, const DataType& data )
{
- IntTrieNodeType* thisNode;
- IntTrieNodeType* nextNode;
- IntTrieNodeType* entNode;
- ANTLR_UINT32 depth;
- TrieEntryType* newEnt;
- TrieEntryType* nextEnt;
- ANTLR_INTKEY xorKey;
-
- /* Cache the bit depth of this trie, which is always the highest index,
- * which is in the root node
- */
- depth = m_root->get_bitNum();
-
- thisNode = m_root; /* Start with the root node */
- nextNode = m_root->get_leftN(); /* And assume we start to the left */
-
- /* Now find the only node that can be currently reached by the bits in the
- * key we are being asked to insert.
- */
- const ANTLR_UINT64* bitMask = this->get_bitMask();
- while (thisNode->get_bitNum() > nextNode->get_bitNum() )
- {
- /* Still descending the structure, next node becomes current.
- */
- thisNode = nextNode;
-
- if (key & bitMask[nextNode->get_bitNum()])
- {
- /* Bit at the required index was 1, so travers the right node from here
- */
- nextNode = nextNode->get_rightN();
- }
- else
- {
- /* Bit at the required index was 0, so we traverse to the left
- */
- nextNode = nextNode->get_leftN();
- }
- }
- /* Here we have located the only node that can be reached by the
- * bits in the requested key. It could in fact be that key or the node
- * we need to use to insert the new key.
- */
- if (nextNode->get_key() == key)
- {
- /* We have located an exact match, but we will only append to the bucket chain
- * if this trie accepts duplicate keys.
- */
- if (m_allowDups ==true)
- {
- /* Yes, we are accepting duplicates
- */
- newEnt = new TrieEntryType(data, NULL);
-
- /* We want to be able to traverse the stored elements in the order that they were
- * added as duplicate keys. We might need to revise this opinion if we end up having many duplicate keys
- * as perhaps reverse order is just as good, so long as it is ordered.
- */
- nextEnt = nextNode->get_buckets();
- while (nextEnt->get_next() != NULL)
- {
- nextEnt = nextEnt->get_next();
- }
- nextEnt->set_next(newEnt);
-
- m_count++;
- return true;
- }
- else
- {
- /* We found the key is already there and we are not allowed duplicates in this
- * trie.
- */
- return false;
- }
- }
-
- /* Here we have discovered the only node that can be reached by the bits in the key
- * but we have found that this node is not the key we need to insert. We must find the
- * the leftmost bit by which the current key for that node and the new key we are going
- * to insert, differ. While this nested series of ifs may look a bit strange, experimentation
- * showed that it allows a machine code path that works well with predicated execution
- */
- xorKey = (key ^ nextNode->get_key() ); /* Gives 1 bits only where they differ then we find the left most 1 bit*/
-
- /* Most common case is a 32 bit key really
- */
- const ANTLR_UINT8* bitIndex = this->get_bitIndex();
-#ifdef ANTLR_USE_64BIT
- if (xorKey & 0xFFFFFFFF00000000)
- {
- if (xorKey & 0xFFFF000000000000)
- {
- if (xorKey & 0xFF00000000000000)
- {
- depth = 56 + bitIndex[((xorKey & 0xFF00000000000000)>>56)];
- }
- else
- {
- depth = 48 + bitIndex[((xorKey & 0x00FF000000000000)>>48)];
- }
- }
- else
- {
- if (xorKey & 0x0000FF0000000000)
- {
- depth = 40 + bitIndex[((xorKey & 0x0000FF0000000000)>>40)];
- }
- else
- {
- depth = 32 + bitIndex[((xorKey & 0x000000FF00000000)>>32)];
- }
- }
- }
- else
+ IntTrieNodeType* thisNode;
+ IntTrieNodeType* nextNode;
+ IntTrieNodeType* entNode;
+ ANTLR_UINT32 depth;
+ TrieEntryType* newEnt;
+ TrieEntryType* nextEnt;
+ ANTLR_INTKEY xorKey;
+
+ /* Cache the bit depth of this trie, which is always the highest index,
+ * which is in the root node
+ */
+ depth = m_root->get_bitNum();
+
+ thisNode = m_root; /* Start with the root node */
+ nextNode = m_root->get_leftN(); /* And assume we start to the left */
+
+ /* Now find the only node that can be currently reached by the bits in the
+ * key we are being asked to insert.
+ */
+ const ANTLR_UINT64* bitMask = this->get_bitMask();
+ while (thisNode->get_bitNum() > nextNode->get_bitNum() )
+ {
+ /* Still descending the structure, next node becomes current.
+ */
+ thisNode = nextNode;
+
+ if (key & bitMask[nextNode->get_bitNum()])
+ {
+ /* Bit at the required index was 1, so travers the right node from here
+ */
+ nextNode = nextNode->get_rightN();
+ }
+ else
+ {
+ /* Bit at the required index was 0, so we traverse to the left
+ */
+ nextNode = nextNode->get_leftN();
+ }
+ }
+ /* Here we have located the only node that can be reached by the
+ * bits in the requested key. It could in fact be that key or the node
+ * we need to use to insert the new key.
+ */
+ if (nextNode->get_key() == key)
+ {
+ /* We have located an exact match, but we will only append to the bucket chain
+ * if this trie accepts duplicate keys.
+ */
+ if (m_allowDups ==true)
+ {
+ /* Yes, we are accepting duplicates
+ */
+ newEnt = new TrieEntryType(data, NULL);
+
+ /* We want to be able to traverse the stored elements in the order that they were
+ * added as duplicate keys. We might need to revise this opinion if we end up having many duplicate keys
+ * as perhaps reverse order is just as good, so long as it is ordered.
+ */
+ nextEnt = nextNode->get_buckets();
+ while (nextEnt->get_next() != NULL)
+ {
+ nextEnt = nextEnt->get_next();
+ }
+ nextEnt->set_next(newEnt);
+
+ m_count++;
+ return true;
+ }
+ else
+ {
+ /* We found the key is already there and we are not allowed duplicates in this
+ * trie.
+ */
+ return false;
+ }
+ }
+
+ /* Here we have discovered the only node that can be reached by the bits in the key
+ * but we have found that this node is not the key we need to insert. We must find the
+ * the leftmost bit by which the current key for that node and the new key we are going
+ * to insert, differ. While this nested series of ifs may look a bit strange, experimentation
+ * showed that it allows a machine code path that works well with predicated execution
+ */
+ xorKey = (key ^ nextNode->get_key() ); /* Gives 1 bits only where they differ then we find the left most 1 bit*/
+
+ /* Most common case is a 32 bit key really
+ */
+ const ANTLR_UINT8* bitIndex = this->get_bitIndex();
+#ifdef ANTLR_USE_64BIT
+ if (xorKey & 0xFFFFFFFF00000000)
+ {
+ if (xorKey & 0xFFFF000000000000)
+ {
+ if (xorKey & 0xFF00000000000000)
+ {
+ depth = 56 + bitIndex[((xorKey & 0xFF00000000000000)>>56)];
+ }
+ else
+ {
+ depth = 48 + bitIndex[((xorKey & 0x00FF000000000000)>>48)];
+ }
+ }
+ else
+ {
+ if (xorKey & 0x0000FF0000000000)
+ {
+ depth = 40 + bitIndex[((xorKey & 0x0000FF0000000000)>>40)];
+ }
+ else
+ {
+ depth = 32 + bitIndex[((xorKey & 0x000000FF00000000)>>32)];
+ }
+ }
+ }
+ else
#endif
- {
- if (xorKey & 0x00000000FFFF0000)
- {
- if (xorKey & 0x00000000FF000000)
- {
- depth = 24 + bitIndex[((xorKey & 0x00000000FF000000)>>24)];
- }
- else
- {
- depth = 16 + bitIndex[((xorKey & 0x0000000000FF0000)>>16)];
- }
- }
- else
- {
- if (xorKey & 0x000000000000FF00)
- {
- depth = 8 + bitIndex[((xorKey & 0x0000000000000FF00)>>8)];
- }
- else
- {
- depth = bitIndex[xorKey & 0x00000000000000FF];
- }
- }
- }
+ {
+ if (xorKey & 0x00000000FFFF0000)
+ {
+ if (xorKey & 0x00000000FF000000)
+ {
+ depth = 24 + bitIndex[((xorKey & 0x00000000FF000000)>>24)];
+ }
+ else
+ {
+ depth = 16 + bitIndex[((xorKey & 0x0000000000FF0000)>>16)];
+ }
+ }
+ else
+ {
+ if (xorKey & 0x000000000000FF00)
+ {
+ depth = 8 + bitIndex[((xorKey & 0x0000000000000FF00)>>8)];
+ }
+ else
+ {
+ depth = bitIndex[xorKey & 0x00000000000000FF];
+ }
+ }
+ }
/* We have located the leftmost differing bit, indicated by the depth variable. So, we know what
* bit index we are to insert the new entry at. There are two cases, being where the two keys
@@ -409,41 +409,41 @@ bool IntTrie<ImplTraits, DataType>::add( ANTLR_INTKEY key, const DataType& data
* So, set up to descend the tree again, but this time looking for the insert point
* according to whether we skip the bit that differs or not.
*/
- thisNode = m_root;
- entNode = m_root->get_leftN();
+ thisNode = m_root;
+ entNode = m_root->get_leftN();
/* Note the slight difference in the checks here to cover both cases
*/
while (thisNode->get_bitNum() > entNode->get_bitNum() && entNode->get_bitNum() > depth)
{
- /* Still descending the structure, next node becomes current.
- */
- thisNode = entNode;
-
- if (key & bitMask[entNode->get_bitNum()])
- {
- /* Bit at the required index was 1, so traverse the right node from here
- */
- entNode = entNode->get_rightN();
- }
- else
- {
- /* Bit at the required index was 0, so we traverse to the left
- */
- entNode = entNode->get_leftN();
- }
+ /* Still descending the structure, next node becomes current.
+ */
+ thisNode = entNode;
+
+ if (key & bitMask[entNode->get_bitNum()])
+ {
+ /* Bit at the required index was 1, so traverse the right node from here
+ */
+ entNode = entNode->get_rightN();
+ }
+ else
+ {
+ /* Bit at the required index was 0, so we traverse to the left
+ */
+ entNode = entNode->get_leftN();
+ }
}
/* We have located the correct insert point for this new key, so we need
* to allocate our entry and insert it etc.
*/
- nextNode = new IntTrieNodeType();
+ nextNode = new IntTrieNodeType();
/* Build a new entry block for the new node
*/
newEnt = new TrieEntryType(data, NULL);
- /* Install it
+ /* Install it
*/
nextNode->set_buckets(newEnt);
nextNode->set_key(key);
@@ -455,27 +455,27 @@ bool IntTrie<ImplTraits, DataType>::add( ANTLR_INTKEY key, const DataType& data
*/
if (key & bitMask[depth])
{
- nextNode->set_leftN(entNode); /* Terminates at previous position */
- nextNode->set_rightN(nextNode); /* Terminates with itself */
+ nextNode->set_leftN(entNode); /* Terminates at previous position */
+ nextNode->set_rightN(nextNode); /* Terminates with itself */
}
else
{
- nextNode->set_rightN(entNode); /* Terminates at previous position */
- nextNode->set_leftN(nextNode); /* Terminates with itself */
+ nextNode->set_rightN(entNode); /* Terminates at previous position */
+ nextNode->set_leftN(nextNode); /* Terminates with itself */
}
/* Finally, we need to change the pointers at the node we located
* for inserting. If the key bit at its index is set then the right
- * pointer for that node becomes the newly created node, otherwise the left
+ * pointer for that node becomes the newly created node, otherwise the left
* pointer does.
*/
if (key & bitMask[thisNode->get_bitNum()] )
{
- thisNode->set_rightN( nextNode );
+ thisNode->set_rightN( nextNode );
}
else
{
- thisNode->set_leftN(nextNode);
+ thisNode->set_leftN(nextNode);
}
/* Et voila
@@ -487,52 +487,52 @@ bool IntTrie<ImplTraits, DataType>::add( ANTLR_INTKEY key, const DataType& data
template< class ImplTraits, class DataType >
IntTrieNode<ImplTraits, DataType>::IntTrieNode()
{
- m_bitNum = 0;
- m_key = 0;
- m_buckets = NULL;
- m_leftN = NULL;
- m_rightN = NULL;
+ m_bitNum = 0;
+ m_key = 0;
+ m_buckets = NULL;
+ m_leftN = NULL;
+ m_rightN = NULL;
}
template< class ImplTraits, class DataType >
IntTrieNode<ImplTraits, DataType>::~IntTrieNode()
{
- TrieEntryType* thisEntry;
- TrieEntryType* nextEntry;
+ TrieEntryType* thisEntry;
+ TrieEntryType* nextEntry;
/* If this node has a left pointer that is not a back pointer
* then recursively call to free this
*/
if ( m_bitNum > m_leftN->get_bitNum())
{
- /* We have a left node that needs descending, so do it.
- */
- delete m_leftN;
+ /* We have a left node that needs descending, so do it.
+ */
+ delete m_leftN;
}
- /* The left nodes from here should now be dealt with, so
+ /* The left nodes from here should now be dealt with, so
* we need to descend any right nodes that are not back pointers
*/
if ( m_bitNum > m_rightN->get_bitNum() )
{
- /* There are some right nodes to descend and deal with.
- */
- delete m_rightN;
+ /* There are some right nodes to descend and deal with.
+ */
+ delete m_rightN;
}
/* Now all the children are dealt with, we can destroy
* this node too
*/
- thisEntry = m_buckets;
+ thisEntry = m_buckets;
while (thisEntry != NULL)
{
- nextEntry = thisEntry->get_next();
+ nextEntry = thisEntry->get_next();
- /* Now free the data for this bucket entry
- */
- delete thisEntry;
- thisEntry = nextEntry; /* See if there are any more to free */
+ /* Now free the data for this bucket entry
+ */
+ delete thisEntry;
+ thisEntry = nextEntry; /* See if there are any more to free */
}
/* The bucket entry is now gone, so we can free the memory for
@@ -583,7 +583,7 @@ Topo<ImplTraits>::Topo()
template<class ImplTraits>
void Topo<ImplTraits>::addEdge(ANTLR_UINT32 edge, ANTLR_UINT32 dependency)
{
- ANTLR_UINT32 i;
+ ANTLR_UINT32 i;
ANTLR_UINT32 maxEdge;
BitsetType* edgeDeps;
@@ -670,7 +670,7 @@ void Topo<ImplTraits>::addEdge(ANTLR_UINT32 edge, ANTLR_UINT32 dependency)
template<class ImplTraits>
void Topo<ImplTraits>::DFS(ANTLR_UINT32 node)
{
- BitsetType* edges;
+ BitsetType* edges;
// Guard against a revisit and check for cycles
//
@@ -734,7 +734,7 @@ void Topo<ImplTraits>::DFS(ANTLR_UINT32 node)
// We have some edges, so visit each of the edge nodes
// that have not already been visited.
//
- ANTLR_UINT32 numBits; // How many bits are in the set
+ ANTLR_UINT32 numBits; // How many bits are in the set
ANTLR_UINT32 i;
ANTLR_UINT32 range;
@@ -778,7 +778,7 @@ void Topo<ImplTraits>::DFS(ANTLR_UINT32 node)
template<class ImplTraits>
ANTLR_UINT32* Topo<ImplTraits>::sortToArray()
{
- ANTLR_UINT32 v;
+ ANTLR_UINT32 v;
ANTLR_UINT32 oldLimit;
// Guard against being called with no edges defined
@@ -844,7 +844,7 @@ ANTLR_UINT32* Topo<ImplTraits>::sortToArray()
}
template<class ImplTraits>
- template<typename DataType>
+ template<typename DataType>
void Topo<ImplTraits>::sortVector( typename ImplTraits::template VectorType<DataType>& v )
{
// To sort a vector, we first perform the
@@ -928,7 +928,7 @@ void Topo<ImplTraits>::sortVector( typename ImplTraits::template VectorType<D
// find where it is now and move it from there to i.
//
ind = vIndex[m_sorted[i]];
- std::swap( v[i], v[ind] );
+ std::swap( v[i], v[ind] );
// Update our index. The element at i is now the one we wanted
// to be sorted here and the element we swapped out is now the
@@ -961,7 +961,7 @@ Topo<ImplTraits>::~Topo()
//
if (m_visited != NULL)
{
- delete m_visited;
+ delete m_visited;
}
// Free any edgemaps
@@ -975,14 +975,14 @@ Topo<ImplTraits>::~Topo()
edgeList = *((m_edges) + i);
if (edgeList != NULL)
{
- delete edgeList;
+ delete edgeList;
}
}
AllocPolicyType::free( m_edges );
}
m_edges = NULL;
-
+
// Free any cycle map
//
if (m_cycle != NULL)
@@ -992,4 +992,4 @@ Topo<ImplTraits>::~Topo()
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontoken.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontoken.hpp
index 1e7d4e0ef4..51fa3954ab 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontoken.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontoken.hpp
@@ -8,8 +8,8 @@
* of the interface functions, but all of them may be rplaced by your own
* implementation if you require it.
*/
-#ifndef _ANTLR3_COMMON_TOKEN_HPP
-#define _ANTLR3_COMMON_TOKEN_HPP
+#ifndef _ANTLR3_COMMON_TOKEN_HPP
+#define _ANTLR3_COMMON_TOKEN_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -39,7 +39,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
/** The definition of an ANTLR3 common token structure, which all implementations
* of a token stream should provide, installing any further structures in the
@@ -54,62 +54,62 @@ template<class ImplTraits>
class CommonToken : public ImplTraits::AllocPolicyType
{
public:
- /* Base token types, which all lexer/parser tokens come after in sequence.
- */
- enum TOKEN_TYPE : ANTLR_UINT32
- {
- /** Indicator of an invalid token
- */
- TOKEN_INVALID = 0
- , EOR_TOKEN_TYPE
- /** Imaginary token type to cause a traversal of child nodes in a tree parser
- */
- , TOKEN_DOWN
- /** Imaginary token type to signal the end of a stream of child nodes.
- */
- , TOKEN_UP
- /** First token that can be used by users/generated code
- */
- , MIN_TOKEN_TYPE = TOKEN_UP + 1
-
- /** End of file token
- */
-#ifndef _MSC_VER
- , TOKEN_EOF = std::numeric_limits<ANTLR_UINT32>::max()
-#else
- , TOKEN_EOF = 0xFFFFFFFF
-#endif
- };
-
- typedef typename ImplTraits::TokenIntStreamType TokenIntStreamType;
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::InputStreamType InputStreamType;
- typedef typename ImplTraits::StreamDataType StreamDataType;
- typedef typename ImplTraits::TokenUserDataType UserDataType;
+ /* Base token types, which all lexer/parser tokens come after in sequence.
+ */
+ enum TOKEN_TYPE : ANTLR_UINT32
+ {
+ /** Indicator of an invalid token
+ */
+ TOKEN_INVALID = 0
+ , EOR_TOKEN_TYPE
+ /** Imaginary token type to cause a traversal of child nodes in a tree parser
+ */
+ , TOKEN_DOWN
+ /** Imaginary token type to signal the end of a stream of child nodes.
+ */
+ , TOKEN_UP
+ /** First token that can be used by users/generated code
+ */
+ , MIN_TOKEN_TYPE = TOKEN_UP + 1
+
+ /** End of file token
+ */
+#ifndef _MSC_VER
+ , TOKEN_EOF = std::numeric_limits<ANTLR_UINT32>::max()
+#else
+ , TOKEN_EOF = 0xFFFFFFFF
+#endif
+ };
+
+ typedef typename ImplTraits::TokenIntStreamType TokenIntStreamType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::InputStreamType InputStreamType;
+ typedef typename ImplTraits::StreamDataType StreamDataType;
+ typedef typename ImplTraits::TokenUserDataType UserDataType;
private:
/** The actual type of this token
*/
ANTLR_UINT32 m_type;
- /** The virtual channel that this token exists in.
+ /** The virtual channel that this token exists in.
*/
- ANTLR_UINT32 m_channel;
-
- mutable StringType m_tokText;
+ ANTLR_UINT32 m_channel;
+
+ mutable StringType m_tokText;
/** The offset into the input stream that the line in which this
* token resides starts.
*/
- const StreamDataType* m_lineStart;
+ const StreamDataType* m_lineStart;
- /** The line number in the input stream where this token was derived from
+ /** The line number in the input stream where this token was derived from
*/
- ANTLR_UINT32 m_line;
+ ANTLR_UINT32 m_line;
/** The character position in the line that this token was derived from
*/
- ANTLR_INT32 m_charPositionInLine;
+ ANTLR_INT32 m_charPositionInLine;
/** Pointer to the input stream that this token originated in.
*/
@@ -117,44 +117,44 @@ private:
/** What the index of this token is, 0, 1, .., n-2, n-1 tokens
*/
- ANTLR_MARKER m_index;
+ ANTLR_MARKER m_index;
/** The character offset in the input stream where the text for this token
* starts.
*/
- ANTLR_MARKER m_startIndex;
+ ANTLR_MARKER m_startIndex;
/** The character offset in the input stream where the text for this token
* stops.
*/
- ANTLR_MARKER m_stopIndex;
+ ANTLR_MARKER m_stopIndex;
public:
- CommonToken();
- CommonToken(ANTLR_UINT32 type);
- CommonToken(TOKEN_TYPE type);
- CommonToken( const CommonToken& ctoken );
-
- ~CommonToken() {}
-
- CommonToken& operator=( const CommonToken& ctoken );
- bool operator==( const CommonToken& ctoken ) const;
- bool operator<( const CommonToken& ctoken ) const;
-
- InputStreamType* get_input() const;
- ANTLR_MARKER get_index() const;
- void set_index( ANTLR_MARKER index );
- void set_input( InputStreamType* input );
-
+ CommonToken();
+ CommonToken(ANTLR_UINT32 type);
+ CommonToken(TOKEN_TYPE type);
+ CommonToken( const CommonToken& ctoken );
+
+ ~CommonToken() {}
+
+ CommonToken& operator=( const CommonToken& ctoken );
+ bool operator==( const CommonToken& ctoken ) const;
+ bool operator<( const CommonToken& ctoken ) const;
+
+ InputStreamType* get_input() const;
+ ANTLR_MARKER get_index() const;
+ void set_index( ANTLR_MARKER index );
+ void set_input( InputStreamType* input );
+
/* ==============================
- * API
+ * API
*/
/** Function that returns the text pointer of a token, use
* toString() if you want a pANTLR3_STRING version of the token.
*/
- StringType const & getText() const;
-
+ StringType const & getText() const;
+
/** Pointer to a function that 'might' be able to set the text associated
* with a token. Imaginary tokens such as an ANTLR3_CLASSIC_TOKEN may actually
* do this, however many tokens such as ANTLR3_COMMON_TOKEN do not actaully have
@@ -171,17 +171,17 @@ public:
* tokens will implement this function with a function that errors out (probably
* drastically.
*/
- void setText(ANTLR_UINT8* text);
- void setText(const char* text);
+ void setText(ANTLR_UINT8* text);
+ void setText(const char* text);
/** Pointer to a function that returns the token type of this token
*/
ANTLR_UINT32 get_type() const;
- ANTLR_UINT32 getType() const;
+ ANTLR_UINT32 getType() const;
/** Pointer to a function that sets the type of this token
*/
- void set_type(ANTLR_UINT32 ttype);
+ void set_type(ANTLR_UINT32 ttype);
/** Pointer to a function that gets the 'line' number where this token resides
*/
@@ -192,13 +192,13 @@ public:
void set_line(ANTLR_UINT32 line);
/** Pointer to a function that gets the offset in the line where this token exists
- */
+ */
ANTLR_INT32 get_charPositionInLine() const;
- ANTLR_INT32 getCharPositionInLine() const;
+ ANTLR_INT32 getCharPositionInLine() const;
/** Pointer to a function that sets the offset in the line where this token exists
*/
- void set_charPositionInLine(ANTLR_INT32 pos);
+ void set_charPositionInLine(ANTLR_INT32 pos);
/** Pointer to a function that gets the channel that this token was placed in (parsers
* can 'tune' to these channels.
@@ -217,7 +217,7 @@ public:
/** Pointer to a function that can set the token index of this token in the token
* input stream.
*/
- void set_tokenIndex(ANTLR_MARKER tokenIndex);
+ void set_tokenIndex(ANTLR_MARKER tokenIndex);
/** Pointer to a function that gets the start index in the input stream for this token.
*/
@@ -225,29 +225,29 @@ public:
/** Pointer to a function that sets the start index in the input stream for this token.
*/
- void set_startIndex(ANTLR_MARKER index);
-
+ void set_startIndex(ANTLR_MARKER index);
+
/** Pointer to a function that gets the stop index in the input stream for this token.
*/
ANTLR_MARKER get_stopIndex() const;
/** Pointer to a function that sets the stop index in the input stream for this token.
*/
- void set_stopIndex(ANTLR_MARKER index);
- const StreamDataType* get_lineStart() const;
- void set_lineStart( const StreamDataType* lineStart );
+ void set_stopIndex(ANTLR_MARKER index);
+ const StreamDataType* get_lineStart() const;
+ void set_lineStart( const StreamDataType* lineStart );
- /** Pointer to a function that returns this token as a text representation that can be
+ /** Pointer to a function that returns this token as a text representation that can be
* printed with embedded control codes such as \n replaced with the printable sequence "\\n"
- * This also yields a string structure that can be used more easily than the pointer to
+ * This also yields a string structure that can be used more easily than the pointer to
* the input stream in certain situations.
*/
StringType toString() const;
- UserDataType UserData;
+ UserDataType UserData;
};
-}
+}
#include "antlr3commontoken.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontoken.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontoken.inl
index e86bf0aedf..3277b3def1 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontoken.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontoken.inl
@@ -1,284 +1,284 @@
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits>
CommonToken<ImplTraits>::CommonToken()
{
- m_type = 0;
+ m_type = 0;
m_channel = 0;
- m_lineStart = NULL;
- m_line = 0;
- m_charPositionInLine = 0;
- m_input = NULL;
- m_index = 0;
- m_startIndex = 0;
- m_stopIndex = 0;
+ m_lineStart = NULL;
+ m_line = 0;
+ m_charPositionInLine = 0;
+ m_input = NULL;
+ m_index = 0;
+ m_startIndex = 0;
+ m_stopIndex = 0;
}
template<class ImplTraits>
CommonToken<ImplTraits>::CommonToken(ANTLR_UINT32 type)
{
- m_type = type;
- m_channel = 0;
- m_lineStart = NULL;
- m_line = 0;
- m_charPositionInLine = 0;
- m_input = NULL;
- m_index = 0;
- m_startIndex = 0;
- m_stopIndex = 0;
+ m_type = type;
+ m_channel = 0;
+ m_lineStart = NULL;
+ m_line = 0;
+ m_charPositionInLine = 0;
+ m_input = NULL;
+ m_index = 0;
+ m_startIndex = 0;
+ m_stopIndex = 0;
}
template<class ImplTraits>
CommonToken<ImplTraits>::CommonToken(TOKEN_TYPE type)
{
- m_type = type;
- m_channel = 0;
- m_lineStart = NULL;
- m_line = 0;
- m_charPositionInLine = 0;
- m_input = NULL;
- m_index = 0;
- m_startIndex = 0;
- m_stopIndex = 0;
+ m_type = type;
+ m_channel = 0;
+ m_lineStart = NULL;
+ m_line = 0;
+ m_charPositionInLine = 0;
+ m_input = NULL;
+ m_index = 0;
+ m_startIndex = 0;
+ m_stopIndex = 0;
}
template<class ImplTraits>
CommonToken<ImplTraits>::CommonToken( const CommonToken& ctoken )
- :m_tokText( ctoken.m_tokText )
- ,UserData(ctoken.UserData)
+ :m_tokText( ctoken.m_tokText )
+ ,UserData(ctoken.UserData)
{
- m_type = ctoken.m_type;
- m_channel = ctoken.m_channel;
- m_lineStart = ctoken.m_lineStart;
- m_line = ctoken.m_line;
- m_charPositionInLine = ctoken.m_charPositionInLine;
- m_input = ctoken.m_input;
- m_index = ctoken.m_index;
- m_startIndex = ctoken.m_startIndex;
- m_stopIndex = ctoken.m_stopIndex;
+ m_type = ctoken.m_type;
+ m_channel = ctoken.m_channel;
+ m_lineStart = ctoken.m_lineStart;
+ m_line = ctoken.m_line;
+ m_charPositionInLine = ctoken.m_charPositionInLine;
+ m_input = ctoken.m_input;
+ m_index = ctoken.m_index;
+ m_startIndex = ctoken.m_startIndex;
+ m_stopIndex = ctoken.m_stopIndex;
}
template<class ImplTraits>
CommonToken<ImplTraits>& CommonToken<ImplTraits>::operator=( const CommonToken& ctoken )
{
- UserData = ctoken.UserData;
- m_type = ctoken.m_type;
- m_channel = ctoken.m_channel;
- m_lineStart = ctoken.m_lineStart;
- m_line = ctoken.m_line;
- m_charPositionInLine = ctoken.m_charPositionInLine;
- m_input = ctoken.m_input;
- m_index = ctoken.m_index;
- m_startIndex = ctoken.m_startIndex;
- m_stopIndex = ctoken.m_stopIndex;
+ UserData = ctoken.UserData;
+ m_type = ctoken.m_type;
+ m_channel = ctoken.m_channel;
+ m_lineStart = ctoken.m_lineStart;
+ m_line = ctoken.m_line;
+ m_charPositionInLine = ctoken.m_charPositionInLine;
+ m_input = ctoken.m_input;
+ m_index = ctoken.m_index;
+ m_startIndex = ctoken.m_startIndex;
+ m_stopIndex = ctoken.m_stopIndex;
- m_tokText = ctoken.m_tokText;
- return *this;
+ m_tokText = ctoken.m_tokText;
+ return *this;
}
template<class ImplTraits>
ANTLR_INLINE bool CommonToken<ImplTraits>::operator<( const CommonToken& ctoken ) const
{
- return (m_index < ctoken.m_index);
+ return (m_index < ctoken.m_index);
}
template<class ImplTraits>
bool CommonToken<ImplTraits>::operator==( const CommonToken& ctoken ) const
{
- return ( (m_type == ctoken.m_type) &&
- (m_channel == ctoken.m_channel) &&
- (m_lineStart == ctoken.m_lineStart) &&
- (m_line == ctoken.m_line) &&
- (m_charPositionInLine == ctoken.m_charPositionInLine) &&
- (m_input == ctoken.m_input) &&
- (m_index == ctoken.m_index) &&
- (m_startIndex == ctoken.m_startIndex) &&
- (m_stopIndex == ctoken.m_stopIndex) );
+ return ( (m_type == ctoken.m_type) &&
+ (m_channel == ctoken.m_channel) &&
+ (m_lineStart == ctoken.m_lineStart) &&
+ (m_line == ctoken.m_line) &&
+ (m_charPositionInLine == ctoken.m_charPositionInLine) &&
+ (m_input == ctoken.m_input) &&
+ (m_index == ctoken.m_index) &&
+ (m_startIndex == ctoken.m_startIndex) &&
+ (m_stopIndex == ctoken.m_stopIndex) );
}
template<class ImplTraits>
ANTLR_INLINE typename CommonToken<ImplTraits>::InputStreamType* CommonToken<ImplTraits>::get_input() const
{
- return m_input;
+ return m_input;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_MARKER CommonToken<ImplTraits>::get_index() const
{
- return m_index;
+ return m_index;
}
template<class ImplTraits>
ANTLR_INLINE void CommonToken<ImplTraits>::set_index( ANTLR_MARKER index )
{
- m_index = index;
+ m_index = index;
}
template<class ImplTraits>
void CommonToken<ImplTraits>::set_input( InputStreamType* input )
{
- m_input = input;
+ m_input = input;
}
template<class ImplTraits>
-typename CommonToken<ImplTraits>::StringType const &
-CommonToken<ImplTraits>::getText() const
+typename CommonToken<ImplTraits>::StringType const &
+CommonToken<ImplTraits>::getText() const
{
- static const StringType EOF_STRING("<EOF>");
- static const StringType EMPTY_STRING("");
+ static const StringType EOF_STRING("<EOF>");
+ static const StringType EMPTY_STRING("");
- if ( !m_tokText.empty() )
- return m_tokText;
+ if ( !m_tokText.empty() )
+ return m_tokText;
- // EOF is a special case
- //
- if ( m_type == TOKEN_EOF)
- {
- return EOF_STRING;
- }
+ // EOF is a special case
+ //
+ if ( m_type == TOKEN_EOF)
+ {
+ return EOF_STRING;
+ }
- // We had nothing installed in the token, create a new string
- // from the input stream
- //
- if ( m_input != NULL)
- {
- return m_tokText = m_input->substr( this->get_startIndex(), this->get_stopIndex() );
- }
- // Nothing to return, there is no input stream
- //
- return EMPTY_STRING;
+ // We had nothing installed in the token, create a new string
+ // from the input stream
+ //
+ if ( m_input != NULL)
+ {
+ return m_tokText = m_input->substr( this->get_startIndex(), this->get_stopIndex() );
+ }
+ // Nothing to return, there is no input stream
+ //
+ return EMPTY_STRING;
}
template<class ImplTraits>
ANTLR_INLINE void CommonToken<ImplTraits>::set_tokText( const StringType& text )
{
- m_tokText = text;
+ m_tokText = text;
}
template<class ImplTraits>
ANTLR_INLINE void CommonToken<ImplTraits>::setText(ANTLR_UINT8* text)
{
- if( text == NULL )
- m_tokText.clear();
- else
- m_tokText = (const char*) text;
+ if( text == NULL )
+ m_tokText.clear();
+ else
+ m_tokText = (const char*) text;
}
template<class ImplTraits>
-ANTLR_INLINE void CommonToken<ImplTraits>::setText(const char* text)
+ANTLR_INLINE void CommonToken<ImplTraits>::setText(const char* text)
{
- if( text == NULL )
- m_tokText.clear();
- else
- m_tokText = text;
+ if( text == NULL )
+ m_tokText.clear();
+ else
+ m_tokText = text;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 CommonToken<ImplTraits>::get_type() const
{
- return m_type;
+ return m_type;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 CommonToken<ImplTraits>::getType() const
{
- return m_type;
+ return m_type;
}
template<class ImplTraits>
-ANTLR_INLINE void CommonToken<ImplTraits>::set_type(ANTLR_UINT32 ttype)
+ANTLR_INLINE void CommonToken<ImplTraits>::set_type(ANTLR_UINT32 ttype)
{
- m_type = ttype;
+ m_type = ttype;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 CommonToken<ImplTraits>::get_line() const
{
- return m_line;
+ return m_line;
}
template<class ImplTraits>
ANTLR_INLINE void CommonToken<ImplTraits>::set_line(ANTLR_UINT32 line)
{
- m_line = line;
+ m_line = line;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_INT32 CommonToken<ImplTraits>::get_charPositionInLine() const
{
- return m_charPositionInLine;
+ return m_charPositionInLine;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_INT32 CommonToken<ImplTraits>::getCharPositionInLine() const
{
- return this->get_charPositionInLine();
+ return this->get_charPositionInLine();
}
template<class ImplTraits>
-ANTLR_INLINE void CommonToken<ImplTraits>::set_charPositionInLine(ANTLR_INT32 pos)
+ANTLR_INLINE void CommonToken<ImplTraits>::set_charPositionInLine(ANTLR_INT32 pos)
{
- m_charPositionInLine = pos;
+ m_charPositionInLine = pos;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 CommonToken<ImplTraits>::get_channel() const
{
- return m_channel;
+ return m_channel;
}
template<class ImplTraits>
ANTLR_INLINE void CommonToken<ImplTraits>::set_channel(ANTLR_UINT32 channel)
{
- m_channel = channel;
+ m_channel = channel;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_MARKER CommonToken<ImplTraits>::get_tokenIndex() const
{
- return m_index;
+ return m_index;
}
template<class ImplTraits>
-ANTLR_INLINE void CommonToken<ImplTraits>::set_tokenIndex(ANTLR_MARKER tokenIndex)
+ANTLR_INLINE void CommonToken<ImplTraits>::set_tokenIndex(ANTLR_MARKER tokenIndex)
{
- m_index = tokenIndex;
+ m_index = tokenIndex;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_MARKER CommonToken<ImplTraits>::get_startIndex() const
{
- return (m_startIndex == -1) ? (ANTLR_MARKER)(m_input->get_data()) : m_startIndex;
+ return (m_startIndex == -1) ? (ANTLR_MARKER)(m_input->get_data()) : m_startIndex;
}
template<class ImplTraits>
-ANTLR_INLINE void CommonToken<ImplTraits>::set_startIndex(ANTLR_MARKER index)
+ANTLR_INLINE void CommonToken<ImplTraits>::set_startIndex(ANTLR_MARKER index)
{
- m_startIndex = index;
+ m_startIndex = index;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_MARKER CommonToken<ImplTraits>::get_stopIndex() const
{
- return m_stopIndex;
+ return m_stopIndex;
}
template<class ImplTraits>
-ANTLR_INLINE void CommonToken<ImplTraits>::set_stopIndex(ANTLR_MARKER index)
+ANTLR_INLINE void CommonToken<ImplTraits>::set_stopIndex(ANTLR_MARKER index)
{
- m_stopIndex = index;
+ m_stopIndex = index;
}
template<class ImplTraits>
ANTLR_INLINE const typename CommonToken<ImplTraits>::StreamDataType* CommonToken<ImplTraits>::get_lineStart() const
{
- return m_lineStart;
+ return m_lineStart;
}
template<class ImplTraits>
-ANTLR_INLINE void CommonToken<ImplTraits>::set_lineStart( const StreamDataType* lineStart )
+ANTLR_INLINE void CommonToken<ImplTraits>::set_lineStart( const StreamDataType* lineStart )
{
- m_lineStart = lineStart;
+ m_lineStart = lineStart;
}
template<class ImplTraits>
@@ -286,12 +286,12 @@ typename CommonToken<ImplTraits>::StringType CommonToken<ImplTraits>::toString(
{
StringType text;
typedef typename ImplTraits::StringStreamType StringStreamType;
- StringStreamType outtext;
+ StringStreamType outtext;
- text = this->getText();
+ text = this->getText();
- if (text.empty())
- return "";
+ if (text.empty())
+ return "";
/* Now we use our handy dandy string utility to assemble the
* the reporting string
@@ -309,11 +309,11 @@ typename CommonToken<ImplTraits>::StringType CommonToken<ImplTraits>::toString(
outtext << (int)m_type;
outtext << "> ";
- if (this->get_channel() > TOKEN_DEFAULT_CHANNEL)
+ if (this->get_channel() > TOKEN_DEFAULT_CHANNEL)
{
- outtext << "(channel = ";
- outtext << (int)this->get_channel();
- outtext << ") ";
+ outtext << "(channel = ";
+ outtext << (int)this->get_channel();
+ outtext << ") ";
}
outtext << "Line: ";
@@ -325,4 +325,4 @@ typename CommonToken<ImplTraits>::StringType CommonToken<ImplTraits>::toString(
return outtext.str();
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontree.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontree.hpp
index 35d9ab69d4..2a5e61f94f 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontree.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontree.hpp
@@ -2,8 +2,8 @@
* passed around by the AST producing parser.
*/
-#ifndef _ANTLR3_COMMON_TREE_HPP
-#define _ANTLR3_COMMON_TREE_HPP
+#ifndef _ANTLR3_COMMON_TREE_HPP
+#define _ANTLR3_COMMON_TREE_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -33,117 +33,117 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits>
-class CommonTree : public ImplTraits::AllocPolicyType
+class CommonTree : public ImplTraits::AllocPolicyType
{
public:
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
- //typedef CommonTree TokenType;
- typedef typename AllocPolicyType::template VectorType<TreeTypePtr> ChildrenType;
- typedef typename AllocPolicyType::template ListType<TreeTypePtr> ChildListType;
- typedef typename ImplTraits::TreeUserDataType UserDataType;
-protected:
- /// The list of all the children that belong to this node. They are not part of the node
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+ //typedef CommonTree TokenType;
+ typedef typename AllocPolicyType::template VectorType<TreeTypePtr> ChildrenType;
+ typedef typename AllocPolicyType::template ListType<TreeTypePtr> ChildListType;
+ typedef typename ImplTraits::TreeUserDataType UserDataType;
+protected:
+ /// The list of all the children that belong to this node. They are not part of the node
/// as they belong to the common tree node that implements this.
///
- ChildrenType m_children;
+ ChildrenType m_children;
/// Start token index that encases this tree
///
- ANTLR_MARKER m_startIndex;
+ ANTLR_MARKER m_startIndex;
/// End token that encases this tree
///
- ANTLR_MARKER m_stopIndex;
+ ANTLR_MARKER m_stopIndex;
/// A single token, this is the payload for the tree
///
- const CommonTokenType* m_token;
+ const CommonTokenType* m_token;
- /// Points to the node that has this node as a child.
- /// If this is NULL, then this is the root node.
- ///
- CommonTree* m_parent;
+ /// Points to the node that has this node as a child.
+ /// If this is NULL, then this is the root node.
+ ///
+ CommonTree* m_parent;
- /// What index is this particular node in the child list it
- /// belongs to?
- ///
- ANTLR_INT32 m_childIndex;
+ /// What index is this particular node in the child list it
+ /// belongs to?
+ ///
+ ANTLR_INT32 m_childIndex;
public:
- CommonTree();
- CommonTree( const CommonTokenType* token );
- CommonTree( const CommonTree* token );
- CommonTree( const CommonTree& ctree );
- ~CommonTree();
-
- const CommonTokenType* get_token() const;
- void set_token(CommonTokenType const*);
-
- ChildrenType& get_children();
- const ChildrenType& get_children() const;
- ANTLR_INT32 get_childIndex() const;
- TreeType* get_parent() const;
-
- ANTLR_MARKER get_startIndex() const;
- void set_startIndex(ANTLR_MARKER index);
-
- ANTLR_MARKER get_stopIndex() const;
- void set_stopIndex(ANTLR_MARKER index);
-
- void set_parent( TreeType* parent);
- void set_childIndex( ANTLR_INT32 );
-
- void addChild(TreeTypePtr& child);
- /// Add all elements of the supplied list as children of this node
- ///
- void addChildren(const ChildListType& kids);
-
- TreeTypePtr deleteChild(ANTLR_UINT32 i);
- /// Delete children from start to stop and replace with t even if t is
- /// a list (nil-root tree). Num of children can increase or decrease.
- /// For huge child lists, inserting children can force walking rest of
- /// children to set their child index; could be slow.
- ///
- void replaceChildren(ANTLR_INT32 startChildIndex, ANTLR_INT32 stopChildIndex, TreeTypePtr t);
-
- // clone itself
- CommonTree* dupNode() const;
- // clone itself in pre-allocated storage
- CommonTree* dupNode(void *) const;
-
-
- ANTLR_UINT32 get_charPositionInLine() const;
- ANTLR_UINT32 get_line() const;
-
- TreeTypePtr& getChild(ANTLR_UINT32 i);
- ANTLR_UINT32 getChildCount() const;
- ANTLR_UINT32 getType();
- TreeTypePtr& getFirstChildWithType(ANTLR_UINT32 type);
-
- StringType getText();
- bool isNilNode();
- void setChild(ANTLR_UINT32 i, TreeTypePtr child);
- StringType toStringTree();
- StringType toString();
- void freshenParentAndChildIndexes();
- void freshenParentAndChildIndexes(ANTLR_UINT32 offset);
- void freshenParentAndChildIndexesDeeply();
- void freshenParentAndChildIndexesDeeply(ANTLR_UINT32 offset);
- // Prepare tree node to be re-used
- void reuse();
-
- UserDataType UserData;
+ CommonTree();
+ CommonTree( const CommonTokenType* token );
+ CommonTree( const CommonTree* token );
+ CommonTree( const CommonTree& ctree );
+ ~CommonTree();
+
+ const CommonTokenType* get_token() const;
+ void set_token(CommonTokenType const*);
+
+ ChildrenType& get_children();
+ const ChildrenType& get_children() const;
+ ANTLR_INT32 get_childIndex() const;
+ TreeType* get_parent() const;
+
+ ANTLR_MARKER get_startIndex() const;
+ void set_startIndex(ANTLR_MARKER index);
+
+ ANTLR_MARKER get_stopIndex() const;
+ void set_stopIndex(ANTLR_MARKER index);
+
+ void set_parent( TreeType* parent);
+ void set_childIndex( ANTLR_INT32 );
+
+ void addChild(TreeTypePtr& child);
+ /// Add all elements of the supplied list as children of this node
+ ///
+ void addChildren(const ChildListType& kids);
+
+ TreeTypePtr deleteChild(ANTLR_UINT32 i);
+ /// Delete children from start to stop and replace with t even if t is
+ /// a list (nil-root tree). Num of children can increase or decrease.
+ /// For huge child lists, inserting children can force walking rest of
+ /// children to set their child index; could be slow.
+ ///
+ void replaceChildren(ANTLR_INT32 startChildIndex, ANTLR_INT32 stopChildIndex, TreeTypePtr t);
+
+ // clone itself
+ CommonTree* dupNode() const;
+ // clone itself in pre-allocated storage
+ CommonTree* dupNode(void *) const;
+
+
+ ANTLR_UINT32 get_charPositionInLine() const;
+ ANTLR_UINT32 get_line() const;
+
+ TreeTypePtr& getChild(ANTLR_UINT32 i);
+ ANTLR_UINT32 getChildCount() const;
+ ANTLR_UINT32 getType();
+ TreeTypePtr& getFirstChildWithType(ANTLR_UINT32 type);
+
+ StringType getText();
+ bool isNilNode();
+ void setChild(ANTLR_UINT32 i, TreeTypePtr child);
+ StringType toStringTree();
+ StringType toString();
+ void freshenParentAndChildIndexes();
+ void freshenParentAndChildIndexes(ANTLR_UINT32 offset);
+ void freshenParentAndChildIndexesDeeply();
+ void freshenParentAndChildIndexesDeeply(ANTLR_UINT32 offset);
+ // Prepare tree node to be re-used
+ void reuse();
+
+ UserDataType UserData;
};
-}
+}
#include "antlr3commontree.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontree.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontree.inl
index f618d1d2a1..7000ca4fd2 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontree.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontree.inl
@@ -1,515 +1,515 @@
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits>
CommonTree<ImplTraits>::CommonTree()
{
- m_startIndex = -1;
- m_stopIndex = -1;
- m_childIndex = -1;
- m_token = NULL;
- m_parent = NULL;
+ m_startIndex = -1;
+ m_stopIndex = -1;
+ m_childIndex = -1;
+ m_token = NULL;
+ m_parent = NULL;
}
template<class ImplTraits>
CommonTree<ImplTraits>::CommonTree( const CommonTree& ctree )
- :m_children( ctree.m_children)
- ,UserData(ctree.UserData)
+ :m_children( ctree.m_children)
+ ,UserData(ctree.UserData)
{
- m_startIndex = ctree.m_startIndex;
- m_stopIndex = ctree.m_stopIndex;
- m_childIndex = ctree.m_childIndex;
- m_token = ctree.m_token;
- m_parent = ctree.m_parent;
+ m_startIndex = ctree.m_startIndex;
+ m_stopIndex = ctree.m_stopIndex;
+ m_childIndex = ctree.m_childIndex;
+ m_token = ctree.m_token;
+ m_parent = ctree.m_parent;
}
template<class ImplTraits>
-CommonTree<ImplTraits>::CommonTree( const CommonTokenType* token )
+CommonTree<ImplTraits>::CommonTree( const CommonTokenType* token )
{
- m_startIndex = -1;
- m_stopIndex = -1;
- m_childIndex = -1;
- m_token = token;
- m_parent = NULL;
+ m_startIndex = -1;
+ m_stopIndex = -1;
+ m_childIndex = -1;
+ m_token = token;
+ m_parent = NULL;
}
template<class ImplTraits>
-CommonTree<ImplTraits>::CommonTree( const CommonTree* tree )
- :UserData(tree->UserData)
+CommonTree<ImplTraits>::CommonTree( const CommonTree* tree )
+ :UserData(tree->UserData)
{
- m_startIndex = tree->get_startIndex();
- m_stopIndex = tree->get_stopIndex();
- m_childIndex = -1;
- m_token = tree->get_token();
- m_parent = NULL;
+ m_startIndex = tree->get_startIndex();
+ m_stopIndex = tree->get_stopIndex();
+ m_childIndex = -1;
+ m_token = tree->get_token();
+ m_parent = NULL;
}
template<class ImplTraits>
-const typename CommonTree<ImplTraits>::CommonTokenType* CommonTree<ImplTraits>::get_token() const
+const typename CommonTree<ImplTraits>::CommonTokenType* CommonTree<ImplTraits>::get_token() const
{
- return m_token;
+ return m_token;
}
template<class ImplTraits>
-void CommonTree<ImplTraits>::set_token(typename CommonTree<ImplTraits>::CommonTokenType const* token)
+void CommonTree<ImplTraits>::set_token(typename CommonTree<ImplTraits>::CommonTokenType const* token)
{
- m_token = token;
+ m_token = token;
}
template<class ImplTraits>
-typename CommonTree<ImplTraits>::ChildrenType& CommonTree<ImplTraits>::get_children()
+typename CommonTree<ImplTraits>::ChildrenType& CommonTree<ImplTraits>::get_children()
{
- return m_children;
+ return m_children;
}
template<class ImplTraits>
-const typename CommonTree<ImplTraits>::ChildrenType& CommonTree<ImplTraits>::get_children() const
+const typename CommonTree<ImplTraits>::ChildrenType& CommonTree<ImplTraits>::get_children() const
{
- return m_children;
+ return m_children;
}
template<class ImplTraits>
-void CommonTree<ImplTraits>::addChild(TreeTypePtr& child)
+void CommonTree<ImplTraits>::addChild(TreeTypePtr& child)
{
- if (child == NULL)
- return;
+ if (child == NULL)
+ return;
- ChildrenType& child_children = child->get_children();
- //ChildrenType& tree_children = this->get_children();
+ ChildrenType& child_children = child->get_children();
+ //ChildrenType& tree_children = this->get_children();
- if (child->isNilNode() == true)
- {
- if ( !child_children.empty() && child_children == m_children )
- {
- // TODO: Change to exception rather than ANTLR3_FPRINTF?
- fprintf(stderr, "ANTLR3: An attempt was made to add a child list to itself!\n");
- return;
- }
+ if (child->isNilNode() == true)
+ {
+ if ( !child_children.empty() && child_children == m_children )
+ {
+ // TODO: Change to exception rather than ANTLR3_FPRINTF?
+ fprintf(stderr, "ANTLR3: An attempt was made to add a child list to itself!\n");
+ return;
+ }
// Add all of the children's children to this list
//
if ( !child_children.empty() )
{
- if (!m_children.empty())
+ if (!m_children.empty())
{
- // Need to copy(append) the children
- for(auto i = child_children.begin(); i != child_children.end(); ++i)
- {
- // ANTLR3 lists can be sparse, unlike Array Lists (TODO: really?)
- if ((*i) != NULL)
- {
- m_children.push_back(std::move(*i));
- // static_cast to possible subtype (if TreeType trait defined)
- TreeType* tree = static_cast<TreeType*>(this);
- m_children.back()->set_parent(tree);
- m_children.back()->set_childIndex(m_children.size() - 1);
- }
- }
- } else {
+ // Need to copy(append) the children
+ for(auto i = child_children.begin(); i != child_children.end(); ++i)
+ {
+ // ANTLR3 lists can be sparse, unlike Array Lists (TODO: really?)
+ if ((*i) != NULL)
+ {
+ m_children.push_back(std::move(*i));
+ // static_cast to possible subtype (if TreeType trait defined)
+ TreeType* tree = static_cast<TreeType*>(this);
+ m_children.back()->set_parent(tree);
+ m_children.back()->set_childIndex(m_children.size() - 1);
+ }
+ }
+ } else {
// We are build ing the tree structure here, so we need not
// worry about duplication of pointers as the tree node
// factory will only clean up each node once. So we just
// copy in the child's children pointer as the child is
// a nil node (has not root itself).
//
- m_children.swap( child_children );
- this->freshenParentAndChildIndexes();
+ m_children.swap( child_children );
+ this->freshenParentAndChildIndexes();
}
- }
- }
- else
- {
- // Tree we are adding is not a Nil and might have children to copy
- m_children.push_back( std::move(child) );
- // static_cast to possible subtype (if TreeType trait defined)
- TreeType* tree = static_cast<TreeType*>(this);
- m_children.back()->set_parent(tree);
- m_children.back()->set_childIndex(m_children.size() - 1);
- }
-}
-
-template<class ImplTraits>
-void CommonTree<ImplTraits>::addChildren(const ChildListType& kids)
-{
- for( typename ChildListType::const_iterator iter = kids.begin();
- iter != kids.end(); ++iter )
- {
- this->addChild( *iter );
- }
-}
-
-template<class ImplTraits>
-typename CommonTree<ImplTraits>::TreeTypePtr CommonTree<ImplTraits>::deleteChild(ANTLR_UINT32 i)
-{
- if( m_children.empty() )
- return NULL;
- TreeTypePtr killed = m_children.erase( m_children.begin() + i);
- this->freshenParentAndChildIndexes(i);
- return killed;
-}
-
-template<class ImplTraits>
-void CommonTree<ImplTraits>::replaceChildren(ANTLR_INT32 startChildIndex, ANTLR_INT32 stopChildIndex, TreeTypePtr newTree)
-{
-
- ANTLR_INT32 numNewChildren; // Tracking variable
- ANTLR_INT32 delta; // Difference in new vs existing count
-
- if ( m_children.empty() )
- {
- fprintf(stderr, "replaceChildren call: Indexes are invalid; no children in list for %s", this->get_text().c_str() );
- // TODO throw here
- return;
- }
- // How many nodes will go away
- ANTLR_INT32 replacingHowMany = stopChildIndex - startChildIndex + 1;
- ANTLR_INT32 replacingWithHowMany; // How many nodes will replace them
-
- // Either use the existing list of children in the supplied nil node, or build a vector of the
- // tree we were given if it is not a nil node, then we treat both situations exactly the same
- //
- ChildrenType newChildren;
- ChildrenType &newChildrenRef(newChildren);
+ }
+ }
+ else
+ {
+ // Tree we are adding is not a Nil and might have children to copy
+ m_children.push_back( std::move(child) );
+ // static_cast to possible subtype (if TreeType trait defined)
+ TreeType* tree = static_cast<TreeType*>(this);
+ m_children.back()->set_parent(tree);
+ m_children.back()->set_childIndex(m_children.size() - 1);
+ }
+}
+
+template<class ImplTraits>
+void CommonTree<ImplTraits>::addChildren(const ChildListType& kids)
+{
+ for( typename ChildListType::const_iterator iter = kids.begin();
+ iter != kids.end(); ++iter )
+ {
+ this->addChild( *iter );
+ }
+}
+
+template<class ImplTraits>
+typename CommonTree<ImplTraits>::TreeTypePtr CommonTree<ImplTraits>::deleteChild(ANTLR_UINT32 i)
+{
+ if( m_children.empty() )
+ return NULL;
+ TreeTypePtr killed = m_children.erase( m_children.begin() + i);
+ this->freshenParentAndChildIndexes(i);
+ return killed;
+}
+
+template<class ImplTraits>
+void CommonTree<ImplTraits>::replaceChildren(ANTLR_INT32 startChildIndex, ANTLR_INT32 stopChildIndex, TreeTypePtr newTree)
+{
+
+ ANTLR_INT32 numNewChildren; // Tracking variable
+ ANTLR_INT32 delta; // Difference in new vs existing count
+
+ if ( m_children.empty() )
+ {
+ fprintf(stderr, "replaceChildren call: Indexes are invalid; no children in list for %s", this->get_text().c_str() );
+ // TODO throw here
+ return;
+ }
+ // How many nodes will go away
+ ANTLR_INT32 replacingHowMany = stopChildIndex - startChildIndex + 1;
+ ANTLR_INT32 replacingWithHowMany; // How many nodes will replace them
+
+ // Either use the existing list of children in the supplied nil node, or build a vector of the
+ // tree we were given if it is not a nil node, then we treat both situations exactly the same
+ //
+ ChildrenType newChildren;
+ ChildrenType &newChildrenRef(newChildren);
- if (newTree->isNilNode())
- {
- newChildrenRef = newTree->get_children();
- } else {
- newChildrenRef.push_back(newTree);
- }
+ if (newTree->isNilNode())
+ {
+ newChildrenRef = newTree->get_children();
+ } else {
+ newChildrenRef.push_back(newTree);
+ }
- // Initialize
- replacingWithHowMany = newChildrenRef.size();
- numNewChildren = newChildrenRef.size();
- delta = replacingHowMany - replacingWithHowMany;
+ // Initialize
+ replacingWithHowMany = newChildrenRef.size();
+ numNewChildren = newChildrenRef.size();
+ delta = replacingHowMany - replacingWithHowMany;
- // If it is the same number of nodes, then do a direct replacement
- //
- if (delta == 0)
- {
- ANTLR_INT32 j = 0;
- for (ANTLR_INT32 i = startChildIndex; i <= stopChildIndex; i++)
- {
- TreeType *child = newChildrenRef.at(j);
- m_children[i] = child;
- TreeType* tree = static_cast<TreeType*>(this);
- child->set_parent(tree);
- child->set_childIndex(i);
- j++;
- }
- }
- else if (delta > 0)
- {
- // Less nodes than there were before
- // reuse what we have then delete the rest
- for (ANTLR_UINT32 j = 0; j < numNewChildren; j++)
- {
- m_children[ startChildIndex + j ] = newChildrenRef.at(j);
- }
- // We just delete the same index position until done
- ANTLR_UINT32 indexToDelete = startChildIndex + numNewChildren;
- for (ANTLR_UINT32 j = indexToDelete; j <= stopChildIndex; j++)
- {
- m_children.erase( m_children.begin() + indexToDelete);
- }
- this->freshenParentAndChildIndexes(startChildIndex);
- }
- else
- {
- // More nodes than there were before
- // Use what we can, then start adding
- for (ANTLR_UINT32 j = 0; j < replacingHowMany; j++)
- {
- m_children[ startChildIndex + j ] = newChildrenRef.at(j);
- }
+ // If it is the same number of nodes, then do a direct replacement
+ //
+ if (delta == 0)
+ {
+ ANTLR_INT32 j = 0;
+ for (ANTLR_INT32 i = startChildIndex; i <= stopChildIndex; i++)
+ {
+ TreeType *child = newChildrenRef.at(j);
+ m_children[i] = child;
+ TreeType* tree = static_cast<TreeType*>(this);
+ child->set_parent(tree);
+ child->set_childIndex(i);
+ j++;
+ }
+ }
+ else if (delta > 0)
+ {
+ // Less nodes than there were before
+ // reuse what we have then delete the rest
+ for (ANTLR_UINT32 j = 0; j < numNewChildren; j++)
+ {
+ m_children[ startChildIndex + j ] = newChildrenRef.at(j);
+ }
+ // We just delete the same index position until done
+ ANTLR_UINT32 indexToDelete = startChildIndex + numNewChildren;
+ for (ANTLR_UINT32 j = indexToDelete; j <= stopChildIndex; j++)
+ {
+ m_children.erase( m_children.begin() + indexToDelete);
+ }
+ this->freshenParentAndChildIndexes(startChildIndex);
+ }
+ else
+ {
+ // More nodes than there were before
+ // Use what we can, then start adding
+ for (ANTLR_UINT32 j = 0; j < replacingHowMany; j++)
+ {
+ m_children[ startChildIndex + j ] = newChildrenRef.at(j);
+ }
- for (ANTLR_UINT32 j = replacingHowMany; j < replacingWithHowMany; j++)
- {
- m_children.push_back( newChildrenRef.at(j) );
- }
+ for (ANTLR_UINT32 j = replacingHowMany; j < replacingWithHowMany; j++)
+ {
+ m_children.push_back( newChildrenRef.at(j) );
+ }
- this->freshenParentAndChildIndexes(startChildIndex);
- }
+ this->freshenParentAndChildIndexes(startChildIndex);
+ }
}
template<class ImplTraits>
-CommonTree<ImplTraits>* CommonTree<ImplTraits>::dupNode() const
+CommonTree<ImplTraits>* CommonTree<ImplTraits>::dupNode() const
{
- return new CommonTree<ImplTraits>(this);
+ return new CommonTree<ImplTraits>(this);
}
template<class ImplTraits>
-CommonTree<ImplTraits>* CommonTree<ImplTraits>::dupNode(void *p) const
+CommonTree<ImplTraits>* CommonTree<ImplTraits>::dupNode(void *p) const
{
- return new (p) CommonTree<ImplTraits>(this);
-}
-
+ return new (p) CommonTree<ImplTraits>(this);
+}
+
template<class ImplTraits>
-ANTLR_UINT32 CommonTree<ImplTraits>::get_charPositionInLine() const
+ANTLR_UINT32 CommonTree<ImplTraits>::get_charPositionInLine() const
{
- if(m_token == NULL || (m_token->get_charPositionInLine() == 0) )
- {
- if(m_children.empty())
- return 0;
- if(m_children.front())
- return m_children.front()->get_charPositionInLine();
- return 0;
- }
- return m_token->get_charPositionInLine();
-}
-
-template<class ImplTraits>
-typename CommonTree<ImplTraits>::TreeTypePtr& CommonTree<ImplTraits>::getChild(ANTLR_UINT32 i)
-{
- static TreeTypePtr nul;
- if ( m_children.empty() || i >= m_children.size() )
- {
- // TODO throw here should not happen
- return nul;
- }
- return m_children.at(i);
+ if(m_token == NULL || (m_token->get_charPositionInLine() == 0) )
+ {
+ if(m_children.empty())
+ return 0;
+ if(m_children.front())
+ return m_children.front()->get_charPositionInLine();
+ return 0;
+ }
+ return m_token->get_charPositionInLine();
+}
+
+template<class ImplTraits>
+typename CommonTree<ImplTraits>::TreeTypePtr& CommonTree<ImplTraits>::getChild(ANTLR_UINT32 i)
+{
+ static TreeTypePtr nul;
+ if ( m_children.empty() || i >= m_children.size() )
+ {
+ // TODO throw here should not happen
+ return nul;
+ }
+ return m_children.at(i);
}
template<class ImplTraits>
void CommonTree<ImplTraits>::set_childIndex( ANTLR_INT32 i)
{
- m_childIndex = i;
+ m_childIndex = i;
}
template<class ImplTraits>
-ANTLR_INT32 CommonTree<ImplTraits>::get_childIndex() const
+ANTLR_INT32 CommonTree<ImplTraits>::get_childIndex() const
{
- return m_childIndex;
+ return m_childIndex;
}
template<class ImplTraits>
-ANTLR_UINT32 CommonTree<ImplTraits>::getChildCount() const
+ANTLR_UINT32 CommonTree<ImplTraits>::getChildCount() const
{
- return static_cast<ANTLR_UINT32>( m_children.size() );
+ return static_cast<ANTLR_UINT32>( m_children.size() );
}
template<class ImplTraits>
typename CommonTree<ImplTraits>::TreeType* CommonTree<ImplTraits>::get_parent() const
{
- return m_parent;
+ return m_parent;
}
template<class ImplTraits>
void CommonTree<ImplTraits>::set_parent( TreeType* parent)
{
- m_parent = parent;
+ m_parent = parent;
}
template<class ImplTraits>
-ANTLR_MARKER CommonTree<ImplTraits>::get_startIndex() const
+ANTLR_MARKER CommonTree<ImplTraits>::get_startIndex() const
{
- if( m_startIndex==-1 && m_token!=NULL)
- return m_token->get_tokenIndex();
- return m_startIndex;
+ if( m_startIndex==-1 && m_token!=NULL)
+ return m_token->get_tokenIndex();
+ return m_startIndex;
}
template<class ImplTraits>
-void CommonTree<ImplTraits>::set_startIndex( ANTLR_MARKER index)
+void CommonTree<ImplTraits>::set_startIndex( ANTLR_MARKER index)
{
- m_startIndex = index;
-}
+ m_startIndex = index;
+}
-template<class ImplTraits>
-ANTLR_MARKER CommonTree<ImplTraits>::get_stopIndex() const
-{
- if( m_stopIndex==-1 && m_token!=NULL)
- return m_token->get_tokenIndex();
- return m_stopIndex;
+template<class ImplTraits>
+ANTLR_MARKER CommonTree<ImplTraits>::get_stopIndex() const
+{
+ if( m_stopIndex==-1 && m_token!=NULL)
+ return m_token->get_tokenIndex();
+ return m_stopIndex;
}
template<class ImplTraits>
-void CommonTree<ImplTraits>::set_stopIndex( ANTLR_MARKER index)
+void CommonTree<ImplTraits>::set_stopIndex( ANTLR_MARKER index)
{
- m_stopIndex = index;
-}
+ m_stopIndex = index;
+}
-template<class ImplTraits>
-ANTLR_UINT32 CommonTree<ImplTraits>::getType()
-{
- if (m_token == NULL)
- return CommonTokenType::TOKEN_INVALID;
- else
- return m_token->get_type();
+template<class ImplTraits>
+ANTLR_UINT32 CommonTree<ImplTraits>::getType()
+{
+ if (m_token == NULL)
+ return CommonTokenType::TOKEN_INVALID;
+ else
+ return m_token->get_type();
}
template<class ImplTraits>
-typename CommonTree<ImplTraits>::TreeTypePtr& CommonTree<ImplTraits>::getFirstChildWithType(ANTLR_UINT32 type)
+typename CommonTree<ImplTraits>::TreeTypePtr& CommonTree<ImplTraits>::getFirstChildWithType(ANTLR_UINT32 type)
{
- ANTLR_UINT32 i;
- std::size_t cs;
-
- TreeTypePtr t;
- if ( !m_children.empty() )
- {
- cs = m_children.size();
- for (i = 0; i < cs; i++)
- {
- t = m_children[i];
- if (t->getType() == type)
- {
- return t;
- }
- }
- }
- return NULL;
+ ANTLR_UINT32 i;
+ std::size_t cs;
+
+ TreeTypePtr t;
+ if ( !m_children.empty() )
+ {
+ cs = m_children.size();
+ for (i = 0; i < cs; i++)
+ {
+ t = m_children[i];
+ if (t->getType() == type)
+ {
+ return t;
+ }
+ }
+ }
+ return NULL;
}
template<class ImplTraits>
-ANTLR_UINT32 CommonTree<ImplTraits>::get_line() const
+ANTLR_UINT32 CommonTree<ImplTraits>::get_line() const
{
- if(m_token == NULL || m_token->get_line() == 0)
- {
- if ( m_children.empty())
- return 0;
- if ( m_children.front())
- return m_children.front()->get_line();
- return 0;
- }
- return m_token->get_line();
+ if(m_token == NULL || m_token->get_line() == 0)
+ {
+ if ( m_children.empty())
+ return 0;
+ if ( m_children.front())
+ return m_children.front()->get_line();
+ return 0;
+ }
+ return m_token->get_line();
}
template<class ImplTraits>
-typename CommonTree<ImplTraits>::StringType CommonTree<ImplTraits>::getText()
+typename CommonTree<ImplTraits>::StringType CommonTree<ImplTraits>::getText()
{
- return this->toString();
+ return this->toString();
}
template<class ImplTraits>
-bool CommonTree<ImplTraits>::isNilNode()
+bool CommonTree<ImplTraits>::isNilNode()
{
- // This is a Nil tree if it has no payload (Token in our case)
- if(m_token == NULL)
- return true;
- else
- return false;
-}
+ // This is a Nil tree if it has no payload (Token in our case)
+ if(m_token == NULL)
+ return true;
+ else
+ return false;
+}
-template<class ImplTraits>
-void CommonTree<ImplTraits>::setChild(ANTLR_UINT32 i, TreeTypePtr child)
-{
- if( child==NULL)
- return;
+template<class ImplTraits>
+void CommonTree<ImplTraits>::setChild(ANTLR_UINT32 i, TreeTypePtr child)
+{
+ if( child==NULL)
+ return;
- if( child->isNilNode())
- {
- // TODO: throw IllegalArgumentException
- return;
- }
+ if( child->isNilNode())
+ {
+ // TODO: throw IllegalArgumentException
+ return;
+ }
- if( m_children.size() <= i )
- m_children.resize(i+1);
+ if( m_children.size() <= i )
+ m_children.resize(i+1);
- m_children[i] = child;
- TreeType* tree = static_cast<TreeType*>(this);
- child->set_parent(tree);
- child->set_childIndex(i);
+ m_children[i] = child;
+ TreeType* tree = static_cast<TreeType*>(this);
+ child->set_parent(tree);
+ child->set_childIndex(i);
}
-
-template<class ImplTraits>
-typename CommonTree<ImplTraits>::StringType CommonTree<ImplTraits>::toStringTree()
+
+template<class ImplTraits>
+typename CommonTree<ImplTraits>::StringType CommonTree<ImplTraits>::toStringTree()
{
- StringType retval;
+ StringType retval;
+
+ if( m_children.empty() )
+ return this->toString();
+
+ /* Need a new string with nothing at all in it.
+ */
+ if(this->isNilNode() == false)
+ {
+ retval.append("(");
+ retval.append(this->toString());
+ retval.append(" ");
+ }
- if( m_children.empty() )
- return this->toString();
+ if ( !m_children.empty())
+ {
+ retval.append( m_children.front()->toStringTree());
+ for (auto i = std::next(m_children.begin()); i != m_children.end(); ++i)
+ {
+ retval.append(" ");
+ retval.append((*i)->toStringTree());
+ }
+ }
- /* Need a new string with nothing at all in it.
- */
- if(this->isNilNode() == false)
- {
- retval.append("(");
- retval.append(this->toString());
- retval.append(" ");
- }
-
- if ( !m_children.empty())
- {
- retval.append( m_children.front()->toStringTree());
- for (auto i = std::next(m_children.begin()); i != m_children.end(); ++i)
- {
- retval.append(" ");
- retval.append((*i)->toStringTree());
- }
- }
-
- if (this->isNilNode() == false)
- {
- retval.append(")");
- }
- return retval;
-}
-
-template<class ImplTraits>
-typename CommonTree<ImplTraits>::StringType CommonTree<ImplTraits>::toString()
-{
- if( this->isNilNode())
- return StringType("nil");
- return m_token->toString();
+ if (this->isNilNode() == false)
+ {
+ retval.append(")");
+ }
+ return retval;
}
template<class ImplTraits>
-void CommonTree<ImplTraits>::freshenParentAndChildIndexes()
+typename CommonTree<ImplTraits>::StringType CommonTree<ImplTraits>::toString()
{
- this->freshenParentAndChildIndexes(0);
-}
+ if( this->isNilNode())
+ return StringType("nil");
+ return m_token->toString();
+}
-template<class ImplTraits>
-void CommonTree<ImplTraits>::freshenParentAndChildIndexes(ANTLR_UINT32 offset)
-{
-// ANTLR_UINT32 count = this->getChildCount();
- // Loop from the supplied index and set the indexes and parent
-// for (ANTLR_UINT32 c = offset; c < count; c++)
-// {
-// TreeTypePtr child = this->getChild(c);
-// child->set_childIndex(c);
-// child->set_parent(this);
-// }
- // Loop from the supplied index and set the indexes and parent
- auto i = m_children.begin();
- int c = offset;
- if(offset)
- std::advance( i, offset );
- for(; i != m_children.end(); ++i, ++c)
- {
- (*i)->set_childIndex(c);
- TreeType* tree = static_cast<TreeType*>(this);
- (*i)->set_parent(tree);
- }
-}
-
-template<class ImplTraits>
-void CommonTree<ImplTraits>::freshenParentAndChildIndexesDeeply()
-{
- this->freshenParentAndChildIndexes(0);
-}
-
-template<class ImplTraits>
-void CommonTree<ImplTraits>::freshenParentAndChildIndexesDeeply(ANTLR_UINT32 offset)
-{
- ANTLR_UINT32 count = this->getChildCount();
- for (ANTLR_UINT32 c = offset; c < count; c++) {
- TreeTypePtr child = getChild(c);
- child->set_childIndex(c);
- child->set_parent(this);
- child->freshenParentAndChildIndexesDeeply();
- }
-}
-
-template<class ImplTraits>
-void CommonTree<ImplTraits>::reuse()
-{
- m_startIndex = -1;
- m_stopIndex = -1;
- m_childIndex = -1;
- m_token = NULL;
- m_parent = NULL;
-
- ChildrenType empty;
- m_children.swap(empty);
+template<class ImplTraits>
+void CommonTree<ImplTraits>::freshenParentAndChildIndexes()
+{
+ this->freshenParentAndChildIndexes(0);
+}
+
+template<class ImplTraits>
+void CommonTree<ImplTraits>::freshenParentAndChildIndexes(ANTLR_UINT32 offset)
+{
+// ANTLR_UINT32 count = this->getChildCount();
+ // Loop from the supplied index and set the indexes and parent
+// for (ANTLR_UINT32 c = offset; c < count; c++)
+// {
+// TreeTypePtr child = this->getChild(c);
+// child->set_childIndex(c);
+// child->set_parent(this);
+// }
+ // Loop from the supplied index and set the indexes and parent
+ auto i = m_children.begin();
+ int c = offset;
+ if(offset)
+ std::advance( i, offset );
+ for(; i != m_children.end(); ++i, ++c)
+ {
+ (*i)->set_childIndex(c);
+ TreeType* tree = static_cast<TreeType*>(this);
+ (*i)->set_parent(tree);
+ }
+}
+
+template<class ImplTraits>
+void CommonTree<ImplTraits>::freshenParentAndChildIndexesDeeply()
+{
+ this->freshenParentAndChildIndexes(0);
+}
+
+template<class ImplTraits>
+void CommonTree<ImplTraits>::freshenParentAndChildIndexesDeeply(ANTLR_UINT32 offset)
+{
+ ANTLR_UINT32 count = this->getChildCount();
+ for (ANTLR_UINT32 c = offset; c < count; c++) {
+ TreeTypePtr child = getChild(c);
+ child->set_childIndex(c);
+ child->set_parent(this);
+ child->freshenParentAndChildIndexesDeeply();
+ }
+}
+
+template<class ImplTraits>
+void CommonTree<ImplTraits>::reuse()
+{
+ m_startIndex = -1;
+ m_stopIndex = -1;
+ m_childIndex = -1;
+ m_token = NULL;
+ m_parent = NULL;
+
+ ChildrenType empty;
+ m_children.swap(empty);
}
template<class ImplTraits>
@@ -517,4 +517,4 @@ CommonTree<ImplTraits>::~CommonTree()
{
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreeadaptor.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreeadaptor.hpp
index cd21bf3b47..c32968ac92 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreeadaptor.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreeadaptor.hpp
@@ -2,8 +2,8 @@
* Definition of the ANTLR3 common tree adaptor.
*/
-#ifndef _ANTLR3_COMMON_TREE_ADAPTOR_HPP
-#define _ANTLR3_COMMON_TREE_ADAPTOR_HPP
+#ifndef _ANTLR3_COMMON_TREE_ADAPTOR_HPP
+#define _ANTLR3_COMMON_TREE_ADAPTOR_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -33,215 +33,215 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
-
-template <typename ImplTraits> class CommonTreeStore;
-
-/** Helper class for unique_ptr. Implements deleter for instances of unique_ptr
- While building AST tree dangling pointers are automatically put back into pool
- */
-template <typename ImplTraits>
-class CommonResourcePoolManager
-{
-public:
- typedef typename ImplTraits::TreeType TreeType;
- CommonResourcePoolManager(CommonTreeStore<ImplTraits> * pool);
- CommonResourcePoolManager();
-
- ~CommonResourcePoolManager();
-
- void operator()(TreeType* releasedResource) const;
-private:
- CommonTreeStore<ImplTraits> * m_pool;
-};
-
-template <class ImplTraits>
-class CommonTreeStore
-{
-public:
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
- typedef CommonResourcePoolManager<ImplTraits> ResourcePoolManagerType;
- typedef std::unique_ptr<TreeType, CommonResourcePoolManager<ImplTraits> > TreeTypePtr;
- //typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
-
- CommonTreeStore();
-
- TreeTypePtr create();
- CommonTokenType* createToken();
- CommonTokenType* createToken(const CommonTokenType* fromToken);
-
- // Return special kind of NULL pointer wrapped into TreeTypePtr
- TreeTypePtr
- null()
- {
- return TreeTypePtr(NULL, m_manager);
- }
-
- std::size_t size() const
- {
- return m_treeStore.size();
- }
-
- template <class T>
- bool contains(const std::vector<T> &vec, const T &value)
- {
- return std::find(vec.begin(), vec.end(), value) != vec.end();
- }
-
-protected:
- template<typename> friend class CommonResourcePoolManager;
- template<typename> friend class CommonTreeAdaptor;
-
- void reuse(TreeType* releasedResource);
-
- std::vector<TreeType *> m_recycleBin;
- std::vector<std::unique_ptr<TreeType> > m_treeStore;
- std::vector<std::unique_ptr<CommonTokenType> > m_tokenStore;
- ResourcePoolManagerType m_manager;
-};
-
+namespace antlr3 {
+
+template <typename ImplTraits> class CommonTreeStore;
+
+/** Helper class for unique_ptr. Implements deleter for instances of unique_ptr
+ While building AST tree dangling pointers are automatically put back into pool
+ */
+template <typename ImplTraits>
+class CommonResourcePoolManager
+{
+public:
+ typedef typename ImplTraits::TreeType TreeType;
+ CommonResourcePoolManager(CommonTreeStore<ImplTraits> * pool);
+ CommonResourcePoolManager();
+
+ ~CommonResourcePoolManager();
+
+ void operator()(TreeType* releasedResource) const;
+private:
+ CommonTreeStore<ImplTraits> * m_pool;
+};
+
+template <class ImplTraits>
+class CommonTreeStore
+{
+public:
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
+ typedef CommonResourcePoolManager<ImplTraits> ResourcePoolManagerType;
+ typedef std::unique_ptr<TreeType, CommonResourcePoolManager<ImplTraits> > TreeTypePtr;
+ //typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+
+ CommonTreeStore();
+
+ TreeTypePtr create();
+ CommonTokenType* createToken();
+ CommonTokenType* createToken(const CommonTokenType* fromToken);
+
+ // Return special kind of NULL pointer wrapped into TreeTypePtr
+ TreeTypePtr
+ null()
+ {
+ return TreeTypePtr(NULL, m_manager);
+ }
+
+ std::size_t size() const
+ {
+ return m_treeStore.size();
+ }
+
+ template <class T>
+ bool contains(const std::vector<T> &vec, const T &value)
+ {
+ return std::find(vec.begin(), vec.end(), value) != vec.end();
+ }
+
+protected:
+ template<typename> friend class CommonResourcePoolManager;
+ template<typename> friend class CommonTreeAdaptor;
+
+ void reuse(TreeType* releasedResource);
+
+ std::vector<TreeType *> m_recycleBin;
+ std::vector<std::unique_ptr<TreeType> > m_treeStore;
+ std::vector<std::unique_ptr<CommonTokenType> > m_tokenStore;
+ ResourcePoolManagerType m_manager;
+};
+
template<class ImplTraits>
-class CommonTreeAdaptor
- : public ImplTraits::AllocPolicyType
- , public CommonTreeStore<ImplTraits>
+class CommonTreeAdaptor
+ : public ImplTraits::AllocPolicyType
+ , public CommonTreeStore<ImplTraits>
{
public:
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
- typedef typename TreeType::ChildrenType ChildrenType;
-
- typedef TreeType TokenType;
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
- typedef typename ImplTraits::DebugEventListenerType DebuggerType;
- typedef typename ImplTraits::TokenStreamType TokenStreamType;
- typedef CommonTreeStore<ImplTraits> TreeStoreType;
-
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+ typedef typename TreeType::ChildrenType ChildrenType;
+
+ typedef TreeType TokenType;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
+ typedef typename ImplTraits::DebugEventListenerType DebuggerType;
+ typedef typename ImplTraits::TokenStreamType TokenStreamType;
+ typedef CommonTreeStore<ImplTraits> TreeStoreType;
+
public:
- //The parameter is there only to provide uniform constructor interface
- CommonTreeAdaptor(DebuggerType* dbg = nullptr);
-
- TreeTypePtr nilNode();
- TreeTypePtr dupTree( const TreeTypePtr& tree);
- TreeTypePtr dupTree( const TreeType* tree);
-
- TreeTypePtr dupNode(const TreeTypePtr& treeNode);
- TreeTypePtr dupNode(const TreeType* treeNode);
-
- void addChild( TreeTypePtr& t, TreeTypePtr& child);
- void addChild( TreeTypePtr& t, TreeTypePtr&& child);
- void addChildToken( TreeTypePtr& t, CommonTokenType* child);
- void setParent( TreeTypePtr& child, TreeType* parent);
- TreeType* getParent( TreeTypePtr& child);
-
- TreeTypePtr errorNode( CommonTokenType* tnstream, const CommonTokenType* startToken, const CommonTokenType* stopToken);
- bool isNilNode( TreeTypePtr& t);
-
- TreeTypePtr becomeRoot( TreeTypePtr& newRoot, TreeTypePtr& oldRoot);
- TreeTypePtr becomeRoot( TreeTypePtr&& newRoot, TreeTypePtr& oldRoot);
- TreeTypePtr becomeRootToken(CommonTokenType* newRoot, TreeTypePtr& oldRoot);
- TreeTypePtr rulePostProcessing( TreeTypePtr& root);
-
- TreeTypePtr create( CommonTokenType const* payload);
- TreeTypePtr create( ANTLR_UINT32 tokenType, const CommonTokenType* fromToken);
- TreeTypePtr create( ANTLR_UINT32 tokenType, const CommonTokenType* fromToken, const char* text);
- TreeTypePtr create( ANTLR_UINT32 tokenType, const CommonTokenType* fromToken, StringType const& text);
- TreeTypePtr create( ANTLR_UINT32 tokenType, const char* text);
- TreeTypePtr create( ANTLR_UINT32 tokenType, StringType const& text);
-
- CommonTokenType* createToken( ANTLR_UINT32 tokenType, const char* text);
- CommonTokenType* createToken( ANTLR_UINT32 tokenType, StringType const& text);
- CommonTokenType* createToken( const CommonTokenType* fromToken);
-
- ANTLR_UINT32 getType( TreeTypePtr& t);
- StringType getText( TreeTypePtr& t);
-
- TreeTypePtr& getChild( TreeTypePtr& t, ANTLR_UINT32 i);
- void setChild( TreeTypePtr& t, ANTLR_UINT32 i, TreeTypePtr& child);
- void deleteChild( TreeTypePtr& t, ANTLR_UINT32 i);
- void setChildIndex( TreeTypePtr& t, ANTLR_INT32 i);
- ANTLR_INT32 getChildIndex( TreeTypePtr& t);
-
- ANTLR_UINT32 getChildCount( TreeTypePtr&);
- ANTLR_UINT64 getUniqueID( TreeTypePtr&);
-
- CommonTokenType* getToken( TreeTypePtr& t);
-
- void setTokenBoundaries( TreeTypePtr& t, const CommonTokenType* startToken, const CommonTokenType* stopToken);
- ANTLR_MARKER getTokenStartIndex( TreeTypePtr& t);
- ANTLR_MARKER getTokenStopIndex( TreeTypePtr& t);
-
- /// Produce a DOT (see graphviz freeware suite) from a base tree
- ///
- StringType makeDot( TreeTypePtr& theTree);
-
- /// Replace from start to stop child index of parent with t, which might
- /// be a list. Number of children may be different
- /// after this call.
- ///
- /// If parent is null, don't do anything; must be at root of overall tree.
- /// Can't replace whatever points to the parent externally. Do nothing.
- ///
- void replaceChildren( TreeTypePtr parent, ANTLR_INT32 startChildIndex,
- ANTLR_INT32 stopChildIndex, TreeTypePtr t);
-
- ~CommonTreeAdaptor();
-
-protected:
- TreeTypePtr dupTreeImpl( const TreeType* root, TreeType* parent);
-
- void defineDotNodes(TreeTypePtr t, const StringType& dotSpec);
- void defineDotEdges(TreeTypePtr t, const StringType& dotSpec);
+ //The parameter is there only to provide uniform constructor interface
+ CommonTreeAdaptor(DebuggerType* dbg = nullptr);
+
+ TreeTypePtr nilNode();
+ TreeTypePtr dupTree( const TreeTypePtr& tree);
+ TreeTypePtr dupTree( const TreeType* tree);
+
+ TreeTypePtr dupNode(const TreeTypePtr& treeNode);
+ TreeTypePtr dupNode(const TreeType* treeNode);
+
+ void addChild( TreeTypePtr& t, TreeTypePtr& child);
+ void addChild( TreeTypePtr& t, TreeTypePtr&& child);
+ void addChildToken( TreeTypePtr& t, CommonTokenType* child);
+ void setParent( TreeTypePtr& child, TreeType* parent);
+ TreeType* getParent( TreeTypePtr& child);
+
+ TreeTypePtr errorNode( CommonTokenType* tnstream, const CommonTokenType* startToken, const CommonTokenType* stopToken);
+ bool isNilNode( TreeTypePtr& t);
+
+ TreeTypePtr becomeRoot( TreeTypePtr& newRoot, TreeTypePtr& oldRoot);
+ TreeTypePtr becomeRoot( TreeTypePtr&& newRoot, TreeTypePtr& oldRoot);
+ TreeTypePtr becomeRootToken(CommonTokenType* newRoot, TreeTypePtr& oldRoot);
+ TreeTypePtr rulePostProcessing( TreeTypePtr& root);
+
+ TreeTypePtr create( CommonTokenType const* payload);
+ TreeTypePtr create( ANTLR_UINT32 tokenType, const CommonTokenType* fromToken);
+ TreeTypePtr create( ANTLR_UINT32 tokenType, const CommonTokenType* fromToken, const char* text);
+ TreeTypePtr create( ANTLR_UINT32 tokenType, const CommonTokenType* fromToken, StringType const& text);
+ TreeTypePtr create( ANTLR_UINT32 tokenType, const char* text);
+ TreeTypePtr create( ANTLR_UINT32 tokenType, StringType const& text);
+
+ CommonTokenType* createToken( ANTLR_UINT32 tokenType, const char* text);
+ CommonTokenType* createToken( ANTLR_UINT32 tokenType, StringType const& text);
+ CommonTokenType* createToken( const CommonTokenType* fromToken);
+
+ ANTLR_UINT32 getType( TreeTypePtr& t);
+ StringType getText( TreeTypePtr& t);
+
+ TreeTypePtr& getChild( TreeTypePtr& t, ANTLR_UINT32 i);
+ void setChild( TreeTypePtr& t, ANTLR_UINT32 i, TreeTypePtr& child);
+ void deleteChild( TreeTypePtr& t, ANTLR_UINT32 i);
+ void setChildIndex( TreeTypePtr& t, ANTLR_INT32 i);
+ ANTLR_INT32 getChildIndex( TreeTypePtr& t);
+
+ ANTLR_UINT32 getChildCount( TreeTypePtr&);
+ ANTLR_UINT64 getUniqueID( TreeTypePtr&);
+
+ CommonTokenType* getToken( TreeTypePtr& t);
+
+ void setTokenBoundaries( TreeTypePtr& t, const CommonTokenType* startToken, const CommonTokenType* stopToken);
+ ANTLR_MARKER getTokenStartIndex( TreeTypePtr& t);
+ ANTLR_MARKER getTokenStopIndex( TreeTypePtr& t);
+
+ /// Produce a DOT (see graphviz freeware suite) from a base tree
+ ///
+ StringType makeDot( TreeTypePtr& theTree);
+
+ /// Replace from start to stop child index of parent with t, which might
+ /// be a list. Number of children may be different
+ /// after this call.
+ ///
+ /// If parent is null, don't do anything; must be at root of overall tree.
+ /// Can't replace whatever points to the parent externally. Do nothing.
+ ///
+ void replaceChildren( TreeTypePtr parent, ANTLR_INT32 startChildIndex,
+ ANTLR_INT32 stopChildIndex, TreeTypePtr t);
+
+ ~CommonTreeAdaptor();
+
+protected:
+ TreeTypePtr dupTreeImpl( const TreeType* root, TreeType* parent);
+
+ void defineDotNodes(TreeTypePtr t, const StringType& dotSpec);
+ void defineDotEdges(TreeTypePtr t, const StringType& dotSpec);
};
-//If someone can override the CommonTreeAdaptor at the compile time, that will be
+//If someone can override the CommonTreeAdaptor at the compile time, that will be
//inherited here. Still you can choose to override the DebugTreeAdaptor, if you wish to
//change the DebugTreeAdaptor
template<class ImplTraits>
class DebugTreeAdaptor : public ImplTraits::CommonTreeAdaptorType
{
public:
- //DebugEventListener implements functionality through virtual functions
- //the template parameter is required for pointing back at the adaptor
- typedef typename ImplTraits::DebugEventListener DebuggerType;
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
- typedef typename ImplTraits::CommonTreeAdaptorType super;
+ //DebugEventListener implements functionality through virtual functions
+ //the template parameter is required for pointing back at the adaptor
+ typedef typename ImplTraits::DebugEventListener DebuggerType;
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
+ typedef typename ImplTraits::CommonTreeAdaptorType super;
private:
- /// If set to something other than NULL, then this structure is
- /// points to an instance of the debugger interface. In general, the
- /// debugger is only referenced internally in recovery/error operations
- /// so that it does not cause overhead by having to check this pointer
- /// in every function/method
- ///
- DebuggerType* m_debugger;
+ /// If set to something other than NULL, then this structure is
+ /// points to an instance of the debugger interface. In general, the
+ /// debugger is only referenced internally in recovery/error operations
+ /// so that it does not cause overhead by having to check this pointer
+ /// in every function/method
+ ///
+ DebuggerType* m_debugger;
public:
- DebugTreeAdaptor( DebuggerType* debugger );
- void setDebugEventListener( DebuggerType* debugger);
- TreeTypePtr nilNode();
- void addChild(TreeTypePtr& t, TreeTypePtr& child);
- void addChildToken(TreeTypePtr& t, CommonTokenType* child);
- TreeTypePtr becomeRoot( TreeTypePtr& newRootTree, TreeTypePtr& oldRootTree );
- TreeTypePtr becomeRootToken( CommonTokenType* newRoot, TreeTypePtr& oldRoot);
-
- TreeTypePtr createTypeToken(ANTLR_UINT32 tokenType, CommonTokenType* fromToken);
- TreeTypePtr createTypeTokenText(ANTLR_UINT32 tokenType, CommonTokenType* fromToken, ANTLR_UINT8* text);
- TreeTypePtr createTypeText( ANTLR_UINT32 tokenType, ANTLR_UINT8* text);
-
- TreeTypePtr dupTree( const TreeTypePtr& tree);
- TreeTypePtr dupTree( const TreeType* tree);
-
- /// Sends the required debugging events for duplicating a tree
- /// to the debugger.
- ///
- void simulateTreeConstruction(TreeTypePtr& tree);
+ DebugTreeAdaptor( DebuggerType* debugger );
+ void setDebugEventListener( DebuggerType* debugger);
+ TreeTypePtr nilNode();
+ void addChild(TreeTypePtr& t, TreeTypePtr& child);
+ void addChildToken(TreeTypePtr& t, CommonTokenType* child);
+ TreeTypePtr becomeRoot( TreeTypePtr& newRootTree, TreeTypePtr& oldRootTree );
+ TreeTypePtr becomeRootToken( CommonTokenType* newRoot, TreeTypePtr& oldRoot);
+
+ TreeTypePtr createTypeToken(ANTLR_UINT32 tokenType, CommonTokenType* fromToken);
+ TreeTypePtr createTypeTokenText(ANTLR_UINT32 tokenType, CommonTokenType* fromToken, ANTLR_UINT8* text);
+ TreeTypePtr createTypeText( ANTLR_UINT32 tokenType, ANTLR_UINT8* text);
+
+ TreeTypePtr dupTree( const TreeTypePtr& tree);
+ TreeTypePtr dupTree( const TreeType* tree);
+
+ /// Sends the required debugging events for duplicating a tree
+ /// to the debugger.
+ ///
+ void simulateTreeConstruction(TreeTypePtr& tree);
};
-}
+}
#include "antlr3commontreeadaptor.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreeadaptor.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreeadaptor.inl
index 6b06a6758d..6e191b2a15 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreeadaptor.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreeadaptor.inl
@@ -1,554 +1,554 @@
-namespace antlr3 {
-
-template <typename ImplTraits>
-CommonResourcePoolManager<ImplTraits>::CommonResourcePoolManager(CommonTreeStore<ImplTraits> * pool)
- : m_pool(pool)
-{}
-
-template <typename ImplTraits>
-CommonResourcePoolManager<ImplTraits>::CommonResourcePoolManager()
- : m_pool(NULL)
-{}
-
-template <typename ImplTraits>
-CommonResourcePoolManager<ImplTraits>::~CommonResourcePoolManager()
-{};
-
-template <typename ImplTraits>
-void
-CommonResourcePoolManager<ImplTraits>::operator()(TreeType* releasedResource) const
-{
- if (releasedResource && m_pool)
- m_pool->reuse(releasedResource);
-}
-
-template <class ImplTraits>
-CommonTreeStore<ImplTraits>::CommonTreeStore()
- : m_manager(this)
-{}
-
-template <class ImplTraits>
-typename CommonTreeStore<ImplTraits>::TreeTypePtr
-CommonTreeStore<ImplTraits>::create()
-{
- if (m_recycleBin.empty())
- {
- TreeTypePtr retval = TreeTypePtr(new TreeType, m_manager);
- m_treeStore.push_back(std::unique_ptr<TreeType>(retval.get()));
- return retval;
- } else {
- TreeType* resource = m_recycleBin.back();
- m_recycleBin.pop_back();
- return TreeTypePtr(resource, m_manager);
- }
-}
-
-template <class ImplTraits>
-typename CommonTreeStore<ImplTraits>::CommonTokenType*
-CommonTreeStore<ImplTraits>::createToken()
-{
- CommonTokenType* retval = new CommonTokenType;
- m_tokenStore.push_back(std::unique_ptr<CommonTokenType>(retval));
- return retval;
-}
-
-template <class ImplTraits>
-typename CommonTreeStore<ImplTraits>::CommonTokenType*
-CommonTreeStore<ImplTraits>::createToken( const CommonTokenType* fromToken)
-{
- CommonTokenType* retval = new CommonTokenType(*fromToken);
- m_tokenStore.push_back(std::unique_ptr<CommonTokenType>(retval));
- return retval;
-}
-
-template <class ImplTraits>
-void
-CommonTreeStore<ImplTraits>::reuse(TreeType* releasedResource)
-{
- if (contains(m_recycleBin, releasedResource))
- {
- throw std::string("Grrr double reuse");
- }
- releasedResource->reuse();
- m_recycleBin.push_back(releasedResource);
-}
-
-template<class ImplTraits>
-CommonTreeAdaptor<ImplTraits>::CommonTreeAdaptor(DebuggerType*)
-{}
-
-template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::nilNode()
-{
- return this->create(NULL);
-}
-
-template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::dupTree( const TreeType* tree)
+namespace antlr3 {
+
+template <typename ImplTraits>
+CommonResourcePoolManager<ImplTraits>::CommonResourcePoolManager(CommonTreeStore<ImplTraits> * pool)
+ : m_pool(pool)
+{}
+
+template <typename ImplTraits>
+CommonResourcePoolManager<ImplTraits>::CommonResourcePoolManager()
+ : m_pool(NULL)
+{}
+
+template <typename ImplTraits>
+CommonResourcePoolManager<ImplTraits>::~CommonResourcePoolManager()
+{};
+
+template <typename ImplTraits>
+void
+CommonResourcePoolManager<ImplTraits>::operator()(TreeType* releasedResource) const
{
- if (tree == NULL)
- return NULL;
- return std::move(this->dupTreeImpl(tree, NULL));
+ if (releasedResource && m_pool)
+ m_pool->reuse(releasedResource);
}
-template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::dupTree( const TreeTypePtr& tree)
-{
- if (tree == NULL)
- return NULL;
- return std::move(dupTreeImpl(tree.get(), NULL));
-}
-
-template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::dupTreeImpl( const TreeType *root, TreeType* parent)
-{
- TreeTypePtr newTree(dupNode(root));
-
- // Ensure new subtree root has parent/child index set
- //
- this->setChildIndex( newTree, root->get_childIndex() );
- this->setParent(newTree, parent);
-
- ChildrenType const& r_children = root->get_children();
- for (auto i = r_children.begin(); i != r_children.end(); ++i)
- {
- // add child's clone
- this->addChild(newTree, dupTreeImpl(i->get(), newTree.get()));
- }
+template <class ImplTraits>
+CommonTreeStore<ImplTraits>::CommonTreeStore()
+ : m_manager(this)
+{}
+
+template <class ImplTraits>
+typename CommonTreeStore<ImplTraits>::TreeTypePtr
+CommonTreeStore<ImplTraits>::create()
+{
+ if (m_recycleBin.empty())
+ {
+ TreeTypePtr retval = TreeTypePtr(new TreeType, m_manager);
+ m_treeStore.push_back(std::unique_ptr<TreeType>(retval.get()));
+ return retval;
+ } else {
+ TreeType* resource = m_recycleBin.back();
+ m_recycleBin.pop_back();
+ return TreeTypePtr(resource, m_manager);
+ }
+}
+
+template <class ImplTraits>
+typename CommonTreeStore<ImplTraits>::CommonTokenType*
+CommonTreeStore<ImplTraits>::createToken()
+{
+ CommonTokenType* retval = new CommonTokenType;
+ m_tokenStore.push_back(std::unique_ptr<CommonTokenType>(retval));
+ return retval;
+}
- return newTree;
-}
+template <class ImplTraits>
+typename CommonTreeStore<ImplTraits>::CommonTokenType*
+CommonTreeStore<ImplTraits>::createToken( const CommonTokenType* fromToken)
+{
+ CommonTokenType* retval = new CommonTokenType(*fromToken);
+ m_tokenStore.push_back(std::unique_ptr<CommonTokenType>(retval));
+ return retval;
+}
-template<class ImplTraits>
-void CommonTreeAdaptor<ImplTraits>::addChild( TreeTypePtr& t, TreeTypePtr& child)
-{
- if (t != NULL && child != NULL)
- {
- t->addChild(child);
- }
+template <class ImplTraits>
+void
+CommonTreeStore<ImplTraits>::reuse(TreeType* releasedResource)
+{
+ if (contains(m_recycleBin, releasedResource))
+ {
+ throw std::string("Grrr double reuse");
+ }
+ releasedResource->reuse();
+ m_recycleBin.push_back(releasedResource);
}
template<class ImplTraits>
-void CommonTreeAdaptor<ImplTraits>::addChild( TreeTypePtr& t, TreeTypePtr&& child)
+CommonTreeAdaptor<ImplTraits>::CommonTreeAdaptor(DebuggerType*)
+{}
+
+template<class ImplTraits>
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::nilNode()
{
- if (t != NULL && child != NULL)
- {
- t->addChild(child);
- }
+ return this->create(NULL);
}
template<class ImplTraits>
-void CommonTreeAdaptor<ImplTraits>::addChildToken( TreeTypePtr& t, CommonTokenType* child)
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::dupTree( const TreeType* tree)
{
- if (t != NULL && child != NULL)
- {
- this->addChild(t, this->create(child));
- }
+ if (tree == NULL)
+ return NULL;
+ return std::move(this->dupTreeImpl(tree, NULL));
}
template<class ImplTraits>
-void CommonTreeAdaptor<ImplTraits>::setParent( TreeTypePtr& child, TreeType* parent)
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::dupTree( const TreeTypePtr& tree)
{
- child->set_parent(parent);
+ if (tree == NULL)
+ return NULL;
+ return std::move(dupTreeImpl(tree.get(), NULL));
}
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeType*
-CommonTreeAdaptor<ImplTraits>::getParent( TreeTypePtr& child)
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::dupTreeImpl( const TreeType *root, TreeType* parent)
{
- if ( child==NULL )
- return NULL;
- return child->getParent();
+ TreeTypePtr newTree(dupNode(root));
+
+ // Ensure new subtree root has parent/child index set
+ //
+ this->setChildIndex( newTree, root->get_childIndex() );
+ this->setParent(newTree, parent);
+
+ ChildrenType const& r_children = root->get_children();
+ for (auto i = r_children.begin(); i != r_children.end(); ++i)
+ {
+ // add child's clone
+ this->addChild(newTree, dupTreeImpl(i->get(), newTree.get()));
+ }
+
+ return newTree;
}
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::errorNode( CommonTokenType*,
- const CommonTokenType*,
- const CommonTokenType*)
+void CommonTreeAdaptor<ImplTraits>::addChild( TreeTypePtr& t, TreeTypePtr& child)
{
- // Use the supplied common tree node stream to get another tree from the factory
- // TODO: Look at creating the erronode as in Java, but this is complicated by the
- // need to track and free the memory allocated to it, so for now, we just
- // want something in the tree that isn't a NULL pointer.
- //
- return this->create( CommonTokenType::TOKEN_INVALID, "Tree Error Node");
+ if (t != NULL && child != NULL)
+ {
+ t->addChild(child);
+ }
+}
+template<class ImplTraits>
+void CommonTreeAdaptor<ImplTraits>::addChild( TreeTypePtr& t, TreeTypePtr&& child)
+{
+ if (t != NULL && child != NULL)
+ {
+ t->addChild(child);
+ }
}
template<class ImplTraits>
-bool CommonTreeAdaptor<ImplTraits>::isNilNode( TreeTypePtr& t)
+void CommonTreeAdaptor<ImplTraits>::addChildToken( TreeTypePtr& t, CommonTokenType* child)
{
- return t->isNilNode();
+ if (t != NULL && child != NULL)
+ {
+ this->addChild(t, this->create(child));
+ }
}
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::becomeRoot( TreeTypePtr& newRootTree, TreeTypePtr& oldRootTree)
+void CommonTreeAdaptor<ImplTraits>::setParent( TreeTypePtr& child, TreeType* parent)
{
- /* Protect against tree rewrites if we are in some sort of error
- * state, but have tried to recover. In C we can end up with a null pointer
- * for a tree that was not produced.
- */
- if (newRootTree == NULL)
- {
- return std::move(oldRootTree);
- }
+ child->set_parent(parent);
+}
- /* root is just the new tree as is if there is no
- * current root tree.
- */
- if (oldRootTree == NULL)
- {
- return std::move(newRootTree);
- }
+template<class ImplTraits>
+typename CommonTreeAdaptor<ImplTraits>::TreeType*
+CommonTreeAdaptor<ImplTraits>::getParent( TreeTypePtr& child)
+{
+ if ( child==NULL )
+ return NULL;
+ return child->getParent();
+}
- /* Produce ^(nil real-node)
- */
- if (newRootTree->isNilNode())
- {
- if (newRootTree->getChildCount() > 1)
- {
- /* TODO: Handle tree exceptions
- */
- fprintf(stderr, "More than one node as root! TODO: Create tree exception handling\n");
- return std::move(newRootTree);
- }
+template<class ImplTraits>
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::errorNode( CommonTokenType*,
+ const CommonTokenType*,
+ const CommonTokenType*)
+{
+ // Use the supplied common tree node stream to get another tree from the factory
+ // TODO: Look at creating the erronode as in Java, but this is complicated by the
+ // need to track and free the memory allocated to it, so for now, we just
+ // want something in the tree that isn't a NULL pointer.
+ //
+ return this->create( CommonTokenType::TOKEN_INVALID, "Tree Error Node");
- /* The new root is the first child, keep track of the original newRoot
- * because if it was a Nil Node, then we can reuse it now.
- */
- TreeTypePtr saveRoot = std::move(newRootTree);
- newRootTree = std::move(saveRoot->getChild(0));
+}
- // Will Reclaim the old nilNode() saveRoot here
- }
+template<class ImplTraits>
+bool CommonTreeAdaptor<ImplTraits>::isNilNode( TreeTypePtr& t)
+{
+ return t->isNilNode();
+}
- /* Add old root into new root. addChild takes care of the case where oldRoot
- * is a flat list (nill rooted tree). All children of oldroot are added to
- * new root.
- */
- newRootTree->addChild(oldRootTree);
+template<class ImplTraits>
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::becomeRoot( TreeTypePtr& newRootTree, TreeTypePtr& oldRootTree)
+{
+ /* Protect against tree rewrites if we are in some sort of error
+ * state, but have tried to recover. In C we can end up with a null pointer
+ * for a tree that was not produced.
+ */
+ if (newRootTree == NULL)
+ {
+ return std::move(oldRootTree);
+ }
- /* Always returns new root structure
- */
- return std::move(newRootTree);
-}
+ /* root is just the new tree as is if there is no
+ * current root tree.
+ */
+ if (oldRootTree == NULL)
+ {
+ return std::move(newRootTree);
+ }
-template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::becomeRoot( TreeTypePtr&& newRootTree, TreeTypePtr& oldRootTree)
-{
- /* Protect against tree rewrites if we are in some sort of error
- * state, but have tried to recover. In C we can end up with a null pointer
- * for a tree that was not produced.
- */
- if (newRootTree == NULL)
- {
- return std::move(oldRootTree);
- }
-
- /* root is just the new tree as is if there is no
- * current root tree.
- */
- if (oldRootTree == NULL)
- {
- return std::move(newRootTree);
- }
-
- /* Produce ^(nil real-node)
- */
- if (newRootTree->isNilNode())
- {
- if (newRootTree->getChildCount() > 1)
- {
+ /* Produce ^(nil real-node)
+ */
+ if (newRootTree->isNilNode())
+ {
+ if (newRootTree->getChildCount() > 1)
+ {
/* TODO: Handle tree exceptions
- */
- fprintf(stderr, "More than one node as root! TODO: Create tree exception handling\n");
- return std::move(newRootTree);
- }
-
- /* The new root is the first child, keep track of the original newRoot
- * because if it was a Nil Node, then we can reuse it now.
- */
- TreeTypePtr saveRoot = std::move(newRootTree);
- newRootTree = std::move(saveRoot->getChild(0));
-
- // will Reclaim the old nilNode() here saveRoot.
- }
-
- /* Add old root into new root. addChild takes care of the case where oldRoot
- * is a flat list (nill rooted tree). All children of oldroot are added to
- * new root.
- */
- newRootTree->addChild(oldRootTree);
-
- /* Always returns new root structure
- */
- return std::move(newRootTree);
-}
-
+ */
+ fprintf(stderr, "More than one node as root! TODO: Create tree exception handling\n");
+ return std::move(newRootTree);
+ }
+
+ /* The new root is the first child, keep track of the original newRoot
+ * because if it was a Nil Node, then we can reuse it now.
+ */
+ TreeTypePtr saveRoot = std::move(newRootTree);
+ newRootTree = std::move(saveRoot->getChild(0));
+
+ // Will Reclaim the old nilNode() saveRoot here
+ }
+
+ /* Add old root into new root. addChild takes care of the case where oldRoot
+ * is a flat list (nill rooted tree). All children of oldroot are added to
+ * new root.
+ */
+ newRootTree->addChild(oldRootTree);
+
+ /* Always returns new root structure
+ */
+ return std::move(newRootTree);
+}
+
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::becomeRootToken( CommonTokenType* newRoot, TreeTypePtr& oldRoot)
-{
- return this->becomeRoot(this->create(newRoot), oldRoot);
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::becomeRoot( TreeTypePtr&& newRootTree, TreeTypePtr& oldRootTree)
+{
+ /* Protect against tree rewrites if we are in some sort of error
+ * state, but have tried to recover. In C we can end up with a null pointer
+ * for a tree that was not produced.
+ */
+ if (newRootTree == NULL)
+ {
+ return std::move(oldRootTree);
+ }
+
+ /* root is just the new tree as is if there is no
+ * current root tree.
+ */
+ if (oldRootTree == NULL)
+ {
+ return std::move(newRootTree);
+ }
+
+ /* Produce ^(nil real-node)
+ */
+ if (newRootTree->isNilNode())
+ {
+ if (newRootTree->getChildCount() > 1)
+ {
+ /* TODO: Handle tree exceptions
+ */
+ fprintf(stderr, "More than one node as root! TODO: Create tree exception handling\n");
+ return std::move(newRootTree);
+ }
+
+ /* The new root is the first child, keep track of the original newRoot
+ * because if it was a Nil Node, then we can reuse it now.
+ */
+ TreeTypePtr saveRoot = std::move(newRootTree);
+ newRootTree = std::move(saveRoot->getChild(0));
+
+ // will Reclaim the old nilNode() here saveRoot.
+ }
+
+ /* Add old root into new root. addChild takes care of the case where oldRoot
+ * is a flat list (nill rooted tree). All children of oldroot are added to
+ * new root.
+ */
+ newRootTree->addChild(oldRootTree);
+
+ /* Always returns new root structure
+ */
+ return std::move(newRootTree);
+}
+
+template<class ImplTraits>
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::becomeRootToken( CommonTokenType* newRoot, TreeTypePtr& oldRoot)
+{
+ return this->becomeRoot(this->create(newRoot), oldRoot);
}
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::create( CommonTokenType const* payload)
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::create( CommonTokenType const* payload)
{
- TreeTypePtr retval = TreeStoreType::create();
- retval->set_token(payload);
- return retval;
+ TreeTypePtr retval = TreeStoreType::create();
+ retval->set_token(payload);
+ return retval;
}
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::create( ANTLR_UINT32 tokenType, const CommonTokenType* fromToken)
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::create( ANTLR_UINT32 tokenType, const CommonTokenType* fromToken)
{
- /* Create the new token */
- auto newToken = this->createToken(fromToken);
- /* Set the type of the new token to that supplied */
- newToken->set_type(tokenType);
- /* Return a new node based upon this token */
- return this->create(newToken);
-}
+ /* Create the new token */
+ auto newToken = this->createToken(fromToken);
+ /* Set the type of the new token to that supplied */
+ newToken->set_type(tokenType);
+ /* Return a new node based upon this token */
+ return this->create(newToken);
+}
-template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::create( ANTLR_UINT32 tokenType, const CommonTokenType* fromToken, const char* text)
-{
- if (fromToken == NULL)
- return create(tokenType, text);
- /* Create the new token */
- auto newToken = this->createToken(fromToken);
- /* Set the type of the new token to that supplied */
- newToken->set_type(tokenType);
- /* Set the text of the token accordingly */
- newToken->setText(text);
- /* Return a new node based upon this token */
- return this->create(newToken);
-}
+template<class ImplTraits>
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::create( ANTLR_UINT32 tokenType, const CommonTokenType* fromToken, const char* text)
+{
+ if (fromToken == NULL)
+ return create(tokenType, text);
+ /* Create the new token */
+ auto newToken = this->createToken(fromToken);
+ /* Set the type of the new token to that supplied */
+ newToken->set_type(tokenType);
+ /* Set the text of the token accordingly */
+ newToken->setText(text);
+ /* Return a new node based upon this token */
+ return this->create(newToken);
+}
-template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::create( ANTLR_UINT32 tokenType, const CommonTokenType* fromToken, typename CommonTreeAdaptor<ImplTraits>::StringType const& text)
-{
- if (fromToken == NULL)
- return create(tokenType, text);
- /* Create the new token */
- auto newToken = this->createToken(fromToken);
- /* Set the type of the new token to that supplied */
- newToken->set_type(tokenType);
- /* Set the text of the token accordingly */
- newToken->set_tokText(text);
- /* Return a new node based upon this token */
- return this->create(newToken);
-}
+template<class ImplTraits>
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::create( ANTLR_UINT32 tokenType, const CommonTokenType* fromToken, typename CommonTreeAdaptor<ImplTraits>::StringType const& text)
+{
+ if (fromToken == NULL)
+ return create(tokenType, text);
+ /* Create the new token */
+ auto newToken = this->createToken(fromToken);
+ /* Set the type of the new token to that supplied */
+ newToken->set_type(tokenType);
+ /* Set the text of the token accordingly */
+ newToken->set_tokText(text);
+ /* Return a new node based upon this token */
+ return this->create(newToken);
+}
-template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::create( ANTLR_UINT32 tokenType, const char* text)
-{
- auto fromToken = this->createToken(tokenType, text);
- return this->create(fromToken);
+template<class ImplTraits>
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::create( ANTLR_UINT32 tokenType, const char* text)
+{
+ auto fromToken = this->createToken(tokenType, text);
+ return this->create(fromToken);
}
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::create( ANTLR_UINT32 tokenType, typename CommonTreeAdaptor<ImplTraits>::StringType const& text)
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::create( ANTLR_UINT32 tokenType, typename CommonTreeAdaptor<ImplTraits>::StringType const& text)
{
- auto fromToken = this->createToken(tokenType, text);
- return this->create(fromToken);
+ auto fromToken = this->createToken(tokenType, text);
+ return this->create(fromToken);
}
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::dupNode(const TreeType* treeNode)
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::dupNode(const TreeType* treeNode)
{
- if (treeNode == NULL)
- return TreeStoreType::null();
- TreeTypePtr retval(TreeStoreType::create());
- treeNode->dupNode(retval.get());
- return retval;
+ if (treeNode == NULL)
+ return TreeStoreType::null();
+ TreeTypePtr retval(TreeStoreType::create());
+ treeNode->dupNode(retval.get());
+ return retval;
}
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
-CommonTreeAdaptor<ImplTraits>::dupNode(const TreeTypePtr& treeNode)
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr
+CommonTreeAdaptor<ImplTraits>::dupNode(const TreeTypePtr& treeNode)
{
- if (treeNode == NULL)
- return TreeStoreType::null();
- TreeTypePtr retval(TreeStoreType::create());
- treeNode->dupNode(retval.get());
- return retval;
+ if (treeNode == NULL)
+ return TreeStoreType::null();
+ TreeTypePtr retval(TreeStoreType::create());
+ treeNode->dupNode(retval.get());
+ return retval;
}
template<class ImplTraits>
-ANTLR_UINT32 CommonTreeAdaptor<ImplTraits>::getType( TreeTypePtr& t)
+ANTLR_UINT32 CommonTreeAdaptor<ImplTraits>::getType( TreeTypePtr& t)
{
- if ( t==NULL)
- return CommonTokenType::TOKEN_INVALID;
- return t->getType();
+ if ( t==NULL)
+ return CommonTokenType::TOKEN_INVALID;
+ return t->getType();
}
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::StringType CommonTreeAdaptor<ImplTraits>::getText( TreeTypePtr& t)
+typename CommonTreeAdaptor<ImplTraits>::StringType CommonTreeAdaptor<ImplTraits>::getText( TreeTypePtr& t)
{
- return t->getText();
+ return t->getText();
}
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr& CommonTreeAdaptor<ImplTraits>::getChild( TreeTypePtr& t, ANTLR_UINT32 i)
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr& CommonTreeAdaptor<ImplTraits>::getChild( TreeTypePtr& t, ANTLR_UINT32 i)
{
- if ( t==NULL )
- return NULL;
- return t->getChild(i);
+ if ( t==NULL )
+ return NULL;
+ return t->getChild(i);
}
template<class ImplTraits>
-void CommonTreeAdaptor<ImplTraits>::setChild( TreeTypePtr& t, ANTLR_UINT32 i, TreeTypePtr& child)
+void CommonTreeAdaptor<ImplTraits>::setChild( TreeTypePtr& t, ANTLR_UINT32 i, TreeTypePtr& child)
{
- t->setChild(i, child);
+ t->setChild(i, child);
}
template<class ImplTraits>
-void CommonTreeAdaptor<ImplTraits>::deleteChild( TreeTypePtr& t, ANTLR_UINT32 i)
+void CommonTreeAdaptor<ImplTraits>::deleteChild( TreeTypePtr& t, ANTLR_UINT32 i)
{
- t->deleteChild(i);
+ t->deleteChild(i);
}
template<class ImplTraits>
-void CommonTreeAdaptor<ImplTraits>::setChildIndex( TreeTypePtr& t, ANTLR_INT32 i)
+void CommonTreeAdaptor<ImplTraits>::setChildIndex( TreeTypePtr& t, ANTLR_INT32 i)
{
- if( t!= NULL)
- t->set_childIndex(i);
+ if( t!= NULL)
+ t->set_childIndex(i);
}
template<class ImplTraits>
-ANTLR_INT32 CommonTreeAdaptor<ImplTraits>::getChildIndex( TreeTypePtr& t)
+ANTLR_INT32 CommonTreeAdaptor<ImplTraits>::getChildIndex( TreeTypePtr& t)
{
- if ( t==NULL )
- return 0;
- return t->getChildIndex();
+ if ( t==NULL )
+ return 0;
+ return t->getChildIndex();
}
template<class ImplTraits>
-ANTLR_UINT32 CommonTreeAdaptor<ImplTraits>::getChildCount( TreeTypePtr& t)
+ANTLR_UINT32 CommonTreeAdaptor<ImplTraits>::getChildCount( TreeTypePtr& t)
{
- if ( t==NULL )
- return 0;
- return t->getChildCount();
+ if ( t==NULL )
+ return 0;
+ return t->getChildCount();
}
template<class ImplTraits>
-ANTLR_UINT64 CommonTreeAdaptor<ImplTraits>::getUniqueID( TreeTypePtr& node )
+ANTLR_UINT64 CommonTreeAdaptor<ImplTraits>::getUniqueID( TreeTypePtr& node )
{
- return reinterpret_cast<ANTLR_UINT64>(node);
+ return reinterpret_cast<ANTLR_UINT64>(node);
}
template<class ImplTraits>
typename CommonTreeAdaptor<ImplTraits>::CommonTokenType*
-CommonTreeAdaptor<ImplTraits>::createToken( ANTLR_UINT32 tokenType, const char* text)
+CommonTreeAdaptor<ImplTraits>::createToken( ANTLR_UINT32 tokenType, const char* text)
{
- CommonTokenType* newToken = TreeStoreType::createToken();
- newToken->set_tokText( text );
- newToken->set_type(tokenType);
- return newToken;
+ CommonTokenType* newToken = TreeStoreType::createToken();
+ newToken->set_tokText( text );
+ newToken->set_type(tokenType);
+ return newToken;
}
template<class ImplTraits>
typename CommonTreeAdaptor<ImplTraits>::CommonTokenType*
-CommonTreeAdaptor<ImplTraits>::createToken( ANTLR_UINT32 tokenType, typename CommonTreeAdaptor<ImplTraits>::StringType const& text)
+CommonTreeAdaptor<ImplTraits>::createToken( ANTLR_UINT32 tokenType, typename CommonTreeAdaptor<ImplTraits>::StringType const& text)
{
- CommonTokenType* newToken = TreeStoreType::createToken();
- newToken->set_tokText( text );
- newToken->set_type(tokenType);
- return newToken;
+ CommonTokenType* newToken = TreeStoreType::createToken();
+ newToken->set_tokText( text );
+ newToken->set_type(tokenType);
+ return newToken;
}
template<class ImplTraits>
typename CommonTreeAdaptor<ImplTraits>::CommonTokenType*
-CommonTreeAdaptor<ImplTraits>::createToken( const CommonTokenType* fromToken)
+CommonTreeAdaptor<ImplTraits>::createToken( const CommonTokenType* fromToken)
{
- CommonTokenType* newToken = TreeStoreType::createToken(fromToken);
- return newToken;
+ CommonTokenType* newToken = TreeStoreType::createToken(fromToken);
+ return newToken;
}
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::CommonTokenType*
-CommonTreeAdaptor<ImplTraits>::getToken( TreeTypePtr& t)
+typename CommonTreeAdaptor<ImplTraits>::CommonTokenType*
+CommonTreeAdaptor<ImplTraits>::getToken( TreeTypePtr& t)
{
- return t->getToken();
-}
+ return t->getToken();
+}
-template<class ImplTraits>
-void CommonTreeAdaptor<ImplTraits>::setTokenBoundaries( TreeTypePtr& t, const CommonTokenType* startToken, const CommonTokenType* stopToken)
-{
- ANTLR_MARKER start = 0;
- ANTLR_MARKER stop = 0;
+template<class ImplTraits>
+void CommonTreeAdaptor<ImplTraits>::setTokenBoundaries( TreeTypePtr& t, const CommonTokenType* startToken, const CommonTokenType* stopToken)
+{
+ ANTLR_MARKER start = 0;
+ ANTLR_MARKER stop = 0;
- if (t == NULL)
- return;
+ if (t == NULL)
+ return;
- if ( startToken != NULL)
- start = startToken->get_tokenIndex();
+ if ( startToken != NULL)
+ start = startToken->get_tokenIndex();
- if ( stopToken != NULL)
- stop = stopToken->get_tokenIndex();
+ if ( stopToken != NULL)
+ stop = stopToken->get_tokenIndex();
- t->set_startIndex(start);
- t->set_stopIndex(stop);
+ t->set_startIndex(start);
+ t->set_stopIndex(stop);
}
template<class ImplTraits>
-ANTLR_MARKER CommonTreeAdaptor<ImplTraits>::getTokenStartIndex( TreeTypePtr& t)
+ANTLR_MARKER CommonTreeAdaptor<ImplTraits>::getTokenStartIndex( TreeTypePtr& t)
{
- if ( t==NULL )
- return -1;
- return t->get_tokenStartIndex();
+ if ( t==NULL )
+ return -1;
+ return t->get_tokenStartIndex();
}
template<class ImplTraits>
-ANTLR_MARKER CommonTreeAdaptor<ImplTraits>::getTokenStopIndex( TreeTypePtr& t)
+ANTLR_MARKER CommonTreeAdaptor<ImplTraits>::getTokenStopIndex( TreeTypePtr& t)
{
- if ( t==NULL )
- return -1;
- return t->get_tokenStopIndex();
+ if ( t==NULL )
+ return -1;
+ return t->get_tokenStopIndex();
}
template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::StringType CommonTreeAdaptor<ImplTraits>::makeDot( TreeTypePtr& theTree)
+typename CommonTreeAdaptor<ImplTraits>::StringType CommonTreeAdaptor<ImplTraits>::makeDot( TreeTypePtr& theTree)
{
- // The string we are building up
- //
- StringType dotSpec;
- char buff[64];
- StringType text;
-
- dotSpec = "digraph {\n\n"
- "\tordering=out;\n"
- "\tranksep=.4;\n"
- "\tbgcolor=\"lightgrey\"; node [shape=box, fixedsize=false, fontsize=12, fontname=\"Helvetica-bold\", fontcolor=\"blue\"\n"
- "\twidth=.25, height=.25, color=\"black\", fillcolor=\"white\", style=\"filled, solid, bold\"];\n\n"
- "\tedge [arrowsize=.5, color=\"black\", style=\"bold\"]\n\n";
+ // The string we are building up
+ //
+ StringType dotSpec;
+ char buff[64];
+ StringType text;
+
+ dotSpec = "digraph {\n\n"
+ "\tordering=out;\n"
+ "\tranksep=.4;\n"
+ "\tbgcolor=\"lightgrey\"; node [shape=box, fixedsize=false, fontsize=12, fontname=\"Helvetica-bold\", fontcolor=\"blue\"\n"
+ "\twidth=.25, height=.25, color=\"black\", fillcolor=\"white\", style=\"filled, solid, bold\"];\n\n"
+ "\tedge [arrowsize=.5, color=\"black\", style=\"bold\"]\n\n";
- if (theTree == NULL)
- {
- // No tree, so create a blank spec
- //
- dotSpec->append("n0[label=\"EMPTY TREE\"]\n");
- return dotSpec;
- }
+ if (theTree == NULL)
+ {
+ // No tree, so create a blank spec
+ //
+ dotSpec->append("n0[label=\"EMPTY TREE\"]\n");
+ return dotSpec;
+ }
sprintf(buff, "\tn%p[label=\"", theTree);
- dotSpec.append(buff);
+ dotSpec.append(buff);
text = this->getText(theTree);
for (std::size_t j = 0; j < text.size(); j++)
{
@@ -571,98 +571,98 @@ typename CommonTreeAdaptor<ImplTraits>::StringType CommonTreeAdaptor<ImplTraits
break;
}
}
- dotSpec->append("\"]\n");
+ dotSpec->append("\"]\n");
- // First produce the node defintions
- //
- this->defineDotNodes(theTree, dotSpec);
- dotSpec.append("\n");
- this->defineDotEdges(theTree, dotSpec);
-
- // Terminate the spec
- //
- dotSpec.append("\n}");
+ // First produce the node defintions
+ //
+ this->defineDotNodes(theTree, dotSpec);
+ dotSpec.append("\n");
+ this->defineDotEdges(theTree, dotSpec);
+
+ // Terminate the spec
+ //
+ dotSpec.append("\n}");
- // Result
- //
- return dotSpec;
+ // Result
+ //
+ return dotSpec;
}
template<class ImplTraits>
-void CommonTreeAdaptor<ImplTraits>::replaceChildren( TreeTypePtr parent, ANTLR_INT32 startChildIndex, ANTLR_INT32 stopChildIndex, TreeTypePtr t)
+void CommonTreeAdaptor<ImplTraits>::replaceChildren( TreeTypePtr parent, ANTLR_INT32 startChildIndex, ANTLR_INT32 stopChildIndex, TreeTypePtr t)
{
- if (parent != NULL)
- parent->replaceChildren(startChildIndex, stopChildIndex, t);
+ if (parent != NULL)
+ parent->replaceChildren(startChildIndex, stopChildIndex, t);
}
template<class ImplTraits>
CommonTreeAdaptor<ImplTraits>::~CommonTreeAdaptor()
{
-#ifdef ANTLR3_DEBUG
- std::cout << "SZ" << TreeStoreType::size() << std::endl;
- std::cout << "RZ" << TreeStoreType::m_recycleBin.size() << std::endl;
-
- auto i = TreeStoreType::m_treeStore.begin();
-
- std::cout
- << ' '
- << "Node " << '\t' << "Parent " << '\t' << "Type" << '\t' << "toStringTree" << std::endl;
-
- for(; i != TreeStoreType::m_treeStore.end(); ++i)
- {
- std::cout
- << (TreeStoreType::contains(TreeStoreType::m_recycleBin, i->get()) ? '*' : ' ')
- << i->get() << '\t'
- << (const void *) (*i)->get_parent() << '\t'
- << (*i)->getType() << '\t'
- << (*i)->getChildCount() << '\t'
- << (*i)->toStringTree() << '\t'
- << std::endl;
- }
-#endif
-}
-
-template<class ImplTraits>
-void CommonTreeAdaptor<ImplTraits>::defineDotNodes(TreeTypePtr t, const StringType& dotSpec)
-{
- // How many nodes are we talking about?
- //
- int nCount;
- int i;
- TreeTypePtr child;
- char buff[64];
- StringType text;
- int j;
-
- // Count the nodes
- //
- nCount = this->getChildCount(t);
-
- if (nCount == 0)
- {
- // This will already have been included as a child of another node
- // so there is nothing to add.
- //
- return;
- }
-
- // For each child of the current tree, define a node using the
- // memory address of the node to name it
- //
- for (i = 0; i<nCount; i++)
- {
-
- // Pick up a pointer for the child
- //
- child = this->getChild(t, i);
-
- // Name the node
- //
- sprintf(buff, "\tn%p[label=\"", child);
- dotSpec->append(buff);
- text = this->getText(child);
- for (j = 0; j < text.size(); j++)
- {
+#ifdef ANTLR3_DEBUG
+ std::cout << "SZ" << TreeStoreType::size() << std::endl;
+ std::cout << "RZ" << TreeStoreType::m_recycleBin.size() << std::endl;
+
+ auto i = TreeStoreType::m_treeStore.begin();
+
+ std::cout
+ << ' '
+ << "Node " << '\t' << "Parent " << '\t' << "Type" << '\t' << "toStringTree" << std::endl;
+
+ for(; i != TreeStoreType::m_treeStore.end(); ++i)
+ {
+ std::cout
+ << (TreeStoreType::contains(TreeStoreType::m_recycleBin, i->get()) ? '*' : ' ')
+ << i->get() << '\t'
+ << (const void *) (*i)->get_parent() << '\t'
+ << (*i)->getType() << '\t'
+ << (*i)->getChildCount() << '\t'
+ << (*i)->toStringTree() << '\t'
+ << std::endl;
+ }
+#endif
+}
+
+template<class ImplTraits>
+void CommonTreeAdaptor<ImplTraits>::defineDotNodes(TreeTypePtr t, const StringType& dotSpec)
+{
+ // How many nodes are we talking about?
+ //
+ int nCount;
+ int i;
+ TreeTypePtr child;
+ char buff[64];
+ StringType text;
+ int j;
+
+ // Count the nodes
+ //
+ nCount = this->getChildCount(t);
+
+ if (nCount == 0)
+ {
+ // This will already have been included as a child of another node
+ // so there is nothing to add.
+ //
+ return;
+ }
+
+ // For each child of the current tree, define a node using the
+ // memory address of the node to name it
+ //
+ for (i = 0; i<nCount; i++)
+ {
+
+ // Pick up a pointer for the child
+ //
+ child = this->getChild(t, i);
+
+ // Name the node
+ //
+ sprintf(buff, "\tn%p[label=\"", child);
+ dotSpec->append(buff);
+ text = this->getText(child);
+ for (j = 0; j < text.size(); j++)
+ {
switch(text[j])
{
case '"':
@@ -681,67 +681,67 @@ void CommonTreeAdaptor<ImplTraits>::defineDotNodes(TreeTypePtr t, const StringTy
dotSpec += text[j];
break;
}
- }
- dotSpec.append("\"]\n");
-
- // And now define the children of this child (if any)
- //
- this->defineDotNodes(child, dotSpec);
- }
-
- // Done
- //
- return;
-}
-
-template<class ImplTraits>
-void CommonTreeAdaptor<ImplTraits>::defineDotEdges(TreeTypePtr t, const StringType& dotSpec)
-{
- // How many nodes are we talking about?
- //
- int nCount;
- if (t == NULL)
- {
- // No tree, so do nothing
- //
- return;
- }
-
- // Count the nodes
- //
- nCount = this->getChildCount(t);
-
- if (nCount == 0)
- {
- // This will already have been included as a child of another node
- // so there is nothing to add.
- //
- return;
- }
-
- // For each child, define an edge from this parent, then process
- // and children of this child in the same way
- //
- for (int i=0; i<nCount; i++)
- {
- TreeTypePtr child;
- char buff[128];
+ }
+ dotSpec.append("\"]\n");
+
+ // And now define the children of this child (if any)
+ //
+ this->defineDotNodes(child, dotSpec);
+ }
+
+ // Done
+ //
+ return;
+}
+
+template<class ImplTraits>
+void CommonTreeAdaptor<ImplTraits>::defineDotEdges(TreeTypePtr t, const StringType& dotSpec)
+{
+ // How many nodes are we talking about?
+ //
+ int nCount;
+ if (t == NULL)
+ {
+ // No tree, so do nothing
+ //
+ return;
+ }
+
+ // Count the nodes
+ //
+ nCount = this->getChildCount(t);
+
+ if (nCount == 0)
+ {
+ // This will already have been included as a child of another node
+ // so there is nothing to add.
+ //
+ return;
+ }
+
+ // For each child, define an edge from this parent, then process
+ // and children of this child in the same way
+ //
+ for (int i=0; i<nCount; i++)
+ {
+ TreeTypePtr child;
+ char buff[128];
StringType text;
- // Next child
- //
- child = this->getChild(t, i);
+ // Next child
+ //
+ child = this->getChild(t, i);
- // Create the edge relation
- //
- sprintf(buff, "\t\tn%p -> n%p\t\t// ", t, child);
-
- dotSpec.append(buff);
+ // Create the edge relation
+ //
+ sprintf(buff, "\t\tn%p -> n%p\t\t// ", t, child);
+
+ dotSpec.append(buff);
- // Document the relationship
- //
+ // Document the relationship
+ //
text = this->getText(t);
- for (std::size_t j = 0; j < text.size(); j++)
+ for (std::size_t j = 0; j < text.size(); j++)
{
switch(text[j])
{
@@ -787,186 +787,186 @@ void CommonTreeAdaptor<ImplTraits>::defineDotEdges(TreeTypePtr t, const StringTy
break;
}
}
- dotSpec.append("\n");
-
- // Define edges for this child
- //
- this->defineDotEdges(child, dotSpec);
- }
-
- // Done
- //
- return;
-}
-
-template<class ImplTraits>
-typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr CommonTreeAdaptor<ImplTraits>::rulePostProcessing( TreeTypePtr& root)
-{
- TreeTypePtr saveRoot = std::move(root);
-
- if (saveRoot != NULL && saveRoot->isNilNode())
- {
- if (saveRoot->getChildCount() == 0)
- {
- return TreeTypePtr(NULL, root.get_deleter());
- }
- else if (saveRoot->getChildCount() == 1)
- {
- TreeTypePtr newRoot = std::move(saveRoot->getChild(0));
- newRoot->set_parent(NULL);
- newRoot->set_childIndex(-1);
-
- // The root we were given was a nil node, with one child, which means it has
- // been abandoned and would be lost in the node factory.
- // saveRoot will be releases and put back into factory
- //
- return newRoot;
- }
- }
- return saveRoot;
+ dotSpec.append("\n");
+
+ // Define edges for this child
+ //
+ this->defineDotEdges(child, dotSpec);
+ }
+
+ // Done
+ //
+ return;
+}
+
+template<class ImplTraits>
+typename CommonTreeAdaptor<ImplTraits>::TreeTypePtr CommonTreeAdaptor<ImplTraits>::rulePostProcessing( TreeTypePtr& root)
+{
+ TreeTypePtr saveRoot = std::move(root);
+
+ if (saveRoot != NULL && saveRoot->isNilNode())
+ {
+ if (saveRoot->getChildCount() == 0)
+ {
+ return TreeTypePtr(NULL, root.get_deleter());
+ }
+ else if (saveRoot->getChildCount() == 1)
+ {
+ TreeTypePtr newRoot = std::move(saveRoot->getChild(0));
+ newRoot->set_parent(NULL);
+ newRoot->set_childIndex(-1);
+
+ // The root we were given was a nil node, with one child, which means it has
+ // been abandoned and would be lost in the node factory.
+ // saveRoot will be releases and put back into factory
+ //
+ return newRoot;
+ }
+ }
+ return saveRoot;
}
template<class ImplTraits>
DebugTreeAdaptor<ImplTraits>::DebugTreeAdaptor( DebuggerType* debugger )
{
- m_debugger = debugger;
+ m_debugger = debugger;
}
template<class ImplTraits>
void DebugTreeAdaptor<ImplTraits>::setDebugEventListener( DebuggerType* debugger)
{
- m_debugger = debugger;
+ m_debugger = debugger;
}
template<class ImplTraits>
-typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::nilNode()
+typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::nilNode()
{
- TreeTypePtr t = this->create(NULL);
- m_debugger->createNode(t);
- return t;
+ TreeTypePtr t = this->create(NULL);
+ m_debugger->createNode(t);
+ return t;
}
template<class ImplTraits>
-void DebugTreeAdaptor<ImplTraits>::addChild(TreeTypePtr& t, TreeTypePtr& child)
+void DebugTreeAdaptor<ImplTraits>::addChild(TreeTypePtr& t, TreeTypePtr& child)
{
- if (t != NULL && child != NULL)
- {
- t->addChild(child);
- m_debugger->addChild(t, child);
- }
+ if (t != NULL && child != NULL)
+ {
+ t->addChild(child);
+ m_debugger->addChild(t, child);
+ }
}
template<class ImplTraits>
-void DebugTreeAdaptor<ImplTraits>::addChildToken(TreeTypePtr& t, CommonTokenType* child)
+void DebugTreeAdaptor<ImplTraits>::addChildToken(TreeTypePtr& t, CommonTokenType* child)
{
- TreeTypePtr tc;
- if (t != NULL && child != NULL)
- {
- tc = this->create(child);
- this->addChild(t, tc);
- m_debugger->addChild(t, tc);
- }
+ TreeTypePtr tc;
+ if (t != NULL && child != NULL)
+ {
+ tc = this->create(child);
+ this->addChild(t, tc);
+ m_debugger->addChild(t, tc);
+ }
}
template<class ImplTraits>
-typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::becomeRoot( TreeTypePtr& newRootTree, TreeTypePtr& oldRootTree )
+typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::becomeRoot( TreeTypePtr& newRootTree, TreeTypePtr& oldRootTree )
{
- TreeTypePtr t = super::becomeRoot(newRootTree, oldRootTree);
- m_debugger->becomeRoot(newRootTree, oldRootTree);
- return t;
+ TreeTypePtr t = super::becomeRoot(newRootTree, oldRootTree);
+ m_debugger->becomeRoot(newRootTree, oldRootTree);
+ return t;
}
template<class ImplTraits>
-typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::becomeRootToken(CommonTokenType* newRoot, TreeTypePtr& oldRoot)
+typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::becomeRootToken(CommonTokenType* newRoot, TreeTypePtr& oldRoot)
{
- TreeTypePtr t = super::becomeRoot(this->create(newRoot), oldRoot);
- m_debugger->becomeRoot(t, oldRoot);
- return t;
+ TreeTypePtr t = super::becomeRoot(this->create(newRoot), oldRoot);
+ m_debugger->becomeRoot(t, oldRoot);
+ return t;
}
template<class ImplTraits>
-typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::createTypeToken(ANTLR_UINT32 tokenType, CommonTokenType* fromToken)
+typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::createTypeToken(ANTLR_UINT32 tokenType, CommonTokenType* fromToken)
{
- TreeTypePtr t;
- t = this->createTypeToken(tokenType, fromToken);
- m_debugger->createNode(t);
- return t;
+ TreeTypePtr t;
+ t = this->createTypeToken(tokenType, fromToken);
+ m_debugger->createNode(t);
+ return t;
}
template<class ImplTraits>
-typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::createTypeTokenText(ANTLR_UINT32 tokenType, CommonTokenType* fromToken, ANTLR_UINT8* text)
+typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::createTypeTokenText(ANTLR_UINT32 tokenType, CommonTokenType* fromToken, ANTLR_UINT8* text)
+{
+ TreeTypePtr t;
+ t = this->createTypeTokenText(tokenType, fromToken, text);
+ m_debugger->createNode(t);
+ return t;
+}
+
+template<class ImplTraits>
+typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::createTypeText( ANTLR_UINT32 tokenType, ANTLR_UINT8* text)
{
- TreeTypePtr t;
- t = this->createTypeTokenText(tokenType, fromToken, text);
- m_debugger->createNode(t);
- return t;
+ TreeTypePtr t;
+ t = this->createTypeText(tokenType, text);
+ m_debugger->createNode(t);
+ return t;
}
-
-template<class ImplTraits>
-typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::createTypeText( ANTLR_UINT32 tokenType, ANTLR_UINT8* text)
-{
- TreeTypePtr t;
- t = this->createTypeText(tokenType, text);
- m_debugger->createNode(t);
- return t;
-}
template<class ImplTraits>
-typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::dupTree( const TreeTypePtr& tree)
+typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::dupTree( const TreeTypePtr& tree)
{
- TreeTypePtr t;
-
- // Call the normal dup tree mechanism first
- //
- t = this->dupTreeImpl(tree, NULL);
-
- // In order to tell the debugger what we have just done, we now
- // simulate the tree building mechanism. THis will fire
- // lots of debugging events to the client and look like we
- // duped the tree..
- //
- this->simulateTreeConstruction( t);
-
- return t;
+ TreeTypePtr t;
+
+ // Call the normal dup tree mechanism first
+ //
+ t = this->dupTreeImpl(tree, NULL);
+
+ // In order to tell the debugger what we have just done, we now
+ // simulate the tree building mechanism. THis will fire
+ // lots of debugging events to the client and look like we
+ // duped the tree..
+ //
+ this->simulateTreeConstruction( t);
+
+ return t;
}
template<class ImplTraits>
-typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::dupTree( const TreeType* tree)
+typename DebugTreeAdaptor<ImplTraits>::TreeTypePtr DebugTreeAdaptor<ImplTraits>::dupTree( const TreeType* tree)
{
- TreeTypePtr t;
+ TreeTypePtr t;
- // Call the normal dup tree mechanism first
- //
- t = this->dupTreeImpl(tree, NULL);
+ // Call the normal dup tree mechanism first
+ //
+ t = this->dupTreeImpl(tree, NULL);
- // In order to tell the debugger what we have just done, we now
- // simulate the tree building mechanism. THis will fire
- // lots of debugging events to the client and look like we
- // duped the tree..
- //
- this->simulateTreeConstruction( t);
+ // In order to tell the debugger what we have just done, we now
+ // simulate the tree building mechanism. THis will fire
+ // lots of debugging events to the client and look like we
+ // duped the tree..
+ //
+ this->simulateTreeConstruction( t);
- return t;
+ return t;
}
template<class ImplTraits>
-void DebugTreeAdaptor<ImplTraits>::simulateTreeConstruction(TreeTypePtr& tree)
+void DebugTreeAdaptor<ImplTraits>::simulateTreeConstruction(TreeTypePtr& tree)
{
- ANTLR_UINT32 n;
- ANTLR_UINT32 i;
- TreeTypePtr child;
+ ANTLR_UINT32 n;
+ ANTLR_UINT32 i;
+ TreeTypePtr child;
- // Send the create node event
- //
- m_debugger->createNode(tree);
+ // Send the create node event
+ //
+ m_debugger->createNode(tree);
- n = this->getChildCount(tree);
- for (i = 0; i < n; i++)
- {
- child = this->getChild(tree, i);
- this->simulateTreeConstruction(child);
- m_debugger->addChild(tree, child);
- }
+ n = this->getChildCount(tree);
+ for (i = 0; i < n; i++)
+ {
+ child = this->getChild(tree, i);
+ this->simulateTreeConstruction(child);
+ m_debugger->addChild(tree, child);
+ }
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreenodestream.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreenodestream.hpp
index eaa7cac20e..3adf02e933 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreenodestream.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreenodestream.hpp
@@ -2,8 +2,8 @@
/// Definition of the ANTLR3 common tree node stream.
///
-#ifndef _ANTLR_COMMON_TREE_NODE_STREAM__HPP
-#define _ANTLR_COMMON_TREE_NODE_STREAM__HPP
+#ifndef _ANTLR_COMMON_TREE_NODE_STREAM__HPP
+#define _ANTLR_COMMON_TREE_NODE_STREAM__HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -33,254 +33,254 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits>
class CommonTreeNodeStream : public ImplTraits::TreeNodeIntStreamType
{
public:
- enum Constants
- {
- /// Token buffer initial size settings ( will auto increase)
- ///
- DEFAULT_INITIAL_BUFFER_SIZE = 100
- , INITIAL_CALL_STACK_SIZE = 10
- };
-
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
- typedef TreeType UnitType;
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::StringStreamType StringStreamType;
- typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
- typedef typename ImplTraits::TreeNodeIntStreamType IntStreamType;
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename AllocPolicyType::template VectorType<TreeTypePtr> NodesType;
- typedef typename AllocPolicyType::template VectorType< TreeWalkState<ImplTraits> > MarkersType;
- typedef typename AllocPolicyType::template StackType< ANTLR_INT32 > NodeStackType;
- typedef typename ImplTraits::TreeParserType ComponentType;
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
- typedef typename ImplTraits::TreeNodeIntStreamType BaseType;
+ enum Constants
+ {
+ /// Token buffer initial size settings ( will auto increase)
+ ///
+ DEFAULT_INITIAL_BUFFER_SIZE = 100
+ , INITIAL_CALL_STACK_SIZE = 10
+ };
+
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+ typedef TreeType UnitType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::StringStreamType StringStreamType;
+ typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
+ typedef typename ImplTraits::TreeNodeIntStreamType IntStreamType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename AllocPolicyType::template VectorType<TreeTypePtr> NodesType;
+ typedef typename AllocPolicyType::template VectorType< TreeWalkState<ImplTraits> > MarkersType;
+ typedef typename AllocPolicyType::template StackType< ANTLR_INT32 > NodeStackType;
+ typedef typename ImplTraits::TreeParserType ComponentType;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
+ typedef typename ImplTraits::TreeNodeIntStreamType BaseType;
public:
/// Dummy tree node that indicates a descent into a child
/// tree. Initialized by a call to create a new interface.
///
- TreeType m_DOWN;
+ TreeType m_DOWN;
/// Dummy tree node that indicates a descent up to a parent
/// tree. Initialized by a call to create a new interface.
///
- TreeType m_UP;
+ TreeType m_UP;
/// Dummy tree node that indicates the termination point of the
/// tree. Initialized by a call to create a new interface.
///
- TreeType m_EOF_NODE;
+ TreeType m_EOF_NODE;
/// Dummy node that is returned if we need to indicate an invalid node
/// for any reason.
///
- TreeType m_INVALID_NODE;
-
- /// The complete mapping from stream index to tree node.
- /// This buffer includes pointers to DOWN, UP, and EOF nodes.
- /// It is built upon ctor invocation. The elements are type
- /// Object as we don't what the trees look like.
- ///
- /// Load upon first need of the buffer so we can set token types
- /// of interest for reverseIndexing. Slows us down a wee bit to
- /// do all of the if p==-1 testing everywhere though, though in C
- /// you won't really be able to measure this.
- ///
- /// Must be freed when the tree node stream is torn down.
- ///
- NodesType m_nodes;
-
- /// Which tree are we navigating ?
+ TreeType m_INVALID_NODE;
+
+ /// The complete mapping from stream index to tree node.
+ /// This buffer includes pointers to DOWN, UP, and EOF nodes.
+ /// It is built upon ctor invocation. The elements are type
+ /// Object as we don't what the trees look like.
+ ///
+ /// Load upon first need of the buffer so we can set token types
+ /// of interest for reverseIndexing. Slows us down a wee bit to
+ /// do all of the if p==-1 testing everywhere though, though in C
+ /// you won't really be able to measure this.
+ ///
+ /// Must be freed when the tree node stream is torn down.
+ ///
+ NodesType m_nodes;
+
+ /// Which tree are we navigating ?
///
- TreeTypePtr m_root;
+ TreeTypePtr m_root;
/// Pointer to tree adaptor interface that manipulates/builds
/// the tree.
///
- TreeAdaptorType* m_adaptor;
+ TreeAdaptorType* m_adaptor;
/// As we walk down the nodes, we must track parent nodes so we know
/// where to go after walking the last child of a node. When visiting
/// a child, push current node and current index (current index
/// is first stored in the tree node structure to avoid two stacks.
///
- NodeStackType m_nodeStack;
+ NodeStackType m_nodeStack;
- /// The current index into the nodes vector of the current tree
- /// we are parsing and possibly rewriting.
- ///
- ANTLR_INT32 m_p;
+ /// The current index into the nodes vector of the current tree
+ /// we are parsing and possibly rewriting.
+ ///
+ ANTLR_INT32 m_p;
/// Which node are we currently visiting?
///
- TreeTypePtr m_currentNode;
+ TreeTypePtr m_currentNode;
/// Which node did we last visit? Used for LT(-1)
///
- TreeTypePtr m_previousNode;
+ TreeTypePtr m_previousNode;
/// Which child are we currently visiting? If -1 we have not visited
/// this node yet; next consume() request will set currentIndex to 0.
///
- ANTLR_INT32 m_currentChildIndex;
+ ANTLR_INT32 m_currentChildIndex;
/// What node index did we just consume? i=0..n-1 for n node trees.
/// IntStream.next is hence 1 + this value. Size will be same.
///
- ANTLR_MARKER m_absoluteNodeIndex;
+ ANTLR_MARKER m_absoluteNodeIndex;
/// Buffer tree node stream for use with LT(i). This list grows
/// to fit new lookahead depths, but consume() wraps like a circular
/// buffer.
///
- TreeTypePtr* m_lookAhead;
+ TreeTypePtr* m_lookAhead;
/// Number of elements available in the lookahead buffer at any point in
/// time. This is the current size of the array.
///
- ANTLR_UINT32 m_lookAheadLength;
+ ANTLR_UINT32 m_lookAheadLength;
- /// lookAhead[head] is the first symbol of lookahead, LT(1).
+ /// lookAhead[head] is the first symbol of lookahead, LT(1).
///
- ANTLR_UINT32 m_head;
+ ANTLR_UINT32 m_head;
/// Add new lookahead at lookahead[tail]. tail wraps around at the
/// end of the lookahead buffer so tail could be less than head.
///
- ANTLR_UINT32 m_tail;
+ ANTLR_UINT32 m_tail;
/// Calls to mark() may be nested so we have to track a stack of
/// them. The marker is an index into this stack. Index 0 is
/// the first marker. This is a List<TreeWalkState>
///
- MarkersType m_markers;
+ MarkersType m_markers;
- /// Indicates whether this node stream was derived from a prior
- /// node stream to be used by a rewriting tree parser for instance.
- /// If this flag is set to ANTLR_TRUE, then when this stream is
- /// closed it will not free the root tree as this tree always
- /// belongs to the origniating node stream.
- ///
- bool m_isRewriter;
+ /// Indicates whether this node stream was derived from a prior
+ /// node stream to be used by a rewriting tree parser for instance.
+ /// If this flag is set to ANTLR_TRUE, then when this stream is
+ /// closed it will not free the root tree as this tree always
+ /// belongs to the origniating node stream.
+ ///
+ bool m_isRewriter;
/// If set to ANTLR_TRUE then the navigation nodes UP, DOWN are
/// duplicated rather than reused within the tree.
///
- bool m_uniqueNavigationNodes;
+ bool m_uniqueNavigationNodes;
public:
// INTERFACE
- //
- CommonTreeNodeStream( ANTLR_UINT32 hint );
- CommonTreeNodeStream( const CommonTreeNodeStream& ctn );
- CommonTreeNodeStream( TreeTypePtr tree, ANTLR_UINT32 hint );
-
- void init( ANTLR_UINT32 hint );
- ~CommonTreeNodeStream();
-
- /// Get tree node at current input pointer + i ahead where i=1 is next node.
- /// i<0 indicates nodes in the past. So LT(-1) is previous node, but
- /// implementations are not required to provide results for k < -1.
- /// LT(0) is undefined. For i>=n, return null.
- /// Return NULL for LT(0) and any index that results in an absolute address
- /// that is negative (beyond the start of the list).
- ///
- /// This is analogous to the LT() method of the TokenStream, but this
- /// returns a tree node instead of a token. Makes code gen identical
- /// for both parser and tree grammars. :)
- ///
- TreeTypePtr _LT(ANTLR_INT32 k);
-
- /// Where is this stream pulling nodes from? This is not the name, but
- /// the object that provides node objects.
- ///
- TreeTypePtr getTreeSource();
-
- /// What adaptor can tell me how to interpret/navigate nodes and
- /// trees. E.g., get text of a node.
- ///
- TreeAdaptorType* getTreeAdaptor();
-
- /// As we flatten the tree, we use UP, DOWN nodes to represent
- /// the tree structure. When debugging we need unique nodes
- /// so we have to instantiate new ones. When doing normal tree
- /// parsing, it's slow and a waste of memory to create unique
- /// navigation nodes. Default should be false;
- ///
+ //
+ CommonTreeNodeStream( ANTLR_UINT32 hint );
+ CommonTreeNodeStream( const CommonTreeNodeStream& ctn );
+ CommonTreeNodeStream( TreeTypePtr tree, ANTLR_UINT32 hint );
+
+ void init( ANTLR_UINT32 hint );
+ ~CommonTreeNodeStream();
+
+ /// Get tree node at current input pointer + i ahead where i=1 is next node.
+ /// i<0 indicates nodes in the past. So LT(-1) is previous node, but
+ /// implementations are not required to provide results for k < -1.
+ /// LT(0) is undefined. For i>=n, return null.
+ /// Return NULL for LT(0) and any index that results in an absolute address
+ /// that is negative (beyond the start of the list).
+ ///
+ /// This is analogous to the LT() method of the TokenStream, but this
+ /// returns a tree node instead of a token. Makes code gen identical
+ /// for both parser and tree grammars. :)
+ ///
+ TreeTypePtr _LT(ANTLR_INT32 k);
+
+ /// Where is this stream pulling nodes from? This is not the name, but
+ /// the object that provides node objects.
+ ///
+ TreeTypePtr getTreeSource();
+
+ /// What adaptor can tell me how to interpret/navigate nodes and
+ /// trees. E.g., get text of a node.
+ ///
+ TreeAdaptorType* getTreeAdaptor();
+
+ /// As we flatten the tree, we use UP, DOWN nodes to represent
+ /// the tree structure. When debugging we need unique nodes
+ /// so we have to instantiate new ones. When doing normal tree
+ /// parsing, it's slow and a waste of memory to create unique
+ /// navigation nodes. Default should be false;
+ ///
void set_uniqueNavigationNodes(bool uniqueNavigationNodes);
- StringType toString();
+ StringType toString();
- /// Return the text of all nodes from start to stop, inclusive.
- /// If the stream does not buffer all the nodes then it can still
- /// walk recursively from start until stop. You can always return
- /// null or "" too, but users should not access $ruleLabel.text in
- /// an action of course in that case.
- ///
- StringType toStringSS(TreeTypePtr start, TreeTypePtr stop);
+ /// Return the text of all nodes from start to stop, inclusive.
+ /// If the stream does not buffer all the nodes then it can still
+ /// walk recursively from start until stop. You can always return
+ /// null or "" too, but users should not access $ruleLabel.text in
+ /// an action of course in that case.
+ ///
+ StringType toStringSS(TreeTypePtr start, TreeTypePtr stop);
- /// Return the text of all nodes from start to stop, inclusive, into the
- /// supplied buffer.
- /// If the stream does not buffer all the nodes then it can still
- /// walk recursively from start until stop. You can always return
- /// null or "" too, but users should not access $ruleLabel.text in
- /// an action of course in that case.
- ///
- void toStringWork(TreeTypePtr start, TreeTypePtr stop, StringType& buf);
+ /// Return the text of all nodes from start to stop, inclusive, into the
+ /// supplied buffer.
+ /// If the stream does not buffer all the nodes then it can still
+ /// walk recursively from start until stop. You can always return
+ /// null or "" too, but users should not access $ruleLabel.text in
+ /// an action of course in that case.
+ ///
+ void toStringWork(TreeTypePtr start, TreeTypePtr stop, StringType& buf);
- /// Get a tree node at an absolute index i; 0..n-1.
- /// If you don't want to buffer up nodes, then this method makes no
- /// sense for you.
- ///
- TreeTypePtr get(ANTLR_INT32 i);
+ /// Get a tree node at an absolute index i; 0..n-1.
+ /// If you don't want to buffer up nodes, then this method makes no
+ /// sense for you.
+ ///
+ TreeTypePtr get(ANTLR_INT32 i);
- // REWRITING TREES (used by tree parser)
+ // REWRITING TREES (used by tree parser)
- /// Replace from start to stop child index of parent with t, which might
- /// be a list. Number of children may be different
- /// after this call. The stream is notified because it is walking the
- /// tree and might need to know you are monkeying with the underlying
- /// tree. Also, it might be able to modify the node stream to avoid
- /// restreaming for future phases.
- ///
- /// If parent is null, don't do anything; must be at root of overall tree.
- /// Can't replace whatever points to the parent externally. Do nothing.
- ///
- void replaceChildren(TreeTypePtr parent, ANTLR_INT32 startChildIndex,
- ANTLR_INT32 stopChildIndex, TreeTypePtr t);
+ /// Replace from start to stop child index of parent with t, which might
+ /// be a list. Number of children may be different
+ /// after this call. The stream is notified because it is walking the
+ /// tree and might need to know you are monkeying with the underlying
+ /// tree. Also, it might be able to modify the node stream to avoid
+ /// restreaming for future phases.
+ ///
+ /// If parent is null, don't do anything; must be at root of overall tree.
+ /// Can't replace whatever points to the parent externally. Do nothing.
+ ///
+ void replaceChildren(TreeTypePtr parent, ANTLR_INT32 startChildIndex,
+ ANTLR_INT32 stopChildIndex, TreeTypePtr t);
- TreeTypePtr LB(ANTLR_INT32 k);
+ TreeTypePtr LB(ANTLR_INT32 k);
- /// As we flatten the tree, we use UP, DOWN nodes to represent
- /// the tree structure. When debugging we need unique nodes
- /// so instantiate new ones when uniqueNavigationNodes is true.
- ///
- void addNavigationNode(ANTLR_UINT32 ttype);
+ /// As we flatten the tree, we use UP, DOWN nodes to represent
+ /// the tree structure. When debugging we need unique nodes
+ /// so instantiate new ones when uniqueNavigationNodes is true.
+ ///
+ void addNavigationNode(ANTLR_UINT32 ttype);
- TreeTypePtr newDownNode();
+ TreeTypePtr newDownNode();
- TreeTypePtr newUpNode();
+ TreeTypePtr newUpNode();
- bool hasUniqueNavigationNodes() const;
+ bool hasUniqueNavigationNodes() const;
- ANTLR_UINT32 getLookaheadSize();
+ ANTLR_UINT32 getLookaheadSize();
- void push(ANTLR_INT32 index);
+ void push(ANTLR_INT32 index);
- ANTLR_INT32 pop();
+ ANTLR_INT32 pop();
- void reset();
+ void reset();
- void fillBufferRoot();
- void fillBuffer(TreeTypePtr t);
-
+ void fillBufferRoot();
+ void fillBuffer(TreeTypePtr t);
+
};
/** This structure is used to save the state information in the treenodestream
@@ -293,24 +293,24 @@ template<class ImplTraits>
class TreeWalkState : public ImplTraits::AllocPolicyType
{
public:
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
private:
- ANTLR_UINT32 m_currentChildIndex;
- ANTLR_MARKER m_absoluteNodeIndex;
- TreeTypePtr m_currentNode;
- TreeTypePtr m_previousNode;
- ANTLR_UINT32 m_nodeStackSize;
- TreeTypePtr m_lookAhead;
- ANTLR_UINT32 m_lookAheadLength;
- ANTLR_UINT32 m_tail;
- ANTLR_UINT32 m_head;
+ ANTLR_UINT32 m_currentChildIndex;
+ ANTLR_MARKER m_absoluteNodeIndex;
+ TreeTypePtr m_currentNode;
+ TreeTypePtr m_previousNode;
+ ANTLR_UINT32 m_nodeStackSize;
+ TreeTypePtr m_lookAhead;
+ ANTLR_UINT32 m_lookAheadLength;
+ ANTLR_UINT32 m_tail;
+ ANTLR_UINT32 m_head;
};
-}
+}
#include "antlr3commontreenodestream.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreenodestream.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreenodestream.inl
index 767cde410e..096e15db11 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreenodestream.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3commontreenodestream.inl
@@ -1,148 +1,148 @@
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits>
CommonTreeNodeStream<ImplTraits>::CommonTreeNodeStream(ANTLR_UINT32 hint)
{
- this->init(hint);
+ this->init(hint);
}
template<class ImplTraits>
void CommonTreeNodeStream<ImplTraits>::init( ANTLR_UINT32 hint )
{
- m_root = NULL;
- m_adaptor = new TreeAdaptorType;
- // Create the node list map
- //
- if (hint == 0)
- hint = DEFAULT_INITIAL_BUFFER_SIZE;
- m_nodes.reserve( DEFAULT_INITIAL_BUFFER_SIZE );
-
- m_p = -1;
- m_currentNode = NULL;
- m_previousNode = NULL;
- m_currentChildIndex = 0;
- m_absoluteNodeIndex = 0;
- m_lookAhead = NULL;
- m_lookAheadLength = 0;
- m_head = 0;
- m_tail = 0;
- m_uniqueNavigationNodes = false;
- m_isRewriter = false;
-
- CommonTokenType* token = new CommonTokenType(CommonTokenType::TOKEN_UP);
- token->set_tokText( "UP" );
- m_UP.set_token( token );
-
- token = new CommonTokenType(CommonTokenType::TOKEN_DOWN);
- token->set_tokText( "DOWN" );
- m_DOWN.set_token( token );
-
- token = new CommonTokenType(CommonTokenType::TOKEN_EOF);
- token->set_tokText( "EOF" );
- m_EOF_NODE.set_token( token );
-
- token = new CommonTokenType(CommonTokenType::TOKEN_INVALID);
- token->set_tokText( "INVALID" );
- m_EOF_NODE.set_token( token );
+ m_root = NULL;
+ m_adaptor = new TreeAdaptorType;
+ // Create the node list map
+ //
+ if (hint == 0)
+ hint = DEFAULT_INITIAL_BUFFER_SIZE;
+ m_nodes.reserve( DEFAULT_INITIAL_BUFFER_SIZE );
+
+ m_p = -1;
+ m_currentNode = NULL;
+ m_previousNode = NULL;
+ m_currentChildIndex = 0;
+ m_absoluteNodeIndex = 0;
+ m_lookAhead = NULL;
+ m_lookAheadLength = 0;
+ m_head = 0;
+ m_tail = 0;
+ m_uniqueNavigationNodes = false;
+ m_isRewriter = false;
+
+ CommonTokenType* token = new CommonTokenType(CommonTokenType::TOKEN_UP);
+ token->set_tokText( "UP" );
+ m_UP.set_token( token );
+
+ token = new CommonTokenType(CommonTokenType::TOKEN_DOWN);
+ token->set_tokText( "DOWN" );
+ m_DOWN.set_token( token );
+
+ token = new CommonTokenType(CommonTokenType::TOKEN_EOF);
+ token->set_tokText( "EOF" );
+ m_EOF_NODE.set_token( token );
+
+ token = new CommonTokenType(CommonTokenType::TOKEN_INVALID);
+ token->set_tokText( "INVALID" );
+ m_EOF_NODE.set_token( token );
}
template<class ImplTraits>
CommonTreeNodeStream<ImplTraits>::CommonTreeNodeStream( const CommonTreeNodeStream& ctn )
{
- m_root = ctn.m_root;
- m_adaptor = ctn.m_adaptor;
- m_nodes.reserve( DEFAULT_INITIAL_BUFFER_SIZE );
- m_nodeStack = ctn.m_nodeStack;
- m_p = -1;
- m_currentNode = NULL;
- m_previousNode = NULL;
- m_currentChildIndex = 0;
- m_absoluteNodeIndex = 0;
- m_lookAhead = NULL;
- m_lookAheadLength = 0;
- m_head = 0;
- m_tail = 0;
- m_uniqueNavigationNodes = false;
- m_isRewriter = true;
-
- m_UP.set_token( ctn.m_UP.get_token() );
- m_DOWN.set_token( ctn.m_DOWN.get_token() );
- m_EOF_NODE.set_token( ctn.m_EOF_NODE.get_token() );
- m_INVALID_NODE.set_token( ctn.m_INVALID_NODE.get_token() );
+ m_root = ctn.m_root;
+ m_adaptor = ctn.m_adaptor;
+ m_nodes.reserve( DEFAULT_INITIAL_BUFFER_SIZE );
+ m_nodeStack = ctn.m_nodeStack;
+ m_p = -1;
+ m_currentNode = NULL;
+ m_previousNode = NULL;
+ m_currentChildIndex = 0;
+ m_absoluteNodeIndex = 0;
+ m_lookAhead = NULL;
+ m_lookAheadLength = 0;
+ m_head = 0;
+ m_tail = 0;
+ m_uniqueNavigationNodes = false;
+ m_isRewriter = true;
+
+ m_UP.set_token( ctn.m_UP.get_token() );
+ m_DOWN.set_token( ctn.m_DOWN.get_token() );
+ m_EOF_NODE.set_token( ctn.m_EOF_NODE.get_token() );
+ m_INVALID_NODE.set_token( ctn.m_INVALID_NODE.get_token() );
}
template<class ImplTraits>
-CommonTreeNodeStream<ImplTraits>::CommonTreeNodeStream( TreeTypePtr tree, ANTLR_UINT32 hint )
+CommonTreeNodeStream<ImplTraits>::CommonTreeNodeStream( TreeTypePtr tree, ANTLR_UINT32 hint )
{
- this->init(hint);
- m_root = tree;
+ this->init(hint);
+ m_root = tree;
}
template<class ImplTraits>
CommonTreeNodeStream<ImplTraits>::~CommonTreeNodeStream()
{
- // If this is a rewrting stream, then certain resources
- // belong to the originating node stream and we do not
- // free them here.
- //
- if ( m_isRewriter != true)
- {
- delete m_adaptor;
-
- m_nodeStack.clear();
-
- delete m_INVALID_NODE.get_token();
- delete m_EOF_NODE.get_token();
- delete m_DOWN.get_token();
- delete m_UP.get_token();
- }
-
- m_nodes.clear();
+ // If this is a rewrting stream, then certain resources
+ // belong to the originating node stream and we do not
+ // free them here.
+ //
+ if ( m_isRewriter != true)
+ {
+ delete m_adaptor;
+
+ m_nodeStack.clear();
+
+ delete m_INVALID_NODE.get_token();
+ delete m_EOF_NODE.get_token();
+ delete m_DOWN.get_token();
+ delete m_UP.get_token();
+ }
+
+ m_nodes.clear();
}
template<class ImplTraits>
-typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<ImplTraits>::_LT(ANTLR_INT32 k)
+typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<ImplTraits>::_LT(ANTLR_INT32 k)
{
- if ( m_p == -1)
- {
- this->fillBufferRoot();
- }
-
- if (k < 0)
- {
- return this->LB(-k);
- }
- else if (k == 0)
- {
- return &(m_INVALID_NODE);
- }
-
- // k was a legitimate request,
- //
- if (( m_p + k - 1) >= (ANTLR_INT32)(m_nodes.size()))
- {
- return &(m_EOF_NODE);
- }
-
- return m_nodes[ m_p + k - 1 ];
+ if ( m_p == -1)
+ {
+ this->fillBufferRoot();
+ }
+
+ if (k < 0)
+ {
+ return this->LB(-k);
+ }
+ else if (k == 0)
+ {
+ return &(m_INVALID_NODE);
+ }
+
+ // k was a legitimate request,
+ //
+ if (( m_p + k - 1) >= (ANTLR_INT32)(m_nodes.size()))
+ {
+ return &(m_EOF_NODE);
+ }
+
+ return m_nodes[ m_p + k - 1 ];
}
template<class ImplTraits>
-typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<ImplTraits>::getTreeSource()
+typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<ImplTraits>::getTreeSource()
{
- return m_root;
+ return m_root;
}
template<class ImplTraits>
-typename CommonTreeNodeStream<ImplTraits>::TreeAdaptorType* CommonTreeNodeStream<ImplTraits>::getTreeAdaptor()
+typename CommonTreeNodeStream<ImplTraits>::TreeAdaptorType* CommonTreeNodeStream<ImplTraits>::getTreeAdaptor()
{
- return m_adaptor;
+ return m_adaptor;
}
template<class ImplTraits>
void CommonTreeNodeStream<ImplTraits>::set_uniqueNavigationNodes(bool uniqueNavigationNodes)
{
- m_uniqueNavigationNodes = uniqueNavigationNodes;
+ m_uniqueNavigationNodes = uniqueNavigationNodes;
}
template<class ImplTraits>
@@ -152,161 +152,161 @@ typename CommonTreeNodeStream<ImplTraits>::StringType CommonTreeNodeStream<Impl
}
template<class ImplTraits>
-typename CommonTreeNodeStream<ImplTraits>::StringType CommonTreeNodeStream<ImplTraits>::toStringSS(TreeTypePtr start, TreeTypePtr stop)
+typename CommonTreeNodeStream<ImplTraits>::StringType CommonTreeNodeStream<ImplTraits>::toStringSS(TreeTypePtr start, TreeTypePtr stop)
{
- StringType buf;
+ StringType buf;
this->toStringWork(start, stop, buf);
return buf;
}
template<class ImplTraits>
-void CommonTreeNodeStream<ImplTraits>::toStringWork(TreeTypePtr start, TreeTypePtr stop, StringType& str)
+void CommonTreeNodeStream<ImplTraits>::toStringWork(TreeTypePtr start, TreeTypePtr stop, StringType& str)
{
- ANTLR_UINT32 n;
- ANTLR_UINT32 c;
- StringStreamType buf;
-
- if (!start->isNilNode() )
- {
- StringType text;
-
- text = start->toString();
-
- if (text.empty())
- {
- buf << ' ';
- buf << start->getType();
- }
- else
- buf << text;
- }
-
- if (start == stop)
- {
- return; /* Finished */
- }
-
- n = start->getChildCount();
-
- if (n > 0 && ! start->isNilNode() )
- {
- buf << ' ';
- buf << CommonTokenType::TOKEN_DOWN;
- }
-
- for (c = 0; c<n ; c++)
- {
- TreeTypePtr child;
-
- child = start->getChild(c);
- this->toStringWork(child, stop, buf);
- }
-
- if (n > 0 && ! start->isNilNode() )
- {
- buf << ' ';
- buf << CommonTokenType::TOKEN_UP;
- }
- str = buf.str();
+ ANTLR_UINT32 n;
+ ANTLR_UINT32 c;
+ StringStreamType buf;
+
+ if (!start->isNilNode() )
+ {
+ StringType text;
+
+ text = start->toString();
+
+ if (text.empty())
+ {
+ buf << ' ';
+ buf << start->getType();
+ }
+ else
+ buf << text;
+ }
+
+ if (start == stop)
+ {
+ return; /* Finished */
+ }
+
+ n = start->getChildCount();
+
+ if (n > 0 && ! start->isNilNode() )
+ {
+ buf << ' ';
+ buf << CommonTokenType::TOKEN_DOWN;
+ }
+
+ for (c = 0; c<n ; c++)
+ {
+ TreeTypePtr child;
+
+ child = start->getChild(c);
+ this->toStringWork(child, stop, buf);
+ }
+
+ if (n > 0 && ! start->isNilNode() )
+ {
+ buf << ' ';
+ buf << CommonTokenType::TOKEN_UP;
+ }
+ str = buf.str();
}
template<class ImplTraits>
-typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<ImplTraits>::get(ANTLR_INT32 k)
+typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<ImplTraits>::get(ANTLR_INT32 k)
{
- if( m_p == -1 )
- {
- this->fillBufferRoot();
- }
+ if( m_p == -1 )
+ {
+ this->fillBufferRoot();
+ }
- return m_nodes[k];
+ return m_nodes[k];
}
template<class ImplTraits>
-void CommonTreeNodeStream<ImplTraits>::replaceChildren(TreeTypePtr parent,
- ANTLR_INT32 startChildIndex,
- ANTLR_INT32 stopChildIndex,
- TreeTypePtr t)
+void CommonTreeNodeStream<ImplTraits>::replaceChildren(TreeTypePtr parent,
+ ANTLR_INT32 startChildIndex,
+ ANTLR_INT32 stopChildIndex,
+ TreeTypePtr t)
{
- if (parent != NULL)
- {
- TreeAdaptorType* adaptor;
- adaptor = this->getTreeAdaptor();
- adaptor->replaceChildren(parent, startChildIndex, stopChildIndex, t);
- }
+ if (parent != NULL)
+ {
+ TreeAdaptorType* adaptor;
+ adaptor = this->getTreeAdaptor();
+ adaptor->replaceChildren(parent, startChildIndex, stopChildIndex, t);
+ }
}
template<class ImplTraits>
-typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<ImplTraits>::LB(ANTLR_INT32 k)
+typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<ImplTraits>::LB(ANTLR_INT32 k)
{
- if ( k==0)
- {
- return &(m_INVALID_NODE);
- }
+ if ( k==0)
+ {
+ return &(m_INVALID_NODE);
+ }
- if ( (m_p - k) < 0)
- {
- return &(m_INVALID_NODE);
- }
+ if ( (m_p - k) < 0)
+ {
+ return &(m_INVALID_NODE);
+ }
- return m_nodes[ m_p - k ];
+ return m_nodes[ m_p - k ];
}
template<class ImplTraits>
void CommonTreeNodeStream<ImplTraits>::addNavigationNode(ANTLR_UINT32 ttype)
{
- TreeTypePtr node;
-
- node = NULL;
-
- if (ttype == CommonTokenType::TOKEN_DOWN)
- {
- if (this->hasUniqueNavigationNodes() == true)
- {
- node = this->newDownNode();
- }
- else
- {
- node = &m_DOWN;
- }
- }
- else
- {
- if (this->hasUniqueNavigationNodes() == true)
- {
- node = this->newUpNode();
- }
- else
- {
- node = &m_UP;
- }
- }
-
- // Now add the node we decided upon.
- //
- m_nodes.push_back(node);
+ TreeTypePtr node;
+
+ node = NULL;
+
+ if (ttype == CommonTokenType::TOKEN_DOWN)
+ {
+ if (this->hasUniqueNavigationNodes() == true)
+ {
+ node = this->newDownNode();
+ }
+ else
+ {
+ node = &m_DOWN;
+ }
+ }
+ else
+ {
+ if (this->hasUniqueNavigationNodes() == true)
+ {
+ node = this->newUpNode();
+ }
+ else
+ {
+ node = &m_UP;
+ }
+ }
+
+ // Now add the node we decided upon.
+ //
+ m_nodes.push_back(node);
}
template<class ImplTraits>
-typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<ImplTraits>::newDownNode()
+typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<ImplTraits>::newDownNode()
{
- TreeTypePtr dNode;
+ TreeTypePtr dNode;
CommonTokenType* token;
- token = new CommonTokenType(CommonTokenType::TOKEN_DOWN);
- token->set_tokText("DOWN");
- dNode = new TreeType(token);
+ token = new CommonTokenType(CommonTokenType::TOKEN_DOWN);
+ token->set_tokText("DOWN");
+ dNode = new TreeType(token);
return &dNode;
}
template<class ImplTraits>
-typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<ImplTraits>::newUpNode()
+typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<ImplTraits>::newUpNode()
{
- TreeTypePtr uNode;
+ TreeTypePtr uNode;
CommonTokenType* token;
- token = new CommonTokenType(CommonTokenType::TOKEN_UP);
- token->set_tokText("UP");
- uNode = new TreeType(token);
+ token = new CommonTokenType(CommonTokenType::TOKEN_UP);
+ token->set_tokText("UP");
+ uNode = new TreeType(token);
return &uNode;
}
@@ -314,109 +314,109 @@ typename CommonTreeNodeStream<ImplTraits>::TreeTypePtr CommonTreeNodeStream<Impl
template<class ImplTraits>
bool CommonTreeNodeStream<ImplTraits>::hasUniqueNavigationNodes() const
{
- return m_uniqueNavigationNodes;
+ return m_uniqueNavigationNodes;
}
template<class ImplTraits>
-ANTLR_UINT32 CommonTreeNodeStream<ImplTraits>::getLookaheadSize()
+ANTLR_UINT32 CommonTreeNodeStream<ImplTraits>::getLookaheadSize()
{
- return m_tail < m_head
- ? (m_lookAheadLength - m_head + m_tail)
- : (m_tail - m_head);
+ return m_tail < m_head
+ ? (m_lookAheadLength - m_head + m_tail)
+ : (m_tail - m_head);
}
template<class ImplTraits>
-void CommonTreeNodeStream<ImplTraits>::push(ANTLR_INT32 index)
+void CommonTreeNodeStream<ImplTraits>::push(ANTLR_INT32 index)
{
- m_nodeStack.push(m_p); // Save current index
- this->seek(index);
+ m_nodeStack.push(m_p); // Save current index
+ this->seek(index);
}
template<class ImplTraits>
-ANTLR_INT32 CommonTreeNodeStream<ImplTraits>::pop()
+ANTLR_INT32 CommonTreeNodeStream<ImplTraits>::pop()
{
- ANTLR_INT32 retVal;
+ ANTLR_INT32 retVal;
- retVal = m_nodeStack.top();
- m_nodeStack.pop();
- this->seek(retVal);
- return retVal;
+ retVal = m_nodeStack.top();
+ m_nodeStack.pop();
+ this->seek(retVal);
+ return retVal;
}
template<class ImplTraits>
-void CommonTreeNodeStream<ImplTraits>::reset()
+void CommonTreeNodeStream<ImplTraits>::reset()
{
- if ( m_p != -1)
- {
- m_p = 0;
- }
- BaseType::m_lastMarker = 0;
-
-
- // Free and reset the node stack only if this is not
- // a rewriter, which is going to reuse the originating
- // node streams node stack
- //
- if (m_isRewriter != true)
- m_nodeStack.clear();
+ if ( m_p != -1)
+ {
+ m_p = 0;
+ }
+ BaseType::m_lastMarker = 0;
+
+
+ // Free and reset the node stack only if this is not
+ // a rewriter, which is going to reuse the originating
+ // node streams node stack
+ //
+ if (m_isRewriter != true)
+ m_nodeStack.clear();
}
template<class ImplTraits>
void CommonTreeNodeStream<ImplTraits>::fillBufferRoot()
{
- // Call the generic buffer routine with the root as the
- // argument
- //
- this->fillBuffer(m_root);
- m_p = 0; // Indicate we are at buffer start
+ // Call the generic buffer routine with the root as the
+ // argument
+ //
+ this->fillBuffer(m_root);
+ m_p = 0; // Indicate we are at buffer start
}
template<class ImplTraits>
-void CommonTreeNodeStream<ImplTraits>::fillBuffer(TreeTypePtr t)
+void CommonTreeNodeStream<ImplTraits>::fillBuffer(TreeTypePtr t)
{
- bool nilNode;
- ANTLR_UINT32 nCount;
- ANTLR_UINT32 c;
-
- nilNode = m_adaptor->isNilNode(t);
-
- // If the supplied node is not a nil (list) node then we
- // add in the node itself to the vector
- //
- if (nilNode == false)
- {
- m_nodes.push_back(t);
- }
-
- // Only add a DOWN node if the tree is not a nil tree and
- // the tree does have children.
- //
- nCount = t->getChildCount();
-
- if (nilNode == false && nCount>0)
- {
- this->addNavigationNode( CommonTokenType::TOKEN_DOWN);
- }
-
- // We always add any children the tree contains, which is
- // a recursive call to this function, which will cause similar
- // recursion and implement a depth first addition
- //
- for (c = 0; c < nCount; c++)
- {
- this->fillBuffer( m_adaptor->getChild(t, c));
- }
-
- // If the tree had children and was not a nil (list) node, then we
- // we need to add an UP node here to match the DOWN node
- //
- if (nilNode == false && nCount > 0)
- {
- this->addNavigationNode(CommonTokenType::TOKEN_UP);
- }
+ bool nilNode;
+ ANTLR_UINT32 nCount;
+ ANTLR_UINT32 c;
+
+ nilNode = m_adaptor->isNilNode(t);
+
+ // If the supplied node is not a nil (list) node then we
+ // add in the node itself to the vector
+ //
+ if (nilNode == false)
+ {
+ m_nodes.push_back(t);
+ }
+
+ // Only add a DOWN node if the tree is not a nil tree and
+ // the tree does have children.
+ //
+ nCount = t->getChildCount();
+
+ if (nilNode == false && nCount>0)
+ {
+ this->addNavigationNode( CommonTokenType::TOKEN_DOWN);
+ }
+
+ // We always add any children the tree contains, which is
+ // a recursive call to this function, which will cause similar
+ // recursion and implement a depth first addition
+ //
+ for (c = 0; c < nCount; c++)
+ {
+ this->fillBuffer( m_adaptor->getChild(t, c));
+ }
+
+ // If the tree had children and was not a nil (list) node, then we
+ // we need to add an UP node here to match the DOWN node
+ //
+ if (nilNode == false && nCount > 0)
+ {
+ this->addNavigationNode(CommonTokenType::TOKEN_UP);
+ }
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3convertutf.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3convertutf.hpp
index 9adb0b590e..7f4b7e0d25 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3convertutf.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3convertutf.hpp
@@ -1,8 +1,8 @@
/*
* Copyright 2001-2004 Unicode, Inc.
- *
+ *
* Disclaimer
- *
+ *
* This source code is provided as is by Unicode, Inc. No claims are
* made as to fitness for any particular purpose. No warranties of any
* kind are expressed or implied. The recipient agrees to determine
@@ -10,9 +10,9 @@
* purchased on magnetic or optical media from Unicode, Inc., the
* sole remedy for any claim will be exchange of defective media
* within 90 days of receipt.
- *
+ *
* Limitations on Rights to Redistribute This Code
- *
+ *
* Unicode, Inc. hereby grants the right to freely use the information
* supplied in this file in the creation of products supporting the
* Unicode Standard, and to make copies of this file in any form
@@ -33,7 +33,7 @@
Each routine converts the text between *sourceStart and sourceEnd,
putting the result into the buffer between *targetStart and
- targetEnd. Note: the end pointers are *after* the last item: e.g.
+ targetEnd. Note: the end pointers are *after* the last item: e.g.
*(sourceEnd - 1) is the last item.
The return result indicates whether the conversion was successful,
@@ -45,12 +45,12 @@
the respective buffers.
Input parameters:
- sourceStart - pointer to a pointer to the source buffer.
- The contents of this are modified on return so that
- it points at the next thing to be converted.
- targetStart - similarly, pointer to pointer to the target buffer.
- sourceEnd, targetEnd - respectively pointers to the ends of the
- two buffers, for overflow checking only.
+ sourceStart - pointer to a pointer to the source buffer.
+ The contents of this are modified on return so that
+ it points at the next thing to be converted.
+ targetStart - similarly, pointer to pointer to the target buffer.
+ sourceEnd, targetEnd - respectively pointers to the ends of the
+ two buffers, for overflow checking only.
These conversion functions take a ConversionFlags argument. When this
flag is set to strict, both irregular sequences and isolated surrogates
@@ -67,15 +67,15 @@
they constitute an error.
Output parameters:
- The value "sourceIllegal" is returned from some routines if the input
- sequence is malformed. When "sourceIllegal" is returned, the source
- value will point to the illegal value that caused the problem. E.g.,
- in UTF-8 when a sequence is malformed, it points to the start of the
- malformed sequence.
+ The value "sourceIllegal" is returned from some routines if the input
+ sequence is malformed. When "sourceIllegal" is returned, the source
+ value will point to the illegal value that caused the problem. E.g.,
+ in UTF-8 when a sequence is malformed, it points to the start of the
+ malformed sequence.
Author: Mark E. Davis, 1994.
Rev History: Rick McGowan, fixes & updates May 2001.
- Fixes & updates, Sept 2001.
+ Fixes & updates, Sept 2001.
------------------------------------------------------------------------ */
@@ -93,19 +93,19 @@
// aliases for the types that are system determined by
// ANTLR at compile time.
//
-// typedef unsigned long UTF32; /* at least 32 bits */
-// typedef unsigned short UTF16; /* at least 16 bits */
-// typedef unsigned char UTF8; /* typically 8 bits */
-// typedef unsigned char Boolean; /* 0 or 1 */
+// typedef unsigned long UTF32; /* at least 32 bits */
+// typedef unsigned short UTF16; /* at least 16 bits */
+// typedef unsigned char UTF8; /* typically 8 bits */
+// typedef unsigned char Boolean; /* 0 or 1 */
-#ifndef _ANTLR3_CONVERTUTF_H
-#define _ANTLR3_CONVERTUTF_H
+#ifndef _ANTLR3_CONVERTUTF_H
+#define _ANTLR3_CONVERTUTF_H
-namespace antlr3 {
+namespace antlr3 {
-typedef ANTLR_UINT32 UTF32; /* at least 32 bits */
-typedef ANTLR_UINT16 UTF16; /* at least 16 bits */
-typedef ANTLR_UINT8 UTF8; /* typically 8 bits */
+typedef ANTLR_UINT32 UTF32; /* at least 32 bits */
+typedef ANTLR_UINT16 UTF16; /* at least 16 bits */
+typedef ANTLR_UINT8 UTF8; /* typically 8 bits */
/* Some fundamental constants */
#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
@@ -123,20 +123,20 @@ typedef ANTLR_UINT8 UTF8; /* typically 8 bits */
#define halfMask ((UTF32)0x3FFUL)
enum ConversionResult {
- conversionOK, /* conversion successful */
- sourceExhausted, /* partial character in source, but hit end */
- targetExhausted, /* insuff. room in target for conversion */
- sourceIllegal /* source sequence is illegal/malformed */
+ conversionOK, /* conversion successful */
+ sourceExhausted, /* partial character in source, but hit end */
+ targetExhausted, /* insuff. room in target for conversion */
+ sourceIllegal /* source sequence is illegal/malformed */
};
enum ConversionFlags {
- strictConversion = 0,
- lenientConversion
+ strictConversion = 0,
+ lenientConversion
} ;
-}
+}
#endif
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3cyclicdfa.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3cyclicdfa.hpp
index 8d3f142ff7..2129552f1a 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3cyclicdfa.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3cyclicdfa.hpp
@@ -3,8 +3,8 @@
/// runtime function that can deal with all cyclic dfa
/// structures and show Java how it is done ;-)
///
-#ifndef ANTLR3_CYCLICDFA_HPP
-#define ANTLR3_CYCLICDFA_HPP
+#ifndef ANTLR3_CYCLICDFA_HPP
+#define ANTLR3_CYCLICDFA_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -34,61 +34,61 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits, class CtxType>
class CyclicDFA : public ImplTraits::AllocPolicyType
{
public:
- typedef typename CtxType::StreamType StreamType;
- typedef typename CtxType::ExceptionBaseType ExceptionBaseType;
- typedef typename ImplTraits::template RecognizerType<StreamType> RecognizerType;
- typedef typename StreamType::IntStreamType IntStreamType;
- typedef typename StreamType::TokenType TokenType;
- typedef TokenType CommonTokenType;
- typedef CtxType ContextType;
+ typedef typename CtxType::StreamType StreamType;
+ typedef typename CtxType::ExceptionBaseType ExceptionBaseType;
+ typedef typename ImplTraits::template RecognizerType<StreamType> RecognizerType;
+ typedef typename StreamType::IntStreamType IntStreamType;
+ typedef typename StreamType::TokenType TokenType;
+ typedef TokenType CommonTokenType;
+ typedef CtxType ContextType;
private:
/// Decision number that a particular static structure
/// represents.
///
- const ANTLR_INT32 m_decisionNumber;
+ const ANTLR_INT32 m_decisionNumber;
/// What this decision represents
///
- const ANTLR_UCHAR* m_description;
- const ANTLR_INT32* const m_eot;
- const ANTLR_INT32* const m_eof;
- const ANTLR_INT32* const m_min;
- const ANTLR_INT32* const m_max;
- const ANTLR_INT32* const m_accept;
- const ANTLR_INT32* const m_special;
- const ANTLR_INT32* const *const m_transition;
+ const ANTLR_UCHAR* m_description;
+ const ANTLR_INT32* const m_eot;
+ const ANTLR_INT32* const m_eof;
+ const ANTLR_INT32* const m_min;
+ const ANTLR_INT32* const m_max;
+ const ANTLR_INT32* const m_accept;
+ const ANTLR_INT32* const m_special;
+ const ANTLR_INT32* const *const m_transition;
public:
- CyclicDFA( ANTLR_INT32 decisionNumber
- , const ANTLR_UCHAR* description
- , const ANTLR_INT32* const eot
- , const ANTLR_INT32* const eof
- , const ANTLR_INT32* const min
- , const ANTLR_INT32* const max
- , const ANTLR_INT32* const accept
- , const ANTLR_INT32* const special
- , const ANTLR_INT32* const *const transition );
- CyclicDFA( const CyclicDFA& cdfa );
+ CyclicDFA( ANTLR_INT32 decisionNumber
+ , const ANTLR_UCHAR* description
+ , const ANTLR_INT32* const eot
+ , const ANTLR_INT32* const eof
+ , const ANTLR_INT32* const min
+ , const ANTLR_INT32* const max
+ , const ANTLR_INT32* const accept
+ , const ANTLR_INT32* const special
+ , const ANTLR_INT32* const *const transition );
+ CyclicDFA( const CyclicDFA& cdfa );
CyclicDFA& operator=( const CyclicDFA& dfa);
-
- ANTLR_INT32 specialStateTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s);
- ANTLR_INT32 specialTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s);
+
+ ANTLR_INT32 specialStateTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s);
+ ANTLR_INT32 specialTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s);
- template<typename SuperType>
- ANTLR_INT32 predict(CtxType* ctx, RecognizerType* recognizer, IntStreamType* is, SuperType& super);
-
+ template<typename SuperType>
+ ANTLR_INT32 predict(CtxType* ctx, RecognizerType* recognizer, IntStreamType* is, SuperType& super);
+
private:
- void noViableAlt(RecognizerType* rec, ANTLR_UINT32 s);
+ void noViableAlt(RecognizerType* rec, ANTLR_UINT32 s);
};
-}
+}
#include "antlr3cyclicdfa.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3cyclicdfa.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3cyclicdfa.inl
index 830a4b5770..61d15bfcf2 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3cyclicdfa.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3cyclicdfa.inl
@@ -1,204 +1,204 @@
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits, class CtxType>
-CyclicDFA<ImplTraits, CtxType>::CyclicDFA( ANTLR_INT32 decisionNumber
- , const ANTLR_UCHAR* description
- , const ANTLR_INT32* const eot
- , const ANTLR_INT32* const eof
- , const ANTLR_INT32* const min
- , const ANTLR_INT32* const max
- , const ANTLR_INT32* const accept
- , const ANTLR_INT32* const special
- , const ANTLR_INT32* const *const transition )
- :m_decisionNumber(decisionNumber)
- , m_eot(eot)
- , m_eof(eof)
- , m_min(min)
- , m_max(max)
- , m_accept(accept)
- , m_special(special)
- , m_transition(transition)
+CyclicDFA<ImplTraits, CtxType>::CyclicDFA( ANTLR_INT32 decisionNumber
+ , const ANTLR_UCHAR* description
+ , const ANTLR_INT32* const eot
+ , const ANTLR_INT32* const eof
+ , const ANTLR_INT32* const min
+ , const ANTLR_INT32* const max
+ , const ANTLR_INT32* const accept
+ , const ANTLR_INT32* const special
+ , const ANTLR_INT32* const *const transition )
+ :m_decisionNumber(decisionNumber)
+ , m_eot(eot)
+ , m_eof(eof)
+ , m_min(min)
+ , m_max(max)
+ , m_accept(accept)
+ , m_special(special)
+ , m_transition(transition)
{
- m_description = description;
+ m_description = description;
}
template<class ImplTraits, class CtxType>
CyclicDFA<ImplTraits, CtxType>::CyclicDFA( const CyclicDFA& dfa )
{
- m_decisionNumber = dfa.m_decisionNumber;
- m_description = dfa.m_description;
- m_eot = dfa.m_eot;
- m_eof = dfa.m_eof;
- m_min = dfa.m_min;
- m_max = dfa.m_max;
- m_accept = dfa.m_accept;
- m_special = dfa.m_special;
- m_transition = dfa.m_transition;
+ m_decisionNumber = dfa.m_decisionNumber;
+ m_description = dfa.m_description;
+ m_eot = dfa.m_eot;
+ m_eof = dfa.m_eof;
+ m_min = dfa.m_min;
+ m_max = dfa.m_max;
+ m_accept = dfa.m_accept;
+ m_special = dfa.m_special;
+ m_transition = dfa.m_transition;
}
template<class ImplTraits, class CtxType>
CyclicDFA<ImplTraits, CtxType>& CyclicDFA<ImplTraits, CtxType>::operator=( const CyclicDFA& dfa)
{
- m_decisionNumber = dfa.m_decisionNumber;
- m_description = dfa.m_description;
- m_eot = dfa.m_eot;
- m_eof = dfa.m_eof;
- m_min = dfa.m_min;
- m_max = dfa.m_max;
- m_accept = dfa.m_accept;
- m_special = dfa.m_special;
- m_transition = dfa.m_transition;
- return *this;
+ m_decisionNumber = dfa.m_decisionNumber;
+ m_description = dfa.m_description;
+ m_eot = dfa.m_eot;
+ m_eof = dfa.m_eof;
+ m_min = dfa.m_min;
+ m_max = dfa.m_max;
+ m_accept = dfa.m_accept;
+ m_special = dfa.m_special;
+ m_transition = dfa.m_transition;
+ return *this;
}
template<class ImplTraits, class CtxType>
-ANTLR_INT32 CyclicDFA<ImplTraits, CtxType>::specialStateTransition(CtxType * ,
- RecognizerType* ,
- IntStreamType* , ANTLR_INT32 )
+ANTLR_INT32 CyclicDFA<ImplTraits, CtxType>::specialStateTransition(CtxType * ,
+ RecognizerType* ,
+ IntStreamType* , ANTLR_INT32 )
{
- return -1;
+ return -1;
}
template<class ImplTraits, class CtxType>
-ANTLR_INT32 CyclicDFA<ImplTraits, CtxType>::specialTransition(CtxType * /*ctx*/,
- RecognizerType* /*recognizer*/,
- IntStreamType* /*is*/, ANTLR_INT32 /*s*/)
+ANTLR_INT32 CyclicDFA<ImplTraits, CtxType>::specialTransition(CtxType * /*ctx*/,
+ RecognizerType* /*recognizer*/,
+ IntStreamType* /*is*/, ANTLR_INT32 /*s*/)
{
- return 0;
+ return 0;
}
template<class ImplTraits, class CtxType>
template<typename SuperType>
-ANTLR_INT32 CyclicDFA<ImplTraits, CtxType>::predict(CtxType * ctx,
- RecognizerType* recognizer,
- IntStreamType* is, SuperType& super)
+ANTLR_INT32 CyclicDFA<ImplTraits, CtxType>::predict(CtxType * ctx,
+ RecognizerType* recognizer,
+ IntStreamType* is, SuperType& super)
{
- ANTLR_MARKER mark;
- ANTLR_INT32 s;
- ANTLR_INT32 specialState;
- ANTLR_INT32 c;
-
- mark = is->mark(); /* Store where we are right now */
- s = 0; /* Always start with state 0 */
-
- for (;;)
- {
- /* Pick out any special state entry for this state
- */
- specialState = m_special[s];
-
- /* Transition the special state and consume an input token
- */
- if (specialState >= 0)
- {
- s = super.specialStateTransition(ctx, recognizer, is, specialState);
-
- // Error?
- //
- if (s<0)
- {
- // If the predicate/rule raised an exception then we leave it
- // in tact, else we have an NVA.
- //
- if (recognizer->get_state()->get_error() != true)
- {
- this->noViableAlt(recognizer, s);
- }
- is->rewind(mark);
- return 0;
- }
- is->consume();
- continue;
- }
-
- /* Accept state?
- */
- if (m_accept[s] >= 1)
- {
- is->rewind(mark);
- return m_accept[s];
- }
-
- /* Look for a normal transition state based upon the input token element
- */
- c = is->LA(1);
-
- /* Check against min and max for this state
- */
- if (c>= m_min[s] && c <= m_max[s])
- {
- ANTLR_INT32 snext;
-
- /* What is the next state?
- */
- snext = m_transition[s][c - m_min[s]];
-
- if (snext < 0)
- {
- /* Was in range but not a normal transition
- * must check EOT, which is like the else clause.
- * eot[s]>=0 indicates that an EOT edge goes to another
- * state.
- */
- if ( m_eot[s] >= 0)
- {
- s = m_eot[s];
- is->consume();
- continue;
- }
- this->noViableAlt(recognizer, s);
- is->rewind(mark);
- return 0;
- }
-
- /* New current state - move to it
- */
- s = snext;
- is->consume();
- continue;
- }
- /* EOT Transition?
- */
- if ( m_eot[s] >= 0)
- {
- s = m_eot[s];
- is->consume();
- continue;
- }
- /* EOF transition to accept state?
- */
- if ( c == ImplTraits::CommonTokenType::TOKEN_EOF && m_eof[s] >= 0)
- {
- is->rewind(mark);
- return m_accept[m_eof[s]];
- }
-
- /* No alt, so bomb
- */
- this->noViableAlt(recognizer, s);
- is->rewind(mark);
- return 0;
- }
+ ANTLR_MARKER mark;
+ ANTLR_INT32 s;
+ ANTLR_INT32 specialState;
+ ANTLR_INT32 c;
+
+ mark = is->mark(); /* Store where we are right now */
+ s = 0; /* Always start with state 0 */
+
+ for (;;)
+ {
+ /* Pick out any special state entry for this state
+ */
+ specialState = m_special[s];
+
+ /* Transition the special state and consume an input token
+ */
+ if (specialState >= 0)
+ {
+ s = super.specialStateTransition(ctx, recognizer, is, specialState);
+
+ // Error?
+ //
+ if (s<0)
+ {
+ // If the predicate/rule raised an exception then we leave it
+ // in tact, else we have an NVA.
+ //
+ if (recognizer->get_state()->get_error() != true)
+ {
+ this->noViableAlt(recognizer, s);
+ }
+ is->rewind(mark);
+ return 0;
+ }
+ is->consume();
+ continue;
+ }
+
+ /* Accept state?
+ */
+ if (m_accept[s] >= 1)
+ {
+ is->rewind(mark);
+ return m_accept[s];
+ }
+
+ /* Look for a normal transition state based upon the input token element
+ */
+ c = is->LA(1);
+
+ /* Check against min and max for this state
+ */
+ if (c>= m_min[s] && c <= m_max[s])
+ {
+ ANTLR_INT32 snext;
+
+ /* What is the next state?
+ */
+ snext = m_transition[s][c - m_min[s]];
+
+ if (snext < 0)
+ {
+ /* Was in range but not a normal transition
+ * must check EOT, which is like the else clause.
+ * eot[s]>=0 indicates that an EOT edge goes to another
+ * state.
+ */
+ if ( m_eot[s] >= 0)
+ {
+ s = m_eot[s];
+ is->consume();
+ continue;
+ }
+ this->noViableAlt(recognizer, s);
+ is->rewind(mark);
+ return 0;
+ }
+
+ /* New current state - move to it
+ */
+ s = snext;
+ is->consume();
+ continue;
+ }
+ /* EOT Transition?
+ */
+ if ( m_eot[s] >= 0)
+ {
+ s = m_eot[s];
+ is->consume();
+ continue;
+ }
+ /* EOF transition to accept state?
+ */
+ if ( c == ImplTraits::CommonTokenType::TOKEN_EOF && m_eof[s] >= 0)
+ {
+ is->rewind(mark);
+ return m_accept[m_eof[s]];
+ }
+
+ /* No alt, so bomb
+ */
+ this->noViableAlt(recognizer, s);
+ is->rewind(mark);
+ return 0;
+ }
}
template<class ImplTraits, class CtxType>
void CyclicDFA<ImplTraits, CtxType>::noViableAlt(RecognizerType* rec, ANTLR_UINT32 s)
{
- // In backtracking mode, we just set the failed flag so that the
- // alt can just exit right now. If we are parsing though, then
- // we want the exception to be raised.
- //
- if (rec->get_state()->get_backtracking() > 0)
+ // In backtracking mode, we just set the failed flag so that the
+ // alt can just exit right now. If we are parsing though, then
+ // we want the exception to be raised.
+ //
+ if (rec->get_state()->get_backtracking() > 0)
{
- rec->get_state()->set_failed(true);
+ rec->get_state()->set_failed(true);
}
- else
- {
- ANTLR_Exception<ImplTraits, NO_VIABLE_ALT_EXCEPTION, StreamType>* ex
- = new ANTLR_Exception<ImplTraits, NO_VIABLE_ALT_EXCEPTION, StreamType>( rec, (const char*)m_description );
- ex->set_decisionNum( m_decisionNumber );
- ex->set_state(s);
- }
+ else
+ {
+ ANTLR_Exception<ImplTraits, NO_VIABLE_ALT_EXCEPTION, StreamType>* ex
+ = new ANTLR_Exception<ImplTraits, NO_VIABLE_ALT_EXCEPTION, StreamType>( rec, (const char*)m_description );
+ ex->set_decisionNum( m_decisionNumber );
+ ex->set_state(s);
+ }
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3debugeventlistener.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3debugeventlistener.hpp
index d21382901d..bc5ea00a3b 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3debugeventlistener.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3debugeventlistener.hpp
@@ -12,8 +12,8 @@
* for future. 4/26/2006.
*/
-#ifndef ANTLR3_DEBUG_EVENT_LISTENER_HPP
-#define ANTLR3_DEBUG_EVENT_LISTENER_HPP
+#ifndef ANTLR3_DEBUG_EVENT_LISTENER_HPP
+#define ANTLR3_DEBUG_EVENT_LISTENER_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -43,11 +43,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
/// Default debugging port
///
-#define DEFAULT_DEBUGGER_PORT 0xBFCC;
+#define DEFAULT_DEBUGGER_PORT 0xBFCC;
/** The ANTLR3 debugging interface for communicating with ANLTR Works. Function comments
* mostly taken from the Java version.
@@ -57,343 +57,343 @@ template<class ImplTraits>
class DebugEventListener : public ImplTraits::AllocPolicyType
{
public:
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
- typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
+ typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
private:
- /// The port number which the debug listener should listen on for a connection
- ///
- ANTLR_UINT32 m_port;
+ /// The port number which the debug listener should listen on for a connection
+ ///
+ ANTLR_UINT32 m_port;
- /// The socket structure we receive after a successful accept on the serverSocket
- ///
- SOCKET m_socket;
+ /// The socket structure we receive after a successful accept on the serverSocket
+ ///
+ SOCKET m_socket;
- /** The version of the debugging protocol supported by the providing
- * instance of the debug event listener.
- */
- int m_PROTOCOL_VERSION;
+ /** The version of the debugging protocol supported by the providing
+ * instance of the debug event listener.
+ */
+ int m_PROTOCOL_VERSION;
- /// The name of the grammar file that we are debugging
- ///
- StringType m_grammarFileName;
+ /// The name of the grammar file that we are debugging
+ ///
+ StringType m_grammarFileName;
- /// Indicates whether we have already connected or not
- ///
- bool m_initialized;
+ /// Indicates whether we have already connected or not
+ ///
+ bool m_initialized;
- /// Used to serialize the values of any particular token we need to
- /// send back to the debugger.
- ///
- StringType m_tokenString;
+ /// Used to serialize the values of any particular token we need to
+ /// send back to the debugger.
+ ///
+ StringType m_tokenString;
- /// Allows the debug event system to access the adapter in use
- /// by the recognizer, if this is a tree parser of some sort.
- ///
- TreeAdaptorType* m_adaptor;
+ /// Allows the debug event system to access the adapter in use
+ /// by the recognizer, if this is a tree parser of some sort.
+ ///
+ TreeAdaptorType* m_adaptor;
public:
- /// Wait for a connection from the debugger and initiate the
- /// debugging session.
- ///
- virtual bool handshake();
-
- /** The parser has just entered a rule. No decision has been made about
- * which alt is predicted. This is fired AFTER init actions have been
- * executed. Attributes are defined and available etc...
- */
- virtual void enterRule( const char * grammarFileName, const char * ruleName);
-
- /** Because rules can have lots of alternatives, it is very useful to
- * know which alt you are entering. This is 1..n for n alts.
- */
- virtual void enterAlt( int alt);
-
- /** This is the last thing executed before leaving a rule. It is
- * executed even if an exception is thrown. This is triggered after
- * error reporting and recovery have occurred (unless the exception is
- * not caught in this rule). This implies an "exitAlt" event.
- */
- virtual void exitRule( const char * grammarFileName, const char * ruleName);
-
- /** Track entry into any (...) subrule other EBNF construct
- */
- virtual void enterSubRule( int decisionNumber);
-
- virtual void exitSubRule( int decisionNumber);
-
- /** Every decision, fixed k or arbitrary, has an enter/exit event
- * so that a GUI can easily track what LT/consume events are
- * associated with prediction. You will see a single enter/exit
- * subrule but multiple enter/exit decision events, one for each
- * loop iteration.
- */
- virtual void enterDecision( int decisionNumber);
-
- virtual void exitDecision( int decisionNumber);
-
- /** An input token was consumed; matched by any kind of element.
- * Trigger after the token was matched by things like match(), matchAny().
- */
- virtual void consumeToken( CommonTokenType* t);
-
- /** An off-channel input token was consumed.
- * Trigger after the token was matched by things like match(), matchAny().
- * (unless of course the hidden token is first stuff in the input stream).
- */
- virtual void consumeHiddenToken( CommonTokenType* t);
-
- /** Somebody (anybody) looked ahead. Note that this actually gets
- * triggered by both LA and LT calls. The debugger will want to know
- * which Token object was examined. Like consumeToken, this indicates
- * what token was seen at that depth. A remote debugger cannot look
- * ahead into a file it doesn't have so LT events must pass the token
- * even if the info is redundant.
- */
- virtual void LT( int i, CommonTokenType* t);
-
- /** The parser is going to look arbitrarily ahead; mark this location,
- * the token stream's marker is sent in case you need it.
- */
- virtual void mark( ANTLR_MARKER marker);
-
- /** After an arbitrarily long lookahead as with a cyclic DFA (or with
- * any backtrack), this informs the debugger that stream should be
- * rewound to the position associated with marker.
- */
- virtual void rewind( ANTLR_MARKER marker);
-
- /** Rewind to the input position of the last marker.
- * Used currently only after a cyclic DFA and just
- * before starting a sem/syn predicate to get the
- * input position back to the start of the decision.
- * Do not "pop" the marker off the state. mark(i)
- * and rewind(i) should balance still.
- */
- virtual void rewindLast();
-
- virtual void beginBacktrack( int level);
-
- virtual void endBacktrack( int level, bool successful);
-
- /** To watch a parser move through the grammar, the parser needs to
- * inform the debugger what line/charPos it is passing in the grammar.
- * For now, this does not know how to switch from one grammar to the
- * other and back for island grammars etc...
- *
- * This should also allow breakpoints because the debugger can stop
- * the parser whenever it hits this line/pos.
- */
- virtual void location( int line, int pos);
-
- /** A recognition exception occurred such as NoViableAltException. I made
- * this a generic event so that I can alter the exception hierarchy later
- * without having to alter all the debug objects.
- *
- * Upon error, the stack of enter rule/subrule must be properly unwound.
- * If no viable alt occurs it is within an enter/exit decision, which
- * also must be rewound. Even the rewind for each mark must be unwound.
- * In the Java target this is pretty easy using try/finally, if a bit
- * ugly in the generated code. The rewind is generated in DFA.predict()
- * actually so no code needs to be generated for that. For languages
- * w/o this "finally" feature (C++?), the target implementor will have
- * to build an event stack or something.
- *
- * Across a socket for remote debugging, only the RecognitionException
- * data fields are transmitted. The token object or whatever that
- * caused the problem was the last object referenced by LT. The
- * immediately preceding LT event should hold the unexpected Token or
- * char.
- *
- * Here is a sample event trace for grammar:
- *
- * b : C ({;}A|B) // {;} is there to prevent A|B becoming a set
+ /// Wait for a connection from the debugger and initiate the
+ /// debugging session.
+ ///
+ virtual bool handshake();
+
+ /** The parser has just entered a rule. No decision has been made about
+ * which alt is predicted. This is fired AFTER init actions have been
+ * executed. Attributes are defined and available etc...
+ */
+ virtual void enterRule( const char * grammarFileName, const char * ruleName);
+
+ /** Because rules can have lots of alternatives, it is very useful to
+ * know which alt you are entering. This is 1..n for n alts.
+ */
+ virtual void enterAlt( int alt);
+
+ /** This is the last thing executed before leaving a rule. It is
+ * executed even if an exception is thrown. This is triggered after
+ * error reporting and recovery have occurred (unless the exception is
+ * not caught in this rule). This implies an "exitAlt" event.
+ */
+ virtual void exitRule( const char * grammarFileName, const char * ruleName);
+
+ /** Track entry into any (...) subrule other EBNF construct
+ */
+ virtual void enterSubRule( int decisionNumber);
+
+ virtual void exitSubRule( int decisionNumber);
+
+ /** Every decision, fixed k or arbitrary, has an enter/exit event
+ * so that a GUI can easily track what LT/consume events are
+ * associated with prediction. You will see a single enter/exit
+ * subrule but multiple enter/exit decision events, one for each
+ * loop iteration.
+ */
+ virtual void enterDecision( int decisionNumber);
+
+ virtual void exitDecision( int decisionNumber);
+
+ /** An input token was consumed; matched by any kind of element.
+ * Trigger after the token was matched by things like match(), matchAny().
+ */
+ virtual void consumeToken( CommonTokenType* t);
+
+ /** An off-channel input token was consumed.
+ * Trigger after the token was matched by things like match(), matchAny().
+ * (unless of course the hidden token is first stuff in the input stream).
+ */
+ virtual void consumeHiddenToken( CommonTokenType* t);
+
+ /** Somebody (anybody) looked ahead. Note that this actually gets
+ * triggered by both LA and LT calls. The debugger will want to know
+ * which Token object was examined. Like consumeToken, this indicates
+ * what token was seen at that depth. A remote debugger cannot look
+ * ahead into a file it doesn't have so LT events must pass the token
+ * even if the info is redundant.
+ */
+ virtual void LT( int i, CommonTokenType* t);
+
+ /** The parser is going to look arbitrarily ahead; mark this location,
+ * the token stream's marker is sent in case you need it.
+ */
+ virtual void mark( ANTLR_MARKER marker);
+
+ /** After an arbitrarily long lookahead as with a cyclic DFA (or with
+ * any backtrack), this informs the debugger that stream should be
+ * rewound to the position associated with marker.
+ */
+ virtual void rewind( ANTLR_MARKER marker);
+
+ /** Rewind to the input position of the last marker.
+ * Used currently only after a cyclic DFA and just
+ * before starting a sem/syn predicate to get the
+ * input position back to the start of the decision.
+ * Do not "pop" the marker off the state. mark(i)
+ * and rewind(i) should balance still.
+ */
+ virtual void rewindLast();
+
+ virtual void beginBacktrack( int level);
+
+ virtual void endBacktrack( int level, bool successful);
+
+ /** To watch a parser move through the grammar, the parser needs to
+ * inform the debugger what line/charPos it is passing in the grammar.
+ * For now, this does not know how to switch from one grammar to the
+ * other and back for island grammars etc...
+ *
+ * This should also allow breakpoints because the debugger can stop
+ * the parser whenever it hits this line/pos.
+ */
+ virtual void location( int line, int pos);
+
+ /** A recognition exception occurred such as NoViableAltException. I made
+ * this a generic event so that I can alter the exception hierarchy later
+ * without having to alter all the debug objects.
+ *
+ * Upon error, the stack of enter rule/subrule must be properly unwound.
+ * If no viable alt occurs it is within an enter/exit decision, which
+ * also must be rewound. Even the rewind for each mark must be unwound.
+ * In the Java target this is pretty easy using try/finally, if a bit
+ * ugly in the generated code. The rewind is generated in DFA.predict()
+ * actually so no code needs to be generated for that. For languages
+ * w/o this "finally" feature (C++?), the target implementor will have
+ * to build an event stack or something.
+ *
+ * Across a socket for remote debugging, only the RecognitionException
+ * data fields are transmitted. The token object or whatever that
+ * caused the problem was the last object referenced by LT. The
+ * immediately preceding LT event should hold the unexpected Token or
+ * char.
+ *
+ * Here is a sample event trace for grammar:
+ *
+ * b : C ({;}A|B) // {;} is there to prevent A|B becoming a set
* | D
* ;
*
- * The sequence for this rule (with no viable alt in the subrule) for
- * input 'c c' (there are 3 tokens) is:
- *
- * commence
- * LT(1)
- * enterRule b
- * location 7 1
- * enter decision 3
- * LT(1)
- * exit decision 3
- * enterAlt1
- * location 7 5
- * LT(1)
- * consumeToken [c/<4>,1:0]
- * location 7 7
- * enterSubRule 2
- * enter decision 2
- * LT(1)
- * LT(1)
- * recognitionException NoViableAltException 2 1 2
- * exit decision 2
- * exitSubRule 2
- * beginResync
- * LT(1)
- * consumeToken [c/<4>,1:1]
- * LT(1)
- * endResync
- * LT(-1)
- * exitRule b
- * terminate
- */
- template<typename ExceptionBaseType>
- void recognitionException( ExceptionBaseType* ) {}
-
- /** Indicates the recognizer is about to consume tokens to resynchronize
- * the parser. Any consume events from here until the recovered event
- * are not part of the parse--they are dead tokens.
- */
- virtual void beginResync();
-
- /** Indicates that the recognizer has finished consuming tokens in order
- * to resynchronize. There may be multiple beginResync/endResync pairs
- * before the recognizer comes out of errorRecovery mode (in which
- * multiple errors are suppressed). This will be useful
- * in a gui where you want to probably grey out tokens that are consumed
- * but not matched to anything in grammar. Anything between
- * a beginResync/endResync pair was tossed out by the parser.
- */
- virtual void endResync();
-
- /** A semantic predicate was evaluate with this result and action text
- */
- virtual void semanticPredicate( bool result, const char * predicate);
-
- /** Announce that parsing has begun. Not technically useful except for
- * sending events over a socket. A GUI for example will launch a thread
- * to connect and communicate with a remote parser. The thread will want
- * to notify the GUI when a connection is made. ANTLR parsers
- * trigger this upon entry to the first rule (the ruleLevel is used to
- * figure this out).
- */
- virtual void commence();
-
- /** Parsing is over; successfully or not. Mostly useful for telling
- * remote debugging listeners that it's time to quit. When the rule
- * invocation level goes to zero at the end of a rule, we are done
- * parsing.
- */
- virtual void terminate();
-
- /// Retrieve acknowledge response from the debugger. in fact this
- /// response is never used at the moment. So we just read whatever
- /// is in the socket buffer and throw it away.
- ///
- virtual void ack();
-
- // T r e e P a r s i n g
-
- /** Input for a tree parser is an AST, but we know nothing for sure
- * about a node except its type and text (obtained from the adaptor).
- * This is the analog of the consumeToken method. The ID is usually
- * the memory address of the node.
- * If the type is UP or DOWN, then
- * the ID is not really meaningful as it's fixed--there is
- * just one UP node and one DOWN navigation node.
- *
- * Note that unlike the Java version, the node type of the C parsers
- * is always fixed as pANTLR3_BASE_TREE because all such structures
- * contain a super pointer to their parent, which is generally COMMON_TREE and within
- * that there is a super pointer that can point to a user type that encapsulates it.
- * Almost akin to saying that it is an interface pointer except we don't need to
- * know what the interface is in full, just those bits that are the base.
- * @param t
- */
- virtual void consumeNode( TreeTypePtr t);
-
- /** The tree parser looked ahead. If the type is UP or DOWN,
- * then the ID is not really meaningful as it's fixed--there is
- * just one UP node and one DOWN navigation node.
- */
- virtual void LTT( int i, TreeTypePtr t);
-
-
- // A S T E v e n t s
-
- /** A nil was created (even nil nodes have a unique ID...
- * they are not "null" per se). As of 4/28/2006, this
- * seems to be uniquely triggered when starting a new subtree
- * such as when entering a subrule in automatic mode and when
- * building a tree in rewrite mode.
+ * The sequence for this rule (with no viable alt in the subrule) for
+ * input 'c c' (there are 3 tokens) is:
+ *
+ * commence
+ * LT(1)
+ * enterRule b
+ * location 7 1
+ * enter decision 3
+ * LT(1)
+ * exit decision 3
+ * enterAlt1
+ * location 7 5
+ * LT(1)
+ * consumeToken [c/<4>,1:0]
+ * location 7 7
+ * enterSubRule 2
+ * enter decision 2
+ * LT(1)
+ * LT(1)
+ * recognitionException NoViableAltException 2 1 2
+ * exit decision 2
+ * exitSubRule 2
+ * beginResync
+ * LT(1)
+ * consumeToken [c/<4>,1:1]
+ * LT(1)
+ * endResync
+ * LT(-1)
+ * exitRule b
+ * terminate
+ */
+ template<typename ExceptionBaseType>
+ void recognitionException( ExceptionBaseType* ) {}
+
+ /** Indicates the recognizer is about to consume tokens to resynchronize
+ * the parser. Any consume events from here until the recovered event
+ * are not part of the parse--they are dead tokens.
+ */
+ virtual void beginResync();
+
+ /** Indicates that the recognizer has finished consuming tokens in order
+ * to resynchronize. There may be multiple beginResync/endResync pairs
+ * before the recognizer comes out of errorRecovery mode (in which
+ * multiple errors are suppressed). This will be useful
+ * in a gui where you want to probably grey out tokens that are consumed
+ * but not matched to anything in grammar. Anything between
+ * a beginResync/endResync pair was tossed out by the parser.
+ */
+ virtual void endResync();
+
+ /** A semantic predicate was evaluate with this result and action text
+ */
+ virtual void semanticPredicate( bool result, const char * predicate);
+
+ /** Announce that parsing has begun. Not technically useful except for
+ * sending events over a socket. A GUI for example will launch a thread
+ * to connect and communicate with a remote parser. The thread will want
+ * to notify the GUI when a connection is made. ANTLR parsers
+ * trigger this upon entry to the first rule (the ruleLevel is used to
+ * figure this out).
+ */
+ virtual void commence();
+
+ /** Parsing is over; successfully or not. Mostly useful for telling
+ * remote debugging listeners that it's time to quit. When the rule
+ * invocation level goes to zero at the end of a rule, we are done
+ * parsing.
+ */
+ virtual void terminate();
+
+ /// Retrieve acknowledge response from the debugger. in fact this
+ /// response is never used at the moment. So we just read whatever
+ /// is in the socket buffer and throw it away.
+ ///
+ virtual void ack();
+
+ // T r e e P a r s i n g
+
+ /** Input for a tree parser is an AST, but we know nothing for sure
+ * about a node except its type and text (obtained from the adaptor).
+ * This is the analog of the consumeToken method. The ID is usually
+ * the memory address of the node.
+ * If the type is UP or DOWN, then
+ * the ID is not really meaningful as it's fixed--there is
+ * just one UP node and one DOWN navigation node.
+ *
+ * Note that unlike the Java version, the node type of the C parsers
+ * is always fixed as pANTLR3_BASE_TREE because all such structures
+ * contain a super pointer to their parent, which is generally COMMON_TREE and within
+ * that there is a super pointer that can point to a user type that encapsulates it.
+ * Almost akin to saying that it is an interface pointer except we don't need to
+ * know what the interface is in full, just those bits that are the base.
+ * @param t
+ */
+ virtual void consumeNode( TreeTypePtr t);
+
+ /** The tree parser looked ahead. If the type is UP or DOWN,
+ * then the ID is not really meaningful as it's fixed--there is
+ * just one UP node and one DOWN navigation node.
+ */
+ virtual void LTT( int i, TreeTypePtr t);
+
+
+ // A S T E v e n t s
+
+ /** A nil was created (even nil nodes have a unique ID...
+ * they are not "null" per se). As of 4/28/2006, this
+ * seems to be uniquely triggered when starting a new subtree
+ * such as when entering a subrule in automatic mode and when
+ * building a tree in rewrite mode.
*
- * If you are receiving this event over a socket via
- * RemoteDebugEventSocketListener then only t.ID is set.
- */
- virtual void nilNode( TreeTypePtr t);
-
- /** If a syntax error occurs, recognizers bracket the error
- * with an error node if they are building ASTs. This event
- * notifies the listener that this is the case
- */
- virtual void errorNode( TreeTypePtr t);
-
- /** Announce a new node built from token elements such as type etc...
- *
- * If you are receiving this event over a socket via
- * RemoteDebugEventSocketListener then only t.ID, type, text are
- * set.
- */
- virtual void createNode( TreeTypePtr t);
-
- /** Announce a new node built from an existing token.
- *
- * If you are receiving this event over a socket via
- * RemoteDebugEventSocketListener then only node.ID and token.tokenIndex
- * are set.
- */
- virtual void createNodeTok( TreeTypePtr node, CommonTokenType* token);
-
- /** Make a node the new root of an existing root. See
- *
- * Note: the newRootID parameter is possibly different
- * than the TreeAdaptor.becomeRoot() newRoot parameter.
- * In our case, it will always be the result of calling
- * TreeAdaptor.becomeRoot() and not root_n or whatever.
- *
- * The listener should assume that this event occurs
- * only when the current subrule (or rule) subtree is
- * being reset to newRootID.
- *
- * If you are receiving this event over a socket via
- * RemoteDebugEventSocketListener then only IDs are set.
- *
- * @see org.antlr.runtime.tree.TreeAdaptor.becomeRoot()
- */
- virtual void becomeRoot( TreeTypePtr newRoot, TreeTypePtr oldRoot);
-
- /** Make childID a child of rootID.
- *
- * If you are receiving this event over a socket via
- * RemoteDebugEventSocketListener then only IDs are set.
- *
- * @see org.antlr.runtime.tree.TreeAdaptor.addChild()
- */
- virtual void addChild( TreeTypePtr root, TreeTypePtr child);
-
- /** Set the token start/stop token index for a subtree root or node.
- *
- * If you are receiving this event over a socket via
- * RemoteDebugEventSocketListener then only t.ID is set.
- */
- virtual void setTokenBoundaries( TreeTypePtr t, ANTLR_MARKER tokenStartIndex, ANTLR_MARKER tokenStopIndex);
-
- /// Free up the resources allocated to this structure
- ///
- virtual ~DebugEventListener();
+ * If you are receiving this event over a socket via
+ * RemoteDebugEventSocketListener then only t.ID is set.
+ */
+ virtual void nilNode( TreeTypePtr t);
+
+ /** If a syntax error occurs, recognizers bracket the error
+ * with an error node if they are building ASTs. This event
+ * notifies the listener that this is the case
+ */
+ virtual void errorNode( TreeTypePtr t);
+
+ /** Announce a new node built from token elements such as type etc...
+ *
+ * If you are receiving this event over a socket via
+ * RemoteDebugEventSocketListener then only t.ID, type, text are
+ * set.
+ */
+ virtual void createNode( TreeTypePtr t);
+
+ /** Announce a new node built from an existing token.
+ *
+ * If you are receiving this event over a socket via
+ * RemoteDebugEventSocketListener then only node.ID and token.tokenIndex
+ * are set.
+ */
+ virtual void createNodeTok( TreeTypePtr node, CommonTokenType* token);
+
+ /** Make a node the new root of an existing root. See
+ *
+ * Note: the newRootID parameter is possibly different
+ * than the TreeAdaptor.becomeRoot() newRoot parameter.
+ * In our case, it will always be the result of calling
+ * TreeAdaptor.becomeRoot() and not root_n or whatever.
+ *
+ * The listener should assume that this event occurs
+ * only when the current subrule (or rule) subtree is
+ * being reset to newRootID.
+ *
+ * If you are receiving this event over a socket via
+ * RemoteDebugEventSocketListener then only IDs are set.
+ *
+ * @see org.antlr.runtime.tree.TreeAdaptor.becomeRoot()
+ */
+ virtual void becomeRoot( TreeTypePtr newRoot, TreeTypePtr oldRoot);
+
+ /** Make childID a child of rootID.
+ *
+ * If you are receiving this event over a socket via
+ * RemoteDebugEventSocketListener then only IDs are set.
+ *
+ * @see org.antlr.runtime.tree.TreeAdaptor.addChild()
+ */
+ virtual void addChild( TreeTypePtr root, TreeTypePtr child);
+
+ /** Set the token start/stop token index for a subtree root or node.
+ *
+ * If you are receiving this event over a socket via
+ * RemoteDebugEventSocketListener then only t.ID is set.
+ */
+ virtual void setTokenBoundaries( TreeTypePtr t, ANTLR_MARKER tokenStartIndex, ANTLR_MARKER tokenStopIndex);
+
+ /// Free up the resources allocated to this structure
+ ///
+ virtual ~DebugEventListener();
};
-}
+}
#endif
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3defs.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3defs.hpp
index 6c2d41713e..7f332981e6 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3defs.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3defs.hpp
@@ -1,8 +1,8 @@
/** \file
* Basic type and constant definitions for ANTLR3 Runtime.
*/
-#ifndef _ANTLR3DEFS_HPP
-#define _ANTLR3DEFS_HPP
+#ifndef _ANTLR3DEFS_HPP
+#define _ANTLR3DEFS_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -32,26 +32,26 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// not used in C++ target (kept for "historical" reasons, the generated code still uses this)
-#define ANTLR_SIZE_HINT 0U
+// not used in C++ target (kept for "historical" reasons, the generated code still uses this)
+#define ANTLR_SIZE_HINT 0U
/* Work out what operating system/compiler this is. We just do this once
* here and use an internal symbol after this.
*/
-#ifdef _WIN64
-# define ANTLR_USE_64BIT
+#ifdef _WIN64
+# define ANTLR_USE_64BIT
#endif
-#ifdef _WIN32
+#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
#endif
/* Allow VC 8 (vs2005) and above to use 'secure' versions of various functions such as sprintf
*/
-#ifndef _CRT_SECURE_NO_DEPRECATE
-#define _CRT_SECURE_NO_DEPRECATE
+#ifndef _CRT_SECURE_NO_DEPRECATE
+#define _CRT_SECURE_NO_DEPRECATE
#endif
#ifndef NOMINMAX
@@ -59,56 +59,56 @@
#endif
#include <winsock2.h>
-#define ANTLR_INLINE __inline
+#define ANTLR_INLINE __inline
-typedef FILE * ANTLR_FDSC;
+typedef FILE * ANTLR_FDSC;
-typedef struct sockaddr_in ANTLR_SOCKADDRT, * pANTLR_SOCKADDRT; // Type used for socket address declaration
-typedef struct sockaddr ANTLR_SOCKADDRC, * pANTLR_SOCKADDRC; // Type used for cast on accept()
+typedef struct sockaddr_in ANTLR_SOCKADDRT, * pANTLR_SOCKADDRT; // Type used for socket address declaration
+typedef struct sockaddr ANTLR_SOCKADDRC, * pANTLR_SOCKADDRC; // Type used for cast on accept()
-#define ANTLR_CLOSESOCKET closesocket
+#define ANTLR_CLOSESOCKET closesocket
-#else // Un*x
+#else // Un*x
#ifdef __LP64__
#define ANTLR_USE_64BIT
#endif
-#define ANTLR_INLINE inline
+#define ANTLR_INLINE inline
typedef int SOCKET;
-typedef FILE * ANTLR_FDSC;
-
-#endif
-
-// Standard integer types (since C++11) (should work with MSVC 2010/2013, gcc, clang)
-//
-typedef std::int32_t ANTLR_CHAR;
-typedef std::uint32_t ANTLR_UCHAR;
-
-typedef std::int8_t ANTLR_INT8;
-typedef std::int16_t ANTLR_INT16;
-typedef std::int32_t ANTLR_INT32;
-typedef std::int64_t ANTLR_INT64;
-
-typedef std::uint8_t ANTLR_UINT8;
-typedef std::uint16_t ANTLR_UINT16;
-typedef std::uint32_t ANTLR_UINT32;
-typedef std::uint64_t ANTLR_UINT64;
-typedef std::uint64_t ANTLR_BITWORD;
-
-#ifdef ANTLR_USE_64BIT
-#define ANTLR_UINT64_CAST(ptr) (ANTLR_UINT64)(ptr))
-#define ANTLR_UINT32_CAST(ptr) (ANTLR_UINT32)((ANTLR_UINT64)(ptr))
-typedef ANTLR_INT64 ANTLR_MARKER;
-typedef ANTLR_UINT64 ANTLR_INTKEY;
+typedef FILE * ANTLR_FDSC;
+
+#endif
+
+// Standard integer types (since C++11) (should work with MSVC 2010/2013, gcc, clang)
+//
+typedef std::int32_t ANTLR_CHAR;
+typedef std::uint32_t ANTLR_UCHAR;
+
+typedef std::int8_t ANTLR_INT8;
+typedef std::int16_t ANTLR_INT16;
+typedef std::int32_t ANTLR_INT32;
+typedef std::int64_t ANTLR_INT64;
+
+typedef std::uint8_t ANTLR_UINT8;
+typedef std::uint16_t ANTLR_UINT16;
+typedef std::uint32_t ANTLR_UINT32;
+typedef std::uint64_t ANTLR_UINT64;
+typedef std::uint64_t ANTLR_BITWORD;
+
+#ifdef ANTLR_USE_64BIT
+#define ANTLR_UINT64_CAST(ptr) (ANTLR_UINT64)(ptr))
+#define ANTLR_UINT32_CAST(ptr) (ANTLR_UINT32)((ANTLR_UINT64)(ptr))
+typedef ANTLR_INT64 ANTLR_MARKER;
+typedef ANTLR_UINT64 ANTLR_INTKEY;
#else
#define ANTLR_UINT64_CAST(ptr) (ANTLR_UINT64)((ANTLR_UINT32)(ptr))
-#define ANTLR_UINT32_CAST(ptr) (ANTLR_UINT32)(ptr)
-typedef ANTLR_INT32 ANTLR_MARKER;
-typedef ANTLR_UINT32 ANTLR_INTKEY;
+#define ANTLR_UINT32_CAST(ptr) (ANTLR_UINT32)(ptr)
+typedef ANTLR_INT32 ANTLR_MARKER;
+typedef ANTLR_UINT32 ANTLR_INTKEY;
#endif
-#define ANTLR_UINT64_LIT(lit) lit##ULL
+#define ANTLR_UINT64_LIT(lit) lit##ULL
-#endif /* _ANTLR3DEFS_H */
+#endif /* _ANTLR3DEFS_H */
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3errors.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3errors.hpp
index b0268c4737..0413d87e39 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3errors.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3errors.hpp
@@ -1,5 +1,5 @@
-#ifndef _ANTLR3ERRORS_HPP
-#define _ANTLR3ERRORS_HPP
+#ifndef _ANTLR3ERRORS_HPP
+#define _ANTLR3ERRORS_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -29,15 +29,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#define ANTLR_SUCCESS 0
-#define ANTLR_FAIL 1
+#define ANTLR_SUCCESS 0
+#define ANTLR_FAIL 1
/** Indicates end of character stream and is an invalid Unicode code point. */
-#define ANTLR_CHARSTREAM_EOF 0xFFFFFFFF
+#define ANTLR_CHARSTREAM_EOF 0xFFFFFFFF
/** Indicates memoizing on a rule failed.
*/
-#define MEMO_RULE_FAILED 0xFFFFFFFE
-#define MEMO_RULE_UNKNOWN 0xFFFFFFFF
+#define MEMO_RULE_FAILED 0xFFFFFFFE
+#define MEMO_RULE_UNKNOWN 0xFFFFFFFF
-#endif /* _ANTLR3ERRORS_H */
+#endif /* _ANTLR3ERRORS_H */
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3exception.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3exception.hpp
index d3b873c032..9bc18a0432 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3exception.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3exception.hpp
@@ -12,8 +12,8 @@
one container and hence needs virtual functions. But this would occur only when there is
a exception/ while deleting base recognizer. So shouldn't incur the overhead in normal operation
*/
-#ifndef _ANTLR3_EXCEPTION_HPP
-#define _ANTLR3_EXCEPTION_HPP
+#ifndef _ANTLR3_EXCEPTION_HPP
+#define _ANTLR3_EXCEPTION_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -43,7 +43,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
/** Base structure for an ANTLR3 exception tracker
*/
@@ -52,14 +52,14 @@ template<class ImplTraits, class StreamType>
class ANTLR_ExceptionBase
{
public:
- typedef typename StreamType::UnitType TokenType;
- typedef typename StreamType::IntStreamType IntStreamType;
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::StringStreamType StringStreamType;
- typedef typename ImplTraits::BitsetType BitsetType;
- typedef typename ImplTraits::BitsetListType BitsetListType;
- typedef typename ImplTraits::template ExceptionBaseType<StreamType> ExceptionBaseType;
+ typedef typename StreamType::UnitType TokenType;
+ typedef typename StreamType::IntStreamType IntStreamType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::StringStreamType StringStreamType;
+ typedef typename ImplTraits::BitsetType BitsetType;
+ typedef typename ImplTraits::BitsetListType BitsetListType;
+ typedef typename ImplTraits::template ExceptionBaseType<StreamType> ExceptionBaseType;
protected:
/** The printable message that goes with this exception, in your preferred
@@ -69,22 +69,22 @@ protected:
* the users of your product will understand, as they are unlikely to know what
* to do with "Recognition exception at: [[TOK_GERUND..... " ;-)
*/
- StringType m_message;
+ StringType m_message;
/** Name of the file/input source for reporting. Note that this may be empty!!
*/
- StringType m_streamName;
+ StringType m_streamName;
/** Indicates the index of the 'token' we were looking at when the
* exception occurred.
*/
- ANTLR_MARKER m_index;
+ ANTLR_MARKER m_index;
/** Indicates what the current token/tree was when the error occurred. Since not
* all input streams will be able to retrieve the nth token, we track it here
* instead. This is for parsers, and even tree parsers may set this.
*/
- const TokenType* m_token;
+ const TokenType* m_token;
/** Pointer to the next exception in the chain (if any)
*/
@@ -92,91 +92,91 @@ protected:
/** Indicates the token we were expecting to see next when the error occurred
*/
- ANTLR_UINT32 m_expecting;
+ ANTLR_UINT32 m_expecting;
/** Indicates a set of tokens that we were expecting to see one of when the
* error occurred. It is a following bitset list, so you can use load it and use ->toIntList() on it
* to generate an array of integer tokens that it represents.
*/
- BitsetListType* m_expectingSet;
+ BitsetListType* m_expectingSet;
/** If this is a tree parser exception then the node is set to point to the node
* that caused the issue.
*/
- TokenType* m_node;
+ TokenType* m_node;
/** The current character when an error occurred - for lexers.
*/
- ANTLR_UCHAR m_c;
+ ANTLR_UCHAR m_c;
/** Track the line at which the error occurred in case this is
* generated from a lexer. We need to track this since the
* unexpected char doesn't carry the line info.
*/
- ANTLR_UINT32 m_line;
+ ANTLR_UINT32 m_line;
/** Character position in the line where the error occurred.
*/
- ANTLR_INT32 m_charPositionInLine;
+ ANTLR_INT32 m_charPositionInLine;
/** decision number for NVE
*/
- ANTLR_UINT32 m_decisionNum;
+ ANTLR_UINT32 m_decisionNum;
/** State for NVE
*/
- ANTLR_UINT32 m_state;
+ ANTLR_UINT32 m_state;
/** Rule name for failed predicate exception
*/
- StringType m_ruleName;
+ StringType m_ruleName;
/** Pointer to the input stream that this exception occurred in.
*/
- IntStreamType* m_input;
+ IntStreamType* m_input;
public:
- StringType& get_message();
- StringType& get_streamName();
- ANTLR_MARKER get_index() const;
- const TokenType* get_token() const;
- ExceptionBaseType* get_nextException() const;
- ANTLR_UINT32 get_expecting() const;
- BitsetListType* get_expectingSet() const;
- TokenType* get_node() const;
- ANTLR_UCHAR get_c() const;
- ANTLR_UINT32 get_line() const;
- ANTLR_INT32 get_charPositionInLine() const;
- ANTLR_UINT32 get_decisionNum() const;
- ANTLR_UINT32 get_state() const;
- StringType& get_ruleName();
- IntStreamType* get_input() const;
- void set_message( const StringType& message );
- void set_streamName( const StringType& streamName );
- void set_index( ANTLR_MARKER index );
- void set_token( const TokenType* token );
- void set_nextException( ExceptionBaseType* nextException );
- void set_expecting( ANTLR_UINT32 expecting );
- void set_expectingSet( BitsetListType* expectingSet );
- void set_node( TokenType* node );
- void set_c( ANTLR_UCHAR c );
- void set_line( ANTLR_UINT32 line );
- void set_charPositionInLine( ANTLR_INT32 charPositionInLine );
- void set_decisionNum( ANTLR_UINT32 decisionNum );
- void set_state( ANTLR_UINT32 state );
- void set_ruleName( const StringType& ruleName );
- void set_input( IntStreamType* input );
- StringType getDescription() const;
-
- virtual StringType getName() const = 0;
- virtual ANTLR_UINT32 getType() const = 0;
- virtual void print() const = 0;
- virtual void displayRecognitionError( ANTLR_UINT8** tokenNames, StringStreamType& str ) const = 0;
+ StringType& get_message();
+ StringType& get_streamName();
+ ANTLR_MARKER get_index() const;
+ const TokenType* get_token() const;
+ ExceptionBaseType* get_nextException() const;
+ ANTLR_UINT32 get_expecting() const;
+ BitsetListType* get_expectingSet() const;
+ TokenType* get_node() const;
+ ANTLR_UCHAR get_c() const;
+ ANTLR_UINT32 get_line() const;
+ ANTLR_INT32 get_charPositionInLine() const;
+ ANTLR_UINT32 get_decisionNum() const;
+ ANTLR_UINT32 get_state() const;
+ StringType& get_ruleName();
+ IntStreamType* get_input() const;
+ void set_message( const StringType& message );
+ void set_streamName( const StringType& streamName );
+ void set_index( ANTLR_MARKER index );
+ void set_token( const TokenType* token );
+ void set_nextException( ExceptionBaseType* nextException );
+ void set_expecting( ANTLR_UINT32 expecting );
+ void set_expectingSet( BitsetListType* expectingSet );
+ void set_node( TokenType* node );
+ void set_c( ANTLR_UCHAR c );
+ void set_line( ANTLR_UINT32 line );
+ void set_charPositionInLine( ANTLR_INT32 charPositionInLine );
+ void set_decisionNum( ANTLR_UINT32 decisionNum );
+ void set_state( ANTLR_UINT32 state );
+ void set_ruleName( const StringType& ruleName );
+ void set_input( IntStreamType* input );
+ StringType getDescription() const;
+
+ virtual StringType getName() const = 0;
+ virtual ANTLR_UINT32 getType() const = 0;
+ virtual void print() const = 0;
+ virtual void displayRecognitionError( ANTLR_UINT8** tokenNames, StringStreamType& str ) const = 0;
virtual ~ANTLR_ExceptionBase();
protected:
- ANTLR_ExceptionBase(const StringType& message);
+ ANTLR_ExceptionBase(const StringType& message);
};
@@ -184,23 +184,23 @@ template<class ImplTraits, ExceptionType Ex, class StreamType>
class ANTLR_Exception : public ImplTraits::template ExceptionBaseType<StreamType>
{
public:
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::StringStreamType StringStreamType;
- typedef typename ImplTraits::BitsetType BitsetType;
- typedef typename ImplTraits::template ExceptionBaseType<StreamType> BaseType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::StringStreamType StringStreamType;
+ typedef typename ImplTraits::BitsetType BitsetType;
+ typedef typename ImplTraits::template ExceptionBaseType<StreamType> BaseType;
public:
- template<typename BaseRecognizerType>
- ANTLR_Exception(BaseRecognizerType* recognizer, const StringType& message);
-
- const StringType& get_name() const;
- virtual StringType getName() const;
- virtual ANTLR_UINT32 getType() const;
- virtual void print() const;
- virtual void displayRecognitionError( ANTLR_UINT8** tokenNames, StringStreamType& str_stream) const;
+ template<typename BaseRecognizerType>
+ ANTLR_Exception(BaseRecognizerType* recognizer, const StringType& message);
+
+ const StringType& get_name() const;
+ virtual StringType getName() const;
+ virtual ANTLR_UINT32 getType() const;
+ virtual void print() const;
+ virtual void displayRecognitionError( ANTLR_UINT8** tokenNames, StringStreamType& str_stream) const;
};
-}
+}
#include "antlr3exception.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3exception.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3exception.inl
index 8f9f39c876..27f00bdda8 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3exception.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3exception.inl
@@ -1,385 +1,385 @@
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits, class StreamType>
ANTLR_ExceptionBase<ImplTraits, StreamType>::ANTLR_ExceptionBase(const StringType& message)
- :m_message(message)
- ,m_input(NULL)
-{
- m_index = 0;
- m_token = NULL;
- m_expecting = 0;
- m_expectingSet = NULL;
- m_node = NULL;
- m_c = 0;
- m_line = 0;
- m_charPositionInLine = 0;
- m_decisionNum = 0;
- m_state = 0;
- m_nextException = NULL;
+ :m_message(message)
+ ,m_input(NULL)
+{
+ m_index = 0;
+ m_token = NULL;
+ m_expecting = 0;
+ m_expectingSet = NULL;
+ m_node = NULL;
+ m_c = 0;
+ m_line = 0;
+ m_charPositionInLine = 0;
+ m_decisionNum = 0;
+ m_state = 0;
+ m_nextException = NULL;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename ANTLR_ExceptionBase<ImplTraits, StreamType>::StringType& ANTLR_ExceptionBase<ImplTraits, StreamType>::get_message()
{
- return m_message;
+ return m_message;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename ANTLR_ExceptionBase<ImplTraits, StreamType>::StringType& ANTLR_ExceptionBase<ImplTraits, StreamType>::get_streamName()
{
- return m_streamName;
+ return m_streamName;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_MARKER ANTLR_ExceptionBase<ImplTraits, StreamType>::get_index() const
{
- return m_index;
+ return m_index;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE const typename ANTLR_ExceptionBase<ImplTraits, StreamType>::TokenType* ANTLR_ExceptionBase<ImplTraits, StreamType>::get_token() const
{
- return m_token;
+ return m_token;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename ANTLR_ExceptionBase<ImplTraits, StreamType>::ExceptionBaseType* ANTLR_ExceptionBase<ImplTraits, StreamType>::get_nextException() const
{
- return m_nextException;
+ return m_nextException;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_UINT32 ANTLR_ExceptionBase<ImplTraits, StreamType>::get_expecting() const
{
- return m_expecting;
+ return m_expecting;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename ANTLR_ExceptionBase<ImplTraits, StreamType>::BitsetListType* ANTLR_ExceptionBase<ImplTraits, StreamType>::get_expectingSet() const
{
- return m_expectingSet;
+ return m_expectingSet;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename ANTLR_ExceptionBase<ImplTraits, StreamType>::TokenType* ANTLR_ExceptionBase<ImplTraits, StreamType>::get_node() const
{
- return m_node;
+ return m_node;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_UCHAR ANTLR_ExceptionBase<ImplTraits, StreamType>::get_c() const
{
- return m_c;
+ return m_c;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_UINT32 ANTLR_ExceptionBase<ImplTraits, StreamType>::get_line() const
{
- return m_line;
+ return m_line;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_INT32 ANTLR_ExceptionBase<ImplTraits, StreamType>::get_charPositionInLine() const
{
- return m_charPositionInLine;
+ return m_charPositionInLine;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_UINT32 ANTLR_ExceptionBase<ImplTraits, StreamType>::get_decisionNum() const
{
- return m_decisionNum;
+ return m_decisionNum;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_UINT32 ANTLR_ExceptionBase<ImplTraits, StreamType>::get_state() const
{
- return m_state;
+ return m_state;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename ANTLR_ExceptionBase<ImplTraits, StreamType>::StringType& ANTLR_ExceptionBase<ImplTraits, StreamType>::get_ruleName()
{
- return m_ruleName;
+ return m_ruleName;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename ANTLR_ExceptionBase<ImplTraits, StreamType>::IntStreamType* ANTLR_ExceptionBase<ImplTraits, StreamType>::get_input() const
{
- return m_input;
+ return m_input;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_message( const StringType& message )
{
- m_message = message;
+ m_message = message;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_streamName( const StringType& streamName )
{
- m_streamName = streamName;
+ m_streamName = streamName;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_index( ANTLR_MARKER index )
{
- m_index = index;
+ m_index = index;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_token( const TokenType* token )
{
- if (m_token)
- delete m_token;
- m_token = token;
+ if (m_token)
+ delete m_token;
+ m_token = token;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_nextException( ExceptionBaseType* nextException )
{
- m_nextException = nextException;
+ m_nextException = nextException;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_expecting( ANTLR_UINT32 expecting )
{
- m_expecting = expecting;
+ m_expecting = expecting;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_expectingSet( BitsetListType* expectingSet )
{
- m_expectingSet = expectingSet;
+ m_expectingSet = expectingSet;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_node( TokenType* node )
{
- m_node = node;
+ m_node = node;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_c( ANTLR_UCHAR c )
{
- m_c = c;
+ m_c = c;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_line( ANTLR_UINT32 line )
{
- m_line = line;
+ m_line = line;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_charPositionInLine( ANTLR_INT32 charPositionInLine )
{
- m_charPositionInLine = charPositionInLine;
+ m_charPositionInLine = charPositionInLine;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_decisionNum( ANTLR_UINT32 decisionNum )
{
- m_decisionNum = decisionNum;
+ m_decisionNum = decisionNum;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_state( ANTLR_UINT32 state )
{
- m_state = state;
+ m_state = state;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_ruleName( const StringType& ruleName )
{
- m_ruleName = ruleName;
+ m_ruleName = ruleName;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void ANTLR_ExceptionBase<ImplTraits, StreamType>::set_input( IntStreamType* input )
{
- m_input = input;
+ m_input = input;
}
template<class ImplTraits, ExceptionType Ex, class StreamType>
- template<typename BaseRecognizerType>
+ template<typename BaseRecognizerType>
ANTLR_Exception<ImplTraits, Ex, StreamType>::ANTLR_Exception(BaseRecognizerType* recognizer, const StringType& message)
- :BaseType( message )
+ :BaseType( message )
{
- recognizer->get_super()->fillExceptionData( this );
- BaseType::m_input = recognizer->get_super()->get_istream();
- BaseType::m_nextException = recognizer->get_state()->get_exception(); /* So we don't leak the memory */
- recognizer->get_state()->set_exception(this);
- recognizer->get_state()->set_error( true ); /* Exception is outstanding */
+ recognizer->get_super()->fillExceptionData( this );
+ BaseType::m_input = recognizer->get_super()->get_istream();
+ BaseType::m_nextException = recognizer->get_state()->get_exception(); /* So we don't leak the memory */
+ recognizer->get_state()->set_exception(this);
+ recognizer->get_state()->set_error( true ); /* Exception is outstanding */
}
template<class ImplTraits, ExceptionType Ex, class StreamType>
ANTLR_UINT32 ANTLR_Exception<ImplTraits, Ex, StreamType>::getType() const
{
- return static_cast<ANTLR_UINT32>(Ex);
+ return static_cast<ANTLR_UINT32>(Ex);
}
template<class ImplTraits, ExceptionType Ex, class StreamType>
-void ANTLR_Exception<ImplTraits, Ex, StreamType>::print() const
-{
- /* Ensure valid pointer
- */
- /* Number if no message, else the message
- */
- if ( BaseType::m_message.empty() )
- {
- fprintf(stderr, "ANTLR3_EXCEPTION number %d (%08X).\n", Ex, Ex);
- }
- else
- {
- fprintf(stderr, "ANTLR3_EXCEPTION: %s\n", BaseType::m_message.c_str() );
- }
+void ANTLR_Exception<ImplTraits, Ex, StreamType>::print() const
+{
+ /* Ensure valid pointer
+ */
+ /* Number if no message, else the message
+ */
+ if ( BaseType::m_message.empty() )
+ {
+ fprintf(stderr, "ANTLR3_EXCEPTION number %d (%08X).\n", Ex, Ex);
+ }
+ else
+ {
+ fprintf(stderr, "ANTLR3_EXCEPTION: %s\n", BaseType::m_message.c_str() );
+ }
}
template<class ImplTraits, ExceptionType Ex, class StreamType>
-typename ANTLR_Exception<ImplTraits, Ex, StreamType>::StringType
- ANTLR_Exception<ImplTraits, Ex, StreamType>::getName() const
-{
- const char* exArray[] = {
- "org.antlr.runtime.RecognitionException"
- , "org.antlr.runtime.MismatchedTokenException"
- , "org.antlr.runtime.NoViableAltException"
- , "org.antlr.runtime.MismatchedSetException"
- , "org.antlr.runtime.EarlyExitException"
- , "org.antlr.runtime.FailedPredicateException"
- , "org.antlr.runtime.MismatchedTreeNodeException"
- , "org.antlr.runtime.tree.RewriteEarlyExitException"
- , "org.antlr.runtime.UnwantedTokenException"
- , "org.antlr.runtime.MissingTokenException"
- };
- return StringType(exArray[Ex]);
-}
+typename ANTLR_Exception<ImplTraits, Ex, StreamType>::StringType
+ ANTLR_Exception<ImplTraits, Ex, StreamType>::getName() const
+{
+ const char* exArray[] = {
+ "org.antlr.runtime.RecognitionException"
+ , "org.antlr.runtime.MismatchedTokenException"
+ , "org.antlr.runtime.NoViableAltException"
+ , "org.antlr.runtime.MismatchedSetException"
+ , "org.antlr.runtime.EarlyExitException"
+ , "org.antlr.runtime.FailedPredicateException"
+ , "org.antlr.runtime.MismatchedTreeNodeException"
+ , "org.antlr.runtime.tree.RewriteEarlyExitException"
+ , "org.antlr.runtime.UnwantedTokenException"
+ , "org.antlr.runtime.MissingTokenException"
+ };
+ return StringType(exArray[Ex]);
+}
-template<class ImplTraits, ExceptionType Ex, class StreamType>
-void ANTLR_Exception<ImplTraits, Ex, StreamType>::displayRecognitionError( ANTLR_UINT8** tokenNames,
- StringStreamType& str_stream ) const
-{
- switch( Ex )
- {
- case RECOGNITION_EXCEPTION:
- // Indicates that the recognizer received a token
- // in the input that was not predicted. This is the basic exception type
- // from which all others are derived. So we assume it was a syntax error.
- // You may get this if there are not more tokens and more are needed
- // to complete a parse for instance.
- //
- str_stream << " : syntax error...\n";
- break;
- case UNWANTED_TOKEN_EXCEPTION:
- // Indicates that the recognizer was fed a token which seesm to be
- // spurious input. We can detect this when the token that follows
- // this unwanted token would normally be part of the syntactically
- // correct stream. Then we can see that the token we are looking at
- // is just something that should not be there and throw this exception.
- //
- if (tokenNames == NULL)
- {
- str_stream << " : Extraneous input...";
- }
- else
- {
- if ( BaseType::m_expecting == ImplTraits::CommonTokenType::TOKEN_EOF)
- {
- str_stream << " : Extraneous input - expected <EOF>\n";
- }
- else
- {
- str_stream << " : Extraneous input - expected "
- << tokenNames[ BaseType::m_expecting] << " ...\n";
- }
- }
- break;
- case MISSING_TOKEN_EXCEPTION:
- // Indicates that the recognizer detected that the token we just
- // hit would be valid syntactically if preceeded by a particular
- // token. Perhaps a missing ';' at line end or a missing ',' in an
- // expression list, and such like.
- //
- if (tokenNames == NULL)
- {
- str_stream << " : Missing token ("
- << BaseType::m_expecting << ")...\n";
- }
- else
- {
- if ( BaseType::m_expecting == ImplTraits::CommonTokenType::TOKEN_EOF )
- {
- str_stream <<" : Missing <EOF>\n";
- }
- else
- {
- str_stream << " : Missing " << tokenNames[BaseType::m_expecting] <<" \n";
- }
- }
- break;
- case NO_VIABLE_ALT_EXCEPTION:
- // We could not pick any alt decision from the input given
- // so god knows what happened - however when you examine your grammar,
- // you should. It means that at the point where the current token occurred
- // that the DFA indicates nowhere to go from here.
- //
- str_stream << " : cannot match to any predicted input...\n";
- break;
- case MISMATCHED_SET_EXCEPTION:
- {
- ANTLR_UINT32 count;
- ANTLR_UINT32 bit;
- ANTLR_UINT32 size;
- ANTLR_UINT32 numbits;
+template<class ImplTraits, ExceptionType Ex, class StreamType>
+void ANTLR_Exception<ImplTraits, Ex, StreamType>::displayRecognitionError( ANTLR_UINT8** tokenNames,
+ StringStreamType& str_stream ) const
+{
+ switch( Ex )
+ {
+ case RECOGNITION_EXCEPTION:
+ // Indicates that the recognizer received a token
+ // in the input that was not predicted. This is the basic exception type
+ // from which all others are derived. So we assume it was a syntax error.
+ // You may get this if there are not more tokens and more are needed
+ // to complete a parse for instance.
+ //
+ str_stream << " : syntax error...\n";
+ break;
+ case UNWANTED_TOKEN_EXCEPTION:
+ // Indicates that the recognizer was fed a token which seesm to be
+ // spurious input. We can detect this when the token that follows
+ // this unwanted token would normally be part of the syntactically
+ // correct stream. Then we can see that the token we are looking at
+ // is just something that should not be there and throw this exception.
+ //
+ if (tokenNames == NULL)
+ {
+ str_stream << " : Extraneous input...";
+ }
+ else
+ {
+ if ( BaseType::m_expecting == ImplTraits::CommonTokenType::TOKEN_EOF)
+ {
+ str_stream << " : Extraneous input - expected <EOF>\n";
+ }
+ else
+ {
+ str_stream << " : Extraneous input - expected "
+ << tokenNames[ BaseType::m_expecting] << " ...\n";
+ }
+ }
+ break;
+ case MISSING_TOKEN_EXCEPTION:
+ // Indicates that the recognizer detected that the token we just
+ // hit would be valid syntactically if preceeded by a particular
+ // token. Perhaps a missing ';' at line end or a missing ',' in an
+ // expression list, and such like.
+ //
+ if (tokenNames == NULL)
+ {
+ str_stream << " : Missing token ("
+ << BaseType::m_expecting << ")...\n";
+ }
+ else
+ {
+ if ( BaseType::m_expecting == ImplTraits::CommonTokenType::TOKEN_EOF )
+ {
+ str_stream <<" : Missing <EOF>\n";
+ }
+ else
+ {
+ str_stream << " : Missing " << tokenNames[BaseType::m_expecting] <<" \n";
+ }
+ }
+ break;
+ case NO_VIABLE_ALT_EXCEPTION:
+ // We could not pick any alt decision from the input given
+ // so god knows what happened - however when you examine your grammar,
+ // you should. It means that at the point where the current token occurred
+ // that the DFA indicates nowhere to go from here.
+ //
+ str_stream << " : cannot match to any predicted input...\n";
+ break;
+ case MISMATCHED_SET_EXCEPTION:
+ {
+ ANTLR_UINT32 count;
+ ANTLR_UINT32 bit;
+ ANTLR_UINT32 size;
+ ANTLR_UINT32 numbits;
- // This means we were able to deal with one of a set of
- // possible tokens at this point, but we did not see any
- // member of that set.
- //
+ // This means we were able to deal with one of a set of
+ // possible tokens at this point, but we did not see any
+ // member of that set.
+ //
str_stream << " : unexpected input :";
- // What tokens could we have accepted at this point in the
- // parse?
- //
- count = 0;
+ // What tokens could we have accepted at this point in the
+ // parse?
+ //
+ count = 0;
size = 0;
if (BaseType::m_expectingSet != NULL) {
std::unique_ptr<BitsetType> errBits(BaseType::m_expectingSet->bitsetLoad());
numbits = errBits->numBits();
size = errBits->size();
}
-
- if (size > 0)
- {
- // However many tokens we could have dealt with here, it is usually
- // not useful to print ALL of the set here. I arbitrarily chose 8
- // here, but you should do whatever makes sense for you of course.
- // No token number 0, so look for bit 1 and on.
- //
+
+ if (size > 0)
+ {
+ // However many tokens we could have dealt with here, it is usually
+ // not useful to print ALL of the set here. I arbitrarily chose 8
+ // here, but you should do whatever makes sense for you of course.
+ // No token number 0, so look for bit 1 and on.
+ //
str_stream << " expected one of : ";
- for (bit = 1; bit < numbits && count < 8 && count < size; bit++)
- {
- // TODO: This doesn;t look right - should be asking if the bit is set!!
- //
- if (tokenNames[bit])
- {
- str_stream << ( count > 0 ? ", " : "" )
- << tokenNames[bit];
- count++;
- }
- }
- str_stream << "\n";
- }
- else
- {
+ for (bit = 1; bit < numbits && count < 8 && count < size; bit++)
+ {
+ // TODO: This doesn;t look right - should be asking if the bit is set!!
+ //
+ if (tokenNames[bit])
+ {
+ str_stream << ( count > 0 ? ", " : "" )
+ << tokenNames[bit];
+ count++;
+ }
+ }
+ str_stream << "\n";
+ }
+ else
+ {
str_stream << " nothing is expected here\n";
- }
- }
- break;
- case EARLY_EXIT_EXCEPTION:
- str_stream << " : missing elements...\n";
- break;
- default:
- str_stream << " : syntax not recognized...\n";
- break;
- }
+ }
+ }
+ break;
+ case EARLY_EXIT_EXCEPTION:
+ str_stream << " : missing elements...\n";
+ break;
+ default:
+ str_stream << " : syntax not recognized...\n";
+ break;
+ }
}
template<class ImplTraits, class StreamType>
ANTLR_ExceptionBase<ImplTraits,StreamType>::~ANTLR_ExceptionBase()
{
- ANTLR_ExceptionBase<ImplTraits,StreamType>* next;
- ANTLR_ExceptionBase<ImplTraits,StreamType>* ex = m_nextException;
+ ANTLR_ExceptionBase<ImplTraits,StreamType>* next;
+ ANTLR_ExceptionBase<ImplTraits,StreamType>* ex = m_nextException;
- /* Ensure valid pointer
- */
- while (ex != NULL)
- {
- /* Pick up anythign following now, before we free the
- * current memory block.
- */
- next = ex->m_nextException;
- ex->m_nextException = NULL;
+ /* Ensure valid pointer
+ */
+ while (ex != NULL)
+ {
+ /* Pick up anythign following now, before we free the
+ * current memory block.
+ */
+ next = ex->m_nextException;
+ ex->m_nextException = NULL;
- /* Free the actual structure itself
- */
- delete ex;
+ /* Free the actual structure itself
+ */
+ delete ex;
- ex = next;
- }
- if ( m_token)
- delete m_token;
+ ex = next;
+ }
+ if ( m_token)
+ delete m_token;
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3filestream.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3filestream.hpp
index 55985cb061..140b1a5f67 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3filestream.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3filestream.hpp
@@ -1,5 +1,5 @@
-#ifndef _ANTLR3_FILESTREAM_HPP
-#define _ANTLR3_FILESTREAM_HPP
+#ifndef _ANTLR3_FILESTREAM_HPP
+#define _ANTLR3_FILESTREAM_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -29,41 +29,41 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits>
class FileUtils
{
public:
- /** \brief Open an operating system file and return the descriptor
- * We just use the common open() and related functions here.
- * Later we might find better ways on systems
- * such as Windows and OpenVMS for instance. But the idea is to read the
- * while file at once anyway, so it may be irrelevant.
- */
- static ANTLR_FDSC AntlrFopen(const ANTLR_UINT8* filename, const char * mode);
+ /** \brief Open an operating system file and return the descriptor
+ * We just use the common open() and related functions here.
+ * Later we might find better ways on systems
+ * such as Windows and OpenVMS for instance. But the idea is to read the
+ * while file at once anyway, so it may be irrelevant.
+ */
+ static ANTLR_FDSC AntlrFopen(const ANTLR_UINT8* filename, const char * mode);
- /** \brief Close an operating system file and free any handles
- * etc.
- */
- static void AntlrFclose (ANTLR_FDSC fd);
+ /** \brief Close an operating system file and free any handles
+ * etc.
+ */
+ static void AntlrFclose (ANTLR_FDSC fd);
- static ANTLR_UINT32 AntlrFsize(const ANTLR_UINT8* filename);
- template<typename InputStreamType>
- static ANTLR_UINT32 AntlrRead8Bit(InputStreamType* input, const ANTLR_UINT8* fileName);
- static ANTLR_UINT32 AntlrFread(ANTLR_FDSC fdsc, ANTLR_UINT32 count, void* data);
+ static ANTLR_UINT32 AntlrFsize(const ANTLR_UINT8* filename);
+ template<typename InputStreamType>
+ static ANTLR_UINT32 AntlrRead8Bit(InputStreamType* input, const ANTLR_UINT8* fileName);
+ static ANTLR_UINT32 AntlrFread(ANTLR_FDSC fdsc, ANTLR_UINT32 count, void* data);
};
class ParseFileAbsentException : public std::exception
{
virtual const char* what() const noexcept
- {
- return " Parse File not Present";
- }
+ {
+ return " Parse File not Present";
+ }
};
-}
+}
#include "antlr3filestream.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3filestream.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3filestream.inl
index 3960233175..b67804adf2 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3filestream.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3filestream.inl
@@ -1,21 +1,21 @@
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits>
-ANTLR_FDSC FileUtils<ImplTraits>::AntlrFopen(const ANTLR_UINT8* filename, const char * mode)
+ANTLR_FDSC FileUtils<ImplTraits>::AntlrFopen(const ANTLR_UINT8* filename, const char * mode)
{
- return (ANTLR_FDSC)fopen((const char *)filename, mode);
+ return (ANTLR_FDSC)fopen((const char *)filename, mode);
}
template<class ImplTraits>
-void FileUtils<ImplTraits>::AntlrFclose (ANTLR_FDSC fd)
+void FileUtils<ImplTraits>::AntlrFclose (ANTLR_FDSC fd)
{
- fclose(fd);
+ fclose(fd);
}
template<class ImplTraits>
-ANTLR_UINT32 FileUtils<ImplTraits>::AntlrFsize(const ANTLR_UINT8* filename)
+ANTLR_UINT32 FileUtils<ImplTraits>::AntlrFsize(const ANTLR_UINT8* filename)
{
- struct _stat statbuf;
+ struct _stat statbuf;
_stat((const char *)filename, &statbuf);
@@ -23,52 +23,52 @@ ANTLR_UINT32 FileUtils<ImplTraits>::AntlrFsize(const ANTLR_UINT8* filename)
}
template<class ImplTraits>
-ANTLR_UINT32 FileUtils<ImplTraits>::AntlrFread(ANTLR_FDSC fdsc, ANTLR_UINT32 count, void* data)
+ANTLR_UINT32 FileUtils<ImplTraits>::AntlrFread(ANTLR_FDSC fdsc, ANTLR_UINT32 count, void* data)
{
- return (ANTLR_UINT32)fread(data, (size_t)count, 1, fdsc);
+ return (ANTLR_UINT32)fread(data, (size_t)count, 1, fdsc);
}
template<class ImplTraits>
- template<typename InputStreamType>
-ANTLR_UINT32 FileUtils<ImplTraits>::AntlrRead8Bit(InputStreamType* input, const ANTLR_UINT8* fileName)
+ template<typename InputStreamType>
+ANTLR_UINT32 FileUtils<ImplTraits>::AntlrRead8Bit(InputStreamType* input, const ANTLR_UINT8* fileName)
{
- ANTLR_FDSC infile;
- ANTLR_UINT32 fSize;
-
- /* Open the OS file in read binary mode
- */
- infile = FileUtils<ImplTraits>::AntlrFopen(fileName, "rb");
-
- /* Check that it was there
- */
- if (infile == NULL)
- {
- ParseFileAbsentException ex;
- throw ex;
- }
-
- /* It was there, so we can read the bytes now
- */
- fSize = FileUtils<ImplTraits>::AntlrFsize(fileName); /* Size of input file */
-
- /* Allocate buffer for this input set
- */
- void* data = ImplTraits::AllocPolicyType::alloc(fSize);
- /* Now we read the file. Characters are not converted to
- * the internal ANTLR encoding until they are read from the buffer
- */
- FileUtils<ImplTraits>::AntlrFread(infile, fSize, data );
-
- input->set_data( (unsigned char*) data );
- input->set_sizeBuf( fSize );
-
- input->set_isAllocated(true);
-
- /* And close the file handle
- */
- FileUtils<ImplTraits>::AntlrFclose(infile);
-
- return ANTLR_SUCCESS;
+ ANTLR_FDSC infile;
+ ANTLR_UINT32 fSize;
+
+ /* Open the OS file in read binary mode
+ */
+ infile = FileUtils<ImplTraits>::AntlrFopen(fileName, "rb");
+
+ /* Check that it was there
+ */
+ if (infile == NULL)
+ {
+ ParseFileAbsentException ex;
+ throw ex;
+ }
+
+ /* It was there, so we can read the bytes now
+ */
+ fSize = FileUtils<ImplTraits>::AntlrFsize(fileName); /* Size of input file */
+
+ /* Allocate buffer for this input set
+ */
+ void* data = ImplTraits::AllocPolicyType::alloc(fSize);
+ /* Now we read the file. Characters are not converted to
+ * the internal ANTLR encoding until they are read from the buffer
+ */
+ FileUtils<ImplTraits>::AntlrFread(infile, fSize, data );
+
+ input->set_data( (unsigned char*) data );
+ input->set_sizeBuf( fSize );
+
+ input->set_isAllocated(true);
+
+ /* And close the file handle
+ */
+ FileUtils<ImplTraits>::AntlrFclose(infile);
+
+ return ANTLR_SUCCESS;
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3input.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3input.hpp
index 2416688714..d167f5b392 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3input.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3input.hpp
@@ -5,8 +5,8 @@
* can return a 32 bit Integer representation of their characters amd efficiently mark and revert
* to specific offsets into their input streams.
*/
-#ifndef _ANTLR_INPUT_HPP
-#define _ANTLR_INPUT_HPP
+#ifndef _ANTLR_INPUT_HPP
+#define _ANTLR_INPUT_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -36,83 +36,83 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
/// Master context structure for an ANTLR3 C runtime based input stream.
-/// \ingroup apistructures. Calling LT on this doesn't seem right. You would
-/// call it only with parser / TreeParser, and their respective input streams
+/// \ingroup apistructures. Calling LT on this doesn't seem right. You would
+/// call it only with parser / TreeParser, and their respective input streams
/// has that function. calling it from lexer will throw a compile time error
///
template<class ImplTraits>
-class InputStream : public ImplTraits::template IntStreamType< typename ImplTraits::InputStreamType >
+class InputStream : public ImplTraits::template IntStreamType< typename ImplTraits::InputStreamType >
{
public:
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename ImplTraits::LexStateType LexStateType;
- typedef typename ImplTraits::template IntStreamType< typename ImplTraits::InputStreamType > IntStreamType;
- typedef IntStreamType BaseType;
- typedef typename ImplTraits::StreamDataType UnitType;
- typedef UnitType DataType;
- typedef UnitType TokenType;
- typedef typename AllocPolicyType::template VectorType<LexStateType> MarkersType;
- typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::LexStateType LexStateType;
+ typedef typename ImplTraits::template IntStreamType< typename ImplTraits::InputStreamType > IntStreamType;
+ typedef IntStreamType BaseType;
+ typedef typename ImplTraits::StreamDataType UnitType;
+ typedef UnitType DataType;
+ typedef UnitType TokenType;
+ typedef typename AllocPolicyType::template VectorType<LexStateType> MarkersType;
+ typedef typename ImplTraits::StringType StringType;
private:
/** Pointer the start of the input string, characters may be
* taken as offsets from here and in original input format encoding.
*/
- const DataType* m_data;
+ const DataType* m_data;
/** Pointer to the next character to be consumed from the input data
* This is cast to point at the encoding of the original file that
* was read by the functions installed as pointer in this input stream
* context instance at file/string/whatever load time.
*/
- const DataType* m_nextChar;
+ const DataType* m_nextChar;
/** Number of characters that can be consumed at this point in time.
* Mostly this is just what is left in the pre-read buffer, but if the
* input source is a stream such as a socket or something then we may
* call special read code to wait for more input.
*/
- ANTLR_UINT32 m_sizeBuf;
+ ANTLR_UINT32 m_sizeBuf;
/** The line number we are traversing in the input file. This gets incremented
* by a newline() call in the lexer grammar actions.
*/
- ANTLR_UINT32 m_line;
+ ANTLR_UINT32 m_line;
/** Pointer into the input buffer where the current line
* started.
*/
- const DataType* m_currentLine;
+ const DataType* m_currentLine;
/** The offset within the current line of the current character
*/
- ANTLR_INT32 m_charPositionInLine;
+ ANTLR_INT32 m_charPositionInLine;
/** Tracks how deep mark() calls are nested
*/
- ANTLR_UINT32 m_markDepth;
+ ANTLR_UINT32 m_markDepth;
/** List of mark() points in the input stream
*/
- MarkersType m_markers;
+ MarkersType m_markers;
/** File name string, set to pointer to memory if
* you set it manually as it will be free()d
*/
- StringType m_fileName;
+ StringType m_fileName;
/** File number, needs to be set manually to some file index of your devising.
*/
- ANTLR_UINT32 m_fileNo;
+ ANTLR_UINT32 m_fileNo;
- /// Character that automatically causes an internal line count
+ /// Character that automatically causes an internal line count
/// increment.
///
- ANTLR_UCHAR m_newlineChar;
+ ANTLR_UCHAR m_newlineChar;
/// Indicates the size, in 8 bit units, of a single character. Note that
/// the C runtime does not deal with surrogates as this would be
@@ -120,12 +120,12 @@ private:
/// will be set to 0. Generally you are best working internally with 32 bit characters
/// as this is the most efficient.
///
- ANTLR_UINT8 m_charByteSize;
+ ANTLR_UINT8 m_charByteSize;
/** Indicates if the data pointer was allocated by us, and so should be freed
* when the stream dies.
*/
- bool m_isAllocated;
+ bool m_isAllocated;
/// Indicates the encoding scheme used in this input stream
///
@@ -133,70 +133,70 @@ private:
/* API */
public:
- InputStream(const ANTLR_UINT8* fileName, ANTLR_UINT32 encoding);
- InputStream(const ANTLR_UINT8* data, ANTLR_UINT32 encoding, ANTLR_UINT32 size, ANTLR_UINT8* name);
- ~InputStream();
- const DataType* get_data() const;
- bool get_isAllocated() const;
- const DataType* get_nextChar() const;
- ANTLR_UINT32 get_sizeBuf() const;
- ANTLR_UINT32 get_line() const;
- const DataType* get_currentLine() const;
- ANTLR_INT32 get_charPositionInLine() const;
- ANTLR_UINT32 get_markDepth() const;
- MarkersType& get_markers();
- const StringType& get_fileName() const;
- ANTLR_UINT32 get_fileNo() const;
- ANTLR_UCHAR get_newlineChar() const;
- ANTLR_UINT8 get_charByteSize() const;
- ANTLR_UINT32 get_encoding() const;
-
- void set_data( DataType* data );
- void set_isAllocated( bool isAllocated );
- void set_nextChar( const DataType* nextChar );
- void set_sizeBuf( ANTLR_UINT32 sizeBuf );
- void set_line( ANTLR_UINT32 line );
- void set_currentLine( const DataType* currentLine );
- void set_charPositionInLine( ANTLR_INT32 charPositionInLine );
- void set_markDepth( ANTLR_UINT32 markDepth );
- void set_markers( const MarkersType& markers );
- void set_fileName( const StringType& fileName );
- void set_fileNo( ANTLR_UINT32 fileNo );
- void set_newlineChar( ANTLR_UCHAR newlineChar );
- void set_charByteSize( ANTLR_UINT8 charByteSize );
- void set_encoding( ANTLR_UINT32 encoding );
-
- void inc_charPositionInLine();
- void inc_line();
- void inc_markDepth();
-
- IntStreamType* get_istream();
+ InputStream(const ANTLR_UINT8* fileName, ANTLR_UINT32 encoding);
+ InputStream(const ANTLR_UINT8* data, ANTLR_UINT32 encoding, ANTLR_UINT32 size, ANTLR_UINT8* name);
+ ~InputStream();
+ const DataType* get_data() const;
+ bool get_isAllocated() const;
+ const DataType* get_nextChar() const;
+ ANTLR_UINT32 get_sizeBuf() const;
+ ANTLR_UINT32 get_line() const;
+ const DataType* get_currentLine() const;
+ ANTLR_INT32 get_charPositionInLine() const;
+ ANTLR_UINT32 get_markDepth() const;
+ MarkersType& get_markers();
+ const StringType& get_fileName() const;
+ ANTLR_UINT32 get_fileNo() const;
+ ANTLR_UCHAR get_newlineChar() const;
+ ANTLR_UINT8 get_charByteSize() const;
+ ANTLR_UINT32 get_encoding() const;
+
+ void set_data( DataType* data );
+ void set_isAllocated( bool isAllocated );
+ void set_nextChar( const DataType* nextChar );
+ void set_sizeBuf( ANTLR_UINT32 sizeBuf );
+ void set_line( ANTLR_UINT32 line );
+ void set_currentLine( const DataType* currentLine );
+ void set_charPositionInLine( ANTLR_INT32 charPositionInLine );
+ void set_markDepth( ANTLR_UINT32 markDepth );
+ void set_markers( const MarkersType& markers );
+ void set_fileName( const StringType& fileName );
+ void set_fileNo( ANTLR_UINT32 fileNo );
+ void set_newlineChar( ANTLR_UCHAR newlineChar );
+ void set_charByteSize( ANTLR_UINT8 charByteSize );
+ void set_encoding( ANTLR_UINT32 encoding );
+
+ void inc_charPositionInLine();
+ void inc_line();
+ void inc_markDepth();
+
+ IntStreamType* get_istream();
/** Function that resets the input stream
*/
- void reset();
+ void reset();
/** Pointer to a function that reuses and resets an input stream by
* supplying a new 'source'
*/
void reuse(ANTLR_UINT8* inString, ANTLR_UINT32 size, ANTLR_UINT8* name);
-
+
/** Function to return the total size of the input buffer. For streams
* this may be just the total we have available so far. This means of course that
* the input stream must be careful to accumulate enough input so that any backtracking
* can be satisfied.
*/
- ANTLR_UINT32 size();
+ ANTLR_UINT32 size();
/** Function to return a substring of the input stream. String is returned in allocated
* memory and is in same encoding as the input stream itself, NOT internal ANTLR_UCHAR form.
*/
- StringType substr(ANTLR_MARKER start, ANTLR_MARKER stop);
+ StringType substr(ANTLR_MARKER start, ANTLR_MARKER stop);
/** Function to return the current line number in the input stream
*/
- ANTLR_UINT32 get_line();
+ ANTLR_UINT32 get_line();
/** Function to return the current line buffer in the input stream
* The pointer returned is directly into the input stream so you must copy
@@ -204,18 +204,18 @@ public:
* is obviously in the same form as the input stream.
* \remark
* - Note taht this function wil lbe inaccurate if setLine is called as there
- * is no way at the moment to position the input stream at a particular line
- * number offset.
+ * is no way at the moment to position the input stream at a particular line
+ * number offset.
*/
- const DataType* getLineBuf();
+ const DataType* getLineBuf();
/** Function to return the current offset in the current input stream line
*/
- ANTLR_UINT32 get_charPositionInLine();
+ ANTLR_UINT32 get_charPositionInLine();
/** Function to set the current position in the current line.
*/
- void set_charPositionInLine(ANTLR_UINT32 position);
+ void set_charPositionInLine(ANTLR_UINT32 position);
/** Function to override the default newline character that the input stream
* looks for to trigger the line/offset and line buffer recording information.
@@ -225,45 +225,45 @@ public:
* current line offset is reset to 0. The Pointer for the line of input we are consuming
* is updated to point to the next character after this one in the input stream (which means it
* may become invalid if the last newline character in the file is seen (so watch out).
- * - If for some reason you do not want the counters and pointers to be restee, you can set the
+ * - If for some reason you do not want the counters and pointers to be restee, you can set the
* chracter to some impossible character such as '\0' or whatever.
* - This is a single character only, so choose the last character in a sequence of two or more.
* - This is only a simple aid to error reporting - if you have a complicated binary input structure
* it may not be adequate, but you can always override every function in the input stream with your
* own of course, and can even write your own complete input stream set if you like.
- * - It is your responsiblity to set a valid character for the input stream type. There is no point
+ * - It is your responsiblity to set a valid character for the input stream type. There is no point
* setting this to 0xFFFFFFFF if the input stream is 8 bit ASCII, as this will just be truncated and never
- * trigger as the comparison will be (INT32)0xFF == (INT32)0xFFFFFFFF
+ * trigger as the comparison will be (INT32)0xFF == (INT32)0xFFFFFFFF
*/
- void set_newLineChar(ANTLR_UINT32 newlineChar);
-
- ANTLR_MARKER index_impl();
+ void set_newLineChar(ANTLR_UINT32 newlineChar);
+
+ ANTLR_MARKER index_impl();
private:
- /** \brief Use the contents of an operating system file as the input
- * for an input stream.
- *
- * \param fileName Name of operating system file to read.
- * \return
- * - Pointer to new input stream context upon success
- * - One of the ANTLR3_ERR_ defines on error.
- */
- void createFileStream(const ANTLR_UINT8* fileName);
-
- /** \brief Use the supplied 'string' as input to the stream
- *
- * \param data Pointer to the input data
- * \return
- * - Pointer to new input stream context upon success
- * - NULL defines on error.
- */
- void createStringStream(const ANTLR_UINT8* data);
- void genericSetupStream();
-
- /// Determine endianess of the input stream and install the
- /// API required for the encoding in that format.
- ///
- void setupInputStream();
+ /** \brief Use the contents of an operating system file as the input
+ * for an input stream.
+ *
+ * \param fileName Name of operating system file to read.
+ * \return
+ * - Pointer to new input stream context upon success
+ * - One of the ANTLR3_ERR_ defines on error.
+ */
+ void createFileStream(const ANTLR_UINT8* fileName);
+
+ /** \brief Use the supplied 'string' as input to the stream
+ *
+ * \param data Pointer to the input data
+ * \return
+ * - Pointer to new input stream context upon success
+ * - NULL defines on error.
+ */
+ void createStringStream(const ANTLR_UINT8* data);
+ void genericSetupStream();
+
+ /// Determine endianess of the input stream and install the
+ /// API required for the encoding in that format.
+ ///
+ void setupInputStream();
};
@@ -271,10 +271,10 @@ private:
* and rewind() of lexer.
*/
template<class ImplTraits>
-class LexState : public ImplTraits::AllocPolicyType
+class LexState : public ImplTraits::AllocPolicyType
{
public:
- typedef typename ImplTraits::StreamDataType DataType;
+ typedef typename ImplTraits::StreamDataType DataType;
private:
/** Pointer to the next character to be consumed from the input data
@@ -282,44 +282,44 @@ private:
* was read by the functions installed as pointer in this input stream
* context instance at file/string/whatever load time.
*/
- const DataType* m_nextChar;
+ const DataType* m_nextChar;
/** The line number we are traversing in the input file. This gets incremented
* by a newline() call in the lexer grammer actions.
*/
- ANTLR_UINT32 m_line;
+ ANTLR_UINT32 m_line;
/** Pointer into the input buffer where the current line
* started.
*/
- const DataType* m_currentLine;
+ const DataType* m_currentLine;
/** The offset within the current line of the current character
*/
- ANTLR_INT32 m_charPositionInLine;
+ ANTLR_INT32 m_charPositionInLine;
public:
- LexState();
- const DataType* get_nextChar() const;
- ANTLR_UINT32 get_line() const;
- const DataType* get_currentLine() const;
- ANTLR_INT32 get_charPositionInLine() const;
- void set_nextChar( const DataType* nextChar );
- void set_line( ANTLR_UINT32 line );
- void set_currentLine( const DataType* currentLine );
- void set_charPositionInLine( ANTLR_INT32 charPositionInLine );
+ LexState();
+ const DataType* get_nextChar() const;
+ ANTLR_UINT32 get_line() const;
+ const DataType* get_currentLine() const;
+ ANTLR_INT32 get_charPositionInLine() const;
+ void set_nextChar( const DataType* nextChar );
+ void set_line( ANTLR_UINT32 line );
+ void set_currentLine( const DataType* currentLine );
+ void set_charPositionInLine( ANTLR_INT32 charPositionInLine );
};
class ParseNullStringException : public std::exception
{
virtual const char* what() const noexcept
- {
- return "Null String";
- }
+ {
+ return "Null String";
+ }
};
-}
+}
#include "antlr3input.inl"
-#endif /* _ANTLR_INPUT_H */
+#endif /* _ANTLR_INPUT_H */
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3input.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3input.inl
index 217fffc24e..6837a06540 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3input.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3input.inl
@@ -1,4 +1,4 @@
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits>
InputStream<ImplTraits>::InputStream(const ANTLR_UINT8* fileName, ANTLR_UINT32 encoding)
@@ -10,100 +10,100 @@ InputStream<ImplTraits>::InputStream(const ANTLR_UINT8* fileName, ANTLR_UINT32 e
//
this->createFileStream(fileName);
- // We have the data in memory now so we can deal with it according to
+ // We have the data in memory now so we can deal with it according to
// the encoding scheme we were given by the user.
//
m_encoding = encoding;
- // Now we need to work out the endian type and install any
+ // Now we need to work out the endian type and install any
// API functions that differ from 8Bit
//
this->setupInputStream();
// Now we can set up the file name
- //
- BaseType::m_streamName = (const char* )fileName;
- m_fileName = BaseType::m_streamName;
+ //
+ BaseType::m_streamName = (const char* )fileName;
+ m_fileName = BaseType::m_streamName;
}
template<class ImplTraits>
InputStream<ImplTraits>::InputStream(const ANTLR_UINT8* data, ANTLR_UINT32 encoding, ANTLR_UINT32 size, ANTLR_UINT8* name)
{
- // First order of business is to set up the stream and install the data pointer.
+ // First order of business is to set up the stream and install the data pointer.
// Then we will work out the encoding and byte order and adjust the API functions that are installed for the
// default 8Bit stream accordingly.
//
this->createStringStream(data);
-
+
// Size (in bytes) of the given 'string'
//
- m_sizeBuf = size;
+ m_sizeBuf = size;
- // We have the data in memory now so we can deal with it according to
+ // We have the data in memory now so we can deal with it according to
// the encoding scheme we were given by the user.
//
m_encoding = encoding;
- // Now we need to work out the endian type and install any
+ // Now we need to work out the endian type and install any
// API functions that differ from 8Bit
//
this->setupInputStream();
// Now we can set up the file name
- //
- BaseType::m_streamName = (name == NULL ) ? "" : (const char*)name;
- m_fileName = BaseType::m_streamName;
+ //
+ BaseType::m_streamName = (name == NULL ) ? "" : (const char*)name;
+ m_fileName = BaseType::m_streamName;
}
template<class ImplTraits>
void InputStream<ImplTraits>::createStringStream(const ANTLR_UINT8* data)
{
- if (data == NULL)
- {
- ParseNullStringException ex;
- throw ex;
- }
+ if (data == NULL)
+ {
+ ParseNullStringException ex;
+ throw ex;
+ }
- // Structure was allocated correctly, now we can install the pointer
- //
+ // Structure was allocated correctly, now we can install the pointer
+ //
m_data = data;
- m_isAllocated = false;
+ m_isAllocated = false;
- // Call the common 8 bit input stream handler
- // initialization.
- //
- this->genericSetupStream();
+ // Call the common 8 bit input stream handler
+ // initialization.
+ //
+ this->genericSetupStream();
}
template<class ImplTraits>
void InputStream<ImplTraits>::createFileStream(const ANTLR_UINT8* fileName)
{
- if (fileName == NULL)
- {
- ParseFileAbsentException ex;
- throw ex;
- }
+ if (fileName == NULL)
+ {
+ ParseFileAbsentException ex;
+ throw ex;
+ }
- // Structure was allocated correctly, now we can read the file.
- //
- FileUtils<ImplTraits>::AntlrRead8Bit(this, fileName);
+ // Structure was allocated correctly, now we can read the file.
+ //
+ FileUtils<ImplTraits>::AntlrRead8Bit(this, fileName);
- // Call the common 8 bit input stream handler
- // initialization.
- //
- this->genericSetupStream();
+ // Call the common 8 bit input stream handler
+ // initialization.
+ //
+ this->genericSetupStream();
}
template<class ImplTraits>
void InputStream<ImplTraits>::genericSetupStream()
{
- this->set_charByteSize(1);
-
+ this->set_charByteSize(1);
+
/* Set up the input stream brand new
*/
this->reset();
-
+
/* Install default line separator character (it can be replaced
* by the grammar programmer later)
*/
@@ -113,340 +113,340 @@ void InputStream<ImplTraits>::genericSetupStream()
template<class ImplTraits>
InputStream<ImplTraits>::~InputStream()
{
- // Free the input stream buffer if we allocated it
+ // Free the input stream buffer if we allocated it
//
- if (m_isAllocated && (m_data != NULL))
- AllocPolicyType::free((void*)m_data); //const_cast is required
+ if (m_isAllocated && (m_data != NULL))
+ AllocPolicyType::free((void*)m_data); //const_cast is required
}
template<class ImplTraits>
ANTLR_INLINE const typename InputStream<ImplTraits>::DataType* InputStream<ImplTraits>::get_data() const
{
- return m_data;
+ return m_data;
}
template<class ImplTraits>
ANTLR_INLINE bool InputStream<ImplTraits>::get_isAllocated() const
{
- return m_isAllocated;
+ return m_isAllocated;
}
template<class ImplTraits>
ANTLR_INLINE const typename InputStream<ImplTraits>::DataType* InputStream<ImplTraits>::get_nextChar() const
{
- return m_nextChar;
+ return m_nextChar;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 InputStream<ImplTraits>::get_sizeBuf() const
{
- return m_sizeBuf;
+ return m_sizeBuf;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 InputStream<ImplTraits>::get_line() const
{
- return m_line;
+ return m_line;
}
template<class ImplTraits>
ANTLR_INLINE const typename InputStream<ImplTraits>::DataType* InputStream<ImplTraits>::get_currentLine() const
{
- return m_currentLine;
+ return m_currentLine;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_INT32 InputStream<ImplTraits>::get_charPositionInLine() const
{
- return m_charPositionInLine;
+ return m_charPositionInLine;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 InputStream<ImplTraits>::get_markDepth() const
{
- return m_markDepth;
+ return m_markDepth;
}
template<class ImplTraits>
ANTLR_INLINE typename InputStream<ImplTraits>::MarkersType& InputStream<ImplTraits>::get_markers()
{
- return m_markers;
+ return m_markers;
}
template<class ImplTraits>
ANTLR_INLINE const typename InputStream<ImplTraits>::StringType& InputStream<ImplTraits>::get_fileName() const
{
- return m_fileName;
+ return m_fileName;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 InputStream<ImplTraits>::get_fileNo() const
{
- return m_fileNo;
+ return m_fileNo;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_UCHAR InputStream<ImplTraits>::get_newlineChar() const
{
- return m_newlineChar;
+ return m_newlineChar;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT8 InputStream<ImplTraits>::get_charByteSize() const
{
- return m_charByteSize;
+ return m_charByteSize;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 InputStream<ImplTraits>::get_encoding() const
{
- return m_encoding;
+ return m_encoding;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_data( DataType* data )
{
- m_data = data;
+ m_data = data;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_isAllocated( bool isAllocated )
{
- m_isAllocated = isAllocated;
+ m_isAllocated = isAllocated;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_nextChar( const DataType* nextChar )
{
- m_nextChar = nextChar;
+ m_nextChar = nextChar;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_sizeBuf( ANTLR_UINT32 sizeBuf )
{
- m_sizeBuf = sizeBuf;
+ m_sizeBuf = sizeBuf;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_line( ANTLR_UINT32 line )
{
- m_line = line;
+ m_line = line;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_currentLine( const DataType* currentLine )
{
- m_currentLine = currentLine;
+ m_currentLine = currentLine;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_charPositionInLine( ANTLR_INT32 charPositionInLine )
{
- m_charPositionInLine = charPositionInLine;
+ m_charPositionInLine = charPositionInLine;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_markDepth( ANTLR_UINT32 markDepth )
{
- m_markDepth = markDepth;
+ m_markDepth = markDepth;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_markers( const MarkersType& markers )
{
- m_markers = markers;
+ m_markers = markers;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_fileName( const StringType& fileName )
{
- m_fileName = fileName;
+ m_fileName = fileName;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_fileNo( ANTLR_UINT32 fileNo )
{
- m_fileNo = fileNo;
+ m_fileNo = fileNo;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_newlineChar( ANTLR_UCHAR newlineChar )
{
- m_newlineChar = newlineChar;
+ m_newlineChar = newlineChar;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_charByteSize( ANTLR_UINT8 charByteSize )
{
- m_charByteSize = charByteSize;
+ m_charByteSize = charByteSize;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::set_encoding( ANTLR_UINT32 encoding )
{
- m_encoding = encoding;
+ m_encoding = encoding;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::inc_charPositionInLine()
{
- ++m_charPositionInLine;
+ ++m_charPositionInLine;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::inc_line()
{
- ++m_line;
+ ++m_line;
}
template<class ImplTraits>
ANTLR_INLINE void InputStream<ImplTraits>::inc_markDepth()
{
- ++m_markDepth;
+ ++m_markDepth;
}
template<class ImplTraits>
-ANTLR_INLINE void InputStream<ImplTraits>::reset()
+ANTLR_INLINE void InputStream<ImplTraits>::reset()
{
- m_nextChar = m_data; /* Input at first character */
- m_line = 1; /* starts at line 1 */
- m_charPositionInLine = 0;
- m_currentLine = m_data;
- m_markDepth = 0; /* Reset markers */
-
+ m_nextChar = m_data; /* Input at first character */
+ m_line = 1; /* starts at line 1 */
+ m_charPositionInLine = 0;
+ m_currentLine = m_data;
+ m_markDepth = 0; /* Reset markers */
+
/* Clear out up the markers table if it is there
*/
- m_markers.clear();
+ m_markers.clear();
}
template<class ImplTraits>
void InputStream<ImplTraits>::reuse(ANTLR_UINT8* inString, ANTLR_UINT32 size, ANTLR_UINT8* name)
{
- m_isAllocated = false;
- m_data = inString;
- m_sizeBuf = size;
-
+ m_isAllocated = false;
+ m_data = inString;
+ m_sizeBuf = size;
+
// Now we can set up the file name. As we are reusing the stream, there may already
// be a string that we can reuse for holding the filename.
//
- if ( BaseType::m_streamName.empty() )
- {
- BaseType::m_streamName = ((name == NULL) ? "-memory-" : (const char *)name);
- m_fileName = BaseType::m_streamName;
- }
- else
- {
- BaseType::m_streamName = ((name == NULL) ? "-memory-" : (const char *)name);
- }
+ if ( BaseType::m_streamName.empty() )
+ {
+ BaseType::m_streamName = ((name == NULL) ? "-memory-" : (const char *)name);
+ m_fileName = BaseType::m_streamName;
+ }
+ else
+ {
+ BaseType::m_streamName = ((name == NULL) ? "-memory-" : (const char *)name);
+ }
this->reset();
}
/*
template<class ImplTraits>
-typename InputStream<ImplTraits>::DataType* InputStream<ImplTraits>::LT(ANTLR_INT32 lt)
+typename InputStream<ImplTraits>::DataType* InputStream<ImplTraits>::LT(ANTLR_INT32 lt)
{
- return this->LA(lt);
+ return this->LA(lt);
}
*/
template<class ImplTraits>
-ANTLR_UINT32 InputStream<ImplTraits>::size()
+ANTLR_UINT32 InputStream<ImplTraits>::size()
{
- return m_sizeBuf;
+ return m_sizeBuf;
}
template<class ImplTraits>
-ANTLR_MARKER InputStream<ImplTraits>::index_impl()
+ANTLR_MARKER InputStream<ImplTraits>::index_impl()
{
- return (ANTLR_MARKER)m_nextChar;
+ return (ANTLR_MARKER)m_nextChar;
}
template<class ImplTraits>
-typename InputStream<ImplTraits>::StringType InputStream<ImplTraits>::substr(ANTLR_MARKER start, ANTLR_MARKER stop)
+typename InputStream<ImplTraits>::StringType InputStream<ImplTraits>::substr(ANTLR_MARKER start, ANTLR_MARKER stop)
{
- std::size_t len = static_cast<std::size_t>( (stop-start)/sizeof(DataType) + 1 );
- StringType str( (const char*)start, len );
- return str;
+ std::size_t len = static_cast<std::size_t>( (stop-start)/sizeof(DataType) + 1 );
+ StringType str( (const char*)start, len );
+ return str;
}
template<class ImplTraits>
-ANTLR_UINT32 InputStream<ImplTraits>::get_line()
+ANTLR_UINT32 InputStream<ImplTraits>::get_line()
{
- return m_line;
+ return m_line;
}
template<class ImplTraits>
-const typename InputStream<ImplTraits>::DataType* InputStream<ImplTraits>::getLineBuf()
+const typename InputStream<ImplTraits>::DataType* InputStream<ImplTraits>::getLineBuf()
{
- return m_currentLine;
+ return m_currentLine;
}
template<class ImplTraits>
-ANTLR_INLINE ANTLR_UINT32 InputStream<ImplTraits>::get_charPositionInLine()
+ANTLR_INLINE ANTLR_UINT32 InputStream<ImplTraits>::get_charPositionInLine()
{
- return m_charPositionInLine;
+ return m_charPositionInLine;
}
template<class ImplTraits>
-ANTLR_INLINE void InputStream<ImplTraits>::set_charPositionInLine(ANTLR_UINT32 position)
+ANTLR_INLINE void InputStream<ImplTraits>::set_charPositionInLine(ANTLR_UINT32 position)
{
- m_charPositionInLine = position;
+ m_charPositionInLine = position;
}
template<class ImplTraits>
-void InputStream<ImplTraits>::set_newLineChar(ANTLR_UINT32 newlineChar)
+void InputStream<ImplTraits>::set_newLineChar(ANTLR_UINT32 newlineChar)
{
- m_newlineChar = newlineChar;
+ m_newlineChar = newlineChar;
}
template<class ImplTraits>
ANTLR_INLINE LexState<ImplTraits>::LexState()
{
- m_nextChar = NULL;
- m_line = 0;
- m_currentLine = NULL;
- m_charPositionInLine = 0;
+ m_nextChar = NULL;
+ m_line = 0;
+ m_currentLine = NULL;
+ m_charPositionInLine = 0;
}
template<class ImplTraits>
ANTLR_INLINE const typename LexState<ImplTraits>::DataType* LexState<ImplTraits>::get_nextChar() const
{
- return m_nextChar;
+ return m_nextChar;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 LexState<ImplTraits>::get_line() const
{
- return m_line;
+ return m_line;
}
template<class ImplTraits>
ANTLR_INLINE const typename LexState<ImplTraits>::DataType* LexState<ImplTraits>::get_currentLine() const
{
- return m_currentLine;
+ return m_currentLine;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_INT32 LexState<ImplTraits>::get_charPositionInLine() const
{
- return m_charPositionInLine;
+ return m_charPositionInLine;
}
template<class ImplTraits>
ANTLR_INLINE void LexState<ImplTraits>::set_nextChar( const DataType* nextChar )
{
- m_nextChar = nextChar;
+ m_nextChar = nextChar;
}
template<class ImplTraits>
ANTLR_INLINE void LexState<ImplTraits>::set_line( ANTLR_UINT32 line )
{
- m_line = line;
+ m_line = line;
}
template<class ImplTraits>
ANTLR_INLINE void LexState<ImplTraits>::set_currentLine( const DataType* currentLine )
{
- m_currentLine = currentLine;
+ m_currentLine = currentLine;
}
template<class ImplTraits>
ANTLR_INLINE void LexState<ImplTraits>::set_charPositionInLine( ANTLR_INT32 charPositionInLine )
{
- m_charPositionInLine = charPositionInLine;
+ m_charPositionInLine = charPositionInLine;
}
template<class ImplTraits>
-ANTLR_INLINE typename InputStream<ImplTraits>::IntStreamType* InputStream<ImplTraits>::get_istream()
+ANTLR_INLINE typename InputStream<ImplTraits>::IntStreamType* InputStream<ImplTraits>::get_istream()
{
- return this;
+ return this;
}
template<class ImplTraits>
void InputStream<ImplTraits>::setupInputStream()
{
- bool isBigEndian;
+ bool isBigEndian;
// Used to determine the endianness of the machine we are currently
// running on.
//
ANTLR_UINT16 bomTest = 0xFEFF;
-
+
// What endianess is the machine we are running on? If the incoming
// encoding endianess is the same as this machine's natural byte order
// then we can use more efficient API calls.
@@ -465,7 +465,7 @@ void InputStream<ImplTraits>::setupInputStream()
//
switch (m_encoding)
{
- case ENC_UTF8:
+ case ENC_UTF8:
// See if there is a BOM at the start of this UTF-8 sequence
// and just eat it if there is. Windows .TXT files have this for instance
@@ -484,11 +484,11 @@ void InputStream<ImplTraits>::setupInputStream()
// Install the UTF8 input routines
//
- this->setupIntStream( isBigEndian, isBigEndian );
- this->set_charByteSize(0);
+ this->setupIntStream( isBigEndian, isBigEndian );
+ this->set_charByteSize(0);
break;
- case ENC_UTF16:
+ case ENC_UTF16:
// See if there is a BOM at the start of the input. If not then
// we assume that the byte order is the natural order of this
@@ -503,7 +503,7 @@ void InputStream<ImplTraits>::setupInputStream()
//
m_nextChar += 1;
- this->setupIntStream( isBigEndian, true );
+ this->setupIntStream( isBigEndian, true );
}
else if ( (ANTLR_UINT8)(*((ANTLR_UINT8*)m_nextChar)) == 0xFF
&& (ANTLR_UINT8)(*((ANTLR_UINT8*)m_nextChar+1)) == 0xFE
@@ -521,10 +521,10 @@ void InputStream<ImplTraits>::setupInputStream()
//
this->setupIntStream(isBigEndian, isBigEndian);
}
- this->set_charByteSize(2);
+ this->set_charByteSize(2);
break;
- case ENC_UTF32:
+ case ENC_UTF32:
// See if there is a BOM at the start of the input. If not then
// we assume that the byte order is the natural order of this
@@ -553,67 +553,67 @@ void InputStream<ImplTraits>::setupInputStream()
//
m_nextChar += 1;
- this->setupIntStream( isBigEndian, false );
+ this->setupIntStream( isBigEndian, false );
}
else
{
// No BOM present, assume local computer byte order
//
- this->setupIntStream( isBigEndian, isBigEndian );
+ this->setupIntStream( isBigEndian, isBigEndian );
}
- this->set_charByteSize(4);
+ this->set_charByteSize(4);
break;
- case ENC_UTF16BE:
+ case ENC_UTF16BE:
// Encoding is definately Big Endian with no BOM
//
- this->setupIntStream( isBigEndian, true );
- this->set_charByteSize(2);
+ this->setupIntStream( isBigEndian, true );
+ this->set_charByteSize(2);
break;
- case ENC_UTF16LE:
+ case ENC_UTF16LE:
// Encoding is definately Little Endian with no BOM
//
this->setupIntStream( isBigEndian, false );
- this->set_charByteSize(2);
+ this->set_charByteSize(2);
break;
- case ENC_UTF32BE:
+ case ENC_UTF32BE:
// Encoding is definately Big Endian with no BOM
//
- this->setupIntStream( isBigEndian, true );
- this->set_charByteSize(4);
+ this->setupIntStream( isBigEndian, true );
+ this->set_charByteSize(4);
break;
- case ENC_UTF32LE:
+ case ENC_UTF32LE:
// Encoding is definately Little Endian with no BOM
//
- this->setupIntStream( isBigEndian, false );
- this->set_charByteSize(4);
+ this->setupIntStream( isBigEndian, false );
+ this->set_charByteSize(4);
break;
- case ENC_EBCDIC:
+ case ENC_EBCDIC:
// EBCDIC is basically the same as ASCII but with an on the
// fly translation to ASCII
//
this->setupIntStream( isBigEndian, isBigEndian );
- this->set_charByteSize(1);
+ this->set_charByteSize(1);
break;
- case ENC_8BIT:
+ case ENC_8BIT:
default:
// Standard 8bit/ASCII
//
this->setupIntStream( isBigEndian, isBigEndian );
- this->set_charByteSize(1);
+ this->set_charByteSize(1);
break;
- }
+ }
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3interfaces.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3interfaces.hpp
index ad52c505e5..5f04b40c49 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3interfaces.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3interfaces.hpp
@@ -4,8 +4,8 @@
* each other without trying to sort out the cyclic interdependencies that
* would otherwise result.
*/
-#ifndef _ANTLR3_INTERFACES_HPP
-#define _ANTLR3_INTERFACES_HPP
+#ifndef _ANTLR3_INTERFACES_HPP
+#define _ANTLR3_INTERFACES_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -34,66 +34,66 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
-
-// Definitions that indicate the encoding scheme character streams and strings etc
-enum Encoding
-{
- ENC_8BIT = 4 /// General latin-1 or other 8 bit encoding scheme such as straight ASCII
- , ENC_UTF8 = 8 /// UTF-8 encoding scheme
- , ENC_UTF16 = 16 /// UTF-16 encoding scheme (which also covers UCS2 as that does not have surrogates)
- , ENC_UTF16BE
- , ENC_UTF16LE
- , ENC_UTF32 = 32 /// UTF-32 encoding scheme (basically straight 32 bit)
- , ENC_UTF32BE
- , ENC_UTF32LE
- , ENC_EBCDIC = 64 /// Input is 8 bit EBCDIC (which we convert to 8 bit ASCII on the fly
-};
-
-enum ChannelType
-{
- TOKEN_DEFAULT_CHANNEL = 0 /// Default channel for a token
- , HIDDEN = 99 /// Reserved channel number for a HIDDEN token - a token that is hidden from the parser
-};
-
-/// Pointer to an instantiation of 'class' #ANTLR3_EXCEPTION
-/// \ingroup ANTLR3_EXCEPTION
-///
-enum ExceptionType
-{
- /** Indicates that the recognizer received a token
- * in the input that was not predicted.
- */
- RECOGNITION_EXCEPTION = 0
- /** Indicates that the recognizer was expecting one token and found a
- * a different one.
- */
- , MISMATCHED_TOKEN_EXCEPTION
-
- /** Recognizer could not find a valid alternative from the input
- */
- , NO_VIABLE_ALT_EXCEPTION
-
- /* Character in a set was not found
- */
- , MISMATCHED_SET_EXCEPTION
-
- /* A rule predicting at least n elements found less than that,
- * such as: WS: " "+;
- */
- , EARLY_EXIT_EXCEPTION
-
- , FAILED_PREDICATE_EXCEPTION
-
- , MISMATCHED_TREE_NODE_EXCEPTION
-
- , REWRITE_EARLY_EXCEPTION
-
- , UNWANTED_TOKEN_EXCEPTION
-
- , MISSING_TOKEN_EXCEPTION
-};
-
+namespace antlr3 {
+
+// Definitions that indicate the encoding scheme character streams and strings etc
+enum Encoding
+{
+ ENC_8BIT = 4 /// General latin-1 or other 8 bit encoding scheme such as straight ASCII
+ , ENC_UTF8 = 8 /// UTF-8 encoding scheme
+ , ENC_UTF16 = 16 /// UTF-16 encoding scheme (which also covers UCS2 as that does not have surrogates)
+ , ENC_UTF16BE
+ , ENC_UTF16LE
+ , ENC_UTF32 = 32 /// UTF-32 encoding scheme (basically straight 32 bit)
+ , ENC_UTF32BE
+ , ENC_UTF32LE
+ , ENC_EBCDIC = 64 /// Input is 8 bit EBCDIC (which we convert to 8 bit ASCII on the fly
+};
+
+enum ChannelType
+{
+ TOKEN_DEFAULT_CHANNEL = 0 /// Default channel for a token
+ , HIDDEN = 99 /// Reserved channel number for a HIDDEN token - a token that is hidden from the parser
+};
+
+/// Pointer to an instantiation of 'class' #ANTLR3_EXCEPTION
+/// \ingroup ANTLR3_EXCEPTION
+///
+enum ExceptionType
+{
+ /** Indicates that the recognizer received a token
+ * in the input that was not predicted.
+ */
+ RECOGNITION_EXCEPTION = 0
+ /** Indicates that the recognizer was expecting one token and found a
+ * a different one.
+ */
+ , MISMATCHED_TOKEN_EXCEPTION
+
+ /** Recognizer could not find a valid alternative from the input
+ */
+ , NO_VIABLE_ALT_EXCEPTION
+
+ /* Character in a set was not found
+ */
+ , MISMATCHED_SET_EXCEPTION
+
+ /* A rule predicting at least n elements found less than that,
+ * such as: WS: " "+;
+ */
+ , EARLY_EXIT_EXCEPTION
+
+ , FAILED_PREDICATE_EXCEPTION
+
+ , MISMATCHED_TREE_NODE_EXCEPTION
+
+ , REWRITE_EARLY_EXCEPTION
+
+ , UNWANTED_TOKEN_EXCEPTION
+
+ , MISSING_TOKEN_EXCEPTION
+};
+
template<class ImplTraits, class SuperType>
class IntStream;
@@ -271,23 +271,23 @@ template<class ImplTraits>
class ComponentTypeFinder< ImplTraits, typename ImplTraits::InputStreamType>
{
public:
- typedef typename ImplTraits::LexerType ComponentType;
+ typedef typename ImplTraits::LexerType ComponentType;
};
template<class ImplTraits>
class ComponentTypeFinder< ImplTraits, typename ImplTraits::TokenStreamType>
{
public:
- typedef typename ImplTraits::ParserType ComponentType;
+ typedef typename ImplTraits::ParserType ComponentType;
};
template<class ImplTraits>
class ComponentTypeFinder< ImplTraits, typename ImplTraits::TreeNodeStreamType>
{
public:
- typedef typename ImplTraits::TreeParserType ComponentType;
+ typedef typename ImplTraits::TreeParserType ComponentType;
};
-}
+}
#endif
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3intstream.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3intstream.hpp
index 8803c17327..01bf60a7cb 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3intstream.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3intstream.hpp
@@ -1,6 +1,6 @@
/** \file
* Defines the the class interface for an antlr3 INTSTREAM.
- *
+ *
* Certain functionality (such as DFAs for instance) abstract the stream of tokens
* or characters in to a steam of integers. Hence this structure should be included
* in any stream that is able to provide the output as a stream of integers (which is anything
@@ -11,15 +11,15 @@
* the signature in this interface which abstracts the base immplementation. In essence though
* the base stream provides a pointer to this interface, within which it installs its
* normal match() functions and so on. Interaces such as DFA are then passed the pANTLR3_INT_STREAM
- * and can treat any input as an int stream.
+ * and can treat any input as an int stream.
*
* For instance, a lexer implements a pANTLR3_BASE_RECOGNIZER, within which there is a pANTLR3_INT_STREAM.
* However, a pANTLR3_INPUT_STREAM also provides a pANTLR3_INT_STREAM, which it has constructed from
* it's normal interface when it was created. This is then pointed at by the pANTLR_BASE_RECOGNIZER
* when it is intialized with a pANTLR3_INPUT_STREAM.
*
- * Similarly if a pANTLR3_BASE_RECOGNIZER is initialized with a pANTLR3_TOKEN_STREAM, then the
- * pANTLR3_INT_STREAM is taken from the pANTLR3_TOKEN_STREAM.
+ * Similarly if a pANTLR3_BASE_RECOGNIZER is initialized with a pANTLR3_TOKEN_STREAM, then the
+ * pANTLR3_INT_STREAM is taken from the pANTLR3_TOKEN_STREAM.
*
* If a pANTLR3_BASE_RECOGNIZER is initialized with a pANTLR3_TREENODE_STREAM, then guess where
* the pANTLR3_INT_STREAM comes from?
@@ -28,8 +28,8 @@
* the ANTLR3_INT_STREAM it is defined as a (void *) in this interface. There is no direct implementation
* of an ANTLR3_INT_STREAM (unless someone did not understand what I was doing here =;?P
*/
-#ifndef _ANTLR3_INTSTREAM_HPP
-#define _ANTLR3_INTSTREAM_HPP
+#ifndef _ANTLR3_INTSTREAM_HPP
+#define _ANTLR3_INTSTREAM_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -59,32 +59,32 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
enum STREAM_TYPE
{
- /** Type indicator for a character stream
- * \remark if a custom stream is created but it can be treated as
- * a char stream, then you may OR in this value to your type indicator
- */
- CHARSTREAM = 0x0001
-
- /** Type indicator for a Token stream
- * \remark if a custom stream is created but it can be treated as
- * a token stream, then you may OR in this value to your type indicator
- */
- , TOKENSTREAM = 0x0002
-
- /** Type indicator for a common tree node stream
- * \remark if a custom stream is created but it can be treated as
- * a common tree node stream, then you may OR in this value to your type indicator
- */
- , COMMONTREENODE = 0x0004
-
- /** Type mask for input stream so we can switch in the above types
- * \remark DO NOT USE 0x0000 as a stream type!
- */
- , INPUT_MASK = 0x0007
+ /** Type indicator for a character stream
+ * \remark if a custom stream is created but it can be treated as
+ * a char stream, then you may OR in this value to your type indicator
+ */
+ CHARSTREAM = 0x0001
+
+ /** Type indicator for a Token stream
+ * \remark if a custom stream is created but it can be treated as
+ * a token stream, then you may OR in this value to your type indicator
+ */
+ , TOKENSTREAM = 0x0002
+
+ /** Type indicator for a common tree node stream
+ * \remark if a custom stream is created but it can be treated as
+ * a common tree node stream, then you may OR in this value to your type indicator
+ */
+ , COMMONTREENODE = 0x0004
+
+ /** Type mask for input stream so we can switch in the above types
+ * \remark DO NOT USE 0x0000 as a stream type!
+ */
+ , INPUT_MASK = 0x0007
};
class RESOLVE_ENDIAN_AT_RUNTIME {};
@@ -96,64 +96,64 @@ template<class ImplTraits, class SuperType>
class IntStream : public ImplTraits::AllocPolicyType
{
public:
- typedef typename ImplTraits::StringType StringType;
-
+ typedef typename ImplTraits::StringType StringType;
+
protected:
/** Potentially useful in error reporting and so on, this string is
* an identification of the input source. It may be NULL, so anything
* attempting to access it needs to check this and substitute a sensible
* default.
*/
- StringType m_streamName;
+ StringType m_streamName;
/** Last marker position allocated
*/
- ANTLR_MARKER m_lastMarker;
-
- bool m_upper_case; //if set, values should be returbed in upper case
+ ANTLR_MARKER m_lastMarker;
+
+ bool m_upper_case; //if set, values should be returbed in upper case
/// Indicates whether we should implement endian-specific logic
/// 0 - Undefined 1 - Default(machine and input are both same), 2 - Little Endian, 3 - Big Endian
- ANTLR_UINT8 m_endian_spec;
+ ANTLR_UINT8 m_endian_spec;
public:
- IntStream();
-
- // Return a string that identifies the input source
- //
- StringType getSourceName();
- StringType& get_streamName();
- const StringType& get_streamName() const;
- ANTLR_MARKER get_lastMarker() const;
-
- SuperType* get_super();
- /**
+ IntStream();
+
+ // Return a string that identifies the input source
+ //
+ StringType getSourceName();
+ StringType& get_streamName();
+ const StringType& get_streamName() const;
+ ANTLR_MARKER get_lastMarker() const;
+
+ SuperType* get_super();
+ /**
* Function that installs a version of LA that always
* returns upper case. Only valid for character streams and creates a case
* insensitive lexer if the lexer tokens are described in upper case. The
* tokens will preserve case in the token text.
*/
- void setUcaseLA(bool flag);
+ void setUcaseLA(bool flag);
/** Consume the next 'ANTR3_UINT32' in the stream
*/
- void consume();
+ void consume();
- /** Get ANTLR3_UINT32 at current input pointer + i ahead where i=1 is next ANTLR3_UINT32
+ /** Get ANTLR3_UINT32 at current input pointer + i ahead where i=1 is next ANTLR3_UINT32
*/
- ANTLR_UINT32 LA( ANTLR_INT32 i);
+ ANTLR_UINT32 LA( ANTLR_INT32 i);
/** Tell the stream to start buffering if it hasn't already. Return
* current input position, index(), or some other marker so that
* when passed to rewind() you get back to the same spot.
* rewind(mark()) should not affect the input cursor.
*/
- ANTLR_MARKER mark();
-
+ ANTLR_MARKER mark();
+
/** Return the current input symbol index 0..n where n indicates the
* last symbol has been read.
*/
- ANTLR_MARKER index();
+ ANTLR_MARKER index();
/** Reset the stream so that next call to index would return marker.
* The marker will usually be index() but it doesn't have to be. It's
@@ -163,19 +163,19 @@ public:
* like a stack. Assume the state the stream was in when this marker
* was created.
*/
- void rewind(ANTLR_MARKER marker);
+ void rewind(ANTLR_MARKER marker);
/** Reset the stream to the last marker position, witouh destryoing the
* last marker position.
*/
- void rewindLast();
+ void rewindLast();
/** You may want to commit to a backtrack but don't want to force the
* stream to keep bookkeeping objects around for a marker that is
* no longer necessary. This will have the same behavior as
* rewind() except it releases resources without the backward seek.
*/
- void release(ANTLR_MARKER mark);
+ void release(ANTLR_MARKER mark);
/** Set the input cursor to the position indicated by index. This is
* normally used to seek ahead in the input stream. No buffering is
@@ -193,119 +193,119 @@ public:
* Currently, this method is only used for efficient backtracking, but
* in the future it may be used for incremental parsing.
*/
- void seek(ANTLR_MARKER index);
+ void seek(ANTLR_MARKER index);
- /// Debug only method to flag consumption of initial off-channel
- /// tokens in the input stream
- ///
- void consumeInitialHiddenTokens();
+ /// Debug only method to flag consumption of initial off-channel
+ /// tokens in the input stream
+ ///
+ void consumeInitialHiddenTokens();
- void rewindMark(ANTLR_MARKER marker);
- ANTLR_MARKER tindex();
+ void rewindMark(ANTLR_MARKER marker);
+ ANTLR_MARKER tindex();
/** Frees any resources that were allocated for the implementation of this
* interface. Usually this is just releasing the memory allocated
* for the structure itself, but it may of course do anything it need to
* so long as it does not stamp on anything else.
*/
- ~IntStream();
+ ~IntStream();
protected:
- void setupIntStream(bool machineBigEndian, bool inputBigEndian);
- void findout_endian_spec(bool machineBigEndian, bool inputBigEndian);
+ void setupIntStream(bool machineBigEndian, bool inputBigEndian);
+ void findout_endian_spec(bool machineBigEndian, bool inputBigEndian);
- //If the user chooses this option, then we will be resolving stuffs at run-time
- ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<RESOLVE_ENDIAN_AT_RUNTIME> );
+ //If the user chooses this option, then we will be resolving stuffs at run-time
+ ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<RESOLVE_ENDIAN_AT_RUNTIME> );
- //resolve into one of the three categories below at runtime
- void consume( ClassForwarder<RESOLVE_ENDIAN_AT_RUNTIME> );
+ //resolve into one of the three categories below at runtime
+ void consume( ClassForwarder<RESOLVE_ENDIAN_AT_RUNTIME> );
};
template<class ImplTraits, class SuperType>
class EBCDIC_IntStream : public IntStream<ImplTraits, SuperType>
{
public:
- ANTLR_UINT32 LA( ANTLR_INT32 i);
+ ANTLR_UINT32 LA( ANTLR_INT32 i);
protected:
- void setupIntStream();
+ void setupIntStream();
};
template<class ImplTraits, class SuperType>
class UTF8_IntStream : public IntStream<ImplTraits, SuperType>
{
public:
- ANTLR_UINT32 LA( ANTLR_INT32 i);
- void consume();
+ ANTLR_UINT32 LA( ANTLR_INT32 i);
+ void consume();
protected:
- void setupIntStream(bool machineBigEndian, bool inputBigEndian);
+ void setupIntStream(bool machineBigEndian, bool inputBigEndian);
private:
- static const ANTLR_UINT32* TrailingBytesForUTF8();
- static const UTF32* OffsetsFromUTF8();
+ static const ANTLR_UINT32* TrailingBytesForUTF8();
+ static const UTF32* OffsetsFromUTF8();
};
template<class ImplTraits, class SuperType>
class UTF16_IntStream : public IntStream<ImplTraits, SuperType>
{
public:
- ANTLR_UINT32 LA( ANTLR_INT32 i);
- void consume();
- ANTLR_MARKER index();
- void seek(ANTLR_MARKER seekPoint);
+ ANTLR_UINT32 LA( ANTLR_INT32 i);
+ void consume();
+ ANTLR_MARKER index();
+ void seek(ANTLR_MARKER seekPoint);
protected:
- void setupIntStream(bool machineBigEndian, bool inputBigEndian);
-
- /// \brief Return the input element assuming an 8 bit ascii input
- ///
- /// \param[in] input Input stream context pointer
- /// \param[in] la 1 based offset of next input stream element
- ///
- /// \return Next input character in internal ANTLR3 encoding (UTF32)
- ///
- ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<BYTE_AGNOSTIC> );
-
- /// \brief Return the input element assuming a UTF16 input when the input is Little Endian and the machine is not
- ///
- /// \param[in] input Input stream context pointer
- /// \param[in] la 1 based offset of next input stream element
- ///
- /// \return Next input character in internal ANTLR3 encoding (UTF32)
- ///
- ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<ANTLR_LITTLE_ENDIAN> );
-
- /// \brief Return the input element assuming a UTF16 input when the input is Little Endian and the machine is not
- ///
- /// \param[in] input Input stream context pointer
- /// \param[in] la 1 based offset of next input stream element
- ///
- /// \return Next input character in internal ANTLR3 encoding (UTF32)
- ///
- ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<ANTLR_BIG_ENDIAN> );
-
- /// \brief Consume the next character in a UTF16 input stream
- ///
- /// \param input Input stream context pointer
- ///
- void consume( ClassForwarder<BYTE_AGNOSTIC> );
-
- /// \brief Consume the next character in a UTF16 input stream when the input is Little Endian and the machine is not
- /// Note that the UTF16 routines do not do any substantial verification of the input stream as for performance
- /// sake, we assume it is validly encoded. So if a low surrogate is found at the curent input position then we
- /// just consume it. Surrogate pairs should be seen as Hi, Lo. So if we have a Lo first, then the input stream
- /// is fubar but we just ignore that.
- ///
- /// \param input Input stream context pointer
- ///
- void consume( ClassForwarder<ANTLR_LITTLE_ENDIAN> );
-
- /// \brief Consume the next character in a UTF16 input stream when the input is Big Endian and the machine is not
- ///
- /// \param input Input stream context pointer
- ///
- void consume( ClassForwarder<ANTLR_BIG_ENDIAN> );
+ void setupIntStream(bool machineBigEndian, bool inputBigEndian);
+
+ /// \brief Return the input element assuming an 8 bit ascii input
+ ///
+ /// \param[in] input Input stream context pointer
+ /// \param[in] la 1 based offset of next input stream element
+ ///
+ /// \return Next input character in internal ANTLR3 encoding (UTF32)
+ ///
+ ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<BYTE_AGNOSTIC> );
+
+ /// \brief Return the input element assuming a UTF16 input when the input is Little Endian and the machine is not
+ ///
+ /// \param[in] input Input stream context pointer
+ /// \param[in] la 1 based offset of next input stream element
+ ///
+ /// \return Next input character in internal ANTLR3 encoding (UTF32)
+ ///
+ ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<ANTLR_LITTLE_ENDIAN> );
+
+ /// \brief Return the input element assuming a UTF16 input when the input is Little Endian and the machine is not
+ ///
+ /// \param[in] input Input stream context pointer
+ /// \param[in] la 1 based offset of next input stream element
+ ///
+ /// \return Next input character in internal ANTLR3 encoding (UTF32)
+ ///
+ ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<ANTLR_BIG_ENDIAN> );
+
+ /// \brief Consume the next character in a UTF16 input stream
+ ///
+ /// \param input Input stream context pointer
+ ///
+ void consume( ClassForwarder<BYTE_AGNOSTIC> );
+
+ /// \brief Consume the next character in a UTF16 input stream when the input is Little Endian and the machine is not
+ /// Note that the UTF16 routines do not do any substantial verification of the input stream as for performance
+ /// sake, we assume it is validly encoded. So if a low surrogate is found at the curent input position then we
+ /// just consume it. Surrogate pairs should be seen as Hi, Lo. So if we have a Lo first, then the input stream
+ /// is fubar but we just ignore that.
+ ///
+ /// \param input Input stream context pointer
+ ///
+ void consume( ClassForwarder<ANTLR_LITTLE_ENDIAN> );
+
+ /// \brief Consume the next character in a UTF16 input stream when the input is Big Endian and the machine is not
+ ///
+ /// \param input Input stream context pointer
+ ///
+ void consume( ClassForwarder<ANTLR_BIG_ENDIAN> );
};
@@ -314,86 +314,86 @@ template<class ImplTraits, class SuperType>
class UTF32_IntStream : public IntStream<ImplTraits, SuperType>
{
public:
- ANTLR_UINT32 LA( ANTLR_INT32 i);
- void consume();
-
- /// \brief Calculate the current index in the output stream.
- /// \param[in] input Input stream context pointer
- ///
- ANTLR_MARKER index();
- void seek(ANTLR_MARKER seekPoint);
+ ANTLR_UINT32 LA( ANTLR_INT32 i);
+ void consume();
+
+ /// \brief Calculate the current index in the output stream.
+ /// \param[in] input Input stream context pointer
+ ///
+ ANTLR_MARKER index();
+ void seek(ANTLR_MARKER seekPoint);
protected:
- void setupIntStream(bool machineBigEndian, bool inputBigEndian);
- ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<RESOLVE_ENDIAN_AT_RUNTIME> );
- ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<BYTE_AGNOSTIC> );
- ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<ANTLR_LITTLE_ENDIAN> );
- ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<ANTLR_BIG_ENDIAN> );
-
- void consume( ClassForwarder<RESOLVE_ENDIAN_AT_RUNTIME> );
- void consume( ClassForwarder<BYTE_AGNOSTIC> );
- void consume( ClassForwarder<ANTLR_LITTLE_ENDIAN> );
- void consume( ClassForwarder<ANTLR_BIG_ENDIAN> );
+ void setupIntStream(bool machineBigEndian, bool inputBigEndian);
+ ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<RESOLVE_ENDIAN_AT_RUNTIME> );
+ ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<BYTE_AGNOSTIC> );
+ ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<ANTLR_LITTLE_ENDIAN> );
+ ANTLR_UINT32 LA( ANTLR_INT32 i, ClassForwarder<ANTLR_BIG_ENDIAN> );
+
+ void consume( ClassForwarder<RESOLVE_ENDIAN_AT_RUNTIME> );
+ void consume( ClassForwarder<BYTE_AGNOSTIC> );
+ void consume( ClassForwarder<ANTLR_LITTLE_ENDIAN> );
+ void consume( ClassForwarder<ANTLR_BIG_ENDIAN> );
};
template<class ImplTraits>
class TokenIntStream : public IntStream<ImplTraits, typename ImplTraits::TokenStreamType >
{
public:
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::TokenStreamType TokenStreamType;
- typedef IntStream<ImplTraits, TokenStreamType > BaseType;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::TokenStreamType TokenStreamType;
+ typedef IntStream<ImplTraits, TokenStreamType > BaseType;
private:
- /** Because the indirect call, though small in individual cases can
+ /** Because the indirect call, though small in individual cases can
* mount up if there are thousands of tokens (very large input streams), callers
* of size can optionally use this cached size field.
*/
- ANTLR_UINT32 m_cachedSize;
+ ANTLR_UINT32 m_cachedSize;
public:
- TokenIntStream();
- ANTLR_UINT32 get_cachedSize() const;
- void set_cachedSize( ANTLR_UINT32 cachedSize );
-
- void consume();
- void consumeInitialHiddenTokens();
- ANTLR_UINT32 LA( ANTLR_INT32 i );
- ANTLR_MARKER mark();
- ANTLR_UINT32 size();
- void release();
- ANTLR_MARKER tindex();
- void rewindLast();
- void rewind(ANTLR_MARKER marker);
- void seek(ANTLR_MARKER index);
- StringType getSourceName();
+ TokenIntStream();
+ ANTLR_UINT32 get_cachedSize() const;
+ void set_cachedSize( ANTLR_UINT32 cachedSize );
+
+ void consume();
+ void consumeInitialHiddenTokens();
+ ANTLR_UINT32 LA( ANTLR_INT32 i );
+ ANTLR_MARKER mark();
+ ANTLR_UINT32 size();
+ void release();
+ ANTLR_MARKER tindex();
+ void rewindLast();
+ void rewind(ANTLR_MARKER marker);
+ void seek(ANTLR_MARKER index);
+ StringType getSourceName();
};
template<class ImplTraits>
-class TreeNodeIntStream : public IntStream<ImplTraits, typename ImplTraits::TreeNodeStreamType>
+class TreeNodeIntStream : public IntStream<ImplTraits, typename ImplTraits::TreeNodeStreamType>
{
public:
- typedef typename ImplTraits::TreeNodeStreamType TreeNodeStreamType;
- typedef IntStream<ImplTraits, TreeNodeStreamType > BaseType;
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
+ typedef typename ImplTraits::TreeNodeStreamType TreeNodeStreamType;
+ typedef IntStream<ImplTraits, TreeNodeStreamType > BaseType;
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
public:
- void consume();
- ANTLR_MARKER tindex();
- ANTLR_UINT32 LA(ANTLR_INT32 i);
- ANTLR_MARKER mark();
- void release(ANTLR_MARKER marker);
- void rewindMark(ANTLR_MARKER marker);
- void rewindLast();
- void seek(ANTLR_MARKER index);
- ANTLR_UINT32 size();
+ void consume();
+ ANTLR_MARKER tindex();
+ ANTLR_UINT32 LA(ANTLR_INT32 i);
+ ANTLR_MARKER mark();
+ void release(ANTLR_MARKER marker);
+ void rewindMark(ANTLR_MARKER marker);
+ void rewindLast();
+ void seek(ANTLR_MARKER index);
+ ANTLR_UINT32 size();
};
-}
+}
#include "antlr3intstream.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3intstream.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3intstream.inl
index aa3a925169..e9990786bb 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3intstream.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3intstream.inl
@@ -1,126 +1,126 @@
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits, class SuperType>
ANTLR_INLINE IntStream<ImplTraits, SuperType>::IntStream()
{
- m_lastMarker = 0;
- m_upper_case = false;
+ m_lastMarker = 0;
+ m_upper_case = false;
}
template<class ImplTraits, class SuperType>
-ANTLR_INLINE typename IntStream<ImplTraits, SuperType>::StringType IntStream<ImplTraits, SuperType>::getSourceName()
+ANTLR_INLINE typename IntStream<ImplTraits, SuperType>::StringType IntStream<ImplTraits, SuperType>::getSourceName()
{
- return m_streamName;
+ return m_streamName;
}
template<class ImplTraits, class SuperType>
-ANTLR_INLINE typename IntStream<ImplTraits, SuperType>::StringType& IntStream<ImplTraits, SuperType>::get_streamName()
+ANTLR_INLINE typename IntStream<ImplTraits, SuperType>::StringType& IntStream<ImplTraits, SuperType>::get_streamName()
{
- return m_streamName;
+ return m_streamName;
}
template<class ImplTraits, class SuperType>
-ANTLR_INLINE const typename IntStream<ImplTraits, SuperType>::StringType& IntStream<ImplTraits, SuperType>::get_streamName() const
+ANTLR_INLINE const typename IntStream<ImplTraits, SuperType>::StringType& IntStream<ImplTraits, SuperType>::get_streamName() const
{
- return m_streamName;
+ return m_streamName;
}
template<class ImplTraits, class SuperType>
ANTLR_INLINE ANTLR_MARKER IntStream<ImplTraits, SuperType>::get_lastMarker() const
{
- return m_lastMarker;
+ return m_lastMarker;
}
template<class ImplTraits, class SuperType>
-ANTLR_INLINE void IntStream<ImplTraits, SuperType>::setUcaseLA(bool flag)
+ANTLR_INLINE void IntStream<ImplTraits, SuperType>::setUcaseLA(bool flag)
{
- m_upper_case = flag;
+ m_upper_case = flag;
}
template<class ImplTraits, class SuperType>
ANTLR_INLINE SuperType* IntStream<ImplTraits, SuperType>::get_super()
{
- return static_cast<SuperType*>(this);
+ return static_cast<SuperType*>(this);
}
template<class ImplTraits, class SuperType>
-void IntStream<ImplTraits, SuperType>::consume()
-{
- SuperType* input = this->get_super();
-
- const ANTLR_UINT8* nextChar = input->get_nextChar();
- const ANTLR_UINT8* data = input->get_data();
- ANTLR_UINT32 sizeBuf = input->get_sizeBuf();
-
- if ( nextChar < ( data + sizeBuf ) )
- {
- /* Indicate one more character in this line
- */
- input->inc_charPositionInLine();
-
- if ((ANTLR_UCHAR)(*(nextChar)) == input->get_newlineChar() )
- {
- /* Reset for start of a new line of input
- */
- input->inc_line();
- input->set_charPositionInLine(0);
- input->set_currentLine(nextChar + 1);
- }
-
- /* Increment to next character position
- */
- input->set_nextChar( nextChar + 1 );
+void IntStream<ImplTraits, SuperType>::consume()
+{
+ SuperType* input = this->get_super();
+
+ const ANTLR_UINT8* nextChar = input->get_nextChar();
+ const ANTLR_UINT8* data = input->get_data();
+ ANTLR_UINT32 sizeBuf = input->get_sizeBuf();
+
+ if ( nextChar < ( data + sizeBuf ) )
+ {
+ /* Indicate one more character in this line
+ */
+ input->inc_charPositionInLine();
+
+ if ((ANTLR_UCHAR)(*(nextChar)) == input->get_newlineChar() )
+ {
+ /* Reset for start of a new line of input
+ */
+ input->inc_line();
+ input->set_charPositionInLine(0);
+ input->set_currentLine(nextChar + 1);
+ }
+
+ /* Increment to next character position
+ */
+ input->set_nextChar( nextChar + 1 );
}
}
template<class ImplTraits, class SuperType>
-ANTLR_UINT32 IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la )
+ANTLR_UINT32 IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la )
{
- SuperType* input = this->get_super();
- const ANTLR_UINT8* nextChar = input->get_nextChar();
- const ANTLR_UINT8* data = input->get_data();
- ANTLR_UINT32 sizeBuf = input->get_sizeBuf();
+ SuperType* input = this->get_super();
+ const ANTLR_UINT8* nextChar = input->get_nextChar();
+ const ANTLR_UINT8* data = input->get_data();
+ ANTLR_UINT32 sizeBuf = input->get_sizeBuf();
- if (( nextChar + la - 1) >= (data + sizeBuf))
+ if (( nextChar + la - 1) >= (data + sizeBuf))
{
- return ANTLR_CHARSTREAM_EOF;
+ return ANTLR_CHARSTREAM_EOF;
}
else
{
- if( !m_upper_case )
- return (ANTLR_UCHAR)(*(nextChar + la - 1));
- else
- return (ANTLR_UCHAR)toupper(*(nextChar + la - 1));
+ if( !m_upper_case )
+ return (ANTLR_UCHAR)(*(nextChar + la - 1));
+ else
+ return (ANTLR_UCHAR)toupper(*(nextChar + la - 1));
}
}
template<class ImplTraits, class SuperType>
ANTLR_MARKER IntStream<ImplTraits, SuperType>::mark()
{
- LexState<ImplTraits>* state;
+ LexState<ImplTraits>* state;
SuperType* input = this->get_super();
- /* New mark point
+ /* New mark point
*/
input->inc_markDepth();
/* See if we are revisiting a mark as we can just reuse the vector
* entry if we are, otherwise, we need a new one
*/
- if (input->get_markDepth() > input->get_markers().size() )
- {
- input->get_markers().push_back( LexState<ImplTraits>() );
- LexState<ImplTraits>& state_r = input->get_markers().back();
- state = &state_r;
+ if (input->get_markDepth() > input->get_markers().size() )
+ {
+ input->get_markers().push_back( LexState<ImplTraits>() );
+ LexState<ImplTraits>& state_r = input->get_markers().back();
+ state = &state_r;
}
else
{
- LexState<ImplTraits>& state_r = input->get_markers().at( input->get_markDepth() - 1 );
- state = &state_r;
+ LexState<ImplTraits>& state_r = input->get_markers().at( input->get_markDepth() - 1 );
+ state = &state_r;
- /* Assume no errors for speed, it will just blow up if the table failed
- * for some reasons, hence lots of unit tests on the tables ;-)
- */
+ /* Assume no errors for speed, it will just blow up if the table failed
+ * for some reasons, hence lots of unit tests on the tables ;-)
+ */
}
/* We have created or retrieved the state, so update it with the current
@@ -139,14 +139,14 @@ ANTLR_MARKER IntStream<ImplTraits, SuperType>::mark()
}
template<class ImplTraits, class SuperType>
-ANTLR_MARKER IntStream<ImplTraits, SuperType>::index()
+ANTLR_MARKER IntStream<ImplTraits, SuperType>::index()
{
- SuperType* input = this->get_super();
- return input->index_impl();
+ SuperType* input = this->get_super();
+ return input->index_impl();
}
template<class ImplTraits, class SuperType>
-void IntStream<ImplTraits, SuperType>::rewind(ANTLR_MARKER mark)
+void IntStream<ImplTraits, SuperType>::rewind(ANTLR_MARKER mark)
{
SuperType* input = this->get_super();
@@ -154,16 +154,16 @@ void IntStream<ImplTraits, SuperType>::rewind(ANTLR_MARKER mark)
*/
this->release(mark);
- /* Find the supplied mark state
+ /* Find the supplied mark state
*/
- ANTLR_UINT32 idx = static_cast<ANTLR_UINT32>( mark-1 );
+ ANTLR_UINT32 idx = static_cast<ANTLR_UINT32>( mark-1 );
typename ImplTraits::LexStateType& state = input->get_markers().at( idx );
/* Seek input pointer to the requested point (note we supply the void *pointer
* to whatever is implementing the int stream to seek).
*/
- this->seek( (ANTLR_MARKER)state.get_nextChar() );
-
+ this->seek( (ANTLR_MARKER)state.get_nextChar() );
+
/* Reset to the reset of the information in the mark
*/
input->set_charPositionInLine( state.get_charPositionInLine() );
@@ -176,17 +176,17 @@ void IntStream<ImplTraits, SuperType>::rewind(ANTLR_MARKER mark)
}
template<class ImplTraits, class SuperType>
-void IntStream<ImplTraits, SuperType>::rewindLast()
+void IntStream<ImplTraits, SuperType>::rewindLast()
{
- this->rewind(m_lastMarker);
+ this->rewind(m_lastMarker);
}
template<class ImplTraits, class SuperType>
-void IntStream<ImplTraits, SuperType>::release(ANTLR_MARKER mark)
+void IntStream<ImplTraits, SuperType>::release(ANTLR_MARKER mark)
{
- SuperType* input = this->get_super();
+ SuperType* input = this->get_super();
- /* We don't do much here in fact as we never free any higher marks in
+ /* We don't do much here in fact as we never free any higher marks in
* the hashtable as we just resuse any memory allocated for them.
*/
input->set_markDepth( (ANTLR_UINT32)(mark - 1) );
@@ -199,29 +199,29 @@ void IntStream<ImplTraits, SuperType>::setupIntStream(bool, bool)
}
template<class ImplTraits, class SuperType>
-void IntStream<ImplTraits, SuperType>::seek(ANTLR_MARKER seekPoint)
-{
- ANTLR_INT32 count;
- SuperType* input = this->get_super();
-
- ANTLR_MARKER nextChar = (ANTLR_MARKER) input->get_nextChar();
- /* If the requested seek point is less than the current
- * input point, then we assume that we are resetting from a mark
- * and do not need to scan, but can just set to there.
- */
- if (seekPoint <= nextChar)
- {
- input->set_nextChar((ANTLR_UINT8*) seekPoint);
- }
- else
- {
- count = (ANTLR_UINT32)(seekPoint - nextChar);
-
- while (count--)
- {
- this->consume();
- }
- }
+void IntStream<ImplTraits, SuperType>::seek(ANTLR_MARKER seekPoint)
+{
+ ANTLR_INT32 count;
+ SuperType* input = this->get_super();
+
+ ANTLR_MARKER nextChar = (ANTLR_MARKER) input->get_nextChar();
+ /* If the requested seek point is less than the current
+ * input point, then we assume that we are resetting from a mark
+ * and do not need to scan, but can just set to there.
+ */
+ if (seekPoint <= nextChar)
+ {
+ input->set_nextChar((ANTLR_UINT8*) seekPoint);
+ }
+ else
+ {
+ count = (ANTLR_UINT32)(seekPoint - nextChar);
+
+ while (count--)
+ {
+ this->consume();
+ }
+ }
}
template<class ImplTraits, class SuperType>
@@ -230,225 +230,225 @@ IntStream<ImplTraits, SuperType>::~IntStream()
}
template<class ImplTraits, class SuperType>
-ANTLR_UINT32 EBCDIC_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la)
+ANTLR_UINT32 EBCDIC_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la)
{
- // EBCDIC to ASCII conversion table
+ // EBCDIC to ASCII conversion table
+ //
+ // This for EBCDIC EDF04 translated to ISO-8859.1 which is the usually accepted POSIX
+ // translation and the character tables are published all over the interweb.
//
- // This for EBCDIC EDF04 translated to ISO-8859.1 which is the usually accepted POSIX
- // translation and the character tables are published all over the interweb.
- //
- const ANTLR_UCHAR e2a[256] =
- {
- 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f,
- 0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97,
- 0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f,
- 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b,
- 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07,
- 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04,
- 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a,
- 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5,
- 0xe7, 0xf1, 0x60, 0x2e, 0x3c, 0x28, 0x2b, 0x7c,
- 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef,
- 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x9f,
- 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5,
- 0xc7, 0xd1, 0x5e, 0x2c, 0x25, 0x5f, 0x3e, 0x3f,
- 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf,
- 0xcc, 0xa8, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22,
- 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
- 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1,
- 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
- 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4,
- 0xb5, 0xaf, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
- 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0xdd, 0xde, 0xae,
- 0xa2, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc,
- 0xbd, 0xbe, 0xac, 0x5b, 0x5c, 0x5d, 0xb4, 0xd7,
- 0xf9, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
- 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5,
- 0xa6, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
- 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xdb, 0xfa, 0xff,
- 0xd9, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
- 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5,
- 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
- 0x38, 0x39, 0xb3, 0x7b, 0xdc, 0x7d, 0xda, 0x7e
- };
-
- SuperType* input = this->get_super();
-
- if (( input->get_nextChar() + la - 1) >= ( input->get_data() + input->get_sizeBuf() ))
+ const ANTLR_UCHAR e2a[256] =
+ {
+ 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f,
+ 0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97,
+ 0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07,
+ 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04,
+ 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a,
+ 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5,
+ 0xe7, 0xf1, 0x60, 0x2e, 0x3c, 0x28, 0x2b, 0x7c,
+ 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef,
+ 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x9f,
+ 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5,
+ 0xc7, 0xd1, 0x5e, 0x2c, 0x25, 0x5f, 0x3e, 0x3f,
+ 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf,
+ 0xcc, 0xa8, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22,
+ 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1,
+ 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
+ 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4,
+ 0xb5, 0xaf, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+ 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0xdd, 0xde, 0xae,
+ 0xa2, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc,
+ 0xbd, 0xbe, 0xac, 0x5b, 0x5c, 0x5d, 0xb4, 0xd7,
+ 0xf9, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5,
+ 0xa6, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
+ 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xdb, 0xfa, 0xff,
+ 0xd9, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
+ 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0xb3, 0x7b, 0xdc, 0x7d, 0xda, 0x7e
+ };
+
+ SuperType* input = this->get_super();
+
+ if (( input->get_nextChar() + la - 1) >= ( input->get_data() + input->get_sizeBuf() ))
{
- return ANTLR_CHARSTREAM_EOF;
+ return ANTLR_CHARSTREAM_EOF;
}
else
{
// Translate the required character via the constant conversion table
//
- return e2a[(*(input->get_nextChar() + la - 1))];
+ return e2a[(*(input->get_nextChar() + la - 1))];
}
}
template<class ImplTraits, class SuperType>
void EBCDIC_IntStream<ImplTraits, SuperType>::setupIntStream()
{
- SuperType* super = this->get_super();
- super->set_charByteSize(1);
+ SuperType* super = this->get_super();
+ super->set_charByteSize(1);
}
template<class ImplTraits, class SuperType>
-ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 i)
+ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 i)
{
- return this->LA(i, ClassForwarder< typename ImplTraits::Endianness >() );
+ return this->LA(i, ClassForwarder< typename ImplTraits::Endianness >() );
}
template<class ImplTraits, class SuperType>
void UTF16_IntStream<ImplTraits, SuperType>::consume()
{
- this->consume( ClassForwarder< typename ImplTraits::Endianness >() );
+ this->consume( ClassForwarder< typename ImplTraits::Endianness >() );
}
template<class ImplTraits, class SuperType>
-ANTLR_MARKER UTF16_IntStream<ImplTraits, SuperType>::index()
+ANTLR_MARKER UTF16_IntStream<ImplTraits, SuperType>::index()
{
- SuperType* input = this->get_super();
+ SuperType* input = this->get_super();
return (ANTLR_MARKER)(input->get_nextChar());
}
template<class ImplTraits, class SuperType>
void UTF16_IntStream<ImplTraits, SuperType>::seek(ANTLR_MARKER seekPoint)
{
- SuperType* input = this->get_super();
+ SuperType* input = this->get_super();
- // If the requested seek point is less than the current
- // input point, then we assume that we are resetting from a mark
- // and do not need to scan, but can just set to there as rewind will
+ // If the requested seek point is less than the current
+ // input point, then we assume that we are resetting from a mark
+ // and do not need to scan, but can just set to there as rewind will
// reset line numbers and so on.
- //
- if (seekPoint <= (ANTLR_MARKER)(input->get_nextChar()))
- {
- input->set_nextChar( seekPoint );
- }
- else
- {
+ //
+ if (seekPoint <= (ANTLR_MARKER)(input->get_nextChar()))
+ {
+ input->set_nextChar( seekPoint );
+ }
+ else
+ {
// Call consume until we reach the asked for seek point or EOF
//
- while( (this->LA(1) != ANTLR_CHARSTREAM_EOF) && (seekPoint < (ANTLR_MARKER)input->get_nextChar() ) )
- {
- this->consume();
- }
- }
+ while( (this->LA(1) != ANTLR_CHARSTREAM_EOF) && (seekPoint < (ANTLR_MARKER)input->get_nextChar() ) )
+ {
+ this->consume();
+ }
+ }
}
template<class ImplTraits, class SuperType>
void IntStream<ImplTraits, SuperType>::findout_endian_spec(bool machineBigEndian, bool inputBigEndian)
{
- // We must install different UTF16 routines according to whether the input
- // is the same endianess as the machine we are executing upon or not. If it is not
- // then we must install methods that can convert the endianess on the fly as they go
- //
-
- if(machineBigEndian == true)
- {
- // Machine is Big Endian, if the input is also then install the
- // methods that do not access input by bytes and reverse them.
- // Otherwise install endian aware methods.
- //
- if (inputBigEndian == true)
- {
- // Input is machine compatible
- //
- m_endian_spec = 1;
- }
- else
- {
- // Need to use methods that know that the input is little endian
- //
- m_endian_spec = 2;
- }
- }
- else
- {
- // Machine is Little Endian, if the input is also then install the
- // methods that do not access input by bytes and reverse them.
- // Otherwise install endian aware methods.
- //
- if (inputBigEndian == false)
- {
- // Input is machine compatible
- //
- m_endian_spec = 1;
- }
- else
- {
- // Need to use methods that know that the input is Big Endian
- //
- m_endian_spec = 3;
- }
- }
+ // We must install different UTF16 routines according to whether the input
+ // is the same endianess as the machine we are executing upon or not. If it is not
+ // then we must install methods that can convert the endianess on the fly as they go
+ //
+
+ if(machineBigEndian == true)
+ {
+ // Machine is Big Endian, if the input is also then install the
+ // methods that do not access input by bytes and reverse them.
+ // Otherwise install endian aware methods.
+ //
+ if (inputBigEndian == true)
+ {
+ // Input is machine compatible
+ //
+ m_endian_spec = 1;
+ }
+ else
+ {
+ // Need to use methods that know that the input is little endian
+ //
+ m_endian_spec = 2;
+ }
+ }
+ else
+ {
+ // Machine is Little Endian, if the input is also then install the
+ // methods that do not access input by bytes and reverse them.
+ // Otherwise install endian aware methods.
+ //
+ if (inputBigEndian == false)
+ {
+ // Input is machine compatible
+ //
+ m_endian_spec = 1;
+ }
+ else
+ {
+ // Need to use methods that know that the input is Big Endian
+ //
+ m_endian_spec = 3;
+ }
+ }
}
template<class ImplTraits, class SuperType>
void UTF16_IntStream<ImplTraits, SuperType>::setupIntStream(bool machineBigEndian, bool inputBigEndian)
{
- SuperType* super = this->get_super();
- super->set_charByteSize(2);
+ SuperType* super = this->get_super();
+ super->set_charByteSize(2);
- this->findout_endian_spec( machineBigEndian, inputBigEndian );
+ this->findout_endian_spec( machineBigEndian, inputBigEndian );
}
template<class ImplTraits, class SuperType>
-ANTLR_UINT32 IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 i, ClassForwarder<RESOLVE_ENDIAN_AT_RUNTIME> )
-{
- assert( (m_endian_spec >= 1) && (m_endian_spec <= 3));
- switch(m_endian_spec)
- {
- case 1:
- return this->LA(i, ClassForwarder<BYTE_AGNOSTIC>() );
- break;
- case 2:
- return this->LA(i, ClassForwarder<ANTLR_LITTLE_ENDIAN>() );
- break;
- case 3:
- return this->LA(i, ClassForwarder<ANTLR_BIG_ENDIAN>() );
- break;
- default:
- break;
- }
- return 0;
+ANTLR_UINT32 IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 i, ClassForwarder<RESOLVE_ENDIAN_AT_RUNTIME> )
+{
+ assert( (m_endian_spec >= 1) && (m_endian_spec <= 3));
+ switch(m_endian_spec)
+ {
+ case 1:
+ return this->LA(i, ClassForwarder<BYTE_AGNOSTIC>() );
+ break;
+ case 2:
+ return this->LA(i, ClassForwarder<ANTLR_LITTLE_ENDIAN>() );
+ break;
+ case 3:
+ return this->LA(i, ClassForwarder<ANTLR_BIG_ENDIAN>() );
+ break;
+ default:
+ break;
+ }
+ return 0;
}
template<class ImplTraits, class SuperType>
-void IntStream<ImplTraits, SuperType>::consume( ClassForwarder<RESOLVE_ENDIAN_AT_RUNTIME> )
-{
- assert( (m_endian_spec >= 1) && (m_endian_spec <= 3));
- switch(m_endian_spec)
- {
- case 1:
- this->consume( ClassForwarder<BYTE_AGNOSTIC>() );
- break;
- case 2:
- this->consume( ClassForwarder<ANTLR_LITTLE_ENDIAN>() );
- break;
- case 3:
- this->consume( ClassForwarder<ANTLR_BIG_ENDIAN>() );
- break;
- default:
- break;
- }
+void IntStream<ImplTraits, SuperType>::consume( ClassForwarder<RESOLVE_ENDIAN_AT_RUNTIME> )
+{
+ assert( (m_endian_spec >= 1) && (m_endian_spec <= 3));
+ switch(m_endian_spec)
+ {
+ case 1:
+ this->consume( ClassForwarder<BYTE_AGNOSTIC>() );
+ break;
+ case 2:
+ this->consume( ClassForwarder<ANTLR_LITTLE_ENDIAN>() );
+ break;
+ case 3:
+ this->consume( ClassForwarder<ANTLR_BIG_ENDIAN>() );
+ break;
+ default:
+ break;
+ }
}
template<class ImplTraits, class SuperType>
-ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassForwarder<BYTE_AGNOSTIC> )
+ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassForwarder<BYTE_AGNOSTIC> )
{
- SuperType* input;
+ SuperType* input;
UTF32 ch;
UTF32 ch2;
- UTF16* nextChar;
+ UTF16* nextChar;
// Find the input interface and where we are currently pointing to
// in the input stream
//
- input = this->get_super;
- nextChar = input->get_nextChar();
+ input = this->get_super;
+ nextChar = input->get_nextChar();
// If a positive offset then advance forward, else retreat
//
@@ -465,11 +465,11 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If we have a surrogate pair then we need to consume
// a following valid LO surrogate.
//
- if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
{
// If the 16 bits following the high surrogate are in the source buffer...
//
- if ((ANTLR_UINT8*)(nextChar) < (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf() ))
+ if ((ANTLR_UINT8*)(nextChar) < (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf() ))
{
// Next character is in natural machine byte order
//
@@ -477,16 +477,16 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If it's a valid low surrogate, consume it
//
- if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
+ if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
{
// We consumed one 16 bit character
//
- nextChar++;
+ nextChar++;
}
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it.
//
- }
+ }
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it because the buffer ended
//
@@ -510,10 +510,10 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If we found a low surrogate then go back one more character if
// the hi surrogate is there
//
- if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END)
+ if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END)
{
ch2 = *(nextChar-1);
- if (ch2 >= UNI_SUR_HIGH_START && ch2 <= UNI_SUR_HIGH_END)
+ if (ch2 >= UNI_SUR_HIGH_START && ch2 <= UNI_SUR_HIGH_END)
{
// Yes, there is a high surrogate to match it so decrement one more and point to that
//
@@ -527,12 +527,12 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
//
// Input buffer size is always in bytes
//
- if ( (ANTLR_UINT8*)nextChar >= (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf() ))
- {
- return ANTLR_CHARSTREAM_EOF;
- }
- else
- {
+ if ( (ANTLR_UINT8*)nextChar >= (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf() ))
+ {
+ return ANTLR_CHARSTREAM_EOF;
+ }
+ else
+ {
// Pick up the next 16 character (native machine byte order)
//
ch = *nextChar++;
@@ -540,11 +540,11 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If we have a surrogate pair then we need to consume
// a following valid LO surrogate.
//
- if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
{
// If the 16 bits following the high surrogate are in the source buffer...
//
- if ((ANTLR_UINT8*)(nextChar) < (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf()))
+ if ((ANTLR_UINT8*)(nextChar) < (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf()))
{
// Next character is in natural machine byte order
//
@@ -552,17 +552,17 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If it's a valid low surrogate, consume it
//
- if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
+ if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
{
// Construct the UTF32 code point
//
ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
- + (ch2 - UNI_SUR_LOW_START) + halfBase;
+ + (ch2 - UNI_SUR_LOW_START) + halfBase;
}
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it.
//
- }
+ }
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it because the buffer ended
//
@@ -572,9 +572,9 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
}
template<class ImplTraits, class SuperType>
-ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassForwarder<ANTLR_LITTLE_ENDIAN> )
+ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassForwarder<ANTLR_LITTLE_ENDIAN> )
{
- SuperType* input;
+ SuperType* input;
UTF32 ch;
UTF32 ch2;
ANTLR_UCHAR* nextChar;
@@ -582,7 +582,7 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// Find the input interface and where we are currently pointing to
// in the input stream
//
- input = this->get_super();
+ input = this->get_super();
nextChar = input->get_nextChar();
// If a positive offset then advance forward, else retreat
@@ -601,11 +601,11 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If we have a surrogate pair then we need to consume
// a following valid LO surrogate.
//
- if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
{
// If the 16 bits following the high surrogate are in the source buffer...
//
- if ((ANTLR_UINT8*)(nextChar) < (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf() ))
+ if ((ANTLR_UINT8*)(nextChar) < (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf() ))
{
// Next character is in little endian byte order
//
@@ -613,16 +613,16 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If it's a valid low surrogate, consume it
//
- if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
+ if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
{
// We consumed one 16 bit character
//
- nextChar += 2;
+ nextChar += 2;
}
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it.
//
- }
+ }
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it because the buffer ended
//
@@ -647,10 +647,10 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If we found a low surrogate then go back one more character if
// the hi surrogate is there
//
- if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END)
+ if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END)
{
ch2 = (*nextChar - 2) + ((*nextChar -1) << 8);
- if (ch2 >= UNI_SUR_HIGH_START && ch2 <= UNI_SUR_HIGH_END)
+ if (ch2 >= UNI_SUR_HIGH_START && ch2 <= UNI_SUR_HIGH_END)
{
// Yes, there is a high surrogate to match it so decrement one more and point to that
//
@@ -664,12 +664,12 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
//
// Input buffer size is always in bytes
//
- if ( (ANTLR_UINT8*)nextChar >= (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf()))
- {
- return ANTLR_CHARSTREAM_EOF;
- }
- else
- {
+ if ( (ANTLR_UINT8*)nextChar >= (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf()))
+ {
+ return ANTLR_CHARSTREAM_EOF;
+ }
+ else
+ {
// Pick up the next 16 character (little endian byte order)
//
ch = (*nextChar) + (*(nextChar+1) << 8);
@@ -678,11 +678,11 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If we have a surrogate pair then we need to consume
// a following valid LO surrogate.
//
- if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
{
// If the 16 bits following the high surrogate are in the source buffer...
//
- if ((ANTLR_UINT8*)(nextChar) < (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf()))
+ if ((ANTLR_UINT8*)(nextChar) < (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf()))
{
// Next character is in little endian byte order
//
@@ -690,17 +690,17 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If it's a valid low surrogate, consume it
//
- if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
+ if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
{
// Construct the UTF32 code point
//
ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
- + (ch2 - UNI_SUR_LOW_START) + halfBase;
+ + (ch2 - UNI_SUR_LOW_START) + halfBase;
}
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it.
//
- }
+ }
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it because the buffer ended
//
@@ -710,9 +710,9 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
}
template<class ImplTraits, class SuperType>
-ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassForwarder<ANTLR_BIG_ENDIAN> )
+ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassForwarder<ANTLR_BIG_ENDIAN> )
{
- SuperType* input;
+ SuperType* input;
UTF32 ch;
UTF32 ch2;
ANTLR_UCHAR* nextChar;
@@ -720,7 +720,7 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// Find the input interface and where we are currently pointing to
// in the input stream
//
- input = this->get_super();
+ input = this->get_super();
nextChar = input->get_nextChar();
// If a positive offset then advance forward, else retreat
@@ -739,11 +739,11 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If we have a surrogate pair then we need to consume
// a following valid LO surrogate.
//
- if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
{
// If the 16 bits following the high surrogate are in the source buffer...
//
- if ((ANTLR_UINT8*)(nextChar) < (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf()))
+ if ((ANTLR_UINT8*)(nextChar) < (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf()))
{
// Next character is in big endian byte order
//
@@ -751,16 +751,16 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If it's a valid low surrogate, consume it
//
- if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
+ if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
{
// We consumed one 16 bit character
//
- nextChar += 2;
+ nextChar += 2;
}
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it.
//
- }
+ }
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it because the buffer ended
//
@@ -785,10 +785,10 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If we found a low surrogate then go back one more character if
// the hi surrogate is there
//
- if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END)
+ if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END)
{
ch2 = ((*nextChar - 2) << 8) + (*nextChar -1);
- if (ch2 >= UNI_SUR_HIGH_START && ch2 <= UNI_SUR_HIGH_END)
+ if (ch2 >= UNI_SUR_HIGH_START && ch2 <= UNI_SUR_HIGH_END)
{
// Yes, there is a high surrogate to match it so decrement one more and point to that
//
@@ -802,12 +802,12 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
//
// Input buffer size is always in bytes
//
- if ( (ANTLR_UINT8*)nextChar >= (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf()))
- {
- return ANTLR_CHARSTREAM_EOF;
- }
- else
- {
+ if ( (ANTLR_UINT8*)nextChar >= (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf()))
+ {
+ return ANTLR_CHARSTREAM_EOF;
+ }
+ else
+ {
// Pick up the next 16 character (big endian byte order)
//
ch = ((*nextChar) << 8) + *(nextChar+1);
@@ -816,11 +816,11 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If we have a surrogate pair then we need to consume
// a following valid LO surrogate.
//
- if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
{
// If the 16 bits following the high surrogate are in the source buffer...
//
- if ((ANTLR_UINT8*)(nextChar) < (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf()))
+ if ((ANTLR_UINT8*)(nextChar) < (((ANTLR_UINT8*)input->get_data()) + input->get_sizeBuf()))
{
// Next character is in big endian byte order
//
@@ -828,17 +828,17 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
// If it's a valid low surrogate, consume it
//
- if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
+ if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
{
// Construct the UTF32 code point
//
ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
- + (ch2 - UNI_SUR_LOW_START) + halfBase;
+ + (ch2 - UNI_SUR_LOW_START) + halfBase;
}
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it.
//
- }
+ }
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it because the buffer ended
//
@@ -848,40 +848,40 @@ ANTLR_UINT32 UTF16_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
}
template<class ImplTraits, class SuperType>
-void UTF16_IntStream<ImplTraits, SuperType>::consume( ClassForwarder<BYTE_AGNOSTIC> )
+void UTF16_IntStream<ImplTraits, SuperType>::consume( ClassForwarder<BYTE_AGNOSTIC> )
{
- SuperType* input;
+ SuperType* input;
UTF32 ch;
UTF32 ch2;
- input = this->get_super();
+ input = this->get_super();
// Buffer size is always in bytes
//
- if(input->get_nextChar() < (input->get_data() + input->get_sizeBuf()/2) )
- {
- // Indicate one more character in this line
- //
- input->inc_charPositionInLine();
-
- if ((ANTLR_UCHAR)(*(input->get_nextChar())) == input->get_newlineChar())
- {
- // Reset for start of a new line of input
- //
- input->inc_line();
- input->set_charPositionInLine(0);
- input->set_currentLine( input->get_nextChar() + 1 );
- }
-
- // Increment to next character position, accounting for any surrogates
- //
+ if(input->get_nextChar() < (input->get_data() + input->get_sizeBuf()/2) )
+ {
+ // Indicate one more character in this line
+ //
+ input->inc_charPositionInLine();
+
+ if ((ANTLR_UCHAR)(*(input->get_nextChar())) == input->get_newlineChar())
+ {
+ // Reset for start of a new line of input
+ //
+ input->inc_line();
+ input->set_charPositionInLine(0);
+ input->set_currentLine( input->get_nextChar() + 1 );
+ }
+
+ // Increment to next character position, accounting for any surrogates
+ //
// Next char in natural machine byte order
//
ch = *(input->get_nextChar());
// We consumed one 16 bit character
//
- input->set_nextChar( input->get_nextChar() + 1 );
+ input->set_nextChar( input->get_nextChar() + 1 );
// If we have a surrogate pair then we need to consume
// a following valid LO surrogate.
@@ -898,69 +898,69 @@ void UTF16_IntStream<ImplTraits, SuperType>::consume( ClassForwarder<BYTE_AGNOST
// If it's a valid low surrogate, consume it
//
- if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
+ if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
{
// We consumed one 16 bit character
//
- input->set_nextChar( input->get_nextChar() + 1 );
+ input->set_nextChar( input->get_nextChar() + 1 );
}
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it.
//
- }
+ }
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it because the buffer ended
//
- }
+ }
// Note that we did not check for an invalid low surrogate here, or that fact that the
// lo surrogate was missing. We just picked out one 16 bit character unless the character
// was a valid hi surrogate, in whcih case we consumed two 16 bit characters.
//
- }
+ }
}
template<class ImplTraits, class SuperType>
-void UTF16_IntStream<ImplTraits, SuperType>::consume( ClassForwarder<ANTLR_LITTLE_ENDIAN> )
+void UTF16_IntStream<ImplTraits, SuperType>::consume( ClassForwarder<ANTLR_LITTLE_ENDIAN> )
{
- SuperType* input;
+ SuperType* input;
UTF32 ch;
UTF32 ch2;
- input = this->get_super();
+ input = this->get_super();
// Buffer size is always in bytes
//
- if(input->get_nextChar() < (input->get_data() + input->get_sizeBuf()/2) )
- {
- // Indicate one more character in this line
- //
- input->inc_charPositionInLine();
-
- if ((ANTLR_UCHAR)(*(input->get_nextChar())) == input->get_newlineChar())
- {
- // Reset for start of a new line of input
- //
- input->inc_line();
- input->set_charPositionInLine(0);
- input->set_currentLine(input->get_nextChar() + 1);
- }
-
- // Increment to next character position, accounting for any surrogates
- //
+ if(input->get_nextChar() < (input->get_data() + input->get_sizeBuf()/2) )
+ {
+ // Indicate one more character in this line
+ //
+ input->inc_charPositionInLine();
+
+ if ((ANTLR_UCHAR)(*(input->get_nextChar())) == input->get_newlineChar())
+ {
+ // Reset for start of a new line of input
+ //
+ input->inc_line();
+ input->set_charPositionInLine(0);
+ input->set_currentLine(input->get_nextChar() + 1);
+ }
+
+ // Increment to next character position, accounting for any surrogates
+ //
// Next char in litle endian form
//
ch = *((ANTLR_UINT8*)input->get_nextChar()) + (*((ANTLR_UINT8*)input->get_nextChar() + 1) <<8);
// We consumed one 16 bit character
//
- input->set_nextChar( input->get_nextChar() + 1);
+ input->set_nextChar( input->get_nextChar() + 1);
// If we have a surrogate pair then we need to consume
// a following valid LO surrogate.
//
- if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
- {
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
+ {
// If the 16 bits following the high surrogate are in the source buffer...
//
if(input->get_nextChar() < (input->get_data() + input->get_sizeBuf()/2) )
@@ -969,68 +969,68 @@ void UTF16_IntStream<ImplTraits, SuperType>::consume( ClassForwarder<ANTLR_LITTL
// If it's a valid low surrogate, consume it
//
- if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
+ if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
{
// We consumed one 16 bit character
//
- input->set_nextChar( input->get_nextChar() + 1);
+ input->set_nextChar( input->get_nextChar() + 1);
}
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it.
//
- }
+ }
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it because the buffer ended
//
- }
+ }
// Note that we did not check for an invalid low surrogate here, or that fact that the
// lo surrogate was missing. We just picked out one 16 bit character unless the character
// was a valid hi surrogate, in whcih case we consumed two 16 bit characters.
//
- }
+ }
}
template<class ImplTraits, class SuperType>
-void UTF16_IntStream<ImplTraits, SuperType>::consume( ClassForwarder<ANTLR_BIG_ENDIAN> )
+void UTF16_IntStream<ImplTraits, SuperType>::consume( ClassForwarder<ANTLR_BIG_ENDIAN> )
{
- SuperType* input;
+ SuperType* input;
UTF32 ch;
UTF32 ch2;
- input = this->get_super();
+ input = this->get_super();
// Buffer size is always in bytes
//
- if(input->get_nextChar() < (input->get_data() + input->get_sizeBuf()/2) )
- {
- // Indicate one more character in this line
- //
- input->inc_charPositionInLine();
-
- if ((ANTLR_UCHAR)(*(input->get_nextChar())) == input->get_newlineChar())
- {
- // Reset for start of a new line of input
- //
- input->inc_line();
- input->set_charPositionInLine(0);
- input->set_currentLine(input->get_nextChar() + 1);
- }
-
- // Increment to next character position, accounting for any surrogates
- //
+ if(input->get_nextChar() < (input->get_data() + input->get_sizeBuf()/2) )
+ {
+ // Indicate one more character in this line
+ //
+ input->inc_charPositionInLine();
+
+ if ((ANTLR_UCHAR)(*(input->get_nextChar())) == input->get_newlineChar())
+ {
+ // Reset for start of a new line of input
+ //
+ input->inc_line();
+ input->set_charPositionInLine(0);
+ input->set_currentLine(input->get_nextChar() + 1);
+ }
+
+ // Increment to next character position, accounting for any surrogates
+ //
// Next char in big endian form
//
ch = *((ANTLR_UINT8*)input->get_nextChar() + 1) + (*((ANTLR_UINT8*)input->get_nextChar() ) <<8);
// We consumed one 16 bit character
//
- input->set_nextChar( input->get_nextChar() + 1);
+ input->set_nextChar( input->get_nextChar() + 1);
// If we have a surrogate pair then we need to consume
// a following valid LO surrogate.
//
- if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
- {
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
+ {
// If the 16 bits following the high surrogate are in the source buffer...
//
if(input->get_nextChar() < (input->get_data() + input->get_sizeBuf()/2) )
@@ -1041,100 +1041,100 @@ void UTF16_IntStream<ImplTraits, SuperType>::consume( ClassForwarder<ANTLR_BIG_E
// If it's a valid low surrogate, consume it
//
- if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
+ if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
{
// We consumed one 16 bit character
//
- input->set_nextChar( input->get_nextChar() + 1);
+ input->set_nextChar( input->get_nextChar() + 1);
}
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it.
//
- }
+ }
// Note that we ignore a valid hi surrogate that has no lo surrogate to go with
// it because the buffer ended
//
- }
+ }
// Note that we did not check for an invalid low surrogate here, or that fact that the
// lo surrogate was missing. We just picked out one 16 bit character unless the character
// was a valid hi surrogate, in whcih case we consumed two 16 bit characters.
//
- }
+ }
}
template<class ImplTraits, class SuperType>
-ANTLR_UINT32 UTF32_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 i)
+ANTLR_UINT32 UTF32_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 i)
{
- return this->LA( i, ClassForwarder<typename ImplTraits::Endianness>() );
+ return this->LA( i, ClassForwarder<typename ImplTraits::Endianness>() );
}
template<class ImplTraits, class SuperType>
-ANTLR_MARKER UTF32_IntStream<ImplTraits, SuperType>::index()
+ANTLR_MARKER UTF32_IntStream<ImplTraits, SuperType>::index()
{
- SuperType* input = this->get_super();
+ SuperType* input = this->get_super();
return (ANTLR_MARKER)(input->get_nextChar());
}
template<class ImplTraits, class SuperType>
void UTF32_IntStream<ImplTraits, SuperType>::seek(ANTLR_MARKER seekPoint)
{
- SuperType* input;
+ SuperType* input;
- input = this->get_super();
+ input = this->get_super();
- // If the requested seek point is less than the current
- // input point, then we assume that we are resetting from a mark
- // and do not need to scan, but can just set to there as rewind will
+ // If the requested seek point is less than the current
+ // input point, then we assume that we are resetting from a mark
+ // and do not need to scan, but can just set to there as rewind will
// reset line numbers and so on.
- //
- if (seekPoint <= (ANTLR_MARKER)(input->get_nextChar()))
- {
- input->set_nextChar( static_cast<typename ImplTraits::DataType*>(seekPoint) );
- }
- else
- {
+ //
+ if (seekPoint <= (ANTLR_MARKER)(input->get_nextChar()))
+ {
+ input->set_nextChar( static_cast<typename ImplTraits::DataType*>(seekPoint) );
+ }
+ else
+ {
// Call consume until we reach the asked for seek point or EOF
//
- while( (this->LA(1) != ANTLR_CHARSTREAM_EOF) && (seekPoint < (ANTLR_MARKER)input->get_nextChar()) )
- {
- this->consume();
- }
- }
+ while( (this->LA(1) != ANTLR_CHARSTREAM_EOF) && (seekPoint < (ANTLR_MARKER)input->get_nextChar()) )
+ {
+ this->consume();
+ }
+ }
}
template<class ImplTraits, class SuperType>
void UTF32_IntStream<ImplTraits, SuperType>::setupIntStream(bool machineBigEndian, bool inputBigEndian)
{
- SuperType* super = this->get_super();
- super->set_charByteSize(4);
+ SuperType* super = this->get_super();
+ super->set_charByteSize(4);
- this->findout_endian_spec(machineBigEndian, inputBigEndian);
+ this->findout_endian_spec(machineBigEndian, inputBigEndian);
}
template<class ImplTraits, class SuperType>
-ANTLR_UINT32 UTF32_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassForwarder<BYTE_AGNOSTIC> )
+ANTLR_UINT32 UTF32_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassForwarder<BYTE_AGNOSTIC> )
{
SuperType* input = this->get_super();
- if (( input->get_nextChar() + la - 1) >= (input->get_data() + input->get_sizeBuf()/4 ))
+ if (( input->get_nextChar() + la - 1) >= (input->get_data() + input->get_sizeBuf()/4 ))
{
- return ANTLR_CHARSTREAM_EOF;
+ return ANTLR_CHARSTREAM_EOF;
}
else
{
- return (ANTLR_UCHAR)(*(input->get_nextChar() + la - 1));
+ return (ANTLR_UCHAR)(*(input->get_nextChar() + la - 1));
}
}
template<class ImplTraits, class SuperType>
-ANTLR_UINT32 UTF32_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassForwarder<ANTLR_LITTLE_ENDIAN> )
+ANTLR_UINT32 UTF32_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassForwarder<ANTLR_LITTLE_ENDIAN> )
{
- SuperType* input = this->get_super();
+ SuperType* input = this->get_super();
- if (( input->get_nextChar() + la - 1) >= (input->get_data() + input->get_sizeBuf()/4 ))
+ if (( input->get_nextChar() + la - 1) >= (input->get_data() + input->get_sizeBuf()/4 ))
{
- return ANTLR_CHARSTREAM_EOF;
+ return ANTLR_CHARSTREAM_EOF;
}
else
{
@@ -1149,13 +1149,13 @@ ANTLR_UINT32 UTF32_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
}
template<class ImplTraits, class SuperType>
-ANTLR_UINT32 UTF32_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassForwarder<ANTLR_BIG_ENDIAN> )
+ANTLR_UINT32 UTF32_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassForwarder<ANTLR_BIG_ENDIAN> )
{
- SuperType* input = this->get_super();
+ SuperType* input = this->get_super();
- if (( input->get_nextChar() + la - 1) >= (input->get_data() + input->get_sizeBuf()/4 ))
+ if (( input->get_nextChar() + la - 1) >= (input->get_data() + input->get_sizeBuf()/4 ))
{
- return ANTLR_CHARSTREAM_EOF;
+ return ANTLR_CHARSTREAM_EOF;
}
else
{
@@ -1170,38 +1170,38 @@ ANTLR_UINT32 UTF32_IntStream<ImplTraits, SuperType>::LA( ANTLR_INT32 la, ClassFo
}
template<class ImplTraits, class SuperType>
-void UTF32_IntStream<ImplTraits, SuperType>::consume()
+void UTF32_IntStream<ImplTraits, SuperType>::consume()
{
- SuperType* input = this->get_super();
+ SuperType* input = this->get_super();
// SizeBuf is always in bytes
//
- if ( input->get_nextChar() < (input->get_data() + input->get_sizeBuf()/4 ))
- {
- /* Indicate one more character in this line
- */
- input->inc_charPositionInLine();
-
- if ((ANTLR_UCHAR)(*(input->get_nextChar())) == input->get_newlineChar())
- {
- /* Reset for start of a new line of input
- */
- input->inc_line();
- input->set_charPositionInLine(0);
- input->set_currentLine( input->get_nextChar() + 1 );
- }
-
- /* Increment to next character position
- */
- input->set_nextChar( input->get_nextChar() + 1 );
+ if ( input->get_nextChar() < (input->get_data() + input->get_sizeBuf()/4 ))
+ {
+ /* Indicate one more character in this line
+ */
+ input->inc_charPositionInLine();
+
+ if ((ANTLR_UCHAR)(*(input->get_nextChar())) == input->get_newlineChar())
+ {
+ /* Reset for start of a new line of input
+ */
+ input->inc_line();
+ input->set_charPositionInLine(0);
+ input->set_currentLine( input->get_nextChar() + 1 );
+ }
+
+ /* Increment to next character position
+ */
+ input->set_nextChar( input->get_nextChar() + 1 );
}
}
template<class ImplTraits, class SuperType>
void UTF8_IntStream<ImplTraits, SuperType>::setupIntStream(bool, bool)
{
- SuperType* super = this->get_super();
- super->set_charByteSize(0);
+ SuperType* super = this->get_super();
+ super->set_charByteSize(0);
}
// ------------------------------------------------------
@@ -1217,18 +1217,18 @@ void UTF8_IntStream<ImplTraits, SuperType>::setupIntStream(bool, bool)
template<class ImplTraits, class SuperType>
const ANTLR_UINT32* UTF8_IntStream<ImplTraits, SuperType>::TrailingBytesForUTF8()
{
- static const ANTLR_UINT32 trailingBytesForUTF8[256] = {
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
- 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
- };
+ static const ANTLR_UINT32 trailingBytesForUTF8[256] = {
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
+ };
- return trailingBytesForUTF8;
+ return trailingBytesForUTF8;
}
/// Magic values subtracted from a buffer value during UTF8 conversion.
@@ -1238,11 +1238,11 @@ const ANTLR_UINT32* UTF8_IntStream<ImplTraits, SuperType>::TrailingBytesForUTF8(
template<class ImplTraits, class SuperType>
const UTF32* UTF8_IntStream<ImplTraits, SuperType>::OffsetsFromUTF8()
{
- static const UTF32 offsetsFromUTF8[6] =
- { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
- 0x03C82080UL, 0xFA082080UL, 0x82082080UL
- };
- return offsetsFromUTF8;
+ static const UTF32 offsetsFromUTF8[6] =
+ { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
+ 0x03C82080UL, 0xFA082080UL, 0x82082080UL
+ };
+ return offsetsFromUTF8;
}
// End of Unicode.org tables
@@ -1257,8 +1257,8 @@ template<class ImplTraits, class SuperType>
void UTF8_IntStream<ImplTraits, SuperType>::consume()
{
SuperType* input = this->get_super();
- const ANTLR_UINT32* trailingBytesForUTF8 = UTF8_IntStream::TrailingBytesForUTF8();
- const UTF32* offsetsFromUTF8 = UTF8_IntStream::OffsetsFromUTF8();
+ const ANTLR_UINT32* trailingBytesForUTF8 = UTF8_IntStream::TrailingBytesForUTF8();
+ const UTF32* offsetsFromUTF8 = UTF8_IntStream::OffsetsFromUTF8();
ANTLR_UINT32 extraBytesToRead;
ANTLR_UCHAR ch;
@@ -1266,17 +1266,17 @@ void UTF8_IntStream<ImplTraits, SuperType>::consume()
nextChar = input->get_nextChar();
- if (nextChar < (input->get_data() + input->get_sizeBuf()))
- {
- // Indicate one more character in this line
- //
- input->inc_charPositionInLine();
-
+ if (nextChar < (input->get_data() + input->get_sizeBuf()))
+ {
+ // Indicate one more character in this line
+ //
+ input->inc_charPositionInLine();
+
// Are there more bytes needed to make up the whole thing?
//
extraBytesToRead = trailingBytesForUTF8[*nextChar];
- if ((nextChar + extraBytesToRead) >= (input->get_data() + input->get_sizeBuf()))
+ if ((nextChar + extraBytesToRead) >= (input->get_data() + input->get_sizeBuf()))
{
input->set_nextChar( input->get_data() + input->get_sizeBuf() );
return;
@@ -1287,27 +1287,27 @@ void UTF8_IntStream<ImplTraits, SuperType>::consume()
// we allow it.
//
ch = 0;
- switch (extraBytesToRead)
- {
- case 5: ch += *nextChar++; ch <<= 6;
- case 4: ch += *nextChar++; ch <<= 6;
- case 3: ch += *nextChar++; ch <<= 6;
- case 2: ch += *nextChar++; ch <<= 6;
- case 1: ch += *nextChar++; ch <<= 6;
- case 0: ch += *nextChar++;
- }
+ switch (extraBytesToRead)
+ {
+ case 5: ch += *nextChar++; ch <<= 6;
+ case 4: ch += *nextChar++; ch <<= 6;
+ case 3: ch += *nextChar++; ch <<= 6;
+ case 2: ch += *nextChar++; ch <<= 6;
+ case 1: ch += *nextChar++; ch <<= 6;
+ case 0: ch += *nextChar++;
+ }
// Magically correct the input value
//
- ch -= offsetsFromUTF8[extraBytesToRead];
- if (ch == input->get_newlineChar())
- {
- /* Reset for start of a new line of input
- */
- input->inc_line();
- input->set_charPositionInLine(0);
- input->set_currentLine(nextChar);
- }
+ ch -= offsetsFromUTF8[extraBytesToRead];
+ if (ch == input->get_newlineChar())
+ {
+ /* Reset for start of a new line of input
+ */
+ input->inc_line();
+ input->set_charPositionInLine(0);
+ input->set_currentLine(nextChar);
+ }
// Update input pointer
//
@@ -1323,11 +1323,11 @@ void UTF8_IntStream<ImplTraits, SuperType>::consume()
* \return Next input character in internal ANTLR3 encoding (UTF32)
*/
template<class ImplTraits, class SuperType>
-ANTLR_UCHAR UTF8_IntStream<ImplTraits, SuperType>::LA(ANTLR_INT32 la)
+ANTLR_UCHAR UTF8_IntStream<ImplTraits, SuperType>::LA(ANTLR_INT32 la)
{
SuperType* input = this->get_super();
- const ANTLR_UINT32* trailingBytesForUTF8 = UTF8_IntStream::TrailingBytesForUTF8();
- const UTF32* offsetsFromUTF8 = UTF8_IntStream::OffsetsFromUTF8();
+ const ANTLR_UINT32* trailingBytesForUTF8 = UTF8_IntStream::TrailingBytesForUTF8();
+ const UTF32* offsetsFromUTF8 = UTF8_IntStream::OffsetsFromUTF8();
ANTLR_UINT32 extraBytesToRead;
ANTLR_UCHAR ch;
ANTLR_UINT8* nextChar;
@@ -1345,8 +1345,8 @@ ANTLR_UCHAR UTF8_IntStream<ImplTraits, SuperType>::LA(ANTLR_INT32 la)
// Make sure that we have at least one character left before trying to
// loop through the buffer.
//
- if (nextChar < (input->get_data() + input->get_sizeBuf()))
- {
+ if (nextChar < (input->get_data() + input->get_sizeBuf()))
+ {
// Now traverse n-1 characters forward
//
while (--la > 0)
@@ -1359,7 +1359,7 @@ ANTLR_UCHAR UTF8_IntStream<ImplTraits, SuperType>::LA(ANTLR_INT32 la)
// Does that calculation take us past the byte length of the buffer?
//
- if (nextChar >= (input->get_data() + input->get_sizeBuf()))
+ if (nextChar >= (input->get_data() + input->get_sizeBuf()))
{
return ANTLR_CHARSTREAM_EOF;
}
@@ -1396,16 +1396,16 @@ ANTLR_UCHAR UTF8_IntStream<ImplTraits, SuperType>::LA(ANTLR_INT32 la)
// Are there more bytes needed to make up the whole thing?
//
extraBytesToRead = trailingBytesForUTF8[*nextChar];
- if (nextChar + extraBytesToRead >= (input->get_data() + input->get_sizeBuf()))
+ if (nextChar + extraBytesToRead >= (input->get_data() + input->get_sizeBuf()))
{
return ANTLR_CHARSTREAM_EOF;
}
// Cases deliberately fall through (see note A in antlrconvertutf.c)
- //
+ //
ch = 0;
- switch (extraBytesToRead)
- {
+ switch (extraBytesToRead)
+ {
case 5: ch += *nextChar++; ch <<= 6;
case 4: ch += *nextChar++; ch <<= 6;
case 3: ch += *nextChar++; ch <<= 6;
@@ -1424,19 +1424,19 @@ ANTLR_UCHAR UTF8_IntStream<ImplTraits, SuperType>::LA(ANTLR_INT32 la)
template<class ImplTraits>
TokenIntStream<ImplTraits>::TokenIntStream()
{
- m_cachedSize = 0;
+ m_cachedSize = 0;
}
template<class ImplTraits>
ANTLR_UINT32 TokenIntStream<ImplTraits>::get_cachedSize() const
{
- return m_cachedSize;
+ return m_cachedSize;
}
template<class ImplTraits>
void TokenIntStream<ImplTraits>::set_cachedSize( ANTLR_UINT32 cachedSize )
{
- m_cachedSize = cachedSize;
+ m_cachedSize = cachedSize;
}
/** Move the input pointer to the next incoming token. The stream
@@ -1449,54 +1449,54 @@ void TokenIntStream<ImplTraits>::set_cachedSize( ANTLR_UINT32 cachedSize )
template<class ImplTraits>
void TokenIntStream<ImplTraits>::consume()
{
- TokenStreamType* cts = static_cast<TokenStreamType*>(this);
+ TokenStreamType* cts = static_cast<TokenStreamType*>(this);
if((ANTLR_UINT32)cts->get_p() < m_cachedSize )
- {
- cts->inc_p();
- cts->set_p( cts->skipOffTokenChannels(cts->get_p()) );
- }
+ {
+ cts->inc_p();
+ cts->set_p( cts->skipOffTokenChannels(cts->get_p()) );
+ }
}
template<class ImplTraits>
void TokenIntStream<ImplTraits>::consumeInitialHiddenTokens()
{
- ANTLR_MARKER first;
- ANTLR_INT32 i;
- TokenStreamType* ts;
+ ANTLR_MARKER first;
+ ANTLR_INT32 i;
+ TokenStreamType* ts;
- ts = this->get_super();
- first = this->index();
+ ts = this->get_super();
+ first = this->index();
- for (i=0; i<first; i++)
- {
- ts->get_debugger()->consumeHiddenToken(ts->get(i));
- }
+ for (i=0; i<first; i++)
+ {
+ ts->get_debugger()->consumeHiddenToken(ts->get(i));
+ }
- ts->set_initialStreamState(false);
+ ts->set_initialStreamState(false);
}
template<class ImplTraits>
-ANTLR_UINT32 TokenIntStream<ImplTraits>::LA( ANTLR_INT32 i )
+ANTLR_UINT32 TokenIntStream<ImplTraits>::LA( ANTLR_INT32 i )
{
- const CommonTokenType* tok;
- TokenStreamType* ts = static_cast<TokenStreamType*>(this);
+ const CommonTokenType* tok;
+ TokenStreamType* ts = static_cast<TokenStreamType*>(this);
- tok = ts->LT(i);
+ tok = ts->LT(i);
- if (tok != NULL)
- {
- return tok->get_type();
- }
- else
- {
- return CommonTokenType::TOKEN_INVALID;
- }
+ if (tok != NULL)
+ {
+ return tok->get_type();
+ }
+ else
+ {
+ return CommonTokenType::TOKEN_INVALID;
+ }
}
template<class ImplTraits>
-ANTLR_MARKER TokenIntStream<ImplTraits>::mark()
+ANTLR_MARKER TokenIntStream<ImplTraits>::mark()
{
BaseType::m_lastMarker = this->index();
return BaseType::m_lastMarker;
@@ -1507,7 +1507,7 @@ ANTLR_UINT32 TokenIntStream<ImplTraits>::size()
{
if (this->get_cachedSize() > 0)
{
- return this->get_cachedSize();
+ return this->get_cachedSize();
}
TokenStreamType* cts = this->get_super();
@@ -1516,7 +1516,7 @@ ANTLR_UINT32 TokenIntStream<ImplTraits>::size()
}
template<class ImplTraits>
-void TokenIntStream<ImplTraits>::release()
+void TokenIntStream<ImplTraits>::release()
{
return;
}
@@ -1524,23 +1524,23 @@ void TokenIntStream<ImplTraits>::release()
template<class ImplTraits>
ANTLR_MARKER TokenIntStream<ImplTraits>::tindex()
{
- return this->get_super()->get_p();
+ return this->get_super()->get_p();
}
template<class ImplTraits>
-void TokenIntStream<ImplTraits>::rewindLast()
+void TokenIntStream<ImplTraits>::rewindLast()
{
this->rewind( this->get_lastMarker() );
}
template<class ImplTraits>
-void TokenIntStream<ImplTraits>::rewind(ANTLR_MARKER marker)
+void TokenIntStream<ImplTraits>::rewind(ANTLR_MARKER marker)
{
- return this->seek(marker);
+ return this->seek(marker);
}
template<class ImplTraits>
-void TokenIntStream<ImplTraits>::seek(ANTLR_MARKER index)
+void TokenIntStream<ImplTraits>::seek(ANTLR_MARKER index)
{
TokenStreamType* cts = static_cast<TokenStreamType*>(this);
@@ -1552,75 +1552,75 @@ void TokenIntStream<ImplTraits>::seek(ANTLR_MARKER index)
///
/// /param[in] is The ANTLR3_INT_STREAM interface that is representing this token stream.
///
-/// /returns
+/// /returns
/// /implements ANTLR3_INT_STREAM_struct::getSourceName()
///
template<class ImplTraits>
typename TokenIntStream<ImplTraits>::StringType
TokenIntStream<ImplTraits>::getSourceName()
{
- // Slightly convoluted as we must trace back to the lexer's input source
- // via the token source. The streamName that is here is not initialized
- // because this is a token stream, not a file or string stream, which are the
- // only things that have a context for a source name.
- //
- return this->get_super()->get_tokenSource()->get_fileName();
+ // Slightly convoluted as we must trace back to the lexer's input source
+ // via the token source. The streamName that is here is not initialized
+ // because this is a token stream, not a file or string stream, which are the
+ // only things that have a context for a source name.
+ //
+ return this->get_super()->get_tokenSource()->get_fileName();
}
template<class ImplTraits>
void TreeNodeIntStream<ImplTraits>::consume()
{
- TreeNodeStreamType* ctns = this->get_super();
- if( ctns->get_p() == -1 )
- ctns->fillBufferRoot();
- ctns->inc_p();
+ TreeNodeStreamType* ctns = this->get_super();
+ if( ctns->get_p() == -1 )
+ ctns->fillBufferRoot();
+ ctns->inc_p();
}
template<class ImplTraits>
-ANTLR_MARKER TreeNodeIntStream<ImplTraits>::tindex()
+ANTLR_MARKER TreeNodeIntStream<ImplTraits>::tindex()
{
- TreeNodeStreamType* ctns = this->get_super();
- return (ANTLR_MARKER)(ctns->get_p());
+ TreeNodeStreamType* ctns = this->get_super();
+ return (ANTLR_MARKER)(ctns->get_p());
}
template<class ImplTraits>
-ANTLR_UINT32 TreeNodeIntStream<ImplTraits>::LA(ANTLR_INT32 i)
+ANTLR_UINT32 TreeNodeIntStream<ImplTraits>::LA(ANTLR_INT32 i)
{
- TreeNodeStreamType* tns = this->get_super();
+ TreeNodeStreamType* tns = this->get_super();
- // Ask LT for the 'token' at that position
- //
- TreeTypePtr t = tns->LT(i);
+ // Ask LT for the 'token' at that position
+ //
+ TreeTypePtr t = tns->LT(i);
- if (t == NULL)
- {
- return CommonTokenType::TOKEN_INVALID;
- }
+ if (t == NULL)
+ {
+ return CommonTokenType::TOKEN_INVALID;
+ }
- // Token node was there so return the type of it
- //
- return t->get_type();
+ // Token node was there so return the type of it
+ //
+ return t->get_type();
}
template<class ImplTraits>
-ANTLR_MARKER TreeNodeIntStream<ImplTraits>::mark()
+ANTLR_MARKER TreeNodeIntStream<ImplTraits>::mark()
{
- TreeNodeStreamType* ctns = this->get_super();
-
- if (ctns->get_p() == -1)
- {
- ctns->fillBufferRoot();
- }
+ TreeNodeStreamType* ctns = this->get_super();
+
+ if (ctns->get_p() == -1)
+ {
+ ctns->fillBufferRoot();
+ }
- // Return the current mark point
- //
- this->set_lastMarker( this->index() );
+ // Return the current mark point
+ //
+ this->set_lastMarker( this->index() );
- return this->get_lastMarker();
+ return this->get_lastMarker();
}
template<class ImplTraits>
-void TreeNodeIntStream<ImplTraits>::release(ANTLR_MARKER /*marker*/)
+void TreeNodeIntStream<ImplTraits>::release(ANTLR_MARKER /*marker*/)
{
}
@@ -1628,34 +1628,34 @@ void TreeNodeIntStream<ImplTraits>::release(ANTLR_MARKER /*marker*/)
template<class ImplTraits>
void TreeNodeIntStream<ImplTraits>::rewindMark(ANTLR_MARKER marker)
{
- this->seek(marker);
+ this->seek(marker);
}
template<class ImplTraits>
void TreeNodeIntStream<ImplTraits>::rewindLast()
{
- this->seek( this->get_lastMarker() );
+ this->seek( this->get_lastMarker() );
}
template<class ImplTraits>
-void TreeNodeIntStream<ImplTraits>::seek(ANTLR_MARKER index)
+void TreeNodeIntStream<ImplTraits>::seek(ANTLR_MARKER index)
{
- TreeNodeStreamType* ctns = this->get_super();
- ctns->set_p( ANTLR_UINT32_CAST(index) );
+ TreeNodeStreamType* ctns = this->get_super();
+ ctns->set_p( ANTLR_UINT32_CAST(index) );
}
template<class ImplTraits>
-ANTLR_UINT32 TreeNodeIntStream<ImplTraits>::size()
+ANTLR_UINT32 TreeNodeIntStream<ImplTraits>::size()
{
- TreeNodeStreamType* ctns = this->get_super();
-
- if (ctns->get_p() == -1)
- {
- ctns->fillBufferRoot();
- }
+ TreeNodeStreamType* ctns = this->get_super();
+
+ if (ctns->get_p() == -1)
+ {
+ ctns->fillBufferRoot();
+ }
- return ctns->get_nodes().size();
+ return ctns->get_nodes().size();
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3lexer.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3lexer.hpp
index 213dff6010..d23e65dea0 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3lexer.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3lexer.hpp
@@ -27,8 +27,8 @@
* - When a next token is called, let ze lexing begin.
*
*/
-#ifndef _ANTLR3_LEXER_HPP
-#define _ANTLR3_LEXER_HPP
+#ifndef _ANTLR3_LEXER_HPP
+#define _ANTLR3_LEXER_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -61,31 +61,31 @@
/* Definitions
*/
-namespace antlr3 {
+namespace antlr3 {
-static const ANTLR_UINT32 ANTLR_STRING_TERMINATOR = 0xFFFFFFFF;
+static const ANTLR_UINT32 ANTLR_STRING_TERMINATOR = 0xFFFFFFFF;
template<class ImplTraits>
class Lexer : public ImplTraits::template RecognizerType< typename ImplTraits::InputStreamType >,
- public ImplTraits::TokenSourceType
+ public ImplTraits::TokenSourceType
{
public:
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename ImplTraits::InputStreamType InputStreamType;
- typedef InputStreamType StreamType;
- typedef typename InputStreamType::IntStreamType IntStreamType;
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
- typedef typename ImplTraits::StreamDataType TokenType;
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::StringStreamType StringStreamType;
- typedef typename ImplTraits::template RecognizerType< InputStreamType > RecognizerType;
- typedef typename RecognizerType::RecognizerSharedStateType RecognizerSharedStateType;
- typedef typename ImplTraits::template ExceptionBaseType<InputStreamType> ExceptionBaseType;
- typedef typename ImplTraits::BitsetListType BitsetListType;
- typedef typename ImplTraits::TokenSourceType TokenSourceType;
-
- typedef typename RecognizerSharedStateType::RuleMemoType RuleMemoType;
- typedef typename RecognizerType::DebugEventListenerType DebuggerType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::InputStreamType InputStreamType;
+ typedef InputStreamType StreamType;
+ typedef typename InputStreamType::IntStreamType IntStreamType;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
+ typedef typename ImplTraits::StreamDataType TokenType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::StringStreamType StringStreamType;
+ typedef typename ImplTraits::template RecognizerType< InputStreamType > RecognizerType;
+ typedef typename RecognizerType::RecognizerSharedStateType RecognizerSharedStateType;
+ typedef typename ImplTraits::template ExceptionBaseType<InputStreamType> ExceptionBaseType;
+ typedef typename ImplTraits::BitsetListType BitsetListType;
+ typedef typename ImplTraits::TokenSourceType TokenSourceType;
+
+ typedef typename RecognizerSharedStateType::RuleMemoType RuleMemoType;
+ typedef typename RecognizerType::DebugEventListenerType DebuggerType;
private:
/** A pointer to the character stream whence this lexer is receiving
@@ -93,154 +93,154 @@ private:
* TODO: I may come back to this and implement charstream outside
* the input stream as per the java implementation.
*/
- InputStreamType* m_input;
+ InputStreamType* m_input;
public:
- Lexer(ANTLR_UINT32 sizeHint, RecognizerSharedStateType* state);
- Lexer(ANTLR_UINT32 sizeHint, InputStreamType* input, RecognizerSharedStateType* state);
-
- InputStreamType* get_input() const;
- IntStreamType* get_istream() const;
- RecognizerType* get_rec();
- const RecognizerType* get_rec() const;
- TokenSourceType* get_tokSource();
-
- //functions used in .stg file
- const RecognizerType* get_recognizer() const;
- RecognizerSharedStateType* get_lexstate() const;
- void set_lexstate( RecognizerSharedStateType* lexstate );
- const TokenSourceType* get_tokSource() const;
- CommonTokenType* get_ltoken() const;
- void set_ltoken( const CommonTokenType* ltoken );
- bool hasFailed() const;
- ANTLR_INT32 get_backtracking() const;
- void inc_backtracking();
- void dec_backtracking();
- bool get_failedflag() const;
- void set_failedflag( bool failed );
- InputStreamType* get_strstream() const;
- ANTLR_MARKER index() const;
- void seek(ANTLR_MARKER index);
- const CommonTokenType* EOF_Token() const;
- bool hasException() const;
- ExceptionBaseType* get_exception() const;
- void constructEx();
- void lrecover();
- ANTLR_MARKER mark();
- void rewind(ANTLR_MARKER marker);
- void rewindLast();
- void setText( const StringType& text );
- void skip();
- RuleMemoType* getRuleMemo() const;
- DebuggerType* get_debugger() const;
- void setRuleMemo(RuleMemoType* rulememo);
- ANTLR_UINT32 LA(ANTLR_INT32 i);
- void consume();
- void memoize(ANTLR_MARKER ruleIndex, ANTLR_MARKER ruleParseStart);
- bool haveParsedRule(ANTLR_MARKER ruleIndex);
+ Lexer(ANTLR_UINT32 sizeHint, RecognizerSharedStateType* state);
+ Lexer(ANTLR_UINT32 sizeHint, InputStreamType* input, RecognizerSharedStateType* state);
+
+ InputStreamType* get_input() const;
+ IntStreamType* get_istream() const;
+ RecognizerType* get_rec();
+ const RecognizerType* get_rec() const;
+ TokenSourceType* get_tokSource();
+
+ //functions used in .stg file
+ const RecognizerType* get_recognizer() const;
+ RecognizerSharedStateType* get_lexstate() const;
+ void set_lexstate( RecognizerSharedStateType* lexstate );
+ const TokenSourceType* get_tokSource() const;
+ CommonTokenType* get_ltoken() const;
+ void set_ltoken( const CommonTokenType* ltoken );
+ bool hasFailed() const;
+ ANTLR_INT32 get_backtracking() const;
+ void inc_backtracking();
+ void dec_backtracking();
+ bool get_failedflag() const;
+ void set_failedflag( bool failed );
+ InputStreamType* get_strstream() const;
+ ANTLR_MARKER index() const;
+ void seek(ANTLR_MARKER index);
+ const CommonTokenType* EOF_Token() const;
+ bool hasException() const;
+ ExceptionBaseType* get_exception() const;
+ void constructEx();
+ void lrecover();
+ ANTLR_MARKER mark();
+ void rewind(ANTLR_MARKER marker);
+ void rewindLast();
+ void setText( const StringType& text );
+ void skip();
+ RuleMemoType* getRuleMemo() const;
+ DebuggerType* get_debugger() const;
+ void setRuleMemo(RuleMemoType* rulememo);
+ ANTLR_UINT32 LA(ANTLR_INT32 i);
+ void consume();
+ void memoize(ANTLR_MARKER ruleIndex, ANTLR_MARKER ruleParseStart);
+ bool haveParsedRule(ANTLR_MARKER ruleIndex);
/** Pointer to a function that sets the charstream source for the lexer and
* causes it to be reset.
*/
- void setCharStream(InputStreamType* input);
+ void setCharStream(InputStreamType* input);
/*!
- * \brief
- * Change to a new input stream, remembering the old one.
- *
- * \param lexer
- * Pointer to the lexer instance to switch input streams for.
- *
- * \param input
- * New input stream to install as the current one.
- *
- * Switches the current character input stream to
- * a new one, saving the old one, which we will revert to at the end of this
- * new one.
- */
- void pushCharStream(InputStreamType* input);
-
- /*!
- * \brief
- * Stops using the current input stream and reverts to any prior
- * input stream on the stack.
- *
- * \param lexer
- * Description of parameter lexer.
- *
- * Pointer to a function that abandons the current input stream, whether it
- * is empty or not and reverts to the previous stacked input stream.
- *
- * \remark
- * The function fails silently if there are no prior input streams.
- */
- void popCharStream();
+ * \brief
+ * Change to a new input stream, remembering the old one.
+ *
+ * \param lexer
+ * Pointer to the lexer instance to switch input streams for.
+ *
+ * \param input
+ * New input stream to install as the current one.
+ *
+ * Switches the current character input stream to
+ * a new one, saving the old one, which we will revert to at the end of this
+ * new one.
+ */
+ void pushCharStream(InputStreamType* input);
+
+ /*!
+ * \brief
+ * Stops using the current input stream and reverts to any prior
+ * input stream on the stack.
+ *
+ * \param lexer
+ * Description of parameter lexer.
+ *
+ * Pointer to a function that abandons the current input stream, whether it
+ * is empty or not and reverts to the previous stacked input stream.
+ *
+ * \remark
+ * The function fails silently if there are no prior input streams.
+ */
+ void popCharStream();
/** Function that emits (a copy of ) the supplied token as the next token in
* the stream.
*/
- void emit(const CommonTokenType* token);
+ void emit(const CommonTokenType* token);
/** Pointer to a function that constructs a new token from the lexer stored information
*/
- CommonTokenType* emit();
+ CommonTokenType* emit();
/** Pointer to a function that attempts to match and consume the specified string from the input
* stream. Note that strings muse be passed as terminated arrays of ANTLR3_UCHAR. Strings are terminated
* with 0xFFFFFFFF, which is an invalid UTF32 character
*/
- bool matchs(ANTLR_UCHAR* string);
+ bool matchs(ANTLR_UCHAR* string);
/** Pointer to a function that matches and consumes the specified character from the input stream.
* The input stream is required to provide characters via LA() as UTF32 characters. The default lexer
* implementation is source encoding agnostic and so input streams do not generally need to
* override the default implmentation.
*/
- bool matchc(ANTLR_UCHAR c);
+ bool matchc(ANTLR_UCHAR c);
/** Pointer to a function that matches any character in the supplied range (I suppose it could be a token range too
* but this would only be useful if the tokens were in tsome guaranteed order which is
* only going to happen with a hand crafted token set).
*/
- bool matchRange(ANTLR_UCHAR low, ANTLR_UCHAR high);
+ bool matchRange(ANTLR_UCHAR low, ANTLR_UCHAR high);
/** Pointer to a function that matches the next token/char in the input stream
* regardless of what it actaully is.
*/
- void matchAny();
+ void matchAny();
/** Pointer to a function that recovers from an error found in the input stream.
* Generally, this will be a #ANTLR3_EXCEPTION_NOVIABLE_ALT but it could also
* be from a mismatched token that the (*match)() could not recover from.
*/
- void recover();
+ void recover();
/** Function to return the current line number in the input stream
*/
- ANTLR_UINT32 getLine();
- ANTLR_MARKER getCharIndex();
- ANTLR_UINT32 getCharPositionInLine();
+ ANTLR_UINT32 getLine();
+ ANTLR_MARKER getCharIndex();
+ ANTLR_UINT32 getCharPositionInLine();
/** Function to return the text so far for the current token being generated
*/
- StringType getText();
+ StringType getText();
- //Other utility functions
- void fillExceptionData( ExceptionBaseType* ex );
+ //Other utility functions
+ void fillExceptionData( ExceptionBaseType* ex );
- /** Default lexer error handler (works for 8 bit streams only!!!)
- */
- void displayRecognitionError( ANTLR_UINT8** tokenNames, ExceptionBaseType* ex);
- void exConstruct();
- TokenType* getMissingSymbol( IntStreamType* istream, ExceptionBaseType* e,
- ANTLR_UINT32 expectedTokenType, BitsetListType* follow);
+ /** Default lexer error handler (works for 8 bit streams only!!!)
+ */
+ void displayRecognitionError( ANTLR_UINT8** tokenNames, ExceptionBaseType* ex);
+ void exConstruct();
+ TokenType* getMissingSymbol( IntStreamType* istream, ExceptionBaseType* e,
+ ANTLR_UINT32 expectedTokenType, BitsetListType* follow);
/** Pointer to a function that knows how to free the resources of a lexer
*/
- ~Lexer();
+ ~Lexer();
};
-}
+}
#include "antlr3lexer.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3lexer.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3lexer.inl
index 32984bef68..bf6960569f 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3lexer.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3lexer.inl
@@ -1,134 +1,134 @@
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits>
Lexer<ImplTraits>::Lexer(ANTLR_UINT32 sizeHint, RecognizerSharedStateType* state)
- :Lexer<ImplTraits>::RecognizerType(sizeHint, state)
- ,m_input(NULL)
+ :Lexer<ImplTraits>::RecognizerType(sizeHint, state)
+ ,m_input(NULL)
{
}
template<class ImplTraits>
Lexer<ImplTraits>::Lexer(ANTLR_UINT32 sizeHint, InputStreamType* input, RecognizerSharedStateType* state)
- :Lexer<ImplTraits>::RecognizerType(sizeHint, state)
+ :Lexer<ImplTraits>::RecognizerType(sizeHint, state)
{
- this->setCharStream(input);
+ this->setCharStream(input);
}
template<class ImplTraits>
typename Lexer<ImplTraits>::InputStreamType* Lexer<ImplTraits>::get_input() const
{
- return m_input;
+ return m_input;
}
template<class ImplTraits>
typename Lexer<ImplTraits>::IntStreamType* Lexer<ImplTraits>::get_istream() const
{
- return m_input;
+ return m_input;
}
template<class ImplTraits>
typename Lexer<ImplTraits>::RecognizerType* Lexer<ImplTraits>::get_rec()
{
- return this;
+ return this;
}
template<class ImplTraits>
typename Lexer<ImplTraits>::TokenSourceType* Lexer<ImplTraits>::get_tokSource()
{
- return this;
+ return this;
}
template<class ImplTraits>
void Lexer<ImplTraits>::displayRecognitionError( ANTLR_UINT8** , ExceptionBaseType* ex)
{
- StringStreamType err_stream;
+ StringStreamType err_stream;
- // See if there is a 'filename' we can use
+ // See if there is a 'filename' we can use
//
if( ex->getName().empty() )
{
- err_stream << "-unknown source-(";
+ err_stream << "-unknown source-(";
}
else
{
- err_stream << ex->get_streamName().c_str();
- err_stream << "(";
+ err_stream << ex->get_streamName().c_str();
+ err_stream << "(";
}
err_stream << ex->get_line() << ")";
- err_stream << ": lexer error " << ex->getName() << '(' << ex->getType() << ')' << " :\n\t"
- << ex->get_message() << " at position [" << ex->get_line() << ", "
- << ex->get_charPositionInLine()+1 << "], ";
-
- {
- ANTLR_UINT32 width;
-
- width = ANTLR_UINT32_CAST(( (ANTLR_UINT8*)(m_input->get_data()) +
- (m_input->size() )) - (ANTLR_UINT8*)( ex->get_index() ));
-
- if (width >= 1)
- {
- if (isprint(ex->get_c() ))
- {
- err_stream << "near '" << (typename StringType::value_type) ex->get_c() << "' :\n";
- }
- else
- {
- err_stream << "near char(" << std::hex << ex->get_c() << std::dec << ") :\n";
- }
- err_stream << "\t";
- err_stream.width( width > 20 ? 20 : width );
- err_stream << (typename StringType::const_pointer)ex->get_index() << "\n";
- }
- else
- {
- err_stream << "(end of input).\n\t This indicates a poorly specified lexer RULE\n\t or unterminated input element such as: \"STRING[\"]\n";
- err_stream << "\t The lexer was matching from line "
- << this->get_state()->get_tokenStartLine()
- << ", offset " << this->get_state()->get_tokenStartCharPositionInLine()
- << ", which\n\t ";
- width = ANTLR_UINT32_CAST(((ANTLR_UINT8*)(m_input->get_data() )+
- (m_input->size())) -
- (ANTLR_UINT8*)(this->get_state()->get_tokenStartCharIndex() ));
-
- if (width >= 1)
- {
- err_stream << "looks like this:\n\t\t";
- err_stream.width( width > 20 ? 20 : width );
- err_stream << (typename StringType::const_pointer)this->get_state()->get_tokenStartCharIndex() << "\n";
- }
- else
- {
- err_stream << "is also the end of the line, so you must check your lexer rules\n";
- }
- }
- }
- ImplTraits::displayRecognitionError( err_stream.str() );
+ err_stream << ": lexer error " << ex->getName() << '(' << ex->getType() << ')' << " :\n\t"
+ << ex->get_message() << " at position [" << ex->get_line() << ", "
+ << ex->get_charPositionInLine()+1 << "], ";
+
+ {
+ ANTLR_UINT32 width;
+
+ width = ANTLR_UINT32_CAST(( (ANTLR_UINT8*)(m_input->get_data()) +
+ (m_input->size() )) - (ANTLR_UINT8*)( ex->get_index() ));
+
+ if (width >= 1)
+ {
+ if (isprint(ex->get_c() ))
+ {
+ err_stream << "near '" << (typename StringType::value_type) ex->get_c() << "' :\n";
+ }
+ else
+ {
+ err_stream << "near char(" << std::hex << ex->get_c() << std::dec << ") :\n";
+ }
+ err_stream << "\t";
+ err_stream.width( width > 20 ? 20 : width );
+ err_stream << (typename StringType::const_pointer)ex->get_index() << "\n";
+ }
+ else
+ {
+ err_stream << "(end of input).\n\t This indicates a poorly specified lexer RULE\n\t or unterminated input element such as: \"STRING[\"]\n";
+ err_stream << "\t The lexer was matching from line "
+ << this->get_state()->get_tokenStartLine()
+ << ", offset " << this->get_state()->get_tokenStartCharPositionInLine()
+ << ", which\n\t ";
+ width = ANTLR_UINT32_CAST(((ANTLR_UINT8*)(m_input->get_data() )+
+ (m_input->size())) -
+ (ANTLR_UINT8*)(this->get_state()->get_tokenStartCharIndex() ));
+
+ if (width >= 1)
+ {
+ err_stream << "looks like this:\n\t\t";
+ err_stream.width( width > 20 ? 20 : width );
+ err_stream << (typename StringType::const_pointer)this->get_state()->get_tokenStartCharIndex() << "\n";
+ }
+ else
+ {
+ err_stream << "is also the end of the line, so you must check your lexer rules\n";
+ }
+ }
+ }
+ ImplTraits::displayRecognitionError( err_stream.str() );
}
template<class ImplTraits>
void Lexer<ImplTraits>::fillExceptionData( ExceptionBaseType* ex )
{
- ex->set_c( m_input->LA(1) ); /* Current input character */
- ex->set_line( m_input->get_line() ); /* Line number comes from stream */
- ex->set_charPositionInLine( m_input->get_charPositionInLine() ); /* Line offset also comes from the stream */
- ex->set_index( m_input->index() );
- ex->set_streamName( m_input->get_fileName() );
- ex->set_message( "Unexpected character" );
+ ex->set_c( m_input->LA(1) ); /* Current input character */
+ ex->set_line( m_input->get_line() ); /* Line number comes from stream */
+ ex->set_charPositionInLine( m_input->get_charPositionInLine() ); /* Line offset also comes from the stream */
+ ex->set_index( m_input->index() );
+ ex->set_streamName( m_input->get_fileName() );
+ ex->set_message( "Unexpected character" );
}
template<class ImplTraits>
-void Lexer<ImplTraits>::setCharStream(InputStreamType* input)
+void Lexer<ImplTraits>::setCharStream(InputStreamType* input)
{
/* Install the input interface
*/
- m_input = input;
+ m_input = input;
/* Set the current token to nothing
*/
- RecognizerSharedStateType* state = this->get_rec()->get_state();
+ RecognizerSharedStateType* state = this->get_rec()->get_state();
state->set_token_present( false );
- state->set_text("");
+ state->set_text("");
state->set_tokenStartCharIndex(-1);
/* Copy the name of the char stream to the token source
@@ -137,65 +137,65 @@ void Lexer<ImplTraits>::setCharStream(InputStreamType* input)
}
template<class ImplTraits>
-void Lexer<ImplTraits>::pushCharStream(InputStreamType* input)
+void Lexer<ImplTraits>::pushCharStream(InputStreamType* input)
{
- // We have a stack, so we can save the current input stream
- // into it.
- //
- this->get_istream()->mark();
- this->get_rec()->get_state()->get_streams().push(this->get_input());
+ // We have a stack, so we can save the current input stream
+ // into it.
+ //
+ this->get_istream()->mark();
+ this->get_rec()->get_state()->get_streams().push(this->get_input());
- // And now we can install this new one
- //
- this->setCharStream(input);
+ // And now we can install this new one
+ //
+ this->setCharStream(input);
}
template<class ImplTraits>
-void Lexer<ImplTraits>::popCharStream()
+void Lexer<ImplTraits>::popCharStream()
{
- InputStreamType* input;
+ InputStreamType* input;
// If we do not have a stream stack or we are already at the
// stack bottom, then do nothing.
//
typename RecognizerSharedStateType::StreamsType& streams = this->get_rec()->get_state()->get_streams();
- if ( streams.size() > 0)
+ if ( streams.size() > 0)
{
- // We just leave the current stream to its fate, we do not close
- // it or anything as we do not know what the programmer intended
- // for it. This method can always be overridden of course.
- // So just find out what was currently saved on the stack and use
- // that now, then pop it from the stack.
- //
- input = streams.top();
- streams.pop();
-
- // Now install the stream as the current one.
- //
- this->setCharStream(input);
- this->get_istream()->rewindLast();
+ // We just leave the current stream to its fate, we do not close
+ // it or anything as we do not know what the programmer intended
+ // for it. This method can always be overridden of course.
+ // So just find out what was currently saved on the stack and use
+ // that now, then pop it from the stack.
+ //
+ input = streams.top();
+ streams.pop();
+
+ // Now install the stream as the current one.
+ //
+ this->setCharStream(input);
+ this->get_istream()->rewindLast();
}
return;
}
template<class ImplTraits>
-void Lexer<ImplTraits>::emit(const CommonTokenType* token)
+void Lexer<ImplTraits>::emit(const CommonTokenType* token)
{
- this->get_rec()->get_state()->set_token(token);
+ this->get_rec()->get_state()->set_token(token);
}
template<class ImplTraits>
-typename Lexer<ImplTraits>::CommonTokenType* Lexer<ImplTraits>::emit()
+typename Lexer<ImplTraits>::CommonTokenType* Lexer<ImplTraits>::emit()
{
- /* We could check pointers to token factories and so on, but
+ /* We could check pointers to token factories and so on, but
* we are in code that we want to run as fast as possible
* so we are not checking any errors. So make sure you have installed an input stream before
* trying to emit a new token.
*/
- RecognizerSharedStateType* state = this->get_rec()->get_state();
- state->set_token_present(true);
+ RecognizerSharedStateType* state = this->get_rec()->get_state();
+ state->set_token_present(true);
CommonTokenType* token = state->get_token();
- token->set_input( this->get_input() );
+ token->set_input( this->get_input() );
/* Install the supplied information, and some other bits we already know
* get added automatically, such as the input stream it is associated with
@@ -208,7 +208,7 @@ typename Lexer<ImplTraits>::CommonTokenType* Lexer<ImplTraits>::emit()
token->set_line( state->get_tokenStartLine() );
token->set_charPositionInLine( state->get_tokenStartCharPositionInLine() );
- token->set_tokText( state->get_text() );
+ token->set_tokText( state->get_text() );
token->set_lineStart( this->get_input()->get_currentLine() );
return token;
@@ -217,114 +217,114 @@ typename Lexer<ImplTraits>::CommonTokenType* Lexer<ImplTraits>::emit()
template<class ImplTraits>
Lexer<ImplTraits>::~Lexer()
{
- // This may have ben a delegate or delegator lexer, in which case the
- // state may already have been freed (and set to NULL therefore)
- // so we ignore the state if we don't have it.
- //
- RecognizerSharedStateType* state = this->get_rec()->get_state();
+ // This may have ben a delegate or delegator lexer, in which case the
+ // state may already have been freed (and set to NULL therefore)
+ // so we ignore the state if we don't have it.
+ //
+ RecognizerSharedStateType* state = this->get_rec()->get_state();
- if ( state != NULL)
- {
- state->get_streams().clear();
- }
+ if ( state != NULL)
+ {
+ state->get_streams().clear();
+ }
}
template<class ImplTraits>
-bool Lexer<ImplTraits>::matchs(ANTLR_UCHAR* str )
-{
- RecognizerSharedStateType* state = this->get_rec()->get_state();
- while (*str != ANTLR_STRING_TERMINATOR)
- {
- if ( this->get_istream()->LA(1) != (*str))
- {
- if ( state->get_backtracking() > 0)
- {
- state->set_failed(true);
- return false;
- }
-
- this->exConstruct();
- state->set_failed( true );
-
- /* TODO: Implement exception creation more fully perhaps
- */
- this->recover();
- return false;
- }
-
- /* Matched correctly, do consume it
- */
- this->get_istream()->consume();
- str++;
-
- }
- /* Reset any failed indicator
- */
- state->set_failed( false );
- return true;
+bool Lexer<ImplTraits>::matchs(ANTLR_UCHAR* str )
+{
+ RecognizerSharedStateType* state = this->get_rec()->get_state();
+ while (*str != ANTLR_STRING_TERMINATOR)
+ {
+ if ( this->get_istream()->LA(1) != (*str))
+ {
+ if ( state->get_backtracking() > 0)
+ {
+ state->set_failed(true);
+ return false;
+ }
+
+ this->exConstruct();
+ state->set_failed( true );
+
+ /* TODO: Implement exception creation more fully perhaps
+ */
+ this->recover();
+ return false;
+ }
+
+ /* Matched correctly, do consume it
+ */
+ this->get_istream()->consume();
+ str++;
+
+ }
+ /* Reset any failed indicator
+ */
+ state->set_failed( false );
+ return true;
}
template<class ImplTraits>
-bool Lexer<ImplTraits>::matchc(ANTLR_UCHAR c)
+bool Lexer<ImplTraits>::matchc(ANTLR_UCHAR c)
{
- if (this->get_istream()->LA(1) == c)
- {
- /* Matched correctly, do consume it
- */
- this->get_istream()->consume();
+ if (this->get_istream()->LA(1) == c)
+ {
+ /* Matched correctly, do consume it
+ */
+ this->get_istream()->consume();
- /* Reset any failed indicator
- */
- this->get_rec()->get_state()->set_failed( false );
+ /* Reset any failed indicator
+ */
+ this->get_rec()->get_state()->set_failed( false );
- return true;
- }
+ return true;
+ }
- /* Failed to match, exception and recovery time.
- */
- if(this->get_rec()->get_state()->get_backtracking() > 0)
- {
- this->get_rec()->get_state()->set_failed( true );
- return false;
- }
+ /* Failed to match, exception and recovery time.
+ */
+ if(this->get_rec()->get_state()->get_backtracking() > 0)
+ {
+ this->get_rec()->get_state()->set_failed( true );
+ return false;
+ }
- this->exConstruct();
+ this->exConstruct();
- /* TODO: Implement exception creation more fully perhaps
- */
- this->recover();
+ /* TODO: Implement exception creation more fully perhaps
+ */
+ this->recover();
- return false;
+ return false;
}
template<class ImplTraits>
-bool Lexer<ImplTraits>::matchRange(ANTLR_UCHAR low, ANTLR_UCHAR high)
+bool Lexer<ImplTraits>::matchRange(ANTLR_UCHAR low, ANTLR_UCHAR high)
{
ANTLR_UCHAR c;
/* What is in the stream at the moment?
*/
- c = this->get_istream()->LA(1);
- if ( c >= low && c <= high)
+ c = this->get_istream()->LA(1);
+ if ( c >= low && c <= high)
{
- /* Matched correctly, consume it
- */
- this->get_istream()->consume();
+ /* Matched correctly, consume it
+ */
+ this->get_istream()->consume();
- /* Reset any failed indicator
- */
- this->get_rec()->get_state()->set_failed( false );
+ /* Reset any failed indicator
+ */
+ this->get_rec()->get_state()->set_failed( false );
- return true;
+ return true;
}
/* Failed to match, execption and recovery time.
*/
- if (this->get_rec()->get_state()->get_backtracking() > 0)
+ if (this->get_rec()->get_state()->get_backtracking() > 0)
{
- this->get_rec()->get_state()->set_failed( true );
- return false;
+ this->get_rec()->get_state()->set_failed( true );
+ return false;
}
this->exConstruct();
@@ -337,256 +337,256 @@ bool Lexer<ImplTraits>::matchRange(ANTLR_UCHAR low, ANTLR_UCHAR high)
}
template<class ImplTraits>
-void Lexer<ImplTraits>::matchAny()
+void Lexer<ImplTraits>::matchAny()
{
- this->get_istream()->consume();
+ this->get_istream()->consume();
}
template<class ImplTraits>
-void Lexer<ImplTraits>::recover()
+void Lexer<ImplTraits>::recover()
{
- this->get_istream()->consume();
+ this->get_istream()->consume();
}
template<class ImplTraits>
-ANTLR_UINT32 Lexer<ImplTraits>::getLine()
+ANTLR_UINT32 Lexer<ImplTraits>::getLine()
{
- return this->get_input()->get_line();
+ return this->get_input()->get_line();
}
template<class ImplTraits>
-ANTLR_MARKER Lexer<ImplTraits>::getCharIndex()
+ANTLR_MARKER Lexer<ImplTraits>::getCharIndex()
{
- return this->get_istream()->index();
+ return this->get_istream()->index();
}
template<class ImplTraits>
-ANTLR_UINT32 Lexer<ImplTraits>::getCharPositionInLine()
+ANTLR_UINT32 Lexer<ImplTraits>::getCharPositionInLine()
{
- return this->get_input()->get_charPositionInLine();
+ return this->get_input()->get_charPositionInLine();
}
template<class ImplTraits>
-typename Lexer<ImplTraits>::StringType Lexer<ImplTraits>::getText()
+typename Lexer<ImplTraits>::StringType Lexer<ImplTraits>::getText()
{
- RecognizerSharedStateType* state = this->get_rec()->get_state();
- if ( !state->get_text().empty() )
- {
- return state->get_text();
+ RecognizerSharedStateType* state = this->get_rec()->get_state();
+ if ( !state->get_text().empty() )
+ {
+ return state->get_text();
- }
- return this->get_input()->substr( state->get_tokenStartCharIndex(),
- this->getCharIndex() - this->get_input()->get_charByteSize()
- );
+ }
+ return this->get_input()->substr( state->get_tokenStartCharIndex(),
+ this->getCharIndex() - this->get_input()->get_charByteSize()
+ );
}
template<class ImplTraits>
void Lexer<ImplTraits>::exConstruct()
{
- new ANTLR_Exception<ImplTraits, RECOGNITION_EXCEPTION, InputStreamType>( this->get_rec(), "" );
+ new ANTLR_Exception<ImplTraits, RECOGNITION_EXCEPTION, InputStreamType>( this->get_rec(), "" );
}
template< class ImplTraits>
-typename Lexer<ImplTraits>::TokenType* Lexer<ImplTraits>::getMissingSymbol( IntStreamType*,
- ExceptionBaseType*,
- ANTLR_UINT32 , BitsetListType*)
+typename Lexer<ImplTraits>::TokenType* Lexer<ImplTraits>::getMissingSymbol( IntStreamType*,
+ ExceptionBaseType*,
+ ANTLR_UINT32 , BitsetListType*)
{
- return NULL;
+ return NULL;
}
template< class ImplTraits>
ANTLR_INLINE const typename Lexer<ImplTraits>::RecognizerType* Lexer<ImplTraits>::get_rec() const
{
- return this;
+ return this;
}
template< class ImplTraits>
ANTLR_INLINE const typename Lexer<ImplTraits>::RecognizerType* Lexer<ImplTraits>::get_recognizer() const
{
- return this->get_rec();
+ return this->get_rec();
}
template< class ImplTraits>
ANTLR_INLINE typename Lexer<ImplTraits>::RecognizerSharedStateType* Lexer<ImplTraits>::get_lexstate() const
{
- return this->get_rec()->get_state();
+ return this->get_rec()->get_state();
}
template< class ImplTraits>
ANTLR_INLINE void Lexer<ImplTraits>::set_lexstate( RecognizerSharedStateType* lexstate )
{
- this->get_rec()->set_state(lexstate);
+ this->get_rec()->set_state(lexstate);
}
template< class ImplTraits>
ANTLR_INLINE const typename Lexer<ImplTraits>::TokenSourceType* Lexer<ImplTraits>::get_tokSource() const
{
- return this;
+ return this;
}
template< class ImplTraits>
ANTLR_INLINE typename Lexer<ImplTraits>::CommonTokenType* Lexer<ImplTraits>::get_ltoken() const
{
- return this->get_lexstate()->token();
+ return this->get_lexstate()->token();
}
template< class ImplTraits>
ANTLR_INLINE void Lexer<ImplTraits>::set_ltoken( const CommonTokenType* ltoken )
{
- this->get_lexstate()->set_token( ltoken );
+ this->get_lexstate()->set_token( ltoken );
}
template< class ImplTraits>
ANTLR_INLINE bool Lexer<ImplTraits>::hasFailed() const
{
- return this->get_lexstate()->get_failed();
+ return this->get_lexstate()->get_failed();
}
template< class ImplTraits>
ANTLR_INLINE ANTLR_INT32 Lexer<ImplTraits>::get_backtracking() const
{
- return this->get_lexstate()->get_backtracking();
+ return this->get_lexstate()->get_backtracking();
}
template< class ImplTraits>
ANTLR_INLINE void Lexer<ImplTraits>::inc_backtracking()
{
- this->get_lexstate()->inc_backtracking();
+ this->get_lexstate()->inc_backtracking();
}
template< class ImplTraits>
ANTLR_INLINE void Lexer<ImplTraits>::dec_backtracking()
{
- this->get_lexstate()->dec_backtracking();
+ this->get_lexstate()->dec_backtracking();
}
template< class ImplTraits>
ANTLR_INLINE bool Lexer<ImplTraits>::get_failedflag() const
{
- return this->get_lexstate()->get_failed();
+ return this->get_lexstate()->get_failed();
}
template< class ImplTraits>
ANTLR_INLINE void Lexer<ImplTraits>::set_failedflag( bool failed )
{
- this->get_lexstate()->set_failed(failed);
+ this->get_lexstate()->set_failed(failed);
}
template< class ImplTraits>
ANTLR_INLINE typename Lexer<ImplTraits>::InputStreamType* Lexer<ImplTraits>::get_strstream() const
{
- return this->get_input();
+ return this->get_input();
}
template< class ImplTraits>
ANTLR_INLINE ANTLR_MARKER Lexer<ImplTraits>::index() const
{
- return this->get_istream()->index();
+ return this->get_istream()->index();
}
template< class ImplTraits>
-ANTLR_INLINE void Lexer<ImplTraits>::seek(ANTLR_MARKER index)
+ANTLR_INLINE void Lexer<ImplTraits>::seek(ANTLR_MARKER index)
{
- this->get_istream()->seek(index);
+ this->get_istream()->seek(index);
}
template< class ImplTraits>
ANTLR_INLINE const typename Lexer<ImplTraits>::CommonTokenType* Lexer<ImplTraits>::EOF_Token() const
{
- const CommonTokenType& eof_token = this->get_tokSource()->get_eofToken();
- return &eof_token;
+ const CommonTokenType& eof_token = this->get_tokSource()->get_eofToken();
+ return &eof_token;
}
template< class ImplTraits>
ANTLR_INLINE bool Lexer<ImplTraits>::hasException() const
{
- return this->get_lexstate()->get_error();
+ return this->get_lexstate()->get_error();
}
template< class ImplTraits>
ANTLR_INLINE typename Lexer<ImplTraits>::ExceptionBaseType* Lexer<ImplTraits>::get_exception() const
{
- return this->get_lexstate()->get_exception();
+ return this->get_lexstate()->get_exception();
}
template< class ImplTraits>
ANTLR_INLINE void Lexer<ImplTraits>::constructEx()
{
- this->get_rec()->exConstruct();
+ this->get_rec()->exConstruct();
}
template< class ImplTraits>
ANTLR_INLINE ANTLR_MARKER Lexer<ImplTraits>::mark()
{
- return this->get_istream()->mark();
+ return this->get_istream()->mark();
}
template< class ImplTraits>
ANTLR_INLINE void Lexer<ImplTraits>::rewind(ANTLR_MARKER marker)
{
- this->get_istream()->rewind(marker);
+ this->get_istream()->rewind(marker);
}
template< class ImplTraits>
ANTLR_INLINE void Lexer<ImplTraits>::rewindLast()
{
- this->get_istream()->rewindLast();
+ this->get_istream()->rewindLast();
}
template< class ImplTraits>
-ANTLR_INLINE void Lexer<ImplTraits>::memoize(ANTLR_MARKER ruleIndex, ANTLR_MARKER ruleParseStart)
+ANTLR_INLINE void Lexer<ImplTraits>::memoize(ANTLR_MARKER ruleIndex, ANTLR_MARKER ruleParseStart)
{
- this->get_rec()->memoize( ruleIndex, ruleParseStart );
+ this->get_rec()->memoize( ruleIndex, ruleParseStart );
}
template< class ImplTraits>
-ANTLR_INLINE bool Lexer<ImplTraits>::haveParsedRule(ANTLR_MARKER ruleIndex)
+ANTLR_INLINE bool Lexer<ImplTraits>::haveParsedRule(ANTLR_MARKER ruleIndex)
{
- return this->get_rec()->alreadyParsedRule(ruleIndex);
+ return this->get_rec()->alreadyParsedRule(ruleIndex);
}
template< class ImplTraits>
ANTLR_INLINE void Lexer<ImplTraits>::setText( const StringType& text )
{
- this->get_lexstate()->set_text(text);
+ this->get_lexstate()->set_text(text);
}
template< class ImplTraits>
ANTLR_INLINE void Lexer<ImplTraits>::skip()
{
- CommonTokenType& skipToken = this->get_tokSource()->get_skipToken();
- this->get_lexstate()->set_token( &skipToken );
+ CommonTokenType& skipToken = this->get_tokSource()->get_skipToken();
+ this->get_lexstate()->set_token( &skipToken );
}
template< class ImplTraits>
ANTLR_INLINE typename Lexer<ImplTraits>::RuleMemoType* Lexer<ImplTraits>::getRuleMemo() const
{
- return this->get_lexstate()->get_rulememo();
+ return this->get_lexstate()->get_rulememo();
}
template< class ImplTraits>
ANTLR_INLINE void Lexer<ImplTraits>::setRuleMemo(RuleMemoType* rulememo)
{
- return this->get_lexstate()->set_rulememo(rulememo);
+ return this->get_lexstate()->set_rulememo(rulememo);
}
template< class ImplTraits>
ANTLR_INLINE typename Lexer<ImplTraits>::DebuggerType* Lexer<ImplTraits>::get_debugger() const
{
- return this->get_rec()->get_debugger();
+ return this->get_rec()->get_debugger();
}
template< class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 Lexer<ImplTraits>::LA(ANTLR_INT32 i)
{
- return this->get_istream()->LA(i);
+ return this->get_istream()->LA(i);
}
template< class ImplTraits>
ANTLR_INLINE void Lexer<ImplTraits>::consume()
{
- return this->get_istream()->consume();
+ return this->get_istream()->consume();
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3memory.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3memory.hpp
index 6a3d6d38cc..7b85f67545 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3memory.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3memory.hpp
@@ -1,5 +1,5 @@
-#ifndef _ANTLR3MEMORY_HPP
-#define _ANTLR3MEMORY_HPP
+#ifndef _ANTLR3MEMORY_HPP
+#define _ANTLR3MEMORY_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -29,146 +29,146 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
class DefaultAllocPolicy
{
public:
- //limitation of c++. unable to write a typedef
- template <class TYPE>
- class AllocatorType : public std::allocator<TYPE>
- {
- public:
- typedef TYPE value_type;
- typedef value_type* pointer;
- typedef const value_type* const_pointer;
- typedef value_type& reference;
- typedef const value_type& const_reference;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- template<class U> struct rebind {
- typedef AllocatorType<U> other;
- };
+ //limitation of c++. unable to write a typedef
+ template <class TYPE>
+ class AllocatorType : public std::allocator<TYPE>
+ {
+ public:
+ typedef TYPE value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ template<class U> struct rebind {
+ typedef AllocatorType<U> other;
+ };
AllocatorType() noexcept {}
AllocatorType( const AllocatorType& ) noexcept {}
template<typename U> AllocatorType(const AllocatorType<U>& ) noexcept{}
- };
-
- template<class TYPE>
- class VectorType : public std::vector< TYPE, AllocatorType<TYPE> >
- {
- };
-
- template<class TYPE>
- class ListType : public std::deque< TYPE, AllocatorType<TYPE> >
- {
- };
-
- template<class TYPE>
- class StackType : public std::deque< TYPE, AllocatorType<TYPE> >
- {
- public:
- void push( const TYPE& elem ) { this->push_back(elem); }
- void pop() { this->pop_back(); }
- TYPE& peek() { return this->back(); }
- TYPE& top() { return this->back(); }
- const TYPE& peek() const { return this->back(); }
- const TYPE& top() const { return this->back(); }
- };
-
-
- template<class TYPE>
- class OrderedSetType : public std::set< TYPE, std::less<TYPE>, AllocatorType<TYPE> >
- {
- };
-
- template<class TYPE>
- class UnOrderedSetType : public std::set< TYPE, std::less<TYPE>, AllocatorType<TYPE> >
- {
- };
-
- template<class KeyType, class ValueType>
- class UnOrderedMapType : public std::map< KeyType, ValueType, std::less<KeyType>,
- AllocatorType<std::pair<const KeyType, ValueType> > >
- {
- };
-
- template<class KeyType, class ValueType>
- class OrderedMapType : public std::map< KeyType, ValueType, std::less<KeyType>,
- AllocatorType<std::pair<KeyType, ValueType> > >
- {
- };
-
- template<class TYPE>
- class SmartPtrType : public std::unique_ptr<TYPE, std::default_delete<TYPE> >
- {
- typedef typename std::unique_ptr<TYPE, std::default_delete<TYPE> > BaseType;
- public:
- SmartPtrType() {};
- SmartPtrType( SmartPtrType&& other )
- : BaseType(other)
- {};
- SmartPtrType & operator=(SmartPtrType&& other) //= default;
- {
- BaseType::swap(other);
- //return std::move((BaseType&)other);
- return *this;
- }
- private:
- SmartPtrType & operator=(const SmartPtrType&) /*= delete*/;
- SmartPtrType(const SmartPtrType&) /*= delete*/;
- };
-
- ANTLR_INLINE static void* operator new (std::size_t bytes)
- {
+ };
+
+ template<class TYPE>
+ class VectorType : public std::vector< TYPE, AllocatorType<TYPE> >
+ {
+ };
+
+ template<class TYPE>
+ class ListType : public std::deque< TYPE, AllocatorType<TYPE> >
+ {
+ };
+
+ template<class TYPE>
+ class StackType : public std::deque< TYPE, AllocatorType<TYPE> >
+ {
+ public:
+ void push( const TYPE& elem ) { this->push_back(elem); }
+ void pop() { this->pop_back(); }
+ TYPE& peek() { return this->back(); }
+ TYPE& top() { return this->back(); }
+ const TYPE& peek() const { return this->back(); }
+ const TYPE& top() const { return this->back(); }
+ };
+
+
+ template<class TYPE>
+ class OrderedSetType : public std::set< TYPE, std::less<TYPE>, AllocatorType<TYPE> >
+ {
+ };
+
+ template<class TYPE>
+ class UnOrderedSetType : public std::set< TYPE, std::less<TYPE>, AllocatorType<TYPE> >
+ {
+ };
+
+ template<class KeyType, class ValueType>
+ class UnOrderedMapType : public std::map< KeyType, ValueType, std::less<KeyType>,
+ AllocatorType<std::pair<const KeyType, ValueType> > >
+ {
+ };
+
+ template<class KeyType, class ValueType>
+ class OrderedMapType : public std::map< KeyType, ValueType, std::less<KeyType>,
+ AllocatorType<std::pair<KeyType, ValueType> > >
+ {
+ };
+
+ template<class TYPE>
+ class SmartPtrType : public std::unique_ptr<TYPE, std::default_delete<TYPE> >
+ {
+ typedef typename std::unique_ptr<TYPE, std::default_delete<TYPE> > BaseType;
+ public:
+ SmartPtrType() {};
+ SmartPtrType( SmartPtrType&& other )
+ : BaseType(other)
+ {};
+ SmartPtrType & operator=(SmartPtrType&& other) //= default;
+ {
+ BaseType::swap(other);
+ //return std::move((BaseType&)other);
+ return *this;
+ }
+ private:
+ SmartPtrType & operator=(const SmartPtrType&) /*= delete*/;
+ SmartPtrType(const SmartPtrType&) /*= delete*/;
+ };
+
+ ANTLR_INLINE static void* operator new (std::size_t bytes)
+ {
+ void* p = alloc(bytes);
+ return p;
+ }
+ ANTLR_INLINE static void* operator new (std::size_t , void* p) { return p; }
+ ANTLR_INLINE static void* operator new[]( std::size_t bytes)
+ {
void* p = alloc(bytes);
- return p;
- }
- ANTLR_INLINE static void* operator new (std::size_t , void* p) { return p; }
- ANTLR_INLINE static void* operator new[]( std::size_t bytes)
- {
- void* p = alloc(bytes);
- return p;
- }
- ANTLR_INLINE static void operator delete(void* p)
- {
- DefaultAllocPolicy::free(p);
- }
- ANTLR_INLINE static void operator delete(void* , void* ) {} //placement delete
-
- ANTLR_INLINE static void operator delete[](void* p)
- {
- DefaultAllocPolicy::free(p);
- }
-
- ANTLR_INLINE static void* alloc( std::size_t bytes )
- {
- void* p = malloc(bytes);
- if( p== NULL )
- throw std::bad_alloc();
- return p;
- }
-
- ANTLR_INLINE static void* alloc0( std::size_t bytes )
- {
- void* p = calloc(1, bytes);
- if( p== NULL )
- throw std::bad_alloc();
- return p;
- }
-
- ANTLR_INLINE static void free( void* p )
- {
- return ::free(p);
- }
-
- ANTLR_INLINE static void* realloc(void *ptr, size_t size)
- {
- return ::realloc( ptr, size );
- }
+ return p;
+ }
+ ANTLR_INLINE static void operator delete(void* p)
+ {
+ DefaultAllocPolicy::free(p);
+ }
+ ANTLR_INLINE static void operator delete(void* , void* ) {} //placement delete
+
+ ANTLR_INLINE static void operator delete[](void* p)
+ {
+ DefaultAllocPolicy::free(p);
+ }
+
+ ANTLR_INLINE static void* alloc( std::size_t bytes )
+ {
+ void* p = malloc(bytes);
+ if( p== NULL )
+ throw std::bad_alloc();
+ return p;
+ }
+
+ ANTLR_INLINE static void* alloc0( std::size_t bytes )
+ {
+ void* p = calloc(1, bytes);
+ if( p== NULL )
+ throw std::bad_alloc();
+ return p;
+ }
+
+ ANTLR_INLINE static void free( void* p )
+ {
+ return ::free(p);
+ }
+
+ ANTLR_INLINE static void* realloc(void *ptr, size_t size)
+ {
+ return ::realloc( ptr, size );
+ }
};
-}
+}
-#endif /* _ANTLR3MEMORY_H */
+#endif /* _ANTLR3MEMORY_H */
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3parser.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3parser.hpp
index 2d37250f81..ccf8e9a323 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3parser.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3parser.hpp
@@ -3,8 +3,8 @@
*
*
*/
-#ifndef _ANTLR3_PARSER_HPP
-#define _ANTLR3_PARSER_HPP
+#ifndef _ANTLR3_PARSER_HPP
+#define _ANTLR3_PARSER_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -34,7 +34,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
/** This is the main interface for an ANTLR3 parser.
*/
@@ -42,112 +42,112 @@ template< class ImplTraits >
class Parser : public ImplTraits::template RecognizerType< typename ImplTraits::TokenStreamType >
{
public:
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::TokenStreamType TokenStreamType;
- typedef typename TokenStreamType::IntStreamType IntStreamType;
- typedef TokenStreamType StreamType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::TokenStreamType TokenStreamType;
+ typedef typename TokenStreamType::IntStreamType IntStreamType;
+ typedef TokenStreamType StreamType;
- typedef typename ImplTraits::template RecognizerType< typename ImplTraits::TokenStreamType > RecognizerType;
- typedef typename RecognizerType::RecognizerSharedStateType RecognizerSharedStateType;
+ typedef typename ImplTraits::template RecognizerType< typename ImplTraits::TokenStreamType > RecognizerType;
+ typedef typename RecognizerType::RecognizerSharedStateType RecognizerSharedStateType;
- typedef DebugEventListener<ImplTraits> DebugEventListenerType;
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
- typedef CommonTokenType TokenType;
- typedef typename ImplTraits::BitsetListType BitsetListType;
- typedef ANTLR_ExceptionBase<ImplTraits, TokenStreamType> ExceptionBaseType;
- typedef Empty TokenSourceType;
+ typedef DebugEventListener<ImplTraits> DebugEventListenerType;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
+ typedef CommonTokenType TokenType;
+ typedef typename ImplTraits::BitsetListType BitsetListType;
+ typedef ANTLR_ExceptionBase<ImplTraits, TokenStreamType> ExceptionBaseType;
+ typedef Empty TokenSourceType;
- typedef typename RecognizerSharedStateType::FollowingType FollowingType;
- typedef typename RecognizerSharedStateType::RuleMemoType RuleMemoType;
- typedef typename ImplTraits::DebugEventListenerType DebuggerType;
+ typedef typename RecognizerSharedStateType::FollowingType FollowingType;
+ typedef typename RecognizerSharedStateType::RuleMemoType RuleMemoType;
+ typedef typename ImplTraits::DebugEventListenerType DebuggerType;
private:
/** A provider of a tokenstream interface, for the parser to consume
* tokens from.
*/
- TokenStreamType* m_tstream;
+ TokenStreamType* m_tstream;
public:
- Parser( ANTLR_UINT32 sizeHint, RecognizerSharedStateType* state );
- Parser( ANTLR_UINT32 sizeHint, TokenStreamType* tstream, RecognizerSharedStateType* state );
- Parser( ANTLR_UINT32 sizeHint, TokenStreamType* tstream, DebugEventListenerType* dbg,
- RecognizerSharedStateType* state );
- TokenStreamType* get_tstream() const;
- TokenStreamType* get_input() const;
- IntStreamType* get_istream() const;
- RecognizerType* get_rec();
-
- //same as above. Just that get_istream exists for lexer, parser, treeparser
- //get_parser_istream exists only for parser, treeparser. So use it accordingly
- IntStreamType* get_parser_istream() const;
-
- /** A pointer to a function that installs a debugger object (it also
- * installs the debugging versions of the parser methods. This means that
- * a non debug parser incurs no overhead because of the debugging stuff.
- */
- void setDebugListener(DebugEventListenerType* dbg);
+ Parser( ANTLR_UINT32 sizeHint, RecognizerSharedStateType* state );
+ Parser( ANTLR_UINT32 sizeHint, TokenStreamType* tstream, RecognizerSharedStateType* state );
+ Parser( ANTLR_UINT32 sizeHint, TokenStreamType* tstream, DebugEventListenerType* dbg,
+ RecognizerSharedStateType* state );
+ TokenStreamType* get_tstream() const;
+ TokenStreamType* get_input() const;
+ IntStreamType* get_istream() const;
+ RecognizerType* get_rec();
+
+ //same as above. Just that get_istream exists for lexer, parser, treeparser
+ //get_parser_istream exists only for parser, treeparser. So use it accordingly
+ IntStreamType* get_parser_istream() const;
+
+ /** A pointer to a function that installs a debugger object (it also
+ * installs the debugging versions of the parser methods. This means that
+ * a non debug parser incurs no overhead because of the debugging stuff.
+ */
+ void setDebugListener(DebugEventListenerType* dbg);
/** A pointer to a function that installs a token stream
* for the parser.
*/
- void setTokenStream(TokenStreamType*);
+ void setTokenStream(TokenStreamType*);
/** A pointer to a function that returns the token stream for this
* parser.
*/
- TokenStreamType* getTokenStream();
+ TokenStreamType* getTokenStream();
- void exConstruct();
- TokenType* getMissingSymbol( IntStreamType* istream, ExceptionBaseType* e,
- ANTLR_UINT32 expectedTokenType, BitsetListType* follow);
+ void exConstruct();
+ TokenType* getMissingSymbol( IntStreamType* istream, ExceptionBaseType* e,
+ ANTLR_UINT32 expectedTokenType, BitsetListType* follow);
- void mismatch(ANTLR_UINT32 ttype, BitsetListType* follow);
+ void mismatch(ANTLR_UINT32 ttype, BitsetListType* follow);
/** Pointer to a function that knows how to free resources of an ANTLR3 parser.
*/
- ~Parser();
-
- void fillExceptionData( ExceptionBaseType* ex );
- void displayRecognitionError( ANTLR_UINT8** tokenNames, ExceptionBaseType* ex );
-
- //convenience functions exposed in .stg
- const RecognizerType* get_recognizer() const;
- RecognizerSharedStateType* get_psrstate() const;
- void set_psrstate(RecognizerSharedStateType* state);
- bool haveParsedRule(ANTLR_MARKER ruleIndex);
- void memoize(ANTLR_MARKER ruleIndex, ANTLR_MARKER ruleParseStart);
- ANTLR_MARKER index() const;
- bool hasException() const;
- ExceptionBaseType* get_exception() const;
- const CommonTokenType* matchToken( ANTLR_UINT32 ttype, BitsetListType* follow );
- void matchAnyToken();
- const FollowingType& get_follow_stack() const;
- void followPush( const BitsetListType& follow );
- void followPop();
- void precover();
- void preporterror();
- ANTLR_UINT32 LA(ANTLR_INT32 i);
- const CommonTokenType* LT(ANTLR_INT32 k);
- void constructEx();
- void consume();
- ANTLR_MARKER mark();
- void rewind(ANTLR_MARKER marker);
- void rewindLast();
- void seek(ANTLR_MARKER index);
- bool get_perror_recovery() const;
- void set_perror_recovery( bool val );
- bool hasFailed() const;
- bool get_failedflag() const;
- void set_failedflag( bool failed );
- ANTLR_INT32 get_backtracking() const;
- void inc_backtracking();
- void dec_backtracking();
- CommonTokenType* recoverFromMismatchedSet(BitsetListType* follow);
- bool recoverFromMismatchedElement(BitsetListType* follow);
- RuleMemoType* getRuleMemo() const;
- DebuggerType* get_debugger() const;
- TokenStreamType* get_strstream() const;
- void setRuleMemo(RuleMemoType* rulememo);
+ ~Parser();
+
+ void fillExceptionData( ExceptionBaseType* ex );
+ void displayRecognitionError( ANTLR_UINT8** tokenNames, ExceptionBaseType* ex );
+
+ //convenience functions exposed in .stg
+ const RecognizerType* get_recognizer() const;
+ RecognizerSharedStateType* get_psrstate() const;
+ void set_psrstate(RecognizerSharedStateType* state);
+ bool haveParsedRule(ANTLR_MARKER ruleIndex);
+ void memoize(ANTLR_MARKER ruleIndex, ANTLR_MARKER ruleParseStart);
+ ANTLR_MARKER index() const;
+ bool hasException() const;
+ ExceptionBaseType* get_exception() const;
+ const CommonTokenType* matchToken( ANTLR_UINT32 ttype, BitsetListType* follow );
+ void matchAnyToken();
+ const FollowingType& get_follow_stack() const;
+ void followPush( const BitsetListType& follow );
+ void followPop();
+ void precover();
+ void preporterror();
+ ANTLR_UINT32 LA(ANTLR_INT32 i);
+ const CommonTokenType* LT(ANTLR_INT32 k);
+ void constructEx();
+ void consume();
+ ANTLR_MARKER mark();
+ void rewind(ANTLR_MARKER marker);
+ void rewindLast();
+ void seek(ANTLR_MARKER index);
+ bool get_perror_recovery() const;
+ void set_perror_recovery( bool val );
+ bool hasFailed() const;
+ bool get_failedflag() const;
+ void set_failedflag( bool failed );
+ ANTLR_INT32 get_backtracking() const;
+ void inc_backtracking();
+ void dec_backtracking();
+ CommonTokenType* recoverFromMismatchedSet(BitsetListType* follow);
+ bool recoverFromMismatchedElement(BitsetListType* follow);
+ RuleMemoType* getRuleMemo() const;
+ DebuggerType* get_debugger() const;
+ TokenStreamType* get_strstream() const;
+ void setRuleMemo(RuleMemoType* rulememo);
};
@@ -157,19 +157,19 @@ template<class ImplTraits>
class RuleReturnValue
{
public:
- typedef typename ImplTraits::BaseParserType BaseParserType;
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
-
- const CommonTokenType* start;
- const CommonTokenType* stop;
-
- RuleReturnValue(BaseParserType* psr = NULL );
- RuleReturnValue( const RuleReturnValue& val );
- RuleReturnValue& operator=( const RuleReturnValue& val );
- void call_start_placeholder(BaseParserType*);
- void call_stop_placeholder(BaseParserType*);
- RuleReturnValue& get_struct();
- ~RuleReturnValue();
+ typedef typename ImplTraits::BaseParserType BaseParserType;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
+
+ const CommonTokenType* start;
+ const CommonTokenType* stop;
+
+ RuleReturnValue(BaseParserType* psr = NULL );
+ RuleReturnValue( const RuleReturnValue& val );
+ RuleReturnValue& operator=( const RuleReturnValue& val );
+ void call_start_placeholder(BaseParserType*);
+ void call_stop_placeholder(BaseParserType*);
+ RuleReturnValue& get_struct();
+ ~RuleReturnValue();
};
//This kind makes sure that whenever tokens are condensed into a rule,
@@ -178,19 +178,19 @@ template<class ImplTraits>
class RuleReturnValue_1 : public RuleReturnValue<ImplTraits>
{
public:
- typedef RuleReturnValue<ImplTraits> BaseType;
- typedef typename BaseType::BaseParserType BaseParserType;
-
- BaseParserType* parser;
-
- RuleReturnValue_1();
- RuleReturnValue_1( BaseParserType* psr);
- RuleReturnValue_1( const RuleReturnValue_1& val );
- void call_start_placeholder(BaseParserType*); //its dummy here
- ~RuleReturnValue_1();
+ typedef RuleReturnValue<ImplTraits> BaseType;
+ typedef typename BaseType::BaseParserType BaseParserType;
+
+ BaseParserType* parser;
+
+ RuleReturnValue_1();
+ RuleReturnValue_1( BaseParserType* psr);
+ RuleReturnValue_1( const RuleReturnValue_1& val );
+ void call_start_placeholder(BaseParserType*); //its dummy here
+ ~RuleReturnValue_1();
};
-}
+}
#include "antlr3parser.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3parser.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3parser.inl
index 14a4501678..bb1e4e6960 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3parser.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3parser.inl
@@ -1,234 +1,234 @@
-namespace antlr3 {
+namespace antlr3 {
template< class ImplTraits >
Parser<ImplTraits>::Parser( ANTLR_UINT32 sizeHint, RecognizerSharedStateType* state )
- : RecognizerType( sizeHint, state )
+ : RecognizerType( sizeHint, state )
{
- m_tstream = NULL;
+ m_tstream = NULL;
}
template< class ImplTraits >
Parser<ImplTraits>::Parser( ANTLR_UINT32 sizeHint, TokenStreamType* tstream,
- RecognizerSharedStateType* state )
- : RecognizerType( sizeHint, state )
+ RecognizerSharedStateType* state )
+ : RecognizerType( sizeHint, state )
{
- this->setTokenStream( tstream );
+ this->setTokenStream( tstream );
}
template< class ImplTraits >
Parser<ImplTraits>::Parser( ANTLR_UINT32 sizeHint, TokenStreamType* tstream,
- DebugEventListenerType* dbg,
- RecognizerSharedStateType* state )
- : RecognizerType( sizeHint, state )
+ DebugEventListenerType* dbg,
+ RecognizerSharedStateType* state )
+ : RecognizerType( sizeHint, state )
{
- this->setTokenStream( tstream );
- this->setDebugListener( dbg );
+ this->setTokenStream( tstream );
+ this->setDebugListener( dbg );
}
template< class ImplTraits >
ANTLR_INLINE typename Parser<ImplTraits>::TokenStreamType* Parser<ImplTraits>::get_tstream() const
{
- return m_tstream;
+ return m_tstream;
}
template< class ImplTraits >
ANTLR_INLINE typename Parser<ImplTraits>::IntStreamType* Parser<ImplTraits>::get_istream() const
{
- return m_tstream;
+ return m_tstream;
}
template< class ImplTraits >
ANTLR_INLINE typename Parser<ImplTraits>::IntStreamType* Parser<ImplTraits>::get_parser_istream() const
{
- return m_tstream;
+ return m_tstream;
}
template< class ImplTraits >
ANTLR_INLINE typename Parser<ImplTraits>::TokenStreamType* Parser<ImplTraits>::get_input() const
{
- return m_tstream;
+ return m_tstream;
}
template< class ImplTraits >
void Parser<ImplTraits>::fillExceptionData( ExceptionBaseType* ex )
{
- ex->set_token( new CommonTokenType(*(m_tstream->LT(1))) ); /* Current input token (clonned) - held by the exception */
- ex->set_line( ex->get_token()->get_line() );
- ex->set_charPositionInLine( ex->get_token()->get_charPositionInLine() );
- ex->set_index( this->get_istream()->index() );
- if( ex->get_token()->get_type() == CommonTokenType::TOKEN_EOF)
- {
- ex->set_streamName("");
- }
- else
- {
- ex->set_streamName( ex->get_token()->get_input()->get_fileName() );
- }
- ex->set_message("Unexpected token");
+ ex->set_token( new CommonTokenType(*(m_tstream->LT(1))) ); /* Current input token (clonned) - held by the exception */
+ ex->set_line( ex->get_token()->get_line() );
+ ex->set_charPositionInLine( ex->get_token()->get_charPositionInLine() );
+ ex->set_index( this->get_istream()->index() );
+ if( ex->get_token()->get_type() == CommonTokenType::TOKEN_EOF)
+ {
+ ex->set_streamName("");
+ }
+ else
+ {
+ ex->set_streamName( ex->get_token()->get_input()->get_fileName() );
+ }
+ ex->set_message("Unexpected token");
}
template< class ImplTraits >
void Parser<ImplTraits>::displayRecognitionError( ANTLR_UINT8** tokenNames, ExceptionBaseType* ex )
{
- typename ImplTraits::StringStreamType errtext;
- // See if there is a 'filename' we can use
- //
- if( ex->get_streamName().empty() )
- {
- if(ex->get_token()->get_type() == CommonTokenType::TOKEN_EOF)
- {
- errtext << "-end of input-(";
- }
- else
- {
- errtext << "-unknown source-(";
- }
- }
- else
- {
- errtext << ex->get_streamName() << "(";
- }
-
- // Next comes the line number
- //
- errtext << this->get_rec()->get_state()->get_exception()->get_line() << ") ";
- errtext << " : error " << this->get_rec()->get_state()->get_exception()->getType()
- << " : "
- << this->get_rec()->get_state()->get_exception()->get_message();
-
- // Prepare the knowledge we know we have
- //
- const CommonTokenType* theToken = this->get_rec()->get_state()->get_exception()->get_token();
- StringType ttext = theToken->toString();
-
- errtext << ", at offset , "
- << this->get_rec()->get_state()->get_exception()->get_charPositionInLine();
- if (theToken != NULL)
- {
- if (theToken->get_type() == CommonTokenType::TOKEN_EOF)
- {
- errtext << ", at <EOF>";
- }
- else
- {
- // Guard against null text in a token
- //
- errtext << "\n near " << ( ttext.empty()
- ? "<no text for the token>" : ttext ) << "\n";
- }
- }
-
- ex->displayRecognitionError( tokenNames, errtext );
- ImplTraits::displayRecognitionError( errtext.str() );
+ typename ImplTraits::StringStreamType errtext;
+ // See if there is a 'filename' we can use
+ //
+ if( ex->get_streamName().empty() )
+ {
+ if(ex->get_token()->get_type() == CommonTokenType::TOKEN_EOF)
+ {
+ errtext << "-end of input-(";
+ }
+ else
+ {
+ errtext << "-unknown source-(";
+ }
+ }
+ else
+ {
+ errtext << ex->get_streamName() << "(";
+ }
+
+ // Next comes the line number
+ //
+ errtext << this->get_rec()->get_state()->get_exception()->get_line() << ") ";
+ errtext << " : error " << this->get_rec()->get_state()->get_exception()->getType()
+ << " : "
+ << this->get_rec()->get_state()->get_exception()->get_message();
+
+ // Prepare the knowledge we know we have
+ //
+ const CommonTokenType* theToken = this->get_rec()->get_state()->get_exception()->get_token();
+ StringType ttext = theToken->toString();
+
+ errtext << ", at offset , "
+ << this->get_rec()->get_state()->get_exception()->get_charPositionInLine();
+ if (theToken != NULL)
+ {
+ if (theToken->get_type() == CommonTokenType::TOKEN_EOF)
+ {
+ errtext << ", at <EOF>";
+ }
+ else
+ {
+ // Guard against null text in a token
+ //
+ errtext << "\n near " << ( ttext.empty()
+ ? "<no text for the token>" : ttext ) << "\n";
+ }
+ }
+
+ ex->displayRecognitionError( tokenNames, errtext );
+ ImplTraits::displayRecognitionError( errtext.str() );
}
template< class ImplTraits >
Parser<ImplTraits>::~Parser()
{
- if (this->get_rec() != NULL)
+ if (this->get_rec() != NULL)
{
- // This may have ben a delegate or delegator parser, in which case the
- // state may already have been freed (and set to NULL therefore)
- // so we ignore the state if we don't have it.
- //
- RecognizerSharedStateType* state = this->get_rec()->get_state();
- if (state != NULL)
- {
- state->get_following().clear();
- }
+ // This may have ben a delegate or delegator parser, in which case the
+ // state may already have been freed (and set to NULL therefore)
+ // so we ignore the state if we don't have it.
+ //
+ RecognizerSharedStateType* state = this->get_rec()->get_state();
+ if (state != NULL)
+ {
+ state->get_following().clear();
+ }
}
}
template< class ImplTraits >
-void Parser<ImplTraits>::setDebugListener(DebugEventListenerType* dbg)
-{
- // Set the debug listener. There are no methods to override
- // because currently the only ones that notify the debugger
- // are error reporting and recovery. Hence we can afford to
- // check and see if the debugger interface is null or not
- // there. If there is ever an occasion for a performance
- // sensitive function to use the debugger interface, then
- // a replacement function for debug mode should be supplied
- // and installed here.
- //
- this->get_rec()->set_debugger(dbg);
-
- // If there was a tokenstream installed already
- // then we need to tell it about the debug interface
- //
- if (this->get_tstream() != NULL)
- {
- this->get_tstream()->setDebugListener(dbg);
- }
+void Parser<ImplTraits>::setDebugListener(DebugEventListenerType* dbg)
+{
+ // Set the debug listener. There are no methods to override
+ // because currently the only ones that notify the debugger
+ // are error reporting and recovery. Hence we can afford to
+ // check and see if the debugger interface is null or not
+ // there. If there is ever an occasion for a performance
+ // sensitive function to use the debugger interface, then
+ // a replacement function for debug mode should be supplied
+ // and installed here.
+ //
+ this->get_rec()->set_debugger(dbg);
+
+ // If there was a tokenstream installed already
+ // then we need to tell it about the debug interface
+ //
+ if (this->get_tstream() != NULL)
+ {
+ this->get_tstream()->setDebugListener(dbg);
+ }
}
template< class ImplTraits >
-ANTLR_INLINE void Parser<ImplTraits>::setTokenStream(TokenStreamType* tstream)
+ANTLR_INLINE void Parser<ImplTraits>::setTokenStream(TokenStreamType* tstream)
{
- m_tstream = tstream;
+ m_tstream = tstream;
this->get_rec()->reset();
}
template< class ImplTraits >
-ANTLR_INLINE typename Parser<ImplTraits>::TokenStreamType* Parser<ImplTraits>::getTokenStream()
+ANTLR_INLINE typename Parser<ImplTraits>::TokenStreamType* Parser<ImplTraits>::getTokenStream()
{
- return m_tstream;
+ return m_tstream;
}
template< class ImplTraits >
ANTLR_INLINE typename Parser<ImplTraits>::RecognizerType* Parser<ImplTraits>::get_rec()
{
- return this;
+ return this;
}
template< class ImplTraits >
ANTLR_INLINE void Parser<ImplTraits>::exConstruct()
{
- new ANTLR_Exception<ImplTraits, MISMATCHED_TOKEN_EXCEPTION, StreamType>( this->get_rec(), "" );
+ new ANTLR_Exception<ImplTraits, MISMATCHED_TOKEN_EXCEPTION, StreamType>( this->get_rec(), "" );
}
template< class ImplTraits >
-typename Parser<ImplTraits>::TokenType* Parser<ImplTraits>::getMissingSymbol( IntStreamType* istream,
- ExceptionBaseType*,
- ANTLR_UINT32 expectedTokenType,
- BitsetListType* )
-{
- // Dereference the standard pointers
- //
- TokenStreamType *cts = static_cast<TokenStreamType*>(istream);
-
- // Work out what to use as the current symbol to make a line and offset etc
- // If we are at EOF, we use the token before EOF
- //
- const CommonTokenType* current = cts->LT(1);
- if (current->get_type() == CommonTokenType::TOKEN_EOF)
- {
- current = cts->LT(-1);
- }
-
- CommonTokenType* token = new CommonTokenType;
-
- // Set some of the token properties based on the current token
- //
- token->set_line(current->get_line());
- token->set_charPositionInLine( current->get_charPositionInLine());
- token->set_channel( TOKEN_DEFAULT_CHANNEL );
- token->set_type(expectedTokenType);
- token->set_lineStart( current->get_lineStart() );
-
- // Create the token text that shows it has been inserted
- //
- if ( expectedTokenType == CommonTokenType::TOKEN_EOF )
- {
- token->setText( "<missing EOF>" );
- } else {
- typename ImplTraits::StringStreamType text;
- text << "<missing " << this->get_rec()->get_state()->get_tokenName(expectedTokenType) << ">";
- token->setText( text.str().c_str() );
- }
- // Finally return the pointer to our new token
- //
- return token;
+typename Parser<ImplTraits>::TokenType* Parser<ImplTraits>::getMissingSymbol( IntStreamType* istream,
+ ExceptionBaseType*,
+ ANTLR_UINT32 expectedTokenType,
+ BitsetListType* )
+{
+ // Dereference the standard pointers
+ //
+ TokenStreamType *cts = static_cast<TokenStreamType*>(istream);
+
+ // Work out what to use as the current symbol to make a line and offset etc
+ // If we are at EOF, we use the token before EOF
+ //
+ const CommonTokenType* current = cts->LT(1);
+ if (current->get_type() == CommonTokenType::TOKEN_EOF)
+ {
+ current = cts->LT(-1);
+ }
+
+ CommonTokenType* token = new CommonTokenType;
+
+ // Set some of the token properties based on the current token
+ //
+ token->set_line(current->get_line());
+ token->set_charPositionInLine( current->get_charPositionInLine());
+ token->set_channel( TOKEN_DEFAULT_CHANNEL );
+ token->set_type(expectedTokenType);
+ token->set_lineStart( current->get_lineStart() );
+
+ // Create the token text that shows it has been inserted
+ //
+ if ( expectedTokenType == CommonTokenType::TOKEN_EOF )
+ {
+ token->setText( "<missing EOF>" );
+ } else {
+ typename ImplTraits::StringStreamType text;
+ text << "<missing " << this->get_rec()->get_state()->get_tokenName(expectedTokenType) << ">";
+ token->setText( text.str().c_str() );
+ }
+ // Finally return the pointer to our new token
+ //
+ return token;
}
template< class ImplTraits >
@@ -236,106 +236,106 @@ void Parser<ImplTraits>::mismatch(ANTLR_UINT32 ttype, BitsetListType* follow)
{
// Install a mismatched token exception in the exception stack
//
- new ANTLR_Exception<ImplTraits, MISMATCHED_TOKEN_EXCEPTION, StreamType>(this, "");
+ new ANTLR_Exception<ImplTraits, MISMATCHED_TOKEN_EXCEPTION, StreamType>(this, "");
- //With the statement below, only the parsers are allowed to compile fine
- IntStreamType* is = this->get_istream();
+ //With the statement below, only the parsers are allowed to compile fine
+ IntStreamType* is = this->get_istream();
- if (this->mismatchIsUnwantedToken(is, ttype))
- {
- // Now update it to indicate this is an unwanted token exception
- //
- new ANTLR_Exception<ImplTraits, UNWANTED_TOKEN_EXCEPTION, StreamType>(this, "");
- return;
- }
+ if (this->mismatchIsUnwantedToken(is, ttype))
+ {
+ // Now update it to indicate this is an unwanted token exception
+ //
+ new ANTLR_Exception<ImplTraits, UNWANTED_TOKEN_EXCEPTION, StreamType>(this, "");
+ return;
+ }
- if ( this->mismatchIsMissingToken(is, follow))
- {
- // Now update it to indicate this is an unwanted token exception
- //
- new ANTLR_Exception<ImplTraits, MISSING_TOKEN_EXCEPTION, StreamType>(this, "");
- return;
- }
+ if ( this->mismatchIsMissingToken(is, follow))
+ {
+ // Now update it to indicate this is an unwanted token exception
+ //
+ new ANTLR_Exception<ImplTraits, MISSING_TOKEN_EXCEPTION, StreamType>(this, "");
+ return;
+ }
- // Just a mismatched token is all we can dtermine
- //
- new ANTLR_Exception<ImplTraits, MISMATCHED_TOKEN_EXCEPTION, StreamType>(this, "");
+ // Just a mismatched token is all we can dtermine
+ //
+ new ANTLR_Exception<ImplTraits, MISMATCHED_TOKEN_EXCEPTION, StreamType>(this, "");
- return;
+ return;
}
template< class ImplTraits>
ANTLR_INLINE const typename Parser<ImplTraits>::RecognizerType* Parser<ImplTraits>::get_recognizer() const
{
- return this;
+ return this;
}
template< class ImplTraits>
ANTLR_INLINE typename Parser<ImplTraits>::RecognizerSharedStateType* Parser<ImplTraits>::get_psrstate() const
{
- return this->get_recognizer()->get_state();
+ return this->get_recognizer()->get_state();
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::set_psrstate(RecognizerSharedStateType* state)
{
- this->get_rec()->set_state( state );
+ this->get_rec()->set_state( state );
}
template< class ImplTraits>
-ANTLR_INLINE bool Parser<ImplTraits>::haveParsedRule(ANTLR_MARKER ruleIndex)
+ANTLR_INLINE bool Parser<ImplTraits>::haveParsedRule(ANTLR_MARKER ruleIndex)
{
- return this->get_rec()->alreadyParsedRule(ruleIndex);
+ return this->get_rec()->alreadyParsedRule(ruleIndex);
}
template< class ImplTraits>
-ANTLR_INLINE void Parser<ImplTraits>::memoize(ANTLR_MARKER ruleIndex, ANTLR_MARKER ruleParseStart)
+ANTLR_INLINE void Parser<ImplTraits>::memoize(ANTLR_MARKER ruleIndex, ANTLR_MARKER ruleParseStart)
{
- return this->get_rec()->memoize( ruleIndex, ruleParseStart );
+ return this->get_rec()->memoize( ruleIndex, ruleParseStart );
}
template< class ImplTraits>
ANTLR_INLINE ANTLR_MARKER Parser<ImplTraits>::index() const
{
- return this->get_istream()->index();
+ return this->get_istream()->index();
}
template< class ImplTraits>
ANTLR_INLINE bool Parser<ImplTraits>::hasException() const
{
- return this->get_psrstate()->get_error();
+ return this->get_psrstate()->get_error();
}
template< class ImplTraits>
ANTLR_INLINE typename Parser<ImplTraits>::ExceptionBaseType* Parser<ImplTraits>::get_exception() const
{
- return this->get_psrstate()->get_exception();
+ return this->get_psrstate()->get_exception();
}
template< class ImplTraits>
ANTLR_INLINE const typename Parser<ImplTraits>::CommonTokenType* Parser<ImplTraits>::matchToken( ANTLR_UINT32 ttype, BitsetListType* follow )
{
- return this->get_rec()->match( ttype, follow );
+ return this->get_rec()->match( ttype, follow );
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::matchAnyToken()
{
- return this->get_rec()->matchAny();
+ return this->get_rec()->matchAny();
}
template< class ImplTraits>
ANTLR_INLINE const typename Parser<ImplTraits>::FollowingType& Parser<ImplTraits>::get_follow_stack() const
{
- return this->get_psrstate()->get_following();
+ return this->get_psrstate()->get_following();
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::followPush(const BitsetListType& follow)
{
#ifndef SKIP_FOLLOW_SETS
- this->get_rec()->get_state()->get_following().push(follow);
+ this->get_rec()->get_state()->get_following().push(follow);
#endif
}
@@ -343,174 +343,174 @@ template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::followPop()
{
#ifndef SKIP_FOLLOW_SETS
- this->get_rec()->get_state()->get_following().pop();
+ this->get_rec()->get_state()->get_following().pop();
#endif
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::precover()
{
- return this->get_rec()->recover();
+ return this->get_rec()->recover();
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::preporterror()
{
- return this->get_rec()->reportError();
+ return this->get_rec()->reportError();
}
template< class ImplTraits>
ANTLR_INLINE ANTLR_UINT32 Parser<ImplTraits>::LA(ANTLR_INT32 i)
{
- return this->get_istream()->LA(i);
+ return this->get_istream()->LA(i);
}
template< class ImplTraits>
ANTLR_INLINE const typename Parser<ImplTraits>::CommonTokenType* Parser<ImplTraits>::LT(ANTLR_INT32 k)
{
- return this->get_input()->LT(k);
+ return this->get_input()->LT(k);
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::constructEx()
{
- this->get_rec()->constructEx();
+ this->get_rec()->constructEx();
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::consume()
{
- this->get_istream()->consume();
+ this->get_istream()->consume();
}
template< class ImplTraits>
ANTLR_INLINE ANTLR_MARKER Parser<ImplTraits>::mark()
{
- return this->get_istream()->mark();
+ return this->get_istream()->mark();
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::rewind(ANTLR_MARKER marker)
{
- this->get_istream()->rewind(marker);
+ this->get_istream()->rewind(marker);
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::rewindLast()
{
- this->get_istream()->rewindLast();
+ this->get_istream()->rewindLast();
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::seek(ANTLR_MARKER index)
{
- this->get_istream()->seek(index);
+ this->get_istream()->seek(index);
}
template< class ImplTraits>
ANTLR_INLINE bool Parser<ImplTraits>::get_perror_recovery() const
{
- return this->get_psrstate()->get_errorRecovery();
+ return this->get_psrstate()->get_errorRecovery();
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::set_perror_recovery( bool val )
{
- this->get_psrstate()->set_errorRecovery(val);
+ this->get_psrstate()->set_errorRecovery(val);
}
template< class ImplTraits>
ANTLR_INLINE bool Parser<ImplTraits>::hasFailed() const
{
- return this->get_psrstate()->get_failed();
+ return this->get_psrstate()->get_failed();
}
template< class ImplTraits>
ANTLR_INLINE bool Parser<ImplTraits>::get_failedflag() const
{
- return this->get_psrstate()->get_failed();
+ return this->get_psrstate()->get_failed();
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::set_failedflag( bool failed )
{
- this->get_psrstate()->set_failed(failed);
+ this->get_psrstate()->set_failed(failed);
}
template< class ImplTraits>
ANTLR_INLINE ANTLR_INT32 Parser<ImplTraits>::get_backtracking() const
{
- return this->get_psrstate()->get_backtracking();
+ return this->get_psrstate()->get_backtracking();
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::inc_backtracking()
{
- this->get_psrstate()->inc_backtracking();
+ this->get_psrstate()->inc_backtracking();
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::dec_backtracking()
{
- this->get_psrstate()->dec_backtracking();
+ this->get_psrstate()->dec_backtracking();
}
template< class ImplTraits>
-ANTLR_INLINE typename Parser<ImplTraits>::CommonTokenType* Parser<ImplTraits>::recoverFromMismatchedSet(BitsetListType* follow)
+ANTLR_INLINE typename Parser<ImplTraits>::CommonTokenType* Parser<ImplTraits>::recoverFromMismatchedSet(BitsetListType* follow)
{
- return this->get_rec()->recoverFromMismatchedSet(follow);
+ return this->get_rec()->recoverFromMismatchedSet(follow);
}
template< class ImplTraits>
-ANTLR_INLINE bool Parser<ImplTraits>::recoverFromMismatchedElement(BitsetListType* follow)
+ANTLR_INLINE bool Parser<ImplTraits>::recoverFromMismatchedElement(BitsetListType* follow)
{
- return this->get_rec()->recoverFromMismatchedElement(follow);
+ return this->get_rec()->recoverFromMismatchedElement(follow);
}
template< class ImplTraits>
ANTLR_INLINE typename Parser<ImplTraits>::RuleMemoType* Parser<ImplTraits>::getRuleMemo() const
{
- return this->get_psrstate()->get_ruleMemo();
+ return this->get_psrstate()->get_ruleMemo();
}
template< class ImplTraits>
ANTLR_INLINE void Parser<ImplTraits>::setRuleMemo(RuleMemoType* rulememo)
{
- this->get_psrstate()->set_ruleMemo(rulememo);
+ this->get_psrstate()->set_ruleMemo(rulememo);
}
template< class ImplTraits>
ANTLR_INLINE typename Parser<ImplTraits>::DebuggerType* Parser<ImplTraits>::get_debugger() const
{
- return this->get_rec()->get_debugger();
+ return this->get_rec()->get_debugger();
}
template< class ImplTraits>
ANTLR_INLINE typename Parser<ImplTraits>::TokenStreamType* Parser<ImplTraits>::get_strstream() const
{
- return this->get_tstream();
+ return this->get_tstream();
}
template< class ImplTraits>
-ANTLR_INLINE RuleReturnValue<ImplTraits>::RuleReturnValue(BaseParserType* /*psr*/)
+ANTLR_INLINE RuleReturnValue<ImplTraits>::RuleReturnValue(BaseParserType* /*psr*/)
{
- start = NULL;
- stop = NULL;
+ start = NULL;
+ stop = NULL;
}
template< class ImplTraits>
ANTLR_INLINE RuleReturnValue<ImplTraits>::RuleReturnValue( const RuleReturnValue& val )
{
- start = val.start;
- stop = val.stop;
+ start = val.start;
+ stop = val.stop;
}
template< class ImplTraits>
ANTLR_INLINE RuleReturnValue<ImplTraits>& RuleReturnValue<ImplTraits>::operator=( const RuleReturnValue& val )
{
- start = val.start;
- stop = val.stop;
- return *this;
+ start = val.start;
+ stop = val.stop;
+ return *this;
}
template< class ImplTraits>
@@ -519,61 +519,61 @@ ANTLR_INLINE RuleReturnValue<ImplTraits>::~RuleReturnValue()
}
template< class ImplTraits>
-ANTLR_INLINE void RuleReturnValue<ImplTraits>::call_start_placeholder(BaseParserType *parser)
+ANTLR_INLINE void RuleReturnValue<ImplTraits>::call_start_placeholder(BaseParserType *parser)
{
- start = parser->LT(1);
- stop = start;
+ start = parser->LT(1);
+ stop = start;
}
template< class ImplTraits>
-ANTLR_INLINE void RuleReturnValue<ImplTraits>::call_stop_placeholder(BaseParserType *parser)
+ANTLR_INLINE void RuleReturnValue<ImplTraits>::call_stop_placeholder(BaseParserType *parser)
{
- stop = parser->LT(-1);
+ stop = parser->LT(-1);
}
template< class ImplTraits>
ANTLR_INLINE RuleReturnValue_1<ImplTraits>::RuleReturnValue_1()
- : parser()
+ : parser()
{
}
template< class ImplTraits>
RuleReturnValue_1<ImplTraits>::RuleReturnValue_1( BaseParserType* psr )
- : RuleReturnValue_1<ImplTraits>::BaseType(psr)
- , parser(psr)
+ : RuleReturnValue_1<ImplTraits>::BaseType(psr)
+ , parser(psr)
{
- BaseType::start = psr->LT(1);
- BaseType::stop = BaseType::start;
+ BaseType::start = psr->LT(1);
+ BaseType::stop = BaseType::start;
}
template< class ImplTraits>
RuleReturnValue_1<ImplTraits>::RuleReturnValue_1( const RuleReturnValue_1& val )
- : RuleReturnValue_1<ImplTraits>::BaseType(val)
- , parser(val.parser)
+ : RuleReturnValue_1<ImplTraits>::BaseType(val)
+ , parser(val.parser)
{
}
template< class ImplTraits>
-void RuleReturnValue_1<ImplTraits>::call_start_placeholder(BaseParserType*)
+void RuleReturnValue_1<ImplTraits>::call_start_placeholder(BaseParserType*)
{
}
template< class ImplTraits>
RuleReturnValue_1<ImplTraits>::~RuleReturnValue_1()
{
- if( parser && parser->get_backtracking() == 0 )
- {
- if( BaseType::stop == NULL )
- BaseType::stop = BaseType::parser->LT(-1);
- if( BaseType::stop != NULL )
- {
- ANTLR_MARKER start_token_idx = BaseType::start->get_index() + 1;
- ANTLR_MARKER stop_token_idx = BaseType::stop->get_index() - 1;
- if( start_token_idx > stop_token_idx )
- return;
- parser->getTokenStream()->discardTokens( start_token_idx, stop_token_idx);
- }
- }
-}
-
-}
+ if( parser && parser->get_backtracking() == 0 )
+ {
+ if( BaseType::stop == NULL )
+ BaseType::stop = BaseType::parser->LT(-1);
+ if( BaseType::stop != NULL )
+ {
+ ANTLR_MARKER start_token_idx = BaseType::start->get_index() + 1;
+ ANTLR_MARKER stop_token_idx = BaseType::stop->get_index() - 1;
+ if( start_token_idx > stop_token_idx )
+ return;
+ parser->getTokenStream()->discardTokens( start_token_idx, stop_token_idx);
+ }
+ }
+}
+
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3recognizersharedstate.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3recognizersharedstate.hpp
index c391c1bd8d..ef0855ea08 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3recognizersharedstate.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3recognizersharedstate.hpp
@@ -11,8 +11,8 @@
* imports another.
*/
-#ifndef _ANTLR3_RECOGNIZER_SHARED_STATE_HPP
-#define _ANTLR3_RECOGNIZER_SHARED_STATE_HPP
+#ifndef _ANTLR3_RECOGNIZER_SHARED_STATE_HPP
+#define _ANTLR3_RECOGNIZER_SHARED_STATE_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -42,7 +42,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-namespace antlr3 {
+namespace antlr3 {
/** All the data elements required to track the current state
* of any recognizer (lexer, parser, tree parser).
@@ -53,89 +53,89 @@ template<class ImplTraits, class StreamType>
class RecognizerSharedState : public ImplTraits::AllocPolicyType
{
public:
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename StreamType::UnitType TokenType;
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
-
- typedef typename ComponentTypeFinder<ImplTraits, StreamType>::ComponentType ComponentType;
- typedef typename ImplTraits::template RewriteStreamType< ComponentType > RewriteStreamType;
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::TokenSourceType TokenSourceType;
- typedef typename ImplTraits::template ExceptionBaseType<StreamType> ExceptionBaseType;
- typedef typename ImplTraits::BitsetType BitsetType;
- typedef typename ImplTraits::BitsetListType BitsetListType;
-
- typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
-
- typedef typename AllocPolicyType::template StackType< BitsetListType > FollowingType;
- typedef typename AllocPolicyType::template StackType< typename ImplTraits::InputStreamType* > InputStreamsType;
- typedef InputStreamsType StreamsType;
- typedef typename AllocPolicyType::template VectorType<RewriteStreamType> RewriteStreamsType;
-
- typedef IntTrie<ImplTraits, ANTLR_MARKER> RuleListType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename StreamType::UnitType TokenType;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
+
+ typedef typename ComponentTypeFinder<ImplTraits, StreamType>::ComponentType ComponentType;
+ typedef typename ImplTraits::template RewriteStreamType< ComponentType > RewriteStreamType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::TokenSourceType TokenSourceType;
+ typedef typename ImplTraits::template ExceptionBaseType<StreamType> ExceptionBaseType;
+ typedef typename ImplTraits::BitsetType BitsetType;
+ typedef typename ImplTraits::BitsetListType BitsetListType;
+
+ typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
+
+ typedef typename AllocPolicyType::template StackType< BitsetListType > FollowingType;
+ typedef typename AllocPolicyType::template StackType< typename ImplTraits::InputStreamType* > InputStreamsType;
+ typedef InputStreamsType StreamsType;
+ typedef typename AllocPolicyType::template VectorType<RewriteStreamType> RewriteStreamsType;
+
+ typedef IntTrie<ImplTraits, ANTLR_MARKER> RuleListType;
typedef IntTrie<ImplTraits, std::shared_ptr<RuleListType>> RuleMemoType;
private:
- /** Points to the first in a possible chain of exceptions that the
+ /** Points to the first in a possible chain of exceptions that the
* recognizer has discovered.
*/
- ExceptionBaseType* m_exception;
+ ExceptionBaseType* m_exception;
/** Track the set of token types that can follow any rule invocation.
* Stack structure, to support: List<BitSet>.
*/
- FollowingType m_following;
+ FollowingType m_following;
/** Track around a hint from the creator of the recognizer as to how big this
* thing is going to get, as the actress said to the bishop. This allows us
* to tune hash tables accordingly. This might not be the best place for this
* in the end but we will see.
*/
- ANTLR_UINT32 m_sizeHint;
+ ANTLR_UINT32 m_sizeHint;
/** If set to true then the recognizer has an exception
* condition (this is tested by the generated code for the rules of
* the grammar).
*/
- bool m_error;
+ bool m_error;
/** This is true when we see an error and before having successfully
* matched a token. Prevents generation of more than one error message
* per error.
*/
- bool m_errorRecovery;
+ bool m_errorRecovery;
- /** In lieu of a return value, this indicates that a rule or token
+ /** In lieu of a return value, this indicates that a rule or token
* has failed to match. Reset to false upon valid token match.
*/
- bool m_failed;
+ bool m_failed;
- /*
- Instead of allocating CommonTokenType, we do it in the stack. hence we need a null indicator
- */
- bool m_token_present;
+ /*
+ Instead of allocating CommonTokenType, we do it in the stack. hence we need a null indicator
+ */
+ bool m_token_present;
/** The index into the input stream where the last error occurred.
- * This is used to prevent infinite loops where an error is found
+ * This is used to prevent infinite loops where an error is found
* but no token is consumed during recovery...another error is found,
* ad nauseam. This is a failsafe mechanism to guarantee that at least
* one token/tree node is consumed for two errors.
*/
- ANTLR_MARKER m_lastErrorIndex;
+ ANTLR_MARKER m_lastErrorIndex;
/** When the recognizer terminates, the error handling functions
* will have incremented this value if any error occurred (that was displayed). It can then be
* used by the grammar programmer without having to use static globals.
*/
- ANTLR_UINT32 m_errorCount;
+ ANTLR_UINT32 m_errorCount;
/** If 0, no backtracking is going on. Safe to exec actions etc...
* If >0 then it's the level of backtracking.
*/
- ANTLR_INT32 m_backtracking;
+ ANTLR_INT32 m_backtracking;
/** ANTLR3_VECTOR of ANTLR3_LIST for rule memoizing.
* Tracks the stop token index for each rule. ruleMemo[ruleIndex] is
@@ -144,7 +144,7 @@ private:
*
* This is only used if rule memoization is on.
*/
- RuleMemoType* m_ruleMemo;
+ RuleMemoType* m_ruleMemo;
/** Pointer to an array of token names
* that are generally useful in error reporting. The generated parsers install
@@ -152,7 +152,7 @@ private:
* at parser compile time - grammar token names are thus restricted in character
* sets, which does not seem to terrible.
*/
- ANTLR_UINT8** m_tokenNames;
+ ANTLR_UINT8** m_tokenNames;
/** The goal of all lexer rules/methods is to create a token object.
* This is an instance variable as multiple rules may collaborate to
@@ -160,110 +160,110 @@ private:
* In this case, you want the INT or FLOAT rule to set token and not
* have it reset to a NUM token in rule NUM.
*/
- CommonTokenType m_token;
+ CommonTokenType m_token;
/** A lexer is a source of tokens, produced by all the generated (or
* hand crafted if you like) matching rules. As such it needs to provide
* a token source interface implementation. For others, this will become a empty class
*/
- TokenSourceType* m_tokSource;
+ TokenSourceType* m_tokSource;
/** The channel number for the current token
*/
- ANTLR_UINT32 m_channel;
+ ANTLR_UINT32 m_channel;
/** The token type for the current token
*/
- ANTLR_UINT32 m_type;
+ ANTLR_UINT32 m_type;
/** The input line (where it makes sense) on which the first character of the current
* token resides.
*/
- ANTLR_INT32 m_tokenStartLine;
+ ANTLR_INT32 m_tokenStartLine;
/** The character position of the first character of the current token
* within the line specified by tokenStartLine
*/
- ANTLR_INT32 m_tokenStartCharPositionInLine;
+ ANTLR_INT32 m_tokenStartCharPositionInLine;
/** What character index in the stream did the current token start at?
* Needed, for example, to get the text for current token. Set at
* the start of nextToken.
*/
- ANTLR_MARKER m_tokenStartCharIndex;
+ ANTLR_MARKER m_tokenStartCharIndex;
/** Text for the current token. This can be overridden by setting this
* variable directly or by using the SETTEXT() macro (preferred) in your
* lexer rules.
*/
- StringType m_text;
+ StringType m_text;
/** Input stream stack, which allows the C programmer to switch input streams
* easily and allow the standard nextToken() implementation to deal with it
* as this is a common requirement.
*/
- InputStreamsType m_streams;
+ InputStreamsType m_streams;
+
+ /** Tree adaptor drives an AST trie construction.
+ * Is shared between multiple imported grammars.
+ */
+ TreeAdaptorType* m_treeAdaptor;
- /** Tree adaptor drives an AST trie construction.
- * Is shared between multiple imported grammars.
- */
- TreeAdaptorType* m_treeAdaptor;
-
public:
- RecognizerSharedState();
- ExceptionBaseType* get_exception() const;
- FollowingType& get_following();
- ANTLR_UINT32 get_sizeHint() const;
- bool get_error() const;
- bool get_errorRecovery() const;
- bool get_failed() const;
- bool get_token_present() const;
- ANTLR_MARKER get_lastErrorIndex() const;
- ANTLR_UINT32 get_errorCount() const;
- ANTLR_INT32 get_backtracking() const;
- RuleMemoType* get_ruleMemo() const;
- ANTLR_UINT8** get_tokenNames() const;
- ANTLR_UINT8* get_tokenName( ANTLR_UINT32 i ) const;
- CommonTokenType* get_token();
- TokenSourceType* get_tokSource() const;
- ANTLR_UINT32& get_channel();
- ANTLR_UINT32 get_type() const;
- ANTLR_INT32 get_tokenStartLine() const;
- ANTLR_INT32 get_tokenStartCharPositionInLine() const;
- ANTLR_MARKER get_tokenStartCharIndex() const;
- StringType& get_text();
- InputStreamsType& get_streams();
- TreeAdaptorType* get_treeAdaptor() const;
-
- void set_following( const FollowingType& following );
- void set_sizeHint( ANTLR_UINT32 sizeHint );
- void set_error( bool error );
- void set_errorRecovery( bool errorRecovery );
- void set_failed( bool failed );
- void set_token_present(bool token_present);
- void set_lastErrorIndex( ANTLR_MARKER lastErrorIndex );
- void set_errorCount( ANTLR_UINT32 errorCount );
- void set_backtracking( ANTLR_INT32 backtracking );
- void set_ruleMemo( RuleMemoType* ruleMemo );
- void set_tokenNames( ANTLR_UINT8** tokenNames );
- void set_tokSource( TokenSourceType* tokSource );
- void set_channel( ANTLR_UINT32 channel );
- void set_exception( ExceptionBaseType* exception );
- void set_type( ANTLR_UINT32 type );
- void set_token( const CommonTokenType* tok);
- void set_tokenStartLine( ANTLR_INT32 tokenStartLine );
- void set_tokenStartCharPositionInLine( ANTLR_INT32 tokenStartCharPositionInLine );
- void set_tokenStartCharIndex( ANTLR_MARKER tokenStartCharIndex );
- void set_text( const StringType& text );
- void set_streams( const InputStreamsType& streams );
- void set_treeAdaptor( TreeAdaptorType* adaptor );
-
- void inc_errorCount();
- void inc_backtracking();
- void dec_backtracking();
+ RecognizerSharedState();
+ ExceptionBaseType* get_exception() const;
+ FollowingType& get_following();
+ ANTLR_UINT32 get_sizeHint() const;
+ bool get_error() const;
+ bool get_errorRecovery() const;
+ bool get_failed() const;
+ bool get_token_present() const;
+ ANTLR_MARKER get_lastErrorIndex() const;
+ ANTLR_UINT32 get_errorCount() const;
+ ANTLR_INT32 get_backtracking() const;
+ RuleMemoType* get_ruleMemo() const;
+ ANTLR_UINT8** get_tokenNames() const;
+ ANTLR_UINT8* get_tokenName( ANTLR_UINT32 i ) const;
+ CommonTokenType* get_token();
+ TokenSourceType* get_tokSource() const;
+ ANTLR_UINT32& get_channel();
+ ANTLR_UINT32 get_type() const;
+ ANTLR_INT32 get_tokenStartLine() const;
+ ANTLR_INT32 get_tokenStartCharPositionInLine() const;
+ ANTLR_MARKER get_tokenStartCharIndex() const;
+ StringType& get_text();
+ InputStreamsType& get_streams();
+ TreeAdaptorType* get_treeAdaptor() const;
+
+ void set_following( const FollowingType& following );
+ void set_sizeHint( ANTLR_UINT32 sizeHint );
+ void set_error( bool error );
+ void set_errorRecovery( bool errorRecovery );
+ void set_failed( bool failed );
+ void set_token_present(bool token_present);
+ void set_lastErrorIndex( ANTLR_MARKER lastErrorIndex );
+ void set_errorCount( ANTLR_UINT32 errorCount );
+ void set_backtracking( ANTLR_INT32 backtracking );
+ void set_ruleMemo( RuleMemoType* ruleMemo );
+ void set_tokenNames( ANTLR_UINT8** tokenNames );
+ void set_tokSource( TokenSourceType* tokSource );
+ void set_channel( ANTLR_UINT32 channel );
+ void set_exception( ExceptionBaseType* exception );
+ void set_type( ANTLR_UINT32 type );
+ void set_token( const CommonTokenType* tok);
+ void set_tokenStartLine( ANTLR_INT32 tokenStartLine );
+ void set_tokenStartCharPositionInLine( ANTLR_INT32 tokenStartCharPositionInLine );
+ void set_tokenStartCharIndex( ANTLR_MARKER tokenStartCharIndex );
+ void set_text( const StringType& text );
+ void set_streams( const InputStreamsType& streams );
+ void set_treeAdaptor( TreeAdaptorType* adaptor );
+
+ void inc_errorCount();
+ void inc_backtracking();
+ void dec_backtracking();
};
-}
+}
#include "antlr3recognizersharedstate.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3recognizersharedstate.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3recognizersharedstate.inl
index 29e535800f..27732cb34f 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3recognizersharedstate.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3recognizersharedstate.inl
@@ -1,280 +1,280 @@
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits, class StreamType>
RecognizerSharedState<ImplTraits, StreamType>::RecognizerSharedState()
{
- m_exception = NULL;
- m_sizeHint = 0;
- m_error = false;
- m_errorRecovery = false;
- m_failed = false;
+ m_exception = NULL;
+ m_sizeHint = 0;
+ m_error = false;
+ m_errorRecovery = false;
+ m_failed = false;
m_token_present = false;
- m_lastErrorIndex = 0;
- m_errorCount = 0;
- m_backtracking = false;
- m_ruleMemo = NULL;
- m_tokenNames = NULL;
- m_tokSource = NULL;
- m_channel = 0;
- m_type = 0;
- m_tokenStartLine = 0;
- m_tokenStartCharPositionInLine = 0;
- m_tokenStartCharIndex = 0;
- m_treeAdaptor = NULL;
+ m_lastErrorIndex = 0;
+ m_errorCount = 0;
+ m_backtracking = false;
+ m_ruleMemo = NULL;
+ m_tokenNames = NULL;
+ m_tokSource = NULL;
+ m_channel = 0;
+ m_type = 0;
+ m_tokenStartLine = 0;
+ m_tokenStartCharPositionInLine = 0;
+ m_tokenStartCharIndex = 0;
+ m_treeAdaptor = NULL;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename RecognizerSharedState<ImplTraits, StreamType>::FollowingType& RecognizerSharedState<ImplTraits, StreamType>::get_following()
{
- return m_following;
+ return m_following;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_UINT32 RecognizerSharedState<ImplTraits, StreamType>::get_sizeHint() const
{
- return m_sizeHint;
+ return m_sizeHint;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE bool RecognizerSharedState<ImplTraits, StreamType>::get_error() const
{
- return m_error;
+ return m_error;
}
template<class ImplTraits, class StreamType>
-ANTLR_INLINE typename RecognizerSharedState<ImplTraits, StreamType>::ExceptionBaseType*
+ANTLR_INLINE typename RecognizerSharedState<ImplTraits, StreamType>::ExceptionBaseType*
RecognizerSharedState<ImplTraits, StreamType>::get_exception() const
{
- return m_exception;
+ return m_exception;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE bool RecognizerSharedState<ImplTraits, StreamType>::get_errorRecovery() const
{
- return m_errorRecovery;
+ return m_errorRecovery;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE bool RecognizerSharedState<ImplTraits, StreamType>::get_failed() const
{
- return m_failed;
+ return m_failed;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE bool RecognizerSharedState<ImplTraits, StreamType>::get_token_present() const
{
- return m_token_present;
+ return m_token_present;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_MARKER RecognizerSharedState<ImplTraits, StreamType>::get_lastErrorIndex() const
{
- return m_lastErrorIndex;
+ return m_lastErrorIndex;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_UINT32 RecognizerSharedState<ImplTraits, StreamType>::get_errorCount() const
{
- return m_errorCount;
+ return m_errorCount;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_INT32 RecognizerSharedState<ImplTraits, StreamType>::get_backtracking() const
{
- return m_backtracking;
+ return m_backtracking;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename RecognizerSharedState<ImplTraits, StreamType>::RuleMemoType* RecognizerSharedState<ImplTraits, StreamType>::get_ruleMemo() const
{
- return m_ruleMemo;
+ return m_ruleMemo;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_UINT8** RecognizerSharedState<ImplTraits, StreamType>::get_tokenNames() const
{
- return m_tokenNames;
+ return m_tokenNames;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_UINT8* RecognizerSharedState<ImplTraits, StreamType>::get_tokenName( ANTLR_UINT32 i ) const
{
- return m_tokenNames[i];
+ return m_tokenNames[i];
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename RecognizerSharedState<ImplTraits, StreamType>::CommonTokenType* RecognizerSharedState<ImplTraits, StreamType>::get_token()
{
- return &m_token;
+ return &m_token;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename RecognizerSharedState<ImplTraits, StreamType>::TokenSourceType* RecognizerSharedState<ImplTraits, StreamType>::get_tokSource() const
{
- return m_tokSource;
+ return m_tokSource;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_UINT32& RecognizerSharedState<ImplTraits, StreamType>::get_channel()
{
- return m_channel;
+ return m_channel;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_UINT32 RecognizerSharedState<ImplTraits, StreamType>::get_type() const
{
- return m_type;
+ return m_type;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_INT32 RecognizerSharedState<ImplTraits, StreamType>::get_tokenStartLine() const
{
- return m_tokenStartLine;
+ return m_tokenStartLine;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_INT32 RecognizerSharedState<ImplTraits, StreamType>::get_tokenStartCharPositionInLine() const
{
- return m_tokenStartCharPositionInLine;
+ return m_tokenStartCharPositionInLine;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE ANTLR_MARKER RecognizerSharedState<ImplTraits, StreamType>::get_tokenStartCharIndex() const
{
- return m_tokenStartCharIndex;
+ return m_tokenStartCharIndex;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename RecognizerSharedState<ImplTraits, StreamType>::StringType& RecognizerSharedState<ImplTraits, StreamType>::get_text()
{
- return m_text;
+ return m_text;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE typename RecognizerSharedState<ImplTraits, StreamType>::StreamsType& RecognizerSharedState<ImplTraits, StreamType>::get_streams()
{
- return m_streams;
+ return m_streams;
}
template<class ImplTraits, class StreamType>
-ANTLR_INLINE typename RecognizerSharedState<ImplTraits, StreamType>::TreeAdaptorType* RecognizerSharedState<ImplTraits, StreamType>::get_treeAdaptor() const
-{
- return m_treeAdaptor;
-}
-
-template<class ImplTraits, class StreamType>
+ANTLR_INLINE typename RecognizerSharedState<ImplTraits, StreamType>::TreeAdaptorType* RecognizerSharedState<ImplTraits, StreamType>::get_treeAdaptor() const
+{
+ return m_treeAdaptor;
+}
+
+template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_exception( ExceptionBaseType* exception )
{
- m_exception = exception;
+ m_exception = exception;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_following( const FollowingType& following )
{
- m_following = following;
+ m_following = following;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_sizeHint( ANTLR_UINT32 sizeHint )
{
- m_sizeHint = sizeHint;
+ m_sizeHint = sizeHint;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_error( bool error )
{
- m_error = error;
+ m_error = error;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_errorRecovery( bool errorRecovery )
{
- m_errorRecovery = errorRecovery;
+ m_errorRecovery = errorRecovery;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_failed( bool failed )
{
- m_failed = failed;
+ m_failed = failed;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_token_present(bool token_present)
{
- m_token_present = token_present;
+ m_token_present = token_present;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_lastErrorIndex( ANTLR_MARKER lastErrorIndex )
{
- m_lastErrorIndex = lastErrorIndex;
+ m_lastErrorIndex = lastErrorIndex;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_errorCount( ANTLR_UINT32 errorCount )
{
- m_errorCount = errorCount;
+ m_errorCount = errorCount;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_backtracking( ANTLR_INT32 backtracking )
{
- m_backtracking = backtracking;
+ m_backtracking = backtracking;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_ruleMemo( RuleMemoType* ruleMemo )
{
- m_ruleMemo = ruleMemo;
+ m_ruleMemo = ruleMemo;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_tokenNames( ANTLR_UINT8** tokenNames )
{
- m_tokenNames = tokenNames;
+ m_tokenNames = tokenNames;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_tokSource( TokenSourceType* tokSource )
{
- m_tokSource = tokSource;
+ m_tokSource = tokSource;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_channel( ANTLR_UINT32 channel )
{
- m_channel = channel;
+ m_channel = channel;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_token(const CommonTokenType* tok)
{
- this->set_token_present( tok != NULL );
- if( tok != NULL )
- m_token = *tok;
+ this->set_token_present( tok != NULL );
+ if( tok != NULL )
+ m_token = *tok;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_type( ANTLR_UINT32 type )
{
- m_type = type;
+ m_type = type;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_tokenStartLine( ANTLR_INT32 tokenStartLine )
{
- m_tokenStartLine = tokenStartLine;
+ m_tokenStartLine = tokenStartLine;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_tokenStartCharPositionInLine( ANTLR_INT32 tokenStartCharPositionInLine )
{
- m_tokenStartCharPositionInLine = tokenStartCharPositionInLine;
+ m_tokenStartCharPositionInLine = tokenStartCharPositionInLine;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_tokenStartCharIndex( ANTLR_MARKER tokenStartCharIndex )
{
- m_tokenStartCharIndex = tokenStartCharIndex;
+ m_tokenStartCharIndex = tokenStartCharIndex;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_text( const StringType& text )
{
- m_text = text;
+ m_text = text;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_streams( const InputStreamsType& streams )
{
- m_streams = streams;
+ m_streams = streams;
+}
+template<class ImplTraits, class StreamType>
+ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_treeAdaptor( TreeAdaptorType* adaptor )
+{
+ m_treeAdaptor = adaptor;
}
-template<class ImplTraits, class StreamType>
-ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::set_treeAdaptor( TreeAdaptorType* adaptor )
-{
- m_treeAdaptor = adaptor;
-}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::inc_errorCount()
{
- ++m_errorCount;
+ ++m_errorCount;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::inc_backtracking()
{
- ++m_backtracking;
+ ++m_backtracking;
}
template<class ImplTraits, class StreamType>
ANTLR_INLINE void RecognizerSharedState<ImplTraits, StreamType>::dec_backtracking()
{
- --m_backtracking;
+ --m_backtracking;
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriterulesubtreestream.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriterulesubtreestream.hpp
index fbccd2aff7..db92ee0db0 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriterulesubtreestream.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriterulesubtreestream.hpp
@@ -1,123 +1,123 @@
-#ifndef ANTLR3REWRITERULESUBTREESTREAM_HPP
-#define ANTLR3REWRITERULESUBTREESTREAM_HPP
-
-// [The "BSD licence"]
-// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
-
-//
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-// 1. Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-// 3. The name of the author may not be used to endorse or promote products
-// derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-namespace antlr3 {
-
-/// This is an implementation of a subtree stream which is a set of trees
-/// modeled as an element stream.
-///
-template<class ImplTraits>
-class RewriteRuleSubtreeStream
-{
-public:
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
- typedef typename ImplTraits::TreeParserType ComponentType;
- typedef typename ComponentType::StreamType StreamType;
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
- typedef TreeType TokenType;
- typedef typename ImplTraits::template RecognizerType< StreamType > RecognizerType;
- typedef typename AllocPolicyType::template VectorType< TreeTypePtr > ElementsType;
- typedef typename ImplTraits::TreeType ElementType;
-
- RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description);
- RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description, TreeType* oneElement);
- RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description, TreeTypePtr& oneElement);
- RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements);
- ~RewriteRuleSubtreeStream();
-
- /// Reset the condition of this stream so that it appears we have
- /// not consumed any of its elements. Elements themselves are untouched.
- ///
- void reset();
-
- TreeTypePtr nextNode();
-
- /// TODO copied from RewriteRuleElementStreamType
- /// Add a new pANTLR3_BASE_TREE to this stream
- ///
- void add(TreeTypePtr& el);
- bool hasNext();
- TreeTypePtr nextTree();
- typename ElementsType::iterator _next();
- ElementType* toTree(ElementType* el);
-
- /// Number of elements available in the stream
- ///
- ANTLR_UINT32 size();
-
- /// Returns the description string if there is one available (check for NULL).
- ///
- StringType getDescription();
-
-protected:
- TreeTypePtr dup(const TreeTypePtr& el );
- TreeTypePtr dup(const TreeType* el );
-
- TreeTypePtr& leftestNode(TreeTypePtr& node) const;
-private:
- /// Pointer to the tree adaptor in use for this stream
- ///
- TreeAdaptorType* m_adaptor;
-
- /// Cursor 0..n-1. If singleElement!=NULL, cursor is 0 until you next(),
- /// which bumps it to 1 meaning no more elements.
- ///
- typename ElementsType::iterator m_cursor;
-
- /// The element or stream description; usually has name of the token or
- /// rule reference that this list tracks. Can include rulename too, but
- /// the exception would track that info.
- ///
- StringType m_elementDescription;
-
- /// The list of tokens or subtrees we are tracking
- ///
- ElementsType m_elements;
-
- TreeTypePtr dupTree(const TreeTypePtr& el );
- TreeTypePtr dupTree(const TreeType* el );
-
- /// Once a node / subtree has been used in a stream, it must be dup'ed
- /// from then on. Streams are reset after sub rules so that the streams
- /// can be reused in future sub rules. So, reset must set a dirty bit.
- /// If dirty, then next() always returns a dup.
- ///
- bool m_dirty;
-};
-
-}
-
-#include "antlr3rewriterulesubtreestream.inl"
-
-#endif
+#ifndef ANTLR3REWRITERULESUBTREESTREAM_HPP
+#define ANTLR3REWRITERULESUBTREESTREAM_HPP
+
+// [The "BSD licence"]
+// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
+
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// 3. The name of the author may not be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+namespace antlr3 {
+
+/// This is an implementation of a subtree stream which is a set of trees
+/// modeled as an element stream.
+///
+template<class ImplTraits>
+class RewriteRuleSubtreeStream
+{
+public:
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
+ typedef typename ImplTraits::TreeParserType ComponentType;
+ typedef typename ComponentType::StreamType StreamType;
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+ typedef TreeType TokenType;
+ typedef typename ImplTraits::template RecognizerType< StreamType > RecognizerType;
+ typedef typename AllocPolicyType::template VectorType< TreeTypePtr > ElementsType;
+ typedef typename ImplTraits::TreeType ElementType;
+
+ RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description);
+ RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description, TreeType* oneElement);
+ RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description, TreeTypePtr& oneElement);
+ RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements);
+ ~RewriteRuleSubtreeStream();
+
+ /// Reset the condition of this stream so that it appears we have
+ /// not consumed any of its elements. Elements themselves are untouched.
+ ///
+ void reset();
+
+ TreeTypePtr nextNode();
+
+ /// TODO copied from RewriteRuleElementStreamType
+ /// Add a new pANTLR3_BASE_TREE to this stream
+ ///
+ void add(TreeTypePtr& el);
+ bool hasNext();
+ TreeTypePtr nextTree();
+ typename ElementsType::iterator _next();
+ ElementType* toTree(ElementType* el);
+
+ /// Number of elements available in the stream
+ ///
+ ANTLR_UINT32 size();
+
+ /// Returns the description string if there is one available (check for NULL).
+ ///
+ StringType getDescription();
+
+protected:
+ TreeTypePtr dup(const TreeTypePtr& el );
+ TreeTypePtr dup(const TreeType* el );
+
+ TreeTypePtr& leftestNode(TreeTypePtr& node) const;
+private:
+ /// Pointer to the tree adaptor in use for this stream
+ ///
+ TreeAdaptorType* m_adaptor;
+
+ /// Cursor 0..n-1. If singleElement!=NULL, cursor is 0 until you next(),
+ /// which bumps it to 1 meaning no more elements.
+ ///
+ typename ElementsType::iterator m_cursor;
+
+ /// The element or stream description; usually has name of the token or
+ /// rule reference that this list tracks. Can include rulename too, but
+ /// the exception would track that info.
+ ///
+ StringType m_elementDescription;
+
+ /// The list of tokens or subtrees we are tracking
+ ///
+ ElementsType m_elements;
+
+ TreeTypePtr dupTree(const TreeTypePtr& el );
+ TreeTypePtr dupTree(const TreeType* el );
+
+ /// Once a node / subtree has been used in a stream, it must be dup'ed
+ /// from then on. Streams are reset after sub rules so that the streams
+ /// can be reused in future sub rules. So, reset must set a dirty bit.
+ /// If dirty, then next() always returns a dup.
+ ///
+ bool m_dirty;
+};
+
+}
+
+#include "antlr3rewriterulesubtreestream.inl"
+
+#endif
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriterulesubtreestream.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriterulesubtreestream.inl
index 22a0881647..b210586245 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriterulesubtreestream.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriterulesubtreestream.inl
@@ -1,244 +1,244 @@
-namespace antlr3 {
-
-template<class ImplTraits>
-RewriteRuleSubtreeStream<ImplTraits>::RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description)
- : m_adaptor(adaptor)
- , m_elementDescription(description)
- , m_dirty(false)
-{
- m_cursor = m_elements.begin();
-}
-
-template<class ImplTraits>
-RewriteRuleSubtreeStream<ImplTraits>::RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description,
- TreeType* oneElement
- )
- : m_adaptor(adaptor)
- , m_elementDescription(description)
- , m_dirty(false)
-{
- if( oneElement != NULL )
- {
- auto tree_clone = this->dup(oneElement);
- this->add( tree_clone );
- }
- m_cursor = m_elements.begin();
-}
-
-template<class ImplTraits>
-RewriteRuleSubtreeStream<ImplTraits>::RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description,
- TreeTypePtr& oneElement
- )
- : m_adaptor(adaptor)
- , m_elementDescription(description)
- , m_dirty(false)
-{
- if( oneElement != NULL )
- this->add( oneElement );
- m_cursor = m_elements.begin();
-}
-
-template<class ImplTraits>
-RewriteRuleSubtreeStream<ImplTraits>::RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description,
- const ElementsType& elements
- )
- : m_adaptor(adaptor)
- , m_elementDescription(description)
- , m_dirty(false)
- , m_elements(elements)
-{
- m_cursor = m_elements.begin();
-}
-
-template<class ImplTraits>
-void
-RewriteRuleSubtreeStream<ImplTraits>::reset()
-{
- m_cursor = m_elements.begin();
- m_dirty = true;
-}
-
-template<class ImplTraits>
-void
-RewriteRuleSubtreeStream<ImplTraits>::add(TreeTypePtr& el)
-{
- if ( el == NULL )
- return;
-
- m_elements.push_back(std::move(el));
- m_cursor = m_elements.begin();
-}
-
-template<class ImplTraits>
-typename RewriteRuleSubtreeStream<ImplTraits>::ElementsType::iterator
-RewriteRuleSubtreeStream<ImplTraits>::_next()
-{
- if (m_elements.empty())
- {
- // This means that the stream is empty
- // Caller must cope with this (TODO throw RewriteEmptyStreamException)
- return m_elements.end();
- }
-
- if (m_dirty || m_cursor == m_elements.end())
- {
- if( m_elements.size() == 1)
- {
- // Special case when size is single element, it will just dup a lot
- return m_elements.begin();
- }
-
- // Out of elements and the size is not 1, so we cannot assume
- // that we just duplicate the entry n times (such as ID ent+ -> ^(ID ent)+)
- // This means we ran out of elements earlier than was expected.
- //
- return m_elements.end(); // Caller must cope with this (TODO throw RewriteEmptyStreamException)
- }
-
- // More than just a single element so we extract it from the
- // vector.
- return m_cursor++;
-}
-
-template<class ImplTraits>
-typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
-RewriteRuleSubtreeStream<ImplTraits>::nextTree()
-{
- if ( m_dirty || ( m_cursor == m_elements.end() && m_elements.size() == 1 ))
- {
- // if out of elements and size is 1, dup
- typename ElementsType::iterator el = this->_next();
- return this->dup(*el);
- }
-
- // test size above then fetch
- typename ElementsType::iterator el = this->_next();
- return std::move(*el);
-}
-
-/*
-template<class ImplTraits, class SuperType>
-typename RewriteRuleSubtreeStream<ImplTraits, SuperType>::TokenType*
-RewriteRuleSubtreeStream<ImplTraits, SuperType>::nextToken()
-{
- return this->_next();
-}
-
-template<class ImplTraits, class SuperType>
-typename RewriteRuleSubtreeStream<ImplTraits, SuperType>::TokenType*
-RewriteRuleSubtreeStream<ImplTraits, SuperType>::next()
-{
- ANTLR_UINT32 s;
- s = this->size();
- if ( (m_cursor >= s) && (s == 1) )
- {
- TreeTypePtr el;
- el = this->_next();
- return this->dup(el);
- }
- return this->_next();
-}
-
-*/
-
-template<class ImplTraits>
-typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
-RewriteRuleSubtreeStream<ImplTraits>::dup(const TreeTypePtr& element)
-{
- return this->dupTree(element);
-}
-
-template<class ImplTraits>
-typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
-RewriteRuleSubtreeStream<ImplTraits>::dup(const TreeType* element)
-{
- return std::move(this->dupTree(element));
-}
-
-template<class ImplTraits>
-typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
-RewriteRuleSubtreeStream<ImplTraits>::dupTree(const TreeTypePtr& element)
-{
- return std::move(m_adaptor->dupTree(element));
-}
-
-template<class ImplTraits>
-typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
-RewriteRuleSubtreeStream<ImplTraits>::dupTree(const TreeType* element)
-{
- return std::move(m_adaptor->dupTree(element));
-}
-
-template<class ImplTraits>
-typename RewriteRuleSubtreeStream<ImplTraits>::ElementType*
-RewriteRuleSubtreeStream<ImplTraits>::toTree( ElementType* element)
-{
- return element;
-}
-
-template<class ImplTraits>
-bool RewriteRuleSubtreeStream<ImplTraits>::hasNext()
-{
- return m_cursor != m_elements.end();
-}
-
-/// Number of elements available in the stream
-///
-template<class ImplTraits>
-ANTLR_UINT32 RewriteRuleSubtreeStream<ImplTraits>::size()
-{
- return (ANTLR_UINT32)(m_elements.size());
-}
-
-template<class ImplTraits>
-typename RewriteRuleSubtreeStream<ImplTraits>::StringType
-RewriteRuleSubtreeStream<ImplTraits>::getDescription()
-{
- if ( m_elementDescription.empty() )
- {
- m_elementDescription = "<unknown source>";
- }
- return m_elementDescription;
-}
-
-template<class ImplTraits>
-RewriteRuleSubtreeStream<ImplTraits>::~RewriteRuleSubtreeStream()
-{
- // Before placing the stream back in the pool, we
- // need to clear any vector it has.
- m_elements.clear();
-}
-
-template<class ImplTraits>
-typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
-RewriteRuleSubtreeStream<ImplTraits>::nextNode()
-{
- //System.out.println("nextNode: elements="+elements+", singleElement="+((Tree)singleElement).toStringTree());
- //ANTLR_UINT32 n = this->size();
- if (m_dirty || (m_cursor == m_elements.end() && m_elements.size() == 1)) {
- // if out of elements and size is 1, dup (at most a single node
- // since this is for making root nodes).
- typename ElementsType::iterator el = this->_next();
- return m_adaptor->dupNode(*el);
- }
-
- typename ElementsType::iterator el = this->_next();
- //while (m_adaptor->isNilNode(el) && m_adaptor->getChildCount(el) == 1)
- // tree = m_adaptor->getChild(tree, 0);
- TreeTypePtr& node = leftestNode(*el);
- //System.out.println("_next="+((Tree)tree).toStringTree());
- return m_adaptor->dupNode(node); // dup just the root (want node here)
-}
-
-template<class ImplTraits>
-ANTLR_INLINE
-typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr&
-RewriteRuleSubtreeStream<ImplTraits>::leftestNode(TreeTypePtr& node) const
-{
- if(m_adaptor->isNilNode(node) && m_adaptor->getChildCount(node) == 1)
- return leftestNode(node->getChild(0));
- else
- return node;
-}
-
-}
+namespace antlr3 {
+
+template<class ImplTraits>
+RewriteRuleSubtreeStream<ImplTraits>::RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description)
+ : m_adaptor(adaptor)
+ , m_elementDescription(description)
+ , m_dirty(false)
+{
+ m_cursor = m_elements.begin();
+}
+
+template<class ImplTraits>
+RewriteRuleSubtreeStream<ImplTraits>::RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description,
+ TreeType* oneElement
+ )
+ : m_adaptor(adaptor)
+ , m_elementDescription(description)
+ , m_dirty(false)
+{
+ if( oneElement != NULL )
+ {
+ auto tree_clone = this->dup(oneElement);
+ this->add( tree_clone );
+ }
+ m_cursor = m_elements.begin();
+}
+
+template<class ImplTraits>
+RewriteRuleSubtreeStream<ImplTraits>::RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description,
+ TreeTypePtr& oneElement
+ )
+ : m_adaptor(adaptor)
+ , m_elementDescription(description)
+ , m_dirty(false)
+{
+ if( oneElement != NULL )
+ this->add( oneElement );
+ m_cursor = m_elements.begin();
+}
+
+template<class ImplTraits>
+RewriteRuleSubtreeStream<ImplTraits>::RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description,
+ const ElementsType& elements
+ )
+ : m_adaptor(adaptor)
+ , m_elementDescription(description)
+ , m_dirty(false)
+ , m_elements(elements)
+{
+ m_cursor = m_elements.begin();
+}
+
+template<class ImplTraits>
+void
+RewriteRuleSubtreeStream<ImplTraits>::reset()
+{
+ m_cursor = m_elements.begin();
+ m_dirty = true;
+}
+
+template<class ImplTraits>
+void
+RewriteRuleSubtreeStream<ImplTraits>::add(TreeTypePtr& el)
+{
+ if ( el == NULL )
+ return;
+
+ m_elements.push_back(std::move(el));
+ m_cursor = m_elements.begin();
+}
+
+template<class ImplTraits>
+typename RewriteRuleSubtreeStream<ImplTraits>::ElementsType::iterator
+RewriteRuleSubtreeStream<ImplTraits>::_next()
+{
+ if (m_elements.empty())
+ {
+ // This means that the stream is empty
+ // Caller must cope with this (TODO throw RewriteEmptyStreamException)
+ return m_elements.end();
+ }
+
+ if (m_dirty || m_cursor == m_elements.end())
+ {
+ if( m_elements.size() == 1)
+ {
+ // Special case when size is single element, it will just dup a lot
+ return m_elements.begin();
+ }
+
+ // Out of elements and the size is not 1, so we cannot assume
+ // that we just duplicate the entry n times (such as ID ent+ -> ^(ID ent)+)
+ // This means we ran out of elements earlier than was expected.
+ //
+ return m_elements.end(); // Caller must cope with this (TODO throw RewriteEmptyStreamException)
+ }
+
+ // More than just a single element so we extract it from the
+ // vector.
+ return m_cursor++;
+}
+
+template<class ImplTraits>
+typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
+RewriteRuleSubtreeStream<ImplTraits>::nextTree()
+{
+ if ( m_dirty || ( m_cursor == m_elements.end() && m_elements.size() == 1 ))
+ {
+ // if out of elements and size is 1, dup
+ typename ElementsType::iterator el = this->_next();
+ return this->dup(*el);
+ }
+
+ // test size above then fetch
+ typename ElementsType::iterator el = this->_next();
+ return std::move(*el);
+}
+
+/*
+template<class ImplTraits, class SuperType>
+typename RewriteRuleSubtreeStream<ImplTraits, SuperType>::TokenType*
+RewriteRuleSubtreeStream<ImplTraits, SuperType>::nextToken()
+{
+ return this->_next();
+}
+
+template<class ImplTraits, class SuperType>
+typename RewriteRuleSubtreeStream<ImplTraits, SuperType>::TokenType*
+RewriteRuleSubtreeStream<ImplTraits, SuperType>::next()
+{
+ ANTLR_UINT32 s;
+ s = this->size();
+ if ( (m_cursor >= s) && (s == 1) )
+ {
+ TreeTypePtr el;
+ el = this->_next();
+ return this->dup(el);
+ }
+ return this->_next();
+}
+
+*/
+
+template<class ImplTraits>
+typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
+RewriteRuleSubtreeStream<ImplTraits>::dup(const TreeTypePtr& element)
+{
+ return this->dupTree(element);
+}
+
+template<class ImplTraits>
+typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
+RewriteRuleSubtreeStream<ImplTraits>::dup(const TreeType* element)
+{
+ return std::move(this->dupTree(element));
+}
+
+template<class ImplTraits>
+typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
+RewriteRuleSubtreeStream<ImplTraits>::dupTree(const TreeTypePtr& element)
+{
+ return std::move(m_adaptor->dupTree(element));
+}
+
+template<class ImplTraits>
+typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
+RewriteRuleSubtreeStream<ImplTraits>::dupTree(const TreeType* element)
+{
+ return std::move(m_adaptor->dupTree(element));
+}
+
+template<class ImplTraits>
+typename RewriteRuleSubtreeStream<ImplTraits>::ElementType*
+RewriteRuleSubtreeStream<ImplTraits>::toTree( ElementType* element)
+{
+ return element;
+}
+
+template<class ImplTraits>
+bool RewriteRuleSubtreeStream<ImplTraits>::hasNext()
+{
+ return m_cursor != m_elements.end();
+}
+
+/// Number of elements available in the stream
+///
+template<class ImplTraits>
+ANTLR_UINT32 RewriteRuleSubtreeStream<ImplTraits>::size()
+{
+ return (ANTLR_UINT32)(m_elements.size());
+}
+
+template<class ImplTraits>
+typename RewriteRuleSubtreeStream<ImplTraits>::StringType
+RewriteRuleSubtreeStream<ImplTraits>::getDescription()
+{
+ if ( m_elementDescription.empty() )
+ {
+ m_elementDescription = "<unknown source>";
+ }
+ return m_elementDescription;
+}
+
+template<class ImplTraits>
+RewriteRuleSubtreeStream<ImplTraits>::~RewriteRuleSubtreeStream()
+{
+ // Before placing the stream back in the pool, we
+ // need to clear any vector it has.
+ m_elements.clear();
+}
+
+template<class ImplTraits>
+typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
+RewriteRuleSubtreeStream<ImplTraits>::nextNode()
+{
+ //System.out.println("nextNode: elements="+elements+", singleElement="+((Tree)singleElement).toStringTree());
+ //ANTLR_UINT32 n = this->size();
+ if (m_dirty || (m_cursor == m_elements.end() && m_elements.size() == 1)) {
+ // if out of elements and size is 1, dup (at most a single node
+ // since this is for making root nodes).
+ typename ElementsType::iterator el = this->_next();
+ return m_adaptor->dupNode(*el);
+ }
+
+ typename ElementsType::iterator el = this->_next();
+ //while (m_adaptor->isNilNode(el) && m_adaptor->getChildCount(el) == 1)
+ // tree = m_adaptor->getChild(tree, 0);
+ TreeTypePtr& node = leftestNode(*el);
+ //System.out.println("_next="+((Tree)tree).toStringTree());
+ return m_adaptor->dupNode(node); // dup just the root (want node here)
+}
+
+template<class ImplTraits>
+ANTLR_INLINE
+typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr&
+RewriteRuleSubtreeStream<ImplTraits>::leftestNode(TreeTypePtr& node) const
+{
+ if(m_adaptor->isNilNode(node) && m_adaptor->getChildCount(node) == 1)
+ return leftestNode(node->getChild(0));
+ else
+ return node;
+}
+
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriteruletokenstream.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriteruletokenstream.hpp
index 8b2687115e..c982b0a2f1 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriteruletokenstream.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriteruletokenstream.hpp
@@ -1,131 +1,131 @@
-#ifndef ANTLR3REWRITESTREAM_HPP
-#define ANTLR3REWRITESTREAM_HPP
-
-// [The "BSD licence"]
-// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
-
-//
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-// 1. Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-// 3. The name of the author may not be used to endorse or promote products
-// derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-namespace antlr3 {
-
-/// This is an implementation of a token stream, which is basically an element
-/// stream that deals with tokens only.
-///
-template<class ImplTraits>
-class RewriteRuleTokenStream
-{
-public:
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
- typedef typename ImplTraits::ParserType ComponentType;
- typedef typename ComponentType::StreamType StreamType;
- typedef typename ImplTraits::CommonTokenType TokenType;
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
- typedef typename AllocPolicyType::template VectorType<const TokenType* > ElementsType;
- typedef typename ImplTraits::template RecognizerType< StreamType > RecognizerType;
- typedef typename ImplTraits::CommonTokenType ElementType;
-public:
- RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* description);
- RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* description, const TokenType* oneElement);
- RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements);
- ~RewriteRuleTokenStream();
-
- /// Reset the condition of this stream so that it appears we have
- /// not consumed any of its elements. Elements themselves are untouched.
- ///
- void reset();
-
- TreeTypePtr nextNode();
- const TokenType* nextToken();
-
- /// TODO copied from RewriteRuleElementStreamType
- /// Add a new pANTLR3_BASE_TREE to this stream
- ///
- void add(const ElementType* el);
-
- /// When constructing trees, sometimes we need to dup a token or AST
- /// subtree. Dup'ing a token means just creating another AST node
- /// around it. For trees, you must call the adaptor.dupTree().
- ///
- ElementType* dup( ElementType* el );
-
- /// Ensure stream emits trees; tokens must be converted to AST nodes.
- /// AST nodes can be passed through unmolested.
- ///
- TreeTypePtr toTree(const ElementType* el);
-
- /// Pointer to the tree adaptor in use for this stream
- ///
- TreeAdaptorType* m_adaptor;
- ElementType nextTree();
- typename ElementsType::iterator _next();
-
- /// Returns true if there is a next element available
- ///
- bool hasNext();
-
- /// Number of elements available in the stream
- ///
- ANTLR_UINT32 size();
-
- /// Returns the description string if there is one available (check for NULL).
- ///
- StringType getDescription();
-
-private:
- ElementType* dupImpl(typename ImplTraits::CommonTokenType* el);
- ElementType* dupImpl(typename ImplTraits::TreeTypePtr el);
-
- /// Cursor 0..n-1. If singleElement!=NULL, cursor is 0 until you next(),
- /// which bumps it to 1 meaning no more elements.
- ///
- typename ElementsType::iterator m_cursor;
-
- /// The element or stream description; usually has name of the token or
- /// rule reference that this list tracks. Can include rulename too, but
- /// the exception would track that info.
- ///
- StringType m_elementDescription;
-
- /// The list of tokens or subtrees we are tracking
- ///
- ElementsType m_elements;
-
- /// Once a node / subtree has been used in a stream, it must be dup'ed
- /// from then on. Streams are reset after sub rules so that the streams
- /// can be reused in future sub rules. So, reset must set a dirty bit.
- /// If dirty, then next() always returns a dup.
- ///
- bool m_dirty;
-};
-
-}
-
-#include "antlr3rewriteruletokenstream.inl"
-
-#endif
+#ifndef ANTLR3REWRITESTREAM_HPP
+#define ANTLR3REWRITESTREAM_HPP
+
+// [The "BSD licence"]
+// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
+
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// 3. The name of the author may not be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+namespace antlr3 {
+
+/// This is an implementation of a token stream, which is basically an element
+/// stream that deals with tokens only.
+///
+template<class ImplTraits>
+class RewriteRuleTokenStream
+{
+public:
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
+ typedef typename ImplTraits::ParserType ComponentType;
+ typedef typename ComponentType::StreamType StreamType;
+ typedef typename ImplTraits::CommonTokenType TokenType;
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+ typedef typename AllocPolicyType::template VectorType<const TokenType* > ElementsType;
+ typedef typename ImplTraits::template RecognizerType< StreamType > RecognizerType;
+ typedef typename ImplTraits::CommonTokenType ElementType;
+public:
+ RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* description);
+ RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* description, const TokenType* oneElement);
+ RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements);
+ ~RewriteRuleTokenStream();
+
+ /// Reset the condition of this stream so that it appears we have
+ /// not consumed any of its elements. Elements themselves are untouched.
+ ///
+ void reset();
+
+ TreeTypePtr nextNode();
+ const TokenType* nextToken();
+
+ /// TODO copied from RewriteRuleElementStreamType
+ /// Add a new pANTLR3_BASE_TREE to this stream
+ ///
+ void add(const ElementType* el);
+
+ /// When constructing trees, sometimes we need to dup a token or AST
+ /// subtree. Dup'ing a token means just creating another AST node
+ /// around it. For trees, you must call the adaptor.dupTree().
+ ///
+ ElementType* dup( ElementType* el );
+
+ /// Ensure stream emits trees; tokens must be converted to AST nodes.
+ /// AST nodes can be passed through unmolested.
+ ///
+ TreeTypePtr toTree(const ElementType* el);
+
+ /// Pointer to the tree adaptor in use for this stream
+ ///
+ TreeAdaptorType* m_adaptor;
+ ElementType nextTree();
+ typename ElementsType::iterator _next();
+
+ /// Returns true if there is a next element available
+ ///
+ bool hasNext();
+
+ /// Number of elements available in the stream
+ ///
+ ANTLR_UINT32 size();
+
+ /// Returns the description string if there is one available (check for NULL).
+ ///
+ StringType getDescription();
+
+private:
+ ElementType* dupImpl(typename ImplTraits::CommonTokenType* el);
+ ElementType* dupImpl(typename ImplTraits::TreeTypePtr el);
+
+ /// Cursor 0..n-1. If singleElement!=NULL, cursor is 0 until you next(),
+ /// which bumps it to 1 meaning no more elements.
+ ///
+ typename ElementsType::iterator m_cursor;
+
+ /// The element or stream description; usually has name of the token or
+ /// rule reference that this list tracks. Can include rulename too, but
+ /// the exception would track that info.
+ ///
+ StringType m_elementDescription;
+
+ /// The list of tokens or subtrees we are tracking
+ ///
+ ElementsType m_elements;
+
+ /// Once a node / subtree has been used in a stream, it must be dup'ed
+ /// from then on. Streams are reset after sub rules so that the streams
+ /// can be reused in future sub rules. So, reset must set a dirty bit.
+ /// If dirty, then next() always returns a dup.
+ ///
+ bool m_dirty;
+};
+
+}
+
+#include "antlr3rewriteruletokenstream.inl"
+
+#endif
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriteruletokenstream.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriteruletokenstream.inl
index e7ad08de43..a7dd8b54fc 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriteruletokenstream.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3rewriteruletokenstream.inl
@@ -1,224 +1,224 @@
-namespace antlr3 {
-
-template<class ImplTraits>
-RewriteRuleTokenStream<ImplTraits>::RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* /*description*/)
- : m_adaptor(adaptor)
- , m_elements()
- , m_dirty(false)
-{
- m_cursor = m_elements.begin();
-}
-
-template<class ImplTraits>
-RewriteRuleTokenStream<ImplTraits>::RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* /*description*/,
- const TokenType* oneElement
- )
- : m_adaptor(adaptor)
- , m_elements()
- , m_dirty(false)
-{
- if( oneElement != NULL )
- this->add( oneElement );
- m_cursor = m_elements.begin();
-}
-
-template<class ImplTraits>
-RewriteRuleTokenStream<ImplTraits>::RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* /*description*/,
- const ElementsType& elements
- )
- : m_adaptor(adaptor)
- , m_elements(elements)
- , m_dirty(false)
-{
- m_cursor = m_elements.begin();
-}
-
-template<class ImplTraits>
-void RewriteRuleTokenStream<ImplTraits>::reset()
-{
- m_cursor = m_elements.begin();
- m_dirty = true;
-}
-
-template<class ImplTraits>
-void RewriteRuleTokenStream<ImplTraits>::add(const ElementType* el)
-{
- if ( el == NULL)
- return;
- m_elements.push_back(el);
- m_cursor = m_elements.begin();
-}
-
-template<class ImplTraits>
-typename RewriteRuleTokenStream<ImplTraits>::ElementsType::iterator
-RewriteRuleTokenStream<ImplTraits>::_next()
-{
- if (m_elements.empty())
- {
- // This means that the stream is empty
- // Caller must cope with this (TODO throw RewriteEmptyStreamException)
- return m_elements.end();
- }
-
- if (m_dirty || m_cursor == m_elements.end())
- {
- if( m_elements.size() == 1)
- {
- // Special case when size is single element, it will just dup a lot
- //return this->toTree(m_singleElement);
- return m_elements.begin();
- }
-
- // Out of elements and the size is not 1, so we cannot assume
- // that we just duplicate the entry n times (such as ID ent+ -> ^(ID ent)+)
- // This means we ran out of elements earlier than was expected.
- //
- return m_elements.end(); // Caller must cope with this (TODO throw RewriteEmptyStreamException)
- }
-
- // More than just a single element so we extract it from the
- // vector.
- return m_cursor++;
-}
-
-template<class ImplTraits>
-typename RewriteRuleTokenStream<ImplTraits>::ElementType
-RewriteRuleTokenStream<ImplTraits>::nextTree()
-{
- ANTLR_UINT32 n = this->size();
- if ( m_dirty || ( (m_cursor >=n) && (n==1)) )
- {
- // if out of elements and size is 1, dup
- typename ElementsType::iterator el = this->_next();
- return this->dup(*el);
- }
-
- // test size above then fetch
- typename ElementsType::iterator el = this->_next();
- return *el;
-}
-
-/*
-template<class ImplTraits, class SuperType>
-typename RewriteRuleTokenStream<ImplTraits, SuperType>::TokenType*
-RewriteRuleTokenStream<ImplTraits, SuperType>::nextToken()
-{
- return this->_next();
-}
-
-template<class ImplTraits, class SuperType>
-typename RewriteRuleTokenStream<ImplTraits, SuperType>::TokenType*
-RewriteRuleTokenStream<ImplTraits, SuperType>::next()
-{
- ANTLR_UINT32 s;
- s = this->size();
- if ( (m_cursor >= s) && (s == 1) )
- {
- TreeTypePtr el;
- el = this->_next();
- return this->dup(el);
- }
- return this->_next();
-}
-
-*/
-
-template<class ImplTraits>
-typename RewriteRuleTokenStream<ImplTraits>::ElementType*
-RewriteRuleTokenStream<ImplTraits>::dup( ElementType* element)
-{
- return dupImpl(element);
-}
-
-template<class ImplTraits>
-typename RewriteRuleTokenStream<ImplTraits>::ElementType*
-RewriteRuleTokenStream<ImplTraits>::dupImpl( typename ImplTraits::CommonTokenType* /*element*/)
-{
- return NULL; // TODO throw here
-}
-
-template<class ImplTraits>
-typename RewriteRuleTokenStream<ImplTraits>::ElementType*
-RewriteRuleTokenStream<ImplTraits>::dupImpl( typename ImplTraits::TreeTypePtr element)
-{
- return m_adaptor->dupTree(element);
-}
-
-template<class ImplTraits>
-typename RewriteRuleTokenStream<ImplTraits>::TreeTypePtr
-RewriteRuleTokenStream<ImplTraits>::toTree(const ElementType* element)
-{
- return m_adaptor->create(element);
-}
-
-template<class ImplTraits>
-bool
-RewriteRuleTokenStream<ImplTraits>::hasNext()
-{
- return m_cursor != m_elements.end();
-}
-
-template<class ImplTraits >
-typename RewriteRuleTokenStream<ImplTraits>::TreeTypePtr
-RewriteRuleTokenStream<ImplTraits>::nextNode()
-{
- const TokenType *Token = this->nextToken();
- return m_adaptor->create(Token);
-}
-
-/// Number of elements available in the stream
-///
-template<class ImplTraits>
-ANTLR_UINT32 RewriteRuleTokenStream<ImplTraits>::size()
-{
- return (ANTLR_UINT32)(m_elements.size());
-}
-
-template<class ImplTraits>
-typename RewriteRuleTokenStream<ImplTraits>::StringType
-RewriteRuleTokenStream<ImplTraits>::getDescription()
-{
- if ( m_elementDescription.empty() )
- {
- m_elementDescription = "<unknown source>";
- }
- return m_elementDescription;
-}
-
-template<class ImplTraits>
-RewriteRuleTokenStream<ImplTraits>::~RewriteRuleTokenStream()
-{
- // Before placing the stream back in the pool, we
- // need to clear any vector it has. This is so any
- // free pointers that are associated with the
- // entries are called. However, if this particular function is called
- // then we know that the entries in the stream are definitely
- // tree nodes. Hence we check to see if any of them were nilNodes as
- // if they were, we can reuse them.
- //
- // We have some elements to traverse
- //
- for (ANTLR_UINT32 i = 0; i < m_elements.size(); i++)
- {
- const ElementType *tree = m_elements.at(i);
- //if ( (tree != NULL) && tree->isNilNode() )
- {
- // Had to remove this for now, check is not comprehensive enough
- // tree->reuse(tree);
- }
- }
- m_elements.clear();
-}
-
-template<class ImplTraits>
-const typename RewriteRuleTokenStream<ImplTraits>::TokenType*
-RewriteRuleTokenStream<ImplTraits>::nextToken()
-{
- auto retval = this->_next();
- if (retval == m_elements.end())
- return NULL;
- else
- return *retval;
-}
-
-}
+namespace antlr3 {
+
+template<class ImplTraits>
+RewriteRuleTokenStream<ImplTraits>::RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* /*description*/)
+ : m_adaptor(adaptor)
+ , m_elements()
+ , m_dirty(false)
+{
+ m_cursor = m_elements.begin();
+}
+
+template<class ImplTraits>
+RewriteRuleTokenStream<ImplTraits>::RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* /*description*/,
+ const TokenType* oneElement
+ )
+ : m_adaptor(adaptor)
+ , m_elements()
+ , m_dirty(false)
+{
+ if( oneElement != NULL )
+ this->add( oneElement );
+ m_cursor = m_elements.begin();
+}
+
+template<class ImplTraits>
+RewriteRuleTokenStream<ImplTraits>::RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* /*description*/,
+ const ElementsType& elements
+ )
+ : m_adaptor(adaptor)
+ , m_elements(elements)
+ , m_dirty(false)
+{
+ m_cursor = m_elements.begin();
+}
+
+template<class ImplTraits>
+void RewriteRuleTokenStream<ImplTraits>::reset()
+{
+ m_cursor = m_elements.begin();
+ m_dirty = true;
+}
+
+template<class ImplTraits>
+void RewriteRuleTokenStream<ImplTraits>::add(const ElementType* el)
+{
+ if ( el == NULL)
+ return;
+ m_elements.push_back(el);
+ m_cursor = m_elements.begin();
+}
+
+template<class ImplTraits>
+typename RewriteRuleTokenStream<ImplTraits>::ElementsType::iterator
+RewriteRuleTokenStream<ImplTraits>::_next()
+{
+ if (m_elements.empty())
+ {
+ // This means that the stream is empty
+ // Caller must cope with this (TODO throw RewriteEmptyStreamException)
+ return m_elements.end();
+ }
+
+ if (m_dirty || m_cursor == m_elements.end())
+ {
+ if( m_elements.size() == 1)
+ {
+ // Special case when size is single element, it will just dup a lot
+ //return this->toTree(m_singleElement);
+ return m_elements.begin();
+ }
+
+ // Out of elements and the size is not 1, so we cannot assume
+ // that we just duplicate the entry n times (such as ID ent+ -> ^(ID ent)+)
+ // This means we ran out of elements earlier than was expected.
+ //
+ return m_elements.end(); // Caller must cope with this (TODO throw RewriteEmptyStreamException)
+ }
+
+ // More than just a single element so we extract it from the
+ // vector.
+ return m_cursor++;
+}
+
+template<class ImplTraits>
+typename RewriteRuleTokenStream<ImplTraits>::ElementType
+RewriteRuleTokenStream<ImplTraits>::nextTree()
+{
+ ANTLR_UINT32 n = this->size();
+ if ( m_dirty || ( (m_cursor >=n) && (n==1)) )
+ {
+ // if out of elements and size is 1, dup
+ typename ElementsType::iterator el = this->_next();
+ return this->dup(*el);
+ }
+
+ // test size above then fetch
+ typename ElementsType::iterator el = this->_next();
+ return *el;
+}
+
+/*
+template<class ImplTraits, class SuperType>
+typename RewriteRuleTokenStream<ImplTraits, SuperType>::TokenType*
+RewriteRuleTokenStream<ImplTraits, SuperType>::nextToken()
+{
+ return this->_next();
+}
+
+template<class ImplTraits, class SuperType>
+typename RewriteRuleTokenStream<ImplTraits, SuperType>::TokenType*
+RewriteRuleTokenStream<ImplTraits, SuperType>::next()
+{
+ ANTLR_UINT32 s;
+ s = this->size();
+ if ( (m_cursor >= s) && (s == 1) )
+ {
+ TreeTypePtr el;
+ el = this->_next();
+ return this->dup(el);
+ }
+ return this->_next();
+}
+
+*/
+
+template<class ImplTraits>
+typename RewriteRuleTokenStream<ImplTraits>::ElementType*
+RewriteRuleTokenStream<ImplTraits>::dup( ElementType* element)
+{
+ return dupImpl(element);
+}
+
+template<class ImplTraits>
+typename RewriteRuleTokenStream<ImplTraits>::ElementType*
+RewriteRuleTokenStream<ImplTraits>::dupImpl( typename ImplTraits::CommonTokenType* /*element*/)
+{
+ return NULL; // TODO throw here
+}
+
+template<class ImplTraits>
+typename RewriteRuleTokenStream<ImplTraits>::ElementType*
+RewriteRuleTokenStream<ImplTraits>::dupImpl( typename ImplTraits::TreeTypePtr element)
+{
+ return m_adaptor->dupTree(element);
+}
+
+template<class ImplTraits>
+typename RewriteRuleTokenStream<ImplTraits>::TreeTypePtr
+RewriteRuleTokenStream<ImplTraits>::toTree(const ElementType* element)
+{
+ return m_adaptor->create(element);
+}
+
+template<class ImplTraits>
+bool
+RewriteRuleTokenStream<ImplTraits>::hasNext()
+{
+ return m_cursor != m_elements.end();
+}
+
+template<class ImplTraits >
+typename RewriteRuleTokenStream<ImplTraits>::TreeTypePtr
+RewriteRuleTokenStream<ImplTraits>::nextNode()
+{
+ const TokenType *Token = this->nextToken();
+ return m_adaptor->create(Token);
+}
+
+/// Number of elements available in the stream
+///
+template<class ImplTraits>
+ANTLR_UINT32 RewriteRuleTokenStream<ImplTraits>::size()
+{
+ return (ANTLR_UINT32)(m_elements.size());
+}
+
+template<class ImplTraits>
+typename RewriteRuleTokenStream<ImplTraits>::StringType
+RewriteRuleTokenStream<ImplTraits>::getDescription()
+{
+ if ( m_elementDescription.empty() )
+ {
+ m_elementDescription = "<unknown source>";
+ }
+ return m_elementDescription;
+}
+
+template<class ImplTraits>
+RewriteRuleTokenStream<ImplTraits>::~RewriteRuleTokenStream()
+{
+ // Before placing the stream back in the pool, we
+ // need to clear any vector it has. This is so any
+ // free pointers that are associated with the
+ // entries are called. However, if this particular function is called
+ // then we know that the entries in the stream are definitely
+ // tree nodes. Hence we check to see if any of them were nilNodes as
+ // if they were, we can reuse them.
+ //
+ // We have some elements to traverse
+ //
+ for (ANTLR_UINT32 i = 0; i < m_elements.size(); i++)
+ {
+ const ElementType *tree = m_elements.at(i);
+ //if ( (tree != NULL) && tree->isNilNode() )
+ {
+ // Had to remove this for now, check is not comprehensive enough
+ // tree->reuse(tree);
+ }
+ }
+ m_elements.clear();
+}
+
+template<class ImplTraits>
+const typename RewriteRuleTokenStream<ImplTraits>::TokenType*
+RewriteRuleTokenStream<ImplTraits>::nextToken()
+{
+ auto retval = this->_next();
+ if (retval == m_elements.end())
+ return NULL;
+ else
+ return *retval;
+}
+
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3rewritestreams.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3rewritestreams.hpp
index a782bd55cd..a8d7396643 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3rewritestreams.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3rewritestreams.hpp
@@ -1,5 +1,5 @@
-#ifndef ANTLR3REWRITESTREAM_HPP
-#define ANTLR3REWRITESTREAM_HPP
+#ifndef ANTLR3REWRITESTREAM_HPP
+#define ANTLR3REWRITESTREAM_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -30,9 +30,9 @@
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/// A generic list of elements tracked in an alternative to be used in
-/// a -> rewrite rule.
+/// a -> rewrite rule.
///
-/// In the C implementation, all tree oriented streams return a pointer to
+/// In the C implementation, all tree oriented streams return a pointer to
/// the same type: pANTLR3_BASE_TREE. Anything that has subclassed from this
/// still passes this type, within which there is a super pointer, which points
/// to it's own data and methods. Hence we do not need to implement this as
@@ -42,100 +42,100 @@
/// Once you start next()ing, do not try to add more elements. It will
/// break the cursor tracking I believe.
///
-///
+///
/// \see #pANTLR3_REWRITE_RULE_NODE_STREAM
/// \see #pANTLR3_REWRITE_RULE_ELEMENT_STREAM
/// \see #pANTLR3_REWRITE_RULE_SUBTREE_STREAM
///
/// TODO: add mechanism to detect/puke on modification after reading from stream
///
-namespace antlr3 {
+namespace antlr3 {
-template<class ImplTraits, class ElementType>
-//template<class ImplTraits>
-class RewriteRuleElementStream : public ImplTraits::AllocPolicyType
+template<class ImplTraits, class ElementType>
+//template<class ImplTraits>
+class RewriteRuleElementStream : public ImplTraits::AllocPolicyType
{
public:
- //typedef typename ElementTypePtr::element_type ElementType; unique_ptr
- //typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
+ //typedef typename ElementTypePtr::element_type ElementType; unique_ptr
+ //typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
- //typedef typename ImplTraits::template RecognizerType< typename SuperType::StreamType > RecognizerType;
- typedef typename ImplTraits::StringType StringType;
- typedef typename AllocPolicyType::template VectorType< ElementType* > ElementsType;
+ //typedef typename ImplTraits::template RecognizerType< typename SuperType::StreamType > RecognizerType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename AllocPolicyType::template VectorType< ElementType* > ElementsType;
protected:
/// The list of tokens or subtrees we are tracking
///
- ElementsType m_elements;
+ ElementsType m_elements;
/// The element or stream description; usually has name of the token or
/// rule reference that this list tracks. Can include rulename too, but
/// the exception would track that info.
///
- StringType m_elementDescription;
+ StringType m_elementDescription;
+
+private:
+ ElementType* dupImpl(typename ImplTraits::CommonTokenType* el);
+ ElementType* dupImpl(typename ImplTraits::TreeTypePtr el);
-private:
- ElementType* dupImpl(typename ImplTraits::CommonTokenType* el);
- ElementType* dupImpl(typename ImplTraits::TreeTypePtr el);
+ /// Pointer to the tree adaptor in use for this stream
+ ///
+ TreeAdaptorType* m_adaptor;
- /// Pointer to the tree adaptor in use for this stream
- ///
- TreeAdaptorType* m_adaptor;
-
- /// Cursor 0..n-1. If singleElement!=NULL, cursor is 0 until you next(),
+ /// Cursor 0..n-1. If singleElement!=NULL, cursor is 0 until you next(),
/// which bumps it to 1 meaning no more elements.
///
- ANTLR_UINT32 m_cursor;
+ ANTLR_UINT32 m_cursor;
- /// Once a node / subtree has been used in a stream, it must be dup'ed
- /// from then on. Streams are reset after sub rules so that the streams
- /// can be reused in future sub rules. So, reset must set a dirty bit.
- /// If dirty, then next() always returns a dup.
- ///
- bool m_dirty;
+ /// Once a node / subtree has been used in a stream, it must be dup'ed
+ /// from then on. Streams are reset after sub rules so that the streams
+ /// can be reused in future sub rules. So, reset must set a dirty bit.
+ /// If dirty, then next() always returns a dup.
+ ///
+ bool m_dirty;
public:
- RewriteRuleElementStream(TreeAdaptorType* adaptor, const char* description);
- RewriteRuleElementStream(TreeAdaptorType* adaptor, const char* description, const ElementType* oneElement);
- RewriteRuleElementStream(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements);
+ RewriteRuleElementStream(TreeAdaptorType* adaptor, const char* description);
+ RewriteRuleElementStream(TreeAdaptorType* adaptor, const char* description, const ElementType* oneElement);
+ RewriteRuleElementStream(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements);
- ~RewriteRuleElementStream();
- // Methods
+ ~RewriteRuleElementStream();
+ // Methods
/// Reset the condition of this stream so that it appears we have
/// not consumed any of its elements. Elements themselves are untouched.
///
- void reset();
+ void reset();
/// Add a new pANTLR3_BASE_TREE to this stream
///
- void add(ElementType* el);
+ void add(ElementType* el);
/// Return the next element in the stream. If out of elements, throw
/// an exception unless size()==1. If size is 1, then return elements[0].
///
- //TokenType* next();
- ElementType nextTree();
- //TokenType* nextToken();
- ElementType* _next();
+ //TokenType* next();
+ ElementType nextTree();
+ //TokenType* nextToken();
+ ElementType* _next();
- /// When constructing trees, sometimes we need to dup a token or AST
- /// subtree. Dup'ing a token means just creating another AST node
+ /// When constructing trees, sometimes we need to dup a token or AST
+ /// subtree. Dup'ing a token means just creating another AST node
/// around it. For trees, you must call the adaptor.dupTree().
///
- ElementType* dup( ElementType* el );
+ ElementType* dup( ElementType* el );
/// Ensure stream emits trees; tokens must be converted to AST nodes.
/// AST nodes can be passed through unmolested.
///
- ElementType* toTree(ElementType* el);
+ ElementType* toTree(ElementType* el);
/// Returns true if there is a next element available
///
- bool hasNext();
+ bool hasNext();
/// Treat next element as a single node even if it's a subtree.
/// This is used instead of next() when the result has to be a
@@ -144,155 +144,155 @@ public:
/// must dup the type node, but ID has been added.
///
/// Referencing to a rule result twice is ok; dup entire tree as
- /// we can't be adding trees; e.g., expr expr.
+ /// we can't be adding trees; e.g., expr expr.
///
- //TreeTypePtr nextNode();
+ //TreeTypePtr nextNode();
/// Number of elements available in the stream
///
- ANTLR_UINT32 size();
+ ANTLR_UINT32 size();
/// Returns the description string if there is one available (check for NULL).
///
StringType getDescription();
protected:
- void init(TreeAdaptorType* adaptor, const char* description);
+ void init(TreeAdaptorType* adaptor, const char* description);
};
/// This is an implementation of a token stream, which is basically an element
/// stream that deals with tokens only.
///
template<class ImplTraits>
-//class RewriteRuleTokenStream : public ImplTraits::template RewriteRuleElementStreamType< typename ImplTraits::ParserType>
-class RewriteRuleTokenStream
- //: public ImplTraits::template RewriteStreamType< const typename ImplTraits::CommonTokenType >
+//class RewriteRuleTokenStream : public ImplTraits::template RewriteRuleElementStreamType< typename ImplTraits::ParserType>
+class RewriteRuleTokenStream
+ //: public ImplTraits::template RewriteStreamType< const typename ImplTraits::CommonTokenType >
{
public:
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
- typedef typename ImplTraits::ParserType ComponentType;
- typedef typename ComponentType::StreamType StreamType;
- typedef typename ImplTraits::CommonTokenType TokenType;
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
- typedef typename AllocPolicyType::template VectorType< TokenType* > ElementsType;
- typedef typename ImplTraits::template RecognizerType< StreamType > RecognizerType;
- typedef typename ImplTraits::template RewriteStreamType< const typename ImplTraits::CommonTokenType > BaseType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
+ typedef typename ImplTraits::ParserType ComponentType;
+ typedef typename ComponentType::StreamType StreamType;
+ typedef typename ImplTraits::CommonTokenType TokenType;
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+ typedef typename AllocPolicyType::template VectorType< TokenType* > ElementsType;
+ typedef typename ImplTraits::template RecognizerType< StreamType > RecognizerType;
+ typedef typename ImplTraits::template RewriteStreamType< const typename ImplTraits::CommonTokenType > BaseType;
public:
- RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* description);
- RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* description, const TokenType* oneElement);
- RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements);
-
- TreeTypePtr nextNode();
- TokenType* nextToken();
-
- /// TODO copied from RewriteRuleElementStreamType
- /// Add a new pANTLR3_BASE_TREE to this stream
- ///
- typedef typename ImplTraits::CommonTokenType ElementType;
- void add(const ElementType* el);
- /// Pointer to the tree adaptor in use for this stream
- ///
- TreeAdaptorType* m_adaptor;
- ElementType* _next();
-
+ RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* description);
+ RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* description, const TokenType* oneElement);
+ RewriteRuleTokenStream(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements);
+
+ TreeTypePtr nextNode();
+ TokenType* nextToken();
+
+ /// TODO copied from RewriteRuleElementStreamType
+ /// Add a new pANTLR3_BASE_TREE to this stream
+ ///
+ typedef typename ImplTraits::CommonTokenType ElementType;
+ void add(const ElementType* el);
+ /// Pointer to the tree adaptor in use for this stream
+ ///
+ TreeAdaptorType* m_adaptor;
+ ElementType* _next();
+
private:
- //TreeTypePtr nextNodeToken();
+ //TreeTypePtr nextNodeToken();
};
/// This is an implementation of a subtree stream which is a set of trees
-/// modeled as an element stream.
+/// modeled as an element stream.
///
template<class ImplTraits>
-//class RewriteRuleSubtreeStream : public ImplTraits::template RewriteStreamType< typename ImplTraits::TreeParserType>
-class RewriteRuleSubtreeStream
- //: public ImplTraits::template RewriteStreamType< typename ImplTraits::TreeType >
+//class RewriteRuleSubtreeStream : public ImplTraits::template RewriteStreamType< typename ImplTraits::TreeParserType>
+class RewriteRuleSubtreeStream
+ //: public ImplTraits::template RewriteStreamType< typename ImplTraits::TreeType >
{
public:
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
- typedef typename ImplTraits::TreeParserType ComponentType;
- typedef typename ComponentType::StreamType StreamType;
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
- typedef TreeType TokenType;
- typedef typename ImplTraits::template RecognizerType< StreamType > RecognizerType;
- typedef typename AllocPolicyType::template VectorType< TokenType* > ElementsType;
- typedef typename ImplTraits::template RewriteStreamType< typename ImplTraits::TreeType > BaseType;
-
- RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description);
- RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description, TreeTypePtr& oneElement);
- RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements);
-
- TreeTypePtr nextNode(TreeTypePtr);
-
- /// TODO copied from RewriteRuleElementStreamType
- /// Add a new pANTLR3_BASE_TREE to this stream
- ///
- void add(TreeTypePtr& el);
- bool hasNext();
- TreeTypePtr& nextTree();
- void reset();
-
-protected:
- TreeTypePtr dup( TreeTypePtr el );
-
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
+ typedef typename ImplTraits::TreeParserType ComponentType;
+ typedef typename ComponentType::StreamType StreamType;
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+ typedef TreeType TokenType;
+ typedef typename ImplTraits::template RecognizerType< StreamType > RecognizerType;
+ typedef typename AllocPolicyType::template VectorType< TokenType* > ElementsType;
+ typedef typename ImplTraits::template RewriteStreamType< typename ImplTraits::TreeType > BaseType;
+
+ RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description);
+ RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description, TreeTypePtr& oneElement);
+ RewriteRuleSubtreeStream(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements);
+
+ TreeTypePtr nextNode(TreeTypePtr);
+
+ /// TODO copied from RewriteRuleElementStreamType
+ /// Add a new pANTLR3_BASE_TREE to this stream
+ ///
+ void add(TreeTypePtr& el);
+ bool hasNext();
+ TreeTypePtr& nextTree();
+ void reset();
+
+protected:
+ TreeTypePtr dup( TreeTypePtr el );
+
private:
- TreeTypePtr dupTree( TreeTypePtr el );
+ TreeTypePtr dupTree( TreeTypePtr el );
};
-/* TODO This class is probably used in TreeParser only
- * Notes about Java target
- * - these classes reimplement only dup and toTree methods:
- * base ElementStr
- * abstract dup
- * toTree(Object e) { return e; }
- * TokenStr
- * dup { throw }
- * toTree(Object e) { return e; }
- * SubTreeStr
- * dup(Object e) { return adaptor.dupTree }
- * NodeStr
- * dup { throw }
- * toTree(Object e) { return adaptor.dupNode }
- * See: RewriteRuleElementStream::dup, RewriteRuleElementStream::dupImpl
- *
- * There should 3 types of specializations for RewriteRuleElementStreamType (which is not defined yet)
- * ATM: RewriteRuleElementStreamType is replaced with ImplTraits::template RewriteStreamType
- *
+/* TODO This class is probably used in TreeParser only
+ * Notes about Java target
+ * - these classes reimplement only dup and toTree methods:
+ * base ElementStr
+ * abstract dup
+ * toTree(Object e) { return e; }
+ * TokenStr
+ * dup { throw }
+ * toTree(Object e) { return e; }
+ * SubTreeStr
+ * dup(Object e) { return adaptor.dupTree }
+ * NodeStr
+ * dup { throw }
+ * toTree(Object e) { return adaptor.dupNode }
+ * See: RewriteRuleElementStream::dup, RewriteRuleElementStream::dupImpl
+ *
+ * There should 3 types of specializations for RewriteRuleElementStreamType (which is not defined yet)
+ * ATM: RewriteRuleElementStreamType is replaced with ImplTraits::template RewriteStreamType
+ *
/// This is an implementation of a node stream, which is basically an element
/// stream that deals with tree nodes only.
///
template<class ImplTraits>
-//class RewriteRuleNodeStream : public ImplTraits::template RewriteStreamType< typename ImplTraits::TreeParserType>
-class RewriteRuleNodeStream : public ImplTraits::template RewriteStreamType< typename ImplTraits::TreeType >
+//class RewriteRuleNodeStream : public ImplTraits::template RewriteStreamType< typename ImplTraits::TreeParserType>
+class RewriteRuleNodeStream : public ImplTraits::template RewriteStreamType< typename ImplTraits::TreeType >
{
public:
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
- typedef typename ImplTraits::TreeParserType ComponentType;
- typedef typename ComponentType::StreamType StreamType;
- typedef typename ImplTraits::TreeType TreeType;
- typedef TreeType TokenType;
- typedef typename ImplTraits::template RecognizerType< StreamType > RecognizerType;
- typedef typename AllocPolicyType::template VectorType< TokenType* > ElementsType;
- typedef typename ImplTraits::template RewriteRuleElementStreamType< typename ImplTraits::TreeType > BaseType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::TreeAdaptorType TreeAdaptorType;
+ typedef typename ImplTraits::TreeParserType ComponentType;
+ typedef typename ComponentType::StreamType StreamType;
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef TreeType TokenType;
+ typedef typename ImplTraits::template RecognizerType< StreamType > RecognizerType;
+ typedef typename AllocPolicyType::template VectorType< TokenType* > ElementsType;
+ typedef typename ImplTraits::template RewriteRuleElementStreamType< typename ImplTraits::TreeType > BaseType;
public:
- RewriteRuleNodeStream(TreeAdaptorType* adaptor, const char* description);
- RewriteRuleNodeStream(TreeAdaptorType* adaptor, const char* description, TokenType* oneElement);
- RewriteRuleNodeStream(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements);
+ RewriteRuleNodeStream(TreeAdaptorType* adaptor, const char* description);
+ RewriteRuleNodeStream(TreeAdaptorType* adaptor, const char* description, TokenType* oneElement);
+ RewriteRuleNodeStream(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements);
-protected:
- TreeTypePtr toTree(TreeTypePtr element);
+protected:
+ TreeTypePtr toTree(TreeTypePtr element);
private:
- TreeTypePtr toTreeNode(TreeTypePtr element);
+ TreeTypePtr toTreeNode(TreeTypePtr element);
};
-*/
-}
+*/
+}
#include "antlr3rewritestreams.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3rewritestreams.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3rewritestreams.inl
index e3557d11a2..47568da649 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3rewritestreams.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3rewritestreams.inl
@@ -1,363 +1,363 @@
-namespace antlr3 {
+namespace antlr3 {
-template<class ImplTraits, class ElementType>
-RewriteRuleElementStream<ImplTraits, ElementType>::RewriteRuleElementStream(TreeAdaptorType* adaptor,
- const char* description)
+template<class ImplTraits, class ElementType>
+RewriteRuleElementStream<ImplTraits, ElementType>::RewriteRuleElementStream(TreeAdaptorType* adaptor,
+ const char* description)
{
- this->init(adaptor, description);
+ this->init(adaptor, description);
}
-template<class ImplTraits, class ElementType>
-RewriteRuleElementStream<ImplTraits, ElementType>::RewriteRuleElementStream(TreeAdaptorType* adaptor,
- const char* description,
- const ElementType* oneElement)
+template<class ImplTraits, class ElementType>
+RewriteRuleElementStream<ImplTraits, ElementType>::RewriteRuleElementStream(TreeAdaptorType* adaptor,
+ const char* description,
+ const ElementType* oneElement)
{
- this->init(adaptor, description);
- if( oneElement != NULL )
- this->add( oneElement );
+ this->init(adaptor, description);
+ if( oneElement != NULL )
+ this->add( oneElement );
}
-template<class ImplTraits, class ElementType>
-RewriteRuleElementStream<ImplTraits, ElementType>::RewriteRuleElementStream(TreeAdaptorType* adaptor,
- const char* description,
- const ElementsType& elements)
- : m_elements(elements)
+template<class ImplTraits, class ElementType>
+RewriteRuleElementStream<ImplTraits, ElementType>::RewriteRuleElementStream(TreeAdaptorType* adaptor,
+ const char* description,
+ const ElementsType& elements)
+ : m_elements(elements)
{
- this->init(adaptor, description);
+ this->init(adaptor, description);
}
-template<class ImplTraits, class ElementType>
-void RewriteRuleElementStream<ImplTraits, ElementType>::init(TreeAdaptorType* adaptor,
- const char* description)
+template<class ImplTraits, class ElementType>
+void RewriteRuleElementStream<ImplTraits, ElementType>::init(TreeAdaptorType* adaptor,
+ const char* description)
{
- m_adaptor = adaptor;
- m_cursor = 0;
- m_dirty = false;
+ m_adaptor = adaptor;
+ m_cursor = 0;
+ m_dirty = false;
}
template<class ImplTraits>
RewriteRuleTokenStream<ImplTraits>::RewriteRuleTokenStream(TreeAdaptorType* adaptor,
- const char* description)
- //: BaseType(adaptor, description)
+ const char* description)
+ //: BaseType(adaptor, description)
{
}
template<class ImplTraits>
-RewriteRuleTokenStream<ImplTraits>::RewriteRuleTokenStream(TreeAdaptorType* adaptor,
- const char* description,
- const TokenType* oneElement)
- //: BaseType(adaptor, description, oneElement)
+RewriteRuleTokenStream<ImplTraits>::RewriteRuleTokenStream(TreeAdaptorType* adaptor,
+ const char* description,
+ const TokenType* oneElement)
+ //: BaseType(adaptor, description, oneElement)
{
}
template<class ImplTraits>
RewriteRuleTokenStream<ImplTraits>::RewriteRuleTokenStream(TreeAdaptorType* adaptor,
- const char* description,
- const ElementsType& elements)
- //: BaseType(adaptor, description, elements)
+ const char* description,
+ const ElementsType& elements)
+ //: BaseType(adaptor, description, elements)
{
}
template<class ImplTraits>
RewriteRuleSubtreeStream<ImplTraits>::RewriteRuleSubtreeStream(TreeAdaptorType* adaptor,
- const char* description)
- //: BaseType(adaptor, description)
+ const char* description)
+ //: BaseType(adaptor, description)
{
}
template<class ImplTraits>
-RewriteRuleSubtreeStream<ImplTraits>::RewriteRuleSubtreeStream(TreeAdaptorType* adaptor,
- const char* description,
- TreeTypePtr& oneElement)
- //: BaseType(adaptor, description, oneElement)
+RewriteRuleSubtreeStream<ImplTraits>::RewriteRuleSubtreeStream(TreeAdaptorType* adaptor,
+ const char* description,
+ TreeTypePtr& oneElement)
+ //: BaseType(adaptor, description, oneElement)
{
}
template<class ImplTraits>
RewriteRuleSubtreeStream<ImplTraits>::RewriteRuleSubtreeStream(TreeAdaptorType* adaptor,
- const char* description,
- const ElementsType& elements)
- //: BaseType(adaptor, description, elements)
+ const char* description,
+ const ElementsType& elements)
+ //: BaseType(adaptor, description, elements)
{
}
-/*
+/*
template<class ImplTraits>
RewriteRuleNodeStream<ImplTraits>::RewriteRuleNodeStream(TreeAdaptorType* adaptor,
- const char* description)
- : BaseType(adaptor, description)
+ const char* description)
+ : BaseType(adaptor, description)
{
}
template<class ImplTraits>
-RewriteRuleNodeStream<ImplTraits>::RewriteRuleNodeStream(TreeAdaptorType* adaptor,
- const char* description,
- TokenType* oneElement)
- : BaseType(adaptor, description, oneElement)
+RewriteRuleNodeStream<ImplTraits>::RewriteRuleNodeStream(TreeAdaptorType* adaptor,
+ const char* description,
+ TokenType* oneElement)
+ : BaseType(adaptor, description, oneElement)
{
}
template<class ImplTraits>
RewriteRuleNodeStream<ImplTraits>::RewriteRuleNodeStream(TreeAdaptorType* adaptor,
- const char* description,
- const ElementsType& elements)
- : BaseType(adaptor, description, elements)
+ const char* description,
+ const ElementsType& elements)
+ : BaseType(adaptor, description, elements)
{
}
-*/
+*/
-template<class ImplTraits, class ElementType>
-void RewriteRuleElementStream<ImplTraits, ElementType>::reset()
+template<class ImplTraits, class ElementType>
+void RewriteRuleElementStream<ImplTraits, ElementType>::reset()
{
- m_cursor = 0;
- m_dirty = true;
+ m_cursor = 0;
+ m_dirty = true;
}
-template<class ImplTraits, class ElementType>
-void RewriteRuleElementStream<ImplTraits, ElementType>::add(ElementType* el)
+template<class ImplTraits, class ElementType>
+void RewriteRuleElementStream<ImplTraits, ElementType>::add(ElementType* el)
{
- if ( el== NULL )
- return;
+ if ( el== NULL )
+ return;
- m_elements.push_back(el);
+ m_elements.push_back(el);
}
-template<class ImplTraits, class ElementType>
-ElementType* RewriteRuleElementStream<ImplTraits, ElementType>::_next()
+template<class ImplTraits, class ElementType>
+ElementType* RewriteRuleElementStream<ImplTraits, ElementType>::_next()
{
- ANTLR_UINT32 n = this->size();
-
- if (n == 0)
- {
- // This means that the stream is empty
- return NULL; // Caller must cope with this (TODO throw RewriteEmptyStreamException)
- }
-
- // Traversed all the available elements already?
- if ( m_cursor >= n) // out of elements?
- {
- if (n == 1)
- {
- // Special case when size is single element, it will just dup a lot
- //return this->toTree(m_singleElement);
- return this->toTree(m_elements.at(0));
- }
-
- // Out of elements and the size is not 1, so we cannot assume
- // that we just duplicate the entry n times (such as ID ent+ -> ^(ID ent)+)
- // This means we ran out of elements earlier than was expected.
- //
- return NULL; // Caller must cope with this (TODO throw RewriteEmptyStreamException)
- }
-
- // More than just a single element so we extract it from the
- // vector.
- ElementType* t = this->toTree(m_elements.at(m_cursor));
- m_cursor++;
- return t;
+ ANTLR_UINT32 n = this->size();
+
+ if (n == 0)
+ {
+ // This means that the stream is empty
+ return NULL; // Caller must cope with this (TODO throw RewriteEmptyStreamException)
+ }
+
+ // Traversed all the available elements already?
+ if ( m_cursor >= n) // out of elements?
+ {
+ if (n == 1)
+ {
+ // Special case when size is single element, it will just dup a lot
+ //return this->toTree(m_singleElement);
+ return this->toTree(m_elements.at(0));
+ }
+
+ // Out of elements and the size is not 1, so we cannot assume
+ // that we just duplicate the entry n times (such as ID ent+ -> ^(ID ent)+)
+ // This means we ran out of elements earlier than was expected.
+ //
+ return NULL; // Caller must cope with this (TODO throw RewriteEmptyStreamException)
+ }
+
+ // More than just a single element so we extract it from the
+ // vector.
+ ElementType* t = this->toTree(m_elements.at(m_cursor));
+ m_cursor++;
+ return t;
}
-template<class ImplTraits, class ElementType>
-ElementType
-RewriteRuleElementStream<ImplTraits, ElementType>::nextTree()
+template<class ImplTraits, class ElementType>
+ElementType
+RewriteRuleElementStream<ImplTraits, ElementType>::nextTree()
{
- ANTLR_UINT32 n = this->size();
- if ( m_dirty || ( (m_cursor >=n) && (n==1)) )
- {
- // if out of elements and size is 1, dup
- ElementType* el = this->_next();
- return this->dup(el);
- }
-
- // test size above then fetch
- ElementType* el = this->_next();
- return el;
+ ANTLR_UINT32 n = this->size();
+ if ( m_dirty || ( (m_cursor >=n) && (n==1)) )
+ {
+ // if out of elements and size is 1, dup
+ ElementType* el = this->_next();
+ return this->dup(el);
+ }
+
+ // test size above then fetch
+ ElementType* el = this->_next();
+ return el;
}
-/*
+/*
template<class ImplTraits, class SuperType>
typename RewriteRuleElementStream<ImplTraits, SuperType>::TokenType*
RewriteRuleElementStream<ImplTraits, SuperType>::nextToken()
{
- return this->_next();
+ return this->_next();
}
template<class ImplTraits, class SuperType>
typename RewriteRuleElementStream<ImplTraits, SuperType>::TokenType*
RewriteRuleElementStream<ImplTraits, SuperType>::next()
{
- ANTLR_UINT32 s;
- s = this->size();
- if ( (m_cursor >= s) && (s == 1) )
- {
- TreeTypePtr el;
- el = this->_next();
- return this->dup(el);
- }
- return this->_next();
-}
-
-*/
-
-template<class ImplTraits, class ElementType>
-ElementType*
-RewriteRuleElementStream<ImplTraits, ElementType>::dup( ElementType* element)
-{
- return dupImpl(element);
-}
-
-template<class ImplTraits, class ElementType>
-ElementType*
-RewriteRuleElementStream<ImplTraits, ElementType>::dupImpl( typename ImplTraits::CommonTokenType* element)
-{
- return NULL; // TODO throw here
-}
-
-template<class ImplTraits, class ElementType>
-ElementType*
-RewriteRuleElementStream<ImplTraits, ElementType>::dupImpl( typename ImplTraits::TreeTypePtr element)
-{
- return m_adaptor->dupTree(element);
-}
-
+ ANTLR_UINT32 s;
+ s = this->size();
+ if ( (m_cursor >= s) && (s == 1) )
+ {
+ TreeTypePtr el;
+ el = this->_next();
+ return this->dup(el);
+ }
+ return this->_next();
+}
+
+*/
+
+template<class ImplTraits, class ElementType>
+ElementType*
+RewriteRuleElementStream<ImplTraits, ElementType>::dup( ElementType* element)
+{
+ return dupImpl(element);
+}
+
+template<class ImplTraits, class ElementType>
+ElementType*
+RewriteRuleElementStream<ImplTraits, ElementType>::dupImpl( typename ImplTraits::CommonTokenType* element)
+{
+ return NULL; // TODO throw here
+}
+
+template<class ImplTraits, class ElementType>
+ElementType*
+RewriteRuleElementStream<ImplTraits, ElementType>::dupImpl( typename ImplTraits::TreeTypePtr element)
+{
+ return m_adaptor->dupTree(element);
+}
+
template<class ImplTraits>
-typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
-RewriteRuleSubtreeStream<ImplTraits>::dup(TreeTypePtr element)
+typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
+RewriteRuleSubtreeStream<ImplTraits>::dup(TreeTypePtr element)
{
- return this->dupTree(element);
+ return this->dupTree(element);
}
template<class ImplTraits>
-typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
-RewriteRuleSubtreeStream<ImplTraits>::dupTree(TreeTypePtr element)
+typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
+RewriteRuleSubtreeStream<ImplTraits>::dupTree(TreeTypePtr element)
{
- return BaseType::m_adaptor->dupNode(element);
+ return BaseType::m_adaptor->dupNode(element);
}
-template<class ImplTraits, class ElementType>
-ElementType*
-RewriteRuleElementStream<ImplTraits, ElementType>::toTree( ElementType* element)
+template<class ImplTraits, class ElementType>
+ElementType*
+RewriteRuleElementStream<ImplTraits, ElementType>::toTree( ElementType* element)
{
- return element;
+ return element;
}
-/*
+/*
template<class ImplTraits>
-typename RewriteRuleNodeStream<ImplTraits>::TreeTypePtr
-RewriteRuleNodeStream<ImplTraits>::toTree(TreeTypePtr element)
+typename RewriteRuleNodeStream<ImplTraits>::TreeTypePtr
+RewriteRuleNodeStream<ImplTraits>::toTree(TreeTypePtr element)
{
- return this->toTreeNode(element);
+ return this->toTreeNode(element);
}
template<class ImplTraits>
-typename RewriteRuleNodeStream<ImplTraits>::TreeTypePtr
-RewriteRuleNodeStream<ImplTraits>::toTreeNode(TreeTypePtr element)
+typename RewriteRuleNodeStream<ImplTraits>::TreeTypePtr
+RewriteRuleNodeStream<ImplTraits>::toTreeNode(TreeTypePtr element)
{
- return BaseType::m_adaptor->dupNode(element);
+ return BaseType::m_adaptor->dupNode(element);
}
-*/
+*/
-template<class ImplTraits, class ElementType>
-bool RewriteRuleElementStream<ImplTraits, ElementType>::hasNext()
+template<class ImplTraits, class ElementType>
+bool RewriteRuleElementStream<ImplTraits, ElementType>::hasNext()
{
- if ( !m_elements.empty() && m_cursor < m_elements.size())
- {
- return true;
- }
- else
- {
- return false;
- }
+ if ( !m_elements.empty() && m_cursor < m_elements.size())
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
template<class ImplTraits >
-typename RewriteRuleTokenStream<ImplTraits>::TreeTypePtr
+typename RewriteRuleTokenStream<ImplTraits>::TreeTypePtr
RewriteRuleTokenStream<ImplTraits>::nextNode()
{
- TokenType *Token = this->nextToken();
- //return BaseType::m_adaptor->create(Token);
- return m_adaptor->create(Token);
+ TokenType *Token = this->nextToken();
+ //return BaseType::m_adaptor->create(Token);
+ return m_adaptor->create(Token);
}
-/*
+/*
template<class ImplTraits>
-typename RewriteRuleTokenStream<ImplTraits>::TreeTypePtr
+typename RewriteRuleTokenStream<ImplTraits>::TreeTypePtr
RewriteRuleTokenStream<ImplTraits>::nextNodeToken()
{
- return BaseType::m_adaptor->create(this->_next());
+ return BaseType::m_adaptor->create(this->_next());
}
-*/
+*/
/// Number of elements available in the stream
///
-template<class ImplTraits, class ElementType>
-ANTLR_UINT32 RewriteRuleElementStream<ImplTraits, ElementType>::size()
+template<class ImplTraits, class ElementType>
+ANTLR_UINT32 RewriteRuleElementStream<ImplTraits, ElementType>::size()
{
- return (ANTLR_UINT32)(m_elements.size());
+ return (ANTLR_UINT32)(m_elements.size());
}
-template<class ImplTraits, class ElementType>
-typename RewriteRuleElementStream<ImplTraits, ElementType>::StringType
-RewriteRuleElementStream<ImplTraits, ElementType>::getDescription()
+template<class ImplTraits, class ElementType>
+typename RewriteRuleElementStream<ImplTraits, ElementType>::StringType
+RewriteRuleElementStream<ImplTraits, ElementType>::getDescription()
{
- if ( m_elementDescription.empty() )
- {
- m_elementDescription = "<unknown source>";
- }
- return m_elementDescription;
+ if ( m_elementDescription.empty() )
+ {
+ m_elementDescription = "<unknown source>";
+ }
+ return m_elementDescription;
}
-template<class ImplTraits, class ElementType>
-RewriteRuleElementStream<ImplTraits, ElementType>::~RewriteRuleElementStream()
+template<class ImplTraits, class ElementType>
+RewriteRuleElementStream<ImplTraits, ElementType>::~RewriteRuleElementStream()
{
// Before placing the stream back in the pool, we
- // need to clear any vector it has. This is so any
- // free pointers that are associated with the
- // entries are called. However, if this particular function is called
- // then we know that the entries in the stream are definitely
+ // need to clear any vector it has. This is so any
+ // free pointers that are associated with the
+ // entries are called. However, if this particular function is called
+ // then we know that the entries in the stream are definitely
// tree nodes. Hence we check to see if any of them were nilNodes as
// if they were, we can reuse them.
- //
- // We have some elements to traverse
- //
- for (ANTLR_UINT32 i = 0; i < m_elements.size(); i++)
- {
- ElementType *tree = m_elements.at(i);
- //if ( (tree != NULL) && tree->isNilNode() )
- {
- // Had to remove this for now, check is not comprehensive enough
- // tree->reuse(tree);
- }
- }
- m_elements.clear();
-}
-
-template<class ImplTraits>
-typename RewriteRuleTokenStream<ImplTraits>::TokenType*
-RewriteRuleTokenStream<ImplTraits>::nextToken()
-{
- return this->_next();
-}
-
-template<class ImplTraits>
-typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
-RewriteRuleSubtreeStream<ImplTraits>::nextNode(TreeTypePtr element)
-{
- //System.out.println("nextNode: elements="+elements+", singleElement="+((Tree)singleElement).toStringTree());
- ANTLR_UINT32 n = this->size();
- if ( BaseType::m_dirty || (BaseType::m_cursor>=n && n==1) ) {
- // if out of elements and size is 1, dup (at most a single node
- // since this is for making root nodes).
- TreeTypePtr el = this->_next();
- return BaseType::m_adaptor->dupNode(el);
- }
- // test size above then fetch
- TreeType *tree = this->_next();
- while (BaseType::m_adaptor.isNil(tree) && BaseType::m_adaptor.getChildCount(tree) == 1)
- tree = BaseType::m_adaptor->getChild(tree, 0);
- //System.out.println("_next="+((Tree)tree).toStringTree());
- TreeType *el = BaseType::m_adaptor->dupNode(tree); // dup just the root (want node here)
- return el;
-}
-
-}
+ //
+ // We have some elements to traverse
+ //
+ for (ANTLR_UINT32 i = 0; i < m_elements.size(); i++)
+ {
+ ElementType *tree = m_elements.at(i);
+ //if ( (tree != NULL) && tree->isNilNode() )
+ {
+ // Had to remove this for now, check is not comprehensive enough
+ // tree->reuse(tree);
+ }
+ }
+ m_elements.clear();
+}
+
+template<class ImplTraits>
+typename RewriteRuleTokenStream<ImplTraits>::TokenType*
+RewriteRuleTokenStream<ImplTraits>::nextToken()
+{
+ return this->_next();
+}
+
+template<class ImplTraits>
+typename RewriteRuleSubtreeStream<ImplTraits>::TreeTypePtr
+RewriteRuleSubtreeStream<ImplTraits>::nextNode(TreeTypePtr element)
+{
+ //System.out.println("nextNode: elements="+elements+", singleElement="+((Tree)singleElement).toStringTree());
+ ANTLR_UINT32 n = this->size();
+ if ( BaseType::m_dirty || (BaseType::m_cursor>=n && n==1) ) {
+ // if out of elements and size is 1, dup (at most a single node
+ // since this is for making root nodes).
+ TreeTypePtr el = this->_next();
+ return BaseType::m_adaptor->dupNode(el);
+ }
+ // test size above then fetch
+ TreeType *tree = this->_next();
+ while (BaseType::m_adaptor.isNil(tree) && BaseType::m_adaptor.getChildCount(tree) == 1)
+ tree = BaseType::m_adaptor->getChild(tree, 0);
+ //System.out.println("_next="+((Tree)tree).toStringTree());
+ TreeType *el = BaseType::m_adaptor->dupNode(tree); // dup just the root (want node here)
+ return el;
+}
+
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3tokenstream.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3tokenstream.hpp
index 706519714d..947ac097c8 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3tokenstream.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3tokenstream.hpp
@@ -3,8 +3,8 @@
* one of these and then override any functions by installing their own pointers
* to implement the various functions.
*/
-#ifndef _ANTLR3_TOKENSTREAM_HPP
-#define _ANTLR3_TOKENSTREAM_HPP
+#ifndef _ANTLR3_TOKENSTREAM_HPP
+#define _ANTLR3_TOKENSTREAM_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -41,17 +41,17 @@
* multiple interfaces without defining them in the interface structure
* or casting (void *), which is too convoluted.
*/
-namespace antlr3 {
+namespace antlr3 {
//We are not making it subclass AllocPolicy, as this will always be a base class
template<class ImplTraits>
class TokenSource
{
public:
- typedef typename ImplTraits::CommonTokenType TokenType;
- typedef TokenType CommonTokenType;
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::LexerType LexerType;
+ typedef typename ImplTraits::CommonTokenType TokenType;
+ typedef TokenType CommonTokenType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::LexerType LexerType;
private:
/** A special pre-allocated token, which signifies End Of Tokens. Because this must
@@ -59,75 +59,75 @@ private:
* return the address of it. It is marked as factoryMade, so that it is never
* attempted to be freed.
*/
- TokenType m_eofToken;
+ TokenType m_eofToken;
- /// A special pre-allocated token, which is returned by mTokens() if the
- /// lexer rule said to just skip the generated token altogether.
- /// Having this single token stops us wasting memory by have the token factory
- /// actually create something that we are going to SKIP(); anyway.
- ///
- TokenType m_skipToken;
+ /// A special pre-allocated token, which is returned by mTokens() if the
+ /// lexer rule said to just skip the generated token altogether.
+ /// Having this single token stops us wasting memory by have the token factory
+ /// actually create something that we are going to SKIP(); anyway.
+ ///
+ TokenType m_skipToken;
/** When the token source is constructed, it is populated with the file
* name from whence the tokens were produced by the lexer. This pointer is a
* copy of the one supplied by the CharStream (and may be NULL) so should
* not be manipulated other than to copy or print it.
*/
- StringType m_fileName;
+ StringType m_fileName;
public:
- TokenType& get_eofToken();
- const TokenType& get_eofToken() const;
- TokenType& get_skipToken();
- StringType& get_fileName();
- LexerType* get_super();
-
- void set_fileName( const StringType& fileName );
-
- /**
- * \brief
- * Default implementation of the nextToken() call for a lexer.
- *
- * \param toksource
- * Points to the implementation of a token source. The lexer is
- * addressed by the super structure pointer.
- *
- * \returns
- * The next token in the current input stream or the EOF token
- * if there are no more tokens in any input stream in the stack.
- *
- * Write detailed description for nextToken here.
- *
- * \remarks
- * Write remarks for nextToken here.
- *
- * \see nextTokenStr
- */
+ TokenType& get_eofToken();
+ const TokenType& get_eofToken() const;
+ TokenType& get_skipToken();
+ StringType& get_fileName();
+ LexerType* get_super();
+
+ void set_fileName( const StringType& fileName );
+
+ /**
+ * \brief
+ * Default implementation of the nextToken() call for a lexer.
+ *
+ * \param toksource
+ * Points to the implementation of a token source. The lexer is
+ * addressed by the super structure pointer.
+ *
+ * \returns
+ * The next token in the current input stream or the EOF token
+ * if there are no more tokens in any input stream in the stack.
+ *
+ * Write detailed description for nextToken here.
+ *
+ * \remarks
+ * Write remarks for nextToken here.
+ *
+ * \see nextTokenStr
+ */
TokenType* nextToken();
- CommonTokenType* nextToken( BoolForwarder<true> /*isFiltered*/ );
- CommonTokenType* nextToken( BoolForwarder<false> /*isFiltered*/ );
-
- ///
- /// \brief
- /// Returns the next available token from the current input stream.
- ///
- /// \param toksource
- /// Points to the implementation of a token source. The lexer is
- /// addressed by the super structure pointer.
- ///
- /// \returns
- /// The next token in the current input stream or the EOF token
- /// if there are no more tokens.
- ///
- /// \remarks
- /// Write remarks for nextToken here.
- ///
- /// \see nextToken
- ///
- TokenType* nextTokenStr();
+ CommonTokenType* nextToken( BoolForwarder<true> /*isFiltered*/ );
+ CommonTokenType* nextToken( BoolForwarder<false> /*isFiltered*/ );
+
+ ///
+ /// \brief
+ /// Returns the next available token from the current input stream.
+ ///
+ /// \param toksource
+ /// Points to the implementation of a token source. The lexer is
+ /// addressed by the super structure pointer.
+ ///
+ /// \returns
+ /// The next token in the current input stream or the EOF token
+ /// if there are no more tokens.
+ ///
+ /// \remarks
+ /// Write remarks for nextToken here.
+ ///
+ /// \see nextToken
+ ///
+ TokenType* nextTokenStr();
protected:
- TokenSource();
+ TokenSource();
};
/** Definition of the ANTLR3 common token stream interface.
@@ -138,33 +138,33 @@ template<class ImplTraits>
class TokenStream : public ImplTraits::TokenIntStreamType
{
public:
- typedef typename ImplTraits::TokenSourceType TokenSourceType;
- typedef typename ImplTraits::TokenIntStreamType IntStreamType;
- typedef typename ImplTraits::CommonTokenType TokenType;
- typedef TokenType UnitType;
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::DebugEventListenerType DebugEventListenerType;
- typedef typename ImplTraits::TokenStreamType TokenStreamType;
- typedef typename ImplTraits::ParserType ComponentType;
+ typedef typename ImplTraits::TokenSourceType TokenSourceType;
+ typedef typename ImplTraits::TokenIntStreamType IntStreamType;
+ typedef typename ImplTraits::CommonTokenType TokenType;
+ typedef TokenType UnitType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::DebugEventListenerType DebugEventListenerType;
+ typedef typename ImplTraits::TokenStreamType TokenStreamType;
+ typedef typename ImplTraits::ParserType ComponentType;
protected:
/** Pointer to the token source for this stream
*/
TokenSourceType* m_tokenSource;
- /// Debugger interface, is this is a debugging token stream
- ///
- DebugEventListenerType* m_debugger;
+ /// Debugger interface, is this is a debugging token stream
+ ///
+ DebugEventListenerType* m_debugger;
- /// Indicates the initial stream state for dbgConsume()
- ///
- bool m_initialStreamState;
+ /// Indicates the initial stream state for dbgConsume()
+ ///
+ bool m_initialStreamState;
public:
- TokenStream(TokenSourceType* source, DebugEventListenerType* debugger);
- IntStreamType* get_istream();
- TokenSourceType* get_tokenSource() const;
- void set_tokenSource( TokenSourceType* tokenSource );
+ TokenStream(TokenSourceType* source, DebugEventListenerType* debugger);
+ IntStreamType* get_istream();
+ TokenSourceType* get_tokenSource() const;
+ void set_tokenSource( TokenSourceType* tokenSource );
/** Get Token at current input pointer + i ahead where i=1 is next Token.
* i<0 indicates tokens in the past. So -1 is previous token and -2 is
@@ -172,7 +172,7 @@ public:
* Return null for LT(0) and any index that results in an absolute address
* that is negative.
*/
- const TokenType* LT(ANTLR_INT32 k);
+ const TokenType* LT(ANTLR_INT32 k);
/** Where is this stream pulling tokens from? This is not the name, but
* a pointer into an interface that contains a ANTLR3_TOKEN_SOURCE interface.
@@ -183,19 +183,19 @@ public:
/** Function that installs a token source for teh stream
*/
- void setTokenSource(TokenSourceType* tokenSource);
+ void setTokenSource(TokenSourceType* tokenSource);
/** Return the text of all the tokens in the stream, as the old tramp in
* Leeds market used to say; "Get the lot!"
*/
- StringType toString();
+ StringType toString();
/** Return the text of all tokens from start to stop, inclusive.
* If the stream does not buffer all the tokens then it can just
* return an empty ANTLR3_STRING or NULL; Grammars should not access $ruleLabel.text in
* an action in that case.
*/
- StringType toStringSS(ANTLR_MARKER start, ANTLR_MARKER stop);
+ StringType toStringSS(ANTLR_MARKER start, ANTLR_MARKER stop);
/** Because the user is not required to use a token with an index stored
* in it, we must provide a means for two token objects themselves to
@@ -203,14 +203,14 @@ public:
* to the other toString(int,int). This is also parallel with
* the pTREENODE_STREAM->toString(Object,Object).
*/
- StringType toStringTT(const TokenType* start, const TokenType* stop);
+ StringType toStringTT(const TokenType* start, const TokenType* stop);
/** Function that sets the token stream into debugging mode
*/
- void setDebugListener(DebugEventListenerType* debugger);
+ void setDebugListener(DebugEventListenerType* debugger);
- TokenStream();
+ TokenStream();
};
@@ -222,34 +222,34 @@ template<bool TOKENS_ACCESSED_FROM_OWNING_RULE, class ListType, class MapType>
class TokenStoreSelector
{
public:
- typedef ListType TokensType;
+ typedef ListType TokensType;
};
template<class ListType, class MapType>
class TokenStoreSelector<true, ListType, MapType>
{
public:
- typedef MapType TokensType;
+ typedef MapType TokensType;
};
template<class ImplTraits>
-class CommonTokenStream : public TokenStream<ImplTraits>
+class CommonTokenStream : public TokenStream<ImplTraits>
{
public:
- typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
- typedef typename ImplTraits::BitsetType BitsetType;
- typedef typename ImplTraits::CommonTokenType TokenType;
- typedef typename ImplTraits::TokenSourceType TokenSourceType;
- typedef typename ImplTraits::DebugEventListenerType DebugEventListenerType;
- typedef typename AllocPolicyType::template ListType<TokenType> TokensListType;
- typedef typename AllocPolicyType::template OrderedMapType<ANTLR_MARKER, TokenType> TokensMapType;
- typedef typename TokenStoreSelector< ImplTraits::TOKENS_ACCESSED_FROM_OWNING_RULE,
- TokensListType, TokensMapType >::TokensType TokensType;
-
- typedef typename AllocPolicyType::template UnOrderedMapType<ANTLR_UINT32, ANTLR_UINT32> ChannelOverridesType;
- typedef typename AllocPolicyType::template OrderedSetType<ANTLR_UINT32> DiscardSetType;
- typedef typename AllocPolicyType::template ListType<ANTLR_UINT32> IntListType;
- typedef TokenStream<ImplTraits> BaseType;
+ typedef typename ImplTraits::AllocPolicyType AllocPolicyType;
+ typedef typename ImplTraits::BitsetType BitsetType;
+ typedef typename ImplTraits::CommonTokenType TokenType;
+ typedef typename ImplTraits::TokenSourceType TokenSourceType;
+ typedef typename ImplTraits::DebugEventListenerType DebugEventListenerType;
+ typedef typename AllocPolicyType::template ListType<TokenType> TokensListType;
+ typedef typename AllocPolicyType::template OrderedMapType<ANTLR_MARKER, TokenType> TokensMapType;
+ typedef typename TokenStoreSelector< ImplTraits::TOKENS_ACCESSED_FROM_OWNING_RULE,
+ TokensListType, TokensMapType >::TokensType TokensType;
+
+ typedef typename AllocPolicyType::template UnOrderedMapType<ANTLR_UINT32, ANTLR_UINT32> ChannelOverridesType;
+ typedef typename AllocPolicyType::template OrderedSetType<ANTLR_UINT32> DiscardSetType;
+ typedef typename AllocPolicyType::template ListType<ANTLR_UINT32> IntListType;
+ typedef TokenStream<ImplTraits> BaseType;
private:
/** Records every single token pulled from the source indexed by the token index.
@@ -258,53 +258,53 @@ private:
* a huge overhead as it only stores pointers anyway, but allows for iterations and
* so on.
*/
- TokensType m_tokens;
+ TokensType m_tokens;
/** Override map of tokens. If a token type has an entry in here, then
* the pointer in the table points to an int, being the override channel number
* that should always be used for this token type.
*/
- ChannelOverridesType m_channelOverrides;
+ ChannelOverridesType m_channelOverrides;
/** Discared set. If a token has an entry in this table, then it is thrown
* away (data pointer is always NULL).
*/
- DiscardSetType m_discardSet;
+ DiscardSetType m_discardSet;
/* The channel number that this token stream is tuned to. For instance, whitespace
* is usually tuned to channel 99, which no token stream would normally tune to and
* so it is thrown away.
*/
- ANTLR_UINT32 m_channel;
+ ANTLR_UINT32 m_channel;
- /** The index into the tokens list of the current token (the next one that will be
+ /** The index into the tokens list of the current token (the next one that will be
* consumed. p = -1 indicates that the token list is empty.
*/
- ANTLR_INT32 m_p;
+ ANTLR_INT32 m_p;
- /* The total number of tokens issued till now. For streams that delete tokens,
- this helps in issuing the index
- */
- ANTLR_UINT32 m_nissued;
+ /* The total number of tokens issued till now. For streams that delete tokens,
+ this helps in issuing the index
+ */
+ ANTLR_UINT32 m_nissued;
/** If this flag is set to true, then tokens that the stream sees that are not
* in the channel that this stream is tuned to, are not tracked in the
* tokens table. When set to false, ALL tokens are added to the tracking.
*/
- bool m_discardOffChannel;
+ bool m_discardOffChannel;
public:
- CommonTokenStream(ANTLR_UINT32 hint, TokenSourceType* source = NULL,
- DebugEventListenerType* debugger = NULL);
- ~CommonTokenStream();
- TokensType& get_tokens();
- const TokensType& get_tokens() const;
- DiscardSetType& get_discardSet();
- const DiscardSetType& get_discardSet() const;
- ANTLR_INT32 get_p() const;
- void set_p( ANTLR_INT32 p );
- void inc_p();
- void dec_p();
+ CommonTokenStream(ANTLR_UINT32 hint, TokenSourceType* source = NULL,
+ DebugEventListenerType* debugger = NULL);
+ ~CommonTokenStream();
+ TokensType& get_tokens();
+ const TokensType& get_tokens() const;
+ DiscardSetType& get_discardSet();
+ const DiscardSetType& get_discardSet() const;
+ ANTLR_INT32 get_p() const;
+ void set_p( ANTLR_INT32 p );
+ void inc_p();
+ void dec_p();
/** A simple filter mechanism whereby you can tell this token stream
* to force all tokens of type ttype to be on channel. For example,
@@ -319,28 +319,28 @@ public:
*/
void discardTokenType(ANTLR_INT32 ttype);
- //This will discard tokens of a particular rule after the rule execution completion
- void discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop );
- void discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop,
- BoolForwarder<true> tokens_accessed_from_owning_rule );
- void discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop,
- BoolForwarder<false> tokens_accessed_from_owning_rule );
-
- void insertToken( const TokenType& tok );
- void insertToken( const TokenType& tok, BoolForwarder<true> tokens_accessed_from_owning_rule );
- void insertToken( const TokenType& tok, BoolForwarder<false> tokens_accessed_from_owning_rule );
-
- /** Get a token at an absolute index i; 0..n-1. This is really only
- * needed for profiling and debugging and token stream rewriting.
- * If you don't want to buffer up tokens, then this method makes no
- * sense for you. Naturally you can't use the rewrite stream feature.
- * I believe DebugTokenStream can easily be altered to not use
- * this method, removing the dependency.
- */
- const TokenType* get(ANTLR_MARKER i);
- const TokenType* getToken(ANTLR_MARKER i);
- const TokenType* getToken( ANTLR_MARKER tok_idx, BoolForwarder<true> tokens_accessed_from_owning_rule );
- const TokenType* getToken( ANTLR_MARKER tok_idx, BoolForwarder<false> tokens_accessed_from_owning_rule );
+ //This will discard tokens of a particular rule after the rule execution completion
+ void discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop );
+ void discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop,
+ BoolForwarder<true> tokens_accessed_from_owning_rule );
+ void discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop,
+ BoolForwarder<false> tokens_accessed_from_owning_rule );
+
+ void insertToken( const TokenType& tok );
+ void insertToken( const TokenType& tok, BoolForwarder<true> tokens_accessed_from_owning_rule );
+ void insertToken( const TokenType& tok, BoolForwarder<false> tokens_accessed_from_owning_rule );
+
+ /** Get a token at an absolute index i; 0..n-1. This is really only
+ * needed for profiling and debugging and token stream rewriting.
+ * If you don't want to buffer up tokens, then this method makes no
+ * sense for you. Naturally you can't use the rewrite stream feature.
+ * I believe DebugTokenStream can easily be altered to not use
+ * this method, removing the dependency.
+ */
+ const TokenType* get(ANTLR_MARKER i);
+ const TokenType* getToken(ANTLR_MARKER i);
+ const TokenType* getToken( ANTLR_MARKER tok_idx, BoolForwarder<true> tokens_accessed_from_owning_rule );
+ const TokenType* getToken( ANTLR_MARKER tok_idx, BoolForwarder<false> tokens_accessed_from_owning_rule );
/** Signal to discard off channel tokens from here on in.
*/
@@ -349,7 +349,7 @@ public:
/** Function that returns a pointer to the ANTLR3_LIST of all tokens
* in the stream (this causes the buffer to fill if we have not get any yet)
*/
- TokensType* getTokens();
+ TokensType* getTokens();
/** Function that returns all the tokens between a start and a stop index.
*/
@@ -362,7 +362,7 @@ public:
/** Function that returns all the tokens indicated by being a member of the supplied List
*/
void getTokensList(ANTLR_UINT32 start, ANTLR_UINT32 stop,
- const IntListType& list, TokensListType& tokenList);
+ const IntListType& list, TokensListType& tokenList);
/** Function that returns all tokens of a certain type within a range.
*/
@@ -377,29 +377,29 @@ public:
*/
void reset();
- const TokenType* LB(ANTLR_INT32 k);
+ const TokenType* LB(ANTLR_INT32 k);
- void fillBufferExt();
- void fillBuffer();
+ void fillBufferExt();
+ void fillBuffer();
- bool hasReachedFillbufferTarget( ANTLR_UINT32 cnt, BoolForwarder<true> tokens_accessed_from_owning_rule );
- bool hasReachedFillbufferTarget( ANTLR_UINT32 cnt, BoolForwarder<false> tokens_accessed_from_owning_rule );
+ bool hasReachedFillbufferTarget( ANTLR_UINT32 cnt, BoolForwarder<true> tokens_accessed_from_owning_rule );
+ bool hasReachedFillbufferTarget( ANTLR_UINT32 cnt, BoolForwarder<false> tokens_accessed_from_owning_rule );
- ANTLR_UINT32 skipOffTokenChannels(ANTLR_INT32 i);
- ANTLR_UINT32 skipOffTokenChannelsReverse(ANTLR_INT32 x);
- ANTLR_MARKER index_impl();
+ ANTLR_UINT32 skipOffTokenChannels(ANTLR_INT32 i);
+ ANTLR_UINT32 skipOffTokenChannelsReverse(ANTLR_INT32 x);
+ ANTLR_MARKER index_impl();
};
class TokenAccessException : public std::exception
{
virtual const char* what() const noexcept
- {
- return " Attempted access on Deleted Token";
- }
+ {
+ return " Attempted access on Deleted Token";
+ }
};
-}
+}
#include "antlr3tokenstream.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3tokenstream.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3tokenstream.inl
index 50e5c288d5..b2c4e3bcc8 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3tokenstream.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3tokenstream.inl
@@ -1,56 +1,56 @@
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits>
TokenSource<ImplTraits>::TokenSource()
- :m_eofToken( ImplTraits::CommonTokenType::TOKEN_EOF),
- m_skipToken( ImplTraits::CommonTokenType::TOKEN_INVALID)
+ :m_eofToken( ImplTraits::CommonTokenType::TOKEN_EOF),
+ m_skipToken( ImplTraits::CommonTokenType::TOKEN_INVALID)
{
}
template<class ImplTraits>
ANTLR_INLINE typename TokenSource<ImplTraits>::CommonTokenType& TokenSource<ImplTraits>::get_eofToken()
{
- return m_eofToken;
+ return m_eofToken;
}
template<class ImplTraits>
ANTLR_INLINE const typename TokenSource<ImplTraits>::TokenType& TokenSource<ImplTraits>::get_eofToken() const
{
- return m_eofToken;
+ return m_eofToken;
}
template<class ImplTraits>
ANTLR_INLINE typename TokenSource<ImplTraits>::CommonTokenType& TokenSource<ImplTraits>::get_skipToken()
{
- return m_skipToken;
+ return m_skipToken;
}
template<class ImplTraits>
ANTLR_INLINE typename TokenSource<ImplTraits>::StringType& TokenSource<ImplTraits>::get_fileName()
{
- return m_fileName;
+ return m_fileName;
}
template<class ImplTraits>
ANTLR_INLINE void TokenSource<ImplTraits>::set_fileName( const StringType& fileName )
{
- m_fileName = fileName;
+ m_fileName = fileName;
}
template<class ImplTraits>
typename TokenSource<ImplTraits>::LexerType* TokenSource<ImplTraits>::get_super()
{
- return static_cast<LexerType*>(this);
+ return static_cast<LexerType*>(this);
}
template<class ImplTraits>
-typename TokenSource<ImplTraits>::TokenType* TokenSource<ImplTraits>::nextTokenStr()
+typename TokenSource<ImplTraits>::TokenType* TokenSource<ImplTraits>::nextTokenStr()
{
- typedef typename LexerType::RecognizerSharedStateType RecognizerSharedStateType;
- typedef typename LexerType::InputStreamType InputStreamType;
- typedef typename LexerType::IntStreamType IntStreamType;
- LexerType* lexer;
- RecognizerSharedStateType* state;
+ typedef typename LexerType::RecognizerSharedStateType RecognizerSharedStateType;
+ typedef typename LexerType::InputStreamType InputStreamType;
+ typedef typename LexerType::IntStreamType IntStreamType;
+ LexerType* lexer;
+ RecognizerSharedStateType* state;
InputStreamType* input;
IntStreamType* istream;
@@ -61,18 +61,18 @@ typename TokenSource<ImplTraits>::TokenType* TokenSource<ImplTraits>::nextTokenS
/// Loop until we get a non skipped token or EOF
///
- for (;;)
+ for (;;)
{
// Get rid of any previous token (token factory takes care of
// any de-allocation when this token is finally used up.
//
state->set_token_present(false);
- state->set_error(false); // Start out without an exception
+ state->set_error(false); // Start out without an exception
state->set_failed(false);
// Now call the matching rules and see if we can generate a new token
//
- for (;;)
+ for (;;)
{
// Record the start of the token in our input stream.
//
@@ -82,7 +82,7 @@ typename TokenSource<ImplTraits>::TokenType* TokenSource<ImplTraits>::nextTokenS
state->set_tokenStartLine( input->get_line() );
state->set_text("");
- if (istream->LA(1) == ANTLR_CHARSTREAM_EOF)
+ if (istream->LA(1) == ANTLR_CHARSTREAM_EOF)
{
// Reached the end of the current stream, nothing more to do if this is
// the last in the stack.
@@ -96,7 +96,7 @@ typename TokenSource<ImplTraits>::TokenType* TokenSource<ImplTraits>::nextTokenS
}
state->set_token_present( false );
- state->set_error(false); // Start out without an exception
+ state->set_error(false); // Start out without an exception
state->set_failed(false);
// Call the generated lexer, see if it can get a new token together.
@@ -109,11 +109,11 @@ typename TokenSource<ImplTraits>::TokenType* TokenSource<ImplTraits>::nextTokenS
//
state->set_failed(true);
lexer->get_rec()->reportError();
- lexer->recover();
- if (state->get_token_present())
- // Good(or invalid) token factored by custom recover procedure
- //
- return state->get_token();
+ lexer->recover();
+ if (state->get_token_present())
+ // Good(or invalid) token factored by custom recover procedure
+ //
+ return state->get_token();
}
else
{
@@ -123,7 +123,7 @@ typename TokenSource<ImplTraits>::TokenType* TokenSource<ImplTraits>::nextTokenS
//
lexer->emit();
}
- else if ( *(state->get_token()) == m_skipToken )
+ else if ( *(state->get_token()) == m_skipToken )
{
// A real token could have been generated, but "Computer say's naaaaah" and it
// it is just something we need to skip altogether.
@@ -142,217 +142,217 @@ typename TokenSource<ImplTraits>::TokenType* TokenSource<ImplTraits>::nextTokenS
template<class ImplTraits>
typename TokenSource<ImplTraits>::TokenType* TokenSource<ImplTraits>::nextToken()
{
- return this->nextToken( BoolForwarder<LexerType::IsFiltered>() );
-}
-
-template<class ImplTraits>
-typename TokenSource<ImplTraits>::CommonTokenType* TokenSource<ImplTraits>::nextToken( BoolForwarder<true> /*isFiltered*/ )
-{
- LexerType* lexer;
- typename LexerType::RecognizerSharedStateType* state;
-
- lexer = this->get_super();
- state = lexer->get_lexstate();
-
- /* Get rid of any previous token (token factory takes care of
- * any deallocation when this token is finally used up.
- */
- state->set_token_present( false );
- state->set_error( false ); /* Start out without an exception */
- state->set_failed(false);
-
- /* Record the start of the token in our input stream.
- */
- state->set_tokenStartCharIndex( lexer->index() );
- state->set_tokenStartCharPositionInLine( lexer->getCharPositionInLine() );
- state->set_tokenStartLine( lexer->getLine() );
- state->set_text("");
-
- /* Now call the matching rules and see if we can generate a new token
- */
- for (;;)
- {
- if (lexer->LA(1) == ANTLR_CHARSTREAM_EOF)
- {
- /* Reached the end of the stream, nothing more to do.
- */
- CommonTokenType& teof = m_eofToken;
-
- teof.set_startIndex(lexer->getCharIndex());
- teof.set_stopIndex(lexer->getCharIndex());
- teof.set_line(lexer->getLine());
- return &teof;
- }
-
- state->set_token_present(false);
- state->set_error(false); /* Start out without an exception */
-
- {
- ANTLR_MARKER m;
-
- m = lexer->get_istream()->mark();
- state->set_backtracking(1); /* No exceptions */
- state->set_failed(false);
-
- /* Call the generated lexer, see if it can get a new token together.
- */
- lexer->mTokens();
- state->set_backtracking(0);
-
- /* mTokens backtracks with synpred at BACKTRACKING==2
- and we set the synpredgate to allow actions at level 1. */
-
- if(state->get_failed())
- {
- lexer->rewind(m);
- lexer->consume(); //<! advance one char and try again !>
- }
- else
- {
- lexer->emit(); /* Assemble the token and emit it to the stream */
- TokenType* tok = state->get_token();
- return tok;
- }
- }
- }
-}
-
-template<class ImplTraits>
-typename TokenSource<ImplTraits>::CommonTokenType* TokenSource<ImplTraits>::nextToken( BoolForwarder<false> /*isFiltered*/ )
-{
- // Find the next token in the current stream
- //
- CommonTokenType* tok = this->nextTokenStr();
-
- // If we got to the EOF token then switch to the previous
- // input stream if there were any and just return the
- // EOF if there are none. We must check the next token
- // in any outstanding input stream we pop into the active
- // role to see if it was sitting at EOF after PUSHing the
- // stream we just consumed, otherwise we will return EOF
- // on the reinstalled input stream, when in actual fact
- // there might be more input streams to POP before the
- // real EOF of the whole logical inptu stream. Hence we
- // use a while loop here until we find somethign in the stream
- // that isn't EOF or we reach the actual end of the last input
- // stream on the stack.
- //
- while(tok->get_type() == CommonTokenType::TOKEN_EOF)
- {
- typename ImplTraits::LexerType* lexer;
- lexer = static_cast<typename ImplTraits::LexerType*>( this->get_super() );
-
- if ( lexer->get_rec()->get_state()->get_streams().size() > 0)
- {
- // We have another input stream in the stack so we
- // need to revert to it, then resume the loop to check
- // it wasn't sitting at EOF itself.
- //
- lexer->popCharStream();
- tok = this->nextTokenStr();
- }
- else
- {
- // There were no more streams on the input stack
- // so this EOF is the 'real' logical EOF for
- // the input stream. So we just exit the loop and
- // return the EOF we have found.
- //
- break;
- }
-
- }
-
- // return whatever token we have, which may be EOF
- //
- return tok;
+ return this->nextToken( BoolForwarder<LexerType::IsFiltered>() );
+}
+
+template<class ImplTraits>
+typename TokenSource<ImplTraits>::CommonTokenType* TokenSource<ImplTraits>::nextToken( BoolForwarder<true> /*isFiltered*/ )
+{
+ LexerType* lexer;
+ typename LexerType::RecognizerSharedStateType* state;
+
+ lexer = this->get_super();
+ state = lexer->get_lexstate();
+
+ /* Get rid of any previous token (token factory takes care of
+ * any deallocation when this token is finally used up.
+ */
+ state->set_token_present( false );
+ state->set_error( false ); /* Start out without an exception */
+ state->set_failed(false);
+
+ /* Record the start of the token in our input stream.
+ */
+ state->set_tokenStartCharIndex( lexer->index() );
+ state->set_tokenStartCharPositionInLine( lexer->getCharPositionInLine() );
+ state->set_tokenStartLine( lexer->getLine() );
+ state->set_text("");
+
+ /* Now call the matching rules and see if we can generate a new token
+ */
+ for (;;)
+ {
+ if (lexer->LA(1) == ANTLR_CHARSTREAM_EOF)
+ {
+ /* Reached the end of the stream, nothing more to do.
+ */
+ CommonTokenType& teof = m_eofToken;
+
+ teof.set_startIndex(lexer->getCharIndex());
+ teof.set_stopIndex(lexer->getCharIndex());
+ teof.set_line(lexer->getLine());
+ return &teof;
+ }
+
+ state->set_token_present(false);
+ state->set_error(false); /* Start out without an exception */
+
+ {
+ ANTLR_MARKER m;
+
+ m = lexer->get_istream()->mark();
+ state->set_backtracking(1); /* No exceptions */
+ state->set_failed(false);
+
+ /* Call the generated lexer, see if it can get a new token together.
+ */
+ lexer->mTokens();
+ state->set_backtracking(0);
+
+ /* mTokens backtracks with synpred at BACKTRACKING==2
+ and we set the synpredgate to allow actions at level 1. */
+
+ if(state->get_failed())
+ {
+ lexer->rewind(m);
+ lexer->consume(); //<! advance one char and try again !>
+ }
+ else
+ {
+ lexer->emit(); /* Assemble the token and emit it to the stream */
+ TokenType* tok = state->get_token();
+ return tok;
+ }
+ }
+ }
+}
+
+template<class ImplTraits>
+typename TokenSource<ImplTraits>::CommonTokenType* TokenSource<ImplTraits>::nextToken( BoolForwarder<false> /*isFiltered*/ )
+{
+ // Find the next token in the current stream
+ //
+ CommonTokenType* tok = this->nextTokenStr();
+
+ // If we got to the EOF token then switch to the previous
+ // input stream if there were any and just return the
+ // EOF if there are none. We must check the next token
+ // in any outstanding input stream we pop into the active
+ // role to see if it was sitting at EOF after PUSHing the
+ // stream we just consumed, otherwise we will return EOF
+ // on the reinstalled input stream, when in actual fact
+ // there might be more input streams to POP before the
+ // real EOF of the whole logical inptu stream. Hence we
+ // use a while loop here until we find somethign in the stream
+ // that isn't EOF or we reach the actual end of the last input
+ // stream on the stack.
+ //
+ while(tok->get_type() == CommonTokenType::TOKEN_EOF)
+ {
+ typename ImplTraits::LexerType* lexer;
+ lexer = static_cast<typename ImplTraits::LexerType*>( this->get_super() );
+
+ if ( lexer->get_rec()->get_state()->get_streams().size() > 0)
+ {
+ // We have another input stream in the stack so we
+ // need to revert to it, then resume the loop to check
+ // it wasn't sitting at EOF itself.
+ //
+ lexer->popCharStream();
+ tok = this->nextTokenStr();
+ }
+ else
+ {
+ // There were no more streams on the input stack
+ // so this EOF is the 'real' logical EOF for
+ // the input stream. So we just exit the loop and
+ // return the EOF we have found.
+ //
+ break;
+ }
+
+ }
+
+ // return whatever token we have, which may be EOF
+ //
+ return tok;
}
template<class ImplTraits>
TokenStream<ImplTraits>::TokenStream()
{
- m_tokenSource = NULL;
- m_debugger = NULL;
- m_initialStreamState = false;
+ m_tokenSource = NULL;
+ m_debugger = NULL;
+ m_initialStreamState = false;
}
template<class ImplTraits>
typename TokenStream<ImplTraits>::IntStreamType* TokenStream<ImplTraits>::get_istream()
{
- return this;
+ return this;
}
template<class ImplTraits>
TokenStream<ImplTraits>::TokenStream(TokenSourceType* source, DebugEventListenerType* debugger)
{
- m_initialStreamState = false;
- m_tokenSource = source;
- m_debugger = debugger;
+ m_initialStreamState = false;
+ m_tokenSource = source;
+ m_debugger = debugger;
}
template<class ImplTraits>
-CommonTokenStream<ImplTraits>::CommonTokenStream(ANTLR_UINT32 , TokenSourceType* source,
- DebugEventListenerType* debugger)
- : CommonTokenStream<ImplTraits>::BaseType( source, debugger )
+CommonTokenStream<ImplTraits>::CommonTokenStream(ANTLR_UINT32 , TokenSourceType* source,
+ DebugEventListenerType* debugger)
+ : CommonTokenStream<ImplTraits>::BaseType( source, debugger )
{
- m_p = -1;
- m_channel = TOKEN_DEFAULT_CHANNEL;
- m_discardOffChannel = false;
- m_nissued = 0;
+ m_p = -1;
+ m_channel = TOKEN_DEFAULT_CHANNEL;
+ m_discardOffChannel = false;
+ m_nissued = 0;
}
template<class ImplTraits>
typename CommonTokenStream<ImplTraits>::TokensType& CommonTokenStream<ImplTraits>::get_tokens()
{
- return m_tokens;
+ return m_tokens;
}
template<class ImplTraits>
const typename CommonTokenStream<ImplTraits>::TokensType& CommonTokenStream<ImplTraits>::get_tokens() const
{
- return m_tokens;
+ return m_tokens;
}
template<class ImplTraits>
typename CommonTokenStream<ImplTraits>::DiscardSetType& CommonTokenStream<ImplTraits>::get_discardSet()
{
- return m_discardSet;
+ return m_discardSet;
}
template<class ImplTraits>
const typename CommonTokenStream<ImplTraits>::DiscardSetType& CommonTokenStream<ImplTraits>::get_discardSet() const
{
- return m_discardSet;
+ return m_discardSet;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_INT32 CommonTokenStream<ImplTraits>::get_p() const
{
- return m_p;
+ return m_p;
}
template<class ImplTraits>
ANTLR_INLINE void CommonTokenStream<ImplTraits>::set_p( ANTLR_INT32 p )
{
- m_p = p;
+ m_p = p;
}
template<class ImplTraits>
ANTLR_INLINE void CommonTokenStream<ImplTraits>::inc_p()
{
- ++m_p;
+ ++m_p;
}
template<class ImplTraits>
ANTLR_INLINE void CommonTokenStream<ImplTraits>::dec_p()
{
- --m_p;
+ --m_p;
}
template<class ImplTraits>
ANTLR_INLINE ANTLR_MARKER CommonTokenStream<ImplTraits>::index_impl()
{
- return m_p;
+ return m_p;
}
// Reset a token stream so it can be used again and can reuse it's
@@ -361,11 +361,11 @@ ANTLR_INLINE ANTLR_MARKER CommonTokenStream<ImplTraits>::index_impl()
template<class ImplTraits>
void CommonTokenStream<ImplTraits>::reset()
{
- // Free any resources that ar most like specifc to the
+ // Free any resources that ar most like specifc to the
// run we just did.
//
- m_discardSet.clear();
- m_channelOverrides.clear();
+ m_discardSet.clear();
+ m_channelOverrides.clear();
// Now, if there were any existing tokens in the stream,
// then we just reset the vector count so that it starts
@@ -374,90 +374,90 @@ void CommonTokenStream<ImplTraits>::reset()
// so on. However that is just a quick NULL check on the
// vector entries.
//
- m_tokens.clear();
+ m_tokens.clear();
// Reset to defaults
//
m_discardOffChannel = false;
m_channel = ImplTraits::CommonTokenType::TOKEN_DEFAULT_CHANNEL;
- m_p = -1;
+ m_p = -1;
}
template<class ImplTraits>
-void TokenStream<ImplTraits>::setDebugListener(DebugEventListenerType* debugger)
+void TokenStream<ImplTraits>::setDebugListener(DebugEventListenerType* debugger)
{
- m_debugger = debugger;
- m_initialStreamState = false;
+ m_debugger = debugger;
+ m_initialStreamState = false;
}
template<class ImplTraits>
-const typename TokenStream<ImplTraits>::TokenType* TokenStream<ImplTraits>::LT(ANTLR_INT32 k)
+const typename TokenStream<ImplTraits>::TokenType* TokenStream<ImplTraits>::LT(ANTLR_INT32 k)
{
- ANTLR_INT32 i;
- ANTLR_INT32 n;
- TokenStreamType* cts;
+ ANTLR_INT32 i;
+ ANTLR_INT32 n;
+ TokenStreamType* cts;
- cts = this->get_super();
+ cts = this->get_super();
if(k < 0)
- {
- return cts->LB(-k);
- }
+ {
+ return cts->LB(-k);
+ }
- ANTLR_INT32 req_idx = cts->get_p() + k - 1;
- ANTLR_INT32 cached_size = static_cast<ANTLR_INT32>(this->get_istream()->get_cachedSize());
+ ANTLR_INT32 req_idx = cts->get_p() + k - 1;
+ ANTLR_INT32 cached_size = static_cast<ANTLR_INT32>(this->get_istream()->get_cachedSize());
- if( (cts->get_p() == -1) ||
- ( ( req_idx >= cached_size ) && ( (cached_size % ImplTraits::TOKEN_FILL_BUFFER_INCREMENT) == 0 ) )
- )
- {
- cts->fillBuffer();
- }
+ if( (cts->get_p() == -1) ||
+ ( ( req_idx >= cached_size ) && ( (cached_size % ImplTraits::TOKEN_FILL_BUFFER_INCREMENT) == 0 ) )
+ )
+ {
+ cts->fillBuffer();
+ }
// Here we used to check for k == 0 and return 0, but this seems
// a superfluous check to me. LT(k=0) is therefore just undefined
// and we won't waste the clock cycles on the check
//
- cached_size = static_cast<ANTLR_INT32>(this->get_istream()->get_cachedSize());
- if ( req_idx >= cached_size )
- {
- TokenType& teof = cts->get_tokenSource()->get_eofToken();
-
- teof.set_startIndex( this->get_istream()->index());
- teof.set_stopIndex( this->get_istream()->index());
- return &teof;
- }
-
- i = cts->get_p();
- n = 1;
-
- /* Need to find k good tokens, skipping ones that are off channel
- */
- while( n < k)
- {
- /* Skip off-channel tokens */
- i = cts->skipOffTokenChannels(i+1); /* leave p on valid token */
- n++;
- }
-
- if( ( i >= cached_size ) && ( (cached_size % ImplTraits::TOKEN_FILL_BUFFER_INCREMENT) == 0 ) )
- {
- cts->fillBuffer();
- }
- if ( (ANTLR_UINT32) i >= this->get_istream()->get_cachedSize() )
- {
- TokenType& teof = cts->get_tokenSource()->get_eofToken();
-
- teof.set_startIndex(this->get_istream()->index());
- teof.set_stopIndex(this->get_istream()->index());
- return &teof;
- }
-
- // Here the token must be in the input vector. Rather then incur
- // function call penalty, we just return the pointer directly
- // from the vector
- //
- return cts->getToken(i);
+ cached_size = static_cast<ANTLR_INT32>(this->get_istream()->get_cachedSize());
+ if ( req_idx >= cached_size )
+ {
+ TokenType& teof = cts->get_tokenSource()->get_eofToken();
+
+ teof.set_startIndex( this->get_istream()->index());
+ teof.set_stopIndex( this->get_istream()->index());
+ return &teof;
+ }
+
+ i = cts->get_p();
+ n = 1;
+
+ /* Need to find k good tokens, skipping ones that are off channel
+ */
+ while( n < k)
+ {
+ /* Skip off-channel tokens */
+ i = cts->skipOffTokenChannels(i+1); /* leave p on valid token */
+ n++;
+ }
+
+ if( ( i >= cached_size ) && ( (cached_size % ImplTraits::TOKEN_FILL_BUFFER_INCREMENT) == 0 ) )
+ {
+ cts->fillBuffer();
+ }
+ if ( (ANTLR_UINT32) i >= this->get_istream()->get_cachedSize() )
+ {
+ TokenType& teof = cts->get_tokenSource()->get_eofToken();
+
+ teof.set_startIndex(this->get_istream()->index());
+ teof.set_stopIndex(this->get_istream()->index());
+ return &teof;
+ }
+
+ // Here the token must be in the input vector. Rather then incur
+ // function call penalty, we just return the pointer directly
+ // from the vector
+ //
+ return cts->getToken(i);
}
template<class ImplTraits>
@@ -496,69 +496,69 @@ const typename CommonTokenStream<ImplTraits>::TokenType* CommonTokenStream<ImplT
{
return NULL;
}
-
- // Here the token must be in the input vector. Rather then incut
- // function call penalty, we jsut return the pointer directly
- // from the vector
- //
- return this->getToken(i);
+
+ // Here the token must be in the input vector. Rather then incut
+ // function call penalty, we jsut return the pointer directly
+ // from the vector
+ //
+ return this->getToken(i);
}
template<class ImplTraits>
const typename CommonTokenStream<ImplTraits>::TokenType* CommonTokenStream<ImplTraits>::getToken(ANTLR_MARKER i)
{
- return this->get(i);
+ return this->get(i);
}
template<class ImplTraits>
const typename CommonTokenStream<ImplTraits>::TokenType* CommonTokenStream<ImplTraits>::get(ANTLR_MARKER i)
{
- return this->getToken( static_cast<ANTLR_MARKER>(i),
- BoolForwarder<ImplTraits::TOKENS_ACCESSED_FROM_OWNING_RULE>() );
+ return this->getToken( static_cast<ANTLR_MARKER>(i),
+ BoolForwarder<ImplTraits::TOKENS_ACCESSED_FROM_OWNING_RULE>() );
}
template<class ImplTraits>
const typename CommonTokenStream<ImplTraits>::TokenType* CommonTokenStream<ImplTraits>::getToken( ANTLR_MARKER tok_idx,
- BoolForwarder<true> /*tokens_accessed_from_owning_rule*/ )
+ BoolForwarder<true> /*tokens_accessed_from_owning_rule*/ )
{
- typename TokensType::iterator iter = m_tokens.find(tok_idx);
- if( iter == m_tokens.end() )
- {
- TokenAccessException ex;
- throw ex;
- }
- const TokenType& tok = iter->second;
- return &tok;
+ typename TokensType::iterator iter = m_tokens.find(tok_idx);
+ if( iter == m_tokens.end() )
+ {
+ TokenAccessException ex;
+ throw ex;
+ }
+ const TokenType& tok = iter->second;
+ return &tok;
}
template<class ImplTraits>
const typename CommonTokenStream<ImplTraits>::TokenType* CommonTokenStream<ImplTraits>::getToken( ANTLR_MARKER tok_idx, BoolForwarder<false> /*tokens_accessed_from_owning_rule*/ )
{
- TokenType& tok = m_tokens.at( static_cast<ANTLR_UINT32>(tok_idx) );
- return &tok;
+ TokenType& tok = m_tokens.at( static_cast<ANTLR_UINT32>(tok_idx) );
+ return &tok;
}
template<class ImplTraits>
typename TokenStream<ImplTraits>::TokenSourceType* TokenStream<ImplTraits>::get_tokenSource() const
{
- return m_tokenSource;
+ return m_tokenSource;
}
template<class ImplTraits>
void TokenStream<ImplTraits>::set_tokenSource( TokenSourceType* tokenSource )
{
- m_tokenSource = tokenSource;
+ m_tokenSource = tokenSource;
}
template<class ImplTraits>
-typename TokenStream<ImplTraits>::StringType TokenStream<ImplTraits>::toString()
+typename TokenStream<ImplTraits>::StringType TokenStream<ImplTraits>::toString()
{
- TokenStreamType* cts = static_cast<TokenStreamType>(this);
+ TokenStreamType* cts = static_cast<TokenStreamType>(this);
- if (cts->get_p() == -1)
+ if (cts->get_p() == -1)
{
- cts->fillBuffer();
+ cts->fillBuffer();
}
return this->toStringSS(0, this->get_istream()->size());
@@ -610,15 +610,15 @@ template<class ImplTraits>
typename TokenStream<ImplTraits>::StringType
TokenStream<ImplTraits>::toStringTT(const TokenType* start, const TokenType* stop)
{
- if (start != NULL && stop != NULL)
- {
- return this->toStringSS( start->get_tokenIndex(),
- stop->get_tokenIndex());
- }
- else
- {
- return "";
- }
+ if (start != NULL && stop != NULL)
+ {
+ return this->toStringSS( start->get_tokenIndex(),
+ stop->get_tokenIndex());
+ }
+ else
+ {
+ return "";
+ }
}
/** A simple filter mechanism whereby you can tell this token stream
@@ -628,7 +628,7 @@ TokenStream<ImplTraits>::toStringTT(const TokenType* start, const TokenType* sto
* channel.
*/
template<class ImplTraits>
-void CommonTokenStream<ImplTraits>::setTokenTypeChannel ( ANTLR_UINT32 ttype, ANTLR_UINT32 channel)
+void CommonTokenStream<ImplTraits>::setTokenTypeChannel ( ANTLR_UINT32 ttype, ANTLR_UINT32 channel)
{
/* We add one to the channel so we can distinguish NULL as being no entry in the
* table for a particular token type.
@@ -640,34 +640,34 @@ void CommonTokenStream<ImplTraits>::setTokenTypeChannel ( ANTLR_UINT32 ttype, AN
template<class ImplTraits>
void CommonTokenStream<ImplTraits>::discardTokenType(ANTLR_INT32 ttype)
{
- /* We add one to the channel so we can distinguish NULL as being no entry in the
+ /* We add one to the channel so we can distinguish NULL as being no entry in the
* table for a particular token type. We could use bitsets for this I suppose too.
*/
- m_discardSet.insert(ttype);
+ m_discardSet.insert(ttype);
}
template<class ImplTraits>
void CommonTokenStream<ImplTraits>::discardOffChannelToks(bool discard)
{
- m_discardOffChannel = discard;
+ m_discardOffChannel = discard;
}
template<class ImplTraits>
typename CommonTokenStream<ImplTraits>::TokensType* CommonTokenStream<ImplTraits>::getTokens()
{
- if (m_p == -1)
+ if (m_p == -1)
{
- this->fillBuffer();
+ this->fillBuffer();
}
return &m_tokens;
}
template<class ImplTraits>
-void CommonTokenStream<ImplTraits>::getTokenRange(ANTLR_UINT32 start, ANTLR_UINT32 stop,
- TokensListType& tokenRange)
+void CommonTokenStream<ImplTraits>::getTokenRange(ANTLR_UINT32 start, ANTLR_UINT32 stop,
+ TokensListType& tokenRange)
{
- return this->getTokensSet(start, stop, NULL, tokenRange);
+ return this->getTokensSet(start, stop, NULL, tokenRange);
}
/** Given a start and stop index, return a List of all tokens in
@@ -679,21 +679,21 @@ void
CommonTokenStream<ImplTraits>::getTokensSet(ANTLR_UINT32 start, ANTLR_UINT32 stop, BitsetType* types,
TokensListType& filteredList )
{
- ANTLR_UINT32 i;
- ANTLR_UINT32 n;
- TokenType* tok;
+ ANTLR_UINT32 i;
+ ANTLR_UINT32 n;
+ TokenType* tok;
- if ( m_p == -1)
+ if ( m_p == -1)
{
- this->fillBuffer();
+ this->fillBuffer();
}
- if (stop > this->get_istream()->size())
+ if (stop > this->get_istream()->size())
{
- stop = this->get_istream()->size();
+ stop = this->get_istream()->size();
}
- if (start > stop)
+ if (start > stop)
{
- return;
+ return;
}
/* We have the range set, now we need to iterate through the
@@ -702,25 +702,25 @@ CommonTokenStream<ImplTraits>::getTokensSet(ANTLR_UINT32 start, ANTLR_UINT32 sto
*/
for(i = start, n = 0; i<= stop; i++)
{
- tok = this->get(i);
-
- if ( types == NULL
- || (types->isMember( tok->get_type() ) == true )
- )
- {
- filteredList.push_back(tok);
- }
- }
-
+ tok = this->get(i);
+
+ if ( types == NULL
+ || (types->isMember( tok->get_type() ) == true )
+ )
+ {
+ filteredList.push_back(tok);
+ }
+ }
+
return ;
}
template<class ImplTraits>
void
-CommonTokenStream<ImplTraits>::getTokensList(ANTLR_UINT32 start, ANTLR_UINT32 stop,
- const IntListType& list, TokensListType& newlist)
+CommonTokenStream<ImplTraits>::getTokensList(ANTLR_UINT32 start, ANTLR_UINT32 stop,
+ const IntListType& list, TokensListType& newlist)
{
- BitsetType* bitSet;
+ BitsetType* bitSet;
bitSet = Bitset<ImplTraits>::BitsetFromList(list);
this->getTokensSet(start, stop, bitSet, newlist);
@@ -728,7 +728,7 @@ CommonTokenStream<ImplTraits>::getTokensList(ANTLR_UINT32 start, ANTLR_UINT32 st
}
template<class ImplTraits>
-void
+void
CommonTokenStream<ImplTraits>::getTokensType(ANTLR_UINT32 start, ANTLR_UINT32 stop, ANTLR_UINT32 type,
TokensListType& newlist )
{
@@ -747,32 +747,32 @@ void CommonTokenStream<ImplTraits>::fillBufferExt()
}
template<class ImplTraits>
-bool CommonTokenStream<ImplTraits>::hasReachedFillbufferTarget( ANTLR_UINT32 cnt,
- BoolForwarder<true> )
+bool CommonTokenStream<ImplTraits>::hasReachedFillbufferTarget( ANTLR_UINT32 cnt,
+ BoolForwarder<true> )
{
- return ( cnt >= ImplTraits::TOKEN_FILL_BUFFER_INCREMENT );
+ return ( cnt >= ImplTraits::TOKEN_FILL_BUFFER_INCREMENT );
}
template<class ImplTraits>
-bool CommonTokenStream<ImplTraits>::hasReachedFillbufferTarget( ANTLR_UINT32,
- BoolForwarder<false> )
+bool CommonTokenStream<ImplTraits>::hasReachedFillbufferTarget( ANTLR_UINT32,
+ BoolForwarder<false> )
{
- return false;
+ return false;
}
template<class ImplTraits>
-void CommonTokenStream<ImplTraits>::fillBuffer()
+void CommonTokenStream<ImplTraits>::fillBuffer()
{
ANTLR_UINT32 index;
TokenType* tok;
bool discard;
-
+
/* Start at index 0 of course
*/
- ANTLR_UINT32 cached_p = (m_p < 0) ? 0 : m_p;
+ ANTLR_UINT32 cached_p = (m_p < 0) ? 0 : m_p;
index = m_nissued;
- ANTLR_UINT32 cnt = 0;
+ ANTLR_UINT32 cnt = 0;
/* Pick out the next token from the token source
* Remember we just get a pointer (reference if you like) here
@@ -782,7 +782,7 @@ void CommonTokenStream<ImplTraits>::fillBuffer()
while ( tok->get_type() != TokenType::TOKEN_EOF )
{
- discard = false; /* Assume we are not discarding */
+ discard = false; /* Assume we are not discarding */
/* I employ a bit of a trick, or perhaps hack here. Rather than
* store a pointer to a structure in the override map and discard set
@@ -804,7 +804,7 @@ void CommonTokenStream<ImplTraits>::fillBuffer()
{
/* See if this type is in the override map
*/
- typename ChannelOverridesType::iterator iter = m_channelOverrides.find( tok->get_type() + 1 );
+ typename ChannelOverridesType::iterator iter = m_channelOverrides.find( tok->get_type() + 1 );
if (iter != m_channelOverrides.end())
{
@@ -824,15 +824,15 @@ void CommonTokenStream<ImplTraits>::fillBuffer()
++m_p;
this->insertToken(*tok);
index++;
- m_nissued++;
- cnt++;
+ m_nissued++;
+ cnt++;
}
- if( !this->hasReachedFillbufferTarget( cnt,
- BoolForwarder<ImplTraits::TOKENS_ACCESSED_FROM_OWNING_RULE>() ) )
- tok = this->get_tokenSource()->nextToken();
- else
- break;
+ if( !this->hasReachedFillbufferTarget( cnt,
+ BoolForwarder<ImplTraits::TOKENS_ACCESSED_FROM_OWNING_RULE>() ) )
+ tok = this->get_tokenSource()->nextToken();
+ else
+ break;
}
/* Cache the size so we don't keep doing indirect method calls. We do this as
@@ -877,7 +877,7 @@ ANTLR_UINT32 CommonTokenStream<ImplTraits>::skipOffTokenChannelsReverse(ANTLR_I
while (x >= 0)
{
const TokenType* tok = this->getToken(x);
-
+
if( tok->get_channel() != m_channel )
{
x--;
@@ -893,49 +893,49 @@ ANTLR_UINT32 CommonTokenStream<ImplTraits>::skipOffTokenChannelsReverse(ANTLR_I
template<class ImplTraits>
void CommonTokenStream<ImplTraits>::discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop )
{
- this->discardTokens( start, stop, BoolForwarder< ImplTraits::TOKENS_ACCESSED_FROM_OWNING_RULE >() );
+ this->discardTokens( start, stop, BoolForwarder< ImplTraits::TOKENS_ACCESSED_FROM_OWNING_RULE >() );
}
template<class ImplTraits>
-void CommonTokenStream<ImplTraits>::discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop,
- BoolForwarder<true> /*tokens_accessed_from_owning_rule */ )
+void CommonTokenStream<ImplTraits>::discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop,
+ BoolForwarder<true> /*tokens_accessed_from_owning_rule */ )
{
- typename TokensType::iterator iter1 = m_tokens.lower_bound(start);
- typename TokensType::iterator iter2 = m_tokens.upper_bound(stop);
- m_tokens.erase( iter1, iter2 );
+ typename TokensType::iterator iter1 = m_tokens.lower_bound(start);
+ typename TokensType::iterator iter2 = m_tokens.upper_bound(stop);
+ m_tokens.erase( iter1, iter2 );
}
template<class ImplTraits>
-void CommonTokenStream<ImplTraits>::discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop,
- BoolForwarder<false> /*tokens_accessed_from_owning_rule*/ )
+void CommonTokenStream<ImplTraits>::discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop,
+ BoolForwarder<false> /*tokens_accessed_from_owning_rule*/ )
{
- m_tokens.erase( m_tokens.begin() + start, m_tokens.begin() + stop );
+ m_tokens.erase( m_tokens.begin() + start, m_tokens.begin() + stop );
}
template<class ImplTraits>
void CommonTokenStream<ImplTraits>::insertToken( const TokenType& tok )
{
- this->insertToken( tok, BoolForwarder< ImplTraits::TOKENS_ACCESSED_FROM_OWNING_RULE >() );
+ this->insertToken( tok, BoolForwarder< ImplTraits::TOKENS_ACCESSED_FROM_OWNING_RULE >() );
}
template<class ImplTraits>
void CommonTokenStream<ImplTraits>::insertToken( const TokenType& tok, BoolForwarder<true> /*tokens_accessed_from_owning_rule*/ )
{
- assert( m_tokens.find( tok.get_index() ) == m_tokens.end() );
- assert( tok.get_index() == m_nissued );
- m_tokens[ tok.get_index() ] = tok;
+ assert( m_tokens.find( tok.get_index() ) == m_tokens.end() );
+ assert( tok.get_index() == m_nissued );
+ m_tokens[ tok.get_index() ] = tok;
}
template<class ImplTraits>
void CommonTokenStream<ImplTraits>::insertToken( const TokenType& tok, BoolForwarder<false> /*tokens_accessed_from_owning_rule*/ )
{
- m_tokens.push_back( tok );
+ m_tokens.push_back( tok );
}
template<class ImplTraits>
CommonTokenStream<ImplTraits>::~CommonTokenStream()
{
- m_tokens.clear();
+ m_tokens.clear();
}
-}
+}
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3traits.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3traits.hpp
index e390f0277b..c5741ce985 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3traits.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3traits.hpp
@@ -1,377 +1,377 @@
#ifndef _ANTLR3_TRAITS_HPP
#define _ANTLR3_TRAITS_HPP
-namespace antlr3 {
+namespace antlr3 {
-/**
- * Users implementing overrides should inherit from this
- *
- * All classes typenames reffer to Empty class
- */
+/**
+ * Users implementing overrides should inherit from this
+ *
+ * All classes typenames reffer to Empty class
+ */
template<class ImplTraits>
class CustomTraitsBase
{
public:
- typedef Empty AllocPolicyType;
- typedef Empty StringType;
- typedef Empty StringStreamType;
- typedef Empty StreamDataType;
- typedef Empty Endianness;
-
- //collections
- typedef Empty BitsetType;
- typedef Empty BitsetListType;
-
- typedef Empty InputStreamType;
-
- template<class StreamType>
- class IntStreamType : public Empty
- {
- public:
- typedef Empty BaseType;
- };
-
- typedef Empty LexStateType;
-
- typedef Empty CommonTokenType;
- typedef Empty TokenUserDataType;
-
- typedef Empty TokenIntStreamType;
- typedef Empty TokenStreamType;
-
- typedef Empty TreeNodeIntStreamType;
- typedef Empty TreeNodeStreamType;
-
-
- typedef Empty DebugEventListenerType;
- template<class StreamType>
- class RecognizerSharedStateType : public Empty
- {
- public:
- typedef Empty BaseType;
- };
-
- template<class StreamType>
- class RecognizerType : public Empty
- {
- public:
- typedef Empty BaseType;
- };
-
- typedef Empty TreeType;
- typedef Empty TreeUserDataType;
- typedef Empty TreeAdaptorType;
- typedef Empty TreeStoreType;
-
- template<class StreamType>
- class ExceptionBaseType : public Empty
- {
- public:
- typedef Empty BaseType;
- };
-
- //this should be overridden with generated lexer
- typedef Empty BaseLexerType;
-
- typedef Empty TokenSourceType;
- typedef Empty BaseParserType;//this should be overridden with generated lexer
- typedef Empty BaseTreeParserType;
-
- template<class ElementType>
- class RewriteStreamType : public Empty
- {
- public:
- typedef Empty BaseType;
- };
-
- typedef Empty RuleReturnValueType;
-
- //If we want to change the way tokens are stored
- static const bool TOKENS_ACCESSED_FROM_OWNING_RULE = false;
- static const unsigned TOKEN_FILL_BUFFER_INCREMENT = 100; //used only if the above val is true
-
- static void displayRecognitionError( const std::string& str ) { printf("%s", str.c_str() ); }
+ typedef Empty AllocPolicyType;
+ typedef Empty StringType;
+ typedef Empty StringStreamType;
+ typedef Empty StreamDataType;
+ typedef Empty Endianness;
+
+ //collections
+ typedef Empty BitsetType;
+ typedef Empty BitsetListType;
+
+ typedef Empty InputStreamType;
+
+ template<class StreamType>
+ class IntStreamType : public Empty
+ {
+ public:
+ typedef Empty BaseType;
+ };
+
+ typedef Empty LexStateType;
+
+ typedef Empty CommonTokenType;
+ typedef Empty TokenUserDataType;
+
+ typedef Empty TokenIntStreamType;
+ typedef Empty TokenStreamType;
+
+ typedef Empty TreeNodeIntStreamType;
+ typedef Empty TreeNodeStreamType;
+
+
+ typedef Empty DebugEventListenerType;
+ template<class StreamType>
+ class RecognizerSharedStateType : public Empty
+ {
+ public:
+ typedef Empty BaseType;
+ };
+
+ template<class StreamType>
+ class RecognizerType : public Empty
+ {
+ public:
+ typedef Empty BaseType;
+ };
+
+ typedef Empty TreeType;
+ typedef Empty TreeUserDataType;
+ typedef Empty TreeAdaptorType;
+ typedef Empty TreeStoreType;
+
+ template<class StreamType>
+ class ExceptionBaseType : public Empty
+ {
+ public:
+ typedef Empty BaseType;
+ };
+
+ //this should be overridden with generated lexer
+ typedef Empty BaseLexerType;
+
+ typedef Empty TokenSourceType;
+ typedef Empty BaseParserType;//this should be overridden with generated lexer
+ typedef Empty BaseTreeParserType;
+
+ template<class ElementType>
+ class RewriteStreamType : public Empty
+ {
+ public:
+ typedef Empty BaseType;
+ };
+
+ typedef Empty RuleReturnValueType;
+
+ //If we want to change the way tokens are stored
+ static const bool TOKENS_ACCESSED_FROM_OWNING_RULE = false;
+ static const unsigned TOKEN_FILL_BUFFER_INCREMENT = 100; //used only if the above val is true
+
+ static void displayRecognitionError( const std::string& str ) { printf("%s", str.c_str() ); }
};
-/**
- * Traits manipulation classes
- */
+/**
+ * Traits manipulation classes
+ */
template<class A, class B>
class TraitsSelector
{
public:
- typedef A selected;
+ typedef A selected;
};
template<class B>
class TraitsSelector<Empty, B>
{
public:
- typedef B selected;
+ typedef B selected;
};
template<class A, class B, class C>
class TraitsOneArgSelector
{
public:
- typedef A selected;
+ typedef A selected;
};
template<class A, class B>
class TraitsOneArgSelector<A,B,Empty>
{
public:
- typedef B selected;
+ typedef B selected;
};
template<bool v, class A, class B>
class BoolSelector
{
public:
- typedef A selected;
+ typedef A selected;
};
template<class A, class B>
class BoolSelector<false, A, B>
{
public:
- typedef B selected;
+ typedef B selected;
};
-/**
- * Base traits template
- *
- * This class contains default typenames for every trait
- */
+/**
+ * Base traits template
+ *
+ * This class contains default typenames for every trait
+ */
template< template<class ImplTraits> class UserTraits >
class TraitsBase
{
public:
- typedef TraitsBase TraitsType;
-
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::AllocPolicyType,
- DefaultAllocPolicy
- >::selected AllocPolicyType;
-
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::StringType,
- std::string
- >::selected StringType;
-
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::StringStreamType,
- std::stringstream
- >::selected StringStreamType;
-
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::StreamDataType,
- ANTLR_UINT8
- >::selected StreamDataType;
-
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::Endianness,
- RESOLVE_ENDIAN_AT_RUNTIME
- >::selected Endianness;
-
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::BitsetType,
- Bitset<TraitsType>
- >::selected BitsetType;
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::BitsetListType,
- BitsetList<TraitsType>
- >::selected BitsetListType;
-
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::InputStreamType,
- InputStream<TraitsType>
- >::selected InputStreamType;
-
- template<class SuperType>
- class IntStreamType : public TraitsOneArgSelector< typename UserTraits<TraitsType>::template IntStreamType<SuperType>,
- IntStream<TraitsType, SuperType>,
- typename UserTraits<TraitsType>::template IntStreamType<SuperType>::BaseType
- >::selected
- { };
-
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::LexStateType,
- LexState<TraitsType>
- >::selected LexStateType;
-
- static const bool TOKENS_ACCESSED_FROM_OWNING_RULE = UserTraits<TraitsType>::TOKENS_ACCESSED_FROM_OWNING_RULE;
- static const unsigned TOKEN_FILL_BUFFER_INCREMENT = UserTraits<TraitsType>::TOKEN_FILL_BUFFER_INCREMENT; //used only if the above val is true
-
- static void displayRecognitionError( const StringType& str ) { UserTraits<TraitsType>::displayRecognitionError(str); }
-};
-
-/**
- * Final traits
- *
- * They combine Traits and user provided traits(UserTraits)
- */
-template< class LxrType,
- class PsrType,
- template<class ImplTraits> class UserTraits = CustomTraitsBase
- //,
- //class TreePsrType = antlr3::Empty
- //template<class ImplTraits> class TreePsrType = TreeParser
- >
-class Traits : public TraitsBase<UserTraits>
-{
-public:
- typedef Traits TraitsType;
- typedef TraitsBase<UserTraits> BaseTraitsType;
-
- // CommonTokenType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::CommonTokenType,
- CommonToken<TraitsType> >::selected CommonTokenType;
-
- // TokenUserDataType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::TokenUserDataType,
- Empty >::selected TokenUserDataType;
-
- // TokenListType
- typedef typename BaseTraitsType::AllocPolicyType::template ListType<const CommonTokenType*> TokenListType;
-
- // TokenIntStreamType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::TokenIntStreamType,
- TokenIntStream<TraitsType> >::selected TokenIntStreamType;
- // TokenStreamType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::TokenStreamType,
- CommonTokenStream<TraitsType> >::selected TokenStreamType;
-
- // TreeNodeIntStreamType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::TreeNodeIntStreamType,
- TreeNodeIntStream<TraitsType> >::selected TreeNodeIntStreamType;
-
- // TreeNodeStreamType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::TreeNodeStreamType,
- CommonTreeNodeStream<TraitsType> >::selected TreeNodeStreamType;
-
- // DebugEventListenerType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::DebugEventListenerType,
- DebugEventListener<TraitsType> >::selected DebugEventListenerType;
-
- // RecognizerSharedStateType
- template<class StreamType>
- class RecognizerSharedStateType : public TraitsOneArgSelector< typename UserTraits<TraitsType>::template RecognizerSharedStateType<StreamType>,
- RecognizerSharedState<TraitsType, StreamType>,
- typename UserTraits<TraitsType>::template RecognizerSharedStateType<StreamType>::BaseType
- >::selected
- {};
-
- // RecognizerType
- template<class StreamType>
- class RecognizerType : public TraitsOneArgSelector< typename UserTraits<TraitsType>::template RecognizerType<StreamType>,
- BaseRecognizer<TraitsType, StreamType>,
- typename UserTraits<TraitsType>::template RecognizerType<StreamType>::BaseType
- >::selected
- {
- public:
- typedef typename TraitsOneArgSelector< typename UserTraits<TraitsType>::template RecognizerType<StreamType>,
- BaseRecognizer<TraitsType, StreamType>,
- typename UserTraits<TraitsType>::template RecognizerType<StreamType>::BaseType
- >::selected BaseType;
- typedef typename BaseType::RecognizerSharedStateType RecognizerSharedStateType;
-
- public:
- RecognizerType(ANTLR_UINT32 sizeHint, RecognizerSharedStateType* state)
- : BaseType( sizeHint, state )
- {
- }
- };
-
- // TreeType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::TreeType,
- CommonTree<TraitsType> >::selected TreeType;
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::TreeUserDataType,
- Empty >::selected TreeUserDataType;
- // TreeAdaptorType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::TreeAdaptorType,
- CommonTreeAdaptor<TraitsType> >::selected TreeAdaptorType;
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::TreeStoreType,
- CommonTreeStore<TraitsType> >::selected TreeStoreType;
- typedef typename TreeStoreType::TreeTypePtr TreeTypePtr;
- //typedef std::unique_ptr<TreeType, ResourcePoolManager<ImplTraits>> TreeTypePtr;
-
- // ExceptionBaseType
- template<class StreamType>
- class ExceptionBaseType : public TraitsOneArgSelector< typename UserTraits<TraitsType>::template ExceptionBaseType<StreamType>,
- ANTLR_ExceptionBase<TraitsType, StreamType>,
- typename UserTraits<TraitsType>::template ExceptionBaseType<StreamType>::BaseType
- >::selected
- {
- public:
- typedef typename TraitsOneArgSelector< typename UserTraits<TraitsType>::template ExceptionBaseType<StreamType>,
- ANTLR_ExceptionBase<TraitsType, StreamType>,
- typename UserTraits<TraitsType>::template ExceptionBaseType<StreamType>::BaseType
- >::selected BaseType;
-
- protected:
- ExceptionBaseType( const typename BaseTraitsType::StringType& message )
- :BaseType(message)
- {
- }
- };
-
- // this should be overridden with generated lexer
- // BaseLexerType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::BaseLexerType,
- Lexer<TraitsType> >::selected BaseLexerType;
- typedef LxrType LexerType;
-
- // TokenSourceType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::TokenSourceType,
- TokenSource<TraitsType> >::selected TokenSourceType;
-
- // this should be overridden with generated parser
- // BaseParserType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::BaseParserType,
- Parser<TraitsType> >::selected BaseParserType;
- typedef PsrType ParserType;
-
- // this should be overridden with generated treeparser (not implemented yet)
- // BaseTreeParserType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::BaseTreeParserType,
- TreeParser<TraitsType> >::selected BaseTreeParserType;
- //typedef TreePsrType<Traits> TreeParserType;
- typedef BaseTreeParserType TreeParserType;
-
- // RewriteStreamType
- template<class ElementType>
- class RewriteStreamType : public TraitsOneArgSelector< typename UserTraits<TraitsType>::template RewriteStreamType<ElementType>,
- RewriteRuleElementStream<TraitsType, ElementType>,
- typename UserTraits<TraitsType>::template RewriteStreamType<ElementType>::BaseType
- >::selected
- {
- public:
- typedef typename TraitsOneArgSelector< typename UserTraits<TraitsType>::template RewriteStreamType<ElementType>,
- RewriteRuleElementStream<TraitsType, ElementType>,
- typename UserTraits<TraitsType>::template RewriteStreamType<ElementType>::BaseType
- >::selected BaseType;
-
- //typedef typename SuperType::StreamType StreamType;
- //typedef typename BaseType::RecognizerType Recognizer_Type;
- //typedef typename BaseType::ElementType ElementType;
- typedef typename BaseType::ElementsType ElementsType;
-
- public:
- RewriteStreamType(TreeAdaptorType* adaptor = NULL, const char* description = NULL)
- :BaseType(adaptor, description)
- {
- }
- RewriteStreamType(TreeAdaptorType* adaptor, const char* description, ElementType* oneElement)
- :BaseType(adaptor, description, oneElement)
- {
- }
- RewriteStreamType(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements)
- :BaseType(adaptor, description, elements)
- {
- }
- };
-
- // RuleReturnValueType
- typedef typename TraitsSelector< typename UserTraits<TraitsType>::RuleReturnValueType,
- typename BoolSelector< TraitsType::TOKENS_ACCESSED_FROM_OWNING_RULE,
- RuleReturnValue_1<TraitsType>,
- RuleReturnValue<TraitsType>
- >::selected
- >::selected RuleReturnValueType;
+ typedef TraitsBase TraitsType;
+
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::AllocPolicyType,
+ DefaultAllocPolicy
+ >::selected AllocPolicyType;
+
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::StringType,
+ std::string
+ >::selected StringType;
+
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::StringStreamType,
+ std::stringstream
+ >::selected StringStreamType;
+
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::StreamDataType,
+ ANTLR_UINT8
+ >::selected StreamDataType;
+
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::Endianness,
+ RESOLVE_ENDIAN_AT_RUNTIME
+ >::selected Endianness;
+
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::BitsetType,
+ Bitset<TraitsType>
+ >::selected BitsetType;
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::BitsetListType,
+ BitsetList<TraitsType>
+ >::selected BitsetListType;
+
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::InputStreamType,
+ InputStream<TraitsType>
+ >::selected InputStreamType;
+
+ template<class SuperType>
+ class IntStreamType : public TraitsOneArgSelector< typename UserTraits<TraitsType>::template IntStreamType<SuperType>,
+ IntStream<TraitsType, SuperType>,
+ typename UserTraits<TraitsType>::template IntStreamType<SuperType>::BaseType
+ >::selected
+ { };
+
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::LexStateType,
+ LexState<TraitsType>
+ >::selected LexStateType;
+
+ static const bool TOKENS_ACCESSED_FROM_OWNING_RULE = UserTraits<TraitsType>::TOKENS_ACCESSED_FROM_OWNING_RULE;
+ static const unsigned TOKEN_FILL_BUFFER_INCREMENT = UserTraits<TraitsType>::TOKEN_FILL_BUFFER_INCREMENT; //used only if the above val is true
+
+ static void displayRecognitionError( const StringType& str ) { UserTraits<TraitsType>::displayRecognitionError(str); }
};
-}
+/**
+ * Final traits
+ *
+ * They combine Traits and user provided traits(UserTraits)
+ */
+template< class LxrType,
+ class PsrType,
+ template<class ImplTraits> class UserTraits = CustomTraitsBase
+ //,
+ //class TreePsrType = antlr3::Empty
+ //template<class ImplTraits> class TreePsrType = TreeParser
+ >
+class Traits : public TraitsBase<UserTraits>
+{
+public:
+ typedef Traits TraitsType;
+ typedef TraitsBase<UserTraits> BaseTraitsType;
+
+ // CommonTokenType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::CommonTokenType,
+ CommonToken<TraitsType> >::selected CommonTokenType;
+
+ // TokenUserDataType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::TokenUserDataType,
+ Empty >::selected TokenUserDataType;
+
+ // TokenListType
+ typedef typename BaseTraitsType::AllocPolicyType::template ListType<const CommonTokenType*> TokenListType;
+
+ // TokenIntStreamType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::TokenIntStreamType,
+ TokenIntStream<TraitsType> >::selected TokenIntStreamType;
+ // TokenStreamType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::TokenStreamType,
+ CommonTokenStream<TraitsType> >::selected TokenStreamType;
+
+ // TreeNodeIntStreamType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::TreeNodeIntStreamType,
+ TreeNodeIntStream<TraitsType> >::selected TreeNodeIntStreamType;
+
+ // TreeNodeStreamType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::TreeNodeStreamType,
+ CommonTreeNodeStream<TraitsType> >::selected TreeNodeStreamType;
+
+ // DebugEventListenerType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::DebugEventListenerType,
+ DebugEventListener<TraitsType> >::selected DebugEventListenerType;
+
+ // RecognizerSharedStateType
+ template<class StreamType>
+ class RecognizerSharedStateType : public TraitsOneArgSelector< typename UserTraits<TraitsType>::template RecognizerSharedStateType<StreamType>,
+ RecognizerSharedState<TraitsType, StreamType>,
+ typename UserTraits<TraitsType>::template RecognizerSharedStateType<StreamType>::BaseType
+ >::selected
+ {};
+
+ // RecognizerType
+ template<class StreamType>
+ class RecognizerType : public TraitsOneArgSelector< typename UserTraits<TraitsType>::template RecognizerType<StreamType>,
+ BaseRecognizer<TraitsType, StreamType>,
+ typename UserTraits<TraitsType>::template RecognizerType<StreamType>::BaseType
+ >::selected
+ {
+ public:
+ typedef typename TraitsOneArgSelector< typename UserTraits<TraitsType>::template RecognizerType<StreamType>,
+ BaseRecognizer<TraitsType, StreamType>,
+ typename UserTraits<TraitsType>::template RecognizerType<StreamType>::BaseType
+ >::selected BaseType;
+ typedef typename BaseType::RecognizerSharedStateType RecognizerSharedStateType;
+
+ public:
+ RecognizerType(ANTLR_UINT32 sizeHint, RecognizerSharedStateType* state)
+ : BaseType( sizeHint, state )
+ {
+ }
+ };
+
+ // TreeType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::TreeType,
+ CommonTree<TraitsType> >::selected TreeType;
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::TreeUserDataType,
+ Empty >::selected TreeUserDataType;
+ // TreeAdaptorType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::TreeAdaptorType,
+ CommonTreeAdaptor<TraitsType> >::selected TreeAdaptorType;
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::TreeStoreType,
+ CommonTreeStore<TraitsType> >::selected TreeStoreType;
+ typedef typename TreeStoreType::TreeTypePtr TreeTypePtr;
+ //typedef std::unique_ptr<TreeType, ResourcePoolManager<ImplTraits>> TreeTypePtr;
+
+ // ExceptionBaseType
+ template<class StreamType>
+ class ExceptionBaseType : public TraitsOneArgSelector< typename UserTraits<TraitsType>::template ExceptionBaseType<StreamType>,
+ ANTLR_ExceptionBase<TraitsType, StreamType>,
+ typename UserTraits<TraitsType>::template ExceptionBaseType<StreamType>::BaseType
+ >::selected
+ {
+ public:
+ typedef typename TraitsOneArgSelector< typename UserTraits<TraitsType>::template ExceptionBaseType<StreamType>,
+ ANTLR_ExceptionBase<TraitsType, StreamType>,
+ typename UserTraits<TraitsType>::template ExceptionBaseType<StreamType>::BaseType
+ >::selected BaseType;
+
+ protected:
+ ExceptionBaseType( const typename BaseTraitsType::StringType& message )
+ :BaseType(message)
+ {
+ }
+ };
+
+ // this should be overridden with generated lexer
+ // BaseLexerType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::BaseLexerType,
+ Lexer<TraitsType> >::selected BaseLexerType;
+ typedef LxrType LexerType;
+
+ // TokenSourceType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::TokenSourceType,
+ TokenSource<TraitsType> >::selected TokenSourceType;
+
+ // this should be overridden with generated parser
+ // BaseParserType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::BaseParserType,
+ Parser<TraitsType> >::selected BaseParserType;
+ typedef PsrType ParserType;
+
+ // this should be overridden with generated treeparser (not implemented yet)
+ // BaseTreeParserType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::BaseTreeParserType,
+ TreeParser<TraitsType> >::selected BaseTreeParserType;
+ //typedef TreePsrType<Traits> TreeParserType;
+ typedef BaseTreeParserType TreeParserType;
+
+ // RewriteStreamType
+ template<class ElementType>
+ class RewriteStreamType : public TraitsOneArgSelector< typename UserTraits<TraitsType>::template RewriteStreamType<ElementType>,
+ RewriteRuleElementStream<TraitsType, ElementType>,
+ typename UserTraits<TraitsType>::template RewriteStreamType<ElementType>::BaseType
+ >::selected
+ {
+ public:
+ typedef typename TraitsOneArgSelector< typename UserTraits<TraitsType>::template RewriteStreamType<ElementType>,
+ RewriteRuleElementStream<TraitsType, ElementType>,
+ typename UserTraits<TraitsType>::template RewriteStreamType<ElementType>::BaseType
+ >::selected BaseType;
+
+ //typedef typename SuperType::StreamType StreamType;
+ //typedef typename BaseType::RecognizerType Recognizer_Type;
+ //typedef typename BaseType::ElementType ElementType;
+ typedef typename BaseType::ElementsType ElementsType;
+
+ public:
+ RewriteStreamType(TreeAdaptorType* adaptor = NULL, const char* description = NULL)
+ :BaseType(adaptor, description)
+ {
+ }
+ RewriteStreamType(TreeAdaptorType* adaptor, const char* description, ElementType* oneElement)
+ :BaseType(adaptor, description, oneElement)
+ {
+ }
+ RewriteStreamType(TreeAdaptorType* adaptor, const char* description, const ElementsType& elements)
+ :BaseType(adaptor, description, elements)
+ {
+ }
+ };
+
+ // RuleReturnValueType
+ typedef typename TraitsSelector< typename UserTraits<TraitsType>::RuleReturnValueType,
+ typename BoolSelector< TraitsType::TOKENS_ACCESSED_FROM_OWNING_RULE,
+ RuleReturnValue_1<TraitsType>,
+ RuleReturnValue<TraitsType>
+ >::selected
+ >::selected RuleReturnValueType;
+};
+
+}
#endif //_ANTLR3_TRAITS_HPP
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3treeparser.hpp b/contrib/libs/antlr3_cpp_runtime/include/antlr3treeparser.hpp
index 5d8fd8f303..c1395382b5 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3treeparser.hpp
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3treeparser.hpp
@@ -1,5 +1,5 @@
-#ifndef ANTLR3TREEPARSER_HPP
-#define ANTLR3TREEPARSER_HPP
+#ifndef ANTLR3TREEPARSER_HPP
+#define ANTLR3TREEPARSER_HPP
// [The "BSD licence"]
// Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
@@ -34,66 +34,66 @@
* if necessary, and contains function can be supported If the hash key
* could be unique I would have invented the perfect compression algorithm ;-)
*/
-namespace antlr3 {
+namespace antlr3 {
template<class ImplTraits>
-class TreeParser : public ImplTraits::template RecognizerType< typename ImplTraits::TreeNodeStreamType >
+class TreeParser : public ImplTraits::template RecognizerType< typename ImplTraits::TreeNodeStreamType >
{
public:
- typedef typename ImplTraits::TreeNodeStreamType TreeNodeStreamType;
- typedef TreeNodeStreamType StreamType;
- typedef typename TreeNodeStreamType::IntStreamType IntStreamType;
- typedef typename ImplTraits::TreeType TreeType;
- typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
- typedef TreeType TokenType;
- typedef typename ImplTraits::template ExceptionBaseType<TreeNodeStreamType> ExceptionBaseType;
- typedef typename ImplTraits::template RecognizerType< typename ImplTraits::TreeNodeStreamType > RecognizerType;
- typedef typename RecognizerType::RecognizerSharedStateType RecognizerSharedStateType;
- typedef Empty TokenSourceType;
- typedef typename ImplTraits::BitsetListType BitsetListType;
- typedef typename ImplTraits::StringType StringType;
- typedef typename ImplTraits::CommonTokenType CommonTokenType;
+ typedef typename ImplTraits::TreeNodeStreamType TreeNodeStreamType;
+ typedef TreeNodeStreamType StreamType;
+ typedef typename TreeNodeStreamType::IntStreamType IntStreamType;
+ typedef typename ImplTraits::TreeType TreeType;
+ typedef typename ImplTraits::TreeTypePtr TreeTypePtr;
+ typedef TreeType TokenType;
+ typedef typename ImplTraits::template ExceptionBaseType<TreeNodeStreamType> ExceptionBaseType;
+ typedef typename ImplTraits::template RecognizerType< typename ImplTraits::TreeNodeStreamType > RecognizerType;
+ typedef typename RecognizerType::RecognizerSharedStateType RecognizerSharedStateType;
+ typedef Empty TokenSourceType;
+ typedef typename ImplTraits::BitsetListType BitsetListType;
+ typedef typename ImplTraits::StringType StringType;
+ typedef typename ImplTraits::CommonTokenType CommonTokenType;
private:
/** Pointer to the common tree node stream for the parser
*/
- TreeNodeStreamType* m_ctnstream;
+ TreeNodeStreamType* m_ctnstream;
public:
- TreeParser( ANTLR_UINT32 sizeHint, TreeNodeStreamType* ctnstream,
- RecognizerSharedStateType* state);
- TreeNodeStreamType* get_ctnstream() const;
- IntStreamType* get_istream() const;
- RecognizerType* get_rec();
+ TreeParser( ANTLR_UINT32 sizeHint, TreeNodeStreamType* ctnstream,
+ RecognizerSharedStateType* state);
+ TreeNodeStreamType* get_ctnstream() const;
+ IntStreamType* get_istream() const;
+ RecognizerType* get_rec();
- //same as above. Just that get_istream exists for lexer, parser, treeparser
- //get_parser_istream exists only for parser, treeparser. So use it accordingly
- IntStreamType* get_parser_istream() const;
+ //same as above. Just that get_istream exists for lexer, parser, treeparser
+ //get_parser_istream exists only for parser, treeparser. So use it accordingly
+ IntStreamType* get_parser_istream() const;
/** Set the input stream and reset the parser
*/
- void setTreeNodeStream(TreeNodeStreamType* input);
+ void setTreeNodeStream(TreeNodeStreamType* input);
/** Return a pointer to the input stream
*/
TreeNodeStreamType* getTreeNodeStream();
- TokenType* getMissingSymbol( IntStreamType* istream,
- ExceptionBaseType* e,
- ANTLR_UINT32 expectedTokenType,
- BitsetListType* follow);
+ TokenType* getMissingSymbol( IntStreamType* istream,
+ ExceptionBaseType* e,
+ ANTLR_UINT32 expectedTokenType,
+ BitsetListType* follow);
/** Pointer to a function that knows how to free resources of an ANTLR3 tree parser.
*/
- ~TreeParser();
+ ~TreeParser();
- void fillExceptionData( ExceptionBaseType* ex );
- void displayRecognitionError( ANTLR_UINT8** tokenNames, ExceptionBaseType* ex );
- void exConstruct();
- void mismatch(ANTLR_UINT32 ttype, BitsetListType* follow);
+ void fillExceptionData( ExceptionBaseType* ex );
+ void displayRecognitionError( ANTLR_UINT8** tokenNames, ExceptionBaseType* ex );
+ void exConstruct();
+ void mismatch(ANTLR_UINT32 ttype, BitsetListType* follow);
};
-}
+}
#include "antlr3treeparser.inl"
diff --git a/contrib/libs/antlr3_cpp_runtime/include/antlr3treeparser.inl b/contrib/libs/antlr3_cpp_runtime/include/antlr3treeparser.inl
index a3399c5b81..5f5991f4eb 100644
--- a/contrib/libs/antlr3_cpp_runtime/include/antlr3treeparser.inl
+++ b/contrib/libs/antlr3_cpp_runtime/include/antlr3treeparser.inl
@@ -1,133 +1,133 @@
-namespace antlr3 {
+namespace antlr3 {
template< class ImplTraits >
TreeParser<ImplTraits>::TreeParser( ANTLR_UINT32 sizeHint, TreeNodeStreamType* ctnstream,
- RecognizerSharedStateType* state)
- :RecognizerType( sizeHint, state )
+ RecognizerSharedStateType* state)
+ :RecognizerType( sizeHint, state )
{
- /* Install the tree node stream
- */
- this->setTreeNodeStream(ctnstream);
+ /* Install the tree node stream
+ */
+ this->setTreeNodeStream(ctnstream);
}
template< class ImplTraits >
TreeParser<ImplTraits>::~TreeParser()
{
- this->get_rec()->get_state()->get_following().clear();
+ this->get_rec()->get_state()->get_following().clear();
}
template< class ImplTraits >
typename TreeParser<ImplTraits>::TreeNodeStreamType* TreeParser<ImplTraits>::get_ctnstream() const
{
- return m_ctnstream;
+ return m_ctnstream;
}
template< class ImplTraits >
typename TreeParser<ImplTraits>::IntStreamType* TreeParser<ImplTraits>::get_istream() const
{
- return m_ctnstream;
+ return m_ctnstream;
}
template< class ImplTraits >
typename TreeParser<ImplTraits>::IntStreamType* TreeParser<ImplTraits>::get_parser_istream() const
{
- return m_ctnstream;
+ return m_ctnstream;
}
template< class ImplTraits >
typename TreeParser<ImplTraits>::RecognizerType* TreeParser<ImplTraits>::get_rec()
{
- return this;
+ return this;
}
template< class ImplTraits >
void TreeParser<ImplTraits>::fillExceptionData( ExceptionBaseType* ex )
{
- auto xxx = m_ctnstream->LT(1);
- //ex->set_token( m_ctnstream->LT(1) ); /* Current input tree node */
- ex->set_line( ex->get_token()->get_line() );
- ex->set_charPositionInLine( ex->get_token()->get_charPositionInLine() );
- ex->set_index( m_ctnstream->index() );
-
- // Are you ready for this? Deep breath now...
- //
- {
- TreeTypePtr tnode;
-
- tnode = ex->get_token();
-
- if (tnode->get_token() == NULL)
- {
- ex->set_streamName("-unknown source-" );
- }
- else
- {
- if ( tnode->get_token()->get_input() == NULL)
- {
- ex->set_streamName("");
- }
- else
- {
- ex->set_streamName( tnode->get_token()->get_input()->get_fileName() );
- }
- }
- ex->set_message("Unexpected node");
- }
+ auto xxx = m_ctnstream->LT(1);
+ //ex->set_token( m_ctnstream->LT(1) ); /* Current input tree node */
+ ex->set_line( ex->get_token()->get_line() );
+ ex->set_charPositionInLine( ex->get_token()->get_charPositionInLine() );
+ ex->set_index( m_ctnstream->index() );
+
+ // Are you ready for this? Deep breath now...
+ //
+ {
+ TreeTypePtr tnode;
+
+ tnode = ex->get_token();
+
+ if (tnode->get_token() == NULL)
+ {
+ ex->set_streamName("-unknown source-" );
+ }
+ else
+ {
+ if ( tnode->get_token()->get_input() == NULL)
+ {
+ ex->set_streamName("");
+ }
+ else
+ {
+ ex->set_streamName( tnode->get_token()->get_input()->get_fileName() );
+ }
+ }
+ ex->set_message("Unexpected node");
+ }
}
template< class ImplTraits >
-void TreeParser<ImplTraits>::displayRecognitionError( ANTLR_UINT8** /*tokenNames*/, ExceptionBaseType* ex )
+void TreeParser<ImplTraits>::displayRecognitionError( ANTLR_UINT8** /*tokenNames*/, ExceptionBaseType* ex )
{
- typename ImplTraits::StringStreamType errtext;
- // See if there is a 'filename' we can use
- //
- if( ex->get_streamName().empty() )
- {
- if(ex->get_token()->get_type() == ImplTraits::CommonTokenType::TOKEN_EOF)
- {
- errtext << "-end of input-(";
- }
- else
- {
- errtext << "-unknown source-(";
- }
- }
- else
- {
- errtext << ex->get_streamName() << "(";
- }
-
- // Next comes the line number
- //
- errtext << this->get_rec()->get_state()->get_exception()->get_line() << ") ";
- errtext << " : error " << this->get_rec()->get_state()->get_exception()->getType()
- << " : "
- << this->get_rec()->get_state()->get_exception()->get_message();
-
- IntStreamType* is = this->get_istream();
- TreeTypePtr theBaseTree = this->get_rec()->get_state()->get_exception()->get_token();
- StringType ttext = theBaseTree->toStringTree();
-
- if (theBaseTree != NULL)
- {
- TreeTypePtr theCommonTree = static_cast<TreeTypePtr>(theBaseTree);
- if (theCommonTree != NULL)
- {
- CommonTokenType* theToken = theBaseTree->getToken();
- }
- errtext << ", at offset "
- << theBaseTree->getCharPositionInLine();
- errtext << ", near " << ttext;
- }
- ex->displayRecognitionError( errtext );
- ImplTraits::displayRecognitionError( errtext.str() );
+ typename ImplTraits::StringStreamType errtext;
+ // See if there is a 'filename' we can use
+ //
+ if( ex->get_streamName().empty() )
+ {
+ if(ex->get_token()->get_type() == ImplTraits::CommonTokenType::TOKEN_EOF)
+ {
+ errtext << "-end of input-(";
+ }
+ else
+ {
+ errtext << "-unknown source-(";
+ }
+ }
+ else
+ {
+ errtext << ex->get_streamName() << "(";
+ }
+
+ // Next comes the line number
+ //
+ errtext << this->get_rec()->get_state()->get_exception()->get_line() << ") ";
+ errtext << " : error " << this->get_rec()->get_state()->get_exception()->getType()
+ << " : "
+ << this->get_rec()->get_state()->get_exception()->get_message();
+
+ IntStreamType* is = this->get_istream();
+ TreeTypePtr theBaseTree = this->get_rec()->get_state()->get_exception()->get_token();
+ StringType ttext = theBaseTree->toStringTree();
+
+ if (theBaseTree != NULL)
+ {
+ TreeTypePtr theCommonTree = static_cast<TreeTypePtr>(theBaseTree);
+ if (theCommonTree != NULL)
+ {
+ CommonTokenType* theToken = theBaseTree->getToken();
+ }
+ errtext << ", at offset "
+ << theBaseTree->getCharPositionInLine();
+ errtext << ", near " << ttext;
+ }
+ ex->displayRecognitionError( errtext );
+ ImplTraits::displayRecognitionError( errtext.str() );
}
template< class ImplTraits >
-void TreeParser<ImplTraits>::setTreeNodeStream(TreeNodeStreamType* input)
+void TreeParser<ImplTraits>::setTreeNodeStream(TreeNodeStreamType* input)
{
- m_ctnstream = input;
+ m_ctnstream = input;
this->get_rec()->reset();
m_ctnstream->reset();
}
@@ -135,65 +135,65 @@ void TreeParser<ImplTraits>::setTreeNodeStream(TreeNodeStreamType* input)
template< class ImplTraits >
typename TreeParser<ImplTraits>::TreeNodeStreamType* TreeParser<ImplTraits>::getTreeNodeStream()
{
- return m_ctnstream;
+ return m_ctnstream;
}
template< class ImplTraits >
void TreeParser<ImplTraits>::exConstruct()
{
- new ANTLR_Exception<ImplTraits, MISMATCHED_TREE_NODE_EXCEPTION, TreeNodeStreamType>( this->get_rec(), "" );
+ new ANTLR_Exception<ImplTraits, MISMATCHED_TREE_NODE_EXCEPTION, TreeNodeStreamType>( this->get_rec(), "" );
}
template< class ImplTraits >
void TreeParser<ImplTraits>::mismatch(ANTLR_UINT32 ttype, BitsetListType* follow)
{
- this->exConstruct();
+ this->exConstruct();
this->recoverFromMismatchedToken(ttype, follow);
}
template< class ImplTraits >
typename TreeParser<ImplTraits>::TokenType*
-TreeParser<ImplTraits>::getMissingSymbol( IntStreamType* istream, ExceptionBaseType* /*e*/,
- ANTLR_UINT32 expectedTokenType, BitsetListType* /*follow*/)
+TreeParser<ImplTraits>::getMissingSymbol( IntStreamType* istream, ExceptionBaseType* /*e*/,
+ ANTLR_UINT32 expectedTokenType, BitsetListType* /*follow*/)
{
- TreeNodeStreamType* tns;
- TreeTypePtr node;
- TreeTypePtr current;
- CommonTokenType* token;
- StringType text;
+ TreeNodeStreamType* tns;
+ TreeTypePtr node;
+ TreeTypePtr current;
+ CommonTokenType* token;
+ StringType text;
ANTLR_INT32 i;
- // Dereference the standard pointers
- //
- tns = static_cast<TreeNodeStreamType*>(istream);
+ // Dereference the standard pointers
+ //
+ tns = static_cast<TreeNodeStreamType*>(istream);
- // Create a new empty node, by stealing the current one, or the previous one if the current one is EOF
- //
- current = tns->LT(1);
+ // Create a new empty node, by stealing the current one, or the previous one if the current one is EOF
+ //
+ current = tns->LT(1);
i = -1;
- if (current == tns->get_EOF_NODE_p())
- {
- current = tns->LT(-1);
+ if (current == tns->get_EOF_NODE_p())
+ {
+ current = tns->LT(-1);
i--;
- }
- node = current->dupNode();
-
- // Find the newly dupicated token
- //
- token = node->getToken();
-
- // Create the token text that shows it has been inserted
- //
- token->setText("<missing ");
- text = token->getText();
- text.append((const char *)this->get_rec()->get_state()->get_tokenName(expectedTokenType));
- text.append((const char *)">");
-
- // Finally return the pointer to our new node
- //
- return node;
+ }
+ node = current->dupNode();
+
+ // Find the newly dupicated token
+ //
+ token = node->getToken();
+
+ // Create the token text that shows it has been inserted
+ //
+ token->setText("<missing ");
+ text = token->getText();
+ text.append((const char *)this->get_rec()->get_state()->get_tokenName(expectedTokenType));
+ text.append((const char *)">");
+
+ // Finally return the pointer to our new node
+ //
+ return node;
}
-}
+}
diff --git a/library/cpp/scheme/scheme.h b/library/cpp/scheme/scheme.h
index dc82028a89..3d7c59f3c9 100644
--- a/library/cpp/scheme/scheme.h
+++ b/library/cpp/scheme/scheme.h
@@ -385,7 +385,7 @@ namespace NSc {
public:
// very specific methods useful in very specific corner cases
- static TValue From(const ::google::protobuf::Message&, bool mapAsDict = false);
+ static TValue From(const ::google::protobuf::Message&, bool mapAsDict = false);
void To(::google::protobuf::Message&, const TProtoOpts& opts = {}) const;
diff --git a/library/cpp/scheme/scimpl_protobuf.cpp b/library/cpp/scheme/scimpl_protobuf.cpp
index ff2e7e0d59..0c99122c69 100644
--- a/library/cpp/scheme/scimpl_protobuf.cpp
+++ b/library/cpp/scheme/scimpl_protobuf.cpp
@@ -10,7 +10,7 @@
using namespace google::protobuf;
namespace NSc {
- TValue TValue::From(const Message& msg, bool mapAsDict) {
+ TValue TValue::From(const Message& msg, bool mapAsDict) {
TValue v;
const Reflection* r = msg.GetReflection();
TVector<const FieldDescriptor*> fields;
@@ -22,18 +22,18 @@ namespace NSc {
const FieldDescriptor* field = *it;
try {
if (field->is_repeated()) {
- if (field->is_map() && mapAsDict) {
+ if (field->is_map() && mapAsDict) {
auto& elem = v[field->name()];
- for (int i2 = 0; i2 < r->FieldSize(msg, field); ++i2) {
- auto val = FromRepeatedField(msg, field, i2);
- if (val.IsDict()) {
- elem[TStringBuf(val["key"])] = val["value"];
- }
- }
- } else {
- for (int i2 = 0; i2 < r->FieldSize(msg, field); ++i2)
- v[field->name()][i2] = FromRepeatedField(msg, field, i2);
- }
+ for (int i2 = 0; i2 < r->FieldSize(msg, field); ++i2) {
+ auto val = FromRepeatedField(msg, field, i2);
+ if (val.IsDict()) {
+ elem[TStringBuf(val["key"])] = val["value"];
+ }
+ }
+ } else {
+ for (int i2 = 0; i2 < r->FieldSize(msg, field); ++i2)
+ v[field->name()][i2] = FromRepeatedField(msg, field, i2);
+ }
} else {
v[field->name()] = FromField(msg, field);
}
@@ -143,9 +143,9 @@ namespace NSc {
const Descriptor* descriptor = msg.GetDescriptor();
for (int i = 0, count = descriptor->field_count(); i < count; ++i) {
const FieldDescriptor* field = descriptor->field(i);
- if (field->is_map()) {
+ if (field->is_map()) {
ToMapField(msg, field, opts);
- } else if (field->is_repeated()) {
+ } else if (field->is_repeated()) {
ToRepeatedField(msg, field, opts);
} else {
ToField(msg, field, opts);
@@ -203,11 +203,11 @@ namespace NSc {
}
void TValue::ToField(Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const {
- const TString& name = field->name();
- const TValue& value = Get(name);
+ const TString& name = field->name();
+ const TValue& value = Get(name);
ValueToField(value, msg, field, opts);
- }
-
+ }
+
void TValue::ToEnumField(Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const {
const EnumDescriptor* enumField = field->enum_type();
@@ -291,39 +291,39 @@ namespace NSc {
}
void TValue::ToMapField(Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const {
- const TString& name = field->name();
-
- const TValue& fieldValue = Get(name);
- if (fieldValue.IsNull()) {
- return;
- }
-
- if (fieldValue.IsArray()) {
- // read dict from key, value array
+ const TString& name = field->name();
+
+ const TValue& fieldValue = Get(name);
+ if (fieldValue.IsNull()) {
+ return;
+ }
+
+ if (fieldValue.IsArray()) {
+ // read dict from key, value array
ToRepeatedField(msg, field, opts);
- return;
- }
-
- if (!fieldValue.IsDict()) {
+ return;
+ }
+
+ if (!fieldValue.IsDict()) {
if (opts.SkipTypeMismatch) {
return; // leave map field empty
} else {
ythrow TSchemeException() << "invalid type of map field " << name << ": not dict or array";
}
- }
-
- const Reflection* reflection = msg.GetReflection();
-
- auto mutableField = reflection->GetMutableRepeatedFieldRef<Message>(&msg, field);
- for (const auto& value : fieldValue.GetDict()) {
+ }
+
+ const Reflection* reflection = msg.GetReflection();
+
+ auto mutableField = reflection->GetMutableRepeatedFieldRef<Message>(&msg, field);
+ for (const auto& value : fieldValue.GetDict()) {
THolder<Message> entry(mutableField.NewMessage());
- auto entryDesc = entry->GetDescriptor();
- auto keyField = entryDesc->FindFieldByNumber(1);
- auto valueField = entryDesc->FindFieldByNumber(2);
- auto entryReflection = entry->GetReflection();
- entryReflection->SetString(entry.Get(), keyField, TString(value.first));
+ auto entryDesc = entry->GetDescriptor();
+ auto keyField = entryDesc->FindFieldByNumber(1);
+ auto valueField = entryDesc->FindFieldByNumber(2);
+ auto entryReflection = entry->GetReflection();
+ entryReflection->SetString(entry.Get(), keyField, TString(value.first));
ValueToField(value.second, *entry, valueField, opts);
- mutableField.Add(*entry);
- }
- }
+ mutableField.Add(*entry);
+ }
+ }
}
diff --git a/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp b/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp
index ae670640ef..e711a0d092 100644
--- a/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp
+++ b/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp
@@ -16,23 +16,23 @@ Y_UNIT_TEST_SUITE(TSchemeProtoTest) {
Y_UNIT_TEST(TestFromProtobufWithDict) {
DoTestProtobuf(true, true);
- }
-
+ }
+
Y_UNIT_TEST(TestToProtobufWithDict) {
DoTestProtobuf(false, true);
- }
-
- template <class T>
- void AddMapPair(NSc::TValue& v, TStringBuf key, T value, bool mapAsDict) {
- if (mapAsDict) {
- v[key] = value;
- } else {
+ }
+
+ template <class T>
+ void AddMapPair(NSc::TValue& v, TStringBuf key, T value, bool mapAsDict) {
+ if (mapAsDict) {
+ v[key] = value;
+ } else {
auto& newElement = v.Push();
- newElement["key"] = key;
- newElement["value"] = value;
- }
- }
-
+ newElement["key"] = key;
+ newElement["value"] = value;
+ }
+ }
+
void DoTestProtobuf(bool fromProto, bool mapAsDict) {
NSc::TMessage m;
NSc::TValue v;
@@ -53,36 +53,36 @@ Y_UNIT_TEST_SUITE(TSchemeProtoTest) {
m.SetBytes("Bytes"), v["Bytes"] = "Bytes";
m.SetEnum(NSc::VALUE1), v["Enum"] = "VALUE1";
- auto& mapDoublesP = *m.mutable_mapdoubles();
- auto& mapDoublesV = v["MapDoubles"];
- mapDoublesP["pi"] = 3.14;
- AddMapPair(mapDoublesV, "pi", 3.14, mapAsDict);
- if (fromProto && mapAsDict) {
- // can not add two entries in dict, as it represent over array with unstable order
- mapDoublesP["back_e"] = 1 / 2.7;
- AddMapPair(mapDoublesV, "back_e", 1 / 2.7, mapAsDict);
- }
-
- auto& mapInt32sP = *m.mutable_mapint32s();
- auto& mapInt32sV = v["MapInt32s"];
- mapInt32sP["pi"] = -7;
- AddMapPair(mapInt32sV, "pi", -7, mapAsDict);
- if (fromProto && mapAsDict) {
- // can not add two entries in dict, as it represent over array with unstable order
- mapInt32sP["back_e"] = 42;
- AddMapPair(mapInt32sV, "back_e", 42, mapAsDict);
- }
-
- auto& mapStringP = *m.mutable_mapstring();
- auto& mapStringV = v["MapString"];
- mapStringP["intro"] = "body";
- AddMapPair(mapStringV, "intro", "body", mapAsDict);
- if (fromProto && mapAsDict) {
- // can not add two entries in dict, as it represent over array with unstable order
- mapStringP["deep"] = "blue";
- AddMapPair(mapStringV, "deep", "blue", mapAsDict);
- }
-
+ auto& mapDoublesP = *m.mutable_mapdoubles();
+ auto& mapDoublesV = v["MapDoubles"];
+ mapDoublesP["pi"] = 3.14;
+ AddMapPair(mapDoublesV, "pi", 3.14, mapAsDict);
+ if (fromProto && mapAsDict) {
+ // can not add two entries in dict, as it represent over array with unstable order
+ mapDoublesP["back_e"] = 1 / 2.7;
+ AddMapPair(mapDoublesV, "back_e", 1 / 2.7, mapAsDict);
+ }
+
+ auto& mapInt32sP = *m.mutable_mapint32s();
+ auto& mapInt32sV = v["MapInt32s"];
+ mapInt32sP["pi"] = -7;
+ AddMapPair(mapInt32sV, "pi", -7, mapAsDict);
+ if (fromProto && mapAsDict) {
+ // can not add two entries in dict, as it represent over array with unstable order
+ mapInt32sP["back_e"] = 42;
+ AddMapPair(mapInt32sV, "back_e", 42, mapAsDict);
+ }
+
+ auto& mapStringP = *m.mutable_mapstring();
+ auto& mapStringV = v["MapString"];
+ mapStringP["intro"] = "body";
+ AddMapPair(mapStringV, "intro", "body", mapAsDict);
+ if (fromProto && mapAsDict) {
+ // can not add two entries in dict, as it represent over array with unstable order
+ mapStringP["deep"] = "blue";
+ AddMapPair(mapStringV, "deep", "blue", mapAsDict);
+ }
+
m.AddDoubles((double)1 / 3), v["Doubles"][0] = (double)1 / 3;
m.AddDoubles((double)1 / 4), v["Doubles"][1] = (double)1 / 4;
@@ -208,7 +208,7 @@ Y_UNIT_TEST_SUITE(TSchemeProtoTest) {
*(m.AddMessages()) = m2, v["Messages"][1] = v2;
if (fromProto) {
- UNIT_ASSERT(NSc::TValue::Equal(v, NSc::TValue::From(m, mapAsDict)));
+ UNIT_ASSERT(NSc::TValue::Equal(v, NSc::TValue::From(m, mapAsDict)));
} else {
NSc::TMessage proto;
v.To(proto);
diff --git a/library/cpp/scheme/tests/ut/scheme_ut.proto b/library/cpp/scheme/tests/ut/scheme_ut.proto
index 1d89d990b3..7981af7eae 100644
--- a/library/cpp/scheme/tests/ut/scheme_ut.proto
+++ b/library/cpp/scheme/tests/ut/scheme_ut.proto
@@ -36,10 +36,10 @@ message TMessage {
repeated bytes Bytess = 32;
repeated EEnum Enums = 33;
repeated TMessage2 Messages = 34;
-
- map<string, double> MapDoubles = 35;
- map<string, int32> MapInt32s = 36;
- map<string, string> MapString = 37;
+
+ map<string, double> MapDoubles = 35;
+ map<string, int32> MapInt32s = 36;
+ map<string, string> MapString = 37;
}
enum EEnum {
diff --git a/ydb/core/client/minikql_compile/yql_expr_minikql.cpp b/ydb/core/client/minikql_compile/yql_expr_minikql.cpp
index 656174184c..76f38bf35c 100644
--- a/ydb/core/client/minikql_compile/yql_expr_minikql.cpp
+++ b/ydb/core/client/minikql_compile/yql_expr_minikql.cpp
@@ -1565,10 +1565,10 @@ private:
auto root = astRes.Root;
astRes.Root = nullptr; // don't cleanup library nodes
if (!root) {
- errors = astRes.Issues;
+ errors = astRes.Issues;
return false;
}
- Expr->Context.IssueManager.AddIssues(std::move(astRes.Issues));
+ Expr->Context.IssueManager.AddIssues(std::move(astRes.Issues));
if (!CompileExpr(*root, Expr->Root, Expr->Context, nullptr)) {
errors = Expr->Context.IssueManager.GetIssues();
return false;
diff --git a/ydb/core/engine/kikimr_program_builder_ut.cpp b/ydb/core/engine/kikimr_program_builder_ut.cpp
index 304678f772..efa073ae2f 100644
--- a/ydb/core/engine/kikimr_program_builder_ut.cpp
+++ b/ydb/core/engine/kikimr_program_builder_ut.cpp
@@ -46,11 +46,11 @@ namespace NMiniKQL {
TAutoPtr<IComputationGraph> BuildGraph(TRuntimeNode pgm) {
Explorer.Walk(pgm.GetNode(), *Env);
- TComputationPatternOpts opts(Alloc.Ref(), *Env, GetLazyListFactory(),
- FunctionRegistry.Get(), NUdf::EValidateMode::None,
+ TComputationPatternOpts opts(Alloc.Ref(), *Env, GetLazyListFactory(),
+ FunctionRegistry.Get(), NUdf::EValidateMode::None,
NUdf::EValidatePolicy::Exception, "OFF", EGraphPerProcess::Multi);
- Pattern = MakeComputationPattern(Explorer, pgm, {}, opts);
- return Pattern->Clone(opts.ToComputationOptions(*RandomProvider, *TimeProvider));
+ Pattern = MakeComputationPattern(Explorer, pgm, {}, opts);
+ return Pattern->Clone(opts.ToComputationOptions(*RandomProvider, *TimeProvider));
}
TIntrusivePtr<IFunctionRegistry> FunctionRegistry;
@@ -62,7 +62,7 @@ namespace NMiniKQL {
THolder<TKikimrProgramBuilder> PgmBuilder;
TExploringNodeVisitor Explorer;
- IComputationPattern::TPtr Pattern;
+ IComputationPattern::TPtr Pattern;
};
Y_UNIT_TEST_SUITE(TMiniKQLProgramBuilderTest) {
diff --git a/ydb/core/engine/minikql/flat_local_tx_minikql.h b/ydb/core/engine/minikql/flat_local_tx_minikql.h
index b8f5db2f7d..0feabf20e6 100644
--- a/ydb/core/engine/minikql/flat_local_tx_minikql.h
+++ b/ydb/core/engine/minikql/flat_local_tx_minikql.h
@@ -89,10 +89,10 @@ class TFlatLocalMiniKQL : public NTabletFlatExecutor::ITransaction {
bool ParseProgram(TStringBuf program, NYql::TIssues &errors, NYql::TExprContainer &expr) {
NYql::TAstParseResult astResult = NYql::ParseAst(program);
if (!astResult.Root) {
- errors = astResult.Issues;
+ errors = astResult.Issues;
return false;
}
- expr.Context.IssueManager.AddIssues(astResult.Issues);
+ expr.Context.IssueManager.AddIssues(astResult.Issues);
if (!NYql::CompileExpr(*astResult.Root, expr.Root, expr.Context, nullptr)) {
errors = expr.Context.IssueManager.GetIssues();
diff --git a/ydb/core/engine/mkql_engine_flat.cpp b/ydb/core/engine/mkql_engine_flat.cpp
index 6de5efdb83..c7fe388eef 100644
--- a/ydb/core/engine/mkql_engine_flat.cpp
+++ b/ydb/core/engine/mkql_engine_flat.cpp
@@ -629,13 +629,13 @@ public:
NUdf::TUnboxedValue value;
{
- TComputationPatternOpts opts(Alloc.Ref(), Env,
+ TComputationPatternOpts opts(Alloc.Ref(), Env,
GetFlatProxyExecutionFactory(execData),
- Settings.FunctionRegistry,
- NUdf::EValidateMode::None, NUdf::EValidatePolicy::Exception,
+ Settings.FunctionRegistry,
+ NUdf::EValidateMode::None, NUdf::EValidatePolicy::Exception,
Settings.LlvmRuntime ? "" : "OFF", EGraphPerProcess::Multi);
- Pattern = MakeComputationPattern(ProxyProgramExplorer, ProxyProgram, {}, opts);
- ResultGraph = Pattern->Clone(opts.ToComputationOptions(Settings.RandomProvider, Settings.TimeProvider));
+ Pattern = MakeComputationPattern(ProxyProgramExplorer, ProxyProgram, {}, opts);
+ ResultGraph = Pattern->Clone(opts.ToComputationOptions(Settings.RandomProvider, Settings.TimeProvider));
const TBindTerminator bind(ResultGraph->GetTerminator());
@@ -1019,13 +1019,13 @@ public:
TShardExecData execData(Settings, Strings, StepTxId);
TExploringNodeVisitor explorer;
explorer.Walk(runPgm.GetNode(), Env);
- TComputationPatternOpts opts(Alloc.Ref(), Env,
+ TComputationPatternOpts opts(Alloc.Ref(), Env,
GetFlatShardExecutionFactory(execData, true),
- Settings.FunctionRegistry,
+ Settings.FunctionRegistry,
NUdf::EValidateMode::None, NUdf::EValidatePolicy::Exception,
Settings.LlvmRuntime ? "" : "OFF", EGraphPerProcess::Multi);
- auto pattern = MakeComputationPattern(explorer, runPgm, {}, opts);
- auto graph = pattern->Clone(opts.ToComputationOptions(Settings.RandomProvider, Settings.TimeProvider));
+ auto pattern = MakeComputationPattern(explorer, runPgm, {}, opts);
+ auto graph = pattern->Clone(opts.ToComputationOptions(Settings.RandomProvider, Settings.TimeProvider));
const TBindTerminator bind(graph->GetTerminator());
@@ -1348,14 +1348,14 @@ public:
<< expectedSizeIt->second << ", got: " << nodesCount << ", origin: " << pgm.first);
}
- TComputationPatternOpts opts(Alloc.Ref(), Env,
+ TComputationPatternOpts opts(Alloc.Ref(), Env,
GetFlatShardExecutionFactory(execData, false),
- Settings.FunctionRegistry,
- NUdf::EValidateMode::None, NUdf::EValidatePolicy::Exception,
+ Settings.FunctionRegistry,
+ NUdf::EValidateMode::None, NUdf::EValidatePolicy::Exception,
Settings.LlvmRuntime ? "" : "OFF", EGraphPerProcess::Multi);
- auto pattern = MakeComputationPattern(runExplorer, runPgm, {}, opts);
- auto compOpts = opts.ToComputationOptions(Settings.RandomProvider, Settings.TimeProvider);
- THolder<IComputationGraph> runGraph = pattern->Clone(compOpts);
+ auto pattern = MakeComputationPattern(runExplorer, runPgm, {}, opts);
+ auto compOpts = opts.ToComputationOptions(Settings.RandomProvider, Settings.TimeProvider);
+ THolder<IComputationGraph> runGraph = pattern->Clone(compOpts);
const TBindTerminator bind(runGraph->GetTerminator());
@@ -2123,8 +2123,8 @@ private:
THashMap<ui64, TStructLiteral*> ReadPerOrigin;
bool IsExecuted;
TMap<ui64, TString> ExecutionReplies;
- IComputationPattern::TPtr Pattern;
- THolder<IComputationGraph> ResultGraph;
+ IComputationPattern::TPtr Pattern;
+ THolder<IComputationGraph> ResultGraph;
THashMap<TString, NUdf::TUnboxedValue> ResultValues;
bool ReadOnlyOriginPrograms;
bool IsCancelled;
diff --git a/ydb/core/engine/mkql_engine_flat_extfunc.cpp b/ydb/core/engine/mkql_engine_flat_extfunc.cpp
index efa3fcfae4..414d3aeeb4 100644
--- a/ydb/core/engine/mkql_engine_flat_extfunc.cpp
+++ b/ydb/core/engine/mkql_engine_flat_extfunc.cpp
@@ -91,7 +91,7 @@ namespace {
};
class TResultWrapper : public TMutableComputationNode<TResultWrapper> {
- typedef TMutableComputationNode<TResultWrapper> TBaseComputation;
+ typedef TMutableComputationNode<TResultWrapper> TBaseComputation;
public:
class TResult : public TComputationValue<TResult> {
public:
@@ -129,18 +129,18 @@ namespace {
};
TResultWrapper(
- TComputationMutables& mutables,
+ TComputationMutables& mutables,
const TStringBuf& label,
IComputationNode* payload)
:
- TBaseComputation(mutables),
+ TBaseComputation(mutables),
Label(label),
Payload(payload)
{
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- return ctx.HolderFactory.Create<TResult>(Payload->GetValue(ctx), Label);
+ return ctx.HolderFactory.Create<TResult>(Payload->GetValue(ctx), Label);
}
private:
@@ -153,10 +153,10 @@ namespace {
};
class TAcquireLocksWrapper : public TMutableComputationNode<TAcquireLocksWrapper> {
- typedef TMutableComputationNode<TAcquireLocksWrapper> TBaseComputation;
+ typedef TMutableComputationNode<TAcquireLocksWrapper> TBaseComputation;
public:
TAcquireLocksWrapper(TComputationMutables& mutables, NUdf::TUnboxedValue locks, NUdf::TUnboxedValue locks2)
- : TBaseComputation(mutables)
+ : TBaseComputation(mutables)
, Labels({TxLocksResultLabel, TxLocksResultLabel2})
{
Locks.reserve(2);
@@ -176,11 +176,11 @@ namespace {
};
class TDiagnosticsWrapper : public TMutableComputationNode<TDiagnosticsWrapper> {
- typedef TMutableComputationNode<TDiagnosticsWrapper> TBaseComputation;
+ typedef TMutableComputationNode<TDiagnosticsWrapper> TBaseComputation;
public:
- TDiagnosticsWrapper(TComputationMutables& mutables, NUdf::TUnboxedValue&& diags)
- : TBaseComputation(mutables)
- , Diagnostics(std::move(diags))
+ TDiagnosticsWrapper(TComputationMutables& mutables, NUdf::TUnboxedValue&& diags)
+ : TBaseComputation(mutables)
+ , Diagnostics(std::move(diags))
{}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
@@ -198,12 +198,12 @@ namespace {
}
class TDummyWrapper : public TMutableComputationNode<TDummyWrapper> {
- typedef TMutableComputationNode<TDummyWrapper> TBaseComputation;
+ typedef TMutableComputationNode<TDummyWrapper> TBaseComputation;
public:
- TDummyWrapper(TComputationMutables& mutables)
- : TBaseComputation(mutables)
- {}
-
+ TDummyWrapper(TComputationMutables& mutables)
+ : TBaseComputation(mutables)
+ {}
+
NUdf::TUnboxedValuePod DoCalculate(TComputationContext&) const {
Y_FAIL("Failed to build value for dummy node");
}
@@ -212,7 +212,7 @@ namespace {
};
class TEraseRowWrapper : public TMutableComputationNode<TEraseRowWrapper> {
- typedef TMutableComputationNode<TEraseRowWrapper> TBaseComputation;
+ typedef TMutableComputationNode<TEraseRowWrapper> TBaseComputation;
public:
friend class TResult;
@@ -240,16 +240,16 @@ namespace {
const NUdf::TUnboxedValue Row;
};
- TEraseRowWrapper(TComputationMutables& mutables, const TTableId& tableId, TTupleType* rowType, IComputationNode* row)
- : TBaseComputation(mutables)
- , TableId(tableId)
+ TEraseRowWrapper(TComputationMutables& mutables, const TTableId& tableId, TTupleType* rowType, IComputationNode* row)
+ : TBaseComputation(mutables)
+ , TableId(tableId)
, RowType(rowType)
, Row(row)
{
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- return ctx.HolderFactory.Create<TResult>(this, Row->GetValue(ctx));
+ return ctx.HolderFactory.Create<TResult>(this, Row->GetValue(ctx));
}
private:
@@ -263,7 +263,7 @@ namespace {
};
class TUpdateRowWrapper : public TMutableComputationNode<TUpdateRowWrapper> {
- typedef TMutableComputationNode<TUpdateRowWrapper> TBaseComputation;
+ typedef TMutableComputationNode<TUpdateRowWrapper> TBaseComputation;
public:
friend class TResult;
@@ -322,10 +322,10 @@ namespace {
const NUdf::TUnboxedValue Update;
};
- TUpdateRowWrapper(TComputationMutables& mutables, const TTableId& tableId, TTupleType* rowType, IComputationNode* row,
+ TUpdateRowWrapper(TComputationMutables& mutables, const TTableId& tableId, TTupleType* rowType, IComputationNode* row,
TStructLiteral* updateStruct, IComputationNode* update)
- : TBaseComputation(mutables)
- , TableId(tableId)
+ : TBaseComputation(mutables)
+ , TableId(tableId)
, RowType(rowType)
, Row(row)
, UpdateStruct(updateStruct)
@@ -334,7 +334,7 @@ namespace {
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- return ctx.HolderFactory.Create<TResult>(this, Row->GetValue(ctx), Update->GetValue(ctx));
+ return ctx.HolderFactory.Create<TResult>(this, Row->GetValue(ctx), Update->GetValue(ctx));
}
private:
@@ -350,8 +350,8 @@ namespace {
IComputationNode* const Update;
};
- IComputationNode* WrapAsDummy(TComputationMutables& mutables) {
- return new TDummyWrapper(mutables);
+ IComputationNode* WrapAsDummy(TComputationMutables& mutables) {
+ return new TDummyWrapper(mutables);
}
IComputationNode* WrapResult(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
@@ -366,7 +366,7 @@ namespace {
TStringBuf label = labelData.AsValue().AsStringRef();
auto payloadNode = LocateNode(ctx.NodeLocator, callable, 1);
- return new TResultWrapper(ctx.Mutables, label, payloadNode);
+ return new TResultWrapper(ctx.Mutables, label, payloadNode);
}
IComputationNode* WrapAcquireLocks(TCallable& callable, const TComputationNodeFactoryContext& ctx,
@@ -442,7 +442,7 @@ namespace {
NUdf::TUnboxedValuePod(info.TxInfo.ExecLatency.MilliSeconds());
}
- return new TDiagnosticsWrapper(ctx.Mutables, std::move(diagList));
+ return new TDiagnosticsWrapper(ctx.Mutables, std::move(diagList));
}
IComputationNode* WrapAbort(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
@@ -741,7 +741,7 @@ namespace {
const auto tableId = ExtractTableId(tableNode);
auto tupleType = AS_TYPE(TTupleType, callable.GetInput(1));
- return new TEraseRowWrapper(ctx.Mutables, tableId, tupleType,
+ return new TEraseRowWrapper(ctx.Mutables, tableId, tupleType,
LocateNode(ctx.NodeLocator, callable, 1));
}
@@ -784,7 +784,7 @@ namespace {
}
}
- return new TUpdateRowWrapper(ctx.Mutables, tableId, tupleType,
+ return new TUpdateRowWrapper(ctx.Mutables, tableId, tupleType,
LocateNode(ctx.NodeLocator, callable, 1), structUpdate, LocateNode(ctx.NodeLocator, callable, 2));
}
@@ -851,7 +851,7 @@ TComputationNodeFactory GetFlatShardExecutionFactory(TShardExecData& execData, b
if (nameStr == strings.SelectRow) {
if (validateOnly) {
- return WrapAsDummy(ctx.Mutables);
+ return WrapAsDummy(ctx.Mutables);
}
else {
return WrapMergedSelectRow(
@@ -861,7 +861,7 @@ TComputationNodeFactory GetFlatShardExecutionFactory(TShardExecData& execData, b
if (nameStr == strings.SelectRange) {
if (validateOnly) {
- return WrapAsDummy(ctx.Mutables);
+ return WrapAsDummy(ctx.Mutables);
}
else {
return WrapMergedSelectRange(
diff --git a/ydb/core/kqp/host/kqp_host.cpp b/ydb/core/kqp/host/kqp_host.cpp
index 3c843ce345..44af6d1168 100644
--- a/ydb/core/kqp/host/kqp_host.cpp
+++ b/ydb/core/kqp/host/kqp_host.cpp
@@ -1450,7 +1450,7 @@ private:
TypesCtx->DeprecatedSQL = true;
}
- ctx.IssueManager.AddIssues(astRes.Issues);
+ ctx.IssueManager.AddIssues(astRes.Issues);
if (!astRes.IsOk()) {
return nullptr;
}
diff --git a/ydb/core/kqp/host/kqp_run_prepared.cpp b/ydb/core/kqp/host/kqp_run_prepared.cpp
index afea16c09c..e71a3bacee 100644
--- a/ydb/core/kqp/host/kqp_run_prepared.cpp
+++ b/ydb/core/kqp/host/kqp_run_prepared.cpp
@@ -148,7 +148,7 @@ private:
bool GetExpr(const TString& astStr, TExprNode::TPtr& expr, TExprContext& ctx) {
auto astRes = ParseAst(astStr);
- ctx.IssueManager.AddIssues(astRes.Issues);
+ ctx.IssueManager.AddIssues(astRes.Issues);
if (!astRes.IsOk()) {
return false;
}
diff --git a/ydb/core/kqp/provider/yql_kikimr_datasource.cpp b/ydb/core/kqp/provider/yql_kikimr_datasource.cpp
index 31eefe4b2d..65ef7eb932 100644
--- a/ydb/core/kqp/provider/yql_kikimr_datasource.cpp
+++ b/ydb/core/kqp/provider/yql_kikimr_datasource.cpp
@@ -71,7 +71,7 @@ private:
return TStatus::Ok;
}
- return TStatus::Error;
+ return TStatus::Error;
}
private:
diff --git a/ydb/core/kqp/provider/yql_kikimr_type_ann.cpp b/ydb/core/kqp/provider/yql_kikimr_type_ann.cpp
index f29671e0e6..692165204a 100644
--- a/ydb/core/kqp/provider/yql_kikimr_type_ann.cpp
+++ b/ydb/core/kqp/provider/yql_kikimr_type_ann.cpp
@@ -197,7 +197,7 @@ private:
}
}
- return TStatus::Error;
+ return TStatus::Error;
}
TStatus HandleRead(TExprBase node, TExprContext& ctx) override {
diff --git a/ydb/core/testlib/minikql_compile.h b/ydb/core/testlib/minikql_compile.h
index fad1c2bb59..4d76ca8d73 100644
--- a/ydb/core/testlib/minikql_compile.h
+++ b/ydb/core/testlib/minikql_compile.h
@@ -78,7 +78,7 @@ namespace NYql {
inline TExprContainer::TPtr ParseText(const TString& programText) {
TAstParseResult astRes = ParseAst(programText);
- astRes.Issues.PrintTo(Cerr);
+ astRes.Issues.PrintTo(Cerr);
UNIT_ASSERT(astRes.IsOk());
TExprContainer::TPtr expr(new TExprContainer());
diff --git a/ydb/library/yql/ast/yql_ast.cpp b/ydb/library/yql/ast/yql_ast.cpp
index 2cf65af32b..16e521d901 100644
--- a/ydb/library/yql/ast/yql_ast.cpp
+++ b/ydb/library/yql/ast/yql_ast.cpp
@@ -136,8 +136,8 @@ namespace {
}
TAstParseResult result;
- if (!Issues_.Empty()) {
- result.Issues = std::move(Issues_);
+ if (!Issues_.Empty()) {
+ result.Issues = std::move(Issues_);
} else {
result.Root = root;
result.Pool = Ctx_.InnerPool();
@@ -416,7 +416,7 @@ namespace {
private:
TAstParserContext Ctx_;
- TIssues Issues_;
+ TIssues Issues_;
};
///////////////////////////////////////////////////////////////////////////
diff --git a/ydb/library/yql/ast/yql_ast.h b/ydb/library/yql/ast/yql_ast.h
index 8ec4373ebc..887b53dbc5 100644
--- a/ydb/library/yql/ast/yql_ast.h
+++ b/ydb/library/yql/ast/yql_ast.h
@@ -237,7 +237,7 @@ private:
struct TAstParseResult {
std::unique_ptr<TMemoryPool> Pool;
TAstNode* Root = nullptr;
- TIssues Issues;
+ TIssues Issues;
inline bool IsOk() const {
return !!Root;
diff --git a/ydb/library/yql/ast/yql_ast_ut.cpp b/ydb/library/yql/ast/yql_ast_ut.cpp
index 5a761361b4..23e140653d 100644
--- a/ydb/library/yql/ast/yql_ast_ut.cpp
+++ b/ydb/library/yql/ast/yql_ast_ut.cpp
@@ -28,7 +28,7 @@ Y_UNIT_TEST_SUITE(TParseYqlAst) {
TAstParseResult res = ParseAst(TEST_PROGRAM);
UNIT_ASSERT(res.IsOk());
UNIT_ASSERT(res.Root->IsList());
- UNIT_ASSERT(res.Issues.Empty());
+ UNIT_ASSERT(res.Issues.Empty());
}
Y_UNIT_TEST(ParseAstTestPerf) {
@@ -42,7 +42,7 @@ Y_UNIT_TEST_SUITE(TParseYqlAst) {
TAstParseResult res = ParseAst(TEST_PROGRAM);
UNIT_ASSERT(res.IsOk());
UNIT_ASSERT(res.Root->IsList());
- UNIT_ASSERT(res.Issues.Empty());
+ UNIT_ASSERT(res.Issues.Empty());
}
auto t2 = TInstant::Now();
Cout << t2 - t1 << Endl;
@@ -184,8 +184,8 @@ Y_UNIT_TEST_SUITE(TParseYqlAst) {
TAstParseResult ast = ParseAst(program);
UNIT_ASSERT(false == ast.IsOk());
UNIT_ASSERT(false == !!ast.Root);
- UNIT_ASSERT(false == ast.Issues.Empty());
- UNIT_ASSERT_STRINGS_EQUAL(ast.Issues.begin()->Message, expectedError);
+ UNIT_ASSERT(false == ast.Issues.Empty());
+ UNIT_ASSERT_STRINGS_EQUAL(ast.Issues.begin()->Message, expectedError);
}
Y_UNIT_TEST(BadArbitraryAtom) {
diff --git a/ydb/library/yql/ast/yql_expr.cpp b/ydb/library/yql/ast/yql_expr.cpp
index b0757fc12b..82f6c5812a 100644
--- a/ydb/library/yql/ast/yql_expr.cpp
+++ b/ydb/library/yql/ast/yql_expr.cpp
@@ -711,21 +711,21 @@ namespace {
{
auto self = TAstNode::NewLiteralAtom(TPosition(), TStringBuf("Resource"), pool);
auto restype = refAtoms ?
- TAstNode::NewLiteralAtom(TPosition(), annotation.Cast<TResourceExprType>()->GetTag(), pool, TNodeFlags::ArbitraryContent) :
- TAstNode::NewAtom(TPosition(), annotation.Cast<TResourceExprType>()->GetTag(), pool, TNodeFlags::ArbitraryContent);
+ TAstNode::NewLiteralAtom(TPosition(), annotation.Cast<TResourceExprType>()->GetTag(), pool, TNodeFlags::ArbitraryContent) :
+ TAstNode::NewAtom(TPosition(), annotation.Cast<TResourceExprType>()->GetTag(), pool, TNodeFlags::ArbitraryContent);
return TAstNode::NewList(TPosition(), pool, self, restype);
}
- case ETypeAnnotationKind::Tagged:
- {
+ case ETypeAnnotationKind::Tagged:
+ {
auto self = TAstNode::NewLiteralAtom(TPosition(), TStringBuf("Tagged"), pool);
- auto type = ConvertTypeAnnotationToAst(*annotation.Cast<TTaggedExprType>()->GetBaseType(), pool, refAtoms);
- auto restype = refAtoms ?
- TAstNode::NewLiteralAtom(TPosition(), annotation.Cast<TTaggedExprType>()->GetTag(), pool, TNodeFlags::ArbitraryContent) :
- TAstNode::NewAtom(TPosition(), annotation.Cast<TTaggedExprType>()->GetTag(), pool, TNodeFlags::ArbitraryContent);
- return TAstNode::NewList(TPosition(), pool, self, type, restype);
- }
-
+ auto type = ConvertTypeAnnotationToAst(*annotation.Cast<TTaggedExprType>()->GetBaseType(), pool, refAtoms);
+ auto restype = refAtoms ?
+ TAstNode::NewLiteralAtom(TPosition(), annotation.Cast<TTaggedExprType>()->GetTag(), pool, TNodeFlags::ArbitraryContent) :
+ TAstNode::NewAtom(TPosition(), annotation.Cast<TTaggedExprType>()->GetTag(), pool, TNodeFlags::ArbitraryContent);
+ return TAstNode::NewList(TPosition(), pool, self, type, restype);
+ }
+
case ETypeAnnotationKind::Error:
{
auto self = TAstNode::NewLiteralAtom(TPosition(), TStringBuf("Error"), pool);
@@ -938,20 +938,20 @@ namespace {
}
const auto& aliasValue = alias->GetChild(1)->GetContent();
- const auto& moduleName = name->GetContent();
- TStringBuilder baseMsg;
- baseMsg << "Module '" << name->GetContent() << "'";
+ const auto& moduleName = name->GetContent();
+ TStringBuilder baseMsg;
+ baseMsg << "Module '" << name->GetContent() << "'";
- const auto& import = ctx.FindImport(moduleName);
+ const auto& import = ctx.FindImport(moduleName);
if (import.empty()) {
- ctx.AddError(*name, baseMsg << " does not exist");
+ ctx.AddError(*name, baseMsg << " does not exist");
return nullptr;
}
if (ctx.ModuleResolver) {
auto exportsPtr = ctx.ModuleResolver->GetModule(import);
if (!exportsPtr) {
- ctx.AddError(*name, baseMsg << "'" << import << "' does not exist");
+ ctx.AddError(*name, baseMsg << "'" << import << "' does not exist");
return nullptr;
}
@@ -959,7 +959,7 @@ namespace {
const auto ex = exports.find(aliasValue);
if (exports.cend() == ex) {
- ctx.AddError(*alias, baseMsg << " export '" << aliasValue << "' does not exist");
+ ctx.AddError(*alias, baseMsg << " export '" << aliasValue << "' does not exist");
return nullptr;
}
@@ -2632,7 +2632,7 @@ TNodeException::TNodeException(const TPositionHandle& pos)
}
bool ValidateName(TPosition position, TStringBuf name, TStringBuf descr, TExprContext& ctx) {
- if (name.empty()) {
+ if (name.empty()) {
ctx.AddError(TIssue(position,
TStringBuilder() << "Empty " << descr << " name is not allowed"));
return false;
@@ -2684,10 +2684,10 @@ bool TDataExprParamsType::Validate(TPositionHandle position, TExprContext& ctx)
return Validate(ctx.GetPosition(position), ctx);
}
-bool TItemExprType::Validate(TPosition position, TExprContext& ctx) const {
+bool TItemExprType::Validate(TPosition position, TExprContext& ctx) const {
return ValidateName(position, Name, "member", ctx);
-}
-
+}
+
bool TItemExprType::Validate(TPositionHandle position, TExprContext& ctx) const {
return Validate(ctx.GetPosition(position), ctx);
}
diff --git a/ydb/library/yql/ast/yql_expr.h b/ydb/library/yql/ast/yql_expr.h
index 168a57ee53..d6eb544f9a 100644
--- a/ydb/library/yql/ast/yql_expr.h
+++ b/ydb/library/yql/ast/yql_expr.h
@@ -76,8 +76,8 @@ class TFlowExprType;
class TEmptyListExprType;
class TEmptyDictExprType;
-const size_t DefaultMistypeDistance = 3;
-
+const size_t DefaultMistypeDistance = 3;
+
extern const TStringBuf ZeroString;
struct TTypeAnnotationVisitor {
@@ -395,7 +395,7 @@ struct TExprContext;
bool ValidateName(TPosition position, TStringBuf name, TStringBuf descr, TExprContext& ctx);
bool ValidateName(TPositionHandle position, TStringBuf name, TStringBuf descr, TExprContext& ctx);
-
+
class TItemExprType : public TTypeAnnotationNode {
public:
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Item;
@@ -499,9 +499,9 @@ public:
}
TMaybe<TStringBuf> FindMistype(const TStringBuf& name) const {
- for (const auto& item: Items) {
+ for (const auto& item: Items) {
if (NLevenshtein::Distance(name, item->GetName()) < DefaultMistypeDistance) {
- return item->GetName();
+ return item->GetName();
}
}
return TMaybe<TStringBuf>();
diff --git a/ydb/library/yql/ast/yql_expr_ut.cpp b/ydb/library/yql/ast/yql_expr_ut.cpp
index 50c0c63d06..06550f2507 100644
--- a/ydb/library/yql/ast/yql_expr_ut.cpp
+++ b/ydb/library/yql/ast/yql_expr_ut.cpp
@@ -9,7 +9,7 @@ Y_UNIT_TEST_SUITE(TCompileYqlExpr) {
static TAstParseResult ParseAstWithCheck(const TStringBuf& s) {
TAstParseResult res = ParseAst(s);
- res.Issues.PrintTo(Cout);
+ res.Issues.PrintTo(Cout);
UNIT_ASSERT(res.IsOk());
return res;
}
diff --git a/ydb/library/yql/ast/yql_type_string_ut.cpp b/ydb/library/yql/ast/yql_type_string_ut.cpp
index 4ef9fa2ed6..2f22c42258 100644
--- a/ydb/library/yql/ast/yql_type_string_ut.cpp
+++ b/ydb/library/yql/ast/yql_type_string_ut.cpp
@@ -514,7 +514,7 @@ Y_UNIT_TEST_SUITE(TTypeString)
TAstParseResult astRes = ParseAst(yql, &pool);
if (!astRes.IsOk()) {
- astRes.Issues.PrintWithProgramTo(Cerr, "-memory-", yql);
+ astRes.Issues.PrintWithProgramTo(Cerr, "-memory-", yql);
UNIT_FAIL("Can't parse yql");
}
@@ -661,9 +661,9 @@ Y_UNIT_TEST_SUITE(TTypeString)
}
Y_UNIT_TEST(FormatTagged) {
- TestFormat("((Tagged (Data String) aaa))", "Tagged<String,'aaa'>");
- TestFormat("((Tagged (Data String) \"a b\"))", "Tagged<String,'a b'>");
- TestFormat("((Tagged (Data String) \"a\\t\\n\\x01b\"))", "Tagged<String,'a\\t\\n\\x01b'>");
+ TestFormat("((Tagged (Data String) aaa))", "Tagged<String,'aaa'>");
+ TestFormat("((Tagged (Data String) \"a b\"))", "Tagged<String,'a b'>");
+ TestFormat("((Tagged (Data String) \"a\\t\\n\\x01b\"))", "Tagged<String,'a\\t\\n\\x01b'>");
}
}
diff --git a/ydb/library/yql/core/expr_nodes/yql_expr_nodes.json b/ydb/library/yql/core/expr_nodes/yql_expr_nodes.json
index 16646283db..edfcaa1530 100644
--- a/ydb/library/yql/core/expr_nodes/yql_expr_nodes.json
+++ b/ydb/library/yql/core/expr_nodes/yql_expr_nodes.json
@@ -963,12 +963,12 @@
},
{
"Name": "TCoDictFromKeys",
- "Base": "TCallable",
- "Match": {"Type": "Callable", "Name": "DictFromKeys"},
- "Children": [
- {"Index": 0, "Name": "Type", "Type": "TExprBase"},
- {"Index": 1, "Name": "Keys", "Type": "TExprList"}
- ]
+ "Base": "TCallable",
+ "Match": {"Type": "Callable", "Name": "DictFromKeys"},
+ "Children": [
+ {"Index": 0, "Name": "Type", "Type": "TExprBase"},
+ {"Index": 1, "Name": "Keys", "Type": "TExprList"}
+ ]
},
{
"Name": "TCoSqueezeToDict",
@@ -1287,17 +1287,17 @@
"Children": [
{"Index": 0, "Name": "Type", "Type": "TExprBase"}
]
- },
- {
+ },
+ {
"Name": "TCoCalcOverWindowBase",
"Base": "TCoInputBase",
"Match": {"Type": "CallableBase"},
"Builder": {"Generate": "None"},
- "Children": [
+ "Children": [
{"Index": 1, "Name": "Keys", "Type": "TCoAtomList"},
- {"Index": 2, "Name": "SortSpec", "Type": "TExprBase"},
- {"Index": 3, "Name": "Frames", "Type": "TExprList"}
- ]
+ {"Index": 2, "Name": "SortSpec", "Type": "TExprBase"},
+ {"Index": 3, "Name": "Frames", "Type": "TExprList"}
+ ]
},
{
"Name": "TCoCalcOverWindow",
diff --git a/ydb/library/yql/core/facade/yql_facade.cpp b/ydb/library/yql/core/facade/yql_facade.cpp
index 2c739c4fe3..b74abc1c34 100644
--- a/ydb/library/yql/core/facade/yql_facade.cpp
+++ b/ydb/library/yql/core/facade/yql_facade.cpp
@@ -127,10 +127,10 @@ TProgramFactory::TProgramFactory(
AddCredentialsTable(std::make_shared<TCredentialTable>());
}
-void TProgramFactory::UnrepeatableRandom() {
- UseUnrepeatableRandom = true;
-}
-
+void TProgramFactory::UnrepeatableRandom() {
+ UseUnrepeatableRandom = true;
+}
+
void TProgramFactory::EnableRangeComputeFor() {
EnableRangeComputeFor_ = true;
}
@@ -185,7 +185,7 @@ TProgramPtr TProgramFactory::Create(
const TString& sourceCode,
const TString& sessionId)
{
- auto randomProvider = UseRepeatableRandomAndTimeProviders_ && !UseUnrepeatableRandom ?
+ auto randomProvider = UseRepeatableRandomAndTimeProviders_ && !UseUnrepeatableRandom ?
CreateDeterministicRandomProvider(1) : CreateDefaultRandomProvider();
auto timeProvider = UseRepeatableRandomAndTimeProviders_ ?
CreateDeterministicTimeProvider(10000000) : CreateDefaultTimeProvider();
@@ -279,8 +279,8 @@ void TProgram::ConfigureYsonResultFormat(NYson::EYsonFormat format) {
void TProgram::SetValidateOptions(NUdf::EValidateMode validateMode) {
Y_ENSURE(!TypeCtx_, "TypeCtx_ already created");
ValidateMode_ = validateMode;
-}
-
+}
+
void TProgram::SetDisableNativeUdfSupport(bool disable) {
Y_ENSURE(!TypeCtx_, "TypeCtx_ already created");
DisableNativeUdfSupport_ = disable;
@@ -345,27 +345,27 @@ bool TProgram::ExtractQueryParametersMetadata() {
}
bool TProgram::FillParseResult(NYql::TAstParseResult&& astRes, NYql::TWarningRules* warningRules) {
- if (!astRes.Issues.Empty()) {
- if (!ExprCtx_) {
- ExprCtx_.Reset(new TExprContext(NextUniqueId_));
- }
- auto& iManager = ExprCtx_->IssueManager;
+ if (!astRes.Issues.Empty()) {
+ if (!ExprCtx_) {
+ ExprCtx_.Reset(new TExprContext(NextUniqueId_));
+ }
+ auto& iManager = ExprCtx_->IssueManager;
if (warningRules) {
for (auto warningRule: *warningRules) {
iManager.AddWarningRule(warningRule);
- }
- }
- iManager.AddScope([this]() {
- TIssuePtr issueHolder = new TIssue();
- issueHolder->Message = TStringBuilder() << "Parse " << SourceSyntax_;
- issueHolder->Severity = TSeverityIds::S_INFO;
- return issueHolder;
- });
- for (auto issue: astRes.Issues) {
- iManager.RaiseWarning(issue);
- }
- iManager.LeaveScope();
- }
+ }
+ }
+ iManager.AddScope([this]() {
+ TIssuePtr issueHolder = new TIssue();
+ issueHolder->Message = TStringBuilder() << "Parse " << SourceSyntax_;
+ issueHolder->Severity = TSeverityIds::S_INFO;
+ return issueHolder;
+ });
+ for (auto issue: astRes.Issues) {
+ iManager.RaiseWarning(issue);
+ }
+ iManager.LeaveScope();
+ }
if (!astRes.IsOk()) {
return false;
}
@@ -392,7 +392,7 @@ bool TProgram::ParseYql() {
YQL_ENSURE(SourceSyntax_ == ESourceSyntax::Unknown);
SourceSyntax_ = ESourceSyntax::Yql;
SyntaxVersion_ = 1;
- return FillParseResult(ParseAst(SourceCode_));
+ return FillParseResult(ParseAst(SourceCode_));
}
bool TProgram::ParseSql() {
@@ -421,9 +421,9 @@ bool TProgram::Compile(const TString& username) {
YQL_PROFILE_FUNC(TRACE);
Y_ENSURE(AstRoot_, "Program not parsed yet");
- if (!ExprCtx_) {
- ExprCtx_.Reset(new TExprContext(NextUniqueId_));
- }
+ if (!ExprCtx_) {
+ ExprCtx_.Reset(new TExprContext(NextUniqueId_));
+ }
if (!ProvideAnnotationContext(username)->Initialize(*ExprCtx_)) {
return false;
@@ -552,7 +552,7 @@ TProgram::TStatus TProgram::Validate(const TString& username, IOutputStream* exp
TProgram::TFutureStatus TProgram::ValidateAsync(const TString& username, IOutputStream* exprOut, bool withTypes) {
if (!ProvideAnnotationContext(username)->Initialize(*ExprCtx_) || !CollectUsedClusters()) {
- return NThreading::MakeFuture<TStatus>(IGraphTransformer::TStatus::Error);
+ return NThreading::MakeFuture<TStatus>(IGraphTransformer::TStatus::Error);
}
TypeCtx_->IsReadOnly = true;
@@ -617,7 +617,7 @@ TProgram::TFutureStatus TProgram::OptimizeAsync(
bool withTypes)
{
if (!ProvideAnnotationContext(username)->Initialize(*ExprCtx_) || !CollectUsedClusters()) {
- return NThreading::MakeFuture<TStatus>(IGraphTransformer::TStatus::Error);
+ return NThreading::MakeFuture<TStatus>(IGraphTransformer::TStatus::Error);
}
TypeCtx_->IsReadOnly = true;
@@ -758,7 +758,7 @@ TProgram::TFutureStatus TProgram::RunAsync(
bool withTypes)
{
if (!ProvideAnnotationContext(username)->Initialize(*ExprCtx_) || !CollectUsedClusters()) {
- return NThreading::MakeFuture<TStatus>(IGraphTransformer::TStatus::Error);
+ return NThreading::MakeFuture<TStatus>(IGraphTransformer::TStatus::Error);
}
TypeCtx_->IsReadOnly = false;
diff --git a/ydb/library/yql/core/facade/yql_facade.h b/ydb/library/yql/core/facade/yql_facade.h
index c416255fb8..1f8f47681d 100644
--- a/ydb/library/yql/core/facade/yql_facade.h
+++ b/ydb/library/yql/core/facade/yql_facade.h
@@ -63,10 +63,10 @@ public:
const TString& sourceCode,
const TString& sessionId = TString());
- void UnrepeatableRandom();
+ void UnrepeatableRandom();
private:
const bool UseRepeatableRandomAndTimeProviders_;
- bool UseUnrepeatableRandom = false;
+ bool UseUnrepeatableRandom = false;
const NKikimr::NMiniKQL::IFunctionRegistry* FunctionRegistry_;
const ui64 NextUniqueId_;
TVector<TDataProviderInitializer> DataProvidersInit_;
@@ -233,7 +233,7 @@ public:
void SetValidateOptions(NUdf::EValidateMode validateMode);
void SetDisableNativeUdfSupport(bool disable);
void SetUseTableMetaFromGraph(bool use);
-
+
void SetProgressWriter(TOperationProgressWriter writer) {
Y_ENSURE(!TypeCtx_, "TypeCtx_ already created");
ProgressWriter_ = ThreadSafeProgressWriter(writer);
@@ -331,7 +331,7 @@ private:
bool FillParseResult(NYql::TAstParseResult&& astRes, NYql::TWarningRules* warningRules = nullptr);
TString GetSessionId() const;
TString TakeSessionId();
-
+
NThreading::TFuture<IGraphTransformer::TStatus> AsyncTransformWithFallback(bool applyAsyncChanges);
private:
diff --git a/ydb/library/yql/core/issue/protos/issue_id.proto b/ydb/library/yql/core/issue/protos/issue_id.proto
index c924ef8971..a2ed91d640 100644
--- a/ydb/library/yql/core/issue/protos/issue_id.proto
+++ b/ydb/library/yql/core/issue/protos/issue_id.proto
@@ -9,7 +9,7 @@ message TIssuesIds {
DEFAULT_ERROR = 0;
UNEXPECTED = 1;
INFO = 2;
- WARNING = 3;
+ WARNING = 3;
SUCCESS = 4;
// core codes
CORE = 1000;
@@ -98,14 +98,14 @@ message TIssuesIds {
YT_ROWSPEC_HIDES_FIELDS = 3014;
YT_ROWSPEC_DIFF_SORT = 3015;
YT_NATIVE_DESC_SORT_IGNORED = 3016;
-
-// yql parser warnings
- YQL_PRAGMA_WARNING_MSG = 4500;
- YQL_CONST_SUBREQUEST_IN_LIST = 4501;
- YQL_AGGREGATE_BY_WIN_FUNC_WITHOUT_ORDER_BY = 4502;
+
+// yql parser warnings
+ YQL_PRAGMA_WARNING_MSG = 4500;
+ YQL_CONST_SUBREQUEST_IN_LIST = 4501;
+ YQL_AGGREGATE_BY_WIN_FUNC_WITHOUT_ORDER_BY = 4502;
YQL_DEPRECATED_INFERSCHEME = 4503;
YQL_ORDER_BY_WITHOUT_LIMIT_IN_SUBQUERY = 4504;
- YQL_DEPRECATED_DOUBLE_QUOTE_IN_BRACKETS = 4505;
+ YQL_DEPRECATED_DOUBLE_QUOTE_IN_BRACKETS = 4505;
YQL_DEPRECATED_JSON_UDF = 4506;
YQL_MISSING_IS_BEFORE_NOT_NULL = 4507;
YQL_DEPRECATED_TINY_INT_LITERAL_SUFFIX = 4508;
diff --git a/ydb/library/yql/core/issue/yql_issue.txt b/ydb/library/yql/core/issue/yql_issue.txt
index 98ba74a6f7..897d5d6f9a 100644
--- a/ydb/library/yql/core/issue/yql_issue.txt
+++ b/ydb/library/yql/core/issue/yql_issue.txt
@@ -15,10 +15,10 @@ ids {
severity: S_INFO
}
ids {
- code: WARNING
- severity: S_WARNING
-}
-ids {
+ code: WARNING
+ severity: S_WARNING
+}
+ids {
code: CORE
severity: S_INFO
}
@@ -293,17 +293,17 @@ ids {
severity: S_ERROR
}
ids {
- code: YQL_PRAGMA_WARNING_MSG
- severity: S_WARNING
-}
-ids {
- code: YQL_CONST_SUBREQUEST_IN_LIST
- severity: S_WARNING
-}
-ids {
- code: YQL_AGGREGATE_BY_WIN_FUNC_WITHOUT_ORDER_BY
- severity: S_WARNING
-}
+ code: YQL_PRAGMA_WARNING_MSG
+ severity: S_WARNING
+}
+ids {
+ code: YQL_CONST_SUBREQUEST_IN_LIST
+ severity: S_WARNING
+}
+ids {
+ code: YQL_AGGREGATE_BY_WIN_FUNC_WITHOUT_ORDER_BY
+ severity: S_WARNING
+}
ids {
code: YQL_DEPRECATED_INFERSCHEME
severity: S_WARNING
@@ -312,10 +312,10 @@ ids {
code: YQL_ORDER_BY_WITHOUT_LIMIT_IN_SUBQUERY
severity: S_WARNING
}
-ids {
- code: YQL_DEPRECATED_DOUBLE_QUOTE_IN_BRACKETS
- severity: S_WARNING
-}
+ids {
+ code: YQL_DEPRECATED_DOUBLE_QUOTE_IN_BRACKETS
+ severity: S_WARNING
+}
ids {
code: YQL_DEPRECATED_JSON_UDF
severity: S_WARNING
diff --git a/ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp b/ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp
index 076278951a..ce22b12571 100644
--- a/ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp
+++ b/ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp
@@ -440,12 +440,12 @@ TExprNode::TPtr ExpandEquiJoinImpl(const TExprNode& node, TExprContext& ctx) {
.Seal().Build();
}
-TExprNode::TPtr PeepHoleConvertGroupBySingleKey(const TExprNode::TPtr& node, TExprContext& ctx) {
+TExprNode::TPtr PeepHoleConvertGroupBySingleKey(const TExprNode::TPtr& node, TExprContext& ctx) {
const auto keySelectorLambda = node->Child(1);
if (keySelectorLambda->Tail().GetDependencyScope()->second == keySelectorLambda) {
- return node;
- }
-
+ return node;
+ }
+
YQL_CLOG(DEBUG, CorePeepHole) << "Convert " << node->Content() << " single key";
const auto handlerLambda = node->Child(2);
const auto& keyArg = handlerLambda->Head().Head();
@@ -550,8 +550,8 @@ TExprNode::TPtr PeepHoleExpandExtractItems(const TExprNode::TPtr& node, TExprCon
.Add(1, std::move(lambda))
.Seal()
.Build();
-}
-
+}
+
TExprNode::TPtr PeepHoleDictFromKeysToDict(const TExprNode::TPtr& node, TExprContext& ctx) {
YQL_CLOG(DEBUG, CorePeepHole) << "Expand " << node->Content();
@@ -561,7 +561,7 @@ TExprNode::TPtr PeepHoleDictFromKeysToDict(const TExprNode::TPtr& node, TExprCon
.Callable("List")
.Callable(0, "ListType")
.Add(0, ExpandType(callable.Pos(), *itemTypeAnnotation, ctx))
- .Seal()
+ .Seal()
.Do([&](TExprNodeBuilder& parent) -> TExprNodeBuilder& {
ui32 pos = 0;
for (auto child : callable.Keys().Ptr()->Children()) {
@@ -569,8 +569,8 @@ TExprNode::TPtr PeepHoleDictFromKeysToDict(const TExprNode::TPtr& node, TExprCon
}
return parent;
})
- .Seal()
- .Build();
+ .Seal()
+ .Build();
return Build<TCoToDict>(ctx, callable.Pos())
.List(list)
diff --git a/ydb/library/yql/core/type_ann/type_ann_core.cpp b/ydb/library/yql/core/type_ann/type_ann_core.cpp
index d9cd765b76..5846e6cb10 100644
--- a/ydb/library/yql/core/type_ann/type_ann_core.cpp
+++ b/ydb/library/yql/core/type_ann/type_ann_core.cpp
@@ -39,11 +39,11 @@
#include <functional>
namespace NYql {
- TString DotJoin(const TStringBuf& sourceName, const TStringBuf& columnName) {
- TStringBuilder sb;
- sb << sourceName << "." << columnName;
- return sb;
- }
+ TString DotJoin(const TStringBuf& sourceName, const TStringBuf& columnName) {
+ TStringBuilder sb;
+ sb << sourceName << "." << columnName;
+ return sb;
+ }
namespace NTypeAnnImpl {
enum class EDictItems {
@@ -950,12 +950,12 @@ namespace NTypeAnnImpl {
return IGraphTransformer::TStatus::Repeat;
}
- IGraphTransformer::TStatus SqlColumnWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ IGraphTransformer::TStatus SqlColumnWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
const bool columnOrType = input->IsCallable({"SqlColumnOrType", "SqlPlainColumnOrType"});
const bool isPlain = input->IsCallable({"SqlPlainColumn", "SqlPlainColumnOrType"});
if (!EnsureMinArgsCount(*input, 2, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
+ return IGraphTransformer::TStatus::Error;
+ }
if (!EnsureMaxArgsCount(*input, isPlain ? 2 : 3, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
@@ -973,35 +973,35 @@ namespace NTypeAnnImpl {
auto rowNode = input->Child(0);
const auto columnNameNode = input->Child(1);
- TExprNode::TPtr sourceNameNode;
- if (input->ChildrenSize() > 2) {
- sourceNameNode = input->ChildPtr(2);
- }
-
+ TExprNode::TPtr sourceNameNode;
+ if (input->ChildrenSize() > 2) {
+ sourceNameNode = input->ChildPtr(2);
+ }
+
if (!EnsureStructOrOptionalStructType(*rowNode, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
- }
+ }
const TStructExprType* structType = RemoveAllOptionals(rowNode->GetTypeAnn())->Cast<TStructExprType>();
-
- if (!EnsureAtom(*columnNameNode, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- if (sourceNameNode && !EnsureAtom(*sourceNameNode, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+
+ if (!EnsureAtom(*columnNameNode, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ if (sourceNameNode && !EnsureAtom(*sourceNameNode, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
const auto columnName = columnNameNode->Content();
const auto sourceName = sourceNameNode ? sourceNameNode->Content() : "";
-
+
TString effectiveColumnName;
- if (sourceName) {
+ if (sourceName) {
effectiveColumnName = DotJoin(sourceName, columnName);
} else if (isPlain) {
effectiveColumnName = ToString(columnName);
- } else {
- TStringBuf goalItemName;
- for (auto& item: structType->GetItems()) {
- const auto& itemName = item->GetName();
+ } else {
+ TStringBuf goalItemName;
+ for (auto& item: structType->GetItems()) {
+ const auto& itemName = item->GetName();
TStringBuf columnItemName;
auto dotPos = itemName.find_first_of('.');
if (dotPos == TStringBuf::npos) {
@@ -1009,24 +1009,24 @@ namespace NTypeAnnImpl {
} else {
columnItemName = itemName.SubStr(dotPos + 1);
}
- if (columnItemName == columnName) {
- if (goalItemName) {
+ if (columnItemName == columnName) {
+ if (goalItemName) {
auto issue = TIssue(ctx.Expr.GetPosition(input->Pos()), TStringBuilder() << "column name: " <<
- columnName << " conflicted without correlation name it may be one of: " <<
+ columnName << " conflicted without correlation name it may be one of: " <<
goalItemName << ", " << itemName);
if (columnOrType) {
input->SetTypeAnn(ctx.Expr.MakeType<TErrorExprType>(issue));
return IGraphTransformer::TStatus::Ok;
}
ctx.Expr.AddError(issue);
- return IGraphTransformer::TStatus::Error;
- } else {
- goalItemName = itemName;
- }
- }
- }
+ return IGraphTransformer::TStatus::Error;
+ } else {
+ goalItemName = itemName;
+ }
+ }
+ }
effectiveColumnName = goalItemName ? goalItemName : columnName;
- }
+ }
TString errStr;
auto pos = FindOrReportMissingMember(effectiveColumnName, *structType, errStr);
@@ -1045,18 +1045,18 @@ namespace NTypeAnnImpl {
return IGraphTransformer::TStatus::Repeat;
}
- if (!pos) {
+ if (!pos) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Pos()), errStr));
- return IGraphTransformer::TStatus::Error;
- }
- output = ctx.Expr.Builder(input->Pos())
- .Callable("Member")
+ return IGraphTransformer::TStatus::Error;
+ }
+ output = ctx.Expr.Builder(input->Pos())
+ .Callable("Member")
.Add(0, std::move(rowNode))
- .Atom(1, structType->GetItems()[*pos]->GetName())
- .Seal().Build();
- return IGraphTransformer::TStatus::Repeat;
- }
-
+ .Atom(1, structType->GetItems()[*pos]->GetName())
+ .Seal().Build();
+ return IGraphTransformer::TStatus::Repeat;
+ }
+
IGraphTransformer::TStatus SqlColumnFromTypeWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
Y_UNUSED(output);
if (!EnsureArgsCount(*input, 3, ctx.Expr)) {
@@ -1132,26 +1132,26 @@ namespace NTypeAnnImpl {
}
auto otherType = input->Child(2)->GetTypeAnn();
- const bool isOptional = otherType->GetKind() == ETypeAnnotationKind::Optional;
+ const bool isOptional = otherType->GetKind() == ETypeAnnotationKind::Optional;
auto memberName = input->Child(1)->Content();
const TTypeAnnotationNode* foundFieldType = otherType;
bool fieldFound = false;
for (auto& field : structType->GetItems()) {
if (field->GetName() == memberName) {
fieldFound = true;
- auto fieldType = field->GetItemType();
+ auto fieldType = field->GetItemType();
if (otherType->GetKind() == ETypeAnnotationKind::Null) {
foundFieldType = fieldType;
break;
}
- if (IsSameAnnotation(*otherType, *fieldType) ||
- isOptional && IsSameAnnotation(*otherType, *ctx.Expr.MakeType<TOptionalExprType>(fieldType))) {
- break;
+ if (IsSameAnnotation(*otherType, *fieldType) ||
+ isOptional && IsSameAnnotation(*otherType, *ctx.Expr.MakeType<TOptionalExprType>(fieldType))) {
+ break;
}
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Pos()), TStringBuilder() << "Mismatch member '" << memberName
<< "' type, expected: " << *otherType << ", got: " << *fieldType));
- return IGraphTransformer::TStatus::Error;
+ return IGraphTransformer::TStatus::Error;
}
}
@@ -1260,20 +1260,20 @@ namespace NTypeAnnImpl {
YQL_ENSURE(input->IsCallable({"DivePrefixMembers", "SelectMembers", "FilterMembers", "RemovePrefixMembers"}));
if (!EnsureArgsCount(*input, 2, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto prefixes = input->Child(1);
- if (!EnsureTuple(*prefixes, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
+ if (!EnsureTuple(*prefixes, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
for (auto& node : prefixes->Children()) {
if (!EnsureAtom(*node, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+ }
+
auto descending = [](const TExprNode::TPtr& left, const TExprNode::TPtr& right) {
return left->Content() > right->Content();
};
@@ -1302,98 +1302,98 @@ namespace NTypeAnnImpl {
}
auto structObj = input->Child(0);
- if (!EnsureStructOrOptionalStructType(*structObj, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ if (!EnsureStructOrOptionalStructType(*structObj, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto status = NormalizeAtomListForDiveOrSelect(input, output, ctx);
if (status != IGraphTransformer::TStatus::Ok) {
return status;
}
auto type = structObj->GetTypeAnn();
- const bool optional = type->GetKind() == ETypeAnnotationKind::Optional;
- if (optional) {
- type = type->Cast<TOptionalExprType>()->GetItemType();
- }
+ const bool optional = type->GetKind() == ETypeAnnotationKind::Optional;
+ if (optional) {
+ type = type->Cast<TOptionalExprType>()->GetItemType();
+ }
TVector<const TItemExprType*> allItems;
- auto structExprType = type->Cast<TStructExprType>();
- for (auto& field: structExprType->GetItems()) {
- const auto& fieldName = field->GetName();
+ auto structExprType = type->Cast<TStructExprType>();
+ for (auto& field: structExprType->GetItems()) {
+ const auto& fieldName = field->GetName();
auto prefixes = input->Child(1);
for (const auto& prefixNode: prefixes->Children()) {
const auto& prefix = prefixNode->Content();
if (ByPrefix ? fieldName.StartsWith(prefix) : fieldName == prefix) {
- allItems.push_back(field);
- break;
- }
- }
- }
-
- if (allItems.size() < structExprType->GetSize()) {
+ allItems.push_back(field);
+ break;
+ }
+ }
+ }
+
+ if (allItems.size() < structExprType->GetSize()) {
input->SetTypeAnn(ctx.Expr.MakeType<TStructExprType>(allItems));
- } else {
+ } else {
input->SetTypeAnn(structExprType);
- }
+ }
if (!input->GetTypeAnn()->Cast<TStructExprType>()->Validate(input->Pos(), ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
- return IGraphTransformer::TStatus::Ok;
- }
-
- IGraphTransformer::TStatus DivePrefixMembersWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- if (!EnsureArgsCount(*input, 2, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
- auto structObj = input->Child(0);
- if (!EnsureStructOrOptionalStructType(*structObj, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ return IGraphTransformer::TStatus::Ok;
+ }
+
+ IGraphTransformer::TStatus DivePrefixMembersWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ if (!EnsureArgsCount(*input, 2, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ auto structObj = input->Child(0);
+ if (!EnsureStructOrOptionalStructType(*structObj, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto status = NormalizeAtomListForDiveOrSelect(input, output, ctx);
if (status != IGraphTransformer::TStatus::Ok) {
return status;
}
auto type = structObj->GetTypeAnn();
- const bool optional = type->GetKind() == ETypeAnnotationKind::Optional;
- if (optional) {
- type = type->Cast<TOptionalExprType>()->GetItemType();
- }
+ const bool optional = type->GetKind() == ETypeAnnotationKind::Optional;
+ if (optional) {
+ type = type->Cast<TOptionalExprType>()->GetItemType();
+ }
TVector<const TItemExprType*> allItems;
- auto structExprType = type->Cast<TStructExprType>();
- for (auto& field: structExprType->GetItems()) {
- const auto& fieldName = field->GetName();
+ auto structExprType = type->Cast<TStructExprType>();
+ for (auto& field: structExprType->GetItems()) {
+ const auto& fieldName = field->GetName();
auto prefixes = input->Child(1);
- for (const auto& prefixNode: prefixes->Children()) {
- const auto& prefix = prefixNode->Content();
- if (fieldName.StartsWith(prefix)) {
- auto itemType = field->GetItemType();
- if (optional && itemType->GetKind() != ETypeAnnotationKind::Optional) {
- itemType = ctx.Expr.MakeType<TOptionalExprType>(itemType);
- }
- auto newField = ctx.Expr.MakeType<TItemExprType>(fieldName.substr(prefix.length()), itemType);
- allItems.push_back(newField);
- break;
- }
- }
- }
-
+ for (const auto& prefixNode: prefixes->Children()) {
+ const auto& prefix = prefixNode->Content();
+ if (fieldName.StartsWith(prefix)) {
+ auto itemType = field->GetItemType();
+ if (optional && itemType->GetKind() != ETypeAnnotationKind::Optional) {
+ itemType = ctx.Expr.MakeType<TOptionalExprType>(itemType);
+ }
+ auto newField = ctx.Expr.MakeType<TItemExprType>(fieldName.substr(prefix.length()), itemType);
+ allItems.push_back(newField);
+ break;
+ }
+ }
+ }
+
input->SetTypeAnn(ctx.Expr.MakeType<TStructExprType>(allItems));
if (!input->GetTypeAnn()->Cast<TStructExprType>()->Validate(input->Pos(), ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
- return IGraphTransformer::TStatus::Ok;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ return IGraphTransformer::TStatus::Ok;
+ }
+
IGraphTransformer::TStatus FlattenByColumns(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- Y_UNUSED(output);
+ Y_UNUSED(output);
if (!EnsureMinArgsCount(*input, 2, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
+ return IGraphTransformer::TStatus::Error;
+ }
auto iter = input->Children().begin();
TString mode = "auto";
if ((*iter)->IsAtom()) {
@@ -1410,91 +1410,91 @@ namespace NTypeAnnImpl {
++iter;
}
- auto structObj = *iter;
- if (!EnsureStructOrOptionalStructType(*structObj, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
+ auto structObj = *iter;
+ if (!EnsureStructOrOptionalStructType(*structObj, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
TSet<TString> aliases;
TMap<TString, TString> flattenByColumns;
for (++iter; iter != input->Children().end(); ++iter) {
- const auto& child = *iter;
+ const auto& child = *iter;
TString alias;
- const auto& argType = child->Type();
- if (argType != TExprNode::List && argType != TExprNode::Atom) {
+ const auto& argType = child->Type();
+ if (argType != TExprNode::List && argType != TExprNode::Atom) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(child->Pos()), TStringBuilder() << "Expected atom or tuple, but got: " << argType));
- return IGraphTransformer::TStatus::Error;
- }
+ return IGraphTransformer::TStatus::Error;
+ }
TExprNode* columnNameNode = child.Get();
- if (argType == TExprNode::List) {
- if (!EnsureTupleSize(*child, 2, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- columnNameNode = child->Child(0);
- auto aliasNode = child->Child(1);
- if (!EnsureAtom(*aliasNode, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- alias = aliasNode->Content();
- if (!aliases.emplace(alias).second) {
+ if (argType == TExprNode::List) {
+ if (!EnsureTupleSize(*child, 2, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ columnNameNode = child->Child(0);
+ auto aliasNode = child->Child(1);
+ if (!EnsureAtom(*aliasNode, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ alias = aliasNode->Content();
+ if (!aliases.emplace(alias).second) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(aliasNode->Pos()), TStringBuilder() <<
- "Duplicate flatten alias found: " << alias));
- return IGraphTransformer::TStatus::Error;
- }
+ "Duplicate flatten alias found: " << alias));
+ return IGraphTransformer::TStatus::Error;
+ }
if (flattenByColumns.contains(alias)) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(columnNameNode->Pos()), TStringBuilder() <<
- "Collision between alias and column name: " << alias));
- return IGraphTransformer::TStatus::Error;
- }
- }
- if (!EnsureAtom(*columnNameNode, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- auto columnName = columnNameNode->Content();
+ "Collision between alias and column name: " << alias));
+ return IGraphTransformer::TStatus::Error;
+ }
+ }
+ if (!EnsureAtom(*columnNameNode, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ auto columnName = columnNameNode->Content();
if (!flattenByColumns.emplace(TString(columnName), alias).second) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(columnNameNode->Pos()), TStringBuilder() <<
- "Duplicate flatten field found: " << columnName));
- return IGraphTransformer::TStatus::Error;
- }
+ "Duplicate flatten field found: " << columnName));
+ return IGraphTransformer::TStatus::Error;
+ }
if (aliases.contains(columnName)) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(columnNameNode->Pos()), TStringBuilder() <<
- "Collision between alias and column name: " << columnName));
- return IGraphTransformer::TStatus::Error;
- }
- }
-
+ "Collision between alias and column name: " << columnName));
+ return IGraphTransformer::TStatus::Error;
+ }
+ }
+
auto type = structObj->GetTypeAnn();
- if (type->GetKind() == ETypeAnnotationKind::Optional) {
- type = type->Cast<TOptionalExprType>()->GetItemType();
- }
-
- bool allFieldOptional = true;
+ if (type->GetKind() == ETypeAnnotationKind::Optional) {
+ type = type->Cast<TOptionalExprType>()->GetItemType();
+ }
+
+ bool allFieldOptional = true;
TVector<const TItemExprType*> allItems;
- for (auto& field: type->Cast<TStructExprType>()->GetItems()) {
- const auto& fieldName = field->GetName();
- auto flattenIter = flattenByColumns.find(fieldName);
- if (flattenIter == flattenByColumns.end()) {
+ for (auto& field: type->Cast<TStructExprType>()->GetItems()) {
+ const auto& fieldName = field->GetName();
+ auto flattenIter = flattenByColumns.find(fieldName);
+ if (flattenIter == flattenByColumns.end()) {
if (aliases.contains(fieldName)) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(structObj->Pos()), TStringBuilder() <<
- "Conflict flatten alias and column name: '" << fieldName << "'"));
- return IGraphTransformer::TStatus::Error;
- }
- /// left fields untouched by flatten
- allItems.push_back(field);
- continue;
- }
- const bool isAliasExists = !flattenIter->second.empty();
- if (isAliasExists) {
- /// left original fields if alias exists
- allItems.push_back(field);
- }
- const auto flattenItemName = isAliasExists ? flattenIter->second : fieldName;
- auto fieldType = field->GetItemType();
- const bool fieldOptional = fieldType->GetKind() == ETypeAnnotationKind::Optional;
- if (fieldOptional) {
- fieldType = fieldType->Cast<TOptionalExprType>()->GetItemType();
- } else {
- allFieldOptional = false;
- }
+ "Conflict flatten alias and column name: '" << fieldName << "'"));
+ return IGraphTransformer::TStatus::Error;
+ }
+ /// left fields untouched by flatten
+ allItems.push_back(field);
+ continue;
+ }
+ const bool isAliasExists = !flattenIter->second.empty();
+ if (isAliasExists) {
+ /// left original fields if alias exists
+ allItems.push_back(field);
+ }
+ const auto flattenItemName = isAliasExists ? flattenIter->second : fieldName;
+ auto fieldType = field->GetItemType();
+ const bool fieldOptional = fieldType->GetKind() == ETypeAnnotationKind::Optional;
+ if (fieldOptional) {
+ fieldType = fieldType->Cast<TOptionalExprType>()->GetItemType();
+ } else {
+ allFieldOptional = false;
+ }
if (mode == "optional" && !fieldOptional) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(structObj->Pos()), TStringBuilder() <<
@@ -1533,9 +1533,9 @@ namespace NTypeAnnImpl {
}
}
- const TTypeAnnotationNode* flattenItemType = nullptr;
- if (fieldOptional) {
- flattenItemType = fieldType;
+ const TTypeAnnotationNode* flattenItemType = nullptr;
+ if (fieldOptional) {
+ flattenItemType = fieldType;
if (mode == "list") {
auto listType = fieldType->Cast<TListExprType>();
flattenItemType = listType->GetItemType();
@@ -1547,42 +1547,42 @@ namespace NTypeAnnImpl {
flattenItemType = ctx.Expr.MakeType<TTupleExprType>(TTypeAnnotationNode::TListType({ keyType, payloadType }));
allFieldOptional = false;
}
- } else if (fieldType->GetKind() == ETypeAnnotationKind::List) {
- auto listType = fieldType->Cast<TListExprType>();
- flattenItemType = listType->GetItemType();
- } else if (fieldType->GetKind() == ETypeAnnotationKind::Dict) {
- auto dictType = fieldType->Cast<TDictExprType>();
- const auto keyType = dictType->GetKeyType();
- const auto payloadType = dictType->GetPayloadType();
+ } else if (fieldType->GetKind() == ETypeAnnotationKind::List) {
+ auto listType = fieldType->Cast<TListExprType>();
+ flattenItemType = listType->GetItemType();
+ } else if (fieldType->GetKind() == ETypeAnnotationKind::Dict) {
+ auto dictType = fieldType->Cast<TDictExprType>();
+ const auto keyType = dictType->GetKeyType();
+ const auto payloadType = dictType->GetPayloadType();
flattenItemType = ctx.Expr.MakeType<TTupleExprType>(TTypeAnnotationNode::TListType({keyType, payloadType}));
- } else {
+ } else {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(structObj->Pos()), TStringBuilder() <<
- "Expected list, dict or optional types in field of struct: '" << fieldName <<
- "', but got: " << *field->GetItemType()));
- return IGraphTransformer::TStatus::Error;
- }
-
- allItems.push_back(ctx.Expr.MakeType<TItemExprType>(flattenItemName, flattenItemType));
- flattenByColumns.erase(flattenIter);
- }
- if (!flattenByColumns.empty()) {
+ "Expected list, dict or optional types in field of struct: '" << fieldName <<
+ "', but got: " << *field->GetItemType()));
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ allItems.push_back(ctx.Expr.MakeType<TItemExprType>(flattenItemName, flattenItemType));
+ flattenByColumns.erase(flattenIter);
+ }
+ if (!flattenByColumns.empty()) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(structObj->Pos()), TStringBuilder() <<
"Column for flatten \"" << flattenByColumns.begin()->first << "\" does not exist"));
- return IGraphTransformer::TStatus::Error;
- }
-
- auto resultStruct = ctx.Expr.MakeType<TStructExprType>(allItems);
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ auto resultStruct = ctx.Expr.MakeType<TStructExprType>(allItems);
if (!resultStruct->Validate(input->Pos(), ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- if (allFieldOptional) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ if (allFieldOptional) {
input->SetTypeAnn(ctx.Expr.MakeType<TOptionalExprType>(resultStruct));
- } else {
+ } else {
input->SetTypeAnn(ctx.Expr.MakeType<TListExprType>(resultStruct));
- }
- return IGraphTransformer::TStatus::Ok;
- }
-
+ }
+ return IGraphTransformer::TStatus::Ok;
+ }
+
IGraphTransformer::TStatus NthWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
if (!EnsureArgsCount(*input, 2, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
@@ -4476,7 +4476,7 @@ namespace NTypeAnnImpl {
return IGraphTransformer::TStatus::Error;
}
- if (!EnsureDependsOnTail(*input, ctx.Expr, 0)) {
+ if (!EnsureDependsOnTail(*input, ctx.Expr, 0)) {
return IGraphTransformer::TStatus::Error;
}
@@ -5413,42 +5413,42 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
return IGraphTransformer::TStatus::Ok;
}
- IGraphTransformer::TStatus DictFromKeysWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ IGraphTransformer::TStatus DictFromKeysWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
Y_UNUSED(output);
- if (!EnsureArgsCount(*input, 2, ctx.Expr)) {
+ if (!EnsureArgsCount(*input, 2, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
}
- auto typeNode = input->Child(0);
- auto keysListNode = input->Child(1);
-
+ auto typeNode = input->Child(0);
+ auto keysListNode = input->Child(1);
+
if (auto status = EnsureTypeRewrite(input->HeadRef(), ctx.Expr); status != IGraphTransformer::TStatus::Ok) {
return status;
}
const auto keyType = typeNode->GetTypeAnn()->Cast<TTypeExprType>()->GetType();
if (!EnsureComputableType(typeNode->Pos(), *keyType, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
if (!EnsureTuple(*keysListNode, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
}
TExprNode::TListType newChildren;
IGraphTransformer::TStatus totalStatus = IGraphTransformer::TStatus::Ok;
- for (size_t i = 0; i < keysListNode->ChildrenSize(); ++i) {
+ for (size_t i = 0; i < keysListNode->ChildrenSize(); ++i) {
newChildren.push_back(keysListNode->ChildPtr(i));
auto& childRef = newChildren.back();
auto status = TryConvertTo(childRef, *keyType, ctx.Expr);
totalStatus = totalStatus.Combine(status);
if (status.Level == IGraphTransformer::TStatus::Error) {
return status;
- }
+ }
}
if (totalStatus.Level != IGraphTransformer::TStatus::Ok) {
input->ChildRef(1) = ctx.Expr.ChangeChildren(*keysListNode, std::move(newChildren));
return totalStatus;
- }
+ }
const TDictExprType* dictType = ctx.Expr.MakeType<TDictExprType>(keyType, ctx.Expr.MakeType<TVoidExprType>());
if (!dictType->Validate(input->Pos(), ctx.Expr)) {
@@ -5999,16 +5999,16 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
const auto& param = input->Head();
auto argType = param.GetTypeAnn();
- if (!argType) {
+ if (!argType) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(param.Pos()), TStringBuilder() << "Lambda is unexpected here"));
return IGraphTransformer::TStatus::Error;
}
- auto argKind = argType->GetKind();
+ auto argKind = argType->GetKind();
if (argKind == ETypeAnnotationKind::Type) {
argType = argType->Cast<TTypeExprType>()->GetType();
argKind = argType->GetKind();
- }
+ }
const auto argDataType = argKind == ETypeAnnotationKind::Data ? TMaybe<EDataSlot>(argType->Cast<TDataExprType>()->GetSlot()) : Nothing();
@@ -6580,17 +6580,17 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
}
bool ValidateFileAlias(const TExprNode& aliasNode, TExtContext& ctx) {
- if (!EnsureAtom(aliasNode, ctx.Expr)) {
+ if (!EnsureAtom(aliasNode, ctx.Expr)) {
return false;
}
- const auto content = aliasNode.Content();
+ const auto content = aliasNode.Content();
if (!ctx.Types.UserDataStorage->ContainsUserDataBlock(content)) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(aliasNode.Pos()), TStringBuilder() << "File not found: " << content));
return false;
}
return true;
- }
+ }
bool ValidateFolderAlias(const TExprNode& aliasNode, TExtContext& ctx) {
if (!EnsureAtom(aliasNode, ctx.Expr)) {
@@ -6607,7 +6607,7 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
}
IGraphTransformer::TStatus FilePathWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExtContext& ctx) {
- Y_UNUSED(output);
+ Y_UNUSED(output);
if (!EnsureArgsCount(*input, 1, ctx.Expr) || !ValidateFileAlias(input->Head(), ctx)) {
return IGraphTransformer::TStatus::Error;
}
@@ -7138,7 +7138,7 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
IGraphTransformer::TStatus NamedApplyWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
Y_UNUSED(output);
- if (!EnsureDependsOnTail(*input, ctx.Expr, 3)) {
+ if (!EnsureDependsOnTail(*input, ctx.Expr, 3)) {
return IGraphTransformer::TStatus::Error;
}
@@ -8015,14 +8015,14 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
if (input->Head().Content() == "tuple" || input->Head().Content() == "struct") {
key = ctx.Expr.NewCallable(input->Pos(), "String", { std::move(key) });
} else if (input->Head().Content() == "dict") {
- key = ctx.Expr.Builder(input->Pos())
+ key = ctx.Expr.Builder(input->Pos())
.Callable("SafeCast")
.Add(0, std::move(key))
.Callable(1, "DataType")
.Atom(0, "String", TNodeFlags::Default)
.Seal()
- .Seal().Build();
- } else {
+ .Seal().Build();
+ } else {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Head().Pos()), TStringBuilder() << "Unknown access mode: " << input->Head().Content()));
return IGraphTransformer::TStatus::Error;
}
@@ -10861,15 +10861,15 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
return IGraphTransformer::TStatus::Ok;
}
- IGraphTransformer::TStatus QueueCreateWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- Y_UNUSED(output);
- if (!EnsureDependsOnTail(*input, ctx.Expr, 3)) {
- return IGraphTransformer::TStatus::Error;
- }
+ IGraphTransformer::TStatus QueueCreateWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ Y_UNUSED(output);
+ if (!EnsureDependsOnTail(*input, ctx.Expr, 3)) {
+ return IGraphTransformer::TStatus::Error;
+ }
if (auto status = EnsureTypeRewrite(input->HeadRef(), ctx.Expr); status != IGraphTransformer::TStatus::Ok) {
return status;
}
- auto typeArg = input->Child(0);
+ auto typeArg = input->Child(0);
const auto queueType = typeArg->GetTypeAnn()->Cast<TTypeExprType>()->GetType();
if (!queueType) {
@@ -10881,18 +10881,18 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
return IGraphTransformer::TStatus::Error;
}
- auto& capacityArg = input->ChildRef(1);
- auto& initSizeArg = input->ChildRef(2);
+ auto& capacityArg = input->ChildRef(1);
+ auto& initSizeArg = input->ChildRef(2);
if (!capacityArg->IsCallable("Uint64") && !capacityArg->IsCallable("Void")) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(capacityArg->Pos()), TStringBuilder() << "Queue capacity should be Uint64 literal or Void"));
- return IGraphTransformer::TStatus::Error;
- }
+ return IGraphTransformer::TStatus::Error;
+ }
if (!initSizeArg->IsCallable("Uint64")) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(initSizeArg->Pos()), TStringBuilder() << "Queue initial size should be Uint64 literal"));
return IGraphTransformer::TStatus::Error;
- }
+ }
if (capacityArg->IsCallable("Uint64")) {
auto capacity = FromString<ui64>(capacityArg->Child(0)->Content());
@@ -10905,94 +10905,94 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
input->SetTypeAnn(ctx.Expr.MakeType<TResourceExprType>(TStringBuilder() <<
NKikimr::NMiniKQL::ResourceQueuePrefix << FormatType(queueType)));
- return IGraphTransformer::TStatus::Ok;
- }
-
- bool EnsureQueueResource(const TExprNode* resourceArg, const TTypeAnnotationNode*& elementType, TExtContext& ctx) {
- if (!EnsureResourceType(*resourceArg, ctx.Expr)) {
- return false;
- }
+ return IGraphTransformer::TStatus::Ok;
+ }
+
+ bool EnsureQueueResource(const TExprNode* resourceArg, const TTypeAnnotationNode*& elementType, TExtContext& ctx) {
+ if (!EnsureResourceType(*resourceArg, ctx.Expr)) {
+ return false;
+ }
const auto resourceType = resourceArg->GetTypeAnn()->Cast<TResourceExprType>();
- const auto resourceTag = resourceType->GetTag();
- using NKikimr::NMiniKQL::ResourceQueuePrefix;
+ const auto resourceTag = resourceType->GetTag();
+ using NKikimr::NMiniKQL::ResourceQueuePrefix;
if (!resourceTag.StartsWith(ResourceQueuePrefix)) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(resourceArg->Pos()), "You should use resource from QueueCreate"));
- return false;
- }
- auto typeExpr = ctx.Expr.Builder(resourceArg->Pos()).Callable("ParseType")
+ return false;
+ }
+ auto typeExpr = ctx.Expr.Builder(resourceArg->Pos()).Callable("ParseType")
.Atom(0, TString(resourceTag.data()+ResourceQueuePrefix.size(), resourceTag.size()-ResourceQueuePrefix.size()))
- .Seal().Build();
- auto parseTypeResult = ParseTypeWrapper(typeExpr, typeExpr, ctx);
- if (parseTypeResult == IGraphTransformer::TStatus::Error) {
- return false;
- }
- if (!EnsureType(*typeExpr, ctx.Expr)) {
- return false;
- }
+ .Seal().Build();
+ auto parseTypeResult = ParseTypeWrapper(typeExpr, typeExpr, ctx);
+ if (parseTypeResult == IGraphTransformer::TStatus::Error) {
+ return false;
+ }
+ if (!EnsureType(*typeExpr, ctx.Expr)) {
+ return false;
+ }
elementType = typeExpr->GetTypeAnn()->Cast<TTypeExprType>()->GetType();
- return true;
- }
-
- IGraphTransformer::TStatus QueuePushWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExtContext& ctx) {
- Y_UNUSED(output);
- if (!EnsureArgsCount(*input, 2, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- auto resourceArg = input->Child(0);
- auto& valueArg = input->ChildRef(1);
-
- if (!EnsureComputable(*valueArg, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- const TTypeAnnotationNode* expectedValueType;
- if (!EnsureQueueResource(resourceArg, expectedValueType, ctx)) {
- return IGraphTransformer::TStatus::Error;
- }
- auto convertStatus = TryConvertTo(valueArg, *expectedValueType, ctx.Expr);
- if (convertStatus.Level != IGraphTransformer::TStatus::Ok) {
- return convertStatus;
- }
+ return true;
+ }
+
+ IGraphTransformer::TStatus QueuePushWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExtContext& ctx) {
+ Y_UNUSED(output);
+ if (!EnsureArgsCount(*input, 2, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ auto resourceArg = input->Child(0);
+ auto& valueArg = input->ChildRef(1);
+
+ if (!EnsureComputable(*valueArg, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ const TTypeAnnotationNode* expectedValueType;
+ if (!EnsureQueueResource(resourceArg, expectedValueType, ctx)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ auto convertStatus = TryConvertTo(valueArg, *expectedValueType, ctx.Expr);
+ if (convertStatus.Level != IGraphTransformer::TStatus::Ok) {
+ return convertStatus;
+ }
input->SetTypeAnn(resourceArg->GetTypeAnn());
- return IGraphTransformer::TStatus::Ok;
- }
-
- IGraphTransformer::TStatus QueuePopWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- Y_UNUSED(output);
- if (!EnsureArgsCount(*input, 1, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- auto resourceArg = input->Child(0);
-
- if (!EnsureResourceType(*resourceArg, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Ok;
+ }
+
+ IGraphTransformer::TStatus QueuePopWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ Y_UNUSED(output);
+ if (!EnsureArgsCount(*input, 1, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ auto resourceArg = input->Child(0);
+
+ if (!EnsureResourceType(*resourceArg, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
input->SetTypeAnn(resourceArg->GetTypeAnn());
- return IGraphTransformer::TStatus::Ok;
- }
-
- IGraphTransformer::TStatus QueuePeekWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExtContext& ctx) {
- Y_UNUSED(output);
- if (!EnsureDependsOnTail(*input, ctx.Expr, 2)) {
- return IGraphTransformer::TStatus::Error;
- }
- auto resourceArg = input->Child(0);
- auto& indexArg = input->ChildRef(1);
-
- const TTypeAnnotationNode* expectedValueType;
- if (!EnsureQueueResource(resourceArg, expectedValueType, ctx)) {
- return IGraphTransformer::TStatus::Error;
- }
+ return IGraphTransformer::TStatus::Ok;
+ }
+
+ IGraphTransformer::TStatus QueuePeekWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExtContext& ctx) {
+ Y_UNUSED(output);
+ if (!EnsureDependsOnTail(*input, ctx.Expr, 2)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ auto resourceArg = input->Child(0);
+ auto& indexArg = input->ChildRef(1);
+
+ const TTypeAnnotationNode* expectedValueType;
+ if (!EnsureQueueResource(resourceArg, expectedValueType, ctx)) {
+ return IGraphTransformer::TStatus::Error;
+ }
auto expectedIndexType = ctx.Expr.MakeType<TDataExprType>(EDataSlot::Uint64);
- auto convertStatus = TryConvertTo(indexArg, *expectedIndexType, ctx.Expr);
- if (convertStatus.Level != IGraphTransformer::TStatus::Ok) {
- return convertStatus;
- }
-
+ auto convertStatus = TryConvertTo(indexArg, *expectedIndexType, ctx.Expr);
+ if (convertStatus.Level != IGraphTransformer::TStatus::Ok) {
+ return convertStatus;
+ }
+
input->SetTypeAnn(ctx.Expr.MakeType<TOptionalExprType>(expectedValueType));
- return IGraphTransformer::TStatus::Ok;
- }
-
+ return IGraphTransformer::TStatus::Ok;
+ }
+
IGraphTransformer::TStatus QueueRangeWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExtContext& ctx) {
Y_UNUSED(output);
if (!EnsureDependsOnTail(*input, ctx.Expr, 3)) {
@@ -11019,38 +11019,38 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
return IGraphTransformer::TStatus::Ok;
}
- IGraphTransformer::TStatus PreserveStreamWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExtContext& ctx) {
- Y_UNUSED(output);
+ IGraphTransformer::TStatus PreserveStreamWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExtContext& ctx) {
+ Y_UNUSED(output);
if (!EnsureArgsCount(*input, 3, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- auto streamArg = input->Child(0);
- auto resourceArg = input->Child(1);
- if (!EnsureStreamType(*streamArg, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- const TTypeAnnotationNode* expectedValueType;
- if (!EnsureQueueResource(resourceArg, expectedValueType, ctx)) {
- return IGraphTransformer::TStatus::Error;
- }
+ return IGraphTransformer::TStatus::Error;
+ }
+ auto streamArg = input->Child(0);
+ auto resourceArg = input->Child(1);
+ if (!EnsureStreamType(*streamArg, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ const TTypeAnnotationNode* expectedValueType;
+ if (!EnsureQueueResource(resourceArg, expectedValueType, ctx)) {
+ return IGraphTransformer::TStatus::Error;
+ }
const TTypeAnnotationNode* streamType = streamArg->GetTypeAnn();
- const TTypeAnnotationNode* itemType = streamType->Cast<TStreamExprType>()->GetItemType();
- if (!IsSameAnnotation(*itemType, *expectedValueType)) {
+ const TTypeAnnotationNode* itemType = streamType->Cast<TStreamExprType>()->GetItemType();
+ if (!IsSameAnnotation(*itemType, *expectedValueType)) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Pos()), TStringBuilder() << "mismatch of stream and queue types: "
- << *itemType << " != " << *expectedValueType));
- return IGraphTransformer::TStatus::Error;
- }
-
+ << *itemType << " != " << *expectedValueType));
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto outpaceArg = input->Child(2);
if (!outpaceArg->IsCallable("Uint64")) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(outpaceArg->Pos()), TStringBuilder() << "Outpace arg should be Uint64 literal"));
return IGraphTransformer::TStatus::Error;
- }
-
+ }
+
input->SetTypeAnn(streamType);
- return IGraphTransformer::TStatus::Ok;
- }
-
+ return IGraphTransformer::TStatus::Ok;
+ }
+
IGraphTransformer::TStatus DependsOnWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
Y_UNUSED(output);
if (!EnsureArgsCount(*input, 1, ctx.Expr)) {
@@ -11144,48 +11144,48 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
}
}
- IGraphTransformer::TStatus WeakFieldWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- if (!EnsureMinArgsCount(*input, 3, ctx.Expr) || !EnsureMaxArgsCount(*input, 4, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ IGraphTransformer::TStatus WeakFieldWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ if (!EnsureMinArgsCount(*input, 3, ctx.Expr) || !EnsureMaxArgsCount(*input, 4, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
if (!EnsureStructType(input->Head(), ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
+ return IGraphTransformer::TStatus::Error;
+ }
const TStructExprType* structType = input->Head().GetTypeAnn()->Cast<TStructExprType>();
-
+
auto targetSlot = ExtractDataType(*input->Child(1), ctx.Expr);
if (!targetSlot) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto targetType = NKikimr::NUdf::GetDataTypeInfo(*targetSlot).Name;
auto targetTypeExpr = ctx.Expr.MakeType<TOptionalExprType>(ctx.Expr.MakeType<TDataExprType>(*targetSlot));
- if (!EnsureTupleMinSize(*input->Child(2), 1, ctx.Expr) && !EnsureTupleMaxSize(*input->Child(2), 2, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- for (const auto& child: input->Child(2)->Children()) {
- if (!EnsureAtom(*child, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- }
-
- const bool isDefault = input->ChildrenSize() == 4;
- if (isDefault) {
- auto convertStatus = TryConvertTo(input->ChildRef(3), *targetTypeExpr, ctx.Expr);
- if (convertStatus.Level == IGraphTransformer::TStatus::Error) {
+ if (!EnsureTupleMinSize(*input->Child(2), 1, ctx.Expr) && !EnsureTupleMaxSize(*input->Child(2), 2, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ for (const auto& child: input->Child(2)->Children()) {
+ if (!EnsureAtom(*child, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ }
+
+ const bool isDefault = input->ChildrenSize() == 4;
+ if (isDefault) {
+ auto convertStatus = TryConvertTo(input->ChildRef(3), *targetTypeExpr, ctx.Expr);
+ if (convertStatus.Level == IGraphTransformer::TStatus::Error) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Child(1)->Pos()), TStringBuilder() <<
- "Default value not correspond weak field type: " << targetType));
- return IGraphTransformer::TStatus::Error;
- }
- }
-
- const auto sourceName = input->Child(2)->ChildrenSize() == 2 ? input->Child(2)->Child(1)->Content() : "";
+ "Default value not correspond weak field type: " << targetType));
+ return IGraphTransformer::TStatus::Error;
+ }
+ }
+
+ const auto sourceName = input->Child(2)->ChildrenSize() == 2 ? input->Child(2)->Child(1)->Content() : "";
const auto memberName = input->Child(2)->Head().Content();
- const auto fullMemberName = sourceName ? DotJoin(sourceName, memberName) : TString(memberName);
- const auto otherField = sourceName ? DotJoin(sourceName, "_other") : "_other";
- const auto restField = sourceName ? DotJoin(sourceName, "_rest") : "_rest";
- const TTypeAnnotationNode* fieldType = nullptr;
+ const auto fullMemberName = sourceName ? DotJoin(sourceName, memberName) : TString(memberName);
+ const auto otherField = sourceName ? DotJoin(sourceName, "_other") : "_other";
+ const auto restField = sourceName ? DotJoin(sourceName, "_rest") : "_rest";
+ const TTypeAnnotationNode* fieldType = nullptr;
const TTypeAnnotationNode* otherType = nullptr;
const TTypeAnnotationNode* restType = nullptr;
TExprNode::TPtr otherMember;
@@ -11207,9 +11207,9 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
.Seal().Build();
} else {
otherType = nullptr;
- }
- }
-
+ }
+ }
+
if (!otherMember) {
otherMember = ctx.Expr.NewCallable(input->Pos(), "Null", {});
}
@@ -11305,102 +11305,102 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
}
}
- if (fieldType) {
- if (fieldType->GetKind() == ETypeAnnotationKind::Optional) {
- output = ctx.Expr.Builder(input->Pos())
- .Callable("Coalesce")
- .Callable(0, "Member")
- .Add(0, input->Child(0))
- .Atom(1, fullMemberName)
- .Seal()
- .Callable(1, "TryWeakMemberFromDict")
- .Add(0, otherMember)
- .Add(1, restMember)
- .Atom(2, targetType)
- .Atom(3, memberName)
- .Seal()
- .Seal().Build();
- } else {
- output = ctx.Expr.Builder(input->Pos())
- .Callable("Just")
- .Callable(0, "Member")
- .Add(0, input->Child(0))
- .Atom(1, fullMemberName)
- .Seal()
- .Seal().Build();
- }
+ if (fieldType) {
+ if (fieldType->GetKind() == ETypeAnnotationKind::Optional) {
+ output = ctx.Expr.Builder(input->Pos())
+ .Callable("Coalesce")
+ .Callable(0, "Member")
+ .Add(0, input->Child(0))
+ .Atom(1, fullMemberName)
+ .Seal()
+ .Callable(1, "TryWeakMemberFromDict")
+ .Add(0, otherMember)
+ .Add(1, restMember)
+ .Atom(2, targetType)
+ .Atom(3, memberName)
+ .Seal()
+ .Seal().Build();
+ } else {
+ output = ctx.Expr.Builder(input->Pos())
+ .Callable("Just")
+ .Callable(0, "Member")
+ .Add(0, input->Child(0))
+ .Atom(1, fullMemberName)
+ .Seal()
+ .Seal().Build();
+ }
} else if (otherType || restType) {
- output = ctx.Expr.Builder(input->Pos())
- .Callable("TryWeakMemberFromDict")
+ output = ctx.Expr.Builder(input->Pos())
+ .Callable("TryWeakMemberFromDict")
.Add(0, otherMember)
.Add(1, restMember)
- .Atom(2, targetType)
- .Atom(3, memberName)
- .Seal().Build();
- if (isDefault) {
- output = ctx.Expr.Builder(input->Pos())
- .Callable("Coalesce")
- .Add(0, output)
- .Add(1, input->Child(3))
- .Seal().Build();
- }
- } else {
- if (isDefault) {
- output = input->ChildPtr(3);
- } else {
- output = ctx.Expr.Builder(input->Pos())
- .Callable("Nothing")
- .Callable(0, "OptionalType")
- .Callable(0, "DataType")
- .Atom(0, targetType)
- .Seal()
- .Seal()
- .Seal().Build();
- }
- }
- return IGraphTransformer::TStatus::Repeat;
- }
-
- IGraphTransformer::TStatus TryWeakMemberFromDictWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- Y_UNUSED(output);
- if (!EnsureArgsCount(*input, 4, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
- for (unsigned index = 0; index < 2; ++index) {
- auto& dictNodeRef = input->ChildRef(index);
- const bool isYsonPayload = index > 0;
+ .Atom(2, targetType)
+ .Atom(3, memberName)
+ .Seal().Build();
+ if (isDefault) {
+ output = ctx.Expr.Builder(input->Pos())
+ .Callable("Coalesce")
+ .Add(0, output)
+ .Add(1, input->Child(3))
+ .Seal().Build();
+ }
+ } else {
+ if (isDefault) {
+ output = input->ChildPtr(3);
+ } else {
+ output = ctx.Expr.Builder(input->Pos())
+ .Callable("Nothing")
+ .Callable(0, "OptionalType")
+ .Callable(0, "DataType")
+ .Atom(0, targetType)
+ .Seal()
+ .Seal()
+ .Seal().Build();
+ }
+ }
+ return IGraphTransformer::TStatus::Repeat;
+ }
+
+ IGraphTransformer::TStatus TryWeakMemberFromDictWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ Y_UNUSED(output);
+ if (!EnsureArgsCount(*input, 4, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ for (unsigned index = 0; index < 2; ++index) {
+ auto& dictNodeRef = input->ChildRef(index);
+ const bool isYsonPayload = index > 0;
const EDataSlot payloadStr = isYsonPayload ? EDataSlot::Yson : EDataSlot::String;
- auto expectedType = ctx.Expr.MakeType<TOptionalExprType>(ctx.Expr.MakeType<TDictExprType>(
+ auto expectedType = ctx.Expr.MakeType<TOptionalExprType>(ctx.Expr.MakeType<TDictExprType>(
ctx.Expr.MakeType<TDataExprType>(EDataSlot::String), ctx.Expr.MakeType<TDataExprType>(payloadStr)));
- auto convertStatus = TryConvertTo(dictNodeRef, *expectedType, ctx.Expr);
- if (convertStatus.Level != IGraphTransformer::TStatus::Ok) {
- return convertStatus;
- }
- }
-
- auto targetTypeNode = input->Child(2);
- auto memberNameNode = input->Child(3);
- if (!EnsureAtom(*targetTypeNode, ctx.Expr) || !EnsureAtom(*memberNameNode, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ auto convertStatus = TryConvertTo(dictNodeRef, *expectedType, ctx.Expr);
+ if (convertStatus.Level != IGraphTransformer::TStatus::Ok) {
+ return convertStatus;
+ }
+ }
+
+ auto targetTypeNode = input->Child(2);
+ auto memberNameNode = input->Child(3);
+ if (!EnsureAtom(*targetTypeNode, ctx.Expr) || !EnsureAtom(*memberNameNode, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
if (!NYql::ValidateName(memberNameNode->Pos(), memberNameNode->Content(), "member", ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
- auto targetType = targetTypeNode->Content();
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ auto targetType = targetTypeNode->Content();
auto targetSlot = NKikimr::NUdf::FindDataSlot(targetType);
if (!targetSlot) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(targetTypeNode->Pos()), TStringBuilder() << "Unknown datatype: " << targetType));
- return IGraphTransformer::TStatus::Error;
- }
+ return IGraphTransformer::TStatus::Error;
+ }
auto targetTypeExpr = ctx.Expr.MakeType<TOptionalExprType>(ctx.Expr.MakeType<TDataExprType>(*targetSlot));
-
+
input->SetTypeAnn(targetTypeExpr);
- return IGraphTransformer::TStatus::Ok;
- }
-
+ return IGraphTransformer::TStatus::Ok;
+ }
+
IGraphTransformer::TStatus LambdaArgumentsCountWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
if (!EnsureArgsCount(*input, 1, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
@@ -11420,40 +11420,40 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
return IGraphTransformer::TStatus::Repeat;
}
- IGraphTransformer::TStatus FromYsonSimpleType(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- Y_UNUSED(output);
- if (!EnsureArgsCount(*input, 2, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
- bool isOptional;
- const TDataExprType* sourceType;
+ IGraphTransformer::TStatus FromYsonSimpleType(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ Y_UNUSED(output);
+ if (!EnsureArgsCount(*input, 2, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ bool isOptional;
+ const TDataExprType* sourceType;
if (!EnsureDataOrOptionalOfData(input->Head(), isOptional, sourceType, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto sourceSlot = sourceType->GetSlot();
if (sourceSlot != EDataSlot::String && sourceSlot != EDataSlot::Yson) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Pos()), TStringBuilder() << "Expected string, yson or optional of it"));
- return IGraphTransformer::TStatus::Error;
- }
-
- if (!EnsureAtom(*input->Child(1), ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
- auto targetType = input->Child(1)->Content();
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ if (!EnsureAtom(*input->Child(1), ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ auto targetType = input->Child(1)->Content();
auto targetSlot = NKikimr::NUdf::FindDataSlot(targetType);
if (!targetSlot) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Child(1)->Pos()), TStringBuilder() << "Unknown datatype: " << targetType));
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
input->SetTypeAnn(ctx.Expr.MakeType<TDataExprType>(*targetSlot));
input->SetTypeAnn(ctx.Expr.MakeType<TOptionalExprType>(input->GetTypeAnn()));
- return IGraphTransformer::TStatus::Ok;
- }
-
+ return IGraphTransformer::TStatus::Ok;
+ }
+
IGraphTransformer::TStatus CurrentOperationIdWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExtContext& ctx) {
if (!EnsureArgsCount(*input, 0, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
@@ -12725,7 +12725,7 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
Functions["SkipWhileInclusive"] = &InclusiveFilterWrapper<true>;
Functions["Member"] = &MemberWrapper;
Functions["SingleMember"] = &SingleMemberWrapper;
- Functions["SqlColumn"] = &SqlColumnWrapper;
+ Functions["SqlColumn"] = &SqlColumnWrapper;
Functions["SqlPlainColumn"] = &SqlColumnWrapper;
Functions["SqlColumnOrType"] = &SqlColumnWrapper;
Functions["SqlPlainColumnOrType"] = &SqlColumnWrapper;
@@ -12734,8 +12734,8 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
Functions["FlattenMembers"] = &FlattenMembersWrapper;
Functions["SelectMembers"] = &SelectMembersWrapper<true>;
Functions["FilterMembers"] = &SelectMembersWrapper<false>;
- Functions["DivePrefixMembers"] = &DivePrefixMembersWrapper;
- Functions["FlattenByColumns"] = &FlattenByColumns;
+ Functions["DivePrefixMembers"] = &DivePrefixMembersWrapper;
+ Functions["FlattenByColumns"] = &FlattenByColumns;
Functions["ExtractMembers"] = &ExtractMembersWrapper;
Functions["FlattenStructs"] = &FlattenStructsWrapper;
Functions["<"] = &CompareWrapper<false>;
@@ -12813,8 +12813,8 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
Functions["Likely"] = &BoolOpt1Wrapper;
Functions["Map"] = &MapWrapper;
Functions["OrderedMap"] = &MapWrapper;
- Functions["FoldMap"] = &FoldMapWrapper;
- Functions["Fold1Map"] = &Fold1MapWrapper;
+ Functions["FoldMap"] = &FoldMapWrapper;
+ Functions["Fold1Map"] = &Fold1MapWrapper;
Functions["Chain1Map"] = &Chain1MapWrapper;
Functions["LMap"] = &LMapWrapper;
Functions["OrderedLMap"] = &LMapWrapper;
@@ -12840,7 +12840,7 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
Functions["EmptyIterator"] = &EmptyIteratorWrapper;
Functions["ForwardList"] = &ForwardListWrapper;
Functions["ToStream"] = &ToStreamWrapper;
- Functions["ToSequence"] = &ToSequenceWrapper;
+ Functions["ToSequence"] = &ToSequenceWrapper;
Functions["Collect"] = &CollectWrapper;
Functions["LazyList"] = &LazyListWrapper;
Functions["ListFromRange"] = &ListFromRangeWrapper;
@@ -12950,7 +12950,7 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
Functions["AsDictStrict"] = &AsDictWrapper<true, false>;
Functions["AsSet"] = &AsDictWrapper<false, true>;
Functions["AsSetStrict"] = &AsDictWrapper<true, true>;
- Functions["DictFromKeys"] = &DictFromKeysWrapper;
+ Functions["DictFromKeys"] = &DictFromKeysWrapper;
Functions["If"] = &IfWrapper<false>;
Functions["IfStrict"] = &IfWrapper<true>;
Functions[IfName] = &IfWorldWrapper;
@@ -13023,15 +13023,15 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
Functions["MultiAggregate"] = &MultiAggregateWrapper;
Functions["Aggregate"] = &AggregateWrapper;
Functions["SqlAggregateAll"] = &SqlAggregateAllWrapper;
- Functions["WinOnRows"] = &WinOnRowsWrapper;
- Functions["WinOnRange"] = &WinOnRangeWrapper;
- Functions["WindowTraits"] = &WindowTraitsWrapper;
- Functions["CalcOverWindow"] = &CalcOverWindowWrapper;
+ Functions["WinOnRows"] = &WinOnRowsWrapper;
+ Functions["WinOnRange"] = &WinOnRangeWrapper;
+ Functions["WindowTraits"] = &WindowTraitsWrapper;
+ Functions["CalcOverWindow"] = &CalcOverWindowWrapper;
Functions["CalcOverSessionWindow"] = &CalcOverWindowWrapper;
Functions["CalcOverWindowGroup"] = &CalcOverWindowGroupWrapper;
- Functions["Lag"] = &WinLeadLagWrapper;
- Functions["Lead"] = &WinLeadLagWrapper;
- Functions["RowNumber"] = &WinRowNumberWrapper;
+ Functions["Lag"] = &WinLeadLagWrapper;
+ Functions["Lead"] = &WinLeadLagWrapper;
+ Functions["RowNumber"] = &WinRowNumberWrapper;
Functions["Rank"] = &WinRankWrapper;
Functions["DenseRank"] = &WinRankWrapper;
Functions["Ascending"] = &PresortWrapper;
@@ -13079,13 +13079,13 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
Functions["AutoDemuxList"] = &AutoDemuxListWrapper;
Functions["AggrCountInit"] = &AggrCountInitWrapper;
Functions["AggrCountUpdate"] = &AggrCountUpdateWrapper;
- Functions["QueueCreate"] = &QueueCreateWrapper;
- Functions["QueuePop"] = &QueuePopWrapper;
+ Functions["QueueCreate"] = &QueueCreateWrapper;
+ Functions["QueuePop"] = &QueuePopWrapper;
Functions["DependsOn"] = &DependsOnWrapper;
Functions["Seq"] = &SeqWrapper;
Functions["Parameter"] = &ParameterWrapper;
- Functions["WeakField"] = &WeakFieldWrapper;
- Functions["TryWeakMemberFromDict"] = &TryWeakMemberFromDictWrapper;
+ Functions["WeakField"] = &WeakFieldWrapper;
+ Functions["TryWeakMemberFromDict"] = &TryWeakMemberFromDictWrapper;
Functions["ByteString"] = &ByteStringWrapper;
Functions["Utf8String"] = &Utf8StringWrapper;
Functions["FromYsonSimpleType"] = &FromYsonSimpleType;
@@ -13217,10 +13217,10 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
ExtFunctions["CurrentTzDatetime"] = &CurrentTzWrapper<NKikimr::NUdf::EDataSlot::TzDatetime>;
ExtFunctions["CurrentTzTimestamp"] = &CurrentTzWrapper<NKikimr::NUdf::EDataSlot::TzTimestamp>;
ExtFunctions["CurrentActorId"] = &DataGeneratorWrapper<NKikimr::NUdf::EDataSlot::String>;
- ExtFunctions["QueuePush"] = &QueuePushWrapper; ///< Ext for ParseTypeWrapper compatibility
- ExtFunctions["QueuePeek"] = &QueuePeekWrapper; ///< Ext for ParseTypeWrapper compatibility
+ ExtFunctions["QueuePush"] = &QueuePushWrapper; ///< Ext for ParseTypeWrapper compatibility
+ ExtFunctions["QueuePeek"] = &QueuePeekWrapper; ///< Ext for ParseTypeWrapper compatibility
ExtFunctions["QueueRange"] = &QueueRangeWrapper; ///< Ext for ParseTypeWrapper compatibility
- ExtFunctions["PreserveStream"] = &PreserveStreamWrapper;
+ ExtFunctions["PreserveStream"] = &PreserveStreamWrapper;
ExtFunctions["FilePath"] = &FilePathWrapper;
ExtFunctions["FileContent"] = &FileContentWrapper;
ExtFunctions["FolderPath"] = &FolderPathWrapper;
diff --git a/ydb/library/yql/core/type_ann/type_ann_expr.cpp b/ydb/library/yql/core/type_ann/type_ann_expr.cpp
index ce4e35b779..f67d3b4120 100644
--- a/ydb/library/yql/core/type_ann/type_ann_expr.cpp
+++ b/ydb/library/yql/core/type_ann/type_ann_expr.cpp
@@ -657,7 +657,7 @@ TExprNode::TPtr ParseAndAnnotate(
TTypeAnnotationContext& typeAnnotationContext)
{
TAstParseResult astRes = ParseAst(str);
- exprCtx.IssueManager.AddIssues(astRes.Issues);
+ exprCtx.IssueManager.AddIssues(astRes.Issues);
if (!astRes.IsOk()) {
return nullptr;
}
diff --git a/ydb/library/yql/core/type_ann/type_ann_list.cpp b/ydb/library/yql/core/type_ann/type_ann_list.cpp
index 90585128ed..b145cde389 100644
--- a/ydb/library/yql/core/type_ann/type_ann_list.cpp
+++ b/ydb/library/yql/core/type_ann/type_ann_list.cpp
@@ -7,7 +7,7 @@
#include <ydb/library/yql/core/yql_opt_utils.h>
#include <ydb/library/yql/core/yql_opt_window.h>
#include <ydb/library/yql/core/yql_type_helpers.h>
-
+
#include <util/generic/algorithm.h>
#include <util/string/join.h>
@@ -829,133 +829,133 @@ namespace {
return IGraphTransformer::TStatus::Ok;
}
- IGraphTransformer::TStatus FoldMapWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- if (!EnsureArgsCount(*input, 3, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
+ IGraphTransformer::TStatus FoldMapWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ if (!EnsureArgsCount(*input, 3, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
if (IsEmptyList(input->Head())) {
output = input->HeadPtr();
return IGraphTransformer::TStatus::Repeat;
}
- auto& initState = *input->ChildRef(1);
- auto& lambda = input->ChildRef(2);
-
+ auto& initState = *input->ChildRef(1);
+ auto& lambda = input->ChildRef(2);
+
const TTypeAnnotationNode* itemType = nullptr;
if (!EnsureNewSeqType<false>(input->Head(), ctx.Expr, &itemType)) {
- return IGraphTransformer::TStatus::Error;
- }
-
- if (!EnsureComputable(initState, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
- auto status = ConvertToLambda(lambda, ctx.Expr, 2);
- if (status.Level != IGraphTransformer::TStatus::Ok) {
- return status;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ if (!EnsureComputable(initState, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ auto status = ConvertToLambda(lambda, ctx.Expr, 2);
+ if (status.Level != IGraphTransformer::TStatus::Ok) {
+ return status;
+ }
+
if (!UpdateLambdaAllArgumentsTypes(lambda, {itemType, initState.GetTypeAnn()}, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto lambdaType = lambda->GetTypeAnn();
- if (!lambdaType) {
- return IGraphTransformer::TStatus::Repeat;
- }
- if (!EnsureTupleTypeSize(*lambda, 2, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- if (!EnsureComputableType(lambda->Pos(), *lambdaType, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- if (!lambda->Child(1)->IsList()) {
+ if (!lambdaType) {
+ return IGraphTransformer::TStatus::Repeat;
+ }
+ if (!EnsureTupleTypeSize(*lambda, 2, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ if (!EnsureComputableType(lambda->Pos(), *lambdaType, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ if (!lambda->Child(1)->IsList()) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(lambda->Pos()), TStringBuilder() <<
- "Expected literal tuple as result for update lambda for FoldMap"));
- return IGraphTransformer::TStatus::Error;
- }
- auto tupleExprType = lambdaType->Cast<TTupleExprType>();
- auto updatedListType = tupleExprType->GetItems()[0];
- auto stateType = tupleExprType->GetItems()[1];
+ "Expected literal tuple as result for update lambda for FoldMap"));
+ return IGraphTransformer::TStatus::Error;
+ }
+ auto tupleExprType = lambdaType->Cast<TTupleExprType>();
+ auto updatedListType = tupleExprType->GetItems()[0];
+ auto stateType = tupleExprType->GetItems()[1];
if (!IsSameAnnotation(*initState.GetTypeAnn(), *stateType)) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(lambda->Pos()), TStringBuilder() <<
- "Mismatch of update lambda state and init state type: " <<
+ "Mismatch of update lambda state and init state type: " <<
*stateType << " != " << *initState.GetTypeAnn()));
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
input->SetTypeAnn(MakeSequenceType(input->Head().GetTypeAnn()->GetKind(), *updatedListType, ctx.Expr));
- return IGraphTransformer::TStatus::Ok;
- }
-
- IGraphTransformer::TStatus Fold1MapWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- if (!EnsureArgsCount(*input, 3, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
+ return IGraphTransformer::TStatus::Ok;
+ }
+
+ IGraphTransformer::TStatus Fold1MapWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ if (!EnsureArgsCount(*input, 3, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
if (IsEmptyList(input->Head())) {
output = input->HeadPtr();
return IGraphTransformer::TStatus::Repeat;
}
- auto& initLambda = input->ChildRef(1);
- auto& updateLambda = input->ChildRef(2);
-
+ auto& initLambda = input->ChildRef(1);
+ auto& updateLambda = input->ChildRef(2);
+
const TTypeAnnotationNode* itemType = nullptr;
if (!EnsureNewSeqType<false>(input->Head(), ctx.Expr, &itemType)) {
- return IGraphTransformer::TStatus::Error;
- }
+ return IGraphTransformer::TStatus::Error;
+ }
- auto status = ConvertToLambda(initLambda, ctx.Expr, 1);
+ auto status = ConvertToLambda(initLambda, ctx.Expr, 1);
status = status.Combine(ConvertToLambda(updateLambda, ctx.Expr, 2));
- if (status.Level != IGraphTransformer::TStatus::Ok) {
- return status;
- }
-
- if (!UpdateLambdaAllArgumentsTypes(initLambda, {itemType}, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ if (status.Level != IGraphTransformer::TStatus::Ok) {
+ return status;
+ }
+
+ if (!UpdateLambdaAllArgumentsTypes(initLambda, {itemType}, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto lambdaType = initLambda->GetTypeAnn();
- if (!lambdaType) {
- return IGraphTransformer::TStatus::Repeat;
- }
- if (!EnsureTupleTypeSize(*initLambda, 2, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- if (!initLambda->Child(1)->IsList()) {
+ if (!lambdaType) {
+ return IGraphTransformer::TStatus::Repeat;
+ }
+ if (!EnsureTupleTypeSize(*initLambda, 2, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ if (!initLambda->Child(1)->IsList()) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(initLambda->Pos()), TStringBuilder() <<
- "Expected literal tuple as result for init lambda for Fold1Map"));
- return IGraphTransformer::TStatus::Error;
- }
- auto tupleExprType = lambdaType->Cast<TTupleExprType>();
- auto updatedListType = tupleExprType->GetItems()[0];
- auto stateType = tupleExprType->GetItems()[1];
-
- if (!UpdateLambdaAllArgumentsTypes(updateLambda, {itemType, stateType}, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
+ "Expected literal tuple as result for init lambda for Fold1Map"));
+ return IGraphTransformer::TStatus::Error;
+ }
+ auto tupleExprType = lambdaType->Cast<TTupleExprType>();
+ auto updatedListType = tupleExprType->GetItems()[0];
+ auto stateType = tupleExprType->GetItems()[1];
+
+ if (!UpdateLambdaAllArgumentsTypes(updateLambda, {itemType, stateType}, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
auto updateLambdaType = updateLambda->GetTypeAnn();
- if (!updateLambdaType) {
- return IGraphTransformer::TStatus::Repeat;
- }
- if (!IsSameAnnotation(*lambdaType, *updateLambdaType)) {
+ if (!updateLambdaType) {
+ return IGraphTransformer::TStatus::Repeat;
+ }
+ if (!IsSameAnnotation(*lambdaType, *updateLambdaType)) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(updateLambda->Pos()), TStringBuilder() <<
- "Mismatch of update and init lambda types: " <<
- *updateLambdaType << " != " << *lambdaType));
- return IGraphTransformer::TStatus::Error;
- }
- if (!updateLambda->Child(1)->IsList()) {
+ "Mismatch of update and init lambda types: " <<
+ *updateLambdaType << " != " << *lambdaType));
+ return IGraphTransformer::TStatus::Error;
+ }
+ if (!updateLambda->Child(1)->IsList()) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(updateLambda->Pos()), TStringBuilder() <<
"Expected literal tuple as result for update lambda for Fold1Map"));
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
input->SetTypeAnn(MakeSequenceType(input->Head().GetTypeAnn()->GetKind(), *updatedListType, ctx.Expr));
- return IGraphTransformer::TStatus::Ok;
- }
-
+ return IGraphTransformer::TStatus::Ok;
+ }
+
IGraphTransformer::TStatus Chain1MapWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
if (!EnsureArgsCount(*input, 3, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
@@ -1823,27 +1823,27 @@ namespace {
return IGraphTransformer::TStatus::Ok;
}
- IGraphTransformer::TStatus ToSequenceWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- if (!EnsureArgsCount(*input, 1, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ IGraphTransformer::TStatus ToSequenceWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ if (!EnsureArgsCount(*input, 1, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
if (!EnsureComputable(input->Head(), ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
}
switch (input->Head().GetTypeAnn()->GetKind()) {
- case ETypeAnnotationKind::Stream:
- case ETypeAnnotationKind::List:
- case ETypeAnnotationKind::Optional:
+ case ETypeAnnotationKind::Stream:
+ case ETypeAnnotationKind::List:
+ case ETypeAnnotationKind::Optional:
output = input->HeadPtr();
- return IGraphTransformer::TStatus::Repeat;
- default:
- output = ctx.Expr.RenameNode(*input, "Just");
- return IGraphTransformer::TStatus::Repeat;
- }
- }
-
+ return IGraphTransformer::TStatus::Repeat;
+ default:
+ output = ctx.Expr.RenameNode(*input, "Just");
+ return IGraphTransformer::TStatus::Repeat;
+ }
+ }
+
IGraphTransformer::TStatus LazyListWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
if (!EnsureArgsCount(*input, 1U, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
@@ -2588,12 +2588,12 @@ namespace {
}
IGraphTransformer::TStatus ValidateSortTraits(const TTypeAnnotationNode* itemType, const TExprNode::TPtr& direction, TExprNode::TPtr& lambda, TExprContext& ctx) {
- bool isTuple = false;
- if (!ValidateSortDirections(*direction, ctx, isTuple)) {
- return IGraphTransformer::TStatus::Error;
- }
-
- auto status = ConvertToLambda(lambda, ctx, 1);
+ bool isTuple = false;
+ if (!ValidateSortDirections(*direction, ctx, isTuple)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
+ auto status = ConvertToLambda(lambda, ctx, 1);
if (status.Level != IGraphTransformer::TStatus::Ok) {
return status;
}
@@ -2606,7 +2606,7 @@ namespace {
return IGraphTransformer::TStatus::Repeat;
}
- if (isTuple) {
+ if (isTuple) {
const auto directionTupleSize = direction->GetTypeAnn()->Cast<TTupleExprType>()->GetSize();
if (directionTupleSize == 0 || directionTupleSize >= 2) {
if (lambda->GetTypeAnn()->GetKind() != ETypeAnnotationKind::Tuple) {
@@ -2621,7 +2621,7 @@ namespace {
lambdaTupleSize << " != " << directionTupleSize));
return IGraphTransformer::TStatus::Error;
}
- }
+ }
}
if (!lambda->GetTypeAnn()->IsComparable()) {
@@ -2648,14 +2648,14 @@ namespace {
}
auto status = ValidateSortTraits(itemType, input->Child(1), input->TailRef(), ctx.Expr);
- if (status.Level != IGraphTransformer::TStatus::Ok) {
- return status;
- }
-
+ if (status.Level != IGraphTransformer::TStatus::Ok) {
+ return status;
+ }
+
input->SetTypeAnn(input->Head().GetTypeAnn());
- return IGraphTransformer::TStatus::Ok;
- }
-
+ return IGraphTransformer::TStatus::Ok;
+ }
+
IGraphTransformer::TStatus TopWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
if (!EnsureArgsCount(*input, 4, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
@@ -2747,7 +2747,7 @@ namespace {
}
IGraphTransformer::TStatus SortTraitsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- if (!EnsureArgsCount(*input, 3, ctx.Expr)) {
+ if (!EnsureArgsCount(*input, 3, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
}
if (auto status = EnsureTypeRewrite(input->HeadRef(), ctx.Expr); status != IGraphTransformer::TStatus::Ok) {
@@ -2761,10 +2761,10 @@ namespace {
return IGraphTransformer::TStatus::Repeat;
}
- if (!EnsureListType(listTypeNode.Pos(), listType, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ if (!EnsureListType(listTypeNode.Pos(), listType, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto status = ValidateSortTraits(listType.Cast<TListExprType>()->GetItemType(), input->Child(1), input->TailRef(), ctx.Expr);
if (status.Level != IGraphTransformer::TStatus::Ok) {
return status;
@@ -4907,10 +4907,10 @@ namespace {
return IGraphTransformer::TStatus::Ok;
}
- IGraphTransformer::TStatus WinOnRowsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- if (!EnsureMinArgsCount(*input, 1, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
+ IGraphTransformer::TStatus WinOnRowsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ if (!EnsureMinArgsCount(*input, 1, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
auto frameSettingsNode = input->ChildPtr(0);
if (frameSettingsNode->IsList()) {
@@ -4959,28 +4959,28 @@ namespace {
}
input->SetTypeAnn(ctx.Expr.MakeType<TUnitExprType>());
- return IGraphTransformer::TStatus::Ok;
- }
-
- IGraphTransformer::TStatus WinOnRangeWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- Y_UNUSED(output);
+ return IGraphTransformer::TStatus::Ok;
+ }
+
+ IGraphTransformer::TStatus WinOnRangeWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ Y_UNUSED(output);
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Pos()), "WinOnRange is not supported yet"));
return IGraphTransformer::TStatus::Error;
- }
-
- IGraphTransformer::TStatus WindowTraitsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ }
+
+ IGraphTransformer::TStatus WindowTraitsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
if (!EnsureArgsCount(*input, 6, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- auto& item = input->ChildRef(0);
- auto& lambdaInit = input->ChildRef(1);
- auto& lambdaUpdate = input->ChildRef(2);
- auto& lambdaShift = input->ChildRef(3);
- auto& lambdaCurrent = input->ChildRef(4);
-
+ return IGraphTransformer::TStatus::Error;
+ }
+ auto& item = input->ChildRef(0);
+ auto& lambdaInit = input->ChildRef(1);
+ auto& lambdaUpdate = input->ChildRef(2);
+ auto& lambdaShift = input->ChildRef(3);
+ auto& lambdaCurrent = input->ChildRef(4);
+
if (auto status = EnsureTypeRewrite(item, ctx.Expr); status != IGraphTransformer::TStatus::Ok) {
return status;
- }
+ }
auto itemType = item->GetTypeAnn()->Cast<TTypeExprType>()->GetType();
if (itemType->GetKind() == ETypeAnnotationKind::Unit) {
@@ -4989,72 +4989,72 @@ namespace {
return IGraphTransformer::TStatus::Repeat;
}
- auto status = ConvertToLambda(lambdaInit, ctx.Expr, 1, 2);
- status = status.Combine(ConvertToLambda(lambdaUpdate, ctx.Expr, 2, 3));
- status = status.Combine(ConvertToLambda(lambdaShift, ctx.Expr, 2, 3));
- status = status.Combine(ConvertToLambda(lambdaCurrent, ctx.Expr, 1));
- if (status.Level != IGraphTransformer::TStatus::Ok) {
- return status;
- }
-
- if (!EnsureComputableType(item->Pos(), *itemType, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ auto status = ConvertToLambda(lambdaInit, ctx.Expr, 1, 2);
+ status = status.Combine(ConvertToLambda(lambdaUpdate, ctx.Expr, 2, 3));
+ status = status.Combine(ConvertToLambda(lambdaShift, ctx.Expr, 2, 3));
+ status = status.Combine(ConvertToLambda(lambdaCurrent, ctx.Expr, 1));
+ if (status.Level != IGraphTransformer::TStatus::Ok) {
+ return status;
+ }
+
+ if (!EnsureComputableType(item->Pos(), *itemType, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto ui32Type = ctx.Expr.MakeType<TDataExprType>(EDataSlot::Uint32);
if (lambdaInit->Head().ChildrenSize() == 1U) {
- if (!UpdateLambdaAllArgumentsTypes(lambdaInit, {itemType}, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- } else {
- if (!UpdateLambdaAllArgumentsTypes(lambdaInit, {itemType, ui32Type}, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- }
-
+ if (!UpdateLambdaAllArgumentsTypes(lambdaInit, {itemType}, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ } else {
+ if (!UpdateLambdaAllArgumentsTypes(lambdaInit, {itemType, ui32Type}, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ }
+
if (!lambdaInit->GetTypeAnn()) {
- return IGraphTransformer::TStatus::Repeat;
- }
-
+ return IGraphTransformer::TStatus::Repeat;
+ }
+
auto stateType = lambdaInit->GetTypeAnn();
- if (!EnsureComputableType(lambdaInit->Pos(), *stateType, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ if (!EnsureComputableType(lambdaInit->Pos(), *stateType, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
if (lambdaUpdate->Head().ChildrenSize() == 2U) {
- if (!UpdateLambdaAllArgumentsTypes(lambdaUpdate, {itemType, stateType}, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- } else {
- if (!UpdateLambdaAllArgumentsTypes(lambdaUpdate, {itemType, stateType, ui32Type}, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- }
-
+ if (!UpdateLambdaAllArgumentsTypes(lambdaUpdate, {itemType, stateType}, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ } else {
+ if (!UpdateLambdaAllArgumentsTypes(lambdaUpdate, {itemType, stateType, ui32Type}, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ }
+
if (!lambdaUpdate->GetTypeAnn()) {
- return IGraphTransformer::TStatus::Repeat;
- }
-
+ return IGraphTransformer::TStatus::Repeat;
+ }
+
if (!IsSameAnnotation(*lambdaUpdate->GetTypeAnn(), *stateType)) {
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(lambdaUpdate->Pos()), TStringBuilder() << "Mismatch update lambda result type, expected: "
<< *stateType << ", but got: " << *lambdaUpdate->GetTypeAnn()));
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
if (lambdaShift->Head().ChildrenSize() == 2U) {
- if (!UpdateLambdaAllArgumentsTypes(lambdaShift, {itemType, stateType}, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- } else {
- if (!UpdateLambdaAllArgumentsTypes(lambdaShift, {itemType, stateType, ui32Type}, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- }
-
+ if (!UpdateLambdaAllArgumentsTypes(lambdaShift, {itemType, stateType}, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ } else {
+ if (!UpdateLambdaAllArgumentsTypes(lambdaShift, {itemType, stateType, ui32Type}, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+ }
+
if (!lambdaShift->GetTypeAnn()) {
- return IGraphTransformer::TStatus::Repeat;
- }
-
+ return IGraphTransformer::TStatus::Repeat;
+ }
+
if (lambdaShift->Child(1)->GetTypeAnn()->GetKind() != ETypeAnnotationKind::Void && !IsSameAnnotation(*lambdaShift->GetTypeAnn(), *stateType)) {
bool error = false;
if (stateType->GetKind() == ETypeAnnotationKind::Struct && lambdaShift->GetTypeAnn()->GetKind() == ETypeAnnotationKind::Struct) {
@@ -5085,31 +5085,31 @@ namespace {
<< *stateType << ", but got: " << *lambdaShift->GetTypeAnn()));
return IGraphTransformer::TStatus::Error;
}
- }
-
- if (!UpdateLambdaAllArgumentsTypes(lambdaCurrent, {stateType}, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ }
+
+ if (!UpdateLambdaAllArgumentsTypes(lambdaCurrent, {stateType}, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
if (!lambdaCurrent->GetTypeAnn()) {
- return IGraphTransformer::TStatus::Repeat;
- }
-
+ return IGraphTransformer::TStatus::Repeat;
+ }
+
auto currentType = lambdaCurrent->GetTypeAnn();
- if (!EnsureComputableType(lambdaCurrent->Pos(), *currentType, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ if (!EnsureComputableType(lambdaCurrent->Pos(), *currentType, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
status = ValidateTraitsDefaultValue(input, 5, *currentType, "current", output, ctx);
if (status != IGraphTransformer::TStatus::Ok) {
return status;
}
input->SetTypeAnn(ctx.Expr.MakeType<TUnitExprType>());
- return IGraphTransformer::TStatus::Ok;
- }
-
- IGraphTransformer::TStatus CalcOverWindowWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ return IGraphTransformer::TStatus::Ok;
+ }
+
+ IGraphTransformer::TStatus CalcOverWindowWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
const bool isSession = input->IsCallable("CalcOverSessionWindow");
if (isSession && input->ChildrenSize() == 5) {
auto children = input->ChildrenList();
@@ -5118,23 +5118,23 @@ namespace {
return IGraphTransformer::TStatus::Repeat;
}
if (!EnsureArgsCount(*input, isSession ? 6 : 4, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
if (IsEmptyList(input->Head())) {
output = input->HeadPtr();
return IGraphTransformer::TStatus::Repeat;
}
if (!EnsureListType(input->Head(), ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto inputListType = input->Head().GetTypeAnn()->Cast<TListExprType>()->GetItemType();
if (!EnsureStructType(input->Head().Pos(), *inputListType, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto status = NormalizeTupleOfAtoms(input, 1, output, ctx.Expr);
if (isSession) {
status = status.Combine(NormalizeTupleOfAtoms(input, 5, output, ctx.Expr, /*deduplicate=*/false));
@@ -5144,7 +5144,7 @@ namespace {
return status;
}
- auto inputStructType = inputListType->Cast<TStructExprType>();
+ auto inputStructType = inputListType->Cast<TStructExprType>();
TVector<const TItemExprType*> outputColumns = inputStructType->GetItems();
status = ValidateCalcOverWindowArgs(outputColumns, *inputStructType, *input->Child(1), *input->Child(2), *input->Child(3),
@@ -5156,32 +5156,32 @@ namespace {
auto rowType = ctx.Expr.MakeType<TStructExprType>(outputColumns);
if (!rowType->Validate(input->Pos(), ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
input->SetTypeAnn(ctx.Expr.MakeType<TListExprType>(rowType));
return IGraphTransformer::TStatus::Ok;
}
-
+
IGraphTransformer::TStatus CalcOverWindowGroupWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
Y_UNUSED(output);
if (!EnsureArgsCount(*input, 2, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
}
-
+
if (!EnsureListType(input->Head(), ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
- }
-
+ }
+
auto inputListType = input->Head().GetTypeAnn()->Cast<TListExprType>()->GetItemType();
if (!EnsureStructType(input->Head().Pos(), *inputListType, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto& calcs = input->ChildRef(1);
if (!EnsureTuple(*calcs, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
+ return IGraphTransformer::TStatus::Error;
+ }
IGraphTransformer::TStatus status = IGraphTransformer::TStatus::Ok;
TExprNodeList calcsList = calcs->ChildrenList();
@@ -5227,29 +5227,29 @@ namespace {
if (status != IGraphTransformer::TStatus::Ok) {
return status;
- }
- }
-
+ }
+ }
+
auto rowType = ctx.Expr.MakeType<TStructExprType>(outputColumns);
- if (!rowType->Validate(input->Pos(), ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ if (!rowType->Validate(input->Pos(), ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
+
input->SetTypeAnn(ctx.Expr.MakeType<TListExprType>(rowType));
- return IGraphTransformer::TStatus::Ok;
- }
-
- IGraphTransformer::TStatus WinLeadLagWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ return IGraphTransformer::TStatus::Ok;
+ }
+
+ IGraphTransformer::TStatus WinLeadLagWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
if (!EnsureMinArgsCount(*input, 2, ctx.Expr) || !EnsureMaxArgsCount(*input, 3, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- const auto argCount = input->ChildrenSize();
- auto& lambdaValue = input->ChildRef(1);
+ return IGraphTransformer::TStatus::Error;
+ }
+ const auto argCount = input->ChildrenSize();
+ auto& lambdaValue = input->ChildRef(1);
auto winOffsetType = ctx.Expr.MakeType<TDataExprType>(EDataSlot::Int64);
-
+
if (auto status = EnsureTypeRewrite(input->HeadRef(), ctx.Expr); status != IGraphTransformer::TStatus::Ok) {
return status;
- }
+ }
auto rowListType = input->Head().GetTypeAnn()->Cast<TTypeExprType>()->GetType();
if (rowListType->GetKind() == ETypeAnnotationKind::EmptyList) {
output = ctx.Expr.NewCallable(input->Pos(), "Void", {});
@@ -5257,43 +5257,43 @@ namespace {
}
if (!EnsureListType(input->Head().Pos(), *rowListType, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
- auto rowType = rowListType->Cast<TListExprType>()->GetItemType();
+ return IGraphTransformer::TStatus::Error;
+ }
+ auto rowType = rowListType->Cast<TListExprType>()->GetItemType();
if (!EnsureStructType(input->Head().Pos(), *rowType, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
-
+ return IGraphTransformer::TStatus::Error;
+ }
+
auto status = ConvertToLambda(lambdaValue, ctx.Expr, 1);
- if (argCount > 2) {
+ if (argCount > 2) {
status = status.Combine(TryConvertTo(input->ChildRef(2), *winOffsetType, ctx.Expr));
- }
- if (status.Level != IGraphTransformer::TStatus::Ok) {
- return status;
- }
- if (!UpdateLambdaAllArgumentsTypes(lambdaValue, {rowType}, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
+ }
+ if (status.Level != IGraphTransformer::TStatus::Ok) {
+ return status;
+ }
+ if (!UpdateLambdaAllArgumentsTypes(lambdaValue, {rowType}, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
if (!lambdaValue->GetTypeAnn()) {
- return IGraphTransformer::TStatus::Repeat;
- }
+ return IGraphTransformer::TStatus::Repeat;
+ }
const bool isOptional = lambdaValue->GetTypeAnn()->IsOptionalOrNull();
input->SetTypeAnn(isOptional ? lambdaValue->GetTypeAnn() : ctx.Expr.MakeType<TOptionalExprType>(lambdaValue->GetTypeAnn()));
- return IGraphTransformer::TStatus::Ok;
- }
-
- IGraphTransformer::TStatus WinRowNumberWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- Y_UNUSED(output);
- if (!EnsureArgsCount(*input, 1, ctx.Expr)) {
- return IGraphTransformer::TStatus::Error;
- }
+ return IGraphTransformer::TStatus::Ok;
+ }
+
+ IGraphTransformer::TStatus WinRowNumberWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
+ Y_UNUSED(output);
+ if (!EnsureArgsCount(*input, 1, ctx.Expr)) {
+ return IGraphTransformer::TStatus::Error;
+ }
if (auto status = EnsureTypeRewrite(input->HeadRef(), ctx.Expr); status != IGraphTransformer::TStatus::Ok) {
return status;
- }
+ }
input->SetTypeAnn(ctx.Expr.MakeType<TDataExprType>(EDataSlot::Uint64));
- return IGraphTransformer::TStatus::Ok;
- }
-
+ return IGraphTransformer::TStatus::Ok;
+ }
+
IGraphTransformer::TStatus WinRankWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
if (!EnsureArgsCount(*input, 3, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
diff --git a/ydb/library/yql/core/type_ann/type_ann_list.h b/ydb/library/yql/core/type_ann/type_ann_list.h
index afe13fd60f..608b813fe8 100644
--- a/ydb/library/yql/core/type_ann/type_ann_list.h
+++ b/ydb/library/yql/core/type_ann/type_ann_list.h
@@ -35,8 +35,8 @@ namespace NTypeAnnImpl {
IGraphTransformer::TStatus ListSortWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus ListExtractWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus ListCollectWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
- IGraphTransformer::TStatus FoldMapWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
- IGraphTransformer::TStatus Fold1MapWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
+ IGraphTransformer::TStatus FoldMapWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
+ IGraphTransformer::TStatus Fold1MapWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus Chain1MapWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus PrependWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus AppendWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
@@ -45,7 +45,7 @@ namespace NTypeAnnImpl {
IGraphTransformer::TStatus EmptyIteratorWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus ForwardListWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus ToStreamWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
- IGraphTransformer::TStatus ToSequenceWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
+ IGraphTransformer::TStatus ToSequenceWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus LazyListWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus CollectWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus ListFromRangeWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
@@ -96,13 +96,13 @@ namespace NTypeAnnImpl {
IGraphTransformer::TStatus SkipNullMembersWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus FilterNullElementsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus SkipNullElementsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
- IGraphTransformer::TStatus WinOnRowsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
- IGraphTransformer::TStatus WinOnRangeWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
- IGraphTransformer::TStatus WindowTraitsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
- IGraphTransformer::TStatus CalcOverWindowWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
+ IGraphTransformer::TStatus WinOnRowsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
+ IGraphTransformer::TStatus WinOnRangeWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
+ IGraphTransformer::TStatus WindowTraitsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
+ IGraphTransformer::TStatus CalcOverWindowWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus CalcOverWindowGroupWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
- IGraphTransformer::TStatus WinLeadLagWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
- IGraphTransformer::TStatus WinRowNumberWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
+ IGraphTransformer::TStatus WinLeadLagWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
+ IGraphTransformer::TStatus WinRowNumberWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus WinRankWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus HoppingCoreWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus MultiHoppingCoreWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
diff --git a/ydb/library/yql/core/ya.make b/ydb/library/yql/core/ya.make
index ae6ff3b396..29169996f5 100644
--- a/ydb/library/yql/core/ya.make
+++ b/ydb/library/yql/core/ya.make
@@ -80,12 +80,12 @@ PEERDIR(
ydb/library/yql/providers/common/proto
)
-GENERATE_ENUM_SERIALIZATION(yql_data_provider.h)
+GENERATE_ENUM_SERIALIZATION(yql_data_provider.h)
GENERATE_ENUM_SERIALIZATION(yql_user_data.h)
GENERATE_ENUM_SERIALIZATION(yql_atom_enums.h)
-
+
YQL_LAST_ABI_VERSION()
END()
diff --git a/ydb/library/yql/core/yql_execution.cpp b/ydb/library/yql/core/yql_execution.cpp
index 6d20bb1da6..eb138b1b4f 100644
--- a/ydb/library/yql/core/yql_execution.cpp
+++ b/ydb/library/yql/core/yql_execution.cpp
@@ -811,9 +811,9 @@ TAutoPtr<IGraphTransformer> CreateCheckExecutionTransformer(const TTypeAnnotatio
hasErrors = true;
}
} else if (collectCalcOverWindow && node->IsCallable({"CalcOverWindow", "CalcOverSessionWindow", "CalcOverWindowGroup"})) {
- overWinNodes.emplace(node.Get());
- return false;
- } else if (node->IsCallable(notAllowList)) {
+ overWinNodes.emplace(node.Get());
+ return false;
+ } else if (node->IsCallable(notAllowList)) {
hasErrors = true;
const auto err = TIssue(ctx.GetPosition(node->Pos()), TStringBuilder() << "Can't execute " << node->Content());
if (added.insert(err).second) {
@@ -847,19 +847,19 @@ TAutoPtr<IGraphTransformer> CreateCheckExecutionTransformer(const TTypeAnnotatio
}
return true;
- };
+ };
static const THashSet<TStringBuf> noExecutionList = {"InstanceOf", "Lag", "Lead", "Rank", "DenseRank", "RowNumber"};
static const THashSet<TStringBuf> noExecutionListForCalcOverWindow = {"InstanceOf"};
- VisitExpr(input, [funcCheckExecution](const TExprNode::TPtr& node) {
+ VisitExpr(input, [funcCheckExecution](const TExprNode::TPtr& node) {
bool collectCalcOverWindow = true;
return funcCheckExecution(noExecutionList, collectCalcOverWindow, node);
});
- for (auto overWin: overWinNodes) {
- VisitExpr(overWin, [funcCheckExecution](const TExprNode::TPtr& node) {
+ for (auto overWin: overWinNodes) {
+ VisitExpr(overWin, [funcCheckExecution](const TExprNode::TPtr& node) {
bool collectCalcOverWindow = false;
return funcCheckExecution(noExecutionListForCalcOverWindow, collectCalcOverWindow, node);
- });
- }
+ });
+ }
return hasErrors ? IGraphTransformer::TStatus::Error : IGraphTransformer::TStatus::Ok;
});
diff --git a/ydb/library/yql/core/yql_expr_type_annotation.cpp b/ydb/library/yql/core/yql_expr_type_annotation.cpp
index 47f10ccefa..f2b793af8d 100644
--- a/ydb/library/yql/core/yql_expr_type_annotation.cpp
+++ b/ydb/library/yql/core/yql_expr_type_annotation.cpp
@@ -2732,15 +2732,15 @@ bool EnsureTaggedType(const TExprNode& node, TExprContext& ctx) {
bool EnsureOneOrTupleOfDataOrOptionalOfData(const TExprNode& node, TExprContext& ctx) {
if (HasError(node.GetTypeAnn(), ctx) || !node.GetTypeAnn()) {
- YQL_ENSURE(node.Type() == TExprNode::Lambda);
+ YQL_ENSURE(node.Type() == TExprNode::Lambda);
ctx.AddError(TIssue(ctx.GetPosition(node.Pos()), TStringBuilder() <<
- "Expected either data (optional of data) or non-empty tuple of data (optional of data), but got lambda"));
+ "Expected either data (optional of data) or non-empty tuple of data (optional of data), but got lambda"));
return false;
}
return EnsureOneOrTupleOfDataOrOptionalOfData(node.Pos(), *node.GetTypeAnn(), ctx);
-}
-
+}
+
bool EnsureOneOrTupleOfDataOrOptionalOfData(TPositionHandle position, const TTypeAnnotationNode& type, TExprContext& ctx) {
bool ok = false;
bool isOptional = false;
@@ -2748,8 +2748,8 @@ bool EnsureOneOrTupleOfDataOrOptionalOfData(TPositionHandle position, const TTyp
TIssue err;
bool hasErrorType = false;
TPosition pos = ctx.GetPosition(position);
- if (type.GetKind() == ETypeAnnotationKind::Tuple) {
- for (auto& child: type.Cast<TTupleExprType>()->GetItems()) {
+ if (type.GetKind() == ETypeAnnotationKind::Tuple) {
+ for (auto& child: type.Cast<TTupleExprType>()->GetItems()) {
ok = IsDataOrOptionalOfData(pos, child, isOptional, dataType, err, hasErrorType);
if (!ok) {
break;
@@ -3274,18 +3274,18 @@ bool EnsureDependsOn(const TExprNode& node, TExprContext& ctx) {
return true;
}
-bool EnsureDependsOnTail(const TExprNode& node, TExprContext& ctx, unsigned requiredArgumentCount, unsigned requiredDependsOnCount) {
- if (!EnsureMinArgsCount(node, requiredArgumentCount+requiredDependsOnCount, ctx)) {
+bool EnsureDependsOnTail(const TExprNode& node, TExprContext& ctx, unsigned requiredArgumentCount, unsigned requiredDependsOnCount) {
+ if (!EnsureMinArgsCount(node, requiredArgumentCount+requiredDependsOnCount, ctx)) {
return false;
- }
- for (unsigned i = requiredArgumentCount; i < node.ChildrenSize(); ++i) {
- if (!EnsureDependsOn(*node.Child(i), ctx)) {
- return false;
- }
- }
- return true;
-}
-
+ }
+ for (unsigned i = requiredArgumentCount; i < node.ChildrenSize(); ++i) {
+ if (!EnsureDependsOn(*node.Child(i), ctx)) {
+ return false;
+ }
+ }
+ return true;
+}
+
const TTypeAnnotationNode* MakeTypeHandleResourceType(TExprContext& ctx) {
return ctx.MakeType<TResourceExprType>(TypeResourceTag);
}
diff --git a/ydb/library/yql/core/yql_expr_type_annotation.h b/ydb/library/yql/core/yql_expr_type_annotation.h
index e7b94e1d8e..a865aa27cd 100644
--- a/ydb/library/yql/core/yql_expr_type_annotation.h
+++ b/ydb/library/yql/core/yql_expr_type_annotation.h
@@ -154,7 +154,7 @@ bool EnsureNewSeqType(const TExprNode& node, TExprContext& ctx, const TTypeAnnot
template <bool WithOptional, bool WithList = true, bool WithStream = true>
bool EnsureNewSeqType(TPositionHandle position, const TTypeAnnotationNode& type, TExprContext& ctx, const TTypeAnnotationNode** itemType = nullptr);
bool EnsureDependsOn(const TExprNode& node, TExprContext& ctx);
-bool EnsureDependsOnTail(const TExprNode& node, TExprContext& ctx, unsigned requiredArgumentCount, unsigned requiredDependsOnCount = 0);
+bool EnsureDependsOnTail(const TExprNode& node, TExprContext& ctx, unsigned requiredArgumentCount, unsigned requiredDependsOnCount = 0);
const TTypeAnnotationNode* MakeTypeHandleResourceType(TExprContext& ctx);
bool EnsureTypeHandleResourceType(const TExprNode& node, TExprContext& ctx);
diff --git a/ydb/library/yql/core/yql_graph_transformer.cpp b/ydb/library/yql/core/yql_graph_transformer.cpp
index c2ac74c2a6..26193c4c40 100644
--- a/ydb/library/yql/core/yql_graph_transformer.cpp
+++ b/ydb/library/yql/core/yql_graph_transformer.cpp
@@ -361,8 +361,8 @@ NThreading::TFuture<IGraphTransformer::TStatus> AsyncTransform(IGraphTransformer
}
if (ctx.RepeatTransformCounter >= ctx.RepeatTransformLimit) {
AddTooManyTransformationsError(root->Pos(), "AsyncTransform", ctx);
- return NThreading::MakeFuture(IGraphTransformer::TStatus(IGraphTransformer::TStatus::Error));
- }
+ return NThreading::MakeFuture(IGraphTransformer::TStatus(IGraphTransformer::TStatus::Error));
+ }
}
catch (const std::exception& e) {
ctx.AddError(ExceptionToIssue(e));
diff --git a/ydb/library/yql/core/yql_library_compiler.cpp b/ydb/library/yql/core/yql_library_compiler.cpp
index 69c526e0d0..79296792e6 100644
--- a/ydb/library/yql/core/yql_library_compiler.cpp
+++ b/ydb/library/yql/core/yql_library_compiler.cpp
@@ -91,7 +91,7 @@ bool CompileLibrary(const TString& alias, const TString& script, TExprContext& c
{
const auto& res = ParseAst(script, nullptr, alias);
if (!res.IsOk()) {
- for (const auto& originalError : res.Issues) {
+ for (const auto& originalError : res.Issues) {
TIssue error(originalError);
TStringBuilder message;
message << error.Message << " (at " << alias << ")";
diff --git a/ydb/library/yql/core/yql_opt_utils.cpp b/ydb/library/yql/core/yql_opt_utils.cpp
index 8426f93592..69aa84a500 100644
--- a/ydb/library/yql/core/yql_opt_utils.cpp
+++ b/ydb/library/yql/core/yql_opt_utils.cpp
@@ -142,12 +142,12 @@ bool IsPassthroughLambda(const TCoLambda& lambda, TMaybe<THashSet<TStringBuf>>*
for (auto child : maybeStruct.Cast()) {
auto tuple = child.Cast<TCoNameValueTuple>();
- auto value = tuple.Value();
+ auto value = tuple.Value();
if (analyzeJustMember && value.Maybe<TCoJust>()) {
- value = value.Cast<TCoJust>().Input();
- }
+ value = value.Cast<TCoJust>().Input();
+ }
- if (!value.Maybe<TCoMember>()) {
+ if (!value.Maybe<TCoMember>()) {
if (!passthroughFields) {
return false;
}
@@ -155,7 +155,7 @@ bool IsPassthroughLambda(const TCoLambda& lambda, TMaybe<THashSet<TStringBuf>>*
continue;
}
- auto member = value.Cast<TCoMember>();
+ auto member = value.Cast<TCoMember>();
if (member.Struct().Raw() != arg.Raw() || member.Name().Value() != tuple.Name().Value()) {
if (!passthroughFields) {
return false;
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_addmember.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_addmember.cpp
index 73101d3eb3..12b0eac013 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_addmember.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_addmember.cpp
@@ -11,18 +11,18 @@ namespace {
class TAddMemberWrapper : public TMutableCodegeneratorFallbackNode<TAddMemberWrapper> {
typedef TMutableCodegeneratorFallbackNode<TAddMemberWrapper> TBaseComputation;
public:
- TAddMemberWrapper(TComputationMutables& mutables, IComputationNode* structObj, IComputationNode* member, ui32 index,
+ TAddMemberWrapper(TComputationMutables& mutables, IComputationNode* structObj, IComputationNode* member, ui32 index,
std::vector<EValueRepresentation>&& representations)
: TBaseComputation(mutables, EValueRepresentation::Boxed)
- , StructObj(structObj)
+ , StructObj(structObj)
, Member(member)
, Index(index)
, Representations(std::move(representations))
- , Cache(mutables)
+ , Cache(mutables)
{}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- const auto& baseStruct = StructObj->GetValue(ctx);
+ const auto& baseStruct = StructObj->GetValue(ctx);
NUdf::TUnboxedValue* itemsPtr = nullptr;
const auto result = Cache.NewArray(ctx, Representations.size() + 1U, itemsPtr);
@@ -31,7 +31,7 @@ public:
*itemsPtr++ = ptr[i];
}
- *itemsPtr++ = Member->GetValue(ctx);
+ *itemsPtr++ = Member->GetValue(ctx);
for (ui32 i = Index; i < Representations.size(); ++i) {
*itemsPtr++ = ptr[i];
@@ -41,7 +41,7 @@ public:
*itemsPtr++ = baseStruct.GetElement(i);
}
- *itemsPtr++ = Member->GetValue(ctx);
+ *itemsPtr++ = Member->GetValue(ctx);
for (ui32 i = Index; i < Representations.size(); ++i) {
*itemsPtr++ = baseStruct.GetElement(i);
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_aggrcount.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_aggrcount.cpp
index 535c10056e..2c934a95d4 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_aggrcount.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_aggrcount.cpp
@@ -57,9 +57,9 @@ public:
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
- auto state = State->GetValue(compCtx);
- return Arg->GetValue(compCtx) ? NUdf::TUnboxedValuePod(state.Get<ui64>() + 1U) : state.Release();
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
+ auto state = State->GetValue(compCtx);
+ return Arg->GetValue(compCtx) ? NUdf::TUnboxedValuePod(state.Get<ui64>() + 1U) : state.Release();
}
#ifndef MKQL_DISABLE_CODEGEN
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_append.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_append.cpp
index 163c9d0955..703b82141b 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_append.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_append.cpp
@@ -12,16 +12,16 @@ template<bool IsVoid>
class TAppendWrapper : public TMutableCodegeneratorNode<TAppendWrapper<IsVoid>> {
typedef TMutableCodegeneratorNode<TAppendWrapper<IsVoid>> TBaseComputation;
public:
- TAppendWrapper(TComputationMutables& mutables, IComputationNode* left, IComputationNode* right)
+ TAppendWrapper(TComputationMutables& mutables, IComputationNode* left, IComputationNode* right)
: TBaseComputation(mutables, left->GetRepresentation())
- , Left(left)
+ , Left(left)
, Right(right)
{
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
auto left = Left->GetValue(ctx);
- auto right = Right->GetValue(ctx);
+ auto right = Right->GetValue(ctx);
if (IsVoid && !right.IsBoxed())
return left.Release();
@@ -117,9 +117,9 @@ IComputationNode* WrapAppend(TCallable& callable, const TComputationNodeFactoryC
const auto left = LocateNode(ctx.NodeLocator, callable, 0);
const auto right = LocateNode(ctx.NodeLocator, callable, 1);
if (rightType->IsVoid())
- return new TAppendWrapper<true>(ctx.Mutables, left, right);
+ return new TAppendWrapper<true>(ctx.Mutables, left, right);
else
- return new TAppendWrapper<false>(ctx.Mutables, left, right);
+ return new TAppendWrapper<false>(ctx.Mutables, left, right);
}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_apply.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_apply.cpp
index 035cb66d90..a613c9dcd9 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_apply.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_apply.cpp
@@ -16,7 +16,7 @@ public:
TApplyWrapper(TComputationMutables& mutables, EValueRepresentation kind, IComputationNode* callableNode,
TComputationNodePtrVector&& argNodes, ui32 usedArgs, const NUdf::TSourcePosition& pos)
: TBaseComputation(mutables, kind)
- , CallableNode(callableNode)
+ , CallableNode(callableNode)
, ArgNodes(std::move(argNodes))
, UsedArgs(usedArgs)
, Position(pos)
@@ -25,10 +25,10 @@ public:
}
NUdf::TUnboxedValue DoCalculate(TComputationContext& ctx) const {
- NStackArray::TStackArray<NUdf::TUnboxedValue> values(ALLOC_ON_STACK(NUdf::TUnboxedValue, UsedArgs));
+ NStackArray::TStackArray<NUdf::TUnboxedValue> values(ALLOC_ON_STACK(NUdf::TUnboxedValue, UsedArgs));
for (size_t i = 0; i < UsedArgs; ++i) {
if (const auto valueNode = ArgNodes[i]) {
- values[i] = valueNode->GetValue(ctx);
+ values[i] = valueNode->GetValue(ctx);
}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_callable.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_callable.cpp
index 29ab563b30..06010bd4e5 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_callable.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_callable.cpp
@@ -13,10 +13,10 @@ class TCallableWrapper : public TCustomValueCodegeneratorNode<TCallableWrapper>
private:
class TValue : public TComputationValue<TValue> {
public:
- TValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, IComputationNode* resultNode,
+ TValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, IComputationNode* resultNode,
const TComputationExternalNodePtrVector& argNodes)
: TComputationValue(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, ResultNode(resultNode)
, ArgNodes(argNodes)
{}
@@ -25,13 +25,13 @@ private:
NUdf::TUnboxedValue Run(const NUdf::IValueBuilder*, const NUdf::TUnboxedValuePod* args) const override
{
for (const auto node : ArgNodes) {
- node->SetValue(CompCtx, NUdf::TUnboxedValuePod(*args++));
+ node->SetValue(CompCtx, NUdf::TUnboxedValuePod(*args++));
}
- return ResultNode->GetValue(CompCtx);
+ return ResultNode->GetValue(CompCtx);
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
IComputationNode *const ResultNode;
const TComputationExternalNodePtrVector ArgNodes;
};
@@ -58,8 +58,8 @@ private:
};
public:
TCallableWrapper(TComputationMutables& mutables, IComputationNode* resultNode, TComputationExternalNodePtrVector&& argNodes)
- : TBaseComputation(mutables)
- , ResultNode(resultNode)
+ : TBaseComputation(mutables)
+ , ResultNode(resultNode)
, ArgNodes(std::move(argNodes))
{
}
@@ -69,7 +69,7 @@ public:
if (ctx.ExecuteLLVM && Run)
return ctx.HolderFactory.Create<TCodegenValue>(Run, &ctx);
#endif
- return ctx.HolderFactory.Create<TValue>(ctx, ResultNode, ArgNodes);
+ return ctx.HolderFactory.Create<TValue>(ctx, ResultNode, ArgNodes);
}
private:
@@ -174,7 +174,7 @@ IComputationNode* WrapCallable(TCallable& callable, const TComputationNodeFactor
argNodes[i] = LocateExternalNode(ctx.NodeLocator, callable, i);
}
- return new TCallableWrapper(ctx.Mutables, resultNode, std::move(argNodes));
+ return new TCallableWrapper(ctx.Mutables, resultNode, std::move(argNodes));
}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_chain1_map.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_chain1_map.cpp
index fcf94faf78..8f145ae459 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_chain1_map.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_chain1_map.cpp
@@ -3,10 +3,10 @@
#include <ydb/library/yql/minikql/computation/mkql_computation_node_codegen.h>
#include <ydb/library/yql/minikql/computation/mkql_custom_list.h>
#include <ydb/library/yql/minikql/mkql_node_cast.h>
-
-namespace NKikimr {
-namespace NMiniKQL {
-
+
+namespace NKikimr {
+namespace NMiniKQL {
+
namespace {
struct TComputationNodes {
@@ -114,18 +114,18 @@ private:
template <bool IsStream>
class TBaseChain1MapWrapper {
-public:
- class TListValue : public TCustomListValue {
- public:
+public:
+ class TListValue : public TCustomListValue {
+ public:
class TIterator : public TComputationValue<TIterator> {
- public:
- TIterator(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& iter, const TComputationNodes& computationNodes)
+ public:
+ TIterator(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& iter, const TComputationNodes& computationNodes)
: TComputationValue<TIterator>(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Iter(std::move(iter))
- , ComputationNodes(computationNodes)
- {}
-
+ , ComputationNodes(computationNodes)
+ {}
+
private:
bool Next(NUdf::TUnboxedValue& value) final {
if (!Iter.Next(ComputationNodes.ItemArg->RefValue(CompCtx))) {
@@ -136,57 +136,57 @@ public:
auto itemNode = Length == 1 ? ComputationNodes.InitItem : ComputationNodes.UpdateItem;
auto stateNode = Length == 1 ? ComputationNodes.InitState : ComputationNodes.UpdateState;
- value = itemNode->GetValue(CompCtx);
- ComputationNodes.StateArg->SetValue(CompCtx, stateNode->GetValue(CompCtx));
+ value = itemNode->GetValue(CompCtx);
+ ComputationNodes.StateArg->SetValue(CompCtx, stateNode->GetValue(CompCtx));
return true;
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue Iter;
const TComputationNodes& ComputationNodes;
- ui64 Length = 0;
- };
-
- TListValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& list, const TComputationNodes& computationNodes)
- : TCustomListValue(memInfo)
- , CompCtx(compCtx)
+ ui64 Length = 0;
+ };
+
+ TListValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& list, const TComputationNodes& computationNodes)
+ : TCustomListValue(memInfo)
+ , CompCtx(compCtx)
, List(std::move(list))
- , ComputationNodes(computationNodes)
- {}
-
+ , ComputationNodes(computationNodes)
+ {}
+
private:
NUdf::TUnboxedValue GetListIterator() const final {
return CompCtx.HolderFactory.Create<TIterator>(CompCtx, List.GetListIterator(), ComputationNodes);
}
ui64 GetListLength() const final {
- if (!Length) {
- Length = List.GetListLength();
- }
-
+ if (!Length) {
+ Length = List.GetListLength();
+ }
+
return *Length;
- }
-
+ }
+
bool HasListItems() const final {
- if (!HasItems) {
- HasItems = List.HasListItems();
- }
-
- return *HasItems;
- }
-
- TComputationContext& CompCtx;
+ if (!HasItems) {
+ HasItems = List.HasListItems();
+ }
+
+ return *HasItems;
+ }
+
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue List;
const TComputationNodes& ComputationNodes;
- };
-
+ };
+
class TStreamValue : public TComputationValue<TStreamValue> {
public:
using TBase = TComputationValue<TStreamValue>;
- TStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& list, const TComputationNodes& computationNodes)
+ TStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& list, const TComputationNodes& computationNodes)
: TBase(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, List(std::move(list))
, ComputationNodes(computationNodes)
{}
@@ -202,23 +202,23 @@ public:
auto itemNode = Length == 1 ? ComputationNodes.InitItem : ComputationNodes.UpdateItem;
auto stateNode = Length == 1 ? ComputationNodes.InitState : ComputationNodes.UpdateState;
- value = itemNode->GetValue(CompCtx);
- ComputationNodes.StateArg->SetValue(CompCtx, stateNode->GetValue(CompCtx));
+ value = itemNode->GetValue(CompCtx);
+ ComputationNodes.StateArg->SetValue(CompCtx, stateNode->GetValue(CompCtx));
return NUdf::EFetchStatus::Ok;
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue List;
const TComputationNodes& ComputationNodes;
ui64 Length = 0;
};
TBaseChain1MapWrapper(IComputationNode* list, IComputationExternalNode* itemArg, IComputationExternalNode* stateArg,
- IComputationNode* initItem, IComputationNode* initState,
- IComputationNode* updateItem, IComputationNode* updateState)
+ IComputationNode* initItem, IComputationNode* initState,
+ IComputationNode* updateItem, IComputationNode* updateState)
: List(list), ComputationNodes({itemArg, stateArg, initItem, initState, updateItem, updateState})
- {}
-
+ {}
+
#ifndef MKQL_DISABLE_CODEGEN
template<bool IsFirst>
Function* GenerateMapper(const NYql::NCodegen::ICodegen::TPtr& codegen, const TString& name) const {
@@ -296,10 +296,10 @@ public:
TChainMapPtr MapTwo = nullptr;
#endif
- IComputationNode* const List;
+ IComputationNode* const List;
const TComputationNodes ComputationNodes;
-};
-
+};
+
class TStreamChain1MapWrapper : public TCustomValueCodegeneratorNode<TStreamChain1MapWrapper>, private TBaseChain1MapWrapper<true> {
typedef TCustomValueCodegeneratorNode<TStreamChain1MapWrapper> TBaseComputation;
typedef TBaseChain1MapWrapper<true> TBaseWrapper;
@@ -543,7 +543,7 @@ IComputationNode* WrapChain1Map(TCallable& callable, const TComputationNodeFacto
}
THROW yexception() << "Expected flow, list or stream.";
-}
+}
-}
+}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_chain1_map.h b/ydb/library/yql/minikql/comp_nodes/mkql_chain1_map.h
index c4933788dd..13a6f739de 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_chain1_map.h
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_chain1_map.h
@@ -1,10 +1,10 @@
-#pragma once
+#pragma once
#include <ydb/library/yql/minikql/computation/mkql_computation_node.h>
-
-namespace NKikimr {
-namespace NMiniKQL {
-
+
+namespace NKikimr {
+namespace NMiniKQL {
+
IComputationNode* WrapChain1Map(TCallable& callable, const TComputationNodeFactoryContext& ctx);
-
-}
-}
+
+}
+}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_chain_map.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_chain_map.cpp
index d26849ee6b..138944888a 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_chain_map.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_chain_map.cpp
@@ -3,10 +3,10 @@
#include <ydb/library/yql/minikql/computation/mkql_computation_node_codegen.h>
#include <ydb/library/yql/minikql/computation/mkql_custom_list.h>
#include <ydb/library/yql/minikql/mkql_node_cast.h>
-
-namespace NKikimr {
-namespace NMiniKQL {
-
+
+namespace NKikimr {
+namespace NMiniKQL {
+
namespace {
struct TComputationNodes {
@@ -105,20 +105,20 @@ private:
template <bool IsStream>
class TBaseChainMapWrapper {
-public:
- class TListValue : public TCustomListValue {
- public:
+public:
+ class TListValue : public TCustomListValue {
+ public:
class TIterator : public TComputationValue<TIterator> {
- public:
+ public:
TIterator(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& iter, const NUdf::TUnboxedValue& init, const TComputationNodes& computationNodes)
: TComputationValue<TIterator>(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, ComputationNodes(computationNodes)
, Iter(std::move(iter))
, Init(init)
- {
- }
-
+ {
+ }
+
private:
bool Next(NUdf::TUnboxedValue& value) final {
if (!Init.IsInvalid()) {
@@ -130,59 +130,59 @@ public:
return false;
}
- value = ComputationNodes.NewItem->GetValue(CompCtx);
- ComputationNodes.StateArg->SetValue(CompCtx, ComputationNodes.NewState->GetValue(CompCtx));
+ value = ComputationNodes.NewItem->GetValue(CompCtx);
+ ComputationNodes.StateArg->SetValue(CompCtx, ComputationNodes.NewState->GetValue(CompCtx));
return true;
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const TComputationNodes& ComputationNodes;
const NUdf::TUnboxedValue Iter;
NUdf::TUnboxedValue Init;
- };
-
+ };
+
TListValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& list, NUdf::TUnboxedValue&& init, const TComputationNodes& computationNodes)
- : TCustomListValue(memInfo)
- , CompCtx(compCtx)
+ : TCustomListValue(memInfo)
+ , CompCtx(compCtx)
, List(std::move(list))
, Init(std::move(init))
- , ComputationNodes(computationNodes)
+ , ComputationNodes(computationNodes)
{}
-
+
private:
NUdf::TUnboxedValue GetListIterator() const final {
return CompCtx.HolderFactory.Create<TIterator>(CompCtx, List.GetListIterator(), Init, ComputationNodes);
}
ui64 GetListLength() const final {
- if (!Length) {
- Length = List.GetListLength();
- }
-
+ if (!Length) {
+ Length = List.GetListLength();
+ }
+
return *Length;
- }
-
+ }
+
bool HasListItems() const final {
- if (!HasItems) {
- HasItems = List.HasListItems();
- }
-
- return *HasItems;
- }
-
- TComputationContext& CompCtx;
+ if (!HasItems) {
+ HasItems = List.HasListItems();
+ }
+
+ return *HasItems;
+ }
+
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue List;
const NUdf::TUnboxedValue Init;
const TComputationNodes& ComputationNodes;
- };
-
+ };
+
class TStreamValue : public TComputationValue<TStreamValue> {
public:
using TBase = TComputationValue<TStreamValue>;
TStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& list, NUdf::TUnboxedValue&& init, const TComputationNodes& computationNodes)
: TBase(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, ComputationNodes(computationNodes)
, List(std::move(list))
, Init(std::move(init))
@@ -200,12 +200,12 @@ public:
return status;
}
- value = ComputationNodes.NewItem->GetValue(CompCtx);
- ComputationNodes.StateArg->SetValue(CompCtx, ComputationNodes.NewState->GetValue(CompCtx));
+ value = ComputationNodes.NewItem->GetValue(CompCtx);
+ ComputationNodes.StateArg->SetValue(CompCtx, ComputationNodes.NewState->GetValue(CompCtx));
return NUdf::EFetchStatus::Ok;
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const TComputationNodes& ComputationNodes;
const NUdf::TUnboxedValue List;
NUdf::TUnboxedValue Init;
@@ -213,8 +213,8 @@ public:
TBaseChainMapWrapper(IComputationNode* list, IComputationNode* init, IComputationExternalNode* itemArg, IComputationExternalNode* stateArg, IComputationNode* newItem, IComputationNode* newState)
: List(list), Init(init), ComputationNodes({itemArg, stateArg, newItem, newState})
- {}
-
+ {}
+
#ifndef MKQL_DISABLE_CODEGEN
Function* GenerateMapper(const NYql::NCodegen::ICodegen::TPtr& codegen, const TString& name) const {
auto& module = codegen->GetModule();
@@ -300,11 +300,11 @@ public:
TChainMapPtr ChainMap = nullptr;
#endif
- IComputationNode* const List;
+ IComputationNode* const List;
IComputationNode* const Init;
const TComputationNodes ComputationNodes;
-};
-
+};
+
class TStreamChainMapWrapper : public TCustomValueCodegeneratorNode<TStreamChainMapWrapper>, private TBaseChainMapWrapper<true> {
typedef TCustomValueCodegeneratorNode<TStreamChainMapWrapper> TBaseComputation;
typedef TBaseChainMapWrapper<true> TBaseWrapper;
@@ -522,7 +522,7 @@ IComputationNode* WrapChainMap(TCallable& callable, const TComputationNodeFactor
}
THROW yexception() << "Expected flow, list or stream.";
-}
+}
-}
+}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_chain_map.h b/ydb/library/yql/minikql/comp_nodes/mkql_chain_map.h
index 1e87c9c034..e792fed7d1 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_chain_map.h
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_chain_map.h
@@ -1,10 +1,10 @@
-#pragma once
+#pragma once
#include <ydb/library/yql/minikql/computation/mkql_computation_node.h>
-
-namespace NKikimr {
-namespace NMiniKQL {
-
+
+namespace NKikimr {
+namespace NMiniKQL {
+
IComputationNode* WrapChainMap(TCallable& callable, const TComputationNodeFactoryContext& ctx);
-
-}
-}
+
+}
+}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_coalesce.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_coalesce.cpp
index e0ac776bc2..826646a505 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_coalesce.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_coalesce.cpp
@@ -17,7 +17,7 @@ public:
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
if (auto left = this->Left->GetValue(compCtx)) {
return left.Release().template GetOptionalValueIf<Unpack>();
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_collect.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_collect.cpp
index 68ca8df093..db7d2c22f0 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_collect.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_collect.cpp
@@ -116,12 +116,12 @@ template <bool IsList>
class TCollectWrapper : public TMutableCodegeneratorNode<TCollectWrapper<IsList>> {
typedef TMutableCodegeneratorNode<TCollectWrapper<IsList>> TBaseComputation;
public:
- TCollectWrapper(TComputationMutables& mutables, IComputationNode* seq)
+ TCollectWrapper(TComputationMutables& mutables, IComputationNode* seq)
: TBaseComputation(mutables, EValueRepresentation::Boxed), Seq(seq)
{}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- auto seq = Seq->GetValue(ctx);
+ auto seq = Seq->GetValue(ctx);
if (IsList && seq.GetElements()) {
return seq.Release();
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_combine.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_combine.cpp
index ea068ec343..4e13f63a14 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_combine.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_combine.cpp
@@ -553,7 +553,7 @@ public:
, Stream(std::move(stream))
, Nodes(nodes)
, MemLimit(memLimit)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
{}
private:
@@ -616,7 +616,7 @@ public:
NUdf::TUnboxedValue Iterator;
const TCombineCoreNodes Nodes;
const ui64 MemLimit;
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
};
TCombineCoreWrapper(TComputationMutables& mutables, IComputationNode* stream, const TCombineCoreNodes& nodes, TKeyTypes&& keyTypes, bool isTuple, ui64 memLimit)
@@ -971,7 +971,7 @@ IComputationNode* WrapCombineCore(TCallable& callable, const TComputationNodeFac
updateResultNode,
finishResultNode
};
-
+
if (type->IsFlow()) {
const auto kind = GetValueRepresentation(AS_TYPE(TFlowType, type)->GetItemType());
if (finishResultType->IsStream()) {
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_condense.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_condense.cpp
index 0a9539c3d9..c179abab49 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_condense.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_condense.cpp
@@ -241,7 +241,7 @@ public:
}
State.Stage = ESqueezeState::Finished;
- result = State.State->GetValue(Ctx);
+ result = State.State->GetValue(Ctx);
return NUdf::EFetchStatus::Ok;
}
@@ -263,8 +263,8 @@ public:
IComputationExternalNode* inLoad = nullptr,
IComputationNode* outLoad = nullptr,
TType* stateType = nullptr)
- : TBaseComputation(mutables)
- , Stream(stream)
+ : TBaseComputation(mutables)
+ , Stream(stream)
, State(item, state, outSwitch, initState, updateState, inSave, outSave, inLoad, outLoad, stateType)
{
this->Stateless = false;
@@ -273,9 +273,9 @@ public:
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
#ifndef MKQL_DISABLE_CODEGEN
if (ctx.ExecuteLLVM && Fetch)
- return ctx.HolderFactory.Create<TSqueezeCodegenValue>(State, Fetch, ctx, Stream->GetValue(ctx));
+ return ctx.HolderFactory.Create<TSqueezeCodegenValue>(State, Fetch, ctx, Stream->GetValue(ctx));
#endif
- return ctx.HolderFactory.Create<TValue>(Stream->GetValue(ctx), State, ctx);
+ return ctx.HolderFactory.Create<TValue>(Stream->GetValue(ctx), State, ctx);
}
private:
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_condense1.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_condense1.cpp
index 3dd0edebc0..2f5ac89432 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_condense1.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_condense1.cpp
@@ -257,7 +257,7 @@ public:
return NUdf::EFetchStatus::Finish;
}
- result = State.State->GetValue(Ctx);
+ result = State.State->GetValue(Ctx);
State.Stage = ESqueezeState::Finished;
return NUdf::EFetchStatus::Ok;
}
@@ -280,8 +280,8 @@ public:
IComputationExternalNode* inLoad = nullptr,
IComputationNode* outLoad = nullptr,
TType* stateType = nullptr)
- : TBaseComputation(mutables)
- , Stream(stream)
+ : TBaseComputation(mutables)
+ , Stream(stream)
, State(item, state, outSwitch, initState, updateState, inSave, outSave, inLoad, outLoad, stateType)
{
this->Stateless = false;
@@ -290,9 +290,9 @@ public:
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
#ifndef MKQL_DISABLE_CODEGEN
if (ctx.ExecuteLLVM && Fetch)
- return ctx.HolderFactory.Create<TSqueezeCodegenValue>(State, Fetch, ctx, Stream->GetValue(ctx));
+ return ctx.HolderFactory.Create<TSqueezeCodegenValue>(State, Fetch, ctx, Stream->GetValue(ctx));
#endif
- return ctx.HolderFactory.Create<TValue>(Stream->GetValue(ctx), State, ctx);
+ return ctx.HolderFactory.Create<TValue>(Stream->GetValue(ctx), State, ctx);
}
private:
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_contains.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_contains.cpp
index b736c53131..54e2e0293d 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_contains.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_contains.cpp
@@ -10,15 +10,15 @@ namespace {
class TContainsWrapper : public TMutableCodegeneratorNode<TContainsWrapper> {
typedef TMutableCodegeneratorNode<TContainsWrapper> TBaseComputation;
public:
- TContainsWrapper(TComputationMutables& mutables, IComputationNode* dict, IComputationNode* key)
+ TContainsWrapper(TComputationMutables& mutables, IComputationNode* dict, IComputationNode* key)
: TBaseComputation(mutables, EValueRepresentation::Embedded)
- , Dict(dict)
+ , Dict(dict)
, Key(key)
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
- return NUdf::TUnboxedValuePod(Dict->GetValue(compCtx).Contains(Key->GetValue(compCtx)));
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
+ return NUdf::TUnboxedValuePod(Dict->GetValue(compCtx).Contains(Key->GetValue(compCtx)));
}
#ifndef MKQL_DISABLE_CODEGEN
@@ -57,7 +57,7 @@ IComputationNode* WrapContains(TCallable& callable, const TComputationNodeFactor
const auto dict = LocateNode(ctx.NodeLocator, callable, 0);
const auto key = LocateNode(ctx.NodeLocator, callable, 1);
- return new TContainsWrapper(ctx.Mutables, dict, key);
+ return new TContainsWrapper(ctx.Mutables, dict, key);
}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_dictitems.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_dictitems.cpp
index 14ff6f6548..a20f016b57 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_dictitems.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_dictitems.cpp
@@ -54,10 +54,10 @@ public:
class TIterator : public TComputationValue<TIterator> {
public:
TIterator(TMemoryUsageInfo* memInfo, NUdf::TUnboxedValue&& inner,
- TComputationContext& compCtx, const TSelf* self)
+ TComputationContext& compCtx, const TSelf* self)
: TComputationValue<TIterator>(memInfo)
, Inner(std::move(inner))
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Self(self)
{
}
@@ -80,17 +80,17 @@ public:
}
const NUdf::TUnboxedValue Inner;
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const TSelf* const Self;
};
TValue(
TMemoryUsageInfo* memInfo,
- const NUdf::TUnboxedValue&& dict,
- TComputationContext& compCtx, const TSelf* self)
+ const NUdf::TUnboxedValue&& dict,
+ TComputationContext& compCtx, const TSelf* self)
: TComputationValue<TValue>(memInfo)
- , Dict(std::move(dict))
- , CompCtx(compCtx)
+ , Dict(std::move(dict))
+ , CompCtx(compCtx)
, Self(self)
{
}
@@ -113,22 +113,22 @@ public:
}
const NUdf::TUnboxedValue Dict;
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const TSelf* const Self;
};
TDictItemsWrapper(TComputationMutables& mutables, IComputationNode* dict)
- : TBaseComputation(mutables)
+ : TBaseComputation(mutables)
, Dict(dict)
- , ResPair(mutables)
+ , ResPair(mutables)
{}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
#ifndef MKQL_DISABLE_CODEGEN
if (ctx.ExecuteLLVM && Next)
- return ctx.HolderFactory.Create<TCodegenValue>(Next, &ctx, Dict->GetValue(ctx));
+ return ctx.HolderFactory.Create<TCodegenValue>(Next, &ctx, Dict->GetValue(ctx));
#endif
- return ctx.HolderFactory.Create<TValue>(Dict->GetValue(ctx), ctx, this);
+ return ctx.HolderFactory.Create<TValue>(Dict->GetValue(ctx), ctx, this);
}
private:
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_discard.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_discard.cpp
index dcb5bcbf79..88a92bcd4e 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_discard.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_discard.cpp
@@ -138,7 +138,7 @@ public:
if (ctx.ExecuteLLVM && Fetch)
return ctx.HolderFactory.Create<TStreamCodegenValueStateless>(Fetch, &ctx, Stream->GetValue(ctx));
#endif
- return ctx.HolderFactory.Create<TValue>(Stream->GetValue(ctx));
+ return ctx.HolderFactory.Create<TValue>(Stream->GetValue(ctx));
}
private:
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_ensure.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_ensure.cpp
index 12e5284222..85c8371ec6 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_ensure.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_ensure.cpp
@@ -24,7 +24,7 @@ public:
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- const auto& predicate = Predicate->GetValue(ctx);
+ const auto& predicate = Predicate->GetValue(ctx);
if (predicate && predicate.Get<bool>()) {
return Arg->GetValue(ctx).Release();
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_enumerate.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_enumerate.cpp
index 169cbafcc8..727aae0d0b 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_enumerate.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_enumerate.cpp
@@ -22,12 +22,12 @@ public:
TMemoryUsageInfo* memInfo,
NUdf::TUnboxedValue&& inner,
ui64 start, ui64 step,
- TComputationContext& ctx, const TSelf* self)
+ TComputationContext& ctx, const TSelf* self)
: TComputationValue(memInfo)
, Inner(std::move(inner))
, Step(step)
, Counter(start - step)
- , Ctx(ctx)
+ , Ctx(ctx)
, Self(self)
{
}
@@ -59,7 +59,7 @@ public:
const NUdf::TUnboxedValue Inner;
const ui64 Step;
ui64 Counter;
- TComputationContext& Ctx;
+ TComputationContext& Ctx;
const TSelf* const Self;
};
@@ -67,14 +67,14 @@ public:
TMemoryUsageInfo* memInfo,
const NUdf::TUnboxedValue& list,
ui64 start, ui64 step,
- TComputationContext& ctx,
+ TComputationContext& ctx,
const TSelf* self
)
: TCustomListValue(memInfo)
, List(list)
, Start(start)
, Step(step)
- , Ctx(ctx)
+ , Ctx(ctx)
, Self(self)
{}
@@ -102,16 +102,16 @@ public:
const NUdf::TUnboxedValue List;
const ui64 Start;
const ui64 Step;
- TComputationContext& Ctx;
+ TComputationContext& Ctx;
const TSelf* const Self;
};
- TEnumerateWrapper(TComputationMutables& mutables, IComputationNode* list, IComputationNode* start, IComputationNode* step)
+ TEnumerateWrapper(TComputationMutables& mutables, IComputationNode* list, IComputationNode* start, IComputationNode* step)
: TBaseComputation(mutables, EValueRepresentation::Boxed)
- , List(list)
+ , List(list)
, Start(start)
, Step(step)
- , ResPair(mutables)
+ , ResPair(mutables)
{}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
@@ -174,7 +174,7 @@ IComputationNode* WrapEnumerate(TCallable& callable, const TComputationNodeFacto
MKQL_ENSURE(AS_TYPE(TDataType, callable.GetInput(1))->GetSchemeType() == NUdf::TDataType<ui64>::Id, "Expected Uint64");
MKQL_ENSURE(AS_TYPE(TDataType, callable.GetInput(2))->GetSchemeType() == NUdf::TDataType<ui64>::Id, "Expected Uint64");
- return new TEnumerateWrapper(ctx.Mutables, LocateNode(ctx.NodeLocator, callable, 0),
+ return new TEnumerateWrapper(ctx.Mutables, LocateNode(ctx.NodeLocator, callable, 0),
LocateNode(ctx.NodeLocator, callable, 1), LocateNode(ctx.NodeLocator, callable, 2));
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_extend.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_extend.cpp
index 8e6cc1fd09..36fd03b0a4 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_extend.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_extend.cpp
@@ -87,9 +87,9 @@ template <bool IsStream>
class TExtendWrapper : public TMutableCodegeneratorNode<TExtendWrapper<IsStream>> {
typedef TMutableCodegeneratorNode<TExtendWrapper<IsStream>> TBaseComputation;
public:
- TExtendWrapper(TComputationMutables& mutables, TComputationNodePtrVector&& lists)
+ TExtendWrapper(TComputationMutables& mutables, TComputationNodePtrVector&& lists)
: TBaseComputation(mutables, EValueRepresentation::Boxed)
- , Lists(std::move(lists))
+ , Lists(std::move(lists))
{
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_factory.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_factory.cpp
index 1e53ca16e0..57599acb64 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_factory.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_factory.cpp
@@ -31,7 +31,7 @@
#include "mkql_fold1.h"
#include "mkql_frombytes.h"
#include "mkql_fromstring.h"
-#include "mkql_fromyson.h"
+#include "mkql_fromyson.h"
#include "mkql_guess.h"
#include "mkql_group.h"
#include "mkql_heap.h"
@@ -58,7 +58,7 @@
#include "mkql_null.h"
#include "mkql_pickle.h"
#include "mkql_prepend.h"
-#include "mkql_queue.h"
+#include "mkql_queue.h"
#include "mkql_random.h"
#include "mkql_range.h"
#include "mkql_reduce.h"
@@ -87,7 +87,7 @@
#include "mkql_varitem.h"
#include "mkql_visitall.h"
#include "mkql_way.h"
-#include "mkql_weakmember.h"
+#include "mkql_weakmember.h"
#include "mkql_while.h"
#include "mkql_wide_chain_map.h"
#include "mkql_wide_chopper.h"
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_filter.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_filter.cpp
index 0e79b95225..7de0ebd830 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_filter.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_filter.cpp
@@ -167,7 +167,7 @@ protected:
public:
TIterator(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& iter, IComputationExternalNode* item, IComputationNode* predicate)
: TComputationValue<TIterator>(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Iter(std::move(iter))
, Item(item)
, Predicate(predicate)
@@ -185,7 +185,7 @@ protected:
return false;
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue Iter;
IComputationExternalNode* const Item;
IComputationNode* const Predicate;
@@ -193,7 +193,7 @@ protected:
TListValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, const NUdf::TUnboxedValue& list, IComputationExternalNode* item, IComputationNode* predicate)
: TCustomListValue(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, List(list)
, Item(item)
, Predicate(predicate)
@@ -205,7 +205,7 @@ protected:
return CompCtx.HolderFactory.Create<TIterator>(CompCtx, List.GetListIterator(), Item, Predicate);
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue List;
IComputationExternalNode* const Item;
IComputationNode* const Predicate;
@@ -217,7 +217,7 @@ protected:
TStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, const NUdf::TUnboxedValue& stream, IComputationExternalNode* item, IComputationNode* predicate)
: TBase(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Stream(stream)
, Item(item)
, Predicate(predicate)
@@ -247,8 +247,8 @@ protected:
return status;
}
- if (Predicate->GetValue(CompCtx).template Get<bool>()) {
- result = Item->GetValue(CompCtx);
+ if (Predicate->GetValue(CompCtx).template Get<bool>()) {
+ result = Item->GetValue(CompCtx);
return NUdf::EFetchStatus::Ok;
}
}
@@ -256,7 +256,7 @@ protected:
return NUdf::EFetchStatus::Finish;
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue Stream;
IComputationExternalNode* const Item;
IComputationNode* const Predicate;
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_flatmap.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_flatmap.cpp
index fac1d02c35..a9d49e109d 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_flatmap.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_flatmap.cpp
@@ -895,7 +895,7 @@ public:
public:
TIterator(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& iter, IComputationExternalNode* item, IComputationNode* newItem)
: TComputationValue<TIterator>(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Iter(std::move(iter))
, Item(item)
, NewItem(newItem)
@@ -908,14 +908,14 @@ public:
return false;
}
- if (auto newItem = NewItem->GetValue(CompCtx)) {
+ if (auto newItem = NewItem->GetValue(CompCtx)) {
value = newItem.Release().template GetOptionalValueIf<MultiOptional>();
return true;
}
}
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue Iter;
IComputationExternalNode* const Item;
@@ -924,7 +924,7 @@ public:
TSimpleListValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& list, IComputationExternalNode* item, IComputationNode* newItem)
: TCustomListValue(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, List(std::move(list))
, Item(item)
, NewItem(newItem)
@@ -936,7 +936,7 @@ private:
return CompCtx.HolderFactory.Create<TIterator>(CompCtx, List.GetListIterator(), Item, NewItem);
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue List;
IComputationExternalNode* const Item;
IComputationNode* const NewItem;
@@ -949,7 +949,7 @@ public:
TSimpleStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& stream, IComputationExternalNode* item, IComputationNode* newItem)
: TBase(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Stream(std::move(stream))
, Item(item)
, NewItem(newItem)
@@ -980,7 +980,7 @@ private:
return status;
}
- if (auto newItem = NewItem->GetValue(CompCtx)) {
+ if (auto newItem = NewItem->GetValue(CompCtx)) {
result = newItem.Release().template GetOptionalValueIf<MultiOptional>();
return NUdf::EFetchStatus::Ok;
}
@@ -988,7 +988,7 @@ private:
}
private:
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue Stream;
IComputationExternalNode* const Item;
IComputationNode* const NewItem;
@@ -1001,7 +1001,7 @@ public:
public:
TIterator(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& iter, IComputationExternalNode* item, IComputationNode* newItem)
: TComputationValue<TIterator>(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Iter(std::move(iter))
, Item(item)
, NewItem(newItem)
@@ -1012,7 +1012,7 @@ public:
for (NUdf::TUnboxedValue current = std::move(Current);; current.Clear()) {
if (!current) {
if (Iter.Next(Item->RefValue(CompCtx))) {
- current = IsNewStream ? NewItem->GetValue(CompCtx) : NewItem->GetValue(CompCtx).GetListIterator();
+ current = IsNewStream ? NewItem->GetValue(CompCtx) : NewItem->GetValue(CompCtx).GetListIterator();
} else {
return false;
}
@@ -1035,7 +1035,7 @@ public:
}
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue Iter;
IComputationExternalNode* const Item;
@@ -1046,7 +1046,7 @@ public:
TListValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& list, IComputationExternalNode* item, IComputationNode* newItem)
: TCustomListValue(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, List(std::move(list))
, Item(item)
, NewItem(newItem)
@@ -1057,7 +1057,7 @@ private:
return CompCtx.HolderFactory.Create<TIterator>(CompCtx, List.GetListIterator(), Item, NewItem);
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue List;
IComputationExternalNode* const Item;
IComputationNode* const NewItem;
@@ -1070,7 +1070,7 @@ public:
TStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& stream, IComputationExternalNode* item, IComputationNode* newItem)
: TBase(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Stream(std::move(stream))
, Item(item)
, NewItem(newItem)
@@ -1101,7 +1101,7 @@ private:
if (NUdf::EFetchStatus::Ok != status) {
return status;
}
- current = IsNewStream ? NewItem->GetValue(CompCtx) : NewItem->GetValue(CompCtx).GetListIterator();
+ current = IsNewStream ? NewItem->GetValue(CompCtx) : NewItem->GetValue(CompCtx).GetListIterator();
}
auto status = NUdf::EFetchStatus::Ok;
@@ -1122,7 +1122,7 @@ private:
}
private:
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue Stream;
IComputationExternalNode* const Item;
IComputationNode* const NewItem;
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_fold.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_fold.cpp
index 2efbfe5975..15d912e49d 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_fold.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_fold.cpp
@@ -13,7 +13,7 @@ public:
TFoldWrapper(TComputationMutables& mutables, EValueRepresentation kind, IComputationNode* list, IComputationExternalNode* item, IComputationExternalNode* state,
IComputationNode* newState, IComputationNode* initialState)
: TBaseComputation(mutables, kind)
- , List(list)
+ , List(list)
, Item(item)
, State(state)
, NewState(newState)
@@ -21,17 +21,17 @@ public:
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
- State->SetValue(compCtx, InitialState->GetValue(compCtx));
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
+ State->SetValue(compCtx, InitialState->GetValue(compCtx));
- TThresher<false>::DoForEachItem(List->GetValue(compCtx),
- [this, &compCtx] (NUdf::TUnboxedValue&& item) {
- Item->SetValue(compCtx, std::move(item));
- State->SetValue(compCtx, NewState->GetValue(compCtx));
+ TThresher<false>::DoForEachItem(List->GetValue(compCtx),
+ [this, &compCtx] (NUdf::TUnboxedValue&& item) {
+ Item->SetValue(compCtx, std::move(item));
+ State->SetValue(compCtx, NewState->GetValue(compCtx));
}
);
- return State->GetValue(compCtx).Release();
+ return State->GetValue(compCtx).Release();
}
#ifndef MKQL_DISABLE_CODEGEN
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_fold1.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_fold1.cpp
index 49f045358e..e6fab3f0a3 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_fold1.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_fold1.cpp
@@ -12,7 +12,7 @@ public:
TFold1Wrapper(TComputationMutables& mutables, EValueRepresentation kind, IComputationNode* list, IComputationExternalNode* item, IComputationExternalNode* state,
IComputationNode* newState, IComputationNode* initialState)
: TBaseComputation(mutables, kind)
- , List(list)
+ , List(list)
, Item(item)
, State(state)
, NewState(newState)
@@ -20,17 +20,17 @@ public:
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
ui64 length = 0ULL;
- TThresher<false>::DoForEachItem(List->GetValue(compCtx),
- [this, &length, &compCtx] (NUdf::TUnboxedValue&& item) {
- Item->SetValue(compCtx, std::move(item));
- State->SetValue(compCtx, (length++ ? NewState : InitialState)->GetValue(compCtx));
+ TThresher<false>::DoForEachItem(List->GetValue(compCtx),
+ [this, &length, &compCtx] (NUdf::TUnboxedValue&& item) {
+ Item->SetValue(compCtx, std::move(item));
+ State->SetValue(compCtx, (length++ ? NewState : InitialState)->GetValue(compCtx));
}
);
- return length ? State->GetValue(compCtx).Release().MakeOptional() : NUdf::TUnboxedValuePod();
+ return length ? State->GetValue(compCtx).Release().MakeOptional() : NUdf::TUnboxedValuePod();
}
#ifndef MKQL_DISABLE_CODEGEN
@@ -204,7 +204,7 @@ private:
}
IComputationNode* WrapFold1(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
- MKQL_ENSURE(callable.GetInputsCount() == 5, "Expected 5 args");
+ MKQL_ENSURE(callable.GetInputsCount() == 5, "Expected 5 args");
MKQL_ENSURE(callable.GetInput(0).GetStaticType()->IsList(), "Expected List");
const auto list = LocateNode(ctx.NodeLocator, callable, 0);
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_frombytes.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_frombytes.cpp
index 82dd1f7423..16f9109b70 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_frombytes.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_frombytes.cpp
@@ -19,17 +19,17 @@ using NYql::SwapBytes;
template <bool IsOptional>
class TFromBytesWrapper : public TMutableComputationNode<TFromBytesWrapper<IsOptional>> {
- typedef TMutableComputationNode<TFromBytesWrapper<IsOptional>> TBaseComputation;
+ typedef TMutableComputationNode<TFromBytesWrapper<IsOptional>> TBaseComputation;
public:
- TFromBytesWrapper(TComputationMutables& mutables, IComputationNode* data, NUdf::TDataTypeId schemeType)
- : TBaseComputation(mutables)
- , Data(data)
+ TFromBytesWrapper(TComputationMutables& mutables, IComputationNode* data, NUdf::TDataTypeId schemeType)
+ : TBaseComputation(mutables)
+ , Data(data)
, SchemeType(NUdf::GetDataSlot(schemeType))
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- auto data = Data->GetValue(ctx);
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ auto data = Data->GetValue(ctx);
if (IsOptional && !data) {
return NUdf::TUnboxedValuePod();
}
@@ -137,9 +137,9 @@ IComputationNode* WrapFromBytes(TCallable& callable, const TComputationNodeFacto
const auto data = LocateNode(ctx.NodeLocator, callable, 0);
if (isOptional) {
- return new TFromBytesWrapper<true>(ctx.Mutables, data, static_cast<NUdf::TDataTypeId>(schemeType));
+ return new TFromBytesWrapper<true>(ctx.Mutables, data, static_cast<NUdf::TDataTypeId>(schemeType));
} else {
- return new TFromBytesWrapper<false>(ctx.Mutables, data, static_cast<NUdf::TDataTypeId>(schemeType));
+ return new TFromBytesWrapper<false>(ctx.Mutables, data, static_cast<NUdf::TDataTypeId>(schemeType));
}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_fromstring.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_fromstring.cpp
index f812a449f9..7090aff8cd 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_fromstring.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_fromstring.cpp
@@ -29,7 +29,7 @@ class TDecimalFromStringWrapper : public TMutableCodegeneratorNode<TDecimalFromS
public:
TDecimalFromStringWrapper(TComputationMutables& mutables, IComputationNode* data, ui8 precision, ui8 scale)
: TBaseComputation(mutables, EValueRepresentation::Embedded)
- , Data(data)
+ , Data(data)
, Precision(precision)
, Scale(scale)
{
@@ -163,7 +163,7 @@ public:
{}
NUdf::TUnboxedValue DoCalculate(TComputationContext& ctx) const {
- const auto& data = Data->GetValue(ctx);
+ const auto& data = Data->GetValue(ctx);
if (IsOptional && !data) {
return NUdf::TUnboxedValuePod();
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_fromyson.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_fromyson.cpp
index e73d966bfa..98aa7d9c3e 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_fromyson.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_fromyson.cpp
@@ -1,62 +1,62 @@
-#include "mkql_fromyson.h"
+#include "mkql_fromyson.h"
#include <ydb/library/yql/minikql/computation/mkql_computation_node_holders.h>
#include <ydb/library/yql/minikql/mkql_node_cast.h>
#include <ydb/library/yql/minikql/mkql_node_builder.h>
-
-namespace NKikimr {
-namespace NMiniKQL {
-
+
+namespace NKikimr {
+namespace NMiniKQL {
+
namespace {
template<bool IsOptional>
class TFromYsonSimpleTypeWrapper : public TMutableComputationNode<TFromYsonSimpleTypeWrapper<IsOptional>> {
typedef TMutableComputationNode<TFromYsonSimpleTypeWrapper<IsOptional>> TBaseComputation;
-public:
- TFromYsonSimpleTypeWrapper(TComputationMutables& mutables, IComputationNode* data, NUdf::TDataTypeId schemeType)
- : TBaseComputation(mutables)
- , Data(data)
+public:
+ TFromYsonSimpleTypeWrapper(TComputationMutables& mutables, IComputationNode* data, NUdf::TDataTypeId schemeType)
+ : TBaseComputation(mutables)
+ , Data(data)
, SchemeType(NUdf::GetDataSlot(schemeType))
{}
-
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- const auto& data = Data->GetValue(ctx);
+
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ const auto& data = Data->GetValue(ctx);
if (IsOptional && !data) {
return NUdf::TUnboxedValuePod();
- }
-
+ }
+
return SimpleValueFromYson(SchemeType, data.AsStringRef());
- }
-
+ }
+
private:
void RegisterDependencies() const final {
this->DependsOn(Data);
- }
-
- IComputationNode* const Data;
+ }
+
+ IComputationNode* const Data;
const NUdf::EDataSlot SchemeType;
-};
-
+};
+
}
-IComputationNode* WrapFromYsonSimpleType(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
- MKQL_ENSURE(callable.GetInputsCount() == 2, "Expected 2 args");
-
- bool isOptional;
+IComputationNode* WrapFromYsonSimpleType(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
+ MKQL_ENSURE(callable.GetInputsCount() == 2, "Expected 2 args");
+
+ bool isOptional;
const auto dataType = UnpackOptionalData(callable.GetInput(0), isOptional);
const auto dataSchemeType = dataType->GetSchemeType();
- MKQL_ENSURE(dataSchemeType == NUdf::TDataType<char*>::Id || dataSchemeType == NUdf::TDataType<NUdf::TYson>::Id,
- "Expected String or Yson");
-
+ MKQL_ENSURE(dataSchemeType == NUdf::TDataType<char*>::Id || dataSchemeType == NUdf::TDataType<NUdf::TYson>::Id,
+ "Expected String or Yson");
+
const auto schemeTypeData = AS_VALUE(TDataLiteral, callable.GetInput(1));
const auto schemeType = schemeTypeData->AsValue().Get<ui32>();
-
+
const auto data = LocateNode(ctx.NodeLocator, callable, 0);
if (isOptional) {
return new TFromYsonSimpleTypeWrapper<true>(ctx.Mutables, data, static_cast<NUdf::TDataTypeId>(schemeType));
} else {
return new TFromYsonSimpleTypeWrapper<false>(ctx.Mutables, data, static_cast<NUdf::TDataTypeId>(schemeType));
}
-}
-
-}
-}
+}
+
+}
+}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_fromyson.h b/ydb/library/yql/minikql/comp_nodes/mkql_fromyson.h
index 44b461f057..d94d3bf5dd 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_fromyson.h
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_fromyson.h
@@ -1,10 +1,10 @@
-#pragma once
+#pragma once
#include <ydb/library/yql/minikql/computation/mkql_computation_node.h>
-
-namespace NKikimr {
-namespace NMiniKQL {
-
-IComputationNode* WrapFromYsonSimpleType(TCallable& callable, const TComputationNodeFactoryContext& ctx);
-
-}
-}
+
+namespace NKikimr {
+namespace NMiniKQL {
+
+IComputationNode* WrapFromYsonSimpleType(TCallable& callable, const TComputationNodeFactoryContext& ctx);
+
+}
+}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_group.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_group.cpp
index 3cf8cccce7..0d0ff62fae 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_group.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_group.cpp
@@ -31,9 +31,9 @@ public:
Finished,
};
- TSplitStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, const TSelf* self, NUdf::TUnboxedValue&& stream)
+ TSplitStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, const TSelf* self, NUdf::TUnboxedValue&& stream)
: TBase(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Self(self)
, Stream(std::move(stream))
{
@@ -64,7 +64,7 @@ public:
}
Self->KeyExtractorItemNode->SetValue(CompCtx, NUdf::TUnboxedValue(Value));
- key = Self->KeyExtractorResultNode->GetValue(CompCtx);
+ key = Self->KeyExtractorResultNode->GetValue(CompCtx);
Self->GroupSwitchKeyNode->SetValue(CompCtx, NUdf::TUnboxedValue(key));
Self->GroupSwitchItemNode->SetValue(CompCtx, NUdf::TUnboxedValue(Value));
State = AtGroupStart;
@@ -108,7 +108,7 @@ public:
}
private:
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const TSelf* const Self;
NUdf::TUnboxedValue Stream;
EState State = AtStart;
@@ -119,10 +119,10 @@ public:
public:
using TBase = TComputationValue<TGroupStreamValue>;
- TGroupStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, const TSelf* self, NUdf::TUnboxedValue&& stream)
+ TGroupStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, const TSelf* self, NUdf::TUnboxedValue&& stream)
: TBase(memInfo)
- , CompCtx(compCtx)
- , SplitStream(CompCtx.HolderFactory.Create<TSplitStreamValue>(CompCtx, self, std::move(stream)))
+ , CompCtx(compCtx)
+ , SplitStream(CompCtx.HolderFactory.Create<TSplitStreamValue>(CompCtx, self, std::move(stream)))
, SplitStreamValue(static_cast<TSplitStreamValue*>(SplitStream.AsBoxed().Get()))
{
}
@@ -136,7 +136,7 @@ public:
}
NKikimr::NUdf::TUnboxedValue* itemsPtr;
- result = CompCtx.HolderFactory.CreateDirectArrayHolder(2, itemsPtr);
+ result = CompCtx.HolderFactory.CreateDirectArrayHolder(2, itemsPtr);
itemsPtr[0] = std::move(key);
itemsPtr[1] = SplitStream;
@@ -144,7 +144,7 @@ public:
}
private:
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
NUdf::TUnboxedValue SplitStream;
TSplitStreamValue* SplitStreamValue;
};
@@ -171,7 +171,7 @@ public:
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- return ctx.HolderFactory.Create<TGroupStreamValue>(ctx, this, Stream->GetValue(ctx));
+ return ctx.HolderFactory.Create<TGroupStreamValue>(ctx, this, Stream->GetValue(ctx));
}
private:
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_guess.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_guess.cpp
index 6f8161ece3..0e0c734a5e 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_guess.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_guess.cpp
@@ -14,13 +14,13 @@ class TGuessWrapper: public TMutableCodegeneratorPtrNode<TGuessWrapper<IsOptiona
public:
TGuessWrapper(TComputationMutables& mutables, EValueRepresentation kind, IComputationNode* varNode, ui32 index)
: TBaseComputation(mutables, kind)
- , VarNode(varNode)
+ , VarNode(varNode)
, Index(index)
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
- auto var = VarNode->GetValue(compCtx);
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
+ auto var = VarNode->GetValue(compCtx);
if (IsOptional && !var) {
return NUdf::TUnboxedValuePod();
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_hasitems.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_hasitems.cpp
index aa2d85a32e..3fb5f02ae8 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_hasitems.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_hasitems.cpp
@@ -12,12 +12,12 @@ template <bool IsDict, bool IsOptional>
class THasItemsWrapper : public TMutableCodegeneratorNode<THasItemsWrapper<IsDict, IsOptional>> {
typedef TMutableCodegeneratorNode<THasItemsWrapper<IsDict, IsOptional>> TBaseComputation;
public:
- THasItemsWrapper(TComputationMutables& mutables, IComputationNode* collection)
+ THasItemsWrapper(TComputationMutables& mutables, IComputationNode* collection)
: TBaseComputation(mutables, EValueRepresentation::Embedded)
- , Collection(collection)
+ , Collection(collection)
{}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
const auto& collection = Collection->GetValue(compCtx);
if (IsOptional && !collection) {
return NUdf::TUnboxedValuePod();
@@ -77,7 +77,7 @@ IComputationNode* WrapHasItems(TCallable& callable, const TComputationNodeFactor
return new THasItemsWrapper<true, true>(ctx.Mutables, LocateNode(ctx.NodeLocator, callable, 0));
else
return new THasItemsWrapper<true, false>(ctx.Mutables, LocateNode(ctx.NodeLocator, callable, 0));
- } else {
+ } else {
if (isOptional)
return new THasItemsWrapper<false, true>(ctx.Mutables, LocateNode(ctx.NodeLocator, callable, 0));
else
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_hopping.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_hopping.cpp
index 895c0e6978..27d1e000ac 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_hopping.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_hopping.cpp
@@ -17,7 +17,7 @@ const TStatKey Hop_NewHopsCount("Hop_NewHopsCount", true);
const TStatKey Hop_ThrownEventsCount("Hop_ThrownEventsCount", true);
class THoppingCoreWrapper : public TMutableComputationNode<THoppingCoreWrapper> {
- typedef TMutableComputationNode<THoppingCoreWrapper> TBaseComputation;
+ typedef TMutableComputationNode<THoppingCoreWrapper> TBaseComputation;
public:
using TSelf = THoppingCoreWrapper;
@@ -62,9 +62,9 @@ public:
WriteBool(out, bucket.HasValue);
if (bucket.HasValue) {
Self->InSave->SetValue(Ctx, NUdf::TUnboxedValue(bucket.Value));
- if (Self->StateType) {
+ if (Self->StateType) {
WriteUnboxedValue(out, Self->Packer.RefMutableObject(Ctx, false, Self->StateType), Self->OutSave->GetValue(Ctx));
- }
+ }
}
}
@@ -84,10 +84,10 @@ public:
for (auto& bucket : Buckets) {
bucket.HasValue = ReadBool(in);
if (bucket.HasValue) {
- if (Self->StateType) {
+ if (Self->StateType) {
Self->InLoad->SetValue(Ctx, ReadUnboxedValue(in, Self->Packer.RefMutableObject(Ctx, false, Self->StateType), Ctx));
- }
- bucket.Value = Self->OutLoad->GetValue(Ctx);
+ }
+ bucket.Value = Self->OutLoad->GetValue(Ctx);
}
}
@@ -132,8 +132,8 @@ public:
return status;
}
- Self->Item->SetValue(Ctx, std::move(item));
- auto time = Self->OutTime->GetValue(Ctx);
+ Self->Item->SetValue(Ctx, std::move(item));
+ auto time = Self->OutTime->GetValue(Ctx);
if (!time) {
continue;
}
@@ -161,7 +161,7 @@ public:
} else {
Self->State->SetValue(Ctx, NUdf::TUnboxedValue(bucket.Value));
Self->State2->SetValue(Ctx, NUdf::TUnboxedValue(*aggregated));
- aggregated = Self->OutMerge->GetValue(Ctx);
+ aggregated = Self->OutMerge->GetValue(Ctx);
}
}
if (++bucketIndex == Buckets.size()) {
@@ -175,8 +175,8 @@ public:
if (aggregated) {
Self->State->SetValue(Ctx, NUdf::TUnboxedValue(*aggregated));
- Self->Time->SetValue(Ctx, NUdf::TUnboxedValuePod((HopIndex - DelayHopCount) * HopTime));
- Ready.emplace_back(Self->OutFinish->GetValue(Ctx));
+ Self->Time->SetValue(Ctx, NUdf::TUnboxedValuePod((HopIndex - DelayHopCount) * HopTime));
+ Ready.emplace_back(Self->OutFinish->GetValue(Ctx));
}
++newHops;
@@ -186,11 +186,11 @@ public:
if (hopIndex + DelayHopCount + 1 >= HopIndex) {
auto& bucket = Buckets[hopIndex % Buckets.size()];
if (!bucket.HasValue) {
- bucket.Value = Self->OutInit->GetValue(Ctx);
+ bucket.Value = Self->OutInit->GetValue(Ctx);
bucket.HasValue = true;
} else {
Self->State->SetValue(Ctx, NUdf::TUnboxedValue(bucket.Value));
- bucket.Value = Self->OutUpdate->GetValue(Ctx);
+ bucket.Value = Self->OutUpdate->GetValue(Ctx);
}
} else {
++thrownEvents;
@@ -221,7 +221,7 @@ public:
};
THoppingCoreWrapper(
- TComputationMutables& mutables,
+ TComputationMutables& mutables,
IComputationNode* stream,
IComputationExternalNode* item,
IComputationExternalNode* state,
@@ -240,8 +240,8 @@ public:
IComputationNode* interval,
IComputationNode* delay,
TType* stateType)
- : TBaseComputation(mutables)
- , Stream(stream)
+ : TBaseComputation(mutables)
+ , Stream(stream)
, Item(item)
, State(state)
, State2(state2)
@@ -258,16 +258,16 @@ public:
, Hop(hop)
, Interval(interval)
, Delay(delay)
- , StateType(stateType)
- , Packer(mutables)
+ , StateType(stateType)
+ , Packer(mutables)
{
Stateless = false;
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- const auto hopTime = Hop->GetValue(ctx).Get<i64>();
- const auto interval = Interval->GetValue(ctx).Get<i64>();
- const auto delay = Delay->GetValue(ctx).Get<i64>();
+ const auto hopTime = Hop->GetValue(ctx).Get<i64>();
+ const auto interval = Interval->GetValue(ctx).Get<i64>();
+ const auto delay = Delay->GetValue(ctx).Get<i64>();
// TODO: move checks from here
MKQL_ENSURE(hopTime > 0, "hop must be positive");
@@ -280,7 +280,7 @@ public:
MKQL_ENSURE(intervalHopCount <= 100000, "too many hops in interval");
MKQL_ENSURE(delayHopCount <= 100000, "too many hops in delay");
- return ctx.HolderFactory.Create<TStreamValue>(Stream->GetValue(ctx), this, (ui64)hopTime, (ui64)intervalHopCount, (ui64)delayHopCount, ctx);
+ return ctx.HolderFactory.Create<TStreamValue>(Stream->GetValue(ctx), this, (ui64)hopTime, (ui64)intervalHopCount, (ui64)delayHopCount, ctx);
}
private:
@@ -325,8 +325,8 @@ private:
IComputationNode* const Interval;
IComputationNode* const Delay;
- TType* const StateType;
- TMutableObjectOverBoxedValue<TValuePackerBoxed> Packer;
+ TType* const StateType;
+ TMutableObjectOverBoxedValue<TValuePackerBoxed> Packer;
};
}
@@ -371,7 +371,7 @@ IComputationNode* WrapHoppingCore(TCallable& callable, const TComputationNodeFac
auto stateType = hasSaveLoad ? callable.GetInput(10).GetStaticType() : nullptr;
- return new THoppingCoreWrapper(ctx.Mutables,
+ return new THoppingCoreWrapper(ctx.Mutables,
stream, item, state, state2, time, inSave, inLoad,
outTime, outInit, outUpdate, outSave, outLoad, outMerge, outFinish,
hop, interval, delay, stateType);
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_if.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_if.cpp
index a77ae3818c..ac25b71031 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_if.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_if.cpp
@@ -14,12 +14,12 @@ using TBaseComputation = TMutableCodegeneratorNode<TIfWrapper<IsOptional>>;
public:
TIfWrapper(TComputationMutables& mutables, EValueRepresentation kind, IComputationNode* predicate, IComputationNode* thenBranch, IComputationNode* elseBranch)
: TBaseComputation(mutables, kind)
- , Predicate(predicate)
+ , Predicate(predicate)
, ThenBranch(thenBranch)
, ElseBranch(elseBranch)
{}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
const auto& predicate = Predicate->GetValue(ctx);
if (IsOptional && !predicate) {
return NUdf::TUnboxedValuePod();
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_ifpresent.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_ifpresent.cpp
index 51197c256f..e017c7ea88 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_ifpresent.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_ifpresent.cpp
@@ -14,7 +14,7 @@ public:
TIfPresentWrapper(TComputationMutables& mutables, EValueRepresentation kind, IComputationNode* optional, IComputationExternalNode* item, IComputationNode* presentBranch,
IComputationNode* missingBranch)
: TBaseComputation(mutables, kind)
- , Optional(optional)
+ , Optional(optional)
, Item(item)
, PresentBranch(presentBranch)
, MissingBranch(missingBranch)
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_iterator.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_iterator.cpp
index f31d845141..8eccbb27b5 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_iterator.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_iterator.cpp
@@ -12,7 +12,7 @@ namespace {
class TIteratorWrapper : public TMutableCodegeneratorNode<TIteratorWrapper> {
typedef TMutableCodegeneratorNode<TIteratorWrapper> TBaseComputation;
public:
- TIteratorWrapper(TComputationMutables& mutables, IComputationNode* list, TComputationNodePtrVector&& dependentNodes)
+ TIteratorWrapper(TComputationMutables& mutables, IComputationNode* list, TComputationNodePtrVector&& dependentNodes)
: TBaseComputation(mutables, EValueRepresentation::Boxed), List(list), DependentNodes(std::move(dependentNodes))
{}
@@ -58,7 +58,7 @@ private:
class TForwardListWrapper : public TMutableCodegeneratorNode<TForwardListWrapper> {
typedef TMutableCodegeneratorNode<TForwardListWrapper> TBaseComputation;
public:
- TForwardListWrapper(TComputationMutables& mutables, IComputationNode* stream)
+ TForwardListWrapper(TComputationMutables& mutables, IComputationNode* stream)
: TBaseComputation(mutables, EValueRepresentation::Boxed), Stream(stream)
{}
@@ -268,7 +268,7 @@ IComputationNode* WrapIterator(TCallable& callable, const TComputationNodeFactor
dependentNodes[i - 1] = LocateNode(ctx.NodeLocator, callable, i);
}
- return new TIteratorWrapper(ctx.Mutables, LocateNode(ctx.NodeLocator, callable, 0), std::move(dependentNodes));
+ return new TIteratorWrapper(ctx.Mutables, LocateNode(ctx.NodeLocator, callable, 0), std::move(dependentNodes));
}
IComputationNode* WrapForwardList(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_join.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_join.cpp
index 3cc00db126..d2182bbc23 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_join.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_join.cpp
@@ -1598,11 +1598,11 @@ private:
NUdf::TUnboxedValue LiveValue;
};
-template <EJoinKind Kind, bool TTrackRss>
-class TCommonJoinCoreWrapper : public TMutableComputationNode<TCommonJoinCoreWrapper<Kind, TTrackRss>> {
- using TSelf = TCommonJoinCoreWrapper<Kind, TTrackRss>;
- using TBase = TMutableComputationNode<TSelf>;
- typedef TBase TBaseComputation;
+template <EJoinKind Kind, bool TTrackRss>
+class TCommonJoinCoreWrapper : public TMutableComputationNode<TCommonJoinCoreWrapper<Kind, TTrackRss>> {
+ using TSelf = TCommonJoinCoreWrapper<Kind, TTrackRss>;
+ using TBase = TMutableComputationNode<TSelf>;
+ typedef TBase TBaseComputation;
public:
class TValue : public TComputationValue<TValue> {
public:
@@ -1979,10 +1979,10 @@ public:
std::vector<ui32>&& leftInputColumns, std::vector<ui32>&& rightInputColumns, std::vector<ui32>&& requiredColumns,
std::vector<ui32>&& leftOutputColumns, std::vector<ui32>&& rightOutputColumns, ui64 memLimit,
std::optional<ui32> sortedTableOrder, std::vector<ui32>&& keyColumns, EAnyJoinSettings anyJoinSettings)
- : TBaseComputation(mutables)
- , Stream(stream)
- , InputStructType(inputStructType)
- , Packer(mutables)
+ : TBaseComputation(mutables)
+ , Stream(stream)
+ , InputStructType(inputStructType)
+ , Packer(mutables)
, TableIndexPos(tableIndexPos)
, LeftInputColumns(std::move(leftInputColumns))
, RightInputColumns(std::move(rightInputColumns))
@@ -1993,21 +1993,21 @@ public:
, SortedTableOrder(sortedTableOrder)
, KeyColumns(std::move(keyColumns))
, IsRequiredColumn(FillRequiredStructColumn(inputWidth, RequiredColumns))
- , ResStruct(mutables)
- , ResStreamIndex(mutables.CurValueIndex++)
+ , ResStruct(mutables)
+ , ResStreamIndex(mutables.CurValueIndex++)
, AnyJoinSettings(anyJoinSettings)
{
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- auto& resStream = ctx.MutableValues[ResStreamIndex];
- if (!resStream || resStream.IsInvalid() || !resStream.UniqueBoxed()) {
- resStream = ctx.HolderFactory.Create<TValue>(Stream->GetValue(ctx), ctx, this);
+ auto& resStream = ctx.MutableValues[ResStreamIndex];
+ if (!resStream || resStream.IsInvalid() || !resStream.UniqueBoxed()) {
+ resStream = ctx.HolderFactory.Create<TValue>(Stream->GetValue(ctx), ctx, this);
} else {
- static_cast<TValue&>(*resStream.AsBoxed()).Reset(Stream->GetValue(ctx));
+ static_cast<TValue&>(*resStream.AsBoxed()).Reset(Stream->GetValue(ctx));
}
- return static_cast<const NUdf::TUnboxedValuePod&>(resStream);
+ return static_cast<const NUdf::TUnboxedValuePod&>(resStream);
}
private:
@@ -2030,7 +2030,7 @@ private:
const std::vector<bool> IsRequiredColumn;
const TContainerCacheOnContext ResStruct;
- const ui32 ResStreamIndex;
+ const ui32 ResStreamIndex;
const EAnyJoinSettings AnyJoinSettings;
};
@@ -2149,7 +2149,7 @@ IComputationNode* WrapCommonJoinCore(TCallable& callable, const TComputationNode
AS_VALUE(TDataLiteral, callable.GetInput(11U))->AsValue().Get<ui32>():
AS_TYPE(TStructType, inputRowType)->GetMemberIndex("_yql_table_index");
- const bool trackRss = EGraphPerProcess::Single == ctx.GraphPerProcess;
+ const bool trackRss = EGraphPerProcess::Single == ctx.GraphPerProcess;
const auto flow = LocateNode(ctx.NodeLocator, callable, 0U);
const auto leftInputType = TTupleType::Create(leftTypes.size(), leftTypes.data(), ctx.Env);
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_join_dict.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_join_dict.cpp
index 223ce5ff21..194a4cb15e 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_join_dict.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_join_dict.cpp
@@ -21,10 +21,10 @@ template <bool KeyTuple>
class TJoinDictWrapper : public TMutableCodegeneratorPtrNode<TJoinDictWrapper<KeyTuple>> {
typedef TMutableCodegeneratorPtrNode<TJoinDictWrapper<KeyTuple>> TBaseComputation;
public:
- TJoinDictWrapper(TComputationMutables& mutables, IComputationNode* dict1, IComputationNode* dict2,
+ TJoinDictWrapper(TComputationMutables& mutables, IComputationNode* dict1, IComputationNode* dict2,
bool isMulti1, bool isMulti2, EJoinKind joinKind, std::vector<ui32>&& indexes = std::vector<ui32>())
: TBaseComputation(mutables, EValueRepresentation::Boxed)
- , Dict1(dict1)
+ , Dict1(dict1)
, Dict2(dict2)
, IsMulti1(isMulti1)
, IsMulti2(isMulti2)
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_length.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_length.cpp
index fa3d3d86eb..db5266928c 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_length.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_length.cpp
@@ -13,12 +13,12 @@ template <bool IsDict, bool IsOptional>
class TLengthWrapper : public TMutableCodegeneratorNode<TLengthWrapper<IsDict, IsOptional>> {
typedef TMutableCodegeneratorNode<TLengthWrapper<IsDict, IsOptional>> TBaseComputation;
public:
- TLengthWrapper(TComputationMutables& mutables, IComputationNode* collection)
+ TLengthWrapper(TComputationMutables& mutables, IComputationNode* collection)
: TBaseComputation(mutables, EValueRepresentation::Embedded)
- , Collection(collection)
+ , Collection(collection)
{}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
const auto& collection = Collection->GetValue(compCtx);
if (IsOptional && !collection) {
return NUdf::TUnboxedValuePod();
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_listfromrange.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_listfromrange.cpp
index 50a4e24f39..5eeac1ea86 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_listfromrange.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_listfromrange.cpp
@@ -306,9 +306,9 @@ private:
this->DependsOn(Step);
}
- IComputationNode* const Start;
- IComputationNode* const End;
- IComputationNode* const Step;
+ IComputationNode* const Start;
+ IComputationNode* const End;
+ IComputationNode* const Step;
};
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_logical.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_logical.cpp
index 355ce5b2e1..7a0f69777e 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_logical.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_logical.cpp
@@ -13,13 +13,13 @@ template <bool IsLeftOptional, bool IsRightOptional>
class TAndWrapper : public TBinaryCodegeneratorNode<TAndWrapper<IsLeftOptional, IsRightOptional>> {
typedef TBinaryCodegeneratorNode<TAndWrapper<IsLeftOptional, IsRightOptional>> TBaseComputation;
public:
- TAndWrapper(TComputationMutables& mutables, IComputationNode* left, IComputationNode* right)
+ TAndWrapper(TComputationMutables& mutables, IComputationNode* left, IComputationNode* right)
: TBaseComputation(left, right, EValueRepresentation::Embedded)
{
Y_UNUSED(mutables);
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
const auto& left = this->Left->GetValue(ctx);
if (!IsLeftOptional || left) {
if (!left.template Get<bool>()) {
@@ -85,13 +85,13 @@ template <bool IsLeftOptional, bool IsRightOptional>
class TOrWrapper : public TBinaryCodegeneratorNode<TOrWrapper<IsLeftOptional, IsRightOptional>> {
typedef TBinaryCodegeneratorNode<TOrWrapper<IsLeftOptional, IsRightOptional>> TBaseComputation;
public:
- TOrWrapper(TComputationMutables& mutables, IComputationNode* left, IComputationNode* right)
+ TOrWrapper(TComputationMutables& mutables, IComputationNode* left, IComputationNode* right)
: TBaseComputation(left, right, EValueRepresentation::Embedded)
{
Y_UNUSED(mutables);
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
const auto& left = this->Left->GetValue(ctx);
if (!IsLeftOptional || left) {
if (left.template Get<bool>()) {
@@ -157,13 +157,13 @@ template <bool IsLeftOptional, bool IsRightOptional>
class TXorWrapper : public TBinaryCodegeneratorNode<TXorWrapper<IsLeftOptional, IsRightOptional>> {
typedef TBinaryCodegeneratorNode<TXorWrapper<IsLeftOptional, IsRightOptional>> TBaseComputation;
public:
- TXorWrapper(TComputationMutables& mutables, IComputationNode* left, IComputationNode* right)
+ TXorWrapper(TComputationMutables& mutables, IComputationNode* left, IComputationNode* right)
: TBaseComputation(left, right, EValueRepresentation::Embedded)
{
Y_UNUSED(mutables);
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
const auto& left = this->Left->GetValue(ctx);
if (IsLeftOptional && !left) {
return NUdf::TUnboxedValuePod();
@@ -270,7 +270,7 @@ public:
};
template <template <bool, bool> class TWrapper>
-IComputationNode* WrapLogicalFunction(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
+IComputationNode* WrapLogicalFunction(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
const auto nodeLocator = ctx.NodeLocator;
MKQL_ENSURE(callable.GetInputsCount() == 2, "Expected 2 args");
@@ -284,16 +284,16 @@ IComputationNode* WrapLogicalFunction(TCallable& callable, const TComputationNod
const auto right = LocateNode(nodeLocator, callable, 1);
if (isLeftOptional) {
if (isRightOptional) {
- return new TWrapper<true, true>(ctx.Mutables, left, right);
+ return new TWrapper<true, true>(ctx.Mutables, left, right);
} else {
- return new TWrapper<true, false>(ctx.Mutables, left, right);
+ return new TWrapper<true, false>(ctx.Mutables, left, right);
}
}
else {
if (isRightOptional) {
- return new TWrapper<false, true>(ctx.Mutables, left, right);
+ return new TWrapper<false, true>(ctx.Mutables, left, right);
} else {
- return new TWrapper<false, false>(ctx.Mutables, left, right);
+ return new TWrapper<false, false>(ctx.Mutables, left, right);
}
}
}
@@ -301,15 +301,15 @@ IComputationNode* WrapLogicalFunction(TCallable& callable, const TComputationNod
}
IComputationNode* WrapAnd(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
- return WrapLogicalFunction<TAndWrapper>(callable, ctx);
+ return WrapLogicalFunction<TAndWrapper>(callable, ctx);
}
IComputationNode* WrapOr(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
- return WrapLogicalFunction<TOrWrapper>(callable, ctx);
+ return WrapLogicalFunction<TOrWrapper>(callable, ctx);
}
IComputationNode* WrapXor(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
- return WrapLogicalFunction<TXorWrapper>(callable, ctx);
+ return WrapLogicalFunction<TXorWrapper>(callable, ctx);
}
IComputationNode* WrapNot(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_lookup.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_lookup.cpp
index 2c2ef6de78..732fe3d5fa 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_lookup.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_lookup.cpp
@@ -12,13 +12,13 @@ class TLookupWrapper : public TMutableCodegeneratorPtrNode<TLookupWrapper> {
public:
TLookupWrapper(TComputationMutables& mutables, EValueRepresentation kind, IComputationNode* dict, IComputationNode* key)
: TBaseComputation(mutables, kind)
- , Dict(dict)
+ , Dict(dict)
, Key(key)
{
}
- NUdf::TUnboxedValue DoCalculate(TComputationContext& ctx) const {
- return Dict->GetValue(ctx).Lookup(Key->GetValue(ctx));
+ NUdf::TUnboxedValue DoCalculate(TComputationContext& ctx) const {
+ return Dict->GetValue(ctx).Lookup(Key->GetValue(ctx));
}
#ifndef MKQL_DISABLE_CODEGEN
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_map.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_map.cpp
index 8520eba5dc..04997bd1f1 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_map.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_map.cpp
@@ -75,7 +75,7 @@ protected:
public:
TIterator(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& iter, IComputationExternalNode* item, IComputationNode* newItem)
: TComputationValue<TIterator>(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Iter(std::move(iter))
, Item(item)
, NewItem(newItem)
@@ -87,11 +87,11 @@ protected:
return false;
}
- value = NewItem->GetValue(CompCtx);
+ value = NewItem->GetValue(CompCtx);
return true;
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue Iter;
IComputationExternalNode* const Item;
IComputationNode* const NewItem;
@@ -99,7 +99,7 @@ protected:
TListValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& list, IComputationExternalNode* item, IComputationNode* newItem)
: TCustomListValue(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, List(std::move(list))
, Item(item)
, NewItem(newItem)
@@ -130,7 +130,7 @@ protected:
return List.HasFastListLength();
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue List;
IComputationExternalNode* const Item;
IComputationNode* const NewItem;
@@ -142,7 +142,7 @@ protected:
TStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& stream, IComputationExternalNode* item, IComputationNode* newItem)
: TBase(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Stream(std::move(stream))
, Item(item)
, NewItem(newItem)
@@ -170,11 +170,11 @@ protected:
return status;
}
- result = NewItem->GetValue(CompCtx);
+ result = NewItem->GetValue(CompCtx);
return NUdf::EFetchStatus::Ok;
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue Stream;
IComputationExternalNode* const Item;
IComputationNode* const NewItem;
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_now.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_now.cpp
index f101236ec4..821eedc692 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_now.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_now.cpp
@@ -8,16 +8,16 @@ namespace NMiniKQL {
namespace {
class TNowWrapper : public TMutableComputationNode<TNowWrapper> {
- typedef TMutableComputationNode<TNowWrapper> TBaseComputation;
+ typedef TMutableComputationNode<TNowWrapper> TBaseComputation;
public:
- TNowWrapper(TComputationMutables& mutables, TComputationNodePtrVector&& dependentNodes)
- : TBaseComputation(mutables)
- , DependentNodes(dependentNodes)
+ TNowWrapper(TComputationMutables& mutables, TComputationNodePtrVector&& dependentNodes)
+ : TBaseComputation(mutables)
+ , DependentNodes(dependentNodes)
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- return NUdf::TUnboxedValuePod(ctx.TimeProvider.Now().MicroSeconds());
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ return NUdf::TUnboxedValuePod(ctx.TimeProvider.Now().MicroSeconds());
}
private:
@@ -36,7 +36,7 @@ IComputationNode* WrapNow(TCallable& callable, const TComputationNodeFactoryCont
dependentNodes[i] = LocateNode(ctx.NodeLocator, callable, i);
}
- return new TNowWrapper(ctx.Mutables, std::move(dependentNodes));
+ return new TNowWrapper(ctx.Mutables, std::move(dependentNodes));
}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_pickle.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_pickle.cpp
index 1013cf7dd1..70c5d93d14 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_pickle.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_pickle.cpp
@@ -14,15 +14,15 @@ template <bool Stable>
class TPickleWrapper : public TMutableComputationNode<TPickleWrapper<Stable>> {
typedef TMutableComputationNode<TPickleWrapper<Stable>> TBaseComputation;
public:
- TPickleWrapper(TComputationMutables& mutables, TType* type, IComputationNode* data)
- : TBaseComputation(mutables)
- , Type(type)
- , ValuePacker(mutables)
+ TPickleWrapper(TComputationMutables& mutables, TType* type, IComputationNode* data)
+ : TBaseComputation(mutables)
+ , Type(type)
+ , ValuePacker(mutables)
, Data(data)
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
return MakeString(ValuePacker.RefMutableObject(ctx, Stable, Type).Pack(Data->GetValue(ctx)));
}
@@ -31,24 +31,24 @@ private:
this->DependsOn(Data);
}
- TType* Type;
- TMutableObjectOverBoxedValue<TValuePackerBoxed> ValuePacker;
+ TType* Type;
+ TMutableObjectOverBoxedValue<TValuePackerBoxed> ValuePacker;
IComputationNode *const Data;
};
class TUnpickleWrapper : public TMutableComputationNode<TUnpickleWrapper> {
- typedef TMutableComputationNode<TUnpickleWrapper> TBaseComputation;
+ typedef TMutableComputationNode<TUnpickleWrapper> TBaseComputation;
public:
- TUnpickleWrapper(TComputationMutables& mutables, TType* type, IComputationNode* data)
- : TBaseComputation(mutables)
- , Type(type)
- , ValuePacker(mutables)
+ TUnpickleWrapper(TComputationMutables& mutables, TType* type, IComputationNode* data)
+ : TBaseComputation(mutables)
+ , Type(type)
+ , ValuePacker(mutables)
, Data(data)
{
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- auto data = Data->GetValue(ctx);
+ auto data = Data->GetValue(ctx);
auto buffer = data.AsStringRef();
return ValuePacker.RefMutableObject(ctx, false, Type).Unpack(buffer, ctx.HolderFactory).Release();
}
@@ -58,8 +58,8 @@ private:
DependsOn(Data);
}
- TType* const Type;
- TMutableObjectOverBoxedValue<TValuePackerBoxed> ValuePacker;
+ TType* const Type;
+ TMutableObjectOverBoxedValue<TValuePackerBoxed> ValuePacker;
IComputationNode *const Data;
};
@@ -114,7 +114,7 @@ IComputationNode* WrapStablePickle(TCallable& callable, const TComputationNodeFa
IComputationNode* WrapUnpickle(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
MKQL_ENSURE(callable.GetInputsCount() == 2, "Expected 2 args");
MKQL_ENSURE(callable.GetInput(0).IsImmediate() && callable.GetInput(0).GetNode()->GetType()->IsType(), "Expected type");
- return new TUnpickleWrapper(ctx.Mutables, static_cast<TType*>(callable.GetInput(0).GetNode()), LocateNode(ctx.NodeLocator, callable, 1));
+ return new TUnpickleWrapper(ctx.Mutables, static_cast<TType*>(callable.GetInput(0).GetNode()), LocateNode(ctx.NodeLocator, callable, 1));
}
IComputationNode* WrapAscending(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_prepend.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_prepend.cpp
index c60b89cab4..6789c4208d 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_prepend.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_prepend.cpp
@@ -12,15 +12,15 @@ template<bool IsVoid>
class TPrependWrapper : public TMutableCodegeneratorNode<TPrependWrapper<IsVoid>> {
typedef TMutableCodegeneratorNode<TPrependWrapper<IsVoid>> TBaseComputation;
public:
- TPrependWrapper(TComputationMutables& mutables, IComputationNode* left, IComputationNode* right)
+ TPrependWrapper(TComputationMutables& mutables, IComputationNode* left, IComputationNode* right)
: TBaseComputation(mutables, right->GetRepresentation())
- , Left(left)
+ , Left(left)
, Right(right)
{
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- auto left = Left->GetValue(ctx);
+ auto left = Left->GetValue(ctx);
auto right = Right->GetValue(ctx);
if (IsVoid && !left.IsBoxed())
@@ -117,9 +117,9 @@ IComputationNode* WrapPrepend(TCallable& callable, const TComputationNodeFactory
const auto left = LocateNode(ctx.NodeLocator, callable, 0);
const auto right = LocateNode(ctx.NodeLocator, callable, 1);
if (leftType->IsVoid())
- return new TPrependWrapper<true>(ctx.Mutables, left, right);
+ return new TPrependWrapper<true>(ctx.Mutables, left, right);
else
- return new TPrependWrapper<false>(ctx.Mutables, left, right);
+ return new TPrependWrapper<false>(ctx.Mutables, left, right);
}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_queue.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_queue.cpp
index 1b023e3091..49cc897f0e 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_queue.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_queue.cpp
@@ -1,110 +1,110 @@
-#include "mkql_queue.h"
-
+#include "mkql_queue.h"
+
#include <ydb/library/yql/minikql/computation/mkql_computation_node_holders.h>
#include <ydb/library/yql/minikql/mkql_node_cast.h>
#include <ydb/library/yql/minikql/mkql_program_builder.h>
#include <ydb/library/yql/public/udf/udf_string.h>
-
-namespace NKikimr {
-using namespace NUdf;
-namespace NMiniKQL {
-
+
+namespace NKikimr {
+using namespace NUdf;
+namespace NMiniKQL {
+
namespace {
-class TQueueResource : public TComputationValue<TQueueResource> {
-public:
+class TQueueResource : public TComputationValue<TQueueResource> {
+public:
TQueueResource(TMemoryUsageInfo* memInfo, const TStringBuf& tag, TMaybe<ui64> capacity, ui64 initSize)
- : TComputationValue(memInfo)
- , ResourceTag(tag)
+ : TComputationValue(memInfo)
+ , ResourceTag(tag)
, Buffer(capacity, TUnboxedValue(), initSize)
, BufferBytes(CurrentMemUsage())
- {
+ {
MKQL_MEM_TAKE(memInfo, &Buffer, BufferBytes);
- }
-
- ~TQueueResource() {
+ }
+
+ ~TQueueResource() {
Y_VERIFY_DEBUG(BufferBytes == CurrentMemUsage());
MKQL_MEM_RETURN(GetMemInfo(), &Buffer, CurrentMemUsage());
Buffer.Clear();
- }
-
+ }
+
void UpdateBufferStats() {
MKQL_MEM_RETURN(GetMemInfo(), &Buffer, BufferBytes);
BufferBytes = CurrentMemUsage();
MKQL_MEM_TAKE(GetMemInfo(), &Buffer, BufferBytes);
- }
-
+ }
+
TSafeCircularBuffer<TUnboxedValue>& GetBuffer() {
return Buffer;
}
private:
- NUdf::TStringRef GetResourceTag() const override {
- return NUdf::TStringRef(ResourceTag);
- }
-
- void* GetResource() override {
- return this;
- }
-
+ NUdf::TStringRef GetResourceTag() const override {
+ return NUdf::TStringRef(ResourceTag);
+ }
+
+ void* GetResource() override {
+ return this;
+ }
+
size_t CurrentMemUsage() const {
return Buffer.Size() * sizeof(TUnboxedValue);
}
- const TStringBuf ResourceTag;
- TSafeCircularBuffer<TUnboxedValue> Buffer;
+ const TStringBuf ResourceTag;
+ TSafeCircularBuffer<TUnboxedValue> Buffer;
size_t BufferBytes;
-};
-
-class TQueueResource;
-class TQueueResourceUser {
-public:
- TQueueResourceUser(TStringBuf&& tag, IComputationNode* resource);
+};
+
+class TQueueResource;
+class TQueueResourceUser {
+public:
+ TQueueResourceUser(TStringBuf&& tag, IComputationNode* resource);
TSafeCircularBuffer<NUdf::TUnboxedValue>& CheckAndGetBuffer(const NUdf::TUnboxedValuePod& resource) const;
void UpdateBufferStats(const NUdf::TUnboxedValuePod& resource) const;
-
-protected:
- const TStringBuf Tag;
- IComputationNode* const Resource;
-
+
+protected:
+ const TStringBuf Tag;
+ IComputationNode* const Resource;
+
TQueueResource& GetResource(const NUdf::TUnboxedValuePod& resource) const;
-};
-
-TQueueResourceUser::TQueueResourceUser(TStringBuf&& tag, IComputationNode* resource)
- : Tag(tag)
- , Resource(resource)
-{}
-
+};
+
+TQueueResourceUser::TQueueResourceUser(TStringBuf&& tag, IComputationNode* resource)
+ : Tag(tag)
+ , Resource(resource)
+{}
+
TSafeCircularBuffer<TUnboxedValue>& TQueueResourceUser::CheckAndGetBuffer(const TUnboxedValuePod& resource) const {
- return GetResource(resource).GetBuffer();
-}
-
+ return GetResource(resource).GetBuffer();
+}
+
void TQueueResourceUser::UpdateBufferStats(const TUnboxedValuePod& resource) const {
GetResource(resource).UpdateBufferStats();
-}
-
+}
+
TQueueResource& TQueueResourceUser::GetResource(const TUnboxedValuePod& resource) const {
- const TStringBuf tag = resource.GetResourceTag();
- Y_VERIFY_DEBUG(tag == Tag, "Expected correct Queue resource");
- return *static_cast<TQueueResource*>(resource.GetResource());
-}
-
+ const TStringBuf tag = resource.GetResourceTag();
+ Y_VERIFY_DEBUG(tag == Tag, "Expected correct Queue resource");
+ return *static_cast<TQueueResource*>(resource.GetResource());
+}
+
class TQueueCreateWrapper : public TMutableComputationNode<TQueueCreateWrapper> {
- typedef TMutableComputationNode<TQueueCreateWrapper> TBaseComputation;
-public:
+ typedef TMutableComputationNode<TQueueCreateWrapper> TBaseComputation;
+public:
TQueueCreateWrapper(TComputationMutables& mutables, TComputationNodePtrVector&& dependentNodes, const TString& name, TMaybe<ui64> capacity, ui64 initSize)
- : TBaseComputation(mutables)
- , DependentNodes(std::move(dependentNodes))
+ : TBaseComputation(mutables)
+ , DependentNodes(std::move(dependentNodes))
, Name(name)
- , Capacity(capacity)
- , InitSize(initSize)
- {}
-
+ , Capacity(capacity)
+ , InitSize(initSize)
+ {}
+
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
return NUdf::TUnboxedValuePod(new TQueueResource(&ctx.HolderFactory.GetMemInfo(), Name, Capacity, InitSize));
- }
-
-private:
+ }
+
+private:
void RegisterDependencies() const final {
std::for_each(DependentNodes.cbegin(), DependentNodes.cend(), std::bind(&TQueueCreateWrapper::DependsOn, this, std::placeholders::_1));
}
@@ -112,84 +112,84 @@ private:
const TComputationNodePtrVector DependentNodes;
const TString Name;
const TMaybe<ui64> Capacity;
- const ui64 InitSize;
-};
-
-class TQueuePushWrapper : public TMutableComputationNode<TQueuePushWrapper>, public TQueueResourceUser {
- typedef TMutableComputationNode<TQueuePushWrapper> TBaseComputation;
-public:
- TQueuePushWrapper(TComputationMutables& mutables, const TResourceType* resourceType, IComputationNode* resource, IComputationNode* value)
- : TBaseComputation(mutables)
- , TQueueResourceUser(resourceType->GetTag(), resource)
- , Value(value)
- {}
-
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- auto resource = Resource->GetValue(ctx);
- auto& buffer = CheckAndGetBuffer(resource);
+ const ui64 InitSize;
+};
+
+class TQueuePushWrapper : public TMutableComputationNode<TQueuePushWrapper>, public TQueueResourceUser {
+ typedef TMutableComputationNode<TQueuePushWrapper> TBaseComputation;
+public:
+ TQueuePushWrapper(TComputationMutables& mutables, const TResourceType* resourceType, IComputationNode* resource, IComputationNode* value)
+ : TBaseComputation(mutables)
+ , TQueueResourceUser(resourceType->GetTag(), resource)
+ , Value(value)
+ {}
+
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ auto resource = Resource->GetValue(ctx);
+ auto& buffer = CheckAndGetBuffer(resource);
buffer.PushBack(Value->GetValue(ctx));
if (buffer.IsUnbounded()) {
UpdateBufferStats(resource);
- }
+ }
return resource.Release();
- }
-
+ }
+
private:
void RegisterDependencies() const final {
DependsOn(Resource);
DependsOn(Value);
- }
-
- IComputationNode* const Value;
-};
-
-class TQueuePopWrapper : public TMutableComputationNode<TQueuePopWrapper>, public TQueueResourceUser {
- typedef TMutableComputationNode<TQueuePopWrapper> TBaseComputation;
-public:
- TQueuePopWrapper(TComputationMutables& mutables, const TResourceType* resourceType, IComputationNode* resource)
- : TBaseComputation(mutables)
- , TQueueResourceUser(resourceType->GetTag(), resource)
- {}
-
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- auto resource = Resource->GetValue(ctx);
- CheckAndGetBuffer(resource).PopFront();
+ }
+
+ IComputationNode* const Value;
+};
+
+class TQueuePopWrapper : public TMutableComputationNode<TQueuePopWrapper>, public TQueueResourceUser {
+ typedef TMutableComputationNode<TQueuePopWrapper> TBaseComputation;
+public:
+ TQueuePopWrapper(TComputationMutables& mutables, const TResourceType* resourceType, IComputationNode* resource)
+ : TBaseComputation(mutables)
+ , TQueueResourceUser(resourceType->GetTag(), resource)
+ {}
+
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ auto resource = Resource->GetValue(ctx);
+ CheckAndGetBuffer(resource).PopFront();
return resource.Release();
- }
-
+ }
+
private:
void RegisterDependencies() const final {
DependsOn(Resource);
- }
-};
-
+ }
+};
+
class TQueuePeekWrapper : public TMutableComputationNode<TQueuePeekWrapper>, public TQueueResourceUser {
- typedef TMutableComputationNode<TQueuePeekWrapper> TBaseComputation;
-public:
- TQueuePeekWrapper(TComputationMutables& mutables, TComputationNodePtrVector&& dependentNodes, const TResourceType* resourceType, IComputationNode* resource, IComputationNode* index)
- : TBaseComputation(mutables)
- , TQueueResourceUser(resourceType->GetTag(), resource)
+ typedef TMutableComputationNode<TQueuePeekWrapper> TBaseComputation;
+public:
+ TQueuePeekWrapper(TComputationMutables& mutables, TComputationNodePtrVector&& dependentNodes, const TResourceType* resourceType, IComputationNode* resource, IComputationNode* index)
+ : TBaseComputation(mutables)
+ , TQueueResourceUser(resourceType->GetTag(), resource)
, Index(index), DependentNodes(std::move(dependentNodes))
- {}
-
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- auto resource = Resource->GetValue(ctx);
- auto index = Index->GetValue(ctx);
- const auto& valRef = CheckAndGetBuffer(resource).Get(index.Get<ui64>());
+ {}
+
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ auto resource = Resource->GetValue(ctx);
+ auto index = Index->GetValue(ctx);
+ const auto& valRef = CheckAndGetBuffer(resource).Get(index.Get<ui64>());
return !valRef ? NUdf::TUnboxedValuePod() : valRef.MakeOptional();
- }
-
+ }
+
private:
void RegisterDependencies() const final {
DependsOn(Resource);
DependsOn(Index);
std::for_each(DependentNodes.cbegin(), DependentNodes.cend(), std::bind(&TQueuePeekWrapper::DependsOn, this, std::placeholders::_1));
- }
-
- IComputationNode* const Index;
+ }
+
+ IComputationNode* const Index;
const TComputationNodePtrVector DependentNodes;
-};
-
+};
+
class TQueueRangeWrapper : public TMutableComputationNode<TQueueRangeWrapper>, public TQueueResourceUser {
typedef TMutableComputationNode<TQueueRangeWrapper> TBaseComputation;
public:
@@ -303,144 +303,144 @@ private:
};
class TPreserveStreamValue : public TComputationValue<TPreserveStreamValue>, public TQueueResourceUser {
-public:
- using TBase = TComputationValue<TPreserveStreamValue>;
-
- TPreserveStreamValue(TMemoryUsageInfo* memInfo, NUdf::TUnboxedValue&& stream
+public:
+ using TBase = TComputationValue<TPreserveStreamValue>;
+
+ TPreserveStreamValue(TMemoryUsageInfo* memInfo, NUdf::TUnboxedValue&& stream
, NUdf::TUnboxedValue&& queue, TStringBuf tag, IComputationNode* resource, ui64 outpace)
- : TBase(memInfo)
+ : TBase(memInfo)
, TQueueResourceUser(std::move(tag), resource)
- , Stream(std::move(stream))
+ , Stream(std::move(stream))
, Queue(std::move(queue))
- , OutpaceGoal(outpace)
+ , OutpaceGoal(outpace)
, Buffer(CheckAndGetBuffer(Queue))
- , FrontIndex(Buffer.UsedSize())
- {}
-
+ , FrontIndex(Buffer.UsedSize())
+ {}
+
private:
- NUdf::EFetchStatus Fetch(NUdf::TUnboxedValue& value) override {
- NUdf::TUnboxedValue item;
- if (State != EPreserveState::Feed) {
- Buffer.PopFront();
- --Outpace;
- }
+ NUdf::EFetchStatus Fetch(NUdf::TUnboxedValue& value) override {
+ NUdf::TUnboxedValue item;
+ if (State != EPreserveState::Feed) {
+ Buffer.PopFront();
+ --Outpace;
+ }
while (State != EPreserveState::Emit && Outpace <= OutpaceGoal) {
- switch (Stream.Fetch(item)) {
- case NUdf::EFetchStatus::Yield:
- return NUdf::EFetchStatus::Yield;
- case NUdf::EFetchStatus::Finish:
- State = EPreserveState::Emit;
- break;
- case NUdf::EFetchStatus::Ok:
- Buffer.PushBack(std::move(item));
+ switch (Stream.Fetch(item)) {
+ case NUdf::EFetchStatus::Yield:
+ return NUdf::EFetchStatus::Yield;
+ case NUdf::EFetchStatus::Finish:
+ State = EPreserveState::Emit;
+ break;
+ case NUdf::EFetchStatus::Ok:
+ Buffer.PushBack(std::move(item));
if (Buffer.IsUnbounded()) {
UpdateBufferStats(Queue);
}
- ++Outpace;
+ ++Outpace;
if (Outpace > OutpaceGoal) {
- State = EPreserveState::GoOn;
- }
- }
- }
- if (!Outpace) {
- Buffer.Clean();
- return NUdf::EFetchStatus::Finish;
- }
- value = Buffer.Get(FrontIndex);
- return NUdf::EFetchStatus::Ok;
- }
-
- enum class EPreserveState {
- Feed,
- GoOn,
- Emit,
- };
+ State = EPreserveState::GoOn;
+ }
+ }
+ }
+ if (!Outpace) {
+ Buffer.Clean();
+ return NUdf::EFetchStatus::Finish;
+ }
+ value = Buffer.Get(FrontIndex);
+ return NUdf::EFetchStatus::Ok;
+ }
+
+ enum class EPreserveState {
+ Feed,
+ GoOn,
+ Emit,
+ };
const NUdf::TUnboxedValue Stream;
const NUdf::TUnboxedValue Queue;
const ui64 OutpaceGoal;
- TSafeCircularBuffer<TUnboxedValue>& Buffer;
+ TSafeCircularBuffer<TUnboxedValue>& Buffer;
const size_t FrontIndex;
-
- EPreserveState State = EPreserveState::Feed;
- ui64 Outpace = 0;
-};
-
-class TPreserveStreamWrapper : public TMutableComputationNode<TPreserveStreamWrapper>, public TQueueResourceUser {
- typedef TMutableComputationNode<TPreserveStreamWrapper> TBaseComputation;
-public:
+
+ EPreserveState State = EPreserveState::Feed;
+ ui64 Outpace = 0;
+};
+
+class TPreserveStreamWrapper : public TMutableComputationNode<TPreserveStreamWrapper>, public TQueueResourceUser {
+ typedef TMutableComputationNode<TPreserveStreamWrapper> TBaseComputation;
+public:
TPreserveStreamWrapper(TComputationMutables& mutables, IComputationNode* stream, const TResourceType* resourceType, IComputationNode* resource, ui64 outpace)
- : TBaseComputation(mutables)
- , TQueueResourceUser(resourceType->GetTag(), resource)
- , Stream(stream)
- , Outpace(outpace)
- {}
-
+ : TBaseComputation(mutables)
+ , TQueueResourceUser(resourceType->GetTag(), resource)
+ , Stream(stream)
+ , Outpace(outpace)
+ {}
+
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
return ctx.HolderFactory.Create<TPreserveStreamValue>(Stream->GetValue(ctx), Resource->GetValue(ctx), Tag, Resource, Outpace);
- }
-
+ }
+
private:
void RegisterDependencies() const final {
DependsOn(Resource);
DependsOn(Stream);
- }
-
- IComputationNode* const Stream;
+ }
+
+ IComputationNode* const Stream;
const ui64 Outpace;
-};
-
+};
+
template<class T, class...Args>
IComputationNode* MakeNodeWithDeps(TCallable& callable, const TComputationNodeFactoryContext& ctx, unsigned reqArgs, Args...args) {
TComputationNodePtrVector dependentNodes(callable.GetInputsCount() - reqArgs);
- for (ui32 i = reqArgs; i < callable.GetInputsCount(); ++i) {
- dependentNodes[i - reqArgs] = LocateNode(ctx.NodeLocator, callable, i);
- }
- return new T(ctx.Mutables, std::move(dependentNodes), std::forward<Args>(args)...);
-}
-
+ for (ui32 i = reqArgs; i < callable.GetInputsCount(); ++i) {
+ dependentNodes[i - reqArgs] = LocateNode(ctx.NodeLocator, callable, i);
+ }
+ return new T(ctx.Mutables, std::move(dependentNodes), std::forward<Args>(args)...);
+}
+
}
-IComputationNode* WrapQueueCreate(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
- const unsigned reqArgs = 3;
- MKQL_ENSURE(callable.GetInputsCount() >= reqArgs, "QueueCreate: Expected at least " << reqArgs << " arg");
- auto queueNameValue = AS_VALUE(TDataLiteral, callable.GetInput(0));
+IComputationNode* WrapQueueCreate(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
+ const unsigned reqArgs = 3;
+ MKQL_ENSURE(callable.GetInputsCount() >= reqArgs, "QueueCreate: Expected at least " << reqArgs << " arg");
+ auto queueNameValue = AS_VALUE(TDataLiteral, callable.GetInput(0));
TMaybe<ui64> capacity;
if (!callable.GetInput(1).GetStaticType()->IsVoid()) {
auto queueCapacityValue = AS_VALUE(TDataLiteral, callable.GetInput(1));
capacity = queueCapacityValue->AsValue().Get<ui64>();
}
- auto queueInitSizeValue = AS_VALUE(TDataLiteral, callable.GetInput(2));
+ auto queueInitSizeValue = AS_VALUE(TDataLiteral, callable.GetInput(2));
const TString name(queueNameValue->AsValue().AsStringRef());
const auto initSize = queueInitSizeValue->AsValue().Get<ui64>();
return MakeNodeWithDeps<TQueueCreateWrapper>(callable, ctx, reqArgs, name, capacity, initSize);
-}
-
-IComputationNode* WrapQueuePush(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
- MKQL_ENSURE(callable.GetInputsCount() == 2, "QueuePush: Expected 2 arg");
- auto resourceType = AS_TYPE(TResourceType, callable.GetInput(0));
- auto resource = LocateNode(ctx.NodeLocator, callable, 0);
- auto value = LocateNode(ctx.NodeLocator, callable, 1);
- return new TQueuePushWrapper(ctx.Mutables, resourceType, resource, value);
-}
-
-IComputationNode* WrapQueuePop(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
- MKQL_ENSURE(callable.GetInputsCount() == 1, "QueuePop: Expected 1 arg");
- auto resourceType = AS_TYPE(TResourceType, callable.GetInput(0));
- auto resource = LocateNode(ctx.NodeLocator, callable, 0);
- return new TQueuePopWrapper(ctx.Mutables, resourceType, resource);
-}
-
-IComputationNode* WrapQueuePeek(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
- const unsigned reqArgs = 2;
- MKQL_ENSURE(callable.GetInputsCount() >= reqArgs, "QueuePeek: Expected at least " << reqArgs << " arg");
- auto resourceType = AS_TYPE(TResourceType, callable.GetInput(0));
- TDataType* indexType = AS_TYPE(TDataType, callable.GetInput(1));
+}
+
+IComputationNode* WrapQueuePush(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
+ MKQL_ENSURE(callable.GetInputsCount() == 2, "QueuePush: Expected 2 arg");
+ auto resourceType = AS_TYPE(TResourceType, callable.GetInput(0));
+ auto resource = LocateNode(ctx.NodeLocator, callable, 0);
+ auto value = LocateNode(ctx.NodeLocator, callable, 1);
+ return new TQueuePushWrapper(ctx.Mutables, resourceType, resource, value);
+}
+
+IComputationNode* WrapQueuePop(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
+ MKQL_ENSURE(callable.GetInputsCount() == 1, "QueuePop: Expected 1 arg");
+ auto resourceType = AS_TYPE(TResourceType, callable.GetInput(0));
+ auto resource = LocateNode(ctx.NodeLocator, callable, 0);
+ return new TQueuePopWrapper(ctx.Mutables, resourceType, resource);
+}
+
+IComputationNode* WrapQueuePeek(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
+ const unsigned reqArgs = 2;
+ MKQL_ENSURE(callable.GetInputsCount() >= reqArgs, "QueuePeek: Expected at least " << reqArgs << " arg");
+ auto resourceType = AS_TYPE(TResourceType, callable.GetInput(0));
+ TDataType* indexType = AS_TYPE(TDataType, callable.GetInput(1));
MKQL_ENSURE(indexType->GetSchemeType() == NUdf::TDataType<ui64>::Id, "Expected ui64 as queue index");
- auto resource = LocateNode(ctx.NodeLocator, callable, 0);
- auto index = LocateNode(ctx.NodeLocator, callable, 1);
+ auto resource = LocateNode(ctx.NodeLocator, callable, 0);
+ auto index = LocateNode(ctx.NodeLocator, callable, 1);
return MakeNodeWithDeps<TQueuePeekWrapper>(callable, ctx, reqArgs, resourceType, resource, index);
-}
-
+}
+
IComputationNode* WrapQueueRange(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
const unsigned reqArgs = 3;
MKQL_ENSURE(callable.GetInputsCount() >= reqArgs, "QueueRange: Expected at least " << reqArgs << " arg");
@@ -458,16 +458,16 @@ IComputationNode* WrapQueueRange(TCallable& callable, const TComputationNodeFact
return MakeNodeWithDeps<TQueueRangeWrapper>(callable, ctx, reqArgs, resourceType, resource, beginIndex, endIndex);
}
-IComputationNode* WrapPreserveStream(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
- Y_UNUSED(ctx);
+IComputationNode* WrapPreserveStream(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
+ Y_UNUSED(ctx);
MKQL_ENSURE(callable.GetInputsCount() == 3, "PreserveStream: Expected 3 arg");
- auto stream = LocateNode(ctx.NodeLocator, callable, 0);
- auto resource = LocateNode(ctx.NodeLocator, callable, 1);
- auto resourceType = AS_TYPE(TResourceType, callable.GetInput(1));
+ auto stream = LocateNode(ctx.NodeLocator, callable, 0);
+ auto resource = LocateNode(ctx.NodeLocator, callable, 1);
+ auto resourceType = AS_TYPE(TResourceType, callable.GetInput(1));
auto outpaceValue = AS_VALUE(TDataLiteral, callable.GetInput(2));
const auto outpace = outpaceValue->AsValue().Get<ui64>();
- return new TPreserveStreamWrapper(ctx.Mutables, stream, resourceType, resource, outpace);
-}
-
-}
-}
+ return new TPreserveStreamWrapper(ctx.Mutables, stream, resourceType, resource, outpace);
+}
+
+}
+}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_queue.h b/ydb/library/yql/minikql/comp_nodes/mkql_queue.h
index 558b1b6b97..8b59f441f7 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_queue.h
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_queue.h
@@ -1,18 +1,18 @@
-#pragma once
+#pragma once
#include <ydb/library/yql/minikql/computation/mkql_computation_node.h>
-#include "mkql_safe_circular_buffer.h"
-
+#include "mkql_safe_circular_buffer.h"
+
#include <ydb/library/yql/public/udf/udf_value.h>
-
-namespace NKikimr {
-namespace NMiniKQL {
-
-IComputationNode* WrapQueueCreate(TCallable& callable, const TComputationNodeFactoryContext& ctx);
-IComputationNode* WrapQueuePush(TCallable& callable, const TComputationNodeFactoryContext& ctx);
-IComputationNode* WrapQueuePop(TCallable& callable, const TComputationNodeFactoryContext& ctx);
-IComputationNode* WrapQueuePeek(TCallable& callable, const TComputationNodeFactoryContext& ctx);
+
+namespace NKikimr {
+namespace NMiniKQL {
+
+IComputationNode* WrapQueueCreate(TCallable& callable, const TComputationNodeFactoryContext& ctx);
+IComputationNode* WrapQueuePush(TCallable& callable, const TComputationNodeFactoryContext& ctx);
+IComputationNode* WrapQueuePop(TCallable& callable, const TComputationNodeFactoryContext& ctx);
+IComputationNode* WrapQueuePeek(TCallable& callable, const TComputationNodeFactoryContext& ctx);
IComputationNode* WrapQueueRange(TCallable& callable, const TComputationNodeFactoryContext& ctx);
-IComputationNode* WrapPreserveStream(TCallable& callable, const TComputationNodeFactoryContext& ctx);
-
-}
-}
+IComputationNode* WrapPreserveStream(TCallable& callable, const TComputationNodeFactoryContext& ctx);
+
+}
+}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_random.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_random.cpp
index 4cde4dbd0a..b489966771 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_random.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_random.cpp
@@ -31,16 +31,16 @@ private:
};
class TNewMTRandWrapper : public TMutableComputationNode<TNewMTRandWrapper> {
- typedef TMutableComputationNode<TNewMTRandWrapper> TBaseComputation;
+ typedef TMutableComputationNode<TNewMTRandWrapper> TBaseComputation;
public:
- TNewMTRandWrapper(TComputationMutables& mutables, IComputationNode* seed)
- : TBaseComputation(mutables)
- , Seed(seed)
+ TNewMTRandWrapper(TComputationMutables& mutables, IComputationNode* seed)
+ : TBaseComputation(mutables)
+ , Seed(seed)
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
- const ui64 seedValue = Seed->GetValue(compCtx).Get<ui64>();
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
+ const ui64 seedValue = Seed->GetValue(compCtx).Get<ui64>();
return compCtx.HolderFactory.Create<TRandomMTResource>(seedValue);
}
@@ -53,17 +53,17 @@ private:
};
class TNextMTRandWrapper : public TMutableComputationNode<TNextMTRandWrapper> {
- typedef TMutableComputationNode<TNextMTRandWrapper> TBaseComputation;
+ typedef TMutableComputationNode<TNextMTRandWrapper> TBaseComputation;
public:
- TNextMTRandWrapper(TComputationMutables& mutables, IComputationNode* rand)
- : TBaseComputation(mutables)
- , Rand(rand)
- , ResPair(mutables)
+ TNextMTRandWrapper(TComputationMutables& mutables, IComputationNode* rand)
+ : TBaseComputation(mutables)
+ , Rand(rand)
+ , ResPair(mutables)
{
}
NUdf::TUnboxedValue DoCalculate(TComputationContext& compCtx) const {
- auto rand = Rand->GetValue(compCtx);
+ auto rand = Rand->GetValue(compCtx);
Y_VERIFY_DEBUG(rand.GetResourceTag() == NUdf::TStringRef(RandomMTResource));
NUdf::TUnboxedValue *items = nullptr;
const auto tuple = ResPair.NewArray(compCtx, 2, items);
@@ -85,18 +85,18 @@ template <ERandom Rnd>
class TRandomWrapper : public TMutableComputationNode<TRandomWrapper<Rnd>> {
typedef TMutableComputationNode<TRandomWrapper<Rnd>> TBaseComputation;
public:
- TRandomWrapper(TComputationMutables& mutables, TComputationNodePtrVector&& dependentNodes)
- : TBaseComputation(mutables)
- , DependentNodes(dependentNodes)
+ TRandomWrapper(TComputationMutables& mutables, TComputationNodePtrVector&& dependentNodes)
+ : TBaseComputation(mutables)
+ , DependentNodes(dependentNodes)
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
switch (Rnd) {
case ERandom::Double:
- return NUdf::TUnboxedValuePod(ctx.RandomProvider.GenRandReal2());
+ return NUdf::TUnboxedValuePod(ctx.RandomProvider.GenRandReal2());
case ERandom::Number:
- return NUdf::TUnboxedValuePod(ctx.RandomProvider.GenRand64());
+ return NUdf::TUnboxedValuePod(ctx.RandomProvider.GenRand64());
case ERandom::Uuid: {
auto uuid = ctx.RandomProvider.GenUuid4();
return MakeString(NUdf::TStringRef((const char*)&uuid, sizeof(uuid)));
@@ -124,7 +124,7 @@ IComputationNode* WrapNewMTRand(TCallable& callable, const TComputationNodeFacto
"Expected ui64");
auto data = LocateNode(ctx.NodeLocator, callable, 0);
- return new TNewMTRandWrapper(ctx.Mutables, data);
+ return new TNewMTRandWrapper(ctx.Mutables, data);
}
IComputationNode* WrapNextMTRand(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
@@ -133,7 +133,7 @@ IComputationNode* WrapNextMTRand(TCallable& callable, const TComputationNodeFact
AS_TYPE(TResourceType, callable.GetInput(0));
auto rand = LocateNode(ctx.NodeLocator, callable, 0);
- return new TNextMTRandWrapper(ctx.Mutables, rand);
+ return new TNextMTRandWrapper(ctx.Mutables, rand);
}
template <ERandom Rnd>
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_reduce.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_reduce.cpp
index 2f66805838..a0bf05f0ac 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_reduce.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_reduce.cpp
@@ -17,7 +17,7 @@ public:
IComputationNode* initialState1, IComputationExternalNode* itemState2, IComputationExternalNode* state3,
IComputationNode* newState3, IComputationNode* initialState3)
: TBaseComputation(mutables, kind)
- , List(list)
+ , List(list)
, Item(item)
, State1(state1)
, NewState1(newState1)
@@ -30,19 +30,19 @@ public:
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
- State1->SetValue(compCtx, InitialState1->GetValue(compCtx));
- State3->SetValue(compCtx, InitialState3->GetValue(compCtx));
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx) const {
+ State1->SetValue(compCtx, InitialState1->GetValue(compCtx));
+ State3->SetValue(compCtx, InitialState3->GetValue(compCtx));
- TThresher<IsStream>::DoForEachItem(List->GetValue(compCtx),
- [this, &compCtx] (NUdf::TUnboxedValue&& item) {
- Item->SetValue(compCtx, std::move(item));
- State1->SetValue(compCtx, NewState1->GetValue(compCtx));
+ TThresher<IsStream>::DoForEachItem(List->GetValue(compCtx),
+ [this, &compCtx] (NUdf::TUnboxedValue&& item) {
+ Item->SetValue(compCtx, std::move(item));
+ State1->SetValue(compCtx, NewState1->GetValue(compCtx));
}
);
- ItemState2->SetValue(compCtx, NewState2->GetValue(compCtx));
- return NewState3->GetValue(compCtx).Release();
+ ItemState2->SetValue(compCtx, NewState2->GetValue(compCtx));
+ return NewState3->GetValue(compCtx).Release();
}
#ifndef MKQL_DISABLE_CODEGEN
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_removemember.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_removemember.cpp
index 07c8df667c..bd5f29452c 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_removemember.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_removemember.cpp
@@ -13,14 +13,14 @@ class TRemoveMemberWrapper : public TMutableCodegeneratorFallbackNode<TRemoveMem
public:
TRemoveMemberWrapper(TComputationMutables& mutables, IComputationNode* structObj, ui32 index, std::vector<EValueRepresentation>&& representations)
: TBaseComputation(mutables, EValueRepresentation::Boxed)
- , StructObj(structObj)
+ , StructObj(structObj)
, Index(index)
, Representations(std::move(representations))
- , Cache(mutables)
+ , Cache(mutables)
{}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- const auto& baseStruct = StructObj->GetValue(ctx);
+ const auto& baseStruct = StructObj->GetValue(ctx);
NUdf::TUnboxedValue* itemsPtr = nullptr;
const auto result = Cache.NewArray(ctx, Representations.size() - 1U, itemsPtr);
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_replicate.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_replicate.cpp
index 9822b5cba0..44489b6266 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_replicate.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_replicate.cpp
@@ -10,7 +10,7 @@ namespace NMiniKQL {
namespace {
class TReplicateWrapper : public TMutableComputationNode<TReplicateWrapper> {
- typedef TMutableComputationNode<TReplicateWrapper> TBaseComputation;
+ typedef TMutableComputationNode<TReplicateWrapper> TBaseComputation;
public:
class TValue : public TCustomListValue {
public:
@@ -190,15 +190,15 @@ public:
TReplicateWrapper(TComputationMutables& mutables, IComputationNode* item, IComputationNode* count,
NUdf::TSourcePosition pos)
- : TBaseComputation(mutables)
- , Item(item)
+ : TBaseComputation(mutables)
+ , Item(item)
, Count(count)
, Pos(pos)
{
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- const auto count = Count->GetValue(ctx).Get<ui64>();
+ const auto count = Count->GetValue(ctx).Get<ui64>();
const ui64 MAX_VALUE = 1ull << 32;
if (count >= MAX_VALUE) {
TStringBuilder res;
@@ -210,7 +210,7 @@ public:
return ctx.HolderFactory.GetEmptyContainer();
}
- return ctx.HolderFactory.Create<TValue>(ctx, Item->GetValue(ctx), count);
+ return ctx.HolderFactory.Create<TValue>(ctx, Item->GetValue(ctx), count);
}
private:
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_reverse.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_reverse.cpp
index 7dfc60f439..4056cfdf67 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_reverse.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_reverse.cpp
@@ -11,9 +11,9 @@ namespace {
class TReverseWrapper : public TMutableCodegeneratorNode<TReverseWrapper> {
typedef TMutableCodegeneratorNode<TReverseWrapper> TBaseComputation;
public:
- TReverseWrapper(TComputationMutables& mutables, IComputationNode* list)
+ TReverseWrapper(TComputationMutables& mutables, IComputationNode* list)
: TBaseComputation(mutables, list->GetRepresentation())
- , List(list)
+ , List(list)
{
}
@@ -66,7 +66,7 @@ private:
IComputationNode* WrapReverse(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
MKQL_ENSURE(callable.GetInputsCount() == 1, "Expected 1 arg");
- return new TReverseWrapper(ctx.Mutables, LocateNode(ctx.NodeLocator, callable, 0));
+ return new TReverseWrapper(ctx.Mutables, LocateNode(ctx.NodeLocator, callable, 0));
}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_safe_circular_buffer.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_safe_circular_buffer.cpp
index ad00157573..c6cda95212 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_safe_circular_buffer.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_safe_circular_buffer.cpp
@@ -1 +1 @@
-#include "mkql_safe_circular_buffer.h"
+#include "mkql_safe_circular_buffer.h"
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_safe_circular_buffer.h b/ydb/library/yql/minikql/comp_nodes/mkql_safe_circular_buffer.h
index 68a7ffe9b8..282349756b 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_safe_circular_buffer.h
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_safe_circular_buffer.h
@@ -1,32 +1,32 @@
-#pragma once
+#pragma once
#include <ydb/library/yql/utils/yql_panic.h>
-#include <util/system/yassert.h>
+#include <util/system/yassert.h>
#include <util/generic/maybe.h>
#include <vector>
-
-namespace NKikimr {
-namespace NMiniKQL {
-
-template<class T>
-class TSafeCircularBuffer {
-public:
+
+namespace NKikimr {
+namespace NMiniKQL {
+
+template<class T>
+class TSafeCircularBuffer {
+public:
TSafeCircularBuffer(TMaybe<size_t> size, T emptyValue, size_t initSize = 0)
: Buffer(size ? *size : initSize, emptyValue)
- , EmptyValue(emptyValue)
+ , EmptyValue(emptyValue)
, Unbounded(!size.Defined())
, Count(initSize)
- {
+ {
if (!Unbounded) {
Y_VERIFY(initSize <= *size);
}
- }
-
+ }
+
bool IsUnbounded() const {
return Unbounded;
- }
-
- void PushBack(T&& data) {
+ }
+
+ void PushBack(T&& data) {
if (Unbounded) {
Y_VERIFY(Head + Count == Size());
Buffer.emplace_back(std::move(data));
@@ -36,61 +36,61 @@ public:
}
Count++;
MutationCount++;
- }
-
- const T& Get(size_t index) const {
+ }
+
+ const T& Get(size_t index) const {
if (index < Count) {
- return Buffer[RealIndex(Head + index)];
- } else {
- // Circular buffer out of bounds
- return EmptyValue;
- }
- }
-
- void PopFront() {
+ return Buffer[RealIndex(Head + index)];
+ } else {
+ // Circular buffer out of bounds
+ return EmptyValue;
+ }
+ }
+
+ void PopFront() {
if (!Count) {
- // Circular buffer not have elements for pop, no elements, no problem
- } else {
- Buffer[Head] = EmptyValue;
+ // Circular buffer not have elements for pop, no elements, no problem
+ } else {
+ Buffer[Head] = EmptyValue;
Head = RealIndex(Head+1);
Count--;
- }
+ }
MutationCount++;
- }
-
+ }
+
size_t Size() const {
return Buffer.size();
- }
-
- size_t UsedSize() const {
+ }
+
+ size_t UsedSize() const {
return Count;
- }
-
+ }
+
ui64 Generation() const {
return MutationCount;
}
- void Clean() {
- const auto usedSize = UsedSize();
- for (size_t index = 0; index < usedSize; ++index) {
- Buffer[RealIndex(Head + index)] = EmptyValue;
- }
- }
-
- void Clear() {
+ void Clean() {
+ const auto usedSize = UsedSize();
+ for (size_t index = 0; index < usedSize; ++index) {
+ Buffer[RealIndex(Head + index)] = EmptyValue;
+ }
+ }
+
+ void Clear() {
Head = Count = 0;
Buffer.clear();
Buffer.shrink_to_fit();
- }
-
+ }
+
private:
bool IsFull() const {
if (Unbounded) {
return false;
}
return UsedSize() == Size();
- }
-
+ }
+
size_t RealIndex(size_t index) const {
auto size = Size();
Y_VERIFY(size);
@@ -98,12 +98,12 @@ private:
}
std::vector<T> Buffer;
- const T EmptyValue;
+ const T EmptyValue;
const bool Unbounded;
- size_t Head = 0;
+ size_t Head = 0;
size_t Count;
ui64 MutationCount = 0;
-};
-
-}
-}
+};
+
+}
+}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_size.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_size.cpp
index 75761bdd84..57c4268416 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_size.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_size.cpp
@@ -36,13 +36,13 @@ template<bool IsOptional>
class TSizeWrapper : public TMutableCodegeneratorNode<TSizeWrapper<IsOptional>> {
typedef TMutableCodegeneratorNode<TSizeWrapper<IsOptional>> TBaseComputation;
public:
- TSizeWrapper(TComputationMutables& mutables, IComputationNode* data)
+ TSizeWrapper(TComputationMutables& mutables, IComputationNode* data)
: TBaseComputation(mutables, EValueRepresentation::Embedded)
- , Data(data)
+ , Data(data)
{}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- const auto& data = Data->GetValue(ctx);
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ const auto& data = Data->GetValue(ctx);
if (IsOptional && !data) {
return NUdf::TUnboxedValuePod();
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_skip.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_skip.cpp
index b106dabcc9..62a7f10f24 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_skip.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_skip.cpp
@@ -283,9 +283,9 @@ private:
class TSkipWrapper : public TMutableCodegeneratorNode<TSkipWrapper> {
typedef TMutableCodegeneratorNode<TSkipWrapper> TBaseComputation;
public:
- TSkipWrapper(TComputationMutables& mutables, IComputationNode* list, IComputationNode* count)
+ TSkipWrapper(TComputationMutables& mutables, IComputationNode* list, IComputationNode* count)
: TBaseComputation(mutables, list->GetRepresentation())
- , List(list)
+ , List(list)
, Count(count)
{
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_sort.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_sort.cpp
index d54654b97f..2f67b24406 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_sort.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_sort.cpp
@@ -15,16 +15,16 @@ namespace {
std::vector<NUdf::EDataSlot> PrepareKeyTypesByScheme(const std::vector<std::tuple<NUdf::EDataSlot, bool, TType*>>& keySchemeTypes) {
MKQL_ENSURE(!keySchemeTypes.empty(), "No key types provided");
- std::vector<NUdf::EDataSlot> keyTypes;
- keyTypes.reserve(keySchemeTypes.size());
+ std::vector<NUdf::EDataSlot> keyTypes;
+ keyTypes.reserve(keySchemeTypes.size());
for (const auto& schemeType: keySchemeTypes) {
keyTypes.emplace_back(std::get<0>(schemeType));
const auto& info = NUdf::GetDataTypeInfo(keyTypes.back());
- MKQL_ENSURE(info.Features & NUdf::CanCompare, "Cannot compare key type: " << info.Name);
- }
- return keyTypes;
-}
-
+ MKQL_ENSURE(info.Features & NUdf::CanCompare, "Cannot compare key type: " << info.Name);
+ }
+ return keyTypes;
+}
+
class TEncoders : public TComputationValue<TEncoders> {
typedef TComputationValue<TEncoders> TBase;
public:
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_squeeze_state.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_squeeze_state.cpp
index ad3fc15fc9..ddd2c5e3ed 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_squeeze_state.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_squeeze_state.cpp
@@ -49,8 +49,8 @@ NUdf::TUnboxedValuePod TSqueezeState::Save(TComputationContext& ctx) const {
TString out;
WriteByte(out, static_cast<ui8>(Stage));
if (ESqueezeState::Work == Stage) {
- InSave->SetValue(ctx, State->GetValue(ctx));
- WriteUnboxedValue(out, GetPacker(), OutSave->GetValue(ctx));
+ InSave->SetValue(ctx, State->GetValue(ctx));
+ WriteUnboxedValue(out, GetPacker(), OutSave->GetValue(ctx));
}
return MakeString(out);
}
@@ -59,8 +59,8 @@ void TSqueezeState::Load(TComputationContext& ctx, const NUdf::TStringRef& state
TStringBuf in(state.Data(), state.Size());
Stage = static_cast<ESqueezeState>(ReadByte(in));
if (ESqueezeState::Work == Stage) {
- InLoad->SetValue(ctx, ReadUnboxedValue(in, GetPacker(), ctx));
- State->SetValue(ctx, OutLoad->GetValue(ctx));
+ InLoad->SetValue(ctx, ReadUnboxedValue(in, GetPacker(), ctx));
+ State->SetValue(ctx, OutLoad->GetValue(ctx));
}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_switch.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_switch.cpp
index 4da45d123d..4571141d80 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_switch.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_switch.cpp
@@ -676,7 +676,7 @@ private:
public:
TSwitchWrapper(TComputationMutables& mutables, IComputationNode* stream, ui64 memLimit, TSwitchHandlersList&& handlers)
: TBaseComputation(mutables)
- , Stream(stream)
+ , Stream(stream)
, MemLimit(memLimit)
, Handlers(std::move(handlers))
{}
@@ -692,10 +692,10 @@ public:
private:
void RegisterDependencies() const final {
- this->DependsOn(Stream);
+ this->DependsOn(Stream);
for (const auto& x : Handlers) {
this->Own(x.Item);
- this->DependsOn(x.NewItem);
+ this->DependsOn(x.NewItem);
}
}
@@ -890,7 +890,7 @@ private:
#endif
IComputationNode *const Stream;
- const ui64 MemLimit;
+ const ui64 MemLimit;
const TSwitchHandlersList Handlers;
};
@@ -927,7 +927,7 @@ IComputationNode* WrapSwitch(TCallable& callable, const TComputationNodeFactoryC
handlers.emplace_back(handler);
}
- const bool trackRss = EGraphPerProcess::Single == ctx.GraphPerProcess;
+ const bool trackRss = EGraphPerProcess::Single == ctx.GraphPerProcess;
if (type->IsFlow()) {
const bool isInputVariant = AS_TYPE(TFlowType, callable.GetInput(0))->GetItemType()->IsVariant();
const auto kind = GetValueRepresentation(type);
@@ -951,7 +951,7 @@ IComputationNode* WrapSwitch(TCallable& callable, const TComputationNodeFactoryC
} else {
return new TSwitchWrapper<false, false>(ctx.Mutables, stream, memLimit, std::move(handlers));
}
- }
+ }
THROW yexception() << "Expected flow or stream.";
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_take.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_take.cpp
index 4cb0e5ff56..1b6e9701b2 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_take.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_take.cpp
@@ -241,9 +241,9 @@ private:
class TTakeWrapper : public TMutableCodegeneratorNode<TTakeWrapper> {
typedef TMutableCodegeneratorNode<TTakeWrapper> TBaseComputation;
public:
- TTakeWrapper(TComputationMutables& mutables, IComputationNode* list, IComputationNode* count)
+ TTakeWrapper(TComputationMutables& mutables, IComputationNode* list, IComputationNode* count)
: TBaseComputation(mutables, list->GetRepresentation())
- , List(list)
+ , List(list)
, Count(count)
{
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_todict.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_todict.cpp
index 53e27034ad..2e299e487d 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_todict.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_todict.cpp
@@ -682,7 +682,7 @@ public:
TSetWrapper(TComputationMutables& mutables, TType* keyType, IComputationNode* list, IComputationExternalNode* item,
IComputationNode* key, ui64 itemsCountHint)
: TBaseComputation(mutables, EValueRepresentation::Boxed)
- , KeyType(keyType)
+ , KeyType(keyType)
, List(list)
, Item(item)
, Key(key)
@@ -697,7 +697,7 @@ public:
TSetAccumulator(KeyType, KeyTypes, IsTuple, Encoded, ctx, ItemsCountHint), ctx);
}
- const auto& list = List->GetValue(ctx);
+ const auto& list = List->GetValue(ctx);
auto itemsCountHint = ItemsCountHint;
if (list.HasFastListLength()) {
if (const auto size = list.GetListLength())
@@ -709,9 +709,9 @@ public:
TSetAccumulator accumulator(KeyType, KeyTypes, IsTuple, Encoded, ctx, itemsCountHint);
TThresher<false>::DoForEachItem(list,
- [this, &accumulator, &ctx] (NUdf::TUnboxedValue&& item) {
- Item->SetValue(ctx, std::move(item));
- accumulator.Add(Key->GetValue(ctx));
+ [this, &accumulator, &ctx] (NUdf::TUnboxedValue&& item) {
+ Item->SetValue(ctx, std::move(item));
+ accumulator.Add(Key->GetValue(ctx));
}
);
@@ -725,7 +725,7 @@ private:
this->DependsOn(Key);
}
- TType* const KeyType;
+ TType* const KeyType;
IComputationNode* const List;
IComputationExternalNode* const Item;
IComputationNode* const Key;
@@ -1164,7 +1164,7 @@ public:
TMapWrapper(TComputationMutables& mutables, TType* keyType, TType* payloadType, IComputationNode* list, IComputationExternalNode* item,
IComputationNode* key, IComputationNode* payload, ui64 itemsCountHint)
: TBaseComputation(mutables, EValueRepresentation::Boxed)
- , KeyType(keyType)
+ , KeyType(keyType)
, PayloadType(payloadType)
, List(list)
, Item(item)
@@ -1181,7 +1181,7 @@ public:
TMapAccumulator(KeyType, PayloadType, KeyTypes, IsTuple, Encoded, ctx, ItemsCountHint), ctx);
}
- const auto& list = List->GetValue(ctx);
+ const auto& list = List->GetValue(ctx);
auto itemsCountHint = ItemsCountHint;
if (list.HasFastListLength()) {
@@ -1194,9 +1194,9 @@ public:
TMapAccumulator accumulator(KeyType, PayloadType, KeyTypes, IsTuple, Encoded, ctx, itemsCountHint);
TThresher<false>::DoForEachItem(list,
- [this, &accumulator, &ctx] (NUdf::TUnboxedValue&& item) {
- Item->SetValue(ctx, std::move(item));
- accumulator.Add(Key->GetValue(ctx), Payload->GetValue(ctx));
+ [this, &accumulator, &ctx] (NUdf::TUnboxedValue&& item) {
+ Item->SetValue(ctx, std::move(item));
+ accumulator.Add(Key->GetValue(ctx), Payload->GetValue(ctx));
}
);
@@ -1211,7 +1211,7 @@ private:
this->DependsOn(Payload);
}
- TType* const KeyType;
+ TType* const KeyType;
TType* PayloadType;
IComputationNode* const List;
IComputationExternalNode* const Item;
@@ -1781,7 +1781,7 @@ IComputationNode* WrapToHashedDictInternal(TCallable& callable, const TComputati
#define USE_HASHED_SINGLE_FIXED_COMPACT_SET(xType, xLayoutType) \
case NUdf::TDataType<xType>::Id: \
return WrapToSet< \
- THashedSingleFixedCompactSetAccumulator<xLayoutType>>(callable, ctx.NodeLocator, ctx.Mutables);
+ THashedSingleFixedCompactSetAccumulator<xLayoutType>>(callable, ctx.NodeLocator, ctx.Mutables);
switch (AS_TYPE(TDataType, keyType)->GetSchemeType()) {
KNOWN_FIXED_VALUE_TYPES(USE_HASHED_SINGLE_FIXED_COMPACT_SET)
@@ -1789,21 +1789,21 @@ IComputationNode* WrapToHashedDictInternal(TCallable& callable, const TComputati
#undef USE_HASHED_SINGLE_FIXED_COMPACT_SET
}
- return WrapToSet<THashedCompactSetAccumulator>(callable, ctx.NodeLocator, ctx.Mutables);
+ return WrapToSet<THashedCompactSetAccumulator>(callable, ctx.NodeLocator, ctx.Mutables);
}
if (keyType->IsData()) {
#define USE_HASHED_SINGLE_FIXED_SET(xType, xLayoutType) \
case NUdf::TDataType<xType>::Id: \
return WrapToSet< \
- THashedSingleFixedSetAccumulator<xLayoutType>>(callable, ctx.NodeLocator, ctx.Mutables);
+ THashedSingleFixedSetAccumulator<xLayoutType>>(callable, ctx.NodeLocator, ctx.Mutables);
switch (AS_TYPE(TDataType, keyType)->GetSchemeType()) {
KNOWN_FIXED_VALUE_TYPES(USE_HASHED_SINGLE_FIXED_SET)
}
#undef USE_HASHED_SINGLE_FIXED_SET
}
- return WrapToSet<THashedSetAccumulator>(callable, ctx.NodeLocator, ctx.Mutables);
+ return WrapToSet<THashedSetAccumulator>(callable, ctx.NodeLocator, ctx.Mutables);
}
if (isCompact) {
@@ -1812,10 +1812,10 @@ IComputationNode* WrapToHashedDictInternal(TCallable& callable, const TComputati
case NUdf::TDataType<xType>::Id: \
if (multi) { \
return WrapToMap< \
- THashedSingleFixedCompactMapAccumulator<xLayoutType, true>>(callable, ctx.NodeLocator, ctx.Mutables); \
+ THashedSingleFixedCompactMapAccumulator<xLayoutType, true>>(callable, ctx.NodeLocator, ctx.Mutables); \
} else { \
return WrapToMap< \
- THashedSingleFixedCompactMapAccumulator<xLayoutType, false>>(callable, ctx.NodeLocator, ctx.Mutables); \
+ THashedSingleFixedCompactMapAccumulator<xLayoutType, false>>(callable, ctx.NodeLocator, ctx.Mutables); \
}
switch (AS_TYPE(TDataType, keyType)->GetSchemeType()) {
@@ -1825,9 +1825,9 @@ IComputationNode* WrapToHashedDictInternal(TCallable& callable, const TComputati
}
if (multi) {
- return WrapToMap<THashedCompactMapAccumulator<true>>(callable, ctx.NodeLocator, ctx.Mutables);
- } else {
- return WrapToMap<THashedCompactMapAccumulator<false>>(callable, ctx.NodeLocator, ctx.Mutables);
+ return WrapToMap<THashedCompactMapAccumulator<true>>(callable, ctx.NodeLocator, ctx.Mutables);
+ } else {
+ return WrapToMap<THashedCompactMapAccumulator<false>>(callable, ctx.NodeLocator, ctx.Mutables);
}
}
@@ -1836,10 +1836,10 @@ IComputationNode* WrapToHashedDictInternal(TCallable& callable, const TComputati
case NUdf::TDataType<xType>::Id: \
if (multi) { \
return WrapToMap< \
- THashedSingleFixedMultiMapAccumulator<xLayoutType>>(callable, ctx.NodeLocator, ctx.Mutables); \
+ THashedSingleFixedMultiMapAccumulator<xLayoutType>>(callable, ctx.NodeLocator, ctx.Mutables); \
} else { \
return WrapToMap< \
- THashedSingleFixedMapAccumulator<xLayoutType>>(callable, ctx.NodeLocator, ctx.Mutables); \
+ THashedSingleFixedMapAccumulator<xLayoutType>>(callable, ctx.NodeLocator, ctx.Mutables); \
}
switch (AS_TYPE(TDataType, keyType)->GetSchemeType()) {
@@ -1849,9 +1849,9 @@ IComputationNode* WrapToHashedDictInternal(TCallable& callable, const TComputati
}
if (multi) {
- return WrapToMap<THashedMultiMapAccumulator>(callable, ctx.NodeLocator, ctx.Mutables);
+ return WrapToMap<THashedMultiMapAccumulator>(callable, ctx.NodeLocator, ctx.Mutables);
} else {
- return WrapToMap<THashedMapAccumulator>(callable, ctx.NodeLocator, ctx.Mutables);
+ return WrapToMap<THashedMapAccumulator>(callable, ctx.NodeLocator, ctx.Mutables);
}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_toindexdict.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_toindexdict.cpp
index 10dcb15118..5e78b4e100 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_toindexdict.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_toindexdict.cpp
@@ -11,9 +11,9 @@ namespace {
class TToIndexDictWrapper : public TMutableCodegeneratorNode<TToIndexDictWrapper> {
typedef TMutableCodegeneratorNode<TToIndexDictWrapper> TBaseComputation;
public:
- TToIndexDictWrapper(TComputationMutables& mutables, IComputationNode* list)
+ TToIndexDictWrapper(TComputationMutables& mutables, IComputationNode* list)
: TBaseComputation(mutables, list->GetRepresentation())
- , List(list)
+ , List(list)
{
}
@@ -65,7 +65,7 @@ private:
IComputationNode* WrapToIndexDict(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
MKQL_ENSURE(callable.GetInputsCount() == 1, "Expected 1 args");
- return new TToIndexDictWrapper(ctx.Mutables, LocateNode(ctx.NodeLocator, callable, 0));
+ return new TToIndexDictWrapper(ctx.Mutables, LocateNode(ctx.NodeLocator, callable, 0));
}
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_tooptional.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_tooptional.cpp
index d72eba9f33..c41f8c6f0e 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_tooptional.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_tooptional.cpp
@@ -15,7 +15,7 @@ public:
: TBaseComputation(mutables, kind), List(list)
{}
- NUdf::TUnboxedValue DoCalculate(TComputationContext& ctx) const {
+ NUdf::TUnboxedValue DoCalculate(TComputationContext& ctx) const {
const auto& value = List->GetValue(ctx);
if (const auto ptr = value.GetElements()) {
if (value.GetListLength() > 0ULL) {
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_tostring.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_tostring.cpp
index 594abd1605..66e6c73c87 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_tostring.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_tostring.cpp
@@ -34,7 +34,7 @@ class TDecimalToStringWrapper : public TMutableCodegeneratorNode<TDecimalToStrin
public:
TDecimalToStringWrapper(TComputationMutables& mutables, IComputationNode* data, ui8 precision, ui8 scale)
: TBaseComputation(mutables, EValueRepresentation::String)
- , Data(data)
+ , Data(data)
, Precision(precision)
, Scale(scale)
{
@@ -42,8 +42,8 @@ public:
MKQL_ENSURE(scale <= precision, "Wrong scale.");
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- const auto& dataValue = Data->GetValue(ctx);
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ const auto& dataValue = Data->GetValue(ctx);
if (IsOptional && !dataValue) {
return NUdf::TUnboxedValuePod();
}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_udf.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_udf.cpp
index d028325ecc..893cb08456 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_udf.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_udf.cpp
@@ -56,7 +56,7 @@ class TUdfWrapper: public TMutableCodegeneratorPtrNode<TUdfWrapper<TValidatePoli
typedef TMutableCodegeneratorPtrNode<TUdfWrapper<TValidatePolicy,TValidateMode>> TBaseComputation;
public:
TUdfWrapper(
- TComputationMutables& mutables,
+ TComputationMutables& mutables,
IComputationNode* functionImpl,
TString&& functionName,
IComputationNode* runConfigNode,
@@ -71,7 +71,7 @@ public:
}
NUdf::TUnboxedValue DoCalculate(TComputationContext& ctx) const {
- const auto runConfig = RunConfigNode->GetValue(ctx);
+ const auto runConfig = RunConfigNode->GetValue(ctx);
auto callable = FunctionImpl->GetValue(ctx).Run(ctx.Builder, &runConfig);
Wrap(callable);
return callable;
@@ -111,8 +111,8 @@ private:
IComputationNode* const FunctionImpl;
const TString FunctionName;
- IComputationNode* const RunConfigNode;
- const TCallableType* const CallableType;
+ IComputationNode* const RunConfigNode;
+ const TCallableType* const CallableType;
};
inline IComputationNode* CreateUdfWrapper(
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_unwrap.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_unwrap.cpp
index b36d8d9ae2..daef4d28f9 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_unwrap.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_unwrap.cpp
@@ -20,12 +20,12 @@ public:
{
}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx, const NUdf::TUnboxedValuePod& value) const {
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& compCtx, const NUdf::TUnboxedValuePod& value) const {
if (value) {
return value.GetOptionalValue();
}
- Throw(this, &compCtx);
+ Throw(this, &compCtx);
}
#ifndef MKQL_DISABLE_CODEGEN
Value* DoGenerateGetValue(const TCodegenContext& ctx, Value* value, BasicBlock*& block) const {
@@ -41,7 +41,7 @@ public:
const auto doFunc = ConstantInt::get(Type::getInt64Ty(context), GetMethodPtr(&TUnwrapWrapper::Throw));
const auto doFuncArg = ConstantInt::get(Type::getInt64Ty(context), (ui64)this);
const auto doFuncPtr = CastInst::Create(Instruction::IntToPtr, doFunc, PointerType::getUnqual(FunctionType::get(Type::getVoidTy(context), { Type::getInt64Ty(context), ctx.Ctx->getType() }, false)), "thrower", block);
- CallInst::Create(doFuncPtr, { doFuncArg, ctx.Ctx }, "", block)->setTailCall();
+ CallInst::Create(doFuncPtr, { doFuncArg, ctx.Ctx }, "", block)->setTailCall();
new UnreachableInst(context, block);
block = good;
@@ -50,7 +50,7 @@ public:
#endif
private:
[[noreturn]] static void Throw(TUnwrapWrapper const* thisPtr, TComputationContext* ctxPtr) {
- auto message = thisPtr->Message->GetValue(*ctxPtr);
+ auto message = thisPtr->Message->GetValue(*ctxPtr);
auto messageStr = message.AsStringRef();
TStringBuilder res;
res << thisPtr->Pos << " Failed to unwrap empty optional";
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_visitall.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_visitall.cpp
index 7d03e4b27f..76adbc982b 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_visitall.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_visitall.cpp
@@ -13,18 +13,18 @@ using TBaseComputation = TMutableCodegeneratorNode<TVisitAllWrapper>;
public:
TVisitAllWrapper(TComputationMutables& mutables, EValueRepresentation kind, IComputationNode* varNode, TComputationExternalNodePtrVector&& args, TComputationNodePtrVector&& newNodes)
: TBaseComputation(mutables, kind)
- , VarNode(varNode)
+ , VarNode(varNode)
, Args(std::move(args))
, NewNodes(std::move(newNodes))
{}
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- const auto& var = VarNode->GetValue(ctx);
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ const auto& var = VarNode->GetValue(ctx);
const auto currentIndex = var.GetVariantIndex();
if (currentIndex >= Args.size())
return NUdf::TUnboxedValuePod();
- Args[currentIndex]->SetValue(ctx, var.GetVariantItem());
- return NewNodes[currentIndex]->GetValue(ctx).Release();
+ Args[currentIndex]->SetValue(ctx, var.GetVariantItem());
+ return NewNodes[currentIndex]->GetValue(ctx).Release();
}
#ifndef MKQL_DISABLE_CODEGEN
Value* DoGenerateGetValue(const TCodegenContext& ctx, BasicBlock*& block) const {
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_way.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_way.cpp
index 1983b0d2a5..1071b8b780 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_way.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_way.cpp
@@ -18,18 +18,18 @@ class TWayWrapper: public TMutableCodegeneratorNode<TWayWrapper<IsOptional>> {
public:
TWayWrapper(TComputationMutables& mutables, IComputationNode* varNode, EValueRepresentation kind, TComputationNodePtrVector&& literals)
: TBaseComputation(mutables, kind)
- , VarNode(varNode)
+ , VarNode(varNode)
, Literals(std::move(literals))
{}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- const auto& var = VarNode->GetValue(ctx);
+ const auto& var = VarNode->GetValue(ctx);
if (IsOptional && !var) {
return NUdf::TUnboxedValuePod();
}
const ui32 index = var.GetVariantIndex();
- return Literals[index]->GetValue(ctx).Release();
+ return Literals[index]->GetValue(ctx).Release();
}
#ifndef MKQL_DISABLE_CODEGEN
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_weakmember.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_weakmember.cpp
index 06fa988514..e27d397bfd 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_weakmember.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_weakmember.cpp
@@ -1,4 +1,4 @@
-#include "mkql_fromyson.h"
+#include "mkql_fromyson.h"
#include <library/cpp/yson/varint.h>
#include <library/cpp/yson/detail.h>
#include <ydb/library/yql/minikql/computation/mkql_computation_node_holders.h>
@@ -6,33 +6,33 @@
#include <ydb/library/yql/minikql/mkql_node_builder.h>
#include <ydb/library/yql/minikql/mkql_string_util.h>
#include <ydb/library/yql/minikql/mkql_unboxed_value_stream.h>
-
-namespace NKikimr {
-namespace NMiniKQL {
+
+namespace NKikimr {
+namespace NMiniKQL {
namespace {
-
-class TTryWeakMemberFromDictWrapper : public TMutableComputationNode<TTryWeakMemberFromDictWrapper> {
- typedef TMutableComputationNode<TTryWeakMemberFromDictWrapper> TBaseComputation;
-public:
- TTryWeakMemberFromDictWrapper(TComputationMutables& mutables, IComputationNode* otherDict, IComputationNode* restDict, NUdf::TDataTypeId schemeType,
- NUdf::TUnboxedValue&& memberName, NUdf::TUnboxedValue&& otherIsStrMemberName)
- : TBaseComputation(mutables)
- , OtherDict(otherDict)
- , RestDict(restDict)
- , SchemeType(NUdf::GetDataSlot(schemeType))
- , MemberName(std::move(memberName))
- , OtherIsStringMemberName(std::move(otherIsStrMemberName))
- {
- }
-
- NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- if (const auto& restDict = RestDict->GetValue(ctx)) {
+
+class TTryWeakMemberFromDictWrapper : public TMutableComputationNode<TTryWeakMemberFromDictWrapper> {
+ typedef TMutableComputationNode<TTryWeakMemberFromDictWrapper> TBaseComputation;
+public:
+ TTryWeakMemberFromDictWrapper(TComputationMutables& mutables, IComputationNode* otherDict, IComputationNode* restDict, NUdf::TDataTypeId schemeType,
+ NUdf::TUnboxedValue&& memberName, NUdf::TUnboxedValue&& otherIsStrMemberName)
+ : TBaseComputation(mutables)
+ , OtherDict(otherDict)
+ , RestDict(restDict)
+ , SchemeType(NUdf::GetDataSlot(schemeType))
+ , MemberName(std::move(memberName))
+ , OtherIsStringMemberName(std::move(otherIsStrMemberName))
+ {
+ }
+
+ NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
+ if (const auto& restDict = RestDict->GetValue(ctx)) {
if (const auto& tryMember = restDict.Lookup(MemberName)) {
return SimpleValueFromYson(SchemeType, tryMember.AsStringRef());
}
}
- if (const auto& otherDict = OtherDict->GetValue(ctx)) {
+ if (const auto& otherDict = OtherDict->GetValue(ctx)) {
if (auto tryMember = otherDict.Lookup(MemberName)) {
const bool isString = otherDict.Contains(OtherIsStringMemberName);
if (isString) {
@@ -52,58 +52,58 @@ public:
}
} else {
return SimpleValueFromYson(SchemeType, tryMember.AsStringRef());
- }
- }
- }
-
+ }
+ }
+ }
+
return NUdf::TUnboxedValuePod();
- }
-
-private:
+ }
+
+private:
void RegisterDependencies() const final {
DependsOn(OtherDict);
DependsOn(RestDict);
- }
-
- IComputationNode* const OtherDict;
- IComputationNode* const RestDict;
- const NUdf::EDataSlot SchemeType;
- const NUdf::TUnboxedValue MemberName;
- const NUdf::TUnboxedValue OtherIsStringMemberName;
-};
-
+ }
+
+ IComputationNode* const OtherDict;
+ IComputationNode* const RestDict;
+ const NUdf::EDataSlot SchemeType;
+ const NUdf::TUnboxedValue MemberName;
+ const NUdf::TUnboxedValue OtherIsStringMemberName;
+};
+
}
-IComputationNode* WrapTryWeakMemberFromDict(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
- MKQL_ENSURE(callable.GetInputsCount() == 4, "Expected 4 args");
-
- auto otherType = AS_TYPE(TOptionalType, callable.GetInput(0));
- auto otherDictType = AS_TYPE(TDictType, otherType->GetItemType());
- auto otherDictKeyType = AS_TYPE(TDataType, otherDictType->GetKeyType());
- auto otherDictPayloadType = AS_TYPE(TDataType, otherDictType->GetPayloadType());
- MKQL_ENSURE(otherDictKeyType->GetSchemeType() == NUdf::TDataType<char*>::Id, "Expected String");
- MKQL_ENSURE(otherDictPayloadType->GetSchemeType() == NUdf::TDataType<char*>::Id, "Expected String");
-
- auto restType = AS_TYPE(TOptionalType, callable.GetInput(1));
- auto restDictType = AS_TYPE(TDictType, restType->GetItemType());
- auto restDictKeyType = AS_TYPE(TDataType, restDictType->GetKeyType());
- auto restDictPayloadType = AS_TYPE(TDataType, restDictType->GetPayloadType());
- MKQL_ENSURE(restDictKeyType->GetSchemeType() == NUdf::TDataType<char*>::Id, "Expected String");
- MKQL_ENSURE(restDictPayloadType->GetSchemeType() == NUdf::TDataType<NUdf::TYson>::Id, "Expected String");
-
- TDataLiteral* schemeTypeData = AS_VALUE(TDataLiteral, callable.GetInput(2));
- auto schemeType = schemeTypeData->AsValue().Get<ui32>();
-
- auto memberNameValue = AS_VALUE(TDataLiteral, callable.GetInput(3));
- const TString memberName(memberNameValue->AsValue().AsStringRef());
-
- auto otherDict = LocateNode(ctx.NodeLocator, callable, 0);
- auto restDict = LocateNode(ctx.NodeLocator, callable, 1);
+IComputationNode* WrapTryWeakMemberFromDict(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
+ MKQL_ENSURE(callable.GetInputsCount() == 4, "Expected 4 args");
+
+ auto otherType = AS_TYPE(TOptionalType, callable.GetInput(0));
+ auto otherDictType = AS_TYPE(TDictType, otherType->GetItemType());
+ auto otherDictKeyType = AS_TYPE(TDataType, otherDictType->GetKeyType());
+ auto otherDictPayloadType = AS_TYPE(TDataType, otherDictType->GetPayloadType());
+ MKQL_ENSURE(otherDictKeyType->GetSchemeType() == NUdf::TDataType<char*>::Id, "Expected String");
+ MKQL_ENSURE(otherDictPayloadType->GetSchemeType() == NUdf::TDataType<char*>::Id, "Expected String");
+
+ auto restType = AS_TYPE(TOptionalType, callable.GetInput(1));
+ auto restDictType = AS_TYPE(TDictType, restType->GetItemType());
+ auto restDictKeyType = AS_TYPE(TDataType, restDictType->GetKeyType());
+ auto restDictPayloadType = AS_TYPE(TDataType, restDictType->GetPayloadType());
+ MKQL_ENSURE(restDictKeyType->GetSchemeType() == NUdf::TDataType<char*>::Id, "Expected String");
+ MKQL_ENSURE(restDictPayloadType->GetSchemeType() == NUdf::TDataType<NUdf::TYson>::Id, "Expected String");
+
+ TDataLiteral* schemeTypeData = AS_VALUE(TDataLiteral, callable.GetInput(2));
+ auto schemeType = schemeTypeData->AsValue().Get<ui32>();
+
+ auto memberNameValue = AS_VALUE(TDataLiteral, callable.GetInput(3));
+ const TString memberName(memberNameValue->AsValue().AsStringRef());
+
+ auto otherDict = LocateNode(ctx.NodeLocator, callable, 0);
+ auto restDict = LocateNode(ctx.NodeLocator, callable, 1);
auto memberNameStr = MakeString(memberName);
auto otherIsStringMemberNameStr = MakeString("_yql_" + memberName);
- return new TTryWeakMemberFromDictWrapper(ctx.Mutables, otherDict, restDict, static_cast<NUdf::TDataTypeId>(schemeType),
- std::move(memberNameStr), std::move(otherIsStringMemberNameStr));
-}
-
-}
-}
+ return new TTryWeakMemberFromDictWrapper(ctx.Mutables, otherDict, restDict, static_cast<NUdf::TDataTypeId>(schemeType),
+ std::move(memberNameStr), std::move(otherIsStringMemberNameStr));
+}
+
+}
+}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_weakmember.h b/ydb/library/yql/minikql/comp_nodes/mkql_weakmember.h
index 6b389e381f..de2e6d6043 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_weakmember.h
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_weakmember.h
@@ -1,10 +1,10 @@
-#pragma once
+#pragma once
#include <ydb/library/yql/minikql/computation/mkql_computation_node.h>
-
-namespace NKikimr {
-namespace NMiniKQL {
-
-IComputationNode* WrapTryWeakMemberFromDict(TCallable& callable, const TComputationNodeFactoryContext& ctx);
-
-}
-}
+
+namespace NKikimr {
+namespace NMiniKQL {
+
+IComputationNode* WrapTryWeakMemberFromDict(TCallable& callable, const TComputationNodeFactoryContext& ctx);
+
+}
+}
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_while.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_while.cpp
index a15d44aac6..a8650d5754 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_while.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_while.cpp
@@ -123,7 +123,7 @@ protected:
public:
TIterator(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& iter, IComputationExternalNode* item, IComputationNode* predicate)
: TComputationValue<TIterator>(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Iter(std::move(iter))
, Item(item)
, Predicate(predicate)
@@ -137,7 +137,7 @@ protected:
if constexpr (SkipOrTake) {
while (Iter.Next(Item->RefValue(CompCtx))) {
- if (!Predicate->GetValue(CompCtx).template Get<bool>()) {
+ if (!Predicate->GetValue(CompCtx).template Get<bool>()) {
FilterWorkFinished = true;
if constexpr (Inclusive) {
return Iter.Next(value);
@@ -149,8 +149,8 @@ protected:
}
} else {
if (Iter.Next(Item->RefValue(CompCtx))) {
- if (Predicate->GetValue(CompCtx).template Get<bool>()) {
- value = Item->GetValue(CompCtx);
+ if (Predicate->GetValue(CompCtx).template Get<bool>()) {
+ value = Item->GetValue(CompCtx);
return true;
} else {
FilterWorkFinished = true;
@@ -165,7 +165,7 @@ protected:
return false;
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue Iter;
IComputationExternalNode* const Item;
IComputationNode* const Predicate;
@@ -174,7 +174,7 @@ protected:
TListValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, const NUdf::TUnboxedValue& list, IComputationExternalNode* item, IComputationNode* predicate)
: TCustomListValue(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, List(list)
, Item(item)
, Predicate(predicate)
@@ -185,7 +185,7 @@ protected:
return CompCtx.HolderFactory.Create<TIterator>(CompCtx, List.GetListIterator(), Item, Predicate);
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue List;
IComputationExternalNode* const Item;
IComputationNode* const Predicate;
@@ -197,7 +197,7 @@ protected:
TStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, const NUdf::TUnboxedValue& stream, IComputationExternalNode* item, IComputationNode* predicate)
: TBase(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Stream(stream)
, Item(item)
, Predicate(predicate)
@@ -225,7 +225,7 @@ protected:
return status;
}
- if (!Predicate->GetValue(CompCtx).template Get<bool>()) {
+ if (!Predicate->GetValue(CompCtx).template Get<bool>()) {
FilterWorkFinished = true;
if constexpr (Inclusive) {
return Stream.Fetch(result);
@@ -241,8 +241,8 @@ protected:
return status;
case NUdf::EFetchStatus::Ok:
- if (Predicate->GetValue(CompCtx).template Get<bool>()) {
- result = Item->GetValue(CompCtx);
+ if (Predicate->GetValue(CompCtx).template Get<bool>()) {
+ result = Item->GetValue(CompCtx);
return NUdf::EFetchStatus::Ok;
}
case NUdf::EFetchStatus::Finish:
@@ -259,7 +259,7 @@ protected:
}
}
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const NUdf::TUnboxedValue Stream;
IComputationExternalNode* const Item;
IComputationNode* const Predicate;
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_zip.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_zip.cpp
index d75d980e9b..702778d5da 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_zip.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_zip.cpp
@@ -10,7 +10,7 @@ namespace {
template <bool All>
class TZipWrapper : public TMutableComputationNode<TZipWrapper<All>> {
- typedef TMutableComputationNode<TZipWrapper<All>> TBaseComputation;
+ typedef TMutableComputationNode<TZipWrapper<All>> TBaseComputation;
public:
using TSelf = TZipWrapper<All>;
@@ -158,10 +158,10 @@ public:
const TSelf *const Self;
};
- TZipWrapper(TComputationMutables& mutables, TComputationNodePtrVector& lists)
- : TBaseComputation(mutables)
- , Lists(std::move(lists))
- , ResTuple(mutables)
+ TZipWrapper(TComputationMutables& mutables, TComputationNodePtrVector& lists)
+ : TBaseComputation(mutables)
+ , Lists(std::move(lists))
+ , ResTuple(mutables)
{}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
@@ -170,7 +170,7 @@ public:
listValues.reserve(Lists.size());
arrays.reserve(Lists.size());
for (auto& list : Lists) {
- listValues.emplace_back(list->GetValue(ctx));
+ listValues.emplace_back(list->GetValue(ctx));
arrays.emplace_back(listValues.back().GetElements());
}
@@ -227,7 +227,7 @@ IComputationNode* WrapZip(TCallable& callable, const TComputationNodeFactoryCont
lists.push_back(LocateNode(ctx.NodeLocator, callable, i));
}
- return new TZipWrapper<All>(ctx.Mutables, lists);
+ return new TZipWrapper<All>(ctx.Mutables, lists);
}
template
diff --git a/ydb/library/yql/minikql/comp_nodes/ut/mkql_combine_ut.cpp b/ydb/library/yql/minikql/comp_nodes/ut/mkql_combine_ut.cpp
index 8b82baf968..0a147c619d 100644
--- a/ydb/library/yql/minikql/comp_nodes/ut/mkql_combine_ut.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/ut/mkql_combine_ut.cpp
@@ -27,9 +27,9 @@ public:
public:
using TBase = TComputationValue<TStreamValue>;
- TStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, const TTestStreamWrapper* parent)
+ TStreamValue(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, const TTestStreamWrapper* parent)
: TBase(memInfo)
- , CompCtx(compCtx)
+ , CompCtx(compCtx)
, Parent(parent)
{
}
@@ -64,19 +64,19 @@ public:
}
private:
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
const TTestStreamWrapper* const Parent;
ui64 Index = 0;
};
- TTestStreamWrapper(TComputationMutables& mutables, ui64 peakStep)
- : TBaseComputation(mutables)
- , PeakStep(peakStep)
+ TTestStreamWrapper(TComputationMutables& mutables, ui64 peakStep)
+ : TBaseComputation(mutables)
+ , PeakStep(peakStep)
{
}
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
- return ctx.HolderFactory.Create<TStreamValue>(ctx, this);
+ return ctx.HolderFactory.Create<TStreamValue>(ctx, this);
}
private:
@@ -88,7 +88,7 @@ private:
};
template <bool WithYields>
-IComputationNode* WrapTestStream(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
+IComputationNode* WrapTestStream(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
MKQL_ENSURE(callable.GetInputsCount() == 1, "Expected 1 args");
const ui64 peakStep = AS_VALUE(TDataLiteral, callable.GetInput(0))->AsValue().Get<ui64>();
return new TTestStreamWrapper<WithYields>(ctx.Mutables, peakStep);
@@ -130,10 +130,10 @@ struct TSetup_ {
TAutoPtr<IComputationGraph> BuildGraph(TRuntimeNode pgm, EGraphPerProcess graphPerProcess = EGraphPerProcess::Multi, const std::vector<TNode*>& entryPoints = std::vector<TNode*>()) {
Explorer.Walk(pgm.GetNode(), *Env);
- TComputationPatternOpts opts(Alloc.Ref(), *Env, GetTestFactory(), FunctionRegistry.Get(),
+ TComputationPatternOpts opts(Alloc.Ref(), *Env, GetTestFactory(), FunctionRegistry.Get(),
NUdf::EValidateMode::None, NUdf::EValidatePolicy::Exception, UseLLVM ? "" : "OFF", graphPerProcess);
Pattern = MakeComputationPattern(Explorer, pgm, entryPoints, opts);
- return Pattern->Clone(opts.ToComputationOptions(*RandomProvider, *TimeProvider));
+ return Pattern->Clone(opts.ToComputationOptions(*RandomProvider, *TimeProvider));
}
TIntrusivePtr<IFunctionRegistry> FunctionRegistry;
@@ -145,7 +145,7 @@ struct TSetup_ {
THolder<TProgramBuilder> PgmBuilder;
TExploringNodeVisitor Explorer;
- IComputationPattern::TPtr Pattern;
+ IComputationPattern::TPtr Pattern;
};
template <bool LLVM, bool WithYields = false>
diff --git a/ydb/library/yql/minikql/comp_nodes/ut/mkql_computation_node_ut.cpp b/ydb/library/yql/minikql/comp_nodes/ut/mkql_computation_node_ut.cpp
index 905142ac8d..19f82aae4e 100644
--- a/ydb/library/yql/minikql/comp_nodes/ut/mkql_computation_node_ut.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/ut/mkql_computation_node_ut.cpp
@@ -2067,30 +2067,30 @@ Y_UNIT_TEST_SUITE(TMiniKQLComputationNodeTest) {
}
Y_UNIT_TEST_LLVM(TestMapUnwrapThrowMessage) {
- TSetup<LLVM> setup;
+ TSetup<LLVM> setup;
TProgramBuilder& pb = *setup.PgmBuilder;
-
+
const auto dataType = pb.NewOptionalType(pb.NewDataType(NUdf::TDataType<i8>::Id));
const auto data1 = pb.NewOptional(pb.NewDataLiteral<i8>(1));
const auto data2 = pb.NewOptional(pb.NewDataLiteral<i8>(7));
const auto data0 = pb.NewEmptyOptionalDataLiteral(NUdf::TDataType<i8>::Id);
const auto list = pb.LazyList(pb.NewList(dataType, {data1, data0}));
-
+
const auto pgmReturn = pb.Map(list,
- [&](TRuntimeNode item) {
+ [&](TRuntimeNode item) {
return pb.Sub(data2, pb.Unwrap(item, pb.Concat(
pb.NewDataLiteral<NUdf::EDataSlot::String>("a"),
pb.NewDataLiteral<NUdf::EDataSlot::String>("b")),
- "", 0, 0));
- });
-
+ "", 0, 0));
+ });
+
const auto graph = setup.BuildGraph(pgmReturn);
const auto iterator = graph->GetValue().GetListIterator();
- NUdf::TUnboxedValue item;
- UNIT_ASSERT(iterator.Next(item));
- UNIT_ASSERT_VALUES_EQUAL(item.template Get<i8>(), 6);
- UNIT_ASSERT_EXCEPTION(iterator.Next(item), yexception);
- }
+ NUdf::TUnboxedValue item;
+ UNIT_ASSERT(iterator.Next(item));
+ UNIT_ASSERT_VALUES_EQUAL(item.template Get<i8>(), 6);
+ UNIT_ASSERT_EXCEPTION(iterator.Next(item), yexception);
+ }
Y_UNIT_TEST_LLVM(TestMapEnsureThrowMessage) {
TSetup<LLVM> setup;
@@ -4890,7 +4890,7 @@ Y_UNIT_TEST_SUITE(TMiniKQLComputationNodeTest) {
for (ui32 i = 0; i < n; ++i) {
items[keyIndex] = NUdf::TUnboxedValuePod(i);
items[valueIndex] = NUdf::TUnboxedValuePod::Embedded("ABCDF");
- row->SetValue(graph->GetContext(), NUdf::TUnboxedValuePod(structObj));
+ row->SetValue(graph->GetContext(), NUdf::TUnboxedValuePod(structObj));
const bool keep = graph->GetValue().template Get<bool>();
UNIT_ASSERT(!keep);
}
diff --git a/ydb/library/yql/minikql/comp_nodes/ut/mkql_safe_circular_buffer_ut.cpp b/ydb/library/yql/minikql/comp_nodes/ut/mkql_safe_circular_buffer_ut.cpp
index 5a973c1873..9df6d01d4e 100644
--- a/ydb/library/yql/minikql/comp_nodes/ut/mkql_safe_circular_buffer_ut.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/ut/mkql_safe_circular_buffer_ut.cpp
@@ -1,60 +1,60 @@
-#include "mkql_safe_circular_buffer.h"
-
+#include "mkql_safe_circular_buffer.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <ydb/library/yql/public/udf/udf_value.h>
-
-namespace NKikimr {
-using namespace NUdf;
-namespace NMiniKQL {
-
+
+namespace NKikimr {
+using namespace NUdf;
+namespace NMiniKQL {
+
Y_UNIT_TEST_SUITE(TMiniKQLSafeCircularBuffer) {
- typedef TSafeCircularBuffer<TUnboxedValue> TBufUnboxed;
-
+ typedef TSafeCircularBuffer<TUnboxedValue> TBufUnboxed;
+
Y_UNIT_TEST(TestUnboxedNoFailOnEmpty) {
TBufUnboxed bufferOptional(1, TUnboxedValuePod());
- TBufUnboxed buffer(1, TUnboxedValue::Void());
+ TBufUnboxed buffer(1, TUnboxedValue::Void());
UNIT_ASSERT(buffer.Get(0));
UNIT_ASSERT(buffer.Get(1));
UNIT_ASSERT(buffer.Get(3));
UNIT_ASSERT(buffer.Get(-1));
- for (auto i = 0; i < 5; ++i) {
- buffer.PopFront();
- }
- }
-
+ for (auto i = 0; i < 5; ++i) {
+ buffer.PopFront();
+ }
+ }
+
Y_UNIT_TEST(TestUnboxedNormalUsage) {
TBufUnboxed buffer(5, TUnboxedValuePod());
buffer.PushBack(TUnboxedValue::Embedded("It"));
- UNIT_ASSERT_EQUAL(buffer.Get(0).AsStringRef(), "It");
+ UNIT_ASSERT_EQUAL(buffer.Get(0).AsStringRef(), "It");
buffer.PushBack(TUnboxedValue::Embedded("is"));
- UNIT_ASSERT_EQUAL(buffer.Get(0).AsStringRef(), "It");
+ UNIT_ASSERT_EQUAL(buffer.Get(0).AsStringRef(), "It");
buffer.PushBack(TUnboxedValue::Embedded("funny"));
- UNIT_ASSERT_EQUAL(buffer.UsedSize(), 3);
- UNIT_ASSERT_EQUAL(buffer.Get(0).AsStringRef(), "It");
- UNIT_ASSERT_EQUAL(buffer.Get(2).AsStringRef(), "funny");
+ UNIT_ASSERT_EQUAL(buffer.UsedSize(), 3);
+ UNIT_ASSERT_EQUAL(buffer.Get(0).AsStringRef(), "It");
+ UNIT_ASSERT_EQUAL(buffer.Get(2).AsStringRef(), "funny");
UNIT_ASSERT(!buffer.Get(3));
- buffer.PopFront();
- UNIT_ASSERT_EQUAL(buffer.Get(0).AsStringRef(), "is");
- UNIT_ASSERT_EQUAL(buffer.Get(1).AsStringRef(), "funny");
+ buffer.PopFront();
+ UNIT_ASSERT_EQUAL(buffer.Get(0).AsStringRef(), "is");
+ UNIT_ASSERT_EQUAL(buffer.Get(1).AsStringRef(), "funny");
buffer.PushBack(TUnboxedValue::Embedded("bunny"));
- UNIT_ASSERT_EQUAL(buffer.Get(1).AsStringRef(), "funny");
- UNIT_ASSERT_EQUAL(buffer.Get(2).AsStringRef(), "bunny");
+ UNIT_ASSERT_EQUAL(buffer.Get(1).AsStringRef(), "funny");
+ UNIT_ASSERT_EQUAL(buffer.Get(2).AsStringRef(), "bunny");
UNIT_ASSERT(!buffer.Get(3));
- buffer.PopFront();
- UNIT_ASSERT_EQUAL(buffer.Get(0).AsStringRef(), "funny");
- UNIT_ASSERT_EQUAL(buffer.Get(1).AsStringRef(), "bunny");
- UNIT_ASSERT_EQUAL(buffer.UsedSize(), 2);
- buffer.PopFront();
- UNIT_ASSERT_EQUAL(buffer.Get(0).AsStringRef(), "bunny");
- UNIT_ASSERT_EQUAL(buffer.UsedSize(), 1);
- for (auto i = 0; i < 3; ++i) {
- buffer.PopFront();
- UNIT_ASSERT_EQUAL(buffer.UsedSize(), 0);
+ buffer.PopFront();
+ UNIT_ASSERT_EQUAL(buffer.Get(0).AsStringRef(), "funny");
+ UNIT_ASSERT_EQUAL(buffer.Get(1).AsStringRef(), "bunny");
+ UNIT_ASSERT_EQUAL(buffer.UsedSize(), 2);
+ buffer.PopFront();
+ UNIT_ASSERT_EQUAL(buffer.Get(0).AsStringRef(), "bunny");
+ UNIT_ASSERT_EQUAL(buffer.UsedSize(), 1);
+ for (auto i = 0; i < 3; ++i) {
+ buffer.PopFront();
+ UNIT_ASSERT_EQUAL(buffer.UsedSize(), 0);
UNIT_ASSERT(!buffer.Get(0));
- }
- }
-
+ }
+ }
+
Y_UNIT_TEST(TestOverflowNoInitSize) {
TBufUnboxed buffer(3, TUnboxedValuePod(), 0);
buffer.PushBack(TUnboxedValue::Embedded("1"));
@@ -111,33 +111,33 @@ Y_UNIT_TEST_SUITE(TMiniKQLSafeCircularBuffer) {
}
Y_UNIT_TEST(TestUnboxedFewCycles) {
- const auto multFillLevel = 0.6;
- const auto multPopLevel = 0.5;
- const auto initSize = 10;
- const auto iterationCount = 4;
+ const auto multFillLevel = 0.6;
+ const auto multPopLevel = 0.5;
+ const auto initSize = 10;
+ const auto iterationCount = 4;
TBufUnboxed buffer(initSize, NUdf::TUnboxedValuePod());
- unsigned lastDirectIndex = 0;
- unsigned lastChecked = 0;
- for (unsigned iteration = 0; iteration < iterationCount; ++iteration) {
- for (auto i = 0; i < multFillLevel * initSize; ++i) {
+ unsigned lastDirectIndex = 0;
+ unsigned lastChecked = 0;
+ for (unsigned iteration = 0; iteration < iterationCount; ++iteration) {
+ for (auto i = 0; i < multFillLevel * initSize; ++i) {
buffer.PushBack(NUdf::TUnboxedValuePod(++lastDirectIndex));
- }
- UNIT_ASSERT(buffer.UsedSize() > 0);
- UNIT_ASSERT_EQUAL(buffer.Get(buffer.UsedSize() - 1).Get<unsigned>(), lastDirectIndex);
- for (auto i = 0; i < multPopLevel * initSize; ++i) {
- auto curUnboxed = buffer.Get(0);
- auto cur = curUnboxed.Get<unsigned>();
- UNIT_ASSERT(lastChecked < cur);
- lastChecked = cur;
- buffer.PopFront();
- }
- UNIT_ASSERT_EQUAL(buffer.UsedSize(), iteration + 1);
- }
- UNIT_ASSERT_EQUAL(buffer.UsedSize(), lastDirectIndex - lastChecked);
- UNIT_ASSERT_EQUAL(buffer.Get(0).Get<unsigned>(), lastChecked + 1);
- UNIT_ASSERT_EQUAL(buffer.Get(buffer.UsedSize() - 1).Get<unsigned>(), lastDirectIndex);
- }
-}
-
-}
-}
+ }
+ UNIT_ASSERT(buffer.UsedSize() > 0);
+ UNIT_ASSERT_EQUAL(buffer.Get(buffer.UsedSize() - 1).Get<unsigned>(), lastDirectIndex);
+ for (auto i = 0; i < multPopLevel * initSize; ++i) {
+ auto curUnboxed = buffer.Get(0);
+ auto cur = curUnboxed.Get<unsigned>();
+ UNIT_ASSERT(lastChecked < cur);
+ lastChecked = cur;
+ buffer.PopFront();
+ }
+ UNIT_ASSERT_EQUAL(buffer.UsedSize(), iteration + 1);
+ }
+ UNIT_ASSERT_EQUAL(buffer.UsedSize(), lastDirectIndex - lastChecked);
+ UNIT_ASSERT_EQUAL(buffer.Get(0).Get<unsigned>(), lastChecked + 1);
+ UNIT_ASSERT_EQUAL(buffer.Get(buffer.UsedSize() - 1).Get<unsigned>(), lastDirectIndex);
+ }
+}
+
+}
+}
diff --git a/ydb/library/yql/minikql/comp_nodes/ut/ya.make b/ydb/library/yql/minikql/comp_nodes/ut/ya.make
index fb9039f869..dffda1318f 100644
--- a/ydb/library/yql/minikql/comp_nodes/ut/ya.make
+++ b/ydb/library/yql/minikql/comp_nodes/ut/ya.make
@@ -39,7 +39,7 @@ SRCS(
mkql_join_ut.cpp
mkql_join_dict_ut.cpp
mkql_map_join_ut.cpp
- mkql_safe_circular_buffer_ut.cpp
+ mkql_safe_circular_buffer_ut.cpp
mkql_sort_ut.cpp
mkql_switch_ut.cpp
mkql_todict_ut.cpp
diff --git a/ydb/library/yql/minikql/comp_nodes/ya.make b/ydb/library/yql/minikql/comp_nodes/ya.make
index 15763a1538..55838c4012 100644
--- a/ydb/library/yql/minikql/comp_nodes/ya.make
+++ b/ydb/library/yql/minikql/comp_nodes/ya.make
@@ -72,8 +72,8 @@ SRCS(
mkql_frombytes.h
mkql_fromstring.cpp
mkql_fromstring.h
- mkql_fromyson.cpp
- mkql_fromyson.h
+ mkql_fromyson.cpp
+ mkql_fromyson.h
mkql_group.cpp
mkql_group.h
mkql_guess.cpp
@@ -126,8 +126,8 @@ SRCS(
mkql_pickle.h
mkql_prepend.cpp
mkql_prepend.h
- mkql_queue.cpp
- mkql_queue.h
+ mkql_queue.cpp
+ mkql_queue.h
mkql_random.cpp
mkql_random.h
mkql_range.cpp
@@ -142,8 +142,8 @@ SRCS(
mkql_reverse.h
mkql_round.cpp
mkql_round.h
- mkql_safe_circular_buffer.cpp
- mkql_safe_circular_buffer.h
+ mkql_safe_circular_buffer.cpp
+ mkql_safe_circular_buffer.h
mkql_saveload.h
mkql_seq.cpp
mkql_seq.h
@@ -189,8 +189,8 @@ SRCS(
mkql_visitall.h
mkql_way.cpp
mkql_way.h
- mkql_weakmember.cpp
- mkql_weakmember.h
+ mkql_weakmember.cpp
+ mkql_weakmember.h
mkql_while.cpp
mkql_while.h
mkql_wide_chain_map.cpp
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node.cpp b/ydb/library/yql/minikql/computation/mkql_computation_node.cpp
index bc819cd141..aa2e27f028 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node.cpp
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node.cpp
@@ -32,8 +32,8 @@ TComputationContext::TComputationContext(const THolderFactory& holderFactory,
const TComputationMutables& mutables,
arrow::MemoryPool& arrowMemoryPool)
: TComputationContextLLVM{holderFactory, opts.Stats, std::make_unique<NUdf::TUnboxedValue[]>(mutables.CurValueIndex), builder}
- , RandomProvider(opts.RandomProvider)
- , TimeProvider(opts.TimeProvider)
+ , RandomProvider(opts.RandomProvider)
+ , TimeProvider(opts.TimeProvider)
, ArrowMemoryPool(arrowMemoryPool)
{
std::fill_n(MutableValues.get(), mutables.CurValueIndex, NUdf::TUnboxedValue(NUdf::TUnboxedValuePod::Invalid()));
@@ -41,7 +41,7 @@ TComputationContext::TComputationContext(const THolderFactory& holderFactory,
TComputationContext::~TComputationContext() {
#ifndef NDEBUG
- if (RssCounter) {
+ if (RssCounter) {
Cerr << "UsageOnFinish: graph=" << HolderFactory.GetPagePool().GetUsed()
<< ", rss=" << TRusage::Get().MaxRss
<< ", peakAlloc=" << HolderFactory.GetPagePool().GetPeakAllocated()
@@ -58,9 +58,9 @@ void TComputationContext::UpdateUsageAdjustor(ui64 memLimit) {
}
#ifndef NDEBUG
- // Print first time and then each 30 seconds
- bool printUsage = LastPrintUsage == TInstant::Zero()
- || TInstant::Now() > TDuration::Seconds(30).ToDeadLine(LastPrintUsage);
+ // Print first time and then each 30 seconds
+ bool printUsage = LastPrintUsage == TInstant::Zero()
+ || TInstant::Now() > TDuration::Seconds(30).ToDeadLine(LastPrintUsage);
#endif
if (auto peakAlloc = HolderFactory.GetPagePool().GetPeakAllocated()) {
@@ -71,17 +71,17 @@ void TComputationContext::UpdateUsageAdjustor(ui64 memLimit) {
printUsage = UsageAdjustor > 1.f;
#endif
}
- }
+ }
#ifndef NDEBUG
- if (printUsage) {
+ if (printUsage) {
Cerr << "Usage: graph=" << HolderFactory.GetPagePool().GetUsed()
- << ", rss=" << rss
- << ", peakAlloc=" << HolderFactory.GetPagePool().GetPeakAllocated()
- << ", adjustor=" << UsageAdjustor
- << Endl;
- LastPrintUsage = TInstant::Now();
- }
+ << ", rss=" << rss
+ << ", peakAlloc=" << HolderFactory.GetPagePool().GetPeakAllocated()
+ << ", adjustor=" << UsageAdjustor
+ << Endl;
+ LastPrintUsage = TInstant::Now();
+ }
#endif
}
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node.h b/ydb/library/yql/minikql/computation/mkql_computation_node.h
index 6a459035d2..a5d11b180b 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node.h
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node.h
@@ -35,36 +35,36 @@ enum class EGraphPerProcess {
Single
};
-struct TComputationOpts {
- TComputationOpts(IStatsRegistry* stats)
- : Stats(stats)
- {}
+struct TComputationOpts {
+ TComputationOpts(IStatsRegistry* stats)
+ : Stats(stats)
+ {}
IStatsRegistry *const Stats;
-};
-
-struct TComputationOptsFull: public TComputationOpts {
- TComputationOptsFull(IStatsRegistry* stats, TAllocState& allocState, IRandomProvider& randomProvider,
+};
+
+struct TComputationOptsFull: public TComputationOpts {
+ TComputationOptsFull(IStatsRegistry* stats, TAllocState& allocState, IRandomProvider& randomProvider,
ITimeProvider& timeProvider, NUdf::EValidatePolicy validatePolicy, const NUdf::ISecureParamsProvider* secureParamsProvider)
- : TComputationOpts(stats)
- , AllocState(allocState)
- , RandomProvider(randomProvider)
- , TimeProvider(timeProvider)
- , ValidatePolicy(validatePolicy)
+ : TComputationOpts(stats)
+ , AllocState(allocState)
+ , RandomProvider(randomProvider)
+ , TimeProvider(timeProvider)
+ , ValidatePolicy(validatePolicy)
, SecureParamsProvider(secureParamsProvider)
- {}
- TAllocState& AllocState;
- IRandomProvider& RandomProvider;
- ITimeProvider& TimeProvider;
- NUdf::EValidatePolicy ValidatePolicy;
+ {}
+ TAllocState& AllocState;
+ IRandomProvider& RandomProvider;
+ ITimeProvider& TimeProvider;
+ NUdf::EValidatePolicy ValidatePolicy;
const NUdf::ISecureParamsProvider* SecureParamsProvider;
-};
-
-struct TComputationMutables {
+};
+
+struct TComputationMutables {
ui32 CurValueIndex = 0U;
std::vector<ui32> SerializableValues; // Indices of values that need to be saved in IComputationGraph::SaveGraphState() and restored in IComputationGraph::LoadGraphState().
-};
-
+};
+
class THolderFactory;
// Do not reorder: used in LLVM!
@@ -79,8 +79,8 @@ struct TComputationContextLLVM {
};
struct TComputationContext : public TComputationContextLLVM {
- IRandomProvider& RandomProvider;
- ITimeProvider& TimeProvider;
+ IRandomProvider& RandomProvider;
+ ITimeProvider& TimeProvider;
bool ExecuteLLVM = true;
arrow::MemoryPool& ArrowMemoryPool;
@@ -114,7 +114,7 @@ public:
virtual void InitNode(TComputationContext&) const = 0;
- virtual NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const = 0;
+ virtual NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const = 0;
virtual IComputationNode* AddDependence(const IComputationNode* node) = 0;
@@ -195,7 +195,7 @@ public:
virtual void LoadGraphState(TStringBuf state) = 0;
};
-class TNodeFactory;
+class TNodeFactory;
typedef std::function<IComputationNode* (TNode* node, bool pop)> TNodeLocator;
typedef std::function<void (IComputationNode*)> TNodePushBack;
@@ -212,7 +212,7 @@ struct TComputationNodeFactoryContext {
NUdf::EValidateMode ValidateMode;
NUdf::EValidatePolicy ValidatePolicy;
EGraphPerProcess GraphPerProcess;
- TComputationMutables& Mutables;
+ TComputationMutables& Mutables;
TComputationNodeOnNodeMap& ElementsCache;
const TNodePushBack NodePushBack;
@@ -228,7 +228,7 @@ struct TComputationNodeFactoryContext {
const NUdf::IValueBuilder* builder,
NUdf::EValidateMode validateMode,
NUdf::EValidatePolicy validatePolicy,
- EGraphPerProcess graphPerProcess,
+ EGraphPerProcess graphPerProcess,
TComputationMutables& mutables,
TComputationNodeOnNodeMap& elementsCache,
TNodePushBack&& nodePushBack
@@ -245,7 +245,7 @@ struct TComputationNodeFactoryContext {
, ValidateMode(validateMode)
, ValidatePolicy(validatePolicy)
, GraphPerProcess(graphPerProcess)
- , Mutables(mutables)
+ , Mutables(mutables)
, ElementsCache(elementsCache)
, NodePushBack(std::move(nodePushBack))
{}
@@ -254,20 +254,20 @@ struct TComputationNodeFactoryContext {
using TComputationNodeFactory = std::function<IComputationNode* (TCallable&, const TComputationNodeFactoryContext&)>;
using TStreamEmitter = std::function<void(NUdf::TUnboxedValue&&)>;
-struct TComputationPatternOpts {
+struct TComputationPatternOpts {
TComputationPatternOpts(const std::shared_ptr<TInjectedAlloc>& cacheAlloc, const std::shared_ptr<TTypeEnvironment>& cacheEnv)
- : CacheAlloc(std::move(cacheAlloc))
- , CacheEnv(std::move(cacheEnv))
- , AllocState(CacheAlloc->InjectedState())
- , Env(*CacheEnv)
- {}
-
- TComputationPatternOpts(TAllocState& allocState, const TTypeEnvironment& env)
- : AllocState(allocState)
- , Env(env)
- {}
-
- TComputationPatternOpts(
+ : CacheAlloc(std::move(cacheAlloc))
+ , CacheEnv(std::move(cacheEnv))
+ , AllocState(CacheAlloc->InjectedState())
+ , Env(*CacheEnv)
+ {}
+
+ TComputationPatternOpts(TAllocState& allocState, const TTypeEnvironment& env)
+ : AllocState(allocState)
+ , Env(env)
+ {}
+
+ TComputationPatternOpts(
TAllocState& allocState,
const TTypeEnvironment& env,
TComputationNodeFactory factory,
@@ -288,28 +288,28 @@ struct TComputationPatternOpts {
, GraphPerProcess(graphPerProcess)
, Stats(stats)
, CountersProvider(countersProvider)
- {}
-
- void SetOptions(TComputationNodeFactory factory, const IFunctionRegistry* functionRegistry,
- NUdf::EValidateMode validateMode, NUdf::EValidatePolicy validatePolicy,
+ {}
+
+ void SetOptions(TComputationNodeFactory factory, const IFunctionRegistry* functionRegistry,
+ NUdf::EValidateMode validateMode, NUdf::EValidatePolicy validatePolicy,
const TString& optLLVM, EGraphPerProcess graphPerProcess, IStatsRegistry* stats = nullptr,
NUdf::ICountersProvider* counters = nullptr, const NUdf::ISecureParamsProvider* secureParamsProvider = nullptr) {
- Factory = factory;
- FunctionRegistry = functionRegistry;
- ValidateMode = validateMode;
- ValidatePolicy = validatePolicy;
+ Factory = factory;
+ FunctionRegistry = functionRegistry;
+ ValidateMode = validateMode;
+ ValidatePolicy = validatePolicy;
OptLLVM = optLLVM;
- GraphPerProcess = graphPerProcess;
- Stats = stats;
+ GraphPerProcess = graphPerProcess;
+ Stats = stats;
CountersProvider = counters;
SecureParamsProvider = secureParamsProvider;
}
-
+
mutable std::shared_ptr<TInjectedAlloc> CacheAlloc;
mutable std::shared_ptr<TTypeEnvironment> CacheEnv;
TAllocState& AllocState;
const TTypeEnvironment& Env;
-
+
TComputationNodeFactory Factory;
const IFunctionRegistry* FunctionRegistry = nullptr;
NUdf::EValidateMode ValidateMode = NUdf::EValidateMode::None;
@@ -319,42 +319,42 @@ struct TComputationPatternOpts {
IStatsRegistry* Stats = nullptr;
NUdf::ICountersProvider* CountersProvider = nullptr;
const NUdf::ISecureParamsProvider* SecureParamsProvider = nullptr;
-
- /// \todo split and exclude
+
+ /// \todo split and exclude
TComputationOptsFull ToComputationOptions(IRandomProvider& randomProvider, ITimeProvider& timeProvider, TAllocState* allocStatePtr = nullptr) const {
return TComputationOptsFull(Stats, allocStatePtr ? *allocStatePtr : AllocState, randomProvider, timeProvider, ValidatePolicy, SecureParamsProvider);
- }
+ }
+};
+
+class IComputationPattern: public TAtomicRefCount<IComputationPattern> {
+public:
+ typedef TIntrusivePtr<IComputationPattern> TPtr;
+
+ virtual ~IComputationPattern() = default;
+ virtual THolder<IComputationGraph> Clone(const TComputationOptsFull& compOpts) = 0;
};
-class IComputationPattern: public TAtomicRefCount<IComputationPattern> {
-public:
- typedef TIntrusivePtr<IComputationPattern> TPtr;
-
- virtual ~IComputationPattern() = default;
- virtual THolder<IComputationGraph> Clone(const TComputationOptsFull& compOpts) = 0;
-};
-
// node cookie's will be clean up when graph will be destroyed, explorer must not be changed/destroyed until that time
-IComputationPattern::TPtr MakeComputationPattern(
+IComputationPattern::TPtr MakeComputationPattern(
TExploringNodeVisitor& explorer,
- const TRuntimeNode& root,
- const std::vector<TNode*>& entryPoints,
+ const TRuntimeNode& root,
+ const std::vector<TNode*>& entryPoints,
const TComputationPatternOpts& opts);
-class IComputationPatternCache {
-public:
- typedef THolder<IComputationPatternCache> TPtr;
- typedef std::function<IComputationPattern::TPtr()> PrepareFunc;
-
- virtual ~IComputationPatternCache() = default;
- static TPtr Create();
-
- virtual IComputationPattern::TPtr EmplacePattern(const TString& serialized, PrepareFunc prepareFunc) = 0;
- virtual void CleanCache() = 0;
- virtual size_t GetSize() const = 0;
- virtual size_t GetCacheHits() const = 0;
-};
-
+class IComputationPatternCache {
+public:
+ typedef THolder<IComputationPatternCache> TPtr;
+ typedef std::function<IComputationPattern::TPtr()> PrepareFunc;
+
+ virtual ~IComputationPatternCache() = default;
+ static TPtr Create();
+
+ virtual IComputationPattern::TPtr EmplacePattern(const TString& serialized, PrepareFunc prepareFunc) = 0;
+ virtual void CleanCache() = 0;
+ virtual size_t GetSize() const = 0;
+ virtual size_t GetCacheHits() const = 0;
+};
+
std::unique_ptr<NUdf::ISecureParamsProvider> MakeSimpleSecureParamsProvider(const THashMap<TString, TString>& secureParams);
} // namespace NMiniKQL
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node_codegen.cpp b/ydb/library/yql/minikql/computation/mkql_computation_node_codegen.cpp
index 3285225e39..563f820bf6 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node_codegen.cpp
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node_codegen.cpp
@@ -807,17 +807,17 @@ TExternalCodegeneratorRootNode::TExternalCodegeneratorRootNode(TComputationMutab
: TExternalCodegeneratorNode(mutables, kind)
{}
-NUdf::TUnboxedValue TExternalCodegeneratorRootNode::GetValue(TComputationContext& compCtx) const {
+NUdf::TUnboxedValue TExternalCodegeneratorRootNode::GetValue(TComputationContext& compCtx) const {
if (compCtx.ExecuteLLVM && GetFunction)
- return GetFunction(&compCtx);
- return TExternalComputationNode::GetValue(compCtx);
+ return GetFunction(&compCtx);
+ return TExternalComputationNode::GetValue(compCtx);
}
-void TExternalCodegeneratorRootNode::SetValue(TComputationContext& compCtx, NUdf::TUnboxedValue&& newValue) const {
+void TExternalCodegeneratorRootNode::SetValue(TComputationContext& compCtx, NUdf::TUnboxedValue&& newValue) const {
if (compCtx.ExecuteLLVM && SetFunction)
- return SetFunction(&compCtx, newValue.Release());
+ return SetFunction(&compCtx, newValue.Release());
- TExternalComputationNode::SetValue(compCtx, std::move(newValue));
+ TExternalComputationNode::SetValue(compCtx, std::move(newValue));
}
TString TExternalCodegeneratorRootNode::MakeName(const TString& method) const {
@@ -829,7 +829,7 @@ TString TExternalCodegeneratorRootNode::MakeName(const TString& method) const {
void TExternalCodegeneratorRootNode::FinalizeFunctions(const NYql::NCodegen::ICodegen::TPtr& codegen) {
if (GetValueFunc)
GetFunction = reinterpret_cast<TGetPtr>(codegen->GetPointerToFunction(GetValueFunc));
-
+
if (SetValueFunc)
SetFunction = reinterpret_cast<TSetPtr>(codegen->GetPointerToFunction(SetValueFunc));
}
@@ -1666,8 +1666,8 @@ Value* GetNodeValue(IComputationNode* node, const TCodegenContext& ctx, BasicBlo
const auto retPtr = new AllocaInst(Type::getInt128Ty(context), 0U, "return_ptr", &ctx.Func->getEntryBlock().back());
const auto funType = ctx.Codegen->GetEffectiveTarget() != NYql::NCodegen::ETarget::Windows ?
- FunctionType::get(Type::getVoidTy(context), {retPtr->getType(), nodeThis->getType(), ctx.Ctx->getType()}, false):
- FunctionType::get(Type::getVoidTy(context), {nodeThis->getType(), retPtr->getType(), ctx.Ctx->getType()}, false);
+ FunctionType::get(Type::getVoidTy(context), {retPtr->getType(), nodeThis->getType(), ctx.Ctx->getType()}, false):
+ FunctionType::get(Type::getVoidTy(context), {nodeThis->getType(), retPtr->getType(), ctx.Ctx->getType()}, false);
const auto ptrTableType = PointerType::getUnqual(PointerType::getUnqual(PointerType::getUnqual(funType)));
const auto nodeVTable = CastInst::Create(Instruction::IntToPtr, ptr, ptrTableType, "node_vtable", block);
@@ -1676,9 +1676,9 @@ Value* GetNodeValue(IComputationNode* node, const TCodegenContext& ctx, BasicBlo
const auto func = new LoadInst(elem, "func", false, block);
if (ctx.Codegen->GetEffectiveTarget() != NYql::NCodegen::ETarget::Windows) {
- CallInst::Create(func, {retPtr, nodeThis, ctx.Ctx}, "", block);
+ CallInst::Create(func, {retPtr, nodeThis, ctx.Ctx}, "", block);
} else {
- CallInst::Create(func, {nodeThis, retPtr, ctx.Ctx}, "", block);
+ CallInst::Create(func, {nodeThis, retPtr, ctx.Ctx}, "", block);
}
ValueRelease(node->GetRepresentation(), retPtr, ctx, block);
@@ -1700,8 +1700,8 @@ void GetNodeValue(Value* value, IComputationNode* node, const TCodegenContext& c
const auto nodeThis = CastInst::Create(Instruction::IntToPtr, ptr, ptrType, "node_this", block);
const auto funType = ctx.Codegen->GetEffectiveTarget() != NYql::NCodegen::ETarget::Windows ?
- FunctionType::get(Type::getVoidTy(context), {value->getType(), nodeThis->getType(), ctx.Ctx->getType()}, false):
- FunctionType::get(Type::getVoidTy(context), {nodeThis->getType(), value->getType(), ctx.Ctx->getType()}, false);
+ FunctionType::get(Type::getVoidTy(context), {value->getType(), nodeThis->getType(), ctx.Ctx->getType()}, false):
+ FunctionType::get(Type::getVoidTy(context), {nodeThis->getType(), value->getType(), ctx.Ctx->getType()}, false);
const auto ptrTableType = PointerType::getUnqual(PointerType::getUnqual(PointerType::getUnqual(funType)));
const auto nodeVTable = CastInst::Create(Instruction::IntToPtr, ptr, ptrTableType, "node_vtable", block);
@@ -1710,9 +1710,9 @@ void GetNodeValue(Value* value, IComputationNode* node, const TCodegenContext& c
const auto func = new LoadInst(elem, "func", false, block);
if (ctx.Codegen->GetEffectiveTarget() != NYql::NCodegen::ETarget::Windows) {
- CallInst::Create(func, {value, nodeThis, ctx.Ctx}, "", block);
+ CallInst::Create(func, {value, nodeThis, ctx.Ctx}, "", block);
} else {
- CallInst::Create(func, {nodeThis, value, ctx.Ctx}, "", block);
+ CallInst::Create(func, {nodeThis, value, ctx.Ctx}, "", block);
}
}
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node_codegen.h b/ydb/library/yql/minikql/computation/mkql_computation_node_codegen.h
index dcddab180a..d9feede204 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node_codegen.h
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node_codegen.h
@@ -814,11 +814,11 @@ class TCodegeneratorRootNode: public TDerived, public ICodegeneratorRootNode
{
using TBase = TDerived;
public:
- NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const final {
+ NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const final {
if (compCtx.ExecuteLLVM && GetFunction)
- return GetFunction(&compCtx);
+ return GetFunction(&compCtx);
- return TBase::GetValue(compCtx);
+ return TBase::GetValue(compCtx);
}
protected:
@@ -947,9 +947,9 @@ public:
TExternalCodegeneratorRootNode(TComputationMutables& mutables, EValueRepresentation kind);
private:
- NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const final;
+ NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const final;
- void SetValue(TComputationContext& compCtx, NUdf::TUnboxedValue&& newValue) const final;
+ void SetValue(TComputationContext& compCtx, NUdf::TUnboxedValue&& newValue) const final;
TString MakeName(const TString& method) const;
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node_graph.cpp b/ydb/library/yql/minikql/computation/mkql_computation_node_graph.cpp
index ef4b28fb3b..f2b188ae47 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node_graph.cpp
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node_graph.cpp
@@ -8,7 +8,7 @@
#include <ydb/library/yql/minikql/mkql_string_util.h>
#include <util/system/env.h>
#include <util/system/mutex.h>
-#include <util/digest/city.h>
+#include <util/digest/city.h>
#ifndef MKQL_DISABLE_CODEGEN
#include <llvm/Support/raw_ostream.h>
@@ -132,101 +132,101 @@ private:
std::vector<TNode*>* Stack = nullptr;
};
-class TPatternNodes: public TAtomicRefCount<TPatternNodes> {
-public:
- typedef TIntrusivePtr<TPatternNodes> TPtr;
-
- TPatternNodes(TAllocState& allocState)
- : AllocState(allocState)
- , MemInfo(MakeIntrusive<TMemoryUsageInfo>("ComputationPatternNodes"))
- {
+class TPatternNodes: public TAtomicRefCount<TPatternNodes> {
+public:
+ typedef TIntrusivePtr<TPatternNodes> TPtr;
+
+ TPatternNodes(TAllocState& allocState)
+ : AllocState(allocState)
+ , MemInfo(MakeIntrusive<TMemoryUsageInfo>("ComputationPatternNodes"))
+ {
#ifndef NDEBUG
- AllocState.ActiveMemInfo.emplace(MemInfo.Get(), MemInfo);
+ AllocState.ActiveMemInfo.emplace(MemInfo.Get(), MemInfo);
#endif
- }
-
- ~TPatternNodes()
- {
- ComputationNodesList.clear();
- if (!UncaughtException()) {
+ }
+
+ ~TPatternNodes()
+ {
+ ComputationNodesList.clear();
+ if (!UncaughtException()) {
#ifndef NDEBUG
- AllocState.ActiveMemInfo.erase(MemInfo.Get());
+ AllocState.ActiveMemInfo.erase(MemInfo.Get());
#endif
- }
- }
-
- const TComputationMutables& GetMutables() const {
- return Mutables;
- }
-
- const TComputationNodePtrDeque& GetNodes() const {
- return ComputationNodesList;
- }
-
- IComputationNode* GetComputationNode(TNode* node, bool pop = false, bool require = true) {
+ }
+ }
+
+ const TComputationMutables& GetMutables() const {
+ return Mutables;
+ }
+
+ const TComputationNodePtrDeque& GetNodes() const {
+ return ComputationNodesList;
+ }
+
+ IComputationNode* GetComputationNode(TNode* node, bool pop = false, bool require = true) {
const auto cookie = node->GetCookie();
const auto result = reinterpret_cast<IComputationNode*>(cookie);
-
- if (cookie <= IS_NODE_REACHABLE) {
- MKQL_ENSURE(!require, "Computation graph builder, node not found, type:"
- << node->GetType()->GetKindAsStr());
- return result;
- }
-
- if (pop) {
- node->SetCookie(0);
- }
-
- return result;
- }
-
+
+ if (cookie <= IS_NODE_REACHABLE) {
+ MKQL_ENSURE(!require, "Computation graph builder, node not found, type:"
+ << node->GetType()->GetKindAsStr());
+ return result;
+ }
+
+ if (pop) {
+ node->SetCookie(0);
+ }
+
+ return result;
+ }
+
IComputationExternalNode* GetEntryPoint(size_t index, bool require) {
- MKQL_ENSURE(index < Runtime2Computation.size() && (!require || Runtime2Computation[index]),
- "Pattern nodes can not get computation node by index: " << index << ", require: " << require);
- return Runtime2Computation[index];
- }
-
- IComputationNode* GetRoot() {
- return RootNode;
- }
-
-private:
- friend class TComputationGraphBuildingVisitor;
+ MKQL_ENSURE(index < Runtime2Computation.size() && (!require || Runtime2Computation[index]),
+ "Pattern nodes can not get computation node by index: " << index << ", require: " << require);
+ return Runtime2Computation[index];
+ }
+
+ IComputationNode* GetRoot() {
+ return RootNode;
+ }
+
+private:
+ friend class TComputationGraphBuildingVisitor;
friend class TComputationGraph;
- TAllocState& AllocState;
- TIntrusivePtr<TMemoryUsageInfo> MemInfo;
- THolder<THolderFactory> HolderFactory;
+ TAllocState& AllocState;
+ TIntrusivePtr<TMemoryUsageInfo> MemInfo;
+ THolder<THolderFactory> HolderFactory;
THolder<TDefaultValueBuilder> ValueBuilder;
- TComputationMutables Mutables;
- TComputationNodePtrDeque ComputationNodesList;
+ TComputationMutables Mutables;
+ TComputationNodePtrDeque ComputationNodesList;
IComputationNode* RootNode = nullptr;
TComputationExternalNodePtrVector Runtime2Computation;
TComputationNodeOnNodeMap ElementsCache;
-};
-
+};
+
class TComputationGraphBuildingVisitor:
public INodeVisitor,
private TNonCopyable
{
public:
- TComputationGraphBuildingVisitor(const TComputationPatternOpts& opts)
- : Env(opts.Env)
+ TComputationGraphBuildingVisitor(const TComputationPatternOpts& opts)
+ : Env(opts.Env)
, TypeInfoHelper(new TTypeInfoHelper())
, CountersProvider(opts.CountersProvider)
, SecureParamsProvider(opts.SecureParamsProvider)
- , Factory(opts.Factory)
- , FunctionRegistry(*opts.FunctionRegistry)
- , ValidateMode(opts.ValidateMode)
- , ValidatePolicy(opts.ValidatePolicy)
- , GraphPerProcess(opts.GraphPerProcess)
- , PatternNodes(MakeIntrusive<TPatternNodes>(opts.AllocState))
- , ExternalAlloc(opts.CacheAlloc)
+ , Factory(opts.Factory)
+ , FunctionRegistry(*opts.FunctionRegistry)
+ , ValidateMode(opts.ValidateMode)
+ , ValidatePolicy(opts.ValidatePolicy)
+ , GraphPerProcess(opts.GraphPerProcess)
+ , PatternNodes(MakeIntrusive<TPatternNodes>(opts.AllocState))
+ , ExternalAlloc(opts.CacheAlloc)
{
PatternNodes->HolderFactory = MakeHolder<THolderFactory>(opts.AllocState, *PatternNodes->MemInfo, &FunctionRegistry);
PatternNodes->ValueBuilder = MakeHolder<TDefaultValueBuilder>(*PatternNodes->HolderFactory, ValidatePolicy);
PatternNodes->ValueBuilder->SetSecureParamsProvider(opts.SecureParamsProvider);
- NodeFactory = MakeHolder<TNodeFactory>(*PatternNodes->MemInfo, PatternNodes->Mutables);
+ NodeFactory = MakeHolder<TNodeFactory>(*PatternNodes->MemInfo, PatternNodes->Mutables);
}
~TComputationGraphBuildingVisitor() {
@@ -347,17 +347,17 @@ private:
"Bad data literal for type: " << NUdf::GetDataTypeInfo(slot).Name << ", " << value);
}
- NUdf::TUnboxedValue externalValue;
- if (ExternalAlloc) {
- if (value.IsString()) {
+ NUdf::TUnboxedValue externalValue;
+ if (ExternalAlloc) {
+ if (value.IsString()) {
externalValue = MakeString(value.AsStringRef());
- }
- }
- if (!externalValue) {
- externalValue = std::move(value);
- }
-
- AddNode(node, NodeFactory->CreateImmutableNode(std::move(externalValue)));
+ }
+ }
+ if (!externalValue) {
+ externalValue = std::move(value);
+ }
+
+ AddNode(node, NodeFactory->CreateImmutableNode(std::move(externalValue)));
}
void Visit(TStructLiteral& node) override {
@@ -405,7 +405,7 @@ private:
void Visit(TCallable& node) override {
if (node.HasResult()) {
node.GetResult().GetNode()->Accept(*this);
- auto computationNode = PatternNodes->ComputationNodesList.back().Get();
+ auto computationNode = PatternNodes->ComputationNodesList.back().Get();
node.SetCookie((ui64)computationNode);
return;
}
@@ -425,11 +425,11 @@ private:
CountersProvider,
SecureParamsProvider,
*NodeFactory,
- *PatternNodes->HolderFactory,
+ *PatternNodes->HolderFactory,
PatternNodes->ValueBuilder.Get(),
ValidateMode,
ValidatePolicy,
- GraphPerProcess,
+ GraphPerProcess,
PatternNodes->Mutables,
PatternNodes->ElementsCache,
std::bind(&TComputationGraphBuildingVisitor::PushBackNode, this, std::placeholders::_1));
@@ -468,33 +468,33 @@ private:
public:
IComputationNode* GetComputationNode(TNode* node, bool pop = false, bool require = true) {
- return PatternNodes->GetComputationNode(node, pop, require);
+ return PatternNodes->GetComputationNode(node, pop, require);
+ }
+
+ TMemoryUsageInfo& GetMemInfo() {
+ return *PatternNodes->MemInfo;
}
- TMemoryUsageInfo& GetMemInfo() {
- return *PatternNodes->MemInfo;
+ const THolderFactory& GetHolderFactory() const {
+ return *PatternNodes->HolderFactory;
}
- const THolderFactory& GetHolderFactory() const {
- return *PatternNodes->HolderFactory;
+ TPatternNodes::TPtr GetPatternNodes() {
+ return PatternNodes;
}
- TPatternNodes::TPtr GetPatternNodes() {
- return PatternNodes;
+ const TComputationNodePtrDeque& GetNodes() const {
+ return PatternNodes->GetNodes();
}
- const TComputationNodePtrDeque& GetNodes() const {
- return PatternNodes->GetNodes();
+ void PreserveRoot(IComputationNode* rootNode) {
+ PatternNodes->RootNode = rootNode;
}
- void PreserveRoot(IComputationNode* rootNode) {
- PatternNodes->RootNode = rootNode;
- }
-
void PreserveEntryPoints(TComputationExternalNodePtrVector&& runtime2Computation) {
- PatternNodes->Runtime2Computation = std::move(runtime2Computation);
- }
-
+ PatternNodes->Runtime2Computation = std::move(runtime2Computation);
+ }
+
private:
void PushBackNode(const IComputationNode::TPtr& computationNode) {
computationNode->RegisterDependencies();
@@ -518,29 +518,29 @@ private:
NUdf::EValidateMode ValidateMode;
NUdf::EValidatePolicy ValidatePolicy;
EGraphPerProcess GraphPerProcess;
- TPatternNodes::TPtr PatternNodes;
- const bool ExternalAlloc;
+ TPatternNodes::TPtr PatternNodes;
+ const bool ExternalAlloc;
};
class TComputationGraph : public IComputationGraph {
public:
- TComputationGraph(TPatternNodes::TPtr& patternNodes, const TComputationOptsFull& compOpts)
- : PatternNodes(patternNodes)
- , MemInfo(MakeIntrusive<TMemoryUsageInfo>("ComputationGraph"))
- , CompOpts(compOpts)
- {
+ TComputationGraph(TPatternNodes::TPtr& patternNodes, const TComputationOptsFull& compOpts)
+ : PatternNodes(patternNodes)
+ , MemInfo(MakeIntrusive<TMemoryUsageInfo>("ComputationGraph"))
+ , CompOpts(compOpts)
+ {
#ifndef NDEBUG
- CompOpts.AllocState.ActiveMemInfo.emplace(MemInfo.Get(), MemInfo);
+ CompOpts.AllocState.ActiveMemInfo.emplace(MemInfo.Get(), MemInfo);
#endif
HolderFactory = MakeHolder<THolderFactory>(CompOpts.AllocState, *MemInfo, patternNodes->HolderFactory->GetFunctionRegistry());
ValueBuilder = MakeHolder<TDefaultValueBuilder>(*HolderFactory.Get(), compOpts.ValidatePolicy);
ValueBuilder->SetSecureParamsProvider(CompOpts.SecureParamsProvider);
ArrowMemoryPool = MakeArrowMemoryPool(CompOpts.AllocState);
- }
+ }
~TComputationGraph() {
auto stats = CompOpts.Stats;
- auto& pagePool = HolderFactory->GetPagePool();
+ auto& pagePool = HolderFactory->GetPagePool();
MKQL_SET_MAX_STAT(stats, PagePool_PeakAllocated, pagePool.GetPeakAllocated());
MKQL_SET_MAX_STAT(stats, PagePool_PeakUsed, pagePool.GetPeakUsed());
MKQL_ADD_STAT(stats, PagePool_AllocCount, pagePool.GetAllocCount());
@@ -573,28 +573,28 @@ public:
NUdf::TUnboxedValue GetValue() override {
Prepare();
- return PatternNodes->GetRoot()->GetValue(*Ctx);
+ return PatternNodes->GetRoot()->GetValue(*Ctx);
}
IComputationExternalNode* GetEntryPoint(size_t index, bool require) override {
- Prepare();
- return PatternNodes->GetEntryPoint(index, require);
+ Prepare();
+ return PatternNodes->GetEntryPoint(index, require);
}
void Invalidate() override {
- std::fill_n(Ctx->MutableValues.get(), PatternNodes->GetMutables().CurValueIndex, NUdf::TUnboxedValue(NUdf::TUnboxedValuePod::Invalid()));
+ std::fill_n(Ctx->MutableValues.get(), PatternNodes->GetMutables().CurValueIndex, NUdf::TUnboxedValue(NUdf::TUnboxedValuePod::Invalid()));
}
const TComputationNodePtrDeque& GetNodes() const override {
- return PatternNodes->GetNodes();
+ return PatternNodes->GetNodes();
}
TMemoryUsageInfo& GetMemInfo() const override {
- return *MemInfo;
+ return *MemInfo;
}
const THolderFactory& GetHolderFactory() const override {
- return *HolderFactory;
+ return *HolderFactory;
}
ITerminator* GetTerminator() const override {
@@ -648,23 +648,23 @@ public:
private:
const TPatternNodes::TPtr PatternNodes;
const TIntrusivePtr<TMemoryUsageInfo> MemInfo;
- THolder<THolderFactory> HolderFactory;
+ THolder<THolderFactory> HolderFactory;
THolder<TDefaultValueBuilder> ValueBuilder;
std::unique_ptr<arrow::MemoryPool> ArrowMemoryPool;
- THolder<TComputationContext> Ctx;
- TComputationOptsFull CompOpts;
+ THolder<TComputationContext> Ctx;
+ TComputationOptsFull CompOpts;
bool IsPrepared = false;
};
} // namespace
-class TComputationPatternImpl : public IComputationPattern {
-public:
- TComputationPatternImpl(THolder<TComputationGraphBuildingVisitor>&& builder, const TComputationPatternOpts& opts)
-#if defined(MKQL_DISABLE_CODEGEN)
- : Codegen()
-#elif defined(MKQL_FORCE_USE_CODEGEN)
- : Codegen(NYql::NCodegen::ICodegen::Make(NYql::NCodegen::ETarget::Native))
+class TComputationPatternImpl : public IComputationPattern {
+public:
+ TComputationPatternImpl(THolder<TComputationGraphBuildingVisitor>&& builder, const TComputationPatternOpts& opts)
+#if defined(MKQL_DISABLE_CODEGEN)
+ : Codegen()
+#elif defined(MKQL_FORCE_USE_CODEGEN)
+ : Codegen(NYql::NCodegen::ICodegen::Make(NYql::NCodegen::ETarget::Native))
#else
: Codegen(opts.OptLLVM != "OFF" || GetEnv(TString("MKQL_FORCE_USE_LLVM")) ? NYql::NCodegen::ICodegen::Make(NYql::NCodegen::ETarget::Native) : NYql::NCodegen::ICodegen::TPtr())
#endif
@@ -692,7 +692,7 @@ public:
timerGen.Release();
timerGen.Report(opts.Stats);
}
-
+
if (hasCode) {
if (opts.OptLLVM.Contains("--dump-generated")) {
Cerr << "############### Begin generated module ###############" << Endl;
@@ -763,25 +763,25 @@ public:
timerFull.Report(opts.Stats);
}
#endif
- PatternNodes = builder->GetPatternNodes();
+ PatternNodes = builder->GetPatternNodes();
}
- ~TComputationPatternImpl() {
- if (Alloc) {
- Alloc->Acquire();
- }
- PatternNodes.Reset();
+ ~TComputationPatternImpl() {
+ if (Alloc) {
+ Alloc->Acquire();
+ }
+ PatternNodes.Reset();
TypeEnv.reset();
- if (Alloc) {
- Alloc->Release();
- }
- }
-
+ if (Alloc) {
+ Alloc->Release();
+ }
+ }
+
void HoldInternals(const std::shared_ptr<TScopedAlloc>& alloc, const std::shared_ptr<TTypeEnvironment>& typeEnv) {
- Alloc = alloc;
- TypeEnv = typeEnv;
- }
-
+ Alloc = alloc;
+ TypeEnv = typeEnv;
+ }
+
TStringBuf GetCompileOptions(const TString& s) {
const TString flag = "--compile-options";
auto lpos = s.rfind(flag);
@@ -795,23 +795,23 @@ public:
return TStringBuf(s, lpos, rpos - lpos);
};
- THolder<IComputationGraph> Clone(const TComputationOptsFull& compOpts) final {
- return MakeHolder<TComputationGraph>(PatternNodes, compOpts);
- }
-private:
+ THolder<IComputationGraph> Clone(const TComputationOptsFull& compOpts) final {
+ return MakeHolder<TComputationGraph>(PatternNodes, compOpts);
+ }
+private:
std::shared_ptr<TScopedAlloc> Alloc;
std::shared_ptr<TTypeEnvironment> TypeEnv;
- TPatternNodes::TPtr PatternNodes;
+ TPatternNodes::TPtr PatternNodes;
NYql::NCodegen::ICodegen::TPtr Codegen;
-};
-
-
-TIntrusivePtr<TComputationPatternImpl> MakeComputationPatternImpl(TExploringNodeVisitor& explorer, const TRuntimeNode& root,
- const std::vector<TNode*>& entryPoints, const TComputationPatternOpts& opts) {
+};
+
+
+TIntrusivePtr<TComputationPatternImpl> MakeComputationPatternImpl(TExploringNodeVisitor& explorer, const TRuntimeNode& root,
+ const std::vector<TNode*>& entryPoints, const TComputationPatternOpts& opts) {
TDependencyScanVisitor depScanner;
- depScanner.Walk(root.GetNode(), opts.Env);
+ depScanner.Walk(root.GetNode(), opts.Env);
- auto builder = MakeHolder<TComputationGraphBuildingVisitor>(opts);
+ auto builder = MakeHolder<TComputationGraphBuildingVisitor>(opts);
for (const auto& node : explorer.GetNodes()) {
Y_VERIFY(node->GetCookie() <= IS_NODE_REACHABLE, "TNode graph should not be reused");
if (node->GetCookie() == IS_NODE_REACHABLE) {
@@ -822,65 +822,65 @@ TIntrusivePtr<TComputationPatternImpl> MakeComputationPatternImpl(TExploringNode
const auto rootNode = builder->GetComputationNode(root.GetNode());
TComputationExternalNodePtrVector runtime2Computation;
- runtime2Computation.resize(entryPoints.size(), nullptr);
+ runtime2Computation.resize(entryPoints.size(), nullptr);
for (const auto& node : explorer.GetNodes()) {
- for (auto iter = std::find(entryPoints.cbegin(), entryPoints.cend(), node); entryPoints.cend() != iter; iter = std::find(iter + 1, entryPoints.cend(), node)) {
+ for (auto iter = std::find(entryPoints.cbegin(), entryPoints.cend(), node); entryPoints.cend() != iter; iter = std::find(iter + 1, entryPoints.cend(), node)) {
runtime2Computation[iter - entryPoints.begin()] = dynamic_cast<IComputationExternalNode*>(builder->GetComputationNode(node));
}
- node->SetCookie(0);
+ node->SetCookie(0);
}
- builder->PreserveRoot(rootNode);
- builder->PreserveEntryPoints(std::move(runtime2Computation));
+ builder->PreserveRoot(rootNode);
+ builder->PreserveEntryPoints(std::move(runtime2Computation));
- return MakeIntrusive<TComputationPatternImpl>(std::move(builder), opts);
+ return MakeIntrusive<TComputationPatternImpl>(std::move(builder), opts);
}
-IComputationPattern::TPtr MakeComputationPattern(TExploringNodeVisitor& explorer, const TRuntimeNode& root,
- const std::vector<TNode*>& entryPoints, const TComputationPatternOpts& opts) {
- auto pattern = MakeComputationPatternImpl(explorer, root, entryPoints, opts);
- if (opts.CacheAlloc) {
- pattern->HoldInternals(opts.CacheAlloc->InjectedScopeAlloc(), opts.CacheEnv);
- }
- return pattern;
-}
-
-class TComputationPatternCache: public IComputationPatternCache {
-public:
- IComputationPattern::TPtr EmplacePattern(const TString& serialized, PrepareFunc prepareFunc) override;
- void CleanCache() override {
- RewriteToCache.clear();
- }
- size_t GetSize() const override {
- return RewriteToCache.size();
- }
- size_t GetCacheHits() const override {
- return CacheHits;
- }
-private:
- TMutex CacheMutex;
- THashMap<uint128, IComputationPattern::TPtr> RewriteToCache;
- ui64 CacheHits = 0;
- ui64 CacheMiss = 0;
-};
-
-IComputationPatternCache::TPtr IComputationPatternCache::Create() {
+IComputationPattern::TPtr MakeComputationPattern(TExploringNodeVisitor& explorer, const TRuntimeNode& root,
+ const std::vector<TNode*>& entryPoints, const TComputationPatternOpts& opts) {
+ auto pattern = MakeComputationPatternImpl(explorer, root, entryPoints, opts);
+ if (opts.CacheAlloc) {
+ pattern->HoldInternals(opts.CacheAlloc->InjectedScopeAlloc(), opts.CacheEnv);
+ }
+ return pattern;
+}
+
+class TComputationPatternCache: public IComputationPatternCache {
+public:
+ IComputationPattern::TPtr EmplacePattern(const TString& serialized, PrepareFunc prepareFunc) override;
+ void CleanCache() override {
+ RewriteToCache.clear();
+ }
+ size_t GetSize() const override {
+ return RewriteToCache.size();
+ }
+ size_t GetCacheHits() const override {
+ return CacheHits;
+ }
+private:
+ TMutex CacheMutex;
+ THashMap<uint128, IComputationPattern::TPtr> RewriteToCache;
+ ui64 CacheHits = 0;
+ ui64 CacheMiss = 0;
+};
+
+IComputationPatternCache::TPtr IComputationPatternCache::Create() {
return THolder(new TComputationPatternCache());
-}
-
-IComputationPattern::TPtr TComputationPatternCache::EmplacePattern(const TString& serialized, PrepareFunc prepareFunc) {
- const uint128 hash = CityHash128(serialized);
- with_lock(CacheMutex) {
- auto iter = RewriteToCache.find(hash);
- if (iter == RewriteToCache.end()) {
- ++CacheMiss;
- // TODO: do not block without collision by prepareFunc()
- iter = RewriteToCache.emplace(hash, prepareFunc()).first;
- } else {
- ++CacheHits;
- }
- return iter->second;
- }
-}
-
+}
+
+IComputationPattern::TPtr TComputationPatternCache::EmplacePattern(const TString& serialized, PrepareFunc prepareFunc) {
+ const uint128 hash = CityHash128(serialized);
+ with_lock(CacheMutex) {
+ auto iter = RewriteToCache.find(hash);
+ if (iter == RewriteToCache.end()) {
+ ++CacheMiss;
+ // TODO: do not block without collision by prepareFunc()
+ iter = RewriteToCache.emplace(hash, prepareFunc()).first;
+ } else {
+ ++CacheHits;
+ }
+ return iter->second;
+ }
+}
+
} // namespace NMiniKQL
} // namespace NKikimr
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node_graph_saveload_ut.cpp b/ydb/library/yql/minikql/computation/mkql_computation_node_graph_saveload_ut.cpp
index 20609adffb..cc734e11d6 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node_graph_saveload_ut.cpp
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node_graph_saveload_ut.cpp
@@ -44,13 +44,13 @@ namespace {
PgmBuilder.Reset(new TProgramBuilder(*Env, *FunctionRegistry));
}
- THolder<IComputationGraph> BuildGraph(TRuntimeNode pgm, const std::vector<TNode*>& entryPoints = std::vector<TNode*>()) {
+ THolder<IComputationGraph> BuildGraph(TRuntimeNode pgm, const std::vector<TNode*>& entryPoints = std::vector<TNode*>()) {
Explorer.Walk(pgm.GetNode(), *Env);
TComputationPatternOpts opts(Alloc.Ref(), *Env, GetAuxCallableFactory(),
- FunctionRegistry.Get(),
+ FunctionRegistry.Get(),
NUdf::EValidateMode::None, NUdf::EValidatePolicy::Fail, "OFF", EGraphPerProcess::Multi);
Pattern = MakeComputationPattern(Explorer, pgm, entryPoints, opts);
- TComputationOptsFull compOpts = opts.ToComputationOptions(*RandomProvider, *TimeProvider);
+ TComputationOptsFull compOpts = opts.ToComputationOptions(*RandomProvider, *TimeProvider);
return Pattern->Clone(compOpts);
}
@@ -63,7 +63,7 @@ namespace {
THolder<TProgramBuilder> PgmBuilder;
TExploringNodeVisitor Explorer;
- IComputationPattern::TPtr Pattern;
+ IComputationPattern::TPtr Pattern;
};
struct TStreamWithYield : public NUdf::TBoxedValue {
@@ -138,7 +138,7 @@ Y_UNIT_TEST_SUITE(TMiniKQLSaveLoadTest) {
auto graph = setup.BuildGraph(pgmReturn, {streamNode});
auto streamValue = NUdf::TUnboxedValuePod(new TStreamWithYield(streamItems, yieldPos, startIndex));
- graph->GetEntryPoint(0, true)->SetValue(graph->GetContext(), std::move(streamValue));
+ graph->GetEntryPoint(0, true)->SetValue(graph->GetContext(), std::move(streamValue));
return graph;
};
@@ -205,7 +205,7 @@ Y_UNIT_TEST_SUITE(TMiniKQLSaveLoadTest) {
auto graph = setup.BuildGraph(pgmReturn, {streamNode});
auto streamValue = NUdf::TUnboxedValuePod(new TStreamWithYield(streamItems, yieldPos, startIndex));
- graph->GetEntryPoint(0, true)->SetValue(graph->GetContext(), std::move(streamValue));
+ graph->GetEntryPoint(0, true)->SetValue(graph->GetContext(), std::move(streamValue));
return graph;
};
@@ -331,7 +331,7 @@ Y_UNIT_TEST_SUITE(TMiniKQLSaveLoadTest) {
}
auto streamValue = NUdf::TUnboxedValuePod(new TStreamWithYield(streamItems, yieldPos, startIndex));
- graph->GetEntryPoint(0, true)->SetValue(graph->GetContext(), std::move(streamValue));
+ graph->GetEntryPoint(0, true)->SetValue(graph->GetContext(), std::move(streamValue));
return graph;
};
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node_holders.cpp b/ydb/library/yql/minikql/computation/mkql_computation_node_holders.cpp
index d7e0e06367..67a7cfb302 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node_holders.cpp
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node_holders.cpp
@@ -555,10 +555,10 @@ public:
class TArrayNode: public TMutableCodegeneratorFallbackNode<TArrayNode> {
typedef TMutableCodegeneratorFallbackNode<TArrayNode> TBaseComputation;
public:
- TArrayNode(TComputationMutables& mutables, TComputationNodePtrVector&& valueNodes)
+ TArrayNode(TComputationMutables& mutables, TComputationNodePtrVector&& valueNodes)
: TBaseComputation(mutables, EValueRepresentation::Boxed)
- , ValueNodes(std::move(valueNodes))
- , Cache(mutables)
+ , ValueNodes(std::move(valueNodes))
+ , Cache(mutables)
{
}
@@ -585,7 +585,7 @@ public:
const auto valType = Type::getInt128Ty(context);
const auto idxType = Type::getInt32Ty(context);
const auto type = ArrayType::get(valType, ValueNodes.size());
- /// TODO: how to get computation context or other workaround
+ /// TODO: how to get computation context or other workaround
const auto itms = *Stateless || ctx.AlwaysInline ?
new AllocaInst(PointerType::getUnqual(type), 0U, "itms", &ctx.Func->getEntryBlock().back()):
new AllocaInst(PointerType::getUnqual(type), 0U, "itms", block);
@@ -612,10 +612,10 @@ private:
class TEmptyNode : public TMutableCodegeneratorNode<TEmptyNode> {
typedef TMutableCodegeneratorNode<TEmptyNode> TBaseComputation;
public:
- TEmptyNode(TComputationMutables& mutables)
+ TEmptyNode(TComputationMutables& mutables)
: TBaseComputation(mutables, EValueRepresentation::Boxed)
- {}
-
+ {}
+
NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
return ctx.HolderFactory.GetEmptyContainer();
}
@@ -1730,7 +1730,7 @@ public:
return false;
}
- value = Parent->PayloadPacker.Unpack(GetSmallValue(Iterator.GetValue()), Parent->CompCtx.HolderFactory);
+ value = Parent->PayloadPacker.Unpack(GetSmallValue(Iterator.GetValue()), Parent->CompCtx.HolderFactory);
++Iterator;
return true;
}
@@ -1840,7 +1840,7 @@ public:
, Map(std::move(map))
, KeyPacker(true, keyType)
, PayloadPacker(false, payloadType)
- , CompCtx(*ctx)
+ , CompCtx(*ctx)
{
}
@@ -1858,7 +1858,7 @@ private:
if (!it.Ok())
return NUdf::TUnboxedValuePod();
- return CompCtx.HolderFactory.Create<TPayloadList>(this, it);
+ return CompCtx.HolderFactory.Create<TPayloadList>(this, it);
}
NUdf::TUnboxedValue GetKeysIterator() const override {
@@ -1889,7 +1889,7 @@ private:
const TMapType Map;
mutable TValuePacker KeyPacker;
mutable TValuePacker PayloadPacker;
- TComputationContext& CompCtx;
+ TComputationContext& CompCtx;
};
class THashedDictHolder: public TComputationValue<THashedDictHolder> {
@@ -2423,13 +2423,13 @@ private:
};
class TDictNode: public TMutableComputationNode<TDictNode> {
- typedef TMutableComputationNode<TDictNode> TBaseComputation;
+ typedef TMutableComputationNode<TDictNode> TBaseComputation;
public:
- TDictNode(TComputationMutables& mutables,
+ TDictNode(TComputationMutables& mutables,
std::vector<std::pair<IComputationNode*, IComputationNode*>>&& itemNodes,
const TKeyTypes& types, bool isTuple, TType* encodedType)
- : TBaseComputation(mutables)
- , ItemNodes(std::move(itemNodes))
+ : TBaseComputation(mutables)
+ , ItemNodes(std::move(itemNodes))
, Types(types)
, IsTuple(isTuple)
, EncodedType(encodedType)
@@ -2439,7 +2439,7 @@ public:
TKeyPayloadPairVector items;
items.reserve(ItemNodes.size());
for (const auto& node : ItemNodes) {
- items.emplace_back(node.first->GetValue(ctx), node.second->GetValue(ctx));
+ items.emplace_back(node.first->GetValue(ctx), node.second->GetValue(ctx));
}
std::optional<TValuePacker> packer;
@@ -2480,9 +2480,9 @@ private:
class TVariantNode : public TMutableCodegeneratorNode<TVariantNode> {
typedef TMutableCodegeneratorNode<TVariantNode> TBaseComputation;
public:
- TVariantNode(TComputationMutables& mutables, IComputationNode* itemNode, ui32 index)
+ TVariantNode(TComputationMutables& mutables, IComputationNode* itemNode, ui32 index)
: TBaseComputation(mutables, EValueRepresentation::Any)
- , ItemNode(itemNode)
+ , ItemNode(itemNode)
, Index(index)
{}
@@ -3512,7 +3512,7 @@ TNodeFactory::TNodeFactory(TMemoryUsageInfo& memInfo, TComputationMutables& muta
IComputationNode* TNodeFactory::CreateEmptyNode() const
{
- return new TEmptyNode(Mutables);
+ return new TEmptyNode(Mutables);
}
IComputationNode* TNodeFactory::CreateOptionalNode(IComputationNode* item) const
@@ -3523,10 +3523,10 @@ IComputationNode* TNodeFactory::CreateOptionalNode(IComputationNode* item) const
IComputationNode* TNodeFactory::CreateArrayNode(TComputationNodePtrVector&& values) const
{
if (values.empty()) {
- return new TEmptyNode(Mutables);
+ return new TEmptyNode(Mutables);
}
- return new TArrayNode(Mutables, std::move(values));
+ return new TArrayNode(Mutables, std::move(values));
}
IComputationNode* TNodeFactory::CreateDictNode(
@@ -3534,14 +3534,14 @@ IComputationNode* TNodeFactory::CreateDictNode(
const TKeyTypes& types, bool isTuple, TType* encodedType) const
{
if (items.empty()) {
- return new TEmptyNode(Mutables);
+ return new TEmptyNode(Mutables);
}
return new TDictNode(Mutables, std::move(items), types, isTuple, encodedType);
}
IComputationNode* TNodeFactory::CreateVariantNode(IComputationNode* item, ui32 index) const {
- return new TVariantNode(Mutables, item, index);
+ return new TVariantNode(Mutables, item, index);
}
IComputationNode* TNodeFactory::CreateTypeNode(TType* type) const {
@@ -3754,7 +3754,7 @@ Value* TContainerCacheOnContext::GenNewArray(ui32 sz, Value* items, const TCodeg
}
#endif
-TPlainContainerCache::TPlainContainerCache() {
+TPlainContainerCache::TPlainContainerCache() {
Clear();
}
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node_holders.h b/ydb/library/yql/minikql/computation/mkql_computation_node_holders.h
index d75290d9f8..4486d6f43a 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node_holders.h
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node_holders.h
@@ -568,7 +568,7 @@ public:
private:
TMemoryUsageInfo& MemInfo;
- TComputationMutables& Mutables;
+ TComputationMutables& Mutables;
};
void GetDictionaryKeyTypes(TType* keyType, TKeyTypes& types, bool& isTuple, bool& encoded);
@@ -600,25 +600,25 @@ private:
ui8 CacheIndex = 0U;
};
-template<class TObject>
-class TMutableObjectOverBoxedValue {
-public:
- TMutableObjectOverBoxedValue(TComputationMutables& mutables)
- : ObjectIndex(mutables.CurValueIndex++)
- {}
-
- template <typename... Args>
- TObject& RefMutableObject(TComputationContext& ctx, Args&&... args) const {
- auto& unboxed = ctx.MutableValues[ObjectIndex];
- if (!unboxed.HasValue()) {
- unboxed = ctx.HolderFactory.Create<TObject>(std::forward<Args>(args)...);
- }
- auto boxed = unboxed.AsBoxed();
- return *static_cast<TObject*>(boxed.Get());
- }
-private:
- const ui32 ObjectIndex;
-};
-
+template<class TObject>
+class TMutableObjectOverBoxedValue {
+public:
+ TMutableObjectOverBoxedValue(TComputationMutables& mutables)
+ : ObjectIndex(mutables.CurValueIndex++)
+ {}
+
+ template <typename... Args>
+ TObject& RefMutableObject(TComputationContext& ctx, Args&&... args) const {
+ auto& unboxed = ctx.MutableValues[ObjectIndex];
+ if (!unboxed.HasValue()) {
+ unboxed = ctx.HolderFactory.Create<TObject>(std::forward<Args>(args)...);
+ }
+ auto boxed = unboxed.AsBoxed();
+ return *static_cast<TObject*>(boxed.Get());
+ }
+private:
+ const ui32 ObjectIndex;
+};
+
} // namespace NMiniKQL
} // namespace NKikimr
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node_impl.cpp b/ydb/library/yql/minikql/computation/mkql_computation_node_impl.cpp
index eb19f88fe0..15777c3288 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node_impl.cpp
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node_impl.cpp
@@ -1,7 +1,7 @@
#include "mkql_computation_node_impl.h"
#include "ydb/library/yql/minikql/mkql_string_util.h"
-
+
namespace NKikimr {
namespace NMiniKQL {
@@ -38,12 +38,12 @@ TUnboxedImmutableComputationNode::~TUnboxedImmutableComputationNode() {
MKQL_MEM_RETURN(MemInfo, this, sizeof(*this));
}
-NUdf::TUnboxedValue TUnboxedImmutableComputationNode::GetValue(TComputationContext& compCtx) const {
- Y_UNUSED(compCtx);
- if (RepresentationKind == EValueRepresentation::String) {
- /// TODO: YQL-4461
- return MakeString(UnboxedValue.AsStringRef());
- }
+NUdf::TUnboxedValue TUnboxedImmutableComputationNode::GetValue(TComputationContext& compCtx) const {
+ Y_UNUSED(compCtx);
+ if (RepresentationKind == EValueRepresentation::String) {
+ /// TODO: YQL-4461
+ return MakeString(UnboxedValue.AsStringRef());
+ }
return UnboxedValue;
}
@@ -96,7 +96,7 @@ IComputationNode* TStatefulComputationNode<IComputationNodeInterface, Serializab
Dependencies.emplace_back(node);
return this;
}
-
+
template <class IComputationNodeInterface, bool SerializableState>
EValueRepresentation TStatefulComputationNode<IComputationNodeInterface, SerializableState>::GetRepresentation() const {
return RepresentationKind;
@@ -116,7 +116,7 @@ template class TStatefulComputationNode<IComputationExternalNode, true>;
void TExternalComputationNode::CollectDependentIndexes(const IComputationNode*, TIndexesMap& map) const {
map.emplace(ValueIndex, RepresentationKind);
}
-
+
TExternalComputationNode::TExternalComputationNode(TComputationMutables& mutables, EValueRepresentation kind)
: TStatefulComputationNode(mutables, kind)
{}
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node_impl.h b/ydb/library/yql/minikql/computation/mkql_computation_node_impl.h
index 5372ba3c6b..0a63ca9d34 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node_impl.h
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node_impl.h
@@ -44,7 +44,7 @@ public:
private:
void InitNode(TComputationContext&) const override {}
- NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const final;
+ NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const final;
const IComputationNode* GetSource() const final;
@@ -88,15 +88,15 @@ protected:
EValueRepresentation GetRepresentation() const override;
- NUdf::TUnboxedValue& ValueRef(TComputationContext& compCtx) const {
- return compCtx.MutableValues[ValueIndex];
+ NUdf::TUnboxedValue& ValueRef(TComputationContext& compCtx) const {
+ return compCtx.MutableValues[ValueIndex];
}
-
+
ui32 GetIndex() const final;
TConstComputationNodePtrVector Dependencies;
- const ui32 ValueIndex;
+ const ui32 ValueIndex;
const EValueRepresentation RepresentationKind;
private:
ui32 GetDependencesCount() const final;
@@ -106,13 +106,13 @@ class TExternalComputationNode: public TStatefulComputationNode<IComputationExte
{
public:
TExternalComputationNode(TComputationMutables& mutables, EValueRepresentation kind = EValueRepresentation::Any);
-
+
protected:
- NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const override;
+ NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const override;
NUdf::TUnboxedValue& RefValue(TComputationContext& compCtx) const override;
- void SetValue(TComputationContext& compCtx, NUdf::TUnboxedValue&& value) const override;
+ void SetValue(TComputationContext& compCtx, NUdf::TUnboxedValue&& value) const override;
TString DebugString() const final;
private:
@@ -177,10 +177,10 @@ private:
}
const IComputationNode* GetSource() const final { return this; }
-protected:
+protected:
TStatefulSourceComputationNode(TComputationMutables& mutables, EValueRepresentation kind = EValueRepresentation::Any)
: TStatefulComputationNode(mutables, kind)
- {}
+ {}
void DependsOn(IComputationNode* node) const {
if (node) {
@@ -703,29 +703,29 @@ private:
THROW yexception() << "Can't get index from decorator node.";
}
- NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const final {
+ NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const final {
return static_cast<const TDerived*>(this)->DoCalculate(compCtx, Node->GetValue(compCtx));
- }
-
-protected:
+ }
+
+protected:
TDecoratorComputationNode(IComputationNode* node, EValueRepresentation kind)
: Node(node), Kind(kind)
{}
- TDecoratorComputationNode(IComputationNode* node)
+ TDecoratorComputationNode(IComputationNode* node)
: Node(node), Kind(node->GetRepresentation())
- {}
+ {}
+
+
+ TString DebugString() const override {
+ return TypeName<TDerived>() += "(" + Node->DebugString() + ")";
+ }
-
- TString DebugString() const override {
- return TypeName<TDerived>() += "(" + Node->DebugString() + ")";
- }
-
IComputationNode *const Node;
const EValueRepresentation Kind;
-};
-
-template <typename TDerived>
+};
+
+template <typename TDerived>
class TBinaryComputationNode: public TRefCountedComputationNode<IComputationNode>
{
private:
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node_pack.cpp b/ydb/library/yql/minikql/computation/mkql_computation_node_pack.cpp
index d270dd8214..625a269eaf 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node_pack.cpp
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node_pack.cpp
@@ -998,14 +998,14 @@ TValuePacker::MakePackFunction() {
}
TValuePackerBoxed::TValuePackerBoxed(TMemoryUsageInfo* memInfo, bool stable, const TType* type, bool tryUseCodegen)
- : TBase(memInfo)
+ : TBase(memInfo)
, TValuePacker(stable, type, tryUseCodegen)
-{}
-
-TValuePackerBoxed::TValuePackerBoxed(TMemoryUsageInfo* memInfo, const TValuePacker& other)
- : TBase(memInfo)
- , TValuePacker(other)
-{}
-
+{}
+
+TValuePackerBoxed::TValuePackerBoxed(TMemoryUsageInfo* memInfo, const TValuePacker& other)
+ : TBase(memInfo)
+ , TValuePacker(other)
+{}
+
} // NMiniKQL
} // NKikimr
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node_pack.h b/ydb/library/yql/minikql/computation/mkql_computation_node_pack.h
index 1c900c0e30..c69f4467a3 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node_pack.h
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node_pack.h
@@ -67,12 +67,12 @@ private:
friend struct TValuePackerDetails;
};
-class TValuePackerBoxed : public TComputationValue<TValuePackerBoxed>, public TValuePacker {
- typedef TComputationValue<TValuePackerBoxed> TBase;
-public:
+class TValuePackerBoxed : public TComputationValue<TValuePackerBoxed>, public TValuePacker {
+ typedef TComputationValue<TValuePackerBoxed> TBase;
+public:
TValuePackerBoxed(TMemoryUsageInfo* memInfo, bool stable, const TType* type, bool tryUseCodegen = false);
- TValuePackerBoxed(TMemoryUsageInfo* memInfo, const TValuePacker& other);
-};
-
+ TValuePackerBoxed(TMemoryUsageInfo* memInfo, const TValuePacker& other);
+};
+
}
}
diff --git a/ydb/library/yql/minikql/computation/mkql_computation_node_pack_ut.cpp b/ydb/library/yql/minikql/computation/mkql_computation_node_pack_ut.cpp
index be62f94abd..6a47b51829 100644
--- a/ydb/library/yql/minikql/computation/mkql_computation_node_pack_ut.cpp
+++ b/ydb/library/yql/minikql/computation/mkql_computation_node_pack_ut.cpp
@@ -315,7 +315,7 @@ protected:
UNIT_ASSERT_VALUES_EQUAL_C(packedValue.size(), *expectedLength, additionalMsg);
}
ValidateEmbeddedLength(packedValue, additionalMsg);
- return packer.Unpack(packedValue, HolderFactory);
+ return packer.Unpack(packedValue, HolderFactory);
}
NUdf::TUnboxedValue TestPackUnpack(TType* type, const NUdf::TUnboxedValuePod& uValue, const TString& additionalMsg,
diff --git a/ydb/library/yql/minikql/computation/mkql_validate.cpp b/ydb/library/yql/minikql/computation/mkql_validate.cpp
index 9083f37352..b238b28aee 100644
--- a/ydb/library/yql/minikql/computation/mkql_validate.cpp
+++ b/ydb/library/yql/minikql/computation/mkql_validate.cpp
@@ -1,38 +1,38 @@
#include <library/cpp/containers/stack_vector/stack_vec.h>
#include <ydb/library/yql/public/udf/udf_value_builder.h>
-
-#include "mkql_validate.h"
+
+#include "mkql_validate.h"
#include <ydb/library/yql/minikql/mkql_node_printer.h>
#include <ydb/library/yql/minikql/mkql_type_ops.h>
-
-namespace NKikimr {
-namespace NMiniKQL {
-
-namespace {
-
+
+namespace NKikimr {
+namespace NMiniKQL {
+
+namespace {
+
static const TString VERIFY_DELIMITER = "\n - ";
-
-using namespace NUdf;
-
-template<class TValidateErrorPolicy>
-struct TLazyVerifyListValue;
-
-template<class TValidateErrorPolicy>
+
+using namespace NUdf;
+
+template<class TValidateErrorPolicy>
+struct TLazyVerifyListValue;
+
+template<class TValidateErrorPolicy>
struct TLazyVerifyListIterator: public TBoxedValue {
- TLazyVerifyListIterator(const TLazyVerifyListValue<TValidateErrorPolicy>& lazyList, ui64 index = 0)
- : LazyList(lazyList)
+ TLazyVerifyListIterator(const TLazyVerifyListValue<TValidateErrorPolicy>& lazyList, ui64 index = 0)
+ : LazyList(lazyList)
, OrigIter(TBoxedValueAccessor::GetListIterator(*lazyList.Orig))
- , Index(index)
- {
- if (!OrigIter) {
- TValidateErrorPolicy::Generate(TStringBuilder() << "TLazyVerifyListIterator constructor expect non empty result of GetListIterator" << VERIFY_DELIMITER << LazyList.Message);
- }
- }
-private:
- const TLazyVerifyListValue<TValidateErrorPolicy>& LazyList;
+ , Index(index)
+ {
+ if (!OrigIter) {
+ TValidateErrorPolicy::Generate(TStringBuilder() << "TLazyVerifyListIterator constructor expect non empty result of GetListIterator" << VERIFY_DELIMITER << LazyList.Message);
+ }
+ }
+private:
+ const TLazyVerifyListValue<TValidateErrorPolicy>& LazyList;
TUnboxedValue OrigIter;
- ui64 Index;
-
+ ui64 Index;
+
bool Next(NUdf::TUnboxedValue& item) final {
++Index;
if (!OrigIter.Next(item))
@@ -47,108 +47,108 @@ private:
++Index;
return OrigIter.Skip();
}
-};
-
-template<class TValidateErrorPolicy>
-struct TLazyVerifyDictValue;
-
-template<class TValidateErrorPolicy>
-struct TLazyVerifyListValue: public TBoxedValue {
+};
+
+template<class TValidateErrorPolicy>
+struct TLazyVerifyDictValue;
+
+template<class TValidateErrorPolicy>
+struct TLazyVerifyListValue: public TBoxedValue {
TLazyVerifyListValue(const IValueBuilder* valueBuilder, const TListType* listType, IBoxedValuePtr&& orig, const TString& message)
- : ValueBuilder(valueBuilder)
- , ListType(listType)
- , Orig(std::move(orig))
- , Message(message)
- {}
-
+ : ValueBuilder(valueBuilder)
+ , ListType(listType)
+ , Orig(std::move(orig))
+ , Message(message)
+ {}
+
const IValueBuilder *const ValueBuilder;
const TListType *const ListType;
const IBoxedValuePtr Orig;
const TString Message;
-private:
+private:
bool HasFastListLength() const override {
return TBoxedValueAccessor::HasFastListLength(*Orig);
- }
-
+ }
+
ui64 GetListLength() const override {
return TBoxedValueAccessor::GetListLength(*Orig);
- }
-
+ }
+
ui64 GetEstimatedListLength() const override {
return TBoxedValueAccessor::GetEstimatedListLength(*Orig);
- }
-
+ }
+
TUnboxedValue GetListIterator() const override {
return TUnboxedValuePod(new TLazyVerifyListIterator<TValidateErrorPolicy>(*this));
}
-
+
const TOpaqueListRepresentation* GetListRepresentation() const override {
- return nullptr;
- }
-
+ return nullptr;
+ }
+
IBoxedValuePtr ReverseListImpl(const IValueBuilder& builder) const override {
auto upList = TBoxedValueAccessor::ReverseListImpl(*Orig, builder);
- if (upList) {
+ if (upList) {
return new TLazyVerifyListValue<TValidateErrorPolicy>(ValueBuilder, ListType, std::move(upList), Message);
- }
- return upList;
- }
-
+ }
+ return upList;
+ }
+
IBoxedValuePtr SkipListImpl(const IValueBuilder& builder, ui64 count) const override {
auto upList = TBoxedValueAccessor::SkipListImpl(*Orig, builder, count);
- if (upList) {
+ if (upList) {
return new TLazyVerifyListValue<TValidateErrorPolicy>(ValueBuilder, ListType, std::move(upList), Message);
- }
- return upList;
- }
-
+ }
+ return upList;
+ }
+
IBoxedValuePtr TakeListImpl(const IValueBuilder& builder, ui64 count) const override {
auto upList = TBoxedValueAccessor::TakeListImpl(*Orig, builder, count);
- if (upList) {
+ if (upList) {
return new TLazyVerifyListValue<TValidateErrorPolicy>(ValueBuilder, ListType, std::move(upList), Message);
- }
- return upList;
- }
-
+ }
+ return upList;
+ }
+
IBoxedValuePtr ToIndexDictImpl(const IValueBuilder& builder) const override {
auto dictImpl = TBoxedValueAccessor::ToIndexDictImpl(*Orig, builder);
- if (!dictImpl) {
- return dictImpl;
- }
+ if (!dictImpl) {
+ return dictImpl;
+ }
return IBoxedValuePtr(new TLazyVerifyDictValue<TValidateErrorPolicy>(&builder, ListType->IndexDictKeyType(), ListType->GetItemType(), std::move(dictImpl), TStringBuilder() << "LazyDict over IndexToDict" << VERIFY_DELIMITER << Message));
- }
-
- bool HasListItems() const override {
- return TBoxedValueAccessor::HasListItems(*Orig);
- }
-
- bool HasDictItems() const override {
- const bool result = TBoxedValueAccessor::HasDictItems(*Orig);
- if (result) {
- TValidateErrorPolicy::Generate(TStringBuilder() << "TLazyVerifyListValue::HasDictItems expect false, but got true" << VERIFY_DELIMITER << Message);
- }
- return result;
- }
-};
-
+ }
+
+ bool HasListItems() const override {
+ return TBoxedValueAccessor::HasListItems(*Orig);
+ }
+
+ bool HasDictItems() const override {
+ const bool result = TBoxedValueAccessor::HasDictItems(*Orig);
+ if (result) {
+ TValidateErrorPolicy::Generate(TStringBuilder() << "TLazyVerifyListValue::HasDictItems expect false, but got true" << VERIFY_DELIMITER << Message);
+ }
+ return result;
+ }
+};
+
template<class TValidateErrorPolicy, bool Keys>
struct TLazyVerifyDictIterator: public TBoxedValue {
- TLazyVerifyDictIterator(const TLazyVerifyDictValue<TValidateErrorPolicy>& lazyDict, ui64 index = 0)
- : LazyDict(lazyDict)
+ TLazyVerifyDictIterator(const TLazyVerifyDictValue<TValidateErrorPolicy>& lazyDict, ui64 index = 0)
+ : LazyDict(lazyDict)
, OrigIter((Keys ? &TBoxedValueAccessor::GetKeysIterator : &TBoxedValueAccessor::GetDictIterator)(*LazyDict.Orig))
- , Index(index)
- {
- if (!OrigIter) {
- TValidateErrorPolicy::Generate(TStringBuilder() << "TLazyVerifyDictIterator constructor expect non empty result of GetDictIterator" << VERIFY_DELIMITER << LazyDict.Message);
- }
- }
-
-private:
- const TLazyVerifyDictValue<TValidateErrorPolicy>& LazyDict;
+ , Index(index)
+ {
+ if (!OrigIter) {
+ TValidateErrorPolicy::Generate(TStringBuilder() << "TLazyVerifyDictIterator constructor expect non empty result of GetDictIterator" << VERIFY_DELIMITER << LazyDict.Message);
+ }
+ }
+
+private:
+ const TLazyVerifyDictValue<TValidateErrorPolicy>& LazyDict;
TUnboxedValue OrigIter;
- ui64 Index;
-
+ ui64 Index;
+
bool Skip() final {
++Index;
return OrigIter.Skip();
@@ -173,36 +173,36 @@ private:
TStringBuilder() << "LazyDict[" << Index << "], validate payload" << VERIFY_DELIMITER << LazyDict.Message);
return true;
}
-};
-
-template<class TValidateErrorPolicy>
-struct TLazyVerifyDictValue: public TBoxedValue {
+};
+
+template<class TValidateErrorPolicy>
+struct TLazyVerifyDictValue: public TBoxedValue {
TLazyVerifyDictValue(const IValueBuilder* valueBuilder, const TDictType* dictType, IBoxedValuePtr&& orig, const TString& message)
: TLazyVerifyDictValue(valueBuilder, dictType->GetKeyType(), dictType->GetPayloadType(), std::move(orig), message)
- {}
-
+ {}
+
TLazyVerifyDictValue(const IValueBuilder* valueBuilder, const TType* keyType, const TType* payloadType, IBoxedValuePtr&& orig, const TString& message)
- : ValueBuilder(valueBuilder)
- , KeyType(keyType)
- , PayloadType(payloadType)
- , Orig(std::move(orig))
- , Message(message)
- {}
-
+ : ValueBuilder(valueBuilder)
+ , KeyType(keyType)
+ , PayloadType(payloadType)
+ , Orig(std::move(orig))
+ , Message(message)
+ {}
+
const IValueBuilder *const ValueBuilder;
const TType *const KeyType;
const TType *const PayloadType;
const IBoxedValuePtr Orig;
const TString Message;
-
-private:
+
+private:
ui64 GetDictLength() const override {
return TBoxedValueAccessor::GetDictLength(*Orig);
- }
+ }
TUnboxedValue GetKeysIterator() const override {
return TUnboxedValuePod(new TLazyVerifyDictIterator<TValidateErrorPolicy, true>(*this));
- }
+ }
TUnboxedValue GetDictIterator() const override {
return TUnboxedValuePod(new TLazyVerifyDictIterator<TValidateErrorPolicy, false>(*this));
@@ -219,108 +219,108 @@ private:
return TUnboxedValuePod();
}
- bool HasListItems() const override {
- const bool result = TBoxedValueAccessor::HasListItems(*Orig);
- if (result) {
- TValidateErrorPolicy::Generate(TStringBuilder() << "TLazyVerifyDictValue::HasListItems expect false, but got true" << VERIFY_DELIMITER << Message);
- }
- return result;
- }
-
- bool HasDictItems() const override {
- return TBoxedValueAccessor::HasDictItems(*Orig);
- }
-};
-
-template<class TValidateErrorPolicy, class TValidateMode>
-class WrapCallableValue: public TBoxedValue {
-public:
+ bool HasListItems() const override {
+ const bool result = TBoxedValueAccessor::HasListItems(*Orig);
+ if (result) {
+ TValidateErrorPolicy::Generate(TStringBuilder() << "TLazyVerifyDictValue::HasListItems expect false, but got true" << VERIFY_DELIMITER << Message);
+ }
+ return result;
+ }
+
+ bool HasDictItems() const override {
+ return TBoxedValueAccessor::HasDictItems(*Orig);
+ }
+};
+
+template<class TValidateErrorPolicy, class TValidateMode>
+class WrapCallableValue: public TBoxedValue {
+public:
WrapCallableValue(const TCallableType* callableType, TUnboxedValue&& callable, const TString& message);
-
-private:
+
+private:
const TCallableType *const CallableType;
const TUnboxedValue Callable;
const TString Message;
-
+
TUnboxedValue Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const final;
-};
-
-template<class TValidateErrorPolicy, class TValidateMode>
+};
+
+template<class TValidateErrorPolicy, class TValidateMode>
WrapCallableValue<TValidateErrorPolicy, TValidateMode>::WrapCallableValue(const TCallableType* callableType, TUnboxedValue&& callable, const TString& message)
: CallableType(callableType)
- , Callable(std::move(callable))
- , Message(message)
-{
-}
-
-template<class TValidateErrorPolicy, class TValidateMode>
+ , Callable(std::move(callable))
+ , Message(message)
+{
+}
+
+template<class TValidateErrorPolicy, class TValidateMode>
TUnboxedValue WrapCallableValue<TValidateErrorPolicy, TValidateMode>::Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const {
- const ui32 argsCount = CallableType->GetArgumentsCount();
- TSmallVec<TUnboxedValue> wrapArgs(argsCount);
- bool childWrapped = false;
- for (ui32 indexArg = 0; indexArg < argsCount; ++indexArg) {
- const auto argType = CallableType->GetArgumentType(indexArg);
+ const ui32 argsCount = CallableType->GetArgumentsCount();
+ TSmallVec<TUnboxedValue> wrapArgs(argsCount);
+ bool childWrapped = false;
+ for (ui32 indexArg = 0; indexArg < argsCount; ++indexArg) {
+ const auto argType = CallableType->GetArgumentType(indexArg);
wrapArgs[indexArg] = TValidate<TValidateErrorPolicy, TValidateMode>::Value(valueBuilder, argType, TUnboxedValuePod(args[indexArg]), TStringBuilder() << "CallableWrapper<" << CallableType->GetName() << ">.arg[" << indexArg << "]" << VERIFY_DELIMITER << Message, &childWrapped);
- }
+ }
return TValidate<TValidateErrorPolicy, TValidateMode>::Value(valueBuilder, CallableType->GetReturnType(), Callable.Run(valueBuilder, childWrapped ? wrapArgs.data() : args), TStringBuilder() << "CallableWrapper<" << CallableType->GetName() << ">.result" << VERIFY_DELIMITER << Message);
-}
-
-} // anonymous namespace
-
-template<class TValidateErrorPolicy>
-struct TValidateModeLazy {
+}
+
+} // anonymous namespace
+
+template<class TValidateErrorPolicy>
+struct TValidateModeLazy {
static NUdf::TUnboxedValue ProcessList(const IValueBuilder* valueBuilder, const TListType* listType, IBoxedValuePtr&& boxed, const TString& message, bool* wrapped) {
- if (wrapped) {
- *wrapped = true;
- }
+ if (wrapped) {
+ *wrapped = true;
+ }
return NUdf::TUnboxedValuePod(new TLazyVerifyListValue<TValidateErrorPolicy>(valueBuilder, listType, std::move(boxed), message));
- }
-
+ }
+
static NUdf::TUnboxedValue ProcessDict(const IValueBuilder* valueBuilder, const TDictType* dictType, IBoxedValuePtr&& boxed, const TString& message, bool* wrapped) {
- if (wrapped) {
- *wrapped = true;
- }
+ if (wrapped) {
+ *wrapped = true;
+ }
return NUdf::TUnboxedValuePod(new TLazyVerifyDictValue<TValidateErrorPolicy>(valueBuilder, dictType, std::move(boxed), message));
- }
-};
-
-template<class TValidateErrorPolicy>
-struct TValidateModeGreedy {
+ }
+};
+
+template<class TValidateErrorPolicy>
+struct TValidateModeGreedy {
static NUdf::TUnboxedValue ProcessList(const IValueBuilder* valueBuilder, const TListType* listType, IBoxedValuePtr&& boxed, const TString& message, bool* wrapped) {
if (!TBoxedValueAccessor::HasFastListLength(*boxed)) {
return NUdf::TUnboxedValuePod(new TLazyVerifyListValue<TValidateErrorPolicy>(valueBuilder, listType, std::move(boxed), message));
}
- const TType* itemType = listType->GetItemType();
+ const TType* itemType = listType->GetItemType();
std::vector<NUdf::TUnboxedValue> list;
if (TBoxedValueAccessor::HasFastListLength(*boxed))
list.reserve(TBoxedValueAccessor::GetListLength(*boxed));
- bool childWrapped = false;
- ui64 curIndex = 0;
+ bool childWrapped = false;
+ ui64 curIndex = 0;
const auto iter = TBoxedValueAccessor::GetListIterator(*boxed);
for (NUdf::TUnboxedValue current; iter.Next(current); ++curIndex) {
list.emplace_back(TValidate<TValidateErrorPolicy, TValidateModeGreedy>::Value(valueBuilder, itemType, std::move(current),
- TStringBuilder() << "LazyList[" << curIndex << "]" << VERIFY_DELIMITER << message, &childWrapped));
- }
+ TStringBuilder() << "LazyList[" << curIndex << "]" << VERIFY_DELIMITER << message, &childWrapped));
+ }
const auto elementsCount = TBoxedValueAccessor::GetListLength(*boxed);
- if (curIndex != elementsCount) {
- TValidateErrorPolicy::Generate(TStringBuilder() << "TValidateModeGreedy::ProcessList, wrong list length returned, expected: " << curIndex << ", but got: " << elementsCount << VERIFY_DELIMITER << message);
- }
- if (childWrapped) {
- if (wrapped) {
- *wrapped = true;
- }
+ if (curIndex != elementsCount) {
+ TValidateErrorPolicy::Generate(TStringBuilder() << "TValidateModeGreedy::ProcessList, wrong list length returned, expected: " << curIndex << ", but got: " << elementsCount << VERIFY_DELIMITER << message);
+ }
+ if (childWrapped) {
+ if (wrapped) {
+ *wrapped = true;
+ }
return valueBuilder->NewList(list.data(), list.size());
- }
+ }
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
-
+ }
+
static TUnboxedValue ProcessDict(const IValueBuilder* valueBuilder, const TDictType* dictType, IBoxedValuePtr&& boxed, const TString& message, bool* wrapped) {
- auto keyType = dictType->GetKeyType();
- auto payloadType = dictType->GetPayloadType();
- auto dictBuilder = valueBuilder->NewDict(dictType, TDictFlags::Sorted);
- bool childWrapped = false;
- ui64 curIndex = 0;
+ auto keyType = dictType->GetKeyType();
+ auto payloadType = dictType->GetPayloadType();
+ auto dictBuilder = valueBuilder->NewDict(dictType, TDictFlags::Sorted);
+ bool childWrapped = false;
+ ui64 curIndex = 0;
const auto iter = TBoxedValueAccessor::GetDictIterator(*boxed);
for (NUdf::TUnboxedValue key, payload; iter.NextPair(key, payload); ++curIndex) {
key = TValidate<TValidateErrorPolicy, TValidateModeLazy<TValidateErrorPolicy>>::Value(valueBuilder, keyType, std::move(key),
@@ -328,149 +328,149 @@ struct TValidateModeGreedy {
payload = TValidate<TValidateErrorPolicy, TValidateModeLazy<TValidateErrorPolicy>>::Value(valueBuilder, payloadType, std::move(payload),
TStringBuilder() << "GreedyDict[" << curIndex << "], validate payload" << VERIFY_DELIMITER << message);
dictBuilder->Add(std::move(key), std::move(payload));
- }
+ }
const auto elementsCount = TBoxedValueAccessor::GetDictLength(*boxed);
- if (curIndex != elementsCount) {
- TValidateErrorPolicy::Generate(TStringBuilder() << "TValidateModeGreedy::ProcessDict, wrong dict length returned, expected: " << curIndex << ", but got: " << elementsCount << VERIFY_DELIMITER << message);
- }
- if (childWrapped) {
- if (wrapped) {
- *wrapped = true;
- }
- return dictBuilder->Build();
- }
+ if (curIndex != elementsCount) {
+ TValidateErrorPolicy::Generate(TStringBuilder() << "TValidateModeGreedy::ProcessDict, wrong dict length returned, expected: " << curIndex << ", but got: " << elementsCount << VERIFY_DELIMITER << message);
+ }
+ if (childWrapped) {
+ if (wrapped) {
+ *wrapped = true;
+ }
+ return dictBuilder->Build();
+ }
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
-};
-
-template<class TValidateErrorPolicy, class TValidateMode>
+ }
+};
+
+template<class TValidateErrorPolicy, class TValidateMode>
NUdf::TUnboxedValue TValidate<TValidateErrorPolicy, TValidateMode>::Value(const IValueBuilder* valueBuilder, const TType* type, NUdf::TUnboxedValue&& value, const TString& message, bool* wrapped) {
if (!value && !(type->IsOptional() || type->IsNull())) {
TValidateErrorPolicy::Generate(TStringBuilder() << "Expected value '" << PrintNode(type, true) << "', but got Empty" << VERIFY_DELIMITER << message);
- }
-
- switch (type->GetKind()) {
- case TType::EKind::Void:
+ }
+
+ switch (type->GetKind()) {
+ case TType::EKind::Void:
case TType::EKind::Null:
case TType::EKind::EmptyList:
case TType::EKind::EmptyDict:
- break;
-
- case TType::EKind::Data: {
- auto dataType = static_cast<const TDataType*>(type);
- auto dataTypeId = dataType->GetSchemeType();
+ break;
+
+ case TType::EKind::Data: {
+ auto dataType = static_cast<const TDataType*>(type);
+ auto dataTypeId = dataType->GetSchemeType();
auto slot = NUdf::FindDataSlot(dataTypeId);
if (!slot) {
TValidateErrorPolicy::GenerateExc(TUdfValidateException() << "Unregistered TypeId: " << dataTypeId << VERIFY_DELIMITER << message);
- }
+ }
if (!IsValidValue(*slot, value)) {
TValidateErrorPolicy::Generate(TStringBuilder() << "Expected value '" << PrintNode(type, true) << "' does not conform" << VERIFY_DELIMITER << message);
- }
- break;
- }
-
- case TType::EKind::Optional: {
+ }
+ break;
+ }
+
+ case TType::EKind::Optional: {
if (!value) {
- break;
- }
- auto optionalType = static_cast<const TOptionalType*>(type);
- bool childWrapped = false;
+ break;
+ }
+ auto optionalType = static_cast<const TOptionalType*>(type);
+ bool childWrapped = false;
auto upValue = TValidate<TValidateErrorPolicy, TValidateMode>::Value(valueBuilder, optionalType->GetItemType(), value.GetOptionalValue(), TStringBuilder() << "Optional" << message, &childWrapped);
- if (childWrapped) {
- if (wrapped) {
- *wrapped = true;
- }
+ if (childWrapped) {
+ if (wrapped) {
+ *wrapped = true;
+ }
return upValue.Release().MakeOptional();
- }
- break;
- }
-
- case TType::EKind::List: {
- if (!value.IsBoxed()) {
+ }
+ break;
+ }
+
+ case TType::EKind::List: {
+ if (!value.IsBoxed()) {
TValidateErrorPolicy::Generate(TStringBuilder() << "expected value '" << PrintNode(type, true) << "' not conform" << VERIFY_DELIMITER << message);
- }
- auto listType = static_cast<const TListType*>(type);
+ }
+ auto listType = static_cast<const TListType*>(type);
return TValidateMode::ProcessList(valueBuilder, listType, std::move(value.Release().AsBoxed()), message, wrapped);
- }
-
- case TType::EKind::Struct: {
- if (!value.IsBoxed()) {
+ }
+
+ case TType::EKind::Struct: {
+ if (!value.IsBoxed()) {
TValidateErrorPolicy::Generate(TStringBuilder() << "expected value '" << PrintNode(type, true) << "' not conform" << VERIFY_DELIMITER << message);
- }
- auto structType = static_cast<const TStructType*>(type);
- bool childWrapped = false;
- TSmallVec<TUnboxedValue> stackItems(structType->GetMembersCount());
- for (ui32 index = 0; index < structType->GetMembersCount(); ++index) {
- TType* memberType = structType->GetMemberType(index);
+ }
+ auto structType = static_cast<const TStructType*>(type);
+ bool childWrapped = false;
+ TSmallVec<TUnboxedValue> stackItems(structType->GetMembersCount());
+ for (ui32 index = 0; index < structType->GetMembersCount(); ++index) {
+ TType* memberType = structType->GetMemberType(index);
stackItems[index] = TValidate<TValidateErrorPolicy, TValidateMode>::Value(valueBuilder, memberType, value.GetElement(index), TStringBuilder() << "Struct[" << structType->GetMemberName(index) << "]" << VERIFY_DELIMITER << message, &childWrapped);
- }
- if (childWrapped) {
+ }
+ if (childWrapped) {
TUnboxedValue* items = nullptr;
const auto wrappedStruct = valueBuilder->NewArray(structType->GetMembersCount(), items);
- for (ui32 index = 0; index < structType->GetMembersCount(); ++index) {
- items[index] = std::move(stackItems[index]);
- }
- if (wrapped) {
- *wrapped = true;
- }
- return wrappedStruct;
- }
- break;
- }
-
- case TType::EKind::Tuple: {
- if (!value.IsBoxed()) {
+ for (ui32 index = 0; index < structType->GetMembersCount(); ++index) {
+ items[index] = std::move(stackItems[index]);
+ }
+ if (wrapped) {
+ *wrapped = true;
+ }
+ return wrappedStruct;
+ }
+ break;
+ }
+
+ case TType::EKind::Tuple: {
+ if (!value.IsBoxed()) {
TValidateErrorPolicy::Generate(TStringBuilder() << "expected value '" << PrintNode(type, true) << "' not conform" << VERIFY_DELIMITER << message);
- }
- auto tupleType = static_cast<const TTupleType*>(type);
- bool childWrapped = false;
+ }
+ auto tupleType = static_cast<const TTupleType*>(type);
+ bool childWrapped = false;
TSmallVec<NUdf::TUnboxedValue> stackItems(tupleType->GetElementsCount());
- for (ui32 index = 0; index < tupleType->GetElementsCount(); ++index) {
- TType* elementType = tupleType->GetElementType(index);
+ for (ui32 index = 0; index < tupleType->GetElementsCount(); ++index) {
+ TType* elementType = tupleType->GetElementType(index);
stackItems[index] = TValidate<TValidateErrorPolicy, TValidateMode>::Value(valueBuilder, elementType, value.GetElement(index), TStringBuilder() << "Tuple[" << index << "]" << VERIFY_DELIMITER << message, &childWrapped);
- }
- if (childWrapped) {
+ }
+ if (childWrapped) {
TUnboxedValue* items = nullptr;
const auto wrappedTuple = valueBuilder->NewArray(tupleType->GetElementsCount(), items);
- for (ui32 index = 0; index < tupleType->GetElementsCount(); ++index) {
- items[index] = std::move(stackItems[index]);
- }
- if (wrapped) {
- *wrapped = true;
- }
- return wrappedTuple;
- }
- break;
- }
-
- case TType::EKind::Dict: {
- if (!value.IsBoxed()) {
+ for (ui32 index = 0; index < tupleType->GetElementsCount(); ++index) {
+ items[index] = std::move(stackItems[index]);
+ }
+ if (wrapped) {
+ *wrapped = true;
+ }
+ return wrappedTuple;
+ }
+ break;
+ }
+
+ case TType::EKind::Dict: {
+ if (!value.IsBoxed()) {
TValidateErrorPolicy::Generate(TStringBuilder() << "expected value '" << PrintNode(type, true) << "' not conform" << VERIFY_DELIMITER << message);
- }
- auto dictType = static_cast<const TDictType*>(type);
+ }
+ auto dictType = static_cast<const TDictType*>(type);
return TValidateMode::ProcessDict(valueBuilder, dictType, std::move(value.Release().AsBoxed()), message, wrapped);
- }
-
- case TType::EKind::Callable: {
- if (!value.IsBoxed()) {
+ }
+
+ case TType::EKind::Callable: {
+ if (!value.IsBoxed()) {
TValidateErrorPolicy::Generate(TStringBuilder() << "expected value '" << PrintNode(type, true) << "' not conform" << VERIFY_DELIMITER << message);
- }
- auto callableType = static_cast<const TCallableType*>(type);
- if (wrapped) {
- *wrapped = true;
- }
+ }
+ auto callableType = static_cast<const TCallableType*>(type);
+ if (wrapped) {
+ *wrapped = true;
+ }
TValidate<TValidateErrorPolicy>::WrapCallable(callableType, value, message);
return value;
- }
-
- case TType::EKind::Type:
- // metatype allways valid if we meet it
- break;
-
- case TType::EKind::Resource:
- // resource allways valid if we meet it
- break;
-
+ }
+
+ case TType::EKind::Type:
+ // metatype allways valid if we meet it
+ break;
+
+ case TType::EKind::Resource:
+ // resource allways valid if we meet it
+ break;
+
case TType::EKind::Stream:
case TType::EKind::Variant:
// TODO validate it
@@ -489,21 +489,21 @@ NUdf::TUnboxedValue TValidate<TValidateErrorPolicy, TValidateMode>::Value(const
break;
}
- default:
+ default:
Y_FAIL("Verify value meet unexpected type kind: %s", type->GetKindAsStr().data());
- }
+ }
return std::move(value);
-}
-
-template<class TValidateErrorPolicy, class TValidateMode>
+}
+
+template<class TValidateErrorPolicy, class TValidateMode>
void TValidate<TValidateErrorPolicy, TValidateMode>::WrapCallable(const TCallableType* callableType, NUdf::TUnboxedValue& callable, const TString& message) {
callable = NUdf::TUnboxedValuePod(new WrapCallableValue<TValidateErrorPolicy, TValidateMode>(callableType, std::move(callable), TStringBuilder() << "CallableWrapper<" << callableType->GetName() << ">" << VERIFY_DELIMITER << message));
-}
-
-template struct TValidate<TValidateErrorPolicyThrow, TValidateModeLazy<TValidateErrorPolicyThrow>>;
-template struct TValidate<TValidateErrorPolicyThrow, TValidateModeGreedy<TValidateErrorPolicyThrow>>;
-template struct TValidate<TValidateErrorPolicyFail, TValidateModeLazy<TValidateErrorPolicyFail>>;
-template struct TValidate<TValidateErrorPolicyFail, TValidateModeGreedy<TValidateErrorPolicyFail>>;
-
-} // namespace MiniKQL
-} // namespace NKikimr
+}
+
+template struct TValidate<TValidateErrorPolicyThrow, TValidateModeLazy<TValidateErrorPolicyThrow>>;
+template struct TValidate<TValidateErrorPolicyThrow, TValidateModeGreedy<TValidateErrorPolicyThrow>>;
+template struct TValidate<TValidateErrorPolicyFail, TValidateModeLazy<TValidateErrorPolicyFail>>;
+template struct TValidate<TValidateErrorPolicyFail, TValidateModeGreedy<TValidateErrorPolicyFail>>;
+
+} // namespace MiniKQL
+} // namespace NKikimr
diff --git a/ydb/library/yql/minikql/computation/mkql_validate.h b/ydb/library/yql/minikql/computation/mkql_validate.h
index 719314a9bb..136b700d5a 100644
--- a/ydb/library/yql/minikql/computation/mkql_validate.h
+++ b/ydb/library/yql/minikql/computation/mkql_validate.h
@@ -1,27 +1,27 @@
-#pragma once
-
+#pragma once
+
#include <ydb/library/yql/minikql/mkql_node.h>
-
-namespace NKikimr {
-namespace NMiniKQL {
-
-struct TValidateErrorPolicyNone;
-struct TValidateErrorPolicyThrow;
-struct TValidateErrorPolicyFail;
-
-template<class TErrorPolicy>
-struct TValidateModeLazy;
-
-template<class TErrorPolicy>
-struct TValidateModeGreedy;
-
-template<class TErrorPolicy, class TValidateMode = TValidateModeLazy<TErrorPolicy>>
-struct TValidate {
+
+namespace NKikimr {
+namespace NMiniKQL {
+
+struct TValidateErrorPolicyNone;
+struct TValidateErrorPolicyThrow;
+struct TValidateErrorPolicyFail;
+
+template<class TErrorPolicy>
+struct TValidateModeLazy;
+
+template<class TErrorPolicy>
+struct TValidateModeGreedy;
+
+template<class TErrorPolicy, class TValidateMode = TValidateModeLazy<TErrorPolicy>>
+struct TValidate {
static NUdf::TUnboxedValue Value(const NUdf::IValueBuilder* valueBuilder, const TType* type, NUdf::TUnboxedValue&& value, const TString& message, bool* wrapped = nullptr);
static void WrapCallable(const TCallableType* callableType, NUdf::TUnboxedValue& callable, const TString& message);
-};
-
-} // namespace MiniKQL
-} // namespace NKikimr
-
-#include "mkql_validate_impl.h"
+};
+
+} // namespace MiniKQL
+} // namespace NKikimr
+
+#include "mkql_validate_impl.h"
diff --git a/ydb/library/yql/minikql/computation/mkql_validate_impl.h b/ydb/library/yql/minikql/computation/mkql_validate_impl.h
index 45c26e2b89..c4e10ac4b1 100644
--- a/ydb/library/yql/minikql/computation/mkql_validate_impl.h
+++ b/ydb/library/yql/minikql/computation/mkql_validate_impl.h
@@ -1,52 +1,52 @@
-#pragma once
+#pragma once
#include <util/string/cast.h>
-
-namespace NKikimr {
-namespace NMiniKQL {
-
-struct TValidateErrorPolicyNone {
-};
-
-struct TUdfValidateException: public yexception {
-};
-
-struct TValidateErrorPolicyThrow {
+
+namespace NKikimr {
+namespace NMiniKQL {
+
+struct TValidateErrorPolicyNone {
+};
+
+struct TUdfValidateException: public yexception {
+};
+
+struct TValidateErrorPolicyThrow {
static void Generate(const TString& message) {
- GenerateExc(TUdfValidateException() << message);
- }
-
- template<class TException>
- static void GenerateExc(const TException& exc) {
- static_assert(std::is_base_of<yexception, TException>::value, "Must be derived from yexception");
+ GenerateExc(TUdfValidateException() << message);
+ }
+
+ template<class TException>
+ static void GenerateExc(const TException& exc) {
+ static_assert(std::is_base_of<yexception, TException>::value, "Must be derived from yexception");
ythrow TException() << exc.AsStrBuf();
- }
-};
-
-struct TValidateErrorPolicyFail {
+ }
+};
+
+struct TValidateErrorPolicyFail {
static void Generate(const TString& message) {
- Y_FAIL("value verify failed: %s", message.c_str());
- }
-
- template<class TException>
- static void GenerateExc(const TException& exc) {
- Generate(ToString(exc.AsStrBuf()));
- }
-};
-
-template<class TValidateMode>
-struct TValidate<TValidateErrorPolicyNone, TValidateMode> {
-
+ Y_FAIL("value verify failed: %s", message.c_str());
+ }
+
+ template<class TException>
+ static void GenerateExc(const TException& exc) {
+ Generate(ToString(exc.AsStrBuf()));
+ }
+};
+
+template<class TValidateMode>
+struct TValidate<TValidateErrorPolicyNone, TValidateMode> {
+
static NUdf::TUnboxedValue Value(const NUdf::IValueBuilder* valueBuilder, const TType* type, NUdf::TUnboxedValue&& value, const TString& message, bool* wrapped) {
- Y_UNUSED(valueBuilder);
- Y_UNUSED(type);
- Y_UNUSED(message);
- Y_UNUSED(wrapped);
+ Y_UNUSED(valueBuilder);
+ Y_UNUSED(type);
+ Y_UNUSED(message);
+ Y_UNUSED(wrapped);
return std::move(value);
-}
-
+}
+
static void WrapCallable(const TCallableType*, NUdf::TUnboxedValue&, const TString&) {}
-
-};
-
-} // namespace MiniKQL
-} // namespace NKikimr
+
+};
+
+} // namespace MiniKQL
+} // namespace NKikimr
diff --git a/ydb/library/yql/minikql/computation/mkql_validate_ut.cpp b/ydb/library/yql/minikql/computation/mkql_validate_ut.cpp
index 380bb24afe..ed2f12303a 100644
--- a/ydb/library/yql/minikql/computation/mkql_validate_ut.cpp
+++ b/ydb/library/yql/minikql/computation/mkql_validate_ut.cpp
@@ -1,30 +1,30 @@
#include <ydb/library/yql/minikql/mkql_program_builder.h>
#include <ydb/library/yql/minikql/mkql_node_printer.h>
-#include "mkql_computation_list_adapter.h"
-#include "mkql_computation_node_impl.h"
-#include "mkql_computation_node.h"
+#include "mkql_computation_list_adapter.h"
+#include "mkql_computation_node_impl.h"
+#include "mkql_computation_node.h"
#include "mkql_value_builder.h"
#include <ydb/library/yql/minikql/mkql_function_registry.h>
#include <ydb/library/yql/minikql/mkql_string_util.h>
#include <ydb/library/yql/minikql/invoke_builtins/mkql_builtins.h>
-#include "mkql_validate.h"
-
+#include "mkql_validate.h"
+
#include <ydb/library/yql/minikql/mkql_type_builder.h>
#include <ydb/library/yql/minikql/mkql_utils.h>
#include <ydb/library/yql/minikql/comp_nodes/mkql_factories.h>
-
+
#include <library/cpp/testing/unittest/registar.h>
-
-#include <util/generic/algorithm.h>
-
+
+#include <util/generic/algorithm.h>
+
#include <ydb/library/yql/public/udf/udf_helpers.h>
-
+
namespace NYql {
-
+
namespace {
using namespace NKikimr::NMiniKQL;
-static const ui32 RAW_INDEX_NO_HOLE = -1;
-static const ui32 RAW_BROKEN_INDEX_LIST_TO_DICT = 1;
+static const ui32 RAW_INDEX_NO_HOLE = -1;
+static const ui32 RAW_BROKEN_INDEX_LIST_TO_DICT = 1;
template<class T>
NUdf::TUnboxedValue ToUnboxedValue(const T& val) {
@@ -37,184 +37,184 @@ NUdf::TUnboxedValue ToUnboxedValue(const TString& val) {
NUdf::TUnboxedValue ToUnboxedValue(const NUdf::IBoxedValuePtr& val) {
return NUdf::TUnboxedValuePod(NUdf::IBoxedValuePtr(val));
-}
-
-} // namespace NMiniKQL
-
-/// support for build Struct type @{
-namespace NUdf {
-
- template<class TContainer>
+}
+
+} // namespace NMiniKQL
+
+/// support for build Struct type @{
+namespace NUdf {
+
+ template<class TContainer>
struct TListRefIterator: public TBoxedValue {
TListRefIterator(const TContainer& listRef, ui32 holePos)
- : ListRef(listRef)
- , Index(-1)
- , HolePos(holePos)
- {}
- private:
- const TContainer& ListRef;
- ui32 Index;
- ui32 HolePos;
-
+ : ListRef(listRef)
+ , Index(-1)
+ , HolePos(holePos)
+ {}
+ private:
+ const TContainer& ListRef;
+ ui32 Index;
+ ui32 HolePos;
+
bool Next(NUdf::TUnboxedValue& value) final {
if (++Index >= ListRef.size())
return false;
value = Index == HolePos ? NUdf::TUnboxedValue(NUdf::TUnboxedValuePod(42)) : ToUnboxedValue(ListRef[Index]);
return true;
}
- };
-
+ };
+
template<class TContainer, ui32 TIndexDictBrokenHole = RAW_INDEX_NO_HOLE, bool TNoDictIndex = false>
- struct TListRef: public NUdf::TBoxedValue {
+ struct TListRef: public NUdf::TBoxedValue {
TListRef(const TContainer& listRef, ui32 holePos = RAW_INDEX_NO_HOLE)
- : ListRef(listRef)
- , HolePos(holePos)
- {}
-
- private:
- const TContainer& ListRef;
+ : ListRef(listRef)
+ , HolePos(holePos)
+ {}
+
+ private:
+ const TContainer& ListRef;
const NUdf::IValueBuilder* ValueBuilder;
- ui32 HolePos;
-
- bool HasFastListLength() const override {
- return true;
- }
-
- ui64 GetListLength() const override {
- return ListRef.size();
- }
-
- ui64 GetEstimatedListLength() const override {
- return ListRef.size();
- }
-
+ ui32 HolePos;
+
+ bool HasFastListLength() const override {
+ return true;
+ }
+
+ ui64 GetListLength() const override {
+ return ListRef.size();
+ }
+
+ ui64 GetEstimatedListLength() const override {
+ return ListRef.size();
+ }
+
NUdf::TUnboxedValue GetListIterator() const override {
return NUdf::TUnboxedValuePod(new TListRefIterator<TContainer>(ListRef, HolePos));
}
-
+
NUdf::IBoxedValuePtr ToIndexDictImpl(const IValueBuilder& builder) const override {
return TNoDictIndex ? nullptr : builder.ToIndexDict(NUdf::TUnboxedValuePod(
new TListRef<TContainer, TIndexDictBrokenHole, true>(ListRef, TIndexDictBrokenHole))).AsBoxed();
- }
- };
-
- struct PersonStruct {
- static const size_t MEMBERS_COUNT = 3;
- static ui32 MetaIndexes[MEMBERS_COUNT];
- static ui32 MetaBackIndexes[MEMBERS_COUNT];
-
+ }
+ };
+
+ struct PersonStruct {
+ static const size_t MEMBERS_COUNT = 3;
+ static ui32 MetaIndexes[MEMBERS_COUNT];
+ static ui32 MetaBackIndexes[MEMBERS_COUNT];
+
TString FirstName;
TString LastName;
- ui32 Age;
-
+ ui32 Age;
+
NUdf::TUnboxedValue GetByIndex(ui32 index) const {
- switch (index) {
+ switch (index) {
case 0: return ToUnboxedValue(FirstName);
case 1: return ToUnboxedValue(LastName);
case 2: return NUdf::TUnboxedValuePod(Age);
- default: Y_FAIL("Unexpected");
- }
- }
- };
-
- ui32 PersonStruct::MetaIndexes[MEMBERS_COUNT];
- ui32 PersonStruct::MetaBackIndexes[MEMBERS_COUNT];
-
-
- struct PersonStructWithOptList {
- static const size_t MEMBERS_COUNT = 4;
- static ui32 MetaIndexes[MEMBERS_COUNT];
- static ui32 MetaBackIndexes[MEMBERS_COUNT];
-
+ default: Y_FAIL("Unexpected");
+ }
+ }
+ };
+
+ ui32 PersonStruct::MetaIndexes[MEMBERS_COUNT];
+ ui32 PersonStruct::MetaBackIndexes[MEMBERS_COUNT];
+
+
+ struct PersonStructWithOptList {
+ static const size_t MEMBERS_COUNT = 4;
+ static ui32 MetaIndexes[MEMBERS_COUNT];
+ static ui32 MetaBackIndexes[MEMBERS_COUNT];
+
TString FirstName;
TString LastName;
- ui32 Age;
+ ui32 Age;
typedef std::vector<ui32> TTagList;
- TTagList Tags;
-
+ TTagList Tags;
+
NUdf::TUnboxedValue GetByIndex(ui32 index) const {
- switch (index) {
+ switch (index) {
case 0: return ToUnboxedValue(FirstName);
case 1: return ToUnboxedValue(LastName);
case 2: return NUdf::TUnboxedValuePod(Age);
case 3: return Tags.empty() ?
NUdf::TUnboxedValuePod() :
NUdf::TUnboxedValuePod(new TListRef<TTagList>(Tags));
- default: Y_FAIL("Unexpected");
- }
- }
- };
-
- ui32 PersonStructWithOptList::MetaIndexes[MEMBERS_COUNT];
- ui32 PersonStructWithOptList::MetaBackIndexes[MEMBERS_COUNT];
-
- struct TCallableOneUi32Arg {
- };
-
-namespace NImpl {
-
- template<>
- struct TTypeBuilderHelper<NUdf::PersonStruct> {
- static TType* Build(const IFunctionTypeInfoBuilder& builder) {
- auto structBuilder = builder.Struct(3);
- structBuilder->AddField<char*>("FirstName", &PersonStruct::MetaIndexes[0])
- .AddField<char*>("LastName", &PersonStruct::MetaIndexes[1])
- .AddField<ui32>("Age", &PersonStruct::MetaIndexes[2]);
- auto structType = structBuilder->Build();
- for (const auto& index: PersonStruct::MetaIndexes) {
- Y_VERIFY(index < NUdf::PersonStruct::MEMBERS_COUNT);
- NUdf::PersonStruct::MetaBackIndexes[index] = &index - PersonStruct::MetaIndexes;
- Y_VERIFY(NUdf::PersonStruct::MetaBackIndexes[index] < NUdf::PersonStruct::MEMBERS_COUNT);
- }
- return structType;
- }
- };
-
- template<>
- struct TTypeBuilderHelper<NUdf::PersonStructWithOptList> {
- static TType* Build(const IFunctionTypeInfoBuilder& builder) {
- auto listTags = builder.List()->Item<ui32>().Build();
- auto optionalListTags = builder.Optional()->Item(listTags).Build();
- auto structBuilder = builder.Struct(3);
- structBuilder->AddField<char*>("FirstName", &PersonStructWithOptList::MetaIndexes[0])
- .AddField<char*>("LastName", &PersonStructWithOptList::MetaIndexes[1])
- .AddField<ui32>("Age", &PersonStructWithOptList::MetaIndexes[2])
- .AddField("Tags", optionalListTags, &PersonStructWithOptList::MetaIndexes[3]);
- auto structType = structBuilder->Build();
- for (const auto& index: PersonStructWithOptList::MetaIndexes) {
- Y_VERIFY(index < NUdf::PersonStructWithOptList::MEMBERS_COUNT);
- NUdf::PersonStructWithOptList::MetaBackIndexes[index] = &index - PersonStructWithOptList::MetaIndexes;
- Y_VERIFY(NUdf::PersonStructWithOptList::MetaBackIndexes[index] < NUdf::PersonStructWithOptList::MEMBERS_COUNT);
- }
- return structType;
- }
- };
-
- template<>
- struct TTypeBuilderHelper<NUdf::TCallableOneUi32Arg> {
- static TType* Build(const IFunctionTypeInfoBuilder& builder) {
- auto callableBuilder = builder.Callable(1);
- callableBuilder->Returns<ui32>();
- callableBuilder->Arg<ui32>();
- return callableBuilder->Build();
- }
- };
-} // namespace NImpl
-} // namespace NUdf
-/// @}
-
-
+ default: Y_FAIL("Unexpected");
+ }
+ }
+ };
+
+ ui32 PersonStructWithOptList::MetaIndexes[MEMBERS_COUNT];
+ ui32 PersonStructWithOptList::MetaBackIndexes[MEMBERS_COUNT];
+
+ struct TCallableOneUi32Arg {
+ };
+
+namespace NImpl {
+
+ template<>
+ struct TTypeBuilderHelper<NUdf::PersonStruct> {
+ static TType* Build(const IFunctionTypeInfoBuilder& builder) {
+ auto structBuilder = builder.Struct(3);
+ structBuilder->AddField<char*>("FirstName", &PersonStruct::MetaIndexes[0])
+ .AddField<char*>("LastName", &PersonStruct::MetaIndexes[1])
+ .AddField<ui32>("Age", &PersonStruct::MetaIndexes[2]);
+ auto structType = structBuilder->Build();
+ for (const auto& index: PersonStruct::MetaIndexes) {
+ Y_VERIFY(index < NUdf::PersonStruct::MEMBERS_COUNT);
+ NUdf::PersonStruct::MetaBackIndexes[index] = &index - PersonStruct::MetaIndexes;
+ Y_VERIFY(NUdf::PersonStruct::MetaBackIndexes[index] < NUdf::PersonStruct::MEMBERS_COUNT);
+ }
+ return structType;
+ }
+ };
+
+ template<>
+ struct TTypeBuilderHelper<NUdf::PersonStructWithOptList> {
+ static TType* Build(const IFunctionTypeInfoBuilder& builder) {
+ auto listTags = builder.List()->Item<ui32>().Build();
+ auto optionalListTags = builder.Optional()->Item(listTags).Build();
+ auto structBuilder = builder.Struct(3);
+ structBuilder->AddField<char*>("FirstName", &PersonStructWithOptList::MetaIndexes[0])
+ .AddField<char*>("LastName", &PersonStructWithOptList::MetaIndexes[1])
+ .AddField<ui32>("Age", &PersonStructWithOptList::MetaIndexes[2])
+ .AddField("Tags", optionalListTags, &PersonStructWithOptList::MetaIndexes[3]);
+ auto structType = structBuilder->Build();
+ for (const auto& index: PersonStructWithOptList::MetaIndexes) {
+ Y_VERIFY(index < NUdf::PersonStructWithOptList::MEMBERS_COUNT);
+ NUdf::PersonStructWithOptList::MetaBackIndexes[index] = &index - PersonStructWithOptList::MetaIndexes;
+ Y_VERIFY(NUdf::PersonStructWithOptList::MetaBackIndexes[index] < NUdf::PersonStructWithOptList::MEMBERS_COUNT);
+ }
+ return structType;
+ }
+ };
+
+ template<>
+ struct TTypeBuilderHelper<NUdf::TCallableOneUi32Arg> {
+ static TType* Build(const IFunctionTypeInfoBuilder& builder) {
+ auto callableBuilder = builder.Callable(1);
+ callableBuilder->Returns<ui32>();
+ callableBuilder->Arg<ui32>();
+ return callableBuilder->Build();
+ }
+ };
+} // namespace NImpl
+} // namespace NUdf
+/// @}
+
+
struct TBrokenSeqListIterator: public NUdf::TBoxedValue {
- TBrokenSeqListIterator(ui32 size, ui32 holePos)
- : Size(size)
- , HolePos(holePos)
- , Index(-1)
- {}
- private:
- ui32 Size;
- ui32 HolePos;
- ui32 Index;
-
+ TBrokenSeqListIterator(ui32 size, ui32 holePos)
+ : Size(size)
+ , HolePos(holePos)
+ , Index(-1)
+ {}
+ private:
+ ui32 Size;
+ ui32 HolePos;
+ ui32 Index;
+
bool Skip() final {
return ++Index < Size;
}
@@ -225,54 +225,54 @@ namespace NImpl {
value = Index == HolePos ? NUdf::TUnboxedValuePod() : NUdf::TUnboxedValuePod(Index);
return true;
}
- };
-
- struct TBrokenSeqListBoxedValue: public NUdf::TBoxedValue {
- TBrokenSeqListBoxedValue(ui32 size, ui32 holePos)
- : ListSize(size)
- , HolePos(holePos)
- {}
-
- private:
- ui32 ListSize;
- ui32 HolePos;
-
- bool HasFastListLength() const override {
- return true;
- }
-
- ui64 GetListLength() const override {
- return ListSize;
- }
-
- ui64 GetEstimatedListLength() const override {
- return ListSize;
- }
-
+ };
+
+ struct TBrokenSeqListBoxedValue: public NUdf::TBoxedValue {
+ TBrokenSeqListBoxedValue(ui32 size, ui32 holePos)
+ : ListSize(size)
+ , HolePos(holePos)
+ {}
+
+ private:
+ ui32 ListSize;
+ ui32 HolePos;
+
+ bool HasFastListLength() const override {
+ return true;
+ }
+
+ ui64 GetListLength() const override {
+ return ListSize;
+ }
+
+ ui64 GetEstimatedListLength() const override {
+ return ListSize;
+ }
+
NUdf::TUnboxedValue GetListIterator() const override {
return NUdf::TUnboxedValuePod(new TBrokenSeqListIterator(ListSize, HolePos));
}
- };
-
- template<class TStructType>
- struct TBrokenStructBoxedValue: public NUdf::TBoxedValue {
+ };
+
+ template<class TStructType>
+ struct TBrokenStructBoxedValue: public NUdf::TBoxedValue {
TBrokenStructBoxedValue(const TStructType& data, ui32 holePos = RAW_INDEX_NO_HOLE)
- : Struct(data)
- , HolePos(holePos)
- {}
-
- private:
- const TStructType& Struct;
- ui32 HolePos;
-
+ : Struct(data)
+ , HolePos(holePos)
+ {}
+
+ private:
+ const TStructType& Struct;
+ ui32 HolePos;
+
NUdf::TUnboxedValue GetElement(ui32 index) const override {
if (index == HolePos) {
return NUdf::TUnboxedValuePod();
}
return Struct.GetByIndex(TStructType::MetaBackIndexes[index]);
}
- };
-
+ };
+
namespace {
template<>
@@ -283,19 +283,19 @@ namespace {
template<>
NUdf::TUnboxedValue ToUnboxedValue<NUdf::PersonStructWithOptList>(const NUdf::PersonStructWithOptList& val) {
return NUdf::TUnboxedValuePod(new TBrokenStructBoxedValue<NUdf::PersonStructWithOptList>(val));
- }
-
- template<class TTupleType>
- struct TBrokenTupleBoxedValue: public NUdf::TBoxedValue {
+ }
+
+ template<class TTupleType>
+ struct TBrokenTupleBoxedValue: public NUdf::TBoxedValue {
TBrokenTupleBoxedValue(const TTupleType& tuple, ui32 holePos)
- : Tuple(tuple)
- , HolePos(holePos)
- {}
-
- private:
- const TTupleType& Tuple;
- ui32 HolePos;
-
+ : Tuple(tuple)
+ , HolePos(holePos)
+ {}
+
+ private:
+ const TTupleType& Tuple;
+ ui32 HolePos;
+
NUdf::TUnboxedValue GetElement(ui32 index) const override {
if (index == HolePos) {
return NUdf::TUnboxedValuePod();
@@ -307,24 +307,24 @@ namespace {
case 3: return ToUnboxedValue(std::get<3>(Tuple));
default: Y_FAIL("Unexpected");
}
- }
- };
-
- typedef std::pair<ui32, ui32> PosPair;
-
- template<class TKey, class TValue>
+ }
+ };
+
+ typedef std::pair<ui32, ui32> PosPair;
+
+ template<class TKey, class TValue>
struct TBrokenDictIterator: public NUdf::TBoxedValue {
TBrokenDictIterator(const std::vector<std::pair<TKey, TValue>>& dictData, PosPair holePos)
- : DictData(dictData)
- , HolePos(holePos)
- , Index(-1)
- {}
-
- private:
+ : DictData(dictData)
+ , HolePos(holePos)
+ , Index(-1)
+ {}
+
+ private:
const std::vector<std::pair<TKey, TValue>>& DictData;
- PosPair HolePos;
- ui32 Index;
-
+ PosPair HolePos;
+ ui32 Index;
+
bool Skip() final {
return ++Index < DictData.size();
}
@@ -342,31 +342,31 @@ namespace {
payload = Index == HolePos.second ? NUdf::TUnboxedValue() : ToUnboxedValue(DictData[Index].second);
return true;
}
- };
-
- template<class TKey, class TValue>
- struct TBrokenDictBoxedValue: public NUdf::TBoxedValue {
+ };
+
+ template<class TKey, class TValue>
+ struct TBrokenDictBoxedValue: public NUdf::TBoxedValue {
TBrokenDictBoxedValue(const std::vector<std::pair<TKey, TValue>>& dictData,
PosPair holePos, NUdf::TUnboxedValue&& hole = NUdf::TUnboxedValuePod())
- : DictData(dictData)
- , HolePos(holePos)
+ : DictData(dictData)
+ , HolePos(holePos)
, Hole(std::move(hole))
- {}
-
- private:
+ {}
+
+ private:
const std::vector<std::pair<TKey, TValue>> DictData;
- PosPair HolePos;
- NUdf::TUnboxedValue Hole;
+ PosPair HolePos;
+ NUdf::TUnboxedValue Hole;
NUdf::TUnboxedValue GetKeysIterator() const override {
return NUdf::TUnboxedValuePod(new TBrokenDictIterator<TKey, TValue>(DictData, HolePos));
}
-
+
NUdf::TUnboxedValue GetDictIterator() const override {
return NUdf::TUnboxedValuePod(new TBrokenDictIterator<TKey, TValue>(DictData, HolePos));
}
- };
-
+ };
+
struct TThrowerValue: public NUdf::TBoxedValue {
static long Count;
TThrowerValue(NUdf::IBoxedValuePtr&& owner = NUdf::IBoxedValuePtr())
@@ -375,7 +375,7 @@ namespace {
~TThrowerValue() { --Count; }
private:
const NUdf::IBoxedValuePtr Owner;
-
+
bool Skip() override {
ythrow yexception() << "Throw";
}
@@ -393,183 +393,183 @@ namespace {
long TThrowerValue::Count = 0L;
- SIMPLE_UDF(TVoid, void()) {
+ SIMPLE_UDF(TVoid, void()) {
Y_UNUSED(valueBuilder);
Y_UNUSED(args);
return NUdf::TUnboxedValuePod::Void();
- }
-
- SIMPLE_UDF_RUN(TNonEmpty, ui32(), NUdf::TOptional<void>) {
+ }
+
+ SIMPLE_UDF_RUN(TNonEmpty, ui32(), NUdf::TOptional<void>) {
Y_UNUSED(valueBuilder);
Y_UNUSED(args);
return NUdf::TUnboxedValuePod(42);
- }
-
- SIMPLE_UDF(TOptionalNonEmpty, NUdf::TOptional<ui32>()) {
+ }
+
+ SIMPLE_UDF(TOptionalNonEmpty, NUdf::TOptional<ui32>()) {
Y_UNUSED(valueBuilder);
Y_UNUSED(args);
return NUdf::TUnboxedValuePod(42);
- }
-
- SIMPLE_UDF_RUN(TOptionalEmpty, NUdf::TOptional<ui32>(), NUdf::TOptional<void>) {
+ }
+
+ SIMPLE_UDF_RUN(TOptionalEmpty, NUdf::TOptional<ui32>(), NUdf::TOptional<void>) {
Y_UNUSED(valueBuilder);
Y_UNUSED(args);
return NUdf::TUnboxedValuePod();
- }
-
- SIMPLE_UDF(TSub2Mul2BrokenOnLess2, ui32(ui32)) {
- Y_UNUSED(valueBuilder);
- const ui32 arg = args[0].Get<ui32>();
- if (arg >= 2) {
+ }
+
+ SIMPLE_UDF(TSub2Mul2BrokenOnLess2, ui32(ui32)) {
+ Y_UNUSED(valueBuilder);
+ const ui32 arg = args[0].Get<ui32>();
+ if (arg >= 2) {
return NUdf::TUnboxedValuePod((arg - 2) * 2);
- }
+ }
return NUdf::TUnboxedValuePod();
- }
-
- SIMPLE_UDF_RUN(TBackSub2Mul2, ui32(NUdf::TCallableOneUi32Arg, ui32), NUdf::TOptional<void>) {
- const auto func = args[0];
- const auto& arg = args[1];
+ }
+
+ SIMPLE_UDF_RUN(TBackSub2Mul2, ui32(NUdf::TCallableOneUi32Arg, ui32), NUdf::TOptional<void>) {
+ const auto func = args[0];
+ const auto& arg = args[1];
auto usedArg = NUdf::TUnboxedValuePod();
- if (arg.Get<ui32>() < 100) {
- usedArg = arg;
- }
- auto funcResult = func.Run(valueBuilder, &usedArg);
- const auto& backResult = funcResult.Get<ui32>() / 2 + 2;
+ if (arg.Get<ui32>() < 100) {
+ usedArg = arg;
+ }
+ auto funcResult = func.Run(valueBuilder, &usedArg);
+ const auto& backResult = funcResult.Get<ui32>() / 2 + 2;
return NUdf::TUnboxedValuePod(backResult);
- }
-
+ }
+
SIMPLE_UDF(TSeqList, NUdf::TListType<ui32>(ui32)) {
- const ui32 size = args[0].Get<ui32>();
+ const ui32 size = args[0].Get<ui32>();
std::vector<NUdf::TUnboxedValue> res;
- res.resize(size);
- for (ui32 i = 0; i < size; ++i) {
+ res.resize(size);
+ for (ui32 i = 0; i < size; ++i) {
res[i] = NUdf::TUnboxedValuePod(i);
- }
- return valueBuilder->NewList(res.data(), res.size());
- }
-
+ }
+ return valueBuilder->NewList(res.data(), res.size());
+ }
+
SIMPLE_UDF_RUN(TSeqListWithHole, NUdf::TListType<ui32>(ui32, ui32), NUdf::TOptional<void>) {
Y_UNUSED(valueBuilder);
- const ui32 size = args[0].Get<ui32>();
- const ui32 hole = args[1].Get<ui32>();
+ const ui32 size = args[0].Get<ui32>();
+ const ui32 hole = args[1].Get<ui32>();
NUdf::IBoxedValuePtr boxed(new TBrokenSeqListBoxedValue(size, hole));
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
-
+ }
+
static const auto TUPLE = std::make_tuple(ui8(33), TString("world"), ui64(0xFEEDB00B2A115E), TString("funny bunny"));
-
- typedef NUdf::TTuple<ui8, char*, ui64, char*> NUdfTuple;
-
- SIMPLE_UDF(TTuple, NUdfTuple(ui32)) {
+
+ typedef NUdf::TTuple<ui8, char*, ui64, char*> NUdfTuple;
+
+ SIMPLE_UDF(TTuple, NUdfTuple(ui32)) {
Y_UNUSED(valueBuilder);
- const ui32 holePos = args[0].Get<ui32>();
+ const ui32 holePos = args[0].Get<ui32>();
NUdf::IBoxedValuePtr boxed(new TBrokenTupleBoxedValue<decltype(TUPLE)>(TUPLE, holePos));
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
-
+ }
+
static const std::vector<std::pair<ui32, ui64>> DICT_DIGIT2DIGIT = {
- {1, 100500},
- {42, 0xDEADBEAF},
- {911, 1234567890},
- {777, 777777777777},
- };
-
- typedef NUdf::TDict<ui32, ui64> NUdfDictDigDig;
-
- SIMPLE_UDF_RUN(TDictDigDig, NUdfDictDigDig(ui32, ui32), NUdf::TOptional<void>) {
+ {1, 100500},
+ {42, 0xDEADBEAF},
+ {911, 1234567890},
+ {777, 777777777777},
+ };
+
+ typedef NUdf::TDict<ui32, ui64> NUdfDictDigDig;
+
+ SIMPLE_UDF_RUN(TDictDigDig, NUdfDictDigDig(ui32, ui32), NUdf::TOptional<void>) {
Y_UNUSED(valueBuilder);
- const ui32 holeKey = args[0].Get<ui32>();
- const ui32 holeValue = args[1].Get<ui32>();
+ const ui32 holeKey = args[0].Get<ui32>();
+ const ui32 holeValue = args[1].Get<ui32>();
NUdf::IBoxedValuePtr boxed(new TBrokenDictBoxedValue<ui32, ui64>(
DICT_DIGIT2DIGIT, std::make_pair(holeKey, holeValue)));
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
-
- SIMPLE_UDF(TDictDigDigHoleAsOpt, NUdfDictDigDig(ui32, ui32)) {
+ }
+
+ SIMPLE_UDF(TDictDigDigHoleAsOpt, NUdfDictDigDig(ui32, ui32)) {
Y_UNUSED(valueBuilder);
- const ui32 holeKey = args[0].Get<ui32>();
- const ui32 holeValue = args[1].Get<ui32>();
+ const ui32 holeKey = args[0].Get<ui32>();
+ const ui32 holeValue = args[1].Get<ui32>();
NUdf::IBoxedValuePtr boxed(new TBrokenDictBoxedValue<ui32, ui64>(DICT_DIGIT2DIGIT,
std::make_pair(holeKey, holeValue),
NUdf::TUnboxedValuePod()));
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
-
- static const NUdf::PersonStruct STRUCT_PERSON_JONNIE = {"Johnnie Walker", "Blue Label", 25};
- static const NUdf::PersonStruct STRUCT_PERSON_HITHCOCK = {"Alfred", "Hithcock", 81};
- static const NUdf::PersonStruct STRUCT_PERSON_LOVECRAFT = {"Howard", "Lovecraft", 25};
- static const NUdf::PersonStruct STRUCT_PERSON_KING = {"Stephen", "King", 25};
- static const NUdf::PersonStructWithOptList STRUCT_PERSON_HITHCOCK_LIST = {"Alfred", "Hithcock", 81, {}};
- static const NUdf::PersonStructWithOptList STRUCT_PERSON_LOVECRAFT_LIST = {"Howard", "Lovecraft", 25, {3, 2, 99}};
- static const NUdf::PersonStructWithOptList STRUCT_PERSON_KING_LIST = {"Stephen", "King", 25, {}};
-
- SIMPLE_UDF_RUN(TPersonStruct, NUdf::PersonStruct(ui32), NUdf::TOptional<void>) {
+ }
+
+ static const NUdf::PersonStruct STRUCT_PERSON_JONNIE = {"Johnnie Walker", "Blue Label", 25};
+ static const NUdf::PersonStruct STRUCT_PERSON_HITHCOCK = {"Alfred", "Hithcock", 81};
+ static const NUdf::PersonStruct STRUCT_PERSON_LOVECRAFT = {"Howard", "Lovecraft", 25};
+ static const NUdf::PersonStruct STRUCT_PERSON_KING = {"Stephen", "King", 25};
+ static const NUdf::PersonStructWithOptList STRUCT_PERSON_HITHCOCK_LIST = {"Alfred", "Hithcock", 81, {}};
+ static const NUdf::PersonStructWithOptList STRUCT_PERSON_LOVECRAFT_LIST = {"Howard", "Lovecraft", 25, {3, 2, 99}};
+ static const NUdf::PersonStructWithOptList STRUCT_PERSON_KING_LIST = {"Stephen", "King", 25, {}};
+
+ SIMPLE_UDF_RUN(TPersonStruct, NUdf::PersonStruct(ui32), NUdf::TOptional<void>) {
Y_UNUSED(valueBuilder);
- const ui32 holePos = args[0].Get<ui32>();
+ const ui32 holePos = args[0].Get<ui32>();
NUdf::IBoxedValuePtr boxed(new TBrokenStructBoxedValue<NUdf::PersonStruct>(STRUCT_PERSON_JONNIE, holePos));
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
-
- typedef NUdf::TTuple<NUdf::PersonStructWithOptList,NUdf::PersonStruct,NUdf::PersonStructWithOptList,NUdf::PersonStruct> NUdfPersonTuple;
+ }
+
+ typedef NUdf::TTuple<NUdf::PersonStructWithOptList,NUdf::PersonStruct,NUdf::PersonStructWithOptList,NUdf::PersonStruct> NUdfPersonTuple;
static const auto TUPLE_OF_PERSON = std::make_tuple(
STRUCT_PERSON_HITHCOCK_LIST,
STRUCT_PERSON_JONNIE,
STRUCT_PERSON_LOVECRAFT_LIST,
STRUCT_PERSON_KING);
-
+
static const auto TUPLE_OF_PERSON_NO_LIST = std::make_tuple(STRUCT_PERSON_HITHCOCK_LIST,
STRUCT_PERSON_JONNIE,
STRUCT_PERSON_KING_LIST,
STRUCT_PERSON_KING);
- SIMPLE_UDF(TTupleOfPersonStruct, NUdfPersonTuple(ui32)) {
+ SIMPLE_UDF(TTupleOfPersonStruct, NUdfPersonTuple(ui32)) {
Y_UNUSED(valueBuilder);
- const ui32 holePos = args[0].Get<ui32>();
+ const ui32 holePos = args[0].Get<ui32>();
NUdf::IBoxedValuePtr boxed(new TBrokenTupleBoxedValue<decltype(TUPLE_OF_PERSON)>(TUPLE_OF_PERSON, holePos));
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
-
- SIMPLE_UDF(TTupleOfPersonStructNoList, NUdfPersonTuple(ui32)) {
+ }
+
+ SIMPLE_UDF(TTupleOfPersonStructNoList, NUdfPersonTuple(ui32)) {
Y_UNUSED(valueBuilder);
- const ui32 holePos = args[0].Get<ui32>();
+ const ui32 holePos = args[0].Get<ui32>();
NUdf::IBoxedValuePtr boxed(new TBrokenTupleBoxedValue<decltype(TUPLE_OF_PERSON_NO_LIST)>(TUPLE_OF_PERSON_NO_LIST, holePos));
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
-
+ }
+
static const std::vector<NUdf::PersonStructWithOptList> LIST_OF_STRUCT_PERSON = {
- STRUCT_PERSON_HITHCOCK_LIST,
- STRUCT_PERSON_LOVECRAFT_LIST,
- STRUCT_PERSON_KING_LIST
- };
-
- typedef NUdf::TDict<ui64,NUdf::PersonStructWithOptList> TIndexDictFromPersonList;
- SIMPLE_UDF(TListOfPersonStructToIndexDict, TIndexDictFromPersonList(ui32)) {
+ STRUCT_PERSON_HITHCOCK_LIST,
+ STRUCT_PERSON_LOVECRAFT_LIST,
+ STRUCT_PERSON_KING_LIST
+ };
+
+ typedef NUdf::TDict<ui64,NUdf::PersonStructWithOptList> TIndexDictFromPersonList;
+ SIMPLE_UDF(TListOfPersonStructToIndexDict, TIndexDictFromPersonList(ui32)) {
Y_UNUSED(valueBuilder);
- Y_UNUSED(args);
+ Y_UNUSED(args);
NUdf::IBoxedValuePtr boxed(new NUdf::TListRef<decltype(LIST_OF_STRUCT_PERSON)>(LIST_OF_STRUCT_PERSON));
return valueBuilder->ToIndexDict(NUdf::TUnboxedValuePod(std::move(boxed)));
- }
-
+ }
+
SIMPLE_UDF(TListOfPersonStruct, NUdf::TListType<NUdf::PersonStructWithOptList>(ui32)) {
Y_UNUSED(valueBuilder);
- Y_UNUSED(args);
+ Y_UNUSED(args);
NUdf::IBoxedValuePtr boxed(new NUdf::TListRef<decltype(LIST_OF_STRUCT_PERSON)>(LIST_OF_STRUCT_PERSON));
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
-
+ }
+
SIMPLE_UDF(TListOfPersonStructWithBrokenIndexToDict, NUdf::TListType<NUdf::PersonStructWithOptList>()) {
Y_UNUSED(valueBuilder);
- Y_UNUSED(args);
+ Y_UNUSED(args);
NUdf::IBoxedValuePtr boxed(new NUdf::TListRef<decltype(LIST_OF_STRUCT_PERSON), RAW_BROKEN_INDEX_LIST_TO_DICT>(
LIST_OF_STRUCT_PERSON));
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
+ }
- static const NUdf::PersonStruct* DICT_DIGIT2PERSON_BROKEN_CONTENT_BY_INDEX[] = {
- &STRUCT_PERSON_HITHCOCK, &STRUCT_PERSON_JONNIE, &STRUCT_PERSON_LOVECRAFT
- };
+ static const NUdf::PersonStruct* DICT_DIGIT2PERSON_BROKEN_CONTENT_BY_INDEX[] = {
+ &STRUCT_PERSON_HITHCOCK, &STRUCT_PERSON_JONNIE, &STRUCT_PERSON_LOVECRAFT
+ };
const ui32 DICT_DIGIT2PERSON_BROKEN_PERSON_INDEX = 1;
- const ui32 DICT_DIGIT2PERSON_BROKEN_STRUCT_INDEX = 2;
+ const ui32 DICT_DIGIT2PERSON_BROKEN_STRUCT_INDEX = 2;
const std::vector<std::pair<ui32, NUdf::IBoxedValuePtr>> MAKE_DICT_DIGIT2PERSON_BROKEN() {
std::vector<std::pair<ui32, NUdf::IBoxedValuePtr>> DICT_DIGIT2PERSON_BROKEN = {
@@ -581,8 +581,8 @@ namespace {
return DICT_DIGIT2PERSON_BROKEN;
}
- typedef NUdf::TDict<ui32,NUdf::PersonStruct> NUdfDictDigPerson;
-
+ typedef NUdf::TDict<ui32,NUdf::PersonStruct> NUdfDictDigPerson;
+
std::vector<std::pair<ui32, NUdf::IBoxedValuePtr>> MAKE_DICT_DIGIT2PERSON() {
const std::vector<std::pair<ui32, NUdf::IBoxedValuePtr>> DICT_DIGIT2PERSON = {
{ 333, new TBrokenStructBoxedValue<NUdf::PersonStruct>(STRUCT_PERSON_HITHCOCK, RAW_INDEX_NO_HOLE) },
@@ -593,60 +593,60 @@ namespace {
return DICT_DIGIT2PERSON;
}
- SIMPLE_UDF(TDictOfPerson, NUdfDictDigPerson()) {
+ SIMPLE_UDF(TDictOfPerson, NUdfDictDigPerson()) {
Y_UNUSED(args);
Y_UNUSED(valueBuilder);
NUdf::IBoxedValuePtr boxed(new TBrokenDictBoxedValue<ui32, NUdf::IBoxedValuePtr>(
MAKE_DICT_DIGIT2PERSON(), std::make_pair(RAW_INDEX_NO_HOLE, RAW_INDEX_NO_HOLE)));
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
-
- SIMPLE_UDF_RUN(TDictOfPersonBroken, NUdfDictDigPerson(), NUdf::TOptional<void>) {
+ }
+
+ SIMPLE_UDF_RUN(TDictOfPersonBroken, NUdfDictDigPerson(), NUdf::TOptional<void>) {
Y_UNUSED(args);
Y_UNUSED(valueBuilder);
NUdf::IBoxedValuePtr boxed(new TBrokenDictBoxedValue<ui32, NUdf::IBoxedValuePtr>(
MAKE_DICT_DIGIT2PERSON_BROKEN(), std::make_pair(RAW_INDEX_NO_HOLE, RAW_INDEX_NO_HOLE)));
return NUdf::TUnboxedValuePod(std::move(boxed));
- }
-
- SIMPLE_MODULE(TUtUDF,
+ }
+
+ SIMPLE_MODULE(TUtUDF,
TException,
- TVoid,
- TNonEmpty,
- TOptionalNonEmpty,
- TOptionalEmpty,
- TSub2Mul2BrokenOnLess2,
- TBackSub2Mul2,
- TSeqList,
- TSeqListWithHole,
- TTuple,
- TDictDigDig,
- TDictDigDigHoleAsOpt,
- TPersonStruct,
- TTupleOfPersonStruct,
- TTupleOfPersonStructNoList,
- TListOfPersonStructToIndexDict,
- TListOfPersonStruct,
- TListOfPersonStructWithBrokenIndexToDict,
- TDictOfPerson,
- TDictOfPersonBroken
- )
-} // unnamed namespace
-
+ TVoid,
+ TNonEmpty,
+ TOptionalNonEmpty,
+ TOptionalEmpty,
+ TSub2Mul2BrokenOnLess2,
+ TBackSub2Mul2,
+ TSeqList,
+ TSeqListWithHole,
+ TTuple,
+ TDictDigDig,
+ TDictDigDigHoleAsOpt,
+ TPersonStruct,
+ TTupleOfPersonStruct,
+ TTupleOfPersonStructNoList,
+ TListOfPersonStructToIndexDict,
+ TListOfPersonStruct,
+ TListOfPersonStructWithBrokenIndexToDict,
+ TDictOfPerson,
+ TDictOfPersonBroken
+ )
+} // unnamed namespace
+
TIntrusivePtr<IFunctionRegistry> CreateFunctionRegistryWithUDFs() {
auto freg = CreateFunctionRegistry(CreateBuiltinRegistry())->Clone();
- freg->AddModule("", "UtUDF", new TUtUDF());
- return freg;
-}
-
+ freg->AddModule("", "UtUDF", new TUtUDF());
+ return freg;
+}
+
Y_UNIT_TEST_SUITE(TMiniKQLValidateTest) {
typedef std::function<std::vector<TRuntimeNode>(TProgramBuilder&)> BuildArgsFunc;
typedef std::function<void(const NUdf::TUnboxedValuePod&, const NUdf::IValueBuilder*)> ValidateValueFunc;
typedef std::function<void(const NUdf::TUnboxedValuePod&, const NUdf::IValueBuilder*, const TType* type)> FullValidateValueFunc;
-
-
- void ProcessSimpleUdfFunc(const char* udfFuncName, BuildArgsFunc argsFunc = BuildArgsFunc(), ValidateValueFunc validateFunc = ValidateValueFunc(),
- FullValidateValueFunc fullValidateFunc = FullValidateValueFunc(),
+
+
+ void ProcessSimpleUdfFunc(const char* udfFuncName, BuildArgsFunc argsFunc = BuildArgsFunc(), ValidateValueFunc validateFunc = ValidateValueFunc(),
+ FullValidateValueFunc fullValidateFunc = FullValidateValueFunc(),
NUdf::EValidateMode validateMode = NUdf::EValidateMode::Lazy) {
TScopedAlloc alloc;
TTypeEnvironment env(alloc);
@@ -655,41 +655,41 @@ Y_UNIT_TEST_SUITE(TMiniKQLValidateTest) {
auto randomProvider = CreateDeterministicRandomProvider(1);
auto timeProvider = CreateDeterministicTimeProvider(10000000);
TProgramBuilder pgmBuilder(env, *functionRegistry);
-
- auto funcName = pgmBuilder.Udf(udfFuncName);
+
+ auto funcName = pgmBuilder.Udf(udfFuncName);
std::vector<TRuntimeNode> execArgs;
- if (argsFunc) {
- execArgs = argsFunc(pgmBuilder);
- }
- auto pgmReturn = pgmBuilder.Apply(funcName, execArgs);
-
- TExploringNodeVisitor explorer;
- explorer.Walk(pgmReturn.GetNode(), env);
- TComputationPatternOpts opts(alloc.Ref(), env, GetBuiltinFactory(),
- functionRegistry.Get(), validateMode,
+ if (argsFunc) {
+ execArgs = argsFunc(pgmBuilder);
+ }
+ auto pgmReturn = pgmBuilder.Apply(funcName, execArgs);
+
+ TExploringNodeVisitor explorer;
+ explorer.Walk(pgmReturn.GetNode(), env);
+ TComputationPatternOpts opts(alloc.Ref(), env, GetBuiltinFactory(),
+ functionRegistry.Get(), validateMode,
NUdf::EValidatePolicy::Exception, "OFF", EGraphPerProcess::Multi);
- auto pattern = MakeComputationPattern(explorer, pgmReturn, {}, opts);
- auto graph = pattern->Clone(opts.ToComputationOptions(*randomProvider, *timeProvider));
+ auto pattern = MakeComputationPattern(explorer, pgmReturn, {}, opts);
+ auto graph = pattern->Clone(opts.ToComputationOptions(*randomProvider, *timeProvider));
const auto builder = static_cast<TDefaultValueBuilder*>(graph->GetTerminator());
builder->RethrowAtTerminate();
const TBindTerminator bind(graph->GetTerminator());
- auto value = graph->GetValue();
-
- if (validateFunc) {
+ auto value = graph->GetValue();
+
+ if (validateFunc) {
validateFunc(value, builder);
- }
- if (fullValidateFunc) {
- ui32 flags = 0;
- TFunctionTypeInfo funcInfo;
- TType* userType = nullptr;
- TStringBuf typeConfig;
+ }
+ if (fullValidateFunc) {
+ ui32 flags = 0;
+ TFunctionTypeInfo funcInfo;
+ TType* userType = nullptr;
+ TStringBuf typeConfig;
TStatus status = functionRegistry->FindFunctionTypeInfo(env, typeInfoHelper, nullptr, udfFuncName, userType, typeConfig, flags, {}, nullptr, &funcInfo);
- MKQL_ENSURE(status.IsOk(), status.GetError());
- auto type = funcInfo.FunctionType->GetReturnType();
+ MKQL_ENSURE(status.IsOk(), status.GetError());
+ auto type = funcInfo.FunctionType->GetReturnType();
fullValidateFunc(value, builder, type);
- }
- }
-
+ }
+ }
+
Y_UNIT_TEST(TestUdfException) {
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
valueBuilder->NewStringNotFilled(0xBAD).AsStringValue().Ref(); // Leak string.
@@ -700,132 +700,132 @@ Y_UNIT_TEST_SUITE(TMiniKQLValidateTest) {
}
Y_UNIT_TEST(TestUdfResultCheckVoid) {
- ProcessSimpleUdfFunc("UtUDF.Void");
- }
-
+ ProcessSimpleUdfFunc("UtUDF.Void");
+ }
+
Y_UNIT_TEST(TestUdfResultCheckExceptionOnEmpty) {
TScopedAlloc alloc;
TTypeEnvironment env(alloc);
- bool wrapped = false;
+ bool wrapped = false;
UNIT_ASSERT_EXCEPTION(TValidate<TValidateErrorPolicyThrow>::Value(nullptr, env.GetTypeOfType(),
NUdf::TUnboxedValuePod(), "ut for verify empty value exception", &wrapped), TUdfValidateException);
- UNIT_ASSERT(!wrapped);
- }
-
+ UNIT_ASSERT(!wrapped);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckNonEmpty) {
- ProcessSimpleUdfFunc("UtUDF.NonEmpty");
- }
-
+ ProcessSimpleUdfFunc("UtUDF.NonEmpty");
+ }
+
Y_UNIT_TEST(TestUdfResultCheckOptionalNonEmpty) {
- ProcessSimpleUdfFunc("UtUDF.OptionalNonEmpty");
- }
-
+ ProcessSimpleUdfFunc("UtUDF.OptionalNonEmpty");
+ }
+
Y_UNIT_TEST(TestUdfResultCheckOptionalEmpty) {
- ProcessSimpleUdfFunc("UtUDF.OptionalEmpty");
- }
-
+ ProcessSimpleUdfFunc("UtUDF.OptionalEmpty");
+ }
+
std::vector<TRuntimeNode> MakeCallableInArgs(ui32 testVal, TProgramBuilder& pgmBuilder) {
- const auto& functionRegistry = pgmBuilder.GetFunctionRegistry();
-
- const auto udfFuncName = "UtUDF.Sub2Mul2BrokenOnLess2";
- ui32 flags = 0;
- TFunctionTypeInfo funcInfo;
- TType* userType = nullptr;
- TStringBuf typeConfig;
+ const auto& functionRegistry = pgmBuilder.GetFunctionRegistry();
+
+ const auto udfFuncName = "UtUDF.Sub2Mul2BrokenOnLess2";
+ ui32 flags = 0;
+ TFunctionTypeInfo funcInfo;
+ TType* userType = nullptr;
+ TStringBuf typeConfig;
NUdf::ITypeInfoHelper::TPtr typeInfoHelper(new TTypeInfoHelper);
TStatus status = functionRegistry.FindFunctionTypeInfo(pgmBuilder.GetTypeEnvironment(), typeInfoHelper, nullptr,
udfFuncName, userType, typeConfig, flags, {}, nullptr, &funcInfo);
- MKQL_ENSURE(status.IsOk(), status.GetError());
- auto callable = pgmBuilder.Udf(udfFuncName);
+ MKQL_ENSURE(status.IsOk(), status.GetError());
+ auto callable = pgmBuilder.Udf(udfFuncName);
return std::vector<TRuntimeNode>{callable, pgmBuilder.NewDataLiteral(testVal)};
- };
+ };
Y_UNIT_TEST(TestVerifyArgsCallableCorrect) {
- ui32 testVal = 44;
- BuildArgsFunc argsFunc = [testVal](TProgramBuilder& pgmBuilder) {
- return MakeCallableInArgs(testVal, pgmBuilder);
- };
+ ui32 testVal = 44;
+ BuildArgsFunc argsFunc = [testVal](TProgramBuilder& pgmBuilder) {
+ return MakeCallableInArgs(testVal, pgmBuilder);
+ };
ValidateValueFunc validateFunc = [testVal](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
Y_UNUSED(valueBuilder);
- UNIT_ASSERT_VALUES_EQUAL(testVal, value.Get<ui32>());
- };
- ProcessSimpleUdfFunc("UtUDF.BackSub2Mul2", argsFunc, validateFunc);
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(testVal, value.Get<ui32>());
+ };
+ ProcessSimpleUdfFunc("UtUDF.BackSub2Mul2", argsFunc, validateFunc);
+ }
+
Y_UNIT_TEST(TestVerifyArgsCallableBrokenOnArgument) {
- ui32 testVal = 101;
- BuildArgsFunc argsFunc = [testVal](TProgramBuilder& pgmBuilder) {
- return MakeCallableInArgs(testVal, pgmBuilder);
- };
- UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.BackSub2Mul2", argsFunc), TUdfValidateException);
- }
-
+ ui32 testVal = 101;
+ BuildArgsFunc argsFunc = [testVal](TProgramBuilder& pgmBuilder) {
+ return MakeCallableInArgs(testVal, pgmBuilder);
+ };
+ UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.BackSub2Mul2", argsFunc), TUdfValidateException);
+ }
+
Y_UNIT_TEST(TestVerifyArgsCallableBrokenOnReturn) {
- ui32 testVal = 1;
- BuildArgsFunc argsFunc = [testVal](TProgramBuilder& pgmBuilder) {
- return MakeCallableInArgs(testVal, pgmBuilder);
- };
- UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.BackSub2Mul2", argsFunc), TUdfValidateException);
- }
-
+ ui32 testVal = 1;
+ BuildArgsFunc argsFunc = [testVal](TProgramBuilder& pgmBuilder) {
+ return MakeCallableInArgs(testVal, pgmBuilder);
+ };
+ UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.BackSub2Mul2", argsFunc), TUdfValidateException);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckEmptySeqList) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral<ui32>(0)};
- };
+ };
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
Y_UNUSED(valueBuilder);
- auto listIter = value.GetListIterator();
+ auto listIter = value.GetListIterator();
UNIT_ASSERT(!listIter.Skip());
- };
- ProcessSimpleUdfFunc("UtUDF.SeqList", argsFunc, validateFunc);
- }
-
+ };
+ ProcessSimpleUdfFunc("UtUDF.SeqList", argsFunc, validateFunc);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckSeqList) {
static constexpr ui32 listSize = 31;
BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(listSize)};
- };
+ };
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
Y_UNUSED(valueBuilder);
- ui32 index = 0;
+ ui32 index = 0;
auto listIter = value.GetListIterator();
for (NUdf::TUnboxedValue item; listIter.Next(item); ++index) {
UNIT_ASSERT_VALUES_EQUAL(item.Get<ui32>(), index);
- }
- UNIT_ASSERT_VALUES_EQUAL(index, listSize);
- };
- ProcessSimpleUdfFunc("UtUDF.SeqList", argsFunc, validateFunc);
- }
-
+ }
+ UNIT_ASSERT_VALUES_EQUAL(index, listSize);
+ };
+ ProcessSimpleUdfFunc("UtUDF.SeqList", argsFunc, validateFunc);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckSeqListWithHoleFirst) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
const ui32 listSize = 31;
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(listSize),
pgmBuilder.NewDataLiteral<ui32>(0)};
- };
+ };
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
Y_UNUSED(valueBuilder);
- auto listIter = value.GetListIterator();
+ auto listIter = value.GetListIterator();
NUdf::TUnboxedValue item;
UNIT_ASSERT_EXCEPTION(listIter.Next(item), TUdfValidateException);
for (ui32 index = 1; listIter.Next(item); ++index) {
UNIT_ASSERT_VALUES_EQUAL(item.Get<ui32>(), index);
- }
- };
- ProcessSimpleUdfFunc("UtUDF.SeqListWithHole", argsFunc, validateFunc);
+ }
+ };
+ ProcessSimpleUdfFunc("UtUDF.SeqListWithHole", argsFunc, validateFunc);
UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.SeqListWithHole", argsFunc, validateFunc, {}, NUdf::EValidateMode::Greedy), TUdfValidateException);
- }
-
+ }
+
Y_UNIT_TEST(TestUdfResultCheckSeqListWithHoleMiddle) {
static constexpr ui32 listSize = 31;
BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(listSize),
pgmBuilder.NewDataLiteral(listSize / 2)};
- };
+ };
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
Y_UNUSED(valueBuilder);
- UNIT_ASSERT_VALUES_EQUAL(value.GetListLength(), listSize);
- ui32 index = 0;
+ UNIT_ASSERT_VALUES_EQUAL(value.GetListLength(), listSize);
+ ui32 index = 0;
const auto listIter = value.GetListIterator();
for (NUdf::TUnboxedValue item; index < listSize / 2 && listIter.Next(item); ++index) {
UNIT_ASSERT_VALUES_EQUAL(item.Get<ui32>(), index);
@@ -836,208 +836,208 @@ Y_UNIT_TEST_SUITE(TMiniKQLValidateTest) {
for (NUdf::TUnboxedValue item; listIter.Next(item); ++index) {
UNIT_ASSERT_VALUES_EQUAL(item.Get<ui32>(), index);
}
- };
- ProcessSimpleUdfFunc("UtUDF.SeqListWithHole", argsFunc, validateFunc);
+ };
+ ProcessSimpleUdfFunc("UtUDF.SeqListWithHole", argsFunc, validateFunc);
UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.SeqListWithHole", argsFunc, validateFunc, {}, NUdf::EValidateMode::Greedy), TUdfValidateException);
- }
-
+ }
+
Y_UNIT_TEST(TestUdfResultCheckSeqListWithHoleLast) {
static constexpr ui32 listSize = 31;
BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(listSize),
pgmBuilder.NewDataLiteral(listSize - 1)};
- };
+ };
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
Y_UNUSED(valueBuilder);
- UNIT_ASSERT_VALUES_EQUAL(value.GetListLength(), listSize);
- ui32 index = 0;
- auto listIter = value.GetListIterator();
+ UNIT_ASSERT_VALUES_EQUAL(value.GetListLength(), listSize);
+ ui32 index = 0;
+ auto listIter = value.GetListIterator();
for (NUdf::TUnboxedValue item; index < listSize - 1 && listIter.Next(item); ++index) {
UNIT_ASSERT_VALUES_EQUAL(item.Get<ui32>(), index);
}
UNIT_ASSERT_VALUES_EQUAL(index, listSize - 1);
NUdf::TUnboxedValue bad;
UNIT_ASSERT_EXCEPTION(listIter.Next(bad), TUdfValidateException);
- };
- ProcessSimpleUdfFunc("UtUDF.SeqListWithHole", argsFunc, validateFunc);
+ };
+ ProcessSimpleUdfFunc("UtUDF.SeqListWithHole", argsFunc, validateFunc);
UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.SeqListWithHole", argsFunc, validateFunc, {}, NUdf::EValidateMode::Greedy), TUdfValidateException);
- }
-
+ }
+
Y_UNIT_TEST(TestUdfResultCheckTuple) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(RAW_INDEX_NO_HOLE)};
- };
- ProcessSimpleUdfFunc("UtUDF.Tuple", argsFunc);
- }
-
+ };
+ ProcessSimpleUdfFunc("UtUDF.Tuple", argsFunc);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckTupleWithHoleFirst) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral<ui32>(0)};
- };
- UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.Tuple", argsFunc), TUdfValidateException);
- }
-
+ };
+ UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.Tuple", argsFunc), TUdfValidateException);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckTupleWithHoleMiddle) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral<ui32>(std::tuple_size<decltype(TUPLE)>::value / 2)};
- };
- UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.Tuple", argsFunc), TUdfValidateException);
- }
-
+ };
+ UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.Tuple", argsFunc), TUdfValidateException);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckTupleWithHoleLast) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral<ui32>(std::tuple_size<decltype(TUPLE)>::value - 1)};
- };
- UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.Tuple", argsFunc), TUdfValidateException);
- }
-
+ };
+ UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.Tuple", argsFunc), TUdfValidateException);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckDictDigitDigitFull) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(RAW_INDEX_NO_HOLE),
pgmBuilder.NewDataLiteral(RAW_INDEX_NO_HOLE)};
- };
+ };
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
Y_UNUSED(valueBuilder);
- auto dictIter = value.GetDictIterator();
- ui32 index = 0;
+ auto dictIter = value.GetDictIterator();
+ ui32 index = 0;
for (NUdf::TUnboxedValue key, payload; dictIter.NextPair(key, payload); ++index) {
UNIT_ASSERT_VALUES_EQUAL(key.Get<ui32>(), DICT_DIGIT2DIGIT[index].first);
UNIT_ASSERT_VALUES_EQUAL(payload.Get<ui64>(), DICT_DIGIT2DIGIT[index].second);
- }
- UNIT_ASSERT_VALUES_EQUAL(index, DICT_DIGIT2DIGIT.size());
- };
- ProcessSimpleUdfFunc("UtUDF.DictDigDig", argsFunc, validateFunc);
- }
-
+ }
+ UNIT_ASSERT_VALUES_EQUAL(index, DICT_DIGIT2DIGIT.size());
+ };
+ ProcessSimpleUdfFunc("UtUDF.DictDigDig", argsFunc, validateFunc);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckDictDigitDigitKeyHole) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral<ui32>(0),
pgmBuilder.NewDataLiteral(RAW_INDEX_NO_HOLE)};
- };
+ };
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
Y_UNUSED(valueBuilder);
- auto dictIter = value.GetDictIterator();
+ auto dictIter = value.GetDictIterator();
NUdf::TUnboxedValue key, payload;
UNIT_ASSERT_EXCEPTION(dictIter.NextPair(key, payload), TUdfValidateException);
for (ui32 index = 1; dictIter.NextPair(key, payload); ++index) {
UNIT_ASSERT_VALUES_EQUAL(key.Get<ui32>(), DICT_DIGIT2DIGIT[index].first);
UNIT_ASSERT_VALUES_EQUAL(payload.Get<ui64>(), DICT_DIGIT2DIGIT[index].second);
- }
- };
- ProcessSimpleUdfFunc("UtUDF.DictDigDig", argsFunc, validateFunc);
- }
-
+ }
+ };
+ ProcessSimpleUdfFunc("UtUDF.DictDigDig", argsFunc, validateFunc);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckDictDigitDigitValueHole) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(RAW_INDEX_NO_HOLE),
pgmBuilder.NewDataLiteral<ui32>(DICT_DIGIT2DIGIT.size() - 1)};
- };
+ };
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
Y_UNUSED(valueBuilder);
- auto dictIter = value.GetDictIterator();
+ auto dictIter = value.GetDictIterator();
NUdf::TUnboxedValue key, payload;
for (ui32 index = 0; index < DICT_DIGIT2DIGIT.size() - 1 && dictIter.NextPair(key, payload); ++index) {
UNIT_ASSERT_VALUES_EQUAL(key.Get<ui32>(), DICT_DIGIT2DIGIT[index].first);
UNIT_ASSERT_VALUES_EQUAL(payload.Get<ui64>(), DICT_DIGIT2DIGIT[index].second);
}
UNIT_ASSERT_EXCEPTION(dictIter.NextPair(key, payload), TUdfValidateException);
- };
- ProcessSimpleUdfFunc("UtUDF.DictDigDig", argsFunc, validateFunc);
- }
+ };
+ ProcessSimpleUdfFunc("UtUDF.DictDigDig", argsFunc, validateFunc);
+ }
Y_UNIT_TEST(TestUdfResultCheckDictDigitDigitHoleAsOptKeyHole) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(RAW_INDEX_NO_HOLE),
pgmBuilder.NewDataLiteral<ui32>(0)};
- };
+ };
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
Y_UNUSED(valueBuilder);
- auto dictIter = value.GetDictIterator();
+ auto dictIter = value.GetDictIterator();
NUdf::TUnboxedValue key, payload;
UNIT_ASSERT_EXCEPTION(dictIter.NextPair(key, payload), TUdfValidateException);
for (ui32 index = 1; dictIter.NextPair(key, payload); ++index) {
UNIT_ASSERT_VALUES_EQUAL(key.Get<ui32>(), DICT_DIGIT2DIGIT[index].first);
UNIT_ASSERT_VALUES_EQUAL(payload.Get<ui64>(), DICT_DIGIT2DIGIT[index].second);
- }
- };
- ProcessSimpleUdfFunc("UtUDF.DictDigDig", argsFunc, validateFunc);
- }
-
+ }
+ };
+ ProcessSimpleUdfFunc("UtUDF.DictDigDig", argsFunc, validateFunc);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckDictDigitDigitHoleAsOptValueHole) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral<ui32>(DICT_DIGIT2DIGIT.size() - 1),
pgmBuilder.NewDataLiteral(RAW_INDEX_NO_HOLE)};
- };
+ };
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
Y_UNUSED(valueBuilder);
- auto dictIter = value.GetDictIterator();
+ auto dictIter = value.GetDictIterator();
NUdf::TUnboxedValue key, payload;
for (ui32 index = 0; index < DICT_DIGIT2DIGIT.size() - 1 && dictIter.NextPair(key, payload); ++index) {
UNIT_ASSERT_VALUES_EQUAL(key.Get<ui32>(), DICT_DIGIT2DIGIT[index].first);
UNIT_ASSERT_VALUES_EQUAL(payload.Get<ui64>(), DICT_DIGIT2DIGIT[index].second);
}
UNIT_ASSERT_EXCEPTION(dictIter.NextPair(key, payload), TUdfValidateException);
- };
- ProcessSimpleUdfFunc("UtUDF.DictDigDig", argsFunc, validateFunc);
- }
-
+ };
+ ProcessSimpleUdfFunc("UtUDF.DictDigDig", argsFunc, validateFunc);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckPersonStruct) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(RAW_INDEX_NO_HOLE)};
- };
- ProcessSimpleUdfFunc("UtUDF.PersonStruct", argsFunc);
- }
-
+ };
+ ProcessSimpleUdfFunc("UtUDF.PersonStruct", argsFunc);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckPersonStructWithHoleFirst) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral<ui32>(0)};
- };
- UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.PersonStruct", argsFunc), TUdfValidateException);
- }
-
+ };
+ UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.PersonStruct", argsFunc), TUdfValidateException);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckPersonStructWithHoleMiddle) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral<ui32>(1)};
- };
- UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.PersonStruct", argsFunc), TUdfValidateException);
- }
-
+ };
+ UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.PersonStruct", argsFunc), TUdfValidateException);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckPersonStructWithHoleLast) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral<ui32>(2)};
- };
- UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.PersonStruct", argsFunc), TUdfValidateException);
- }
+ };
+ UNIT_ASSERT_EXCEPTION(ProcessSimpleUdfFunc("UtUDF.PersonStruct", argsFunc), TUdfValidateException);
+ }
Y_UNIT_TEST(TestUdfResultCheckTupleOfPersonStruct) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(RAW_INDEX_NO_HOLE)};
- };
+ };
FullValidateValueFunc fullValidateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder,
const TType* type) {
- bool wrapped = false;
+ bool wrapped = false;
TValidate<TValidateErrorPolicyThrow, TValidateModeGreedy<TValidateErrorPolicyThrow>>::Value(valueBuilder, type, NUdf::TUnboxedValuePod(value), "full verify func", &wrapped);
- UNIT_ASSERT(!wrapped);
+ UNIT_ASSERT(!wrapped);
TValidate<TValidateErrorPolicyThrow, TValidateModeLazy<TValidateErrorPolicyThrow>>::Value(valueBuilder, type, NUdf::TUnboxedValuePod(value), "full verify func", &wrapped);
- UNIT_ASSERT(wrapped);
- };
+ UNIT_ASSERT(wrapped);
+ };
ProcessSimpleUdfFunc("UtUDF.TupleOfPersonStruct", argsFunc, {}, fullValidateFunc);
ProcessSimpleUdfFunc("UtUDF.TupleOfPersonStruct", argsFunc, {}, fullValidateFunc, NUdf::EValidateMode::Greedy);
- }
+ }
Y_UNIT_TEST(TestUdfResultCheckTupleOfPersonStructNoList) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(RAW_INDEX_NO_HOLE)};
- };
+ };
FullValidateValueFunc fullValidateFunc = [](const NUdf::TUnboxedValuePod& value,
const NUdf::IValueBuilder* valueBuilder, const TType* type) {
- bool wrapped = false;
+ bool wrapped = false;
TValidate<TValidateErrorPolicyThrow>::Value(valueBuilder, type, NUdf::TUnboxedValuePod(value), "full verify func", &wrapped);
- UNIT_ASSERT(!wrapped);
- };
- ProcessSimpleUdfFunc("UtUDF.TupleOfPersonStructNoList", argsFunc, {}, fullValidateFunc);
+ UNIT_ASSERT(!wrapped);
+ };
+ ProcessSimpleUdfFunc("UtUDF.TupleOfPersonStructNoList", argsFunc, {}, fullValidateFunc);
ProcessSimpleUdfFunc("UtUDF.TupleOfPersonStructNoList", argsFunc, {}, fullValidateFunc, NUdf::EValidateMode::Greedy);
- }
-
+ }
+
void ValidateDictOfPersonStructFunc(const NUdf::TUnboxedValuePod& value, ui32 lookupIndex = 2, ui32 broken_index = RAW_INDEX_NO_HOLE) {
const auto person = value.Lookup(NUdf::TUnboxedValuePod(ui64(lookupIndex)));
UNIT_ASSERT(person);
@@ -1047,7 +1047,7 @@ Y_UNIT_TEST_SUITE(TMiniKQLValidateTest) {
UNIT_ASSERT_VALUES_EQUAL(TString(lastName.AsStringRef()), LIST_OF_STRUCT_PERSON[lookupIndex].LastName);
UNIT_ASSERT_VALUES_EQUAL(person.GetElement(NUdf::PersonStructWithOptList::MetaIndexes[2]).Get<ui32>(), LIST_OF_STRUCT_PERSON[lookupIndex].Age);
UNIT_ASSERT(!person.GetElement(NUdf::PersonStructWithOptList::MetaIndexes[3]));
- auto dictIter = value.GetDictIterator();
+ auto dictIter = value.GetDictIterator();
NUdf::TUnboxedValue key, payload;
for (ui32 index = 0; index < broken_index && dictIter.NextPair(key, payload); ++index) {
UNIT_ASSERT_VALUES_EQUAL(key.Get<ui64>(), index);
@@ -1073,49 +1073,49 @@ Y_UNIT_TEST_SUITE(TMiniKQLValidateTest) {
}
if (broken_index < RAW_INDEX_NO_HOLE)
UNIT_ASSERT_EXCEPTION(dictIter.NextPair(key, payload), TUdfValidateException);
- }
-
+ }
+
Y_UNIT_TEST(TestUdfResultCheckListOfPersonStructToIndexDict) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(RAW_INDEX_NO_HOLE)};
- };
+ };
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder) {
Y_UNUSED(valueBuilder);
- ValidateDictOfPersonStructFunc(value);
- };
- ProcessSimpleUdfFunc("UtUDF.ListOfPersonStructToIndexDict", argsFunc, validateFunc);
- }
-
+ ValidateDictOfPersonStructFunc(value);
+ };
+ ProcessSimpleUdfFunc("UtUDF.ListOfPersonStructToIndexDict", argsFunc, validateFunc);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckListOfPersonStruct) {
- BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
+ BuildArgsFunc argsFunc = [](TProgramBuilder& pgmBuilder) {
return std::vector<TRuntimeNode>{pgmBuilder.NewDataLiteral(RAW_INDEX_NO_HOLE)};
- };
+ };
FullValidateValueFunc fullValidateFunc = [](const NUdf::TUnboxedValuePod& value,
const NUdf::IValueBuilder* valueBuilder, const TType* type) {
- Y_UNUSED(type);
+ Y_UNUSED(type);
auto indexDict = valueBuilder->ToIndexDict(value);
- ValidateDictOfPersonStructFunc(indexDict);
- };
- ProcessSimpleUdfFunc("UtUDF.ListOfPersonStruct", argsFunc, {}, fullValidateFunc);
- }
-
+ ValidateDictOfPersonStructFunc(indexDict);
+ };
+ ProcessSimpleUdfFunc("UtUDF.ListOfPersonStruct", argsFunc, {}, fullValidateFunc);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckListOfPersonStructWithBrokenIndexToDict) {
FullValidateValueFunc fullValidateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder* valueBuilder,
const TType* type) {
- Y_UNUSED(type);
+ Y_UNUSED(type);
auto indexDict = valueBuilder->ToIndexDict(value);
- static_assert(RAW_BROKEN_INDEX_LIST_TO_DICT == 1, "a list is too small");
- ValidateDictOfPersonStructFunc(indexDict, RAW_BROKEN_INDEX_LIST_TO_DICT - 1, RAW_BROKEN_INDEX_LIST_TO_DICT);
- /// verify lookup fail on broken index
- UNIT_ASSERT_EXCEPTION(ValidateDictOfPersonStructFunc(indexDict, RAW_BROKEN_INDEX_LIST_TO_DICT, RAW_BROKEN_INDEX_LIST_TO_DICT), TUdfValidateException);
- ValidateDictOfPersonStructFunc(indexDict, RAW_BROKEN_INDEX_LIST_TO_DICT + 1, RAW_BROKEN_INDEX_LIST_TO_DICT);
- };
- ProcessSimpleUdfFunc("UtUDF.ListOfPersonStructWithBrokenIndexToDict", {}, {}, fullValidateFunc);
- }
-
+ static_assert(RAW_BROKEN_INDEX_LIST_TO_DICT == 1, "a list is too small");
+ ValidateDictOfPersonStructFunc(indexDict, RAW_BROKEN_INDEX_LIST_TO_DICT - 1, RAW_BROKEN_INDEX_LIST_TO_DICT);
+ /// verify lookup fail on broken index
+ UNIT_ASSERT_EXCEPTION(ValidateDictOfPersonStructFunc(indexDict, RAW_BROKEN_INDEX_LIST_TO_DICT, RAW_BROKEN_INDEX_LIST_TO_DICT), TUdfValidateException);
+ ValidateDictOfPersonStructFunc(indexDict, RAW_BROKEN_INDEX_LIST_TO_DICT + 1, RAW_BROKEN_INDEX_LIST_TO_DICT);
+ };
+ ProcessSimpleUdfFunc("UtUDF.ListOfPersonStructWithBrokenIndexToDict", {}, {}, fullValidateFunc);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckDictOfPerson) {
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder*) {
- auto dictIter = value.GetDictIterator();
+ auto dictIter = value.GetDictIterator();
NUdf::TUnboxedValue key, payload;
for (ui32 index = 0; dictIter.NextPair(key, payload); ++index) {
UNIT_ASSERT_VALUES_EQUAL(key.Get<ui32>(), MAKE_DICT_DIGIT2PERSON()[index].first);
@@ -1125,14 +1125,14 @@ Y_UNIT_TEST_SUITE(TMiniKQLValidateTest) {
auto lastName = person.GetElement(NUdf::PersonStruct::MetaIndexes[1]);
UNIT_ASSERT_VALUES_EQUAL(TString(lastName.AsStringRef()), DICT_DIGIT2PERSON_BROKEN_CONTENT_BY_INDEX[index]->LastName);
UNIT_ASSERT_VALUES_EQUAL(person.GetElement(NUdf::PersonStruct::MetaIndexes[2]).Get<ui32>(), DICT_DIGIT2PERSON_BROKEN_CONTENT_BY_INDEX[index]->Age);
- }
- };
- ProcessSimpleUdfFunc("UtUDF.DictOfPerson", {}, validateFunc);
- }
-
+ }
+ };
+ ProcessSimpleUdfFunc("UtUDF.DictOfPerson", {}, validateFunc);
+ }
+
Y_UNIT_TEST(TestUdfResultCheckDictOfPersonBroken) {
ValidateValueFunc validateFunc = [](const NUdf::TUnboxedValuePod& value, const NUdf::IValueBuilder*) {
- auto dictIter = value.GetDictIterator();
+ auto dictIter = value.GetDictIterator();
NUdf::TUnboxedValue key, payload;
for (ui32 index = 0; index < DICT_DIGIT2PERSON_BROKEN_PERSON_INDEX && dictIter.NextPair(key, payload); ++index) {
UNIT_ASSERT_VALUES_EQUAL(key.Get<ui32>(), MAKE_DICT_DIGIT2PERSON_BROKEN()[index].first);
@@ -1144,10 +1144,10 @@ Y_UNIT_TEST_SUITE(TMiniKQLValidateTest) {
UNIT_ASSERT_VALUES_EQUAL(person.GetElement(NUdf::PersonStruct::MetaIndexes[2]).Get<ui32>(), DICT_DIGIT2PERSON_BROKEN_CONTENT_BY_INDEX[index]->Age);
}
UNIT_ASSERT_EXCEPTION(dictIter.NextPair(key, payload), TUdfValidateException);
- };
- ProcessSimpleUdfFunc("UtUDF.DictOfPersonBroken", {}, validateFunc);
+ };
+ ProcessSimpleUdfFunc("UtUDF.DictOfPersonBroken", {}, validateFunc);
}
-}
-
+}
+
}
diff --git a/ydb/library/yql/minikql/computation/mkql_value_builder.cpp b/ydb/library/yql/minikql/computation/mkql_value_builder.cpp
index 6a81815ad4..ad47661715 100644
--- a/ydb/library/yql/minikql/computation/mkql_value_builder.cpp
+++ b/ydb/library/yql/minikql/computation/mkql_value_builder.cpp
@@ -1,5 +1,5 @@
#include "mkql_value_builder.h"
-#include "mkql_validate.h"
+#include "mkql_validate.h"
#include <ydb/library/yql/minikql/mkql_node_cast.h>
#include <ydb/library/yql/minikql/mkql_string_util.h>
@@ -42,7 +42,7 @@ void TDefaultValueBuilder::Terminate(const char* message) const {
Rethrow_ = true;
ythrow yexception() << fullMessage;
- }
+ }
Cerr << fullMessage;
abort();
diff --git a/ydb/library/yql/minikql/computation/ya.make b/ydb/library/yql/minikql/computation/ya.make
index 594ede095b..ae419b3b23 100644
--- a/ydb/library/yql/minikql/computation/ya.make
+++ b/ydb/library/yql/minikql/computation/ya.make
@@ -23,8 +23,8 @@ SRCS(
mkql_computation_node_pack.h
mkql_custom_list.cpp
mkql_custom_list.h
- mkql_validate.cpp
- mkql_validate.h
+ mkql_validate.cpp
+ mkql_validate.h
mkql_value_builder.cpp
mkql_value_builder.h
presort.h
diff --git a/ydb/library/yql/minikql/mkql_alloc.h b/ydb/library/yql/minikql/mkql_alloc.h
index 3dfaf72855..5e864cdc4c 100644
--- a/ydb/library/yql/minikql/mkql_alloc.h
+++ b/ydb/library/yql/minikql/mkql_alloc.h
@@ -127,72 +127,72 @@ private:
TAllocState* PrevState_ = nullptr;
};
-class TInjectedAlloc {
-public:
+class TInjectedAlloc {
+public:
explicit TInjectedAlloc(const TAlignedPagePoolCounters& counters = TAlignedPagePoolCounters(), bool supportsSizedAllocators = false)
- : OldTlsAllocState(TlsAllocState)
- {
- TlsAllocState = nullptr;
+ : OldTlsAllocState(TlsAllocState)
+ {
+ TlsAllocState = nullptr;
InjectedAlloc = std::make_shared<TScopedAlloc>(counters, supportsSizedAllocators);
- AcquireOriginal();
- }
-
- ~TInjectedAlloc() {
- AcquireOriginal();
- }
-
- TScopedAlloc& ScopedRef() {
- return *InjectedAlloc;
- }
-
- TAllocState& InjectedState() {
- return InjectedAlloc->Ref();
- }
-
+ AcquireOriginal();
+ }
+
+ ~TInjectedAlloc() {
+ AcquireOriginal();
+ }
+
+ TScopedAlloc& ScopedRef() {
+ return *InjectedAlloc;
+ }
+
+ TAllocState& InjectedState() {
+ return InjectedAlloc->Ref();
+ }
+
std::shared_ptr<TScopedAlloc> InjectedScopeAlloc() {
- return InjectedAlloc;
- }
-
- void AcquireOriginal() {
- InjectedAlloc->Release();
- TlsAllocState = OldTlsAllocState;
- }
-
- void AcquireInjected() {
- TlsAllocState = nullptr;
- InjectedAlloc->Acquire();
- }
-private:
- TAllocState* OldTlsAllocState;
+ return InjectedAlloc;
+ }
+
+ void AcquireOriginal() {
+ InjectedAlloc->Release();
+ TlsAllocState = OldTlsAllocState;
+ }
+
+ void AcquireInjected() {
+ TlsAllocState = nullptr;
+ InjectedAlloc->Acquire();
+ }
+private:
+ TAllocState* OldTlsAllocState;
std::shared_ptr<TScopedAlloc> InjectedAlloc;
-};
-
-class TInjectFreeGuard: TNonCopyable {
-public:
- TInjectFreeGuard(TInjectedAlloc* injectedAlloc = nullptr)
- : InjectedAllocPtr(injectedAlloc)
- {
- if (InjectedAllocPtr) {
- InjectedAllocPtr->AcquireInjected();
- }
- }
-
- ~TInjectFreeGuard() {
- if (InjectedAllocPtr) {
- InjectedAllocPtr->AcquireOriginal();
- }
- }
-
- void Free() {
- if (InjectedAllocPtr) {
- InjectedAllocPtr->AcquireOriginal();
- InjectedAllocPtr = nullptr;
- }
- }
-private:
- TInjectedAlloc* InjectedAllocPtr;
-};
-
+};
+
+class TInjectFreeGuard: TNonCopyable {
+public:
+ TInjectFreeGuard(TInjectedAlloc* injectedAlloc = nullptr)
+ : InjectedAllocPtr(injectedAlloc)
+ {
+ if (InjectedAllocPtr) {
+ InjectedAllocPtr->AcquireInjected();
+ }
+ }
+
+ ~TInjectFreeGuard() {
+ if (InjectedAllocPtr) {
+ InjectedAllocPtr->AcquireOriginal();
+ }
+ }
+
+ void Free() {
+ if (InjectedAllocPtr) {
+ InjectedAllocPtr->AcquireOriginal();
+ InjectedAllocPtr = nullptr;
+ }
+ }
+private:
+ TInjectedAlloc* InjectedAllocPtr;
+};
+
class TPagedArena {
public:
TPagedArena(TAlignedPagePool* pagePool) noexcept
diff --git a/ydb/library/yql/minikql/mkql_node.cpp b/ydb/library/yql/minikql/mkql_node.cpp
index 5639a9ca15..4c6f3e45ad 100644
--- a/ydb/library/yql/minikql/mkql_node.cpp
+++ b/ydb/library/yql/minikql/mkql_node.cpp
@@ -5,14 +5,14 @@
#include "mkql_node_printer.h"
#include <util/stream/str.h>
-#include <util/string/join.h>
+#include <util/string/join.h>
namespace NKikimr {
namespace NMiniKQL {
-#define MKQL_SWITCH_ENUM_TYPE_TO_STR(name, val) \
+#define MKQL_SWITCH_ENUM_TYPE_TO_STR(name, val) \
case val: return TStringBuf(#name);
-
+
using namespace NDetail;
TTypeEnvironment::TTypeEnvironment(TScopedAlloc& alloc)
@@ -179,8 +179,8 @@ bool TNode::IsMergeable() const {
}
TStringBuf TType::KindAsStr(EKind kind) {
- switch (static_cast<int>(kind)) {
- MKQL_TYPE_KINDS(MKQL_SWITCH_ENUM_TYPE_TO_STR)
+ switch (static_cast<int>(kind)) {
+ MKQL_TYPE_KINDS(MKQL_SWITCH_ENUM_TYPE_TO_STR)
}
return TStringBuf("unknown");
@@ -722,7 +722,7 @@ bool TStructLiteral::Equals(const TStructLiteral& nodeToCompare) const {
TListType::TListType(TType* itemType, const TTypeEnvironment& env, bool validate)
: TType(EKind::List, env.GetTypeOfType())
, Data(itemType)
- , IndexDictKey(env.GetUi64())
+ , IndexDictKey(env.GetUi64())
{
Y_UNUSED(validate);
}
diff --git a/ydb/library/yql/minikql/mkql_node.h b/ydb/library/yql/minikql/mkql_node.h
index aaf085297d..ee74455ea6 100644
--- a/ydb/library/yql/minikql/mkql_node.h
+++ b/ydb/library/yql/minikql/mkql_node.h
@@ -278,7 +278,7 @@ class TOptionalLiteral;
class TAnyType;
class TTupleLiteral;
class TResourceType;
-class TDataType;
+class TDataType;
// A non-owning reference to internalized string
@@ -437,10 +437,10 @@ public:
return Ui32;
}
- TDataType* GetUi64() const {
- return Ui64;
- }
-
+ TDataType* GetUi64() const {
+ return Ui64;
+ }
+
std::vector<TNode*>& GetNodeStack() const {
return Stack;
@@ -698,10 +698,10 @@ public:
return Data;
}
- TDataType* IndexDictKeyType() const {
- return IndexDictKey;
- }
-
+ TDataType* IndexDictKeyType() const {
+ return IndexDictKey;
+ }
+
private:
TListType(TType* itemType, const TTypeEnvironment& env, bool validate = true);
@@ -711,7 +711,7 @@ private:
private:
TType* Data;
- TDataType* IndexDictKey;
+ TDataType* IndexDictKey;
};
class TListLiteral : public TNode {
diff --git a/ydb/library/yql/minikql/mkql_node_serialization.cpp b/ydb/library/yql/minikql/mkql_node_serialization.cpp
index 266f8e9730..e314f38cd6 100644
--- a/ydb/library/yql/minikql/mkql_node_serialization.cpp
+++ b/ydb/library/yql/minikql/mkql_node_serialization.cpp
@@ -75,23 +75,23 @@ namespace {
return Names;
}
- TVector<TInternName>& GetNameOrder() {
- return NameOrder;
- }
-
-
+ TVector<TInternName>& GetNameOrder() {
+ return NameOrder;
+ }
+
+
private:
void AddName(const TInternName& name) {
- auto iter = Names.emplace(name, 0);
- if (iter.second) {
- NameOrder.emplace_back(name);
- }
- ++iter.first->second;
+ auto iter = Names.emplace(name, 0);
+ if (iter.second) {
+ NameOrder.emplace_back(name);
+ }
+ ++iter.first->second;
}
private:
THashMap<TInternName, ui32> Names;
- TVector<TInternName> NameOrder;
+ TVector<TInternName> NameOrder;
};
class TWriter {
@@ -842,10 +842,10 @@ namespace {
TWriter& Owner;
};
- TWriter(THashMap<TInternName, ui32>& names, TVector<TInternName>& nameOrder)
+ TWriter(THashMap<TInternName, ui32>& names, TVector<TInternName>& nameOrder)
{
Names.swap(names);
- NameOrder.swap(nameOrder);
+ NameOrder.swap(nameOrder);
}
void Write(TRuntimeNode node) {
@@ -894,11 +894,11 @@ namespace {
WriteVar32(Names.size());
ui32 nameIndex = 0;
- for (const auto& orderedName: NameOrder) {
- auto it = Names.find(orderedName);
- if (it == Names.end()) {
- continue;
- }
+ for (const auto& orderedName: NameOrder) {
+ auto it = Names.find(orderedName);
+ if (it == Names.end()) {
+ continue;
+ }
const auto& name = it->first;
WriteVar32(name.Str().size());
WriteMany(name.Str().data(), name.Str().size());
@@ -960,7 +960,7 @@ namespace {
TString Out;
ui32 ReferenceCount = 0;
THashMap<TInternName, ui32> Names;
- TVector<TInternName> NameOrder;
+ TVector<TInternName> NameOrder;
TVector<std::pair<TNode*, bool>> Stack;
};
@@ -2054,8 +2054,8 @@ TString SerializeRuntimeNode(TExploringNodeVisitor& explorer, TRuntimeNode node,
}
auto& names = preparer.GetNames();
- auto& nameOrder = preparer.GetNameOrder();
- TWriter writer(names, nameOrder);
+ auto& nameOrder = preparer.GetNameOrder();
+ TWriter writer(names, nameOrder);
writer.Write(node);
for (auto node : explorer.GetNodes()) {
node->SetCookie(0);
diff --git a/ydb/library/yql/minikql/mkql_program_builder.cpp b/ydb/library/yql/minikql/mkql_program_builder.cpp
index 700a3f8cd4..47ae6e4c8f 100644
--- a/ydb/library/yql/minikql/mkql_program_builder.cpp
+++ b/ydb/library/yql/minikql/mkql_program_builder.cpp
@@ -768,19 +768,19 @@ TRuntimeNode TProgramBuilder::ChainMap(TRuntimeNode list, TRuntimeNode state, co
TRuntimeNode TProgramBuilder::ChainMap(TRuntimeNode list, TRuntimeNode state, const TBinarySplitLambda& handler) {
const auto listType = list.GetStaticType();
MKQL_ENSURE(listType->IsFlow() || listType->IsList() || listType->IsStream(), "Expected flow, list or stream");
-
+
const auto itemType = listType->IsFlow() ?
AS_TYPE(TFlowType, listType)->GetItemType():
listType->IsList() ?
AS_TYPE(TListType, listType)->GetItemType():
AS_TYPE(TStreamType, listType)->GetItemType();
- ThrowIfListOfVoid(itemType);
-
+ ThrowIfListOfVoid(itemType);
+
const auto stateNodeArg = Arg(state.GetStaticType());
const auto itemArg = Arg(itemType);
const auto newItemAndState = handler(itemArg, stateNodeArg);
-
+
MKQL_ENSURE(std::get<1U>(newItemAndState).GetStaticType()->IsSameType(*state.GetStaticType()), "State type is changed by the handler");
const auto resultItemType = std::get<0U>(newItemAndState).GetStaticType();
TType* resultListType = nullptr;
@@ -791,17 +791,17 @@ TRuntimeNode TProgramBuilder::ChainMap(TRuntimeNode list, TRuntimeNode state, co
} else if (listType->IsStream()) {
resultListType = TStreamType::Create(resultItemType, Env);
}
-
+
TCallableBuilder callableBuilder(Env, __func__, resultListType);
- callableBuilder.Add(list);
- callableBuilder.Add(state);
- callableBuilder.Add(itemArg);
- callableBuilder.Add(stateNodeArg);
+ callableBuilder.Add(list);
+ callableBuilder.Add(state);
+ callableBuilder.Add(itemArg);
+ callableBuilder.Add(stateNodeArg);
callableBuilder.Add(std::get<0U>(newItemAndState));
callableBuilder.Add(std::get<1U>(newItemAndState));
- return TRuntimeNode(callableBuilder.Build(), false);
-}
-
+ return TRuntimeNode(callableBuilder.Build(), false);
+}
+
TRuntimeNode TProgramBuilder::Chain1Map(TRuntimeNode list, const TUnaryLambda& init, const TBinaryLambda& handler) {
return Chain1Map(list,
[&](TRuntimeNode item) -> TRuntimeNodePair {
@@ -818,15 +818,15 @@ TRuntimeNode TProgramBuilder::Chain1Map(TRuntimeNode list, const TUnaryLambda& i
TRuntimeNode TProgramBuilder::Chain1Map(TRuntimeNode list, const TUnarySplitLambda& init, const TBinarySplitLambda& handler) {
const auto listType = list.GetStaticType();
MKQL_ENSURE(listType->IsFlow() || listType->IsList() || listType->IsStream(), "Expected flow, list or stream");
-
+
const auto itemType = listType->IsFlow() ?
AS_TYPE(TFlowType, listType)->GetItemType():
listType->IsList() ?
AS_TYPE(TListType, listType)->GetItemType():
AS_TYPE(TStreamType, listType)->GetItemType();
- ThrowIfListOfVoid(itemType);
-
+ ThrowIfListOfVoid(itemType);
+
const auto itemArg = Arg(itemType);
const auto initItemAndState = init(itemArg);
const auto resultItemType = std::get<0U>(initItemAndState).GetStaticType();
@@ -839,23 +839,23 @@ TRuntimeNode TProgramBuilder::Chain1Map(TRuntimeNode list, const TUnarySplitLamb
} else if (listType->IsStream()) {
resultListType = TStreamType::Create(resultItemType, Env);
}
-
+
const auto stateArg = Arg(stateType);
const auto updateItemAndState = handler(itemArg, stateArg);
MKQL_ENSURE(std::get<0U>(updateItemAndState).GetStaticType()->IsSameType(*resultItemType), "Item type is changed by the handler");
MKQL_ENSURE(std::get<1U>(updateItemAndState).GetStaticType()->IsSameType(*stateType), "State type is changed by the handler");
-
+
TCallableBuilder callableBuilder(Env, __func__, resultListType);
- callableBuilder.Add(list);
- callableBuilder.Add(itemArg);
+ callableBuilder.Add(list);
+ callableBuilder.Add(itemArg);
callableBuilder.Add(std::get<0U>(initItemAndState));
callableBuilder.Add(std::get<1U>(initItemAndState));
- callableBuilder.Add(stateArg);
+ callableBuilder.Add(stateArg);
callableBuilder.Add(std::get<0U>(updateItemAndState));
callableBuilder.Add(std::get<1U>(updateItemAndState));
- return TRuntimeNode(callableBuilder.Build(), false);
-}
-
+ return TRuntimeNode(callableBuilder.Build(), false);
+}
+
TRuntimeNode TProgramBuilder::ToList(TRuntimeNode optional) {
const auto optionalType = optional.GetStaticType();
MKQL_ENSURE(optionalType->IsOptional(), "Expected optional");
@@ -2722,8 +2722,8 @@ TRuntimeNode TProgramBuilder::AggrAdd(TRuntimeNode data1, TRuntimeNode data2) {
}
TRuntimeNode TProgramBuilder::QueueCreate(TRuntimeNode initCapacity, TRuntimeNode initSize, const TArrayRef<const TRuntimeNode>& dependentNodes, TType* returnType) {
- auto resType = AS_TYPE(TResourceType, returnType);
- const auto tag = resType->GetTag();
+ auto resType = AS_TYPE(TResourceType, returnType);
+ const auto tag = resType->GetTag();
if (initCapacity.GetStaticType()->IsVoid()) {
MKQL_ENSURE(RuntimeVersion >= 13, "Unbounded queue is not supported in runtime version " << RuntimeVersion);
@@ -2732,54 +2732,54 @@ TRuntimeNode TProgramBuilder::QueueCreate(TRuntimeNode initCapacity, TRuntimeNod
MKQL_ENSURE(initCapacityType->GetSchemeType() == NUdf::TDataType<ui64>::Id, "init capcity must be ui64");
}
- auto initSizeType = AS_TYPE(TDataType, initSize);
+ auto initSizeType = AS_TYPE(TDataType, initSize);
MKQL_ENSURE(initSizeType->GetSchemeType() == NUdf::TDataType<ui64>::Id, "init size must be ui64");
TCallableBuilder callableBuilder(Env, __func__, returnType, true);
callableBuilder.Add(NewDataLiteral<NUdf::EDataSlot::String>(tag));
- callableBuilder.Add(initCapacity);
- callableBuilder.Add(initSize);
- for (auto node : dependentNodes) {
- callableBuilder.Add(node);
- }
- return TRuntimeNode(callableBuilder.Build(), false);
-}
-
-TRuntimeNode TProgramBuilder::QueuePush(TRuntimeNode resource, TRuntimeNode value) {
- auto resType = AS_TYPE(TResourceType, resource);
- const auto tag = resType->GetTag();
+ callableBuilder.Add(initCapacity);
+ callableBuilder.Add(initSize);
+ for (auto node : dependentNodes) {
+ callableBuilder.Add(node);
+ }
+ return TRuntimeNode(callableBuilder.Build(), false);
+}
+
+TRuntimeNode TProgramBuilder::QueuePush(TRuntimeNode resource, TRuntimeNode value) {
+ auto resType = AS_TYPE(TResourceType, resource);
+ const auto tag = resType->GetTag();
MKQL_ENSURE(tag.StartsWith(ResourceQueuePrefix), "Expected Queue resource");
TCallableBuilder callableBuilder(Env, __func__, resource.GetStaticType());
- callableBuilder.Add(resource);
- callableBuilder.Add(value);
- return TRuntimeNode(callableBuilder.Build(), false);
-}
-
-TRuntimeNode TProgramBuilder::QueuePop(TRuntimeNode resource) {
- auto resType = AS_TYPE(TResourceType, resource);
- const auto tag = resType->GetTag();
+ callableBuilder.Add(resource);
+ callableBuilder.Add(value);
+ return TRuntimeNode(callableBuilder.Build(), false);
+}
+
+TRuntimeNode TProgramBuilder::QueuePop(TRuntimeNode resource) {
+ auto resType = AS_TYPE(TResourceType, resource);
+ const auto tag = resType->GetTag();
MKQL_ENSURE(tag.StartsWith(ResourceQueuePrefix), "Expected Queue resource");
TCallableBuilder callableBuilder(Env, __func__, resource.GetStaticType());
- callableBuilder.Add(resource);
- return TRuntimeNode(callableBuilder.Build(), false);
-}
-
+ callableBuilder.Add(resource);
+ return TRuntimeNode(callableBuilder.Build(), false);
+}
+
TRuntimeNode TProgramBuilder::QueuePeek(TRuntimeNode resource, TRuntimeNode index, const TArrayRef<const TRuntimeNode>& dependentNodes, TType* returnType) {
- MKQL_ENSURE(returnType->IsOptional(), "Expected optional type as result of QueuePeek");
- auto resType = AS_TYPE(TResourceType, resource);
- auto indexType = AS_TYPE(TDataType, index);
+ MKQL_ENSURE(returnType->IsOptional(), "Expected optional type as result of QueuePeek");
+ auto resType = AS_TYPE(TResourceType, resource);
+ auto indexType = AS_TYPE(TDataType, index);
MKQL_ENSURE(indexType->GetSchemeType() == NUdf::TDataType<ui64>::Id, "index size must be ui64");
- const auto tag = resType->GetTag();
+ const auto tag = resType->GetTag();
MKQL_ENSURE(tag.StartsWith(ResourceQueuePrefix), "Expected Queue resource");
TCallableBuilder callableBuilder(Env, __func__, returnType);
- callableBuilder.Add(resource);
- callableBuilder.Add(index);
- for (auto node : dependentNodes) {
- callableBuilder.Add(node);
- }
- return TRuntimeNode(callableBuilder.Build(), false);
-}
-
+ callableBuilder.Add(resource);
+ callableBuilder.Add(index);
+ for (auto node : dependentNodes) {
+ callableBuilder.Add(node);
+ }
+ return TRuntimeNode(callableBuilder.Build(), false);
+}
+
TRuntimeNode TProgramBuilder::QueueRange(TRuntimeNode resource, TRuntimeNode begin, TRuntimeNode end, const TArrayRef<const TRuntimeNode>& dependentNodes, TType* returnType) {
MKQL_ENSURE(RuntimeVersion >= 14, "QueueRange is not supported in runtime version " << RuntimeVersion);
@@ -2804,20 +2804,20 @@ TRuntimeNode TProgramBuilder::QueueRange(TRuntimeNode resource, TRuntimeNode beg
return TRuntimeNode(callableBuilder.Build(), false);
}
-TRuntimeNode TProgramBuilder::PreserveStream(TRuntimeNode stream, TRuntimeNode queue, TRuntimeNode outpace) {
- auto streamType = AS_TYPE(TStreamType, stream);
- auto resType = AS_TYPE(TResourceType, queue);
- auto outpaceType = AS_TYPE(TDataType, outpace);
+TRuntimeNode TProgramBuilder::PreserveStream(TRuntimeNode stream, TRuntimeNode queue, TRuntimeNode outpace) {
+ auto streamType = AS_TYPE(TStreamType, stream);
+ auto resType = AS_TYPE(TResourceType, queue);
+ auto outpaceType = AS_TYPE(TDataType, outpace);
MKQL_ENSURE(outpaceType->GetSchemeType() == NUdf::TDataType<ui64>::Id, "PreserveStream: outpace size must be ui64");
- const auto tag = resType->GetTag();
- MKQL_ENSURE(tag.StartsWith(ResourceQueuePrefix), "PreserveStream: Expected Queue resource");
+ const auto tag = resType->GetTag();
+ MKQL_ENSURE(tag.StartsWith(ResourceQueuePrefix), "PreserveStream: Expected Queue resource");
TCallableBuilder callableBuilder(Env, __func__, streamType);
- callableBuilder.Add(stream);
- callableBuilder.Add(queue);
- callableBuilder.Add(outpace);
- return TRuntimeNode(callableBuilder.Build(), false);
-}
-
+ callableBuilder.Add(stream);
+ callableBuilder.Add(queue);
+ callableBuilder.Add(outpace);
+ return TRuntimeNode(callableBuilder.Build(), false);
+}
+
TRuntimeNode TProgramBuilder::Seq(const TArrayRef<const TRuntimeNode>& args, TType* returnType) {
MKQL_ENSURE(RuntimeVersion >= 15, "Seq is not supported in runtime version " << RuntimeVersion);
@@ -2829,31 +2829,31 @@ TRuntimeNode TProgramBuilder::Seq(const TArrayRef<const TRuntimeNode>& args, TTy
}
TRuntimeNode TProgramBuilder::FromYsonSimpleType(TRuntimeNode input, NUdf::TDataTypeId schemeType) {
- auto type = input.GetStaticType();
- if (type->IsOptional()) {
- type = static_cast<const TOptionalType&>(*type).GetItemType();
- }
- MKQL_ENSURE(type->IsData(), "Expected data type");
- auto resDataType = NewDataType(schemeType);
- auto resultType = NewOptionalType(resDataType);
+ auto type = input.GetStaticType();
+ if (type->IsOptional()) {
+ type = static_cast<const TOptionalType&>(*type).GetItemType();
+ }
+ MKQL_ENSURE(type->IsData(), "Expected data type");
+ auto resDataType = NewDataType(schemeType);
+ auto resultType = NewOptionalType(resDataType);
TCallableBuilder callableBuilder(Env, __func__, resultType);
- callableBuilder.Add(input);
- callableBuilder.Add(NewDataLiteral(static_cast<ui32>(schemeType)));
- return TRuntimeNode(callableBuilder.Build(), false);
-}
-
+ callableBuilder.Add(input);
+ callableBuilder.Add(NewDataLiteral(static_cast<ui32>(schemeType)));
+ return TRuntimeNode(callableBuilder.Build(), false);
+}
+
TRuntimeNode TProgramBuilder::TryWeakMemberFromDict(TRuntimeNode other, TRuntimeNode rest, NUdf::TDataTypeId schemeType, const std::string_view& memberName) {
- auto resDataType = NewDataType(schemeType);
- auto resultType = NewOptionalType(resDataType);
-
+ auto resDataType = NewDataType(schemeType);
+ auto resultType = NewOptionalType(resDataType);
+
TCallableBuilder callableBuilder(Env, __func__, resultType);
- callableBuilder.Add(other);
- callableBuilder.Add(rest);
- callableBuilder.Add(NewDataLiteral(static_cast<ui32>(schemeType)));
- callableBuilder.Add(NewDataLiteral<NUdf::EDataSlot::String>(memberName));
- return TRuntimeNode(callableBuilder.Build(), false);
-}
-
+ callableBuilder.Add(other);
+ callableBuilder.Add(rest);
+ callableBuilder.Add(NewDataLiteral(static_cast<ui32>(schemeType)));
+ callableBuilder.Add(NewDataLiteral<NUdf::EDataSlot::String>(memberName));
+ return TRuntimeNode(callableBuilder.Build(), false);
+}
+
TRuntimeNode TProgramBuilder::TimezoneId(TRuntimeNode name) {
bool isOptional;
auto dataType = UnpackOptionalData(name, isOptional);
diff --git a/ydb/library/yql/minikql/mkql_program_builder.h b/ydb/library/yql/minikql/mkql_program_builder.h
index 05d9e7bd48..10f1ad7ccf 100644
--- a/ydb/library/yql/minikql/mkql_program_builder.h
+++ b/ydb/library/yql/minikql/mkql_program_builder.h
@@ -579,20 +579,20 @@ public:
TRuntimeNode AggrMax(TRuntimeNode data1, TRuntimeNode data2);
TRuntimeNode AggrAdd(TRuntimeNode data1, TRuntimeNode data2);
- //-- queue functions
+ //-- queue functions
TRuntimeNode QueueCreate(TRuntimeNode initCapacity, TRuntimeNode initCreate, const TArrayRef<const TRuntimeNode>& dependentNodes, TType* returnType);
- TRuntimeNode QueuePush(TRuntimeNode resource, TRuntimeNode value);
- TRuntimeNode QueuePop(TRuntimeNode resource);
+ TRuntimeNode QueuePush(TRuntimeNode resource, TRuntimeNode value);
+ TRuntimeNode QueuePop(TRuntimeNode resource);
TRuntimeNode QueuePeek(TRuntimeNode resource, TRuntimeNode index, const TArrayRef<const TRuntimeNode>& dependentNodes, TType* returnType);
TRuntimeNode QueueRange(TRuntimeNode resource, TRuntimeNode begin, TRuntimeNode end, const TArrayRef<const TRuntimeNode>& dependentNodes, TType* returnType);
- TRuntimeNode PreserveStream(TRuntimeNode stream, TRuntimeNode preserve, TRuntimeNode outpace);
-
+ TRuntimeNode PreserveStream(TRuntimeNode stream, TRuntimeNode preserve, TRuntimeNode outpace);
+
TRuntimeNode Seq(const TArrayRef<const TRuntimeNode>& items, TType* returnType);
TRuntimeNode FromYsonSimpleType(TRuntimeNode input, NUdf::TDataTypeId schemeType);
TRuntimeNode TryWeakMemberFromDict(TRuntimeNode other, TRuntimeNode rest, NUdf::TDataTypeId schemeType, const std::string_view& memberName);
-
+
TRuntimeNode TimezoneId(TRuntimeNode name);
TRuntimeNode TimezoneName(TRuntimeNode id);
TRuntimeNode AddTimezone(TRuntimeNode utc, TRuntimeNode id);
diff --git a/ydb/library/yql/minikql/mkql_type_ops.cpp b/ydb/library/yql/minikql/mkql_type_ops.cpp
index d199917176..d559bb108c 100644
--- a/ydb/library/yql/minikql/mkql_type_ops.cpp
+++ b/ydb/library/yql/minikql/mkql_type_ops.cpp
@@ -1754,15 +1754,15 @@ NUdf::TUnboxedValuePod ValueFromString(NUdf::EDataSlot type, NUdf::TStringRef bu
NUdf::TUnboxedValuePod SimpleValueFromYson(NUdf::EDataSlot type, NUdf::TStringRef buf) {
const bool isBinYson = !buf.Empty() && *buf.Data() <= NYson::NDetail::Uint64Marker;
- if (!isBinYson) {
- auto textBuf = buf;
- switch (type) {
+ if (!isBinYson) {
+ auto textBuf = buf;
+ switch (type) {
case NUdf::EDataSlot::Bool:
- if (buf.Empty()) {
+ if (buf.Empty()) {
return NUdf::TUnboxedValuePod();
- }
- textBuf = buf.Substring(1, buf.Size() - 1);
- break;
+ }
+ textBuf = buf.Substring(1, buf.Size() - 1);
+ break;
case NUdf::EDataSlot::Float:
case NUdf::EDataSlot::Double:
if (buf.Empty()) {
@@ -1781,25 +1781,25 @@ NUdf::TUnboxedValuePod SimpleValueFromYson(NUdf::EDataSlot type, NUdf::TStringRe
case NUdf::EDataSlot::Date:
case NUdf::EDataSlot::Datetime:
case NUdf::EDataSlot::Timestamp:
- if (buf.Empty()) {
+ if (buf.Empty()) {
return NUdf::TUnboxedValuePod();
- }
- /// YSON for unsigned may be with or without suffix 'u'
- if (buf.Data()[buf.Size() - 1] == 'u') {
- textBuf = buf.Substring(0, buf.Size() - 1);
- }
- break;
+ }
+ /// YSON for unsigned may be with or without suffix 'u'
+ if (buf.Data()[buf.Size() - 1] == 'u') {
+ textBuf = buf.Substring(0, buf.Size() - 1);
+ }
+ break;
case NUdf::EDataSlot::String: {
- if (buf.Empty()) {
+ if (buf.Empty()) {
return NUdf::TUnboxedValuePod::Zero();
- }
+ }
- const char ysonQuote = '"';
+ const char ysonQuote = '"';
if (*buf.Data() == NYson::NDetail::EntitySymbol) {
return NUdf::TUnboxedValuePod();
} else if (*buf.Data() != ysonQuote) {
return MakeString(buf);
- }
+ }
if (const auto count = std::count(buf.Data(), buf.Data() + buf.Size(), '\\')) {
if (const auto size = buf.Size() - count) {
@@ -1811,8 +1811,8 @@ NUdf::TUnboxedValuePod SimpleValueFromYson(NUdf::EDataSlot type, NUdf::TStringRe
}
} else {
return MakeString(buf);
- }
- }
+ }
+ }
case NUdf::EDataSlot::TzDate:
case NUdf::EDataSlot::TzDatetime:
case NUdf::EDataSlot::TzTimestamp:
@@ -1825,23 +1825,23 @@ NUdf::TUnboxedValuePod SimpleValueFromYson(NUdf::EDataSlot type, NUdf::TStringRe
}
return ValueFromString(type, textBuf);
- }
+ }
- const ui8 ytBinType = *buf.Data();
- auto binPayload = buf.Substring(1, buf.Size() - 1);
- switch (type) {
+ const ui8 ytBinType = *buf.Data();
+ auto binPayload = buf.Substring(1, buf.Size() - 1);
+ switch (type) {
case NUdf::EDataSlot::Bool: {
if (ytBinType == NYson::NDetail::FalseMarker) {
return NUdf::TUnboxedValuePod(false);
}
-
+
if (ytBinType == NYson::NDetail::TrueMarker) {
return NUdf::TUnboxedValuePod(true);
}
return NUdf::TUnboxedValuePod();
- }
-
+ }
+
case NUdf::EDataSlot::Uint8:
case NUdf::EDataSlot::Uint16:
case NUdf::EDataSlot::Uint32:
@@ -1851,18 +1851,18 @@ NUdf::TUnboxedValuePod SimpleValueFromYson(NUdf::EDataSlot type, NUdf::TStringRe
case NUdf::EDataSlot::Timestamp: {
if (ytBinType != NYson::NDetail::Uint64Marker) {
return NUdf::TUnboxedValuePod();
- }
-
- TMemoryInput stringRefStream(binPayload.Data(), binPayload.Size());
- ui64 value;
+ }
+
+ TMemoryInput stringRefStream(binPayload.Data(), binPayload.Size());
+ ui64 value;
const size_t read = NYson::ReadVarUInt64(&stringRefStream, &value);
- if (read != binPayload.Size()) {
+ if (read != binPayload.Size()) {
return NUdf::TUnboxedValuePod();
- }
-
+ }
+
return NUdf::TUnboxedValuePod(value);
- }
-
+ }
+
case NUdf::EDataSlot::Int8:
case NUdf::EDataSlot::Int16:
case NUdf::EDataSlot::Int32:
@@ -1871,22 +1871,22 @@ NUdf::TUnboxedValuePod SimpleValueFromYson(NUdf::EDataSlot type, NUdf::TStringRe
if (ytBinType != NYson::NDetail::Int64Marker) {
return NUdf::TUnboxedValuePod();
}
-
- TMemoryInput stringRefStream(binPayload.Data(), binPayload.Size());
- i64 value;
+
+ TMemoryInput stringRefStream(binPayload.Data(), binPayload.Size());
+ i64 value;
const size_t read = NYson::ReadVarInt64(&stringRefStream, &value);
- if (read != binPayload.Size()) {
+ if (read != binPayload.Size()) {
return NUdf::TUnboxedValuePod();
- }
-
+ }
+
return NUdf::TUnboxedValuePod(value);
- }
-
+ }
+
case NUdf::EDataSlot::Float: {
if (ytBinType != NYson::NDetail::DoubleMarker || binPayload.Size() != 8) {
return NUdf::TUnboxedValuePod();
}
-
+
const float x = *reinterpret_cast<const double*>(binPayload.Data());
return NUdf::TUnboxedValuePod(x);
}
@@ -1898,28 +1898,28 @@ NUdf::TUnboxedValuePod SimpleValueFromYson(NUdf::EDataSlot type, NUdf::TStringRe
const double x = *reinterpret_cast<const double*>(binPayload.Data());
return NUdf::TUnboxedValuePod(x);
- }
-
+ }
+
case NUdf::EDataSlot::String:
case NUdf::EDataSlot::Utf8:
case NUdf::EDataSlot::Json: {
if (ytBinType != NYson::NDetail::StringMarker) {
return NUdf::TUnboxedValuePod();
}
-
- TMemoryInput stringRefStream(binPayload.Data(), binPayload.Size());
- i32 value;
+
+ TMemoryInput stringRefStream(binPayload.Data(), binPayload.Size());
+ i32 value;
const size_t read = NYson::ReadVarInt32(&stringRefStream, &value);
- binPayload = binPayload.Substring(read, binPayload.Size() - read);
+ binPayload = binPayload.Substring(read, binPayload.Size() - read);
const size_t strLen = value;
- if (strLen != binPayload.Size()) {
+ if (strLen != binPayload.Size()) {
return NUdf::TUnboxedValuePod();
- }
-
+ }
+
return MakeString(NUdf::TStringRef(binPayload.Data(), strLen));
- }
-
- case NUdf::EDataSlot::Yson:
+ }
+
+ case NUdf::EDataSlot::Yson:
return MakeString(buf);
case NUdf::EDataSlot::TzDate:
@@ -1930,11 +1930,11 @@ NUdf::TUnboxedValuePod SimpleValueFromYson(NUdf::EDataSlot type, NUdf::TStringRe
case NUdf::EDataSlot::DyNumber:
case NUdf::EDataSlot::JsonDocument:
Y_FAIL("TODO");
- }
-
- MKQL_ENSURE(false, "SimpleValueFromYson: Incorrect typeid: " << type);
-}
-
+ }
+
+ MKQL_ENSURE(false, "SimpleValueFromYson: Incorrect typeid: " << type);
+}
+
ui16 InitTimezones() {
return ui16(Singleton<TTimezones>()->Zones.size());
}
diff --git a/ydb/library/yql/mount/lib/yql/window.yql b/ydb/library/yql/mount/lib/yql/window.yql
index d60a5df2cf..371f4c687c 100644
--- a/ydb/library/yql/mount/lib/yql/window.yql
+++ b/ydb/library/yql/mount/lib/yql/window.yql
@@ -1,30 +1,30 @@
-# library
-(
-
+# library
+(
+
(let empty_list (lambda '(list_type) (MatchType list_type 'Null (lambda '() (EmptyList)) (lambda '() (List list_type)))))
-# list_type:type function:lambda
-# doesn't support optional values
-# simple function not support shift and recalculated on whole window
-(let simple_traits_factory (lambda '(list_type function) (block '(
- (let init (lambda '(value) value))
- (let update (lambda '(value state) (Apply function value state)))
- (let shift (lambda '(value state) (Void)))
- (let current (lambda '(state) state))
+# list_type:type function:lambda
+# doesn't support optional values
+# simple function not support shift and recalculated on whole window
+(let simple_traits_factory (lambda '(list_type function) (block '(
+ (let init (lambda '(value) value))
+ (let update (lambda '(value state) (Apply function value state)))
+ (let shift (lambda '(value state) (Void)))
+ (let current (lambda '(state) state))
(return (WindowTraits (ListItemType list_type) init update shift current (Null)))
-))))
-
-# list_type:type function:lambda
-# doesn't support optional values
-# easy function with update/shift
-(let easy_traits_factory (lambda '(list_type function_update function_shift) (block '(
- (let init (lambda '(value) value))
- (let update (lambda '(value state) (Apply function_update value state)))
- (let shift (lambda '(value state) (Apply function_shift value state)))
- (let current (lambda '(state) state))
+))))
+
+# list_type:type function:lambda
+# doesn't support optional values
+# easy function with update/shift
+(let easy_traits_factory (lambda '(list_type function_update function_shift) (block '(
+ (let init (lambda '(value) value))
+ (let update (lambda '(value state) (Apply function_update value state)))
+ (let shift (lambda '(value state) (Apply function_shift value state)))
+ (let current (lambda '(state) state))
(return (WindowTraits (ListItemType list_type) init update shift current (Null)))
-))))
-
+))))
+
# list_type:type function:lambda
# doesn't support optional values
# easy function with update/shift
@@ -41,93 +41,93 @@
(let traits (Apply factory (ListType (TypeOf (Apply extractor (InstanceOf (ListItemType list_type)))))))
(let init (NthArg '1 traits))
(let update (NthArg '2 traits))
- (let shift (lambda '(value state) (Void)))
- (let current (NthArg '4 traits))
+ (let shift (lambda '(value state) (Void)))
+ (let current (NthArg '4 traits))
(let defval (NthArg '5 traits))
(let init_ext (lambda '(row) (Apply init (Apply extractor row))))
(let update_ext (lambda '(row state) (Apply update (Apply extractor row) state)))
(return (WindowTraits (ListItemType list_type) init_ext update_ext shift current defval))
))))
-(let rank_traits_factory_raw (lambda '(list_type) (block '(
- (let init (lambda '(value) '((Uint64 '1) (Uint64 '1) value)))
- (let update (lambda '(value state) '((If (== value (Nth state '2)) (Nth state '0) (Inc (Nth state '1))) (Inc (Nth state '1)) value)))
- (let shift (lambda '(value state) (Void)))
- (let current (lambda '(state) (Nth state '0)))
+(let rank_traits_factory_raw (lambda '(list_type) (block '(
+ (let init (lambda '(value) '((Uint64 '1) (Uint64 '1) value)))
+ (let update (lambda '(value state) '((If (== value (Nth state '2)) (Nth state '0) (Inc (Nth state '1))) (Inc (Nth state '1)) value)))
+ (let shift (lambda '(value state) (Void)))
+ (let current (lambda '(state) (Nth state '0)))
(return (WindowTraits (ListItemType list_type) init update shift current (Null)))
-))))
-
-(let dense_rank_traits_factory_raw (lambda '(list_type) (block '(
- (let init (lambda '(value) '((Uint64 '1) value)))
- (let update (lambda '(value state) '((If (== value (Nth state '1)) (Nth state '0) (Inc (Nth state '0))) value)))
- (let shift (lambda '(value state) (Void)))
- (let current (lambda '(state) (Nth state '0)))
+))))
+
+(let dense_rank_traits_factory_raw (lambda '(list_type) (block '(
+ (let init (lambda '(value) '((Uint64 '1) value)))
+ (let update (lambda '(value state) '((If (== value (Nth state '1)) (Nth state '0) (Inc (Nth state '0))) value)))
+ (let shift (lambda '(value state) (Void)))
+ (let current (lambda '(state) (Nth state '0)))
(return (WindowTraits (ListItemType list_type) init update shift current (Null)))
-))))
-
-# list_type:type
-# doesn't support optional values
-(let some_traits_factory_raw (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (Coalesce two one)))))
-(let bit_and_traits_factory_raw (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (BitAnd one two)))))
-(let bit_or_traits_factory_raw (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (BitOr one two)))))
-
-(let bit_xor_traits_factory_raw (lambda '(list_type) (Apply easy_traits_factory list_type (lambda '(one two) (BitXor one two)) (lambda '(val state) (BitXor state val)))))
-
-# list_type:type
-# support optional values
-(let bool_and_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (And one two)))))
-(let bool_or_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (Or one two)))))
-(let first_value_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) two))))
-(let last_value_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) one))))
-(let first_value_ignore_nulls_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (IfPresent two (lambda '(value) two) one)))))
-(let last_value_ignore_nulls_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (IfPresent one (lambda '(value) one) two)))))
-
-(let bool_xor_traits_factory_opt (lambda '(list_type) (Apply easy_traits_factory list_type (lambda '(one two) (Xor one two)) (lambda '(val state) (Xor state val)))))
-
-# list_type:type init:lambda
-# doesn't support optional values
-(let count_traits_factory (lambda '(list_type init) (block '(
- (let update (lambda '(value state) (+ state (Apply init value))))
- (let shift (lambda '(value state) (+ state (Minus (Apply init value)))))
- (let current (lambda '(state) state))
+))))
+
+# list_type:type
+# doesn't support optional values
+(let some_traits_factory_raw (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (Coalesce two one)))))
+(let bit_and_traits_factory_raw (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (BitAnd one two)))))
+(let bit_or_traits_factory_raw (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (BitOr one two)))))
+
+(let bit_xor_traits_factory_raw (lambda '(list_type) (Apply easy_traits_factory list_type (lambda '(one two) (BitXor one two)) (lambda '(val state) (BitXor state val)))))
+
+# list_type:type
+# support optional values
+(let bool_and_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (And one two)))))
+(let bool_or_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (Or one two)))))
+(let first_value_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) two))))
+(let last_value_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) one))))
+(let first_value_ignore_nulls_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (IfPresent two (lambda '(value) two) one)))))
+(let last_value_ignore_nulls_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (IfPresent one (lambda '(value) one) two)))))
+
+(let bool_xor_traits_factory_opt (lambda '(list_type) (Apply easy_traits_factory list_type (lambda '(one two) (Xor one two)) (lambda '(val state) (Xor state val)))))
+
+# list_type:type init:lambda
+# doesn't support optional values
+(let count_traits_factory (lambda '(list_type init) (block '(
+ (let update (lambda '(value state) (+ state (Apply init value))))
+ (let shift (lambda '(value state) (+ state (Minus (Apply init value)))))
+ (let current (lambda '(state) state))
(return (WindowTraits (ListItemType list_type) init update shift current (Uint64 '0)))
-))))
-
-# list_type:type
-# support optional values
-(let count_traits_factory_opt (lambda '(list_type) (block '(
- (let init (lambda '(value) (AggrCountInit value)))
- (let update (lambda '(value state) (AggrCountUpdate value state)))
- (let shift (lambda '(value state) (Void)))
- (let current (lambda '(state) state))
+))))
+
+# list_type:type
+# support optional values
+(let count_traits_factory_opt (lambda '(list_type) (block '(
+ (let init (lambda '(value) (AggrCountInit value)))
+ (let update (lambda '(value state) (AggrCountUpdate value state)))
+ (let shift (lambda '(value state) (Void)))
+ (let current (lambda '(state) state))
(return (WindowTraits (ListItemType list_type) init update shift current (Uint64 '0)))
-))))
-
-# list_type:type
-# support optional values
-(let count_if_traits_factory_opt (lambda '(list_type) (Apply count_traits_factory list_type (lambda '(value) (Convert (Coalesce value (Bool '0)) 'Uint64)))))
-(let count_all_traits_factory_opt (lambda '(list_type) (Apply count_traits_factory list_type (lambda '(value) (Uint64 '1)))))
-
-# list_type:type
-# doesn't support optional values
-(let avg_traits_factory_raw (lambda '(list_type) (block '(
+))))
+
+# list_type:type
+# support optional values
+(let count_if_traits_factory_opt (lambda '(list_type) (Apply count_traits_factory list_type (lambda '(value) (Convert (Coalesce value (Bool '0)) 'Uint64)))))
+(let count_all_traits_factory_opt (lambda '(list_type) (Apply count_traits_factory list_type (lambda '(value) (Uint64 '1)))))
+
+# list_type:type
+# doesn't support optional values
+(let avg_traits_factory_raw (lambda '(list_type) (block '(
(let convert_interval_to_decimal (lambda '(value) (StrictCast (StrictCast value (DataType 'Int64)) (DataType 'Decimal '35 '0))))
(let convert_decimal_to_interval (lambda '(value) (Unwrap (StrictCast (StrictCast value (DataType 'Int64)) (DataType 'Interval)))))
(let init (lambda '(value) '((MatchType (TypeOf value) 'Decimal (lambda '() (WidenIntegral value)) 'Interval (lambda '() (Apply convert_interval_to_decimal value )) (lambda '() (Convert value 'Double))) (Uint64 '1))))
(let update (lambda '(value state) '((+ (Nth state '0) (MatchType (TypeOf value) 'Decimal (lambda '() (WidenIntegral value)) 'Interval (lambda '() (Apply convert_interval_to_decimal value )) (lambda '() (Convert value 'Double)))) (Inc (Nth state '1)))))
- (let shift (lambda '(value state) '((- (Nth state '0) value) (Dec (Nth state '1)))))
+ (let shift (lambda '(value state) '((- (Nth state '0) value) (Dec (Nth state '1)))))
(let current (lambda '(state) (MatchType (ListItemType list_type)
'Decimal (lambda '() (Cast (Div (Nth state '0) (Nth state '1)) (ListItemType list_type)))
'Interval (lambda '() (Apply convert_decimal_to_interval (Div (Nth state '0) (Nth state '1)) ) )
(lambda '() (Div (Nth state '0) (Nth state '1))))))
(return (WindowTraits (ListItemType list_type) init update shift current (Null)))
-))))
-
-# list_type:type
-# support optional values
+))))
+
+# list_type:type
+# support optional values
(let list_traits_factory_opt_gen (lambda '(limit defval) (block '(
(return (lambda '(list_type) (block '(
- (let item_type (ListItemType list_type))
+ (let item_type (ListItemType list_type))
(let init (lambda '(value) (MatchType item_type
'Optional (lambda '() (ToList value))
'Null (lambda '() (EmptyList))
@@ -138,14 +138,14 @@
'Null (lambda '() (EmptyList))
(lambda '() (Insert state value))))
(return (If (== limit (Uint64 '0)) x (Take x limit)))))))
- (let shift (lambda '(value state) (Void)))
- (let current (lambda '(state) state))
+ (let shift (lambda '(value state) (Void)))
+ (let current (lambda '(state) state))
(return (WindowTraits item_type init update shift current defval))
))))))))
-
-# list_type:type stddev:bool sample:bool
-# doesn't support optional values
-(let variance_traits_factory_raw (lambda '(list_type stddev sample) (block '(
+
+# list_type:type stddev:bool sample:bool
+# doesn't support optional values
+(let variance_traits_factory_raw (lambda '(list_type stddev sample) (block '(
(let init (lambda '(value) '(
(Convert value 'Double)
(Double '1)
@@ -158,29 +158,29 @@
next_n
(+ (Nth state '2) (/ (* (* delta delta) (Nth state '1)) next_n))
))))))
- (let shift (lambda '(value state) (Void)))
+ (let shift (lambda '(value state) (Void)))
(let current (lambda '(state) (block '(
(let count (Nth state '1))
(let result (/ (Nth state '2) (If sample (- count (Double '1)) count)))
(return (If stddev (Apply (Udf 'Math.Sqrt) result) result))))))
(return (WindowTraits (ListItemType list_type) init update shift current (Null)))
-))))
-
-# list_type:type
-# doesn't support optional values
-(let variance_0_0_traits_factory_raw (lambda '(list_type) (Apply variance_traits_factory_raw list_type (Bool '0) (Bool '0))))
-(let variance_1_0_traits_factory_raw (lambda '(list_type) (Apply variance_traits_factory_raw list_type (Bool '1) (Bool '0))))
-(let variance_0_1_traits_factory_raw (lambda '(list_type) (Apply variance_traits_factory_raw list_type (Bool '0) (Bool '1))))
-(let variance_1_1_traits_factory_raw (lambda '(list_type) (Apply variance_traits_factory_raw list_type (Bool '1) (Bool '1))))
-
+))))
+
+# list_type:type
+# doesn't support optional values
+(let variance_0_0_traits_factory_raw (lambda '(list_type) (Apply variance_traits_factory_raw list_type (Bool '0) (Bool '0))))
+(let variance_1_0_traits_factory_raw (lambda '(list_type) (Apply variance_traits_factory_raw list_type (Bool '1) (Bool '0))))
+(let variance_0_1_traits_factory_raw (lambda '(list_type) (Apply variance_traits_factory_raw list_type (Bool '0) (Bool '1))))
+(let variance_1_1_traits_factory_raw (lambda '(list_type) (Apply variance_traits_factory_raw list_type (Bool '1) (Bool '1))))
+
# list_type:type
# doesn't support optional values
(let correlation_traits_factory_raw (lambda '(list_type) (block '(
(let init (lambda '(value) '((Uint64 '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (* (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))))))
(let update (lambda '(value state) '((+ (Nth state '0) (Uint64 '1)) (+ (Nth state '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (+ (Nth state '2) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (+ (Nth state '3) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))) (+ (Nth state '4) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)))) (+ (Nth state '5) (* (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))))))
- (let shift (lambda '(value state) (Void)))
- (let current (lambda '(state) (block '(
+ (let shift (lambda '(value state) (Void)))
+ (let current (lambda '(state) (block '(
# Math comes from ISO9075-2:2011(E) and differs from what Excel uses
(let dividend (* (Nth state '3) (Nth state '0)))
(let dividend (- dividend (* (Nth state '1) (Nth state '2))))
@@ -198,8 +198,8 @@
(let covariance_traits_factory_raw (lambda '(list_type sample) (block '(
(let init (lambda '(value) '((Uint64 '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))))))
(let update (lambda '(value state) '((+ (Nth state '0) (Uint64 '1)) (+ (Nth state '1) (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0))) (+ (Nth state '2) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0))) (+ (Nth state '3) (* (Coalesce (Convert (Nth value '0) 'Double) (Double '0.0)) (Coalesce (Convert (Nth value '1) 'Double) (Double '0.0)))))))
- (let shift (lambda '(value state) (Void)))
- (let current (lambda '(state) (block '(
+ (let shift (lambda '(value state) (Void)))
+ (let current (lambda '(state) (block '(
(let covariance_result (- (Nth state '3) (/ (* (Nth state '1) (Nth state '2)) (Nth state '0))))
(let covariance_result (/ covariance_result (If sample (- (Nth state '0) (Uint64 '1)) (Nth state '0))))
(return covariance_result)
@@ -212,13 +212,13 @@
(let covariance_population_traits_factory_raw (lambda '(list_type) (Apply covariance_traits_factory_raw list_type (Bool '0))))
(let covariance_sample_traits_factory_raw (lambda '(list_type) (Apply covariance_traits_factory_raw list_type (Bool '1))))
-# list_type:type histogram:atom value:lamba weight:lambda intervals:integer
-# doesn't support optional values
-(let histogram_traits_factory_raw (lambda '(list_type histogram value weight intervals) (block '(
+# list_type:type histogram:atom value:lamba weight:lambda intervals:integer
+# doesn't support optional values
+(let histogram_traits_factory_raw (lambda '(list_type histogram value weight intervals) (block '(
(let init (lambda '(row parent) (NamedApply (Udf (Combine histogram '_Create)) '((Apply value row) (Apply weight row) intervals) (AsStruct) (DependsOn parent))))
(let update (lambda '(row state parent) (NamedApply (Udf (Combine histogram '_AddValue)) '(state (Apply value row) (Apply weight row)) (AsStruct) (DependsOn parent))))
- (let shift (lambda '(value state) (Void)))
- (let current (lambda '(state) (Apply (Udf (Combine histogram '_GetResult)) state)))
+ (let shift (lambda '(value state) (Void)))
+ (let current (lambda '(state) (Apply (Udf (Combine histogram '_GetResult)) state)))
(return (WindowTraits (ListItemType list_type) init update shift current (Null)))
))))
@@ -256,12 +256,12 @@
(let init (lambda '(value parent) (NamedApply UdfTopFreqCreate '(value buffer) (AsStruct) (DependsOn parent))))
(let update (lambda '(value state parent) (NamedApply UdfTopFreqAddValue '(state value) (AsStruct) (DependsOn parent))))
- (let shift (lambda '(value state) (Void)))
+ (let shift (lambda '(value state) (Void)))
(let current (lambda '(state) (Apply UdfTopFreqGet state n)))
(return (WindowTraits value_type init update shift current (EmptyList)))
-))))
-
+))))
+
# list_type:type extractor:lambda count:ui32 is_top:atom
# doesn't support optional values
(let top_traits_factory_raw (lambda '(list_type extractor count is_top) (block '(
@@ -307,9 +307,9 @@
(return (WindowTraits value_type init update shift current (List (ListType payload_type))))
))))
-# list_type:type n:double
-# doesn't support optional values
-(let percentile_traits_factory_raw (lambda '(list_type n) (block '(
+# list_type:type n:double
+# doesn't support optional values
+(let percentile_traits_factory_raw (lambda '(list_type n) (block '(
(let convert_into (lambda '(value) (MatchType (ListItemType list_type)
'Interval (lambda '() (SafeCast value (DataType 'Double)) ) # TODO:YQL-14129 cast to Decimal
(lambda '() value)
@@ -325,14 +325,14 @@
(let get_convert_percentile (lambda '(state n) (Apply convert_out (Apply (Udf 'Stat.TDigest_GetPercentile) state n))))
(let init (lambda '(value parent) (NamedApply (Udf 'Stat.TDigest_Create) '((Apply convert_into value)) (AsStruct) (DependsOn parent))))
(let update (lambda '(value state parent) (NamedApply (Udf 'Stat.TDigest_AddValue) '(state (Apply convert_into value)) (AsStruct) (DependsOn parent))))
- (let shift (lambda '(value state) (Void)))
+ (let shift (lambda '(value state) (Void)))
(let current (lambda '(state) (MatchType n
'Tuple (lambda '() (StaticMap n (lambda '(n) (Apply get_convert_percentile state n))))
(lambda '() (Apply get_convert_percentile state n))
)))
(return (WindowTraits (ListItemType list_type) init update shift current (Null)))
-))))
-
+))))
+
# list_type:type
# doesn't support optional values
(let hyperloglog_traits_factory_raw (lambda '(list_type n) (block '(
@@ -343,14 +343,14 @@
(return (WindowTraits (ListItemType list_type) init update shift current (Null)))
))))
-# list_type:type value:lambda weight:lambda intervals:integer
-# doesn't support optional values
-(let histogram_adaptive_ward_traits_factory_raw (lambda '(list_type value weight intervals) (Apply histogram_traits_factory_raw list_type 'Histogram.AdaptiveWardHistogram value weight intervals)))
-(let histogram_adaptive_weight_traits_factory_raw (lambda '(list_type value weight intervals) (Apply histogram_traits_factory_raw list_type 'Histogram.AdaptiveWeightHistogram value weight intervals)))
-(let histogram_adaptive_distance_traits_factory_raw (lambda '(list_type value weight intervals) (Apply histogram_traits_factory_raw list_type 'Histogram.AdaptiveDistanceHistogram value weight intervals)))
-(let histogram_block_ward_traits_factory_raw (lambda '(list_type value weight intervals) (Apply histogram_traits_factory_raw list_type 'Histogram.BlockWardHistogram value weight intervals)))
-(let histogram_block_weight_traits_factory_raw (lambda '(list_type value weight intervals) (Apply histogram_traits_factory_raw list_type 'Histogram.BlockWeightHistogram value weight intervals)))
-
+# list_type:type value:lambda weight:lambda intervals:integer
+# doesn't support optional values
+(let histogram_adaptive_ward_traits_factory_raw (lambda '(list_type value weight intervals) (Apply histogram_traits_factory_raw list_type 'Histogram.AdaptiveWardHistogram value weight intervals)))
+(let histogram_adaptive_weight_traits_factory_raw (lambda '(list_type value weight intervals) (Apply histogram_traits_factory_raw list_type 'Histogram.AdaptiveWeightHistogram value weight intervals)))
+(let histogram_adaptive_distance_traits_factory_raw (lambda '(list_type value weight intervals) (Apply histogram_traits_factory_raw list_type 'Histogram.AdaptiveDistanceHistogram value weight intervals)))
+(let histogram_block_ward_traits_factory_raw (lambda '(list_type value weight intervals) (Apply histogram_traits_factory_raw list_type 'Histogram.BlockWardHistogram value weight intervals)))
+(let histogram_block_weight_traits_factory_raw (lambda '(list_type value weight intervals) (Apply histogram_traits_factory_raw list_type 'Histogram.BlockWeightHistogram value weight intervals)))
+
# list_type:type histogram:atom value:lamba binsize:double minimum:double maximum:double
# doesn't support optional values
(let linear_histogram_traits_factory_impl (lambda '(list_type histogram value binsize minimum maximum) (block '(
@@ -366,111 +366,111 @@
(let histogram_linear_traits_factory_raw (lambda '(list_type value binsize minimum maximum) (Apply linear_histogram_traits_factory_impl list_type 'Histogram.LinearHistogram value binsize minimum maximum)))
(let histogram_logarithmic_traits_factory_raw (lambda '(list_type value binsize minimum maximum) (Apply linear_histogram_traits_factory_impl list_type 'Histogram.LogarithmicHistogram value binsize minimum maximum)))
-# list_type:type factory:lambda
-# support optional values
-(let optional_traits_factory (lambda '(list_type factory) (block '(
- (let item_type (ListItemType list_type))
+# list_type:type factory:lambda
+# support optional values
+(let optional_traits_factory (lambda '(list_type factory) (block '(
+ (let item_type (ListItemType list_type))
(let traits (Apply factory (MatchType item_type 'Optional (lambda '() (ListType (OptionalItemType item_type))) (lambda '() (ListType item_type)))))
- (let init (NthArg '1 traits))
- (let update (NthArg '2 traits))
- (let shift (NthArg '3 traits))
- (let current (NthArg '4 traits))
+ (let init (NthArg '1 traits))
+ (let update (NthArg '2 traits))
+ (let shift (NthArg '3 traits))
+ (let current (NthArg '4 traits))
(let defval (NthArg '5 traits))
-
- (let init_optional
- (lambda '(value)
+
+ (let init_optional
+ (lambda '(value)
(MatchType item_type
'Optional (lambda '()
- (IfPresent value
- (lambda '(value) (Just (Apply init value)))
- (Nothing (OptionalType (TypeOf (Apply init (InstanceOf (OptionalItemType (TypeOf value)))))))
- )
- )
+ (IfPresent value
+ (lambda '(value) (Just (Apply init value)))
+ (Nothing (OptionalType (TypeOf (Apply init (InstanceOf (OptionalItemType (TypeOf value)))))))
+ )
+ )
'Null (lambda '() defval)
- (lambda '() (Apply init value))
- )
- )
- )
-
- (let update_optional
- (lambda '(value state)
+ (lambda '() (Apply init value))
+ )
+ )
+ )
+
+ (let update_optional
+ (lambda '(value state)
(MatchType item_type
'Optional (lambda '()
- (IfPresent state
- (lambda '(state)
- (IfPresent value
- (lambda '(value) (Just (Apply update value state)))
- (Just state)
- )
- )
- (Apply init_optional value)
- )
- )
+ (IfPresent state
+ (lambda '(state)
+ (IfPresent value
+ (lambda '(value) (Just (Apply update value state)))
+ (Just state)
+ )
+ )
+ (Apply init_optional value)
+ )
+ )
'Null (lambda '() defval)
- (lambda '() (Apply update value state))
- )
- )
- )
-
-# todo: fill the body
- (let shift_optional (lambda '(value state) (Void)))
-
+ (lambda '() (Apply update value state))
+ )
+ )
+ )
+
+# todo: fill the body
+ (let shift_optional (lambda '(value state) (Void)))
+
(let current_optional (lambda '(state) (MatchType item_type 'Optional (lambda '() (Map state current)) 'Null (lambda '() defval) (lambda '() (Apply current state)))))
(return (WindowTraits item_type init_optional update_optional shift_optional current_optional defval))
-))))
-
-# list_type:type factory:lambda
-# support optional values, init and update with parent
-(let optional_traits_factory_parent (lambda '(list_type factory) (block '(
- (let item_type (ListItemType list_type))
+))))
+
+# list_type:type factory:lambda
+# support optional values, init and update with parent
+(let optional_traits_factory_parent (lambda '(list_type factory) (block '(
+ (let item_type (ListItemType list_type))
(let traits (Apply factory (MatchType item_type 'Optional (lambda '() (ListType (OptionalItemType item_type))) (lambda '() (ListType item_type)))))
- (let init (NthArg '1 traits))
- (let update (NthArg '2 traits))
- (let shift (NthArg '3 traits))
- (let current (NthArg '4 traits))
+ (let init (NthArg '1 traits))
+ (let update (NthArg '2 traits))
+ (let shift (NthArg '3 traits))
+ (let current (NthArg '4 traits))
(let defval (NthArg '5 traits))
-
- (let init_optional
- (lambda '(value parent)
+
+ (let init_optional
+ (lambda '(value parent)
(MatchType item_type
'Optional (lambda '()
- (IfPresent value
- (lambda '(value) (Just (Apply init value parent)))
- (Nothing (OptionalType (TypeOf (Apply init (InstanceOf (OptionalItemType (TypeOf value))) parent))))
- )
- )
+ (IfPresent value
+ (lambda '(value) (Just (Apply init value parent)))
+ (Nothing (OptionalType (TypeOf (Apply init (InstanceOf (OptionalItemType (TypeOf value))) parent))))
+ )
+ )
'Null (lambda '() defval)
- (lambda '() (Apply init value parent))
- )
- )
- )
-
- (let shift_optional (lambda '(value state) (Void)))
-
- (let update_optional
- (lambda '(value state parent)
+ (lambda '() (Apply init value parent))
+ )
+ )
+ )
+
+ (let shift_optional (lambda '(value state) (Void)))
+
+ (let update_optional
+ (lambda '(value state parent)
(MatchType item_type
'Optional (lambda '()
- (IfPresent state
- (lambda '(state)
- (IfPresent value
- (lambda '(value) (Just (Apply update value state parent)))
- (Just state)
- )
- )
- (Apply init_optional value parent)
- )
- )
+ (IfPresent state
+ (lambda '(state)
+ (IfPresent value
+ (lambda '(value) (Just (Apply update value state parent)))
+ (Just state)
+ )
+ )
+ (Apply init_optional value parent)
+ )
+ )
'Null (lambda '() defval)
- (lambda '() (Apply update value state parent))
- )
- )
- )
-
+ (lambda '() (Apply update value state parent))
+ )
+ )
+ )
+
(let current_optional (lambda '(state) (MatchType item_type 'Optional (lambda '() (Map state current)) 'Null (lambda '() defval) (lambda '() (Apply current state)))))
(return (WindowTraits item_type init_optional update_optional shift_optional current_optional defval))
-))))
-
+))))
+
# list_type:type factory:lambda
# support optional values, init and update with parent
(let flatten_traits_factory_parent (lambda '(list_type factory) (block '(
@@ -523,33 +523,33 @@
(return (WindowTraits item_type init_optional update_optional shift_optional current_optional defval))
))))
-# list_type:type
-# support optional values
-(let min_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (AggrMin one two)))))
-(let max_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (AggrMax one two)))))
+# list_type:type
+# support optional values
+(let min_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (AggrMin one two)))))
+(let max_traits_factory_opt (lambda '(list_type) (Apply simple_traits_factory list_type (lambda '(one two) (AggrMax one two)))))
(let sum_traits_factory_opt (lambda '(list_type) (Apply easy_traits_factory_map list_type (lambda '(val state) (AggrAdd val state)) (lambda '(val state) (AggrAdd state (Minus val))) (lambda '(x) (WidenIntegral x)) )))
-(let bit_and_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type bit_and_traits_factory_raw)))
-(let bit_or_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type bit_or_traits_factory_raw)))
-(let bit_xor_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type bit_xor_traits_factory_raw)))
-(let avg_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type avg_traits_factory_raw)))
-(let rank_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type rank_traits_factory_raw)))
-(let dense_rank_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type dense_rank_traits_factory_raw)))
-(let variance_0_0_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type variance_0_0_traits_factory_raw)))
-(let variance_1_0_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type variance_1_0_traits_factory_raw)))
-(let variance_0_1_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type variance_0_1_traits_factory_raw)))
-(let variance_1_1_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type variance_1_1_traits_factory_raw)))
+(let bit_and_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type bit_and_traits_factory_raw)))
+(let bit_or_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type bit_or_traits_factory_raw)))
+(let bit_xor_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type bit_xor_traits_factory_raw)))
+(let avg_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type avg_traits_factory_raw)))
+(let rank_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type rank_traits_factory_raw)))
+(let dense_rank_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type dense_rank_traits_factory_raw)))
+(let variance_0_0_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type variance_0_0_traits_factory_raw)))
+(let variance_1_0_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type variance_1_0_traits_factory_raw)))
+(let variance_0_1_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type variance_0_1_traits_factory_raw)))
+(let variance_1_1_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type variance_1_1_traits_factory_raw)))
(let correlation_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type correlation_traits_factory_raw)))
(let covariance_population_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type covariance_population_traits_factory_raw)))
(let covariance_sample_traits_factory_opt (lambda '(list_type) (Apply optional_traits_factory list_type covariance_sample_traits_factory_raw)))
(let correlation_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor correlation_traits_factory_opt)))
(let covariance_population_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor covariance_population_traits_factory_opt)))
(let covariance_sample_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor covariance_sample_traits_factory_opt)))
-
-# list_type:type n:double
-# support optional values
+
+# list_type:type n:double
+# support optional values
(let percentile_traits_factory_opt (lambda '(list_type n) (Apply optional_traits_factory_parent list_type (lambda '(list_type) (Apply percentile_traits_factory_raw list_type n)))))
-
+
# list_type:type count:ui32
# support optional values
(let set_traits_factory_opt (lambda '(list_type count) (Apply flatten_traits_factory_parent list_type (lambda '(list_type) (Apply set_traits_factory_raw list_type count)))))
@@ -562,74 +562,74 @@
# support optional values
(let hyperloglog_traits_factory_opt (lambda '(list_type n) (Apply optional_traits_factory_parent list_type (lambda '(list_type) (Apply hyperloglog_traits_factory_raw list_type n)))))
-# list_type:type init:lambda update:lambda shift:lambda current:lambda
-# support optional values
+# list_type:type init:lambda update:lambda shift:lambda current:lambda
+# support optional values
(let udwf_traits_factory_opt (lambda '(list_type init update shift current defval) (Apply optional_traits_factory_parent list_type (lambda '(list_type) (WindowTraits (ListItemType list_type) init update shift current defval)))))
-
-# list_type:type, factory:lambda, extractor:lambda
-(let extractor_traits_factory (lambda '(list_type extractor factory) (block '(
+
+# list_type:type, factory:lambda, extractor:lambda
+(let extractor_traits_factory (lambda '(list_type extractor factory) (block '(
(let traits (Apply factory (ListType (TypeOf (Apply extractor (InstanceOf (ListItemType list_type)))))))
- (let init (NthArg '1 traits))
- (let update (NthArg '2 traits))
- (let shift (NthArg '3 traits))
- (let current (NthArg '4 traits))
+ (let init (NthArg '1 traits))
+ (let update (NthArg '2 traits))
+ (let shift (NthArg '3 traits))
+ (let current (NthArg '4 traits))
(let defval (NthArg '5 traits))
- (let init_ext (lambda '(row) (Apply init (Apply extractor row))))
- (let update_ext (lambda '(row state) (Apply update (Apply extractor row) state)))
- (let shift_ext (lambda '(row state) (Apply shift (Apply extractor row) state)))
+ (let init_ext (lambda '(row) (Apply init (Apply extractor row))))
+ (let update_ext (lambda '(row state) (Apply update (Apply extractor row) state)))
+ (let shift_ext (lambda '(row state) (Apply shift (Apply extractor row) state)))
(return (WindowTraits (ListItemType list_type) init_ext update_ext shift_ext current defval))
-))))
-
-# list_type:type, factory:lambda, extractor:lambda
-(let extractor_traits_factory_parent (lambda '(list_type extractor factory) (block '(
+))))
+
+# list_type:type, factory:lambda, extractor:lambda
+(let extractor_traits_factory_parent (lambda '(list_type extractor factory) (block '(
(let traits (Apply factory (ListType (TypeOf (Apply extractor (InstanceOf (ListItemType list_type)))))))
- (let init (NthArg '1 traits))
- (let update (NthArg '2 traits))
- (let shift (NthArg '3 traits))
- (let current (NthArg '4 traits))
+ (let init (NthArg '1 traits))
+ (let update (NthArg '2 traits))
+ (let shift (NthArg '3 traits))
+ (let current (NthArg '4 traits))
(let defval (NthArg '5 traits))
- (let init_ext (lambda '(row parent) (Apply init (Apply extractor row) parent)))
- (let update_ext (lambda '(row state parent) (Apply update (Apply extractor row) state parent)))
- (let shift_ext (lambda '(row state) (Apply shift (Apply extractor row) state)))
+ (let init_ext (lambda '(row parent) (Apply init (Apply extractor row) parent)))
+ (let update_ext (lambda '(row state parent) (Apply update (Apply extractor row) state parent)))
+ (let shift_ext (lambda '(row state) (Apply shift (Apply extractor row) state)))
(return (WindowTraits (ListItemType list_type) init_ext update_ext shift_ext current defval))
-))))
-
-# list_type:type, extractor:lambda
-# support optional columns
-(let min_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor min_traits_factory_opt)))
-(let max_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor max_traits_factory_opt)))
-(let sum_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor sum_traits_factory_opt)))
-(let count_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor count_traits_factory_opt)))
-(let count_all_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor count_all_traits_factory_opt)))
-(let count_if_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor count_if_traits_factory_opt)))
-(let some_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor some_traits_factory_raw)))
-(let bit_and_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor bit_and_traits_factory_opt)))
-(let bit_or_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor bit_or_traits_factory_opt)))
-(let bit_xor_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor bit_xor_traits_factory_opt)))
+))))
+
+# list_type:type, extractor:lambda
+# support optional columns
+(let min_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor min_traits_factory_opt)))
+(let max_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor max_traits_factory_opt)))
+(let sum_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor sum_traits_factory_opt)))
+(let count_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor count_traits_factory_opt)))
+(let count_all_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor count_all_traits_factory_opt)))
+(let count_if_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor count_if_traits_factory_opt)))
+(let some_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor some_traits_factory_raw)))
+(let bit_and_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor bit_and_traits_factory_opt)))
+(let bit_or_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor bit_or_traits_factory_opt)))
+(let bit_xor_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor bit_xor_traits_factory_opt)))
(let and_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type (lambda '(v) (SafeCast (Apply extractor v) (DataType 'Bool))) bool_and_traits_factory_opt)))
(let or_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type (lambda '(v) (SafeCast (Apply extractor v) (DataType 'Bool))) bool_or_traits_factory_opt)))
(let xor_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type (lambda '(v) (SafeCast (Apply extractor v) (DataType 'Bool))) bool_xor_traits_factory_opt)))
-(let avg_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor avg_traits_factory_opt)))
+(let avg_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor avg_traits_factory_opt)))
(let list_traits_factory (lambda '(list_type extractor limit) (Apply extractor_traits_factory list_type extractor (Apply list_traits_factory_opt_gen limit (Null)))))
(let list2_traits_factory (lambda '(list_type extractor limit) (Apply extractor_traits_factory list_type extractor (Apply list_traits_factory_opt_gen limit empty_list))))
-(let variance_0_0_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor variance_0_0_traits_factory_opt)))
-(let variance_1_0_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor variance_1_0_traits_factory_opt)))
-(let variance_0_1_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor variance_0_1_traits_factory_opt)))
-(let variance_1_1_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor variance_1_1_traits_factory_opt)))
-
+(let variance_0_0_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor variance_0_0_traits_factory_opt)))
+(let variance_1_0_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor variance_1_0_traits_factory_opt)))
+(let variance_0_1_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor variance_0_1_traits_factory_opt)))
+(let variance_1_1_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor variance_1_1_traits_factory_opt)))
+
# TODO: rank_traits_factory and dense_rank_traits_factory are only used in v0 syntax
-(let rank_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor rank_traits_factory_opt)))
-(let dense_rank_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor dense_rank_traits_factory_opt)))
-
-(let first_value_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor first_value_traits_factory_opt)))
-(let last_value_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor last_value_traits_factory_opt)))
-(let first_value_ignore_nulls_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor first_value_ignore_nulls_traits_factory_opt)))
-(let last_value_ignore_nulls_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor last_value_ignore_nulls_traits_factory_opt)))
-
-# list_type:type extractor:lambda n:double
-# support optional values
+(let rank_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor rank_traits_factory_opt)))
+(let dense_rank_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor dense_rank_traits_factory_opt)))
+
+(let first_value_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor first_value_traits_factory_opt)))
+(let last_value_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor last_value_traits_factory_opt)))
+(let first_value_ignore_nulls_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor first_value_ignore_nulls_traits_factory_opt)))
+(let last_value_ignore_nulls_traits_factory (lambda '(list_type extractor) (Apply extractor_traits_factory list_type extractor last_value_ignore_nulls_traits_factory_opt)))
+
+# list_type:type extractor:lambda n:double
+# support optional values
(let percentile_traits_factory (lambda '(list_type extractor n) (Apply extractor_traits_factory_parent list_type extractor (lambda '(list_type) (Apply percentile_traits_factory_opt list_type n)))))
-
+
# list_type:type extractor:lambda count:ui32
# support optional values
(let set_traits_factory (lambda '(list_type extractor count) (Apply extractor_traits_factory_parent list_type extractor (lambda '(list_type) (Apply set_traits_factory_opt list_type count)))))
@@ -642,106 +642,106 @@
# support optional values
(let hyperloglog_traits_factory (lambda '(list_type extractor n) (Apply extractor_traits_factory_parent list_type extractor (lambda '(list_type) (Apply hyperloglog_traits_factory_opt list_type n)))))
-# list_type:type extractor:lambda init:lambda update:lambda shift:lambda current:lambda
-# support optional values
+# list_type:type extractor:lambda init:lambda update:lambda shift:lambda current:lambda
+# support optional values
(let udwf_traits_factory (lambda '(list_type extractor init update shift current defval) (Apply extractor_traits_factory_parent list_type extractor (lambda '(list_type) (Apply udwf_traits_factory_opt list_type init update shift current defval)))))
-
-# list_type:type compare:lambda first:lambda second:lambda stub
-# doesn't support optional values
-(let compare_traits_factory_raw (lambda '(list_type compare first second stub) (block '(
- (let key_type (TypeOf (Apply first (InstanceOf (ListItemType list_type)))))
- (let init (lambda '(row) '((Apply second row) (Apply first row))))
- (let update (lambda '(row state) (If (Apply compare (Apply first row) (Nth state '1)) (Apply init row) state)))
- (let shift (lambda '(row state) (lambda '(value state) (Void))))
- (let current (lambda '(state) (Nth state '0)))
+
+# list_type:type compare:lambda first:lambda second:lambda stub
+# doesn't support optional values
+(let compare_traits_factory_raw (lambda '(list_type compare first second stub) (block '(
+ (let key_type (TypeOf (Apply first (InstanceOf (ListItemType list_type)))))
+ (let init (lambda '(row) '((Apply second row) (Apply first row))))
+ (let update (lambda '(row state) (If (Apply compare (Apply first row) (Nth state '1)) (Apply init row) state)))
+ (let shift (lambda '(row state) (lambda '(value state) (Void))))
+ (let current (lambda '(state) (Nth state '0)))
(return (WindowTraits (ListItemType list_type) init update shift current (Null)))
-))))
-
-# list_type:type compare:lambda first:lambda second:lambda limit:Uint64
-# doesn't support optional values
-(let compare_traits_factory_list_raw (lambda '(list_type compare first second limit) (block '(
- (let key_type (TypeOf (Apply first (InstanceOf (ListItemType list_type)))))
- (let init (lambda '(row) '((AsList (Apply second row)) (Apply first row))))
+))))
+
+# list_type:type compare:lambda first:lambda second:lambda limit:Uint64
+# doesn't support optional values
+(let compare_traits_factory_list_raw (lambda '(list_type compare first second limit) (block '(
+ (let key_type (TypeOf (Apply first (InstanceOf (ListItemType list_type)))))
+ (let init (lambda '(row) '((AsList (Apply second row)) (Apply first row))))
(let update (lambda '(row state) (If (AggrEquals (Apply first row) (Nth state '1)) '((Take (Insert (Nth state '0) (Apply second row)) limit) (Nth state '1)) (If (Apply compare (Apply first row) (Nth state '1)) (Apply init row) state))))
- (let shift (lambda '(value state) (Void)))
- (let current (lambda '(state) (Nth state '0)))
+ (let shift (lambda '(value state) (Void)))
+ (let current (lambda '(state) (Nth state '0)))
(return (WindowTraits (ListItemType list_type) init update shift current (Null)))
-))))
-
-# factory:lambda list_type:type first:lambda second:lambda
-# support optional values
-(let double_traits_factory_opt (lambda '(factory list_type first second) (block '(
- (let item_type (ListItemType list_type))
- (let key_type (TypeOf (Apply first (InstanceOf item_type))))
+))))
+
+# factory:lambda list_type:type first:lambda second:lambda
+# support optional values
+(let double_traits_factory_opt (lambda '(factory list_type first second) (block '(
+ (let item_type (ListItemType list_type))
+ (let key_type (TypeOf (Apply first (InstanceOf item_type))))
(let test_type (MatchType item_type 'Optional (lambda '() item_type) (lambda '() key_type)))
(let traits (Apply factory (ListType (MatchType item_type 'Optional (lambda '() (OptionalItemType item_type)) (lambda '() item_type)))
- (lambda '(row) (MatchType key_type 'Optional
- (lambda '() (Unwrap (Apply first row)))
- (lambda '() (Apply first row))
- ))
- second
- ))
- (let init (NthArg '1 traits))
- (let update (NthArg '2 traits))
- (let shift (NthArg '3 traits))
- (let current (NthArg '4 traits))
+ (lambda '(row) (MatchType key_type 'Optional
+ (lambda '() (Unwrap (Apply first row)))
+ (lambda '() (Apply first row))
+ ))
+ second
+ ))
+ (let init (NthArg '1 traits))
+ (let update (NthArg '2 traits))
+ (let shift (NthArg '3 traits))
+ (let current (NthArg '4 traits))
(let defval (NthArg '5 traits))
-
- (let init_opt (lambda '(row) (MatchType test_type 'Optional
- (lambda '() (Map (Apply first row) (lambda '(key) (Apply init row))))
- (lambda '() (Apply init row))
- )))
- (let update_opt (lambda '(row state)
- (MatchType test_type 'Optional
- (lambda '() (IfPresent state (lambda '(state) (Just (If (Exists (Apply first row)) (Apply update row state) state))) (Apply init_opt row)))
- (lambda '() (Apply update row state))
- )
- ))
- (let shift_opt (lambda '(value state) (Void)))
- (let current_opt (lambda '(state) (MatchType test_type 'Optional
- (lambda '() (MatchType (TypeOf (Apply current (InstanceOf (OptionalItemType (TypeOf state))))) 'Optional
- (lambda '() (FlatMap state current))
- (lambda '() (Map state current))
- ))
- (lambda '() (Apply current state))
- )))
+
+ (let init_opt (lambda '(row) (MatchType test_type 'Optional
+ (lambda '() (Map (Apply first row) (lambda '(key) (Apply init row))))
+ (lambda '() (Apply init row))
+ )))
+ (let update_opt (lambda '(row state)
+ (MatchType test_type 'Optional
+ (lambda '() (IfPresent state (lambda '(state) (Just (If (Exists (Apply first row)) (Apply update row state) state))) (Apply init_opt row)))
+ (lambda '() (Apply update row state))
+ )
+ ))
+ (let shift_opt (lambda '(value state) (Void)))
+ (let current_opt (lambda '(state) (MatchType test_type 'Optional
+ (lambda '() (MatchType (TypeOf (Apply current (InstanceOf (OptionalItemType (TypeOf state))))) 'Optional
+ (lambda '() (FlatMap state current))
+ (lambda '() (Map state current))
+ ))
+ (lambda '() (Apply current state))
+ )))
(return (WindowTraits item_type init_opt update_opt shift_opt current_opt defval))
-))))
-
-# factory:lambda list_type:type first:lambda second:lambda
-# support optional values, init and update has parent arg
-(let double_traits_factory_opt_parent (lambda '(factory list_type first second) (block '(
- (let item_type (ListItemType list_type))
- (let key_type (TypeOf (Apply first (InstanceOf item_type))))
+))))
+
+# factory:lambda list_type:type first:lambda second:lambda
+# support optional values, init and update has parent arg
+(let double_traits_factory_opt_parent (lambda '(factory list_type first second) (block '(
+ (let item_type (ListItemType list_type))
+ (let key_type (TypeOf (Apply first (InstanceOf item_type))))
(let test_type (MatchType item_type 'Optional (lambda '() item_type) (lambda '() key_type)))
(let traits (Apply factory (ListType (MatchType item_type 'Optional (lambda '() (OptionalItemType item_type)) (lambda '() item_type)))
- (lambda '(row) (MatchType key_type 'Optional
- (lambda '() (Unwrap (Apply first row)))
- (lambda '() (Apply first row))
- ))
- second
- ))
- (let init (NthArg '1 traits))
- (let update (NthArg '2 traits))
- (let shift (NthArg '3 traits))
- (let current (NthArg '4 traits))
+ (lambda '(row) (MatchType key_type 'Optional
+ (lambda '() (Unwrap (Apply first row)))
+ (lambda '() (Apply first row))
+ ))
+ second
+ ))
+ (let init (NthArg '1 traits))
+ (let update (NthArg '2 traits))
+ (let shift (NthArg '3 traits))
+ (let current (NthArg '4 traits))
(let defval (NthArg '5 traits))
-
- (let init_opt (lambda '(row parent) (MatchType test_type 'Optional
- (lambda '() (Map (Apply first row) (lambda '(key) (Apply init row parent))))
- (lambda '() (Apply init row parent))
- )))
- (let update_opt (lambda '(row state parent)
- (MatchType test_type 'Optional
- (lambda '() (IfPresent state (lambda '(state) (Just (If (Exists (Apply first row)) (Apply update row state parent) state))) (Apply init_opt row parent)))
- (lambda '() (Apply update row state parent))
- )
- ))
- (let shift_opt (lambda '(value state) (Void)))
- (let current_opt (lambda '(state) (MatchType test_type 'Optional (lambda '() (Map state current)) (lambda '() (Apply current state)))))
+
+ (let init_opt (lambda '(row parent) (MatchType test_type 'Optional
+ (lambda '() (Map (Apply first row) (lambda '(key) (Apply init row parent))))
+ (lambda '() (Apply init row parent))
+ )))
+ (let update_opt (lambda '(row state parent)
+ (MatchType test_type 'Optional
+ (lambda '() (IfPresent state (lambda '(state) (Just (If (Exists (Apply first row)) (Apply update row state parent) state))) (Apply init_opt row parent)))
+ (lambda '() (Apply update row state parent))
+ )
+ ))
+ (let shift_opt (lambda '(value state) (Void)))
+ (let current_opt (lambda '(state) (MatchType test_type 'Optional (lambda '() (Map state current)) (lambda '() (Apply current state)))))
(return (WindowTraits item_type init_opt update_opt shift_opt current_opt defval))
-))))
-
+))))
+
# factory:lambda list_type:type first:lambda second:lambda
# support optional values, init and update has parent arg
(let list_by_traits_factory_opt_parent (lambda '(factory list_type first second) (block '(
@@ -785,14 +785,14 @@
(return (WindowTraits item_type init_opt update_opt shift_opt current_opt defval))
))))
-# list_type:type value:lambda weight:lambda intervals:integer
-# support optional values
-(let histogram_adaptive_ward_traits_factory (lambda '(list_type value weight intervals) (Apply double_traits_factory_opt_parent (lambda '(list_type value weight) (Apply histogram_adaptive_ward_traits_factory_raw list_type value weight intervals)) list_type value weight)))
-(let histogram_adaptive_weight_traits_factory (lambda '(list_type value weight intervals) (Apply double_traits_factory_opt_parent (lambda '(list_type value weight) (Apply histogram_adaptive_weight_traits_factory_raw list_type value weight intervals)) list_type value weight)))
-(let histogram_adaptive_distance_traits_factory (lambda '(list_type value weight intervals) (Apply double_traits_factory_opt_parent (lambda '(list_type value weight) (Apply histogram_adaptive_distance_traits_factory_raw list_type value weight intervals)) list_type value weight)))
-(let histogram_block_ward_traits_factory (lambda '(list_type value weight intervals) (Apply double_traits_factory_opt_parent (lambda '(list_type value weight) (Apply histogram_block_ward_traits_factory_raw list_type value weight intervals)) list_type value weight)))
-(let histogram_block_weight_traits_factory (lambda '(list_type value weight intervals) (Apply double_traits_factory_opt_parent (lambda '(list_type value weight) (Apply histogram_block_weight_traits_factory_raw list_type value weight intervals)) list_type value weight)))
-
+# list_type:type value:lambda weight:lambda intervals:integer
+# support optional values
+(let histogram_adaptive_ward_traits_factory (lambda '(list_type value weight intervals) (Apply double_traits_factory_opt_parent (lambda '(list_type value weight) (Apply histogram_adaptive_ward_traits_factory_raw list_type value weight intervals)) list_type value weight)))
+(let histogram_adaptive_weight_traits_factory (lambda '(list_type value weight intervals) (Apply double_traits_factory_opt_parent (lambda '(list_type value weight) (Apply histogram_adaptive_weight_traits_factory_raw list_type value weight intervals)) list_type value weight)))
+(let histogram_adaptive_distance_traits_factory (lambda '(list_type value weight intervals) (Apply double_traits_factory_opt_parent (lambda '(list_type value weight) (Apply histogram_adaptive_distance_traits_factory_raw list_type value weight intervals)) list_type value weight)))
+(let histogram_block_ward_traits_factory (lambda '(list_type value weight intervals) (Apply double_traits_factory_opt_parent (lambda '(list_type value weight) (Apply histogram_block_ward_traits_factory_raw list_type value weight intervals)) list_type value weight)))
+(let histogram_block_weight_traits_factory (lambda '(list_type value weight intervals) (Apply double_traits_factory_opt_parent (lambda '(list_type value weight) (Apply histogram_block_weight_traits_factory_raw list_type value weight intervals)) list_type value weight)))
+
# list_type:type value:lambda weight:lambda intervals:integer
# support optional values
(let histogram_linear_traits_factory (lambda '(list_type value binsize minimum maximum) (Apply double_traits_factory_opt_parent (lambda '(list_type value binsize) (Apply histogram_linear_traits_factory_raw list_type value binsize minimum maximum)) list_type value binsize)))
@@ -800,13 +800,13 @@
(let compare_by_traits_factory_opt (lambda '(list_type compare first second limit) (Apply double_traits_factory_opt (lambda '(list_type first second) (Apply compare_traits_factory_raw list_type compare first second limit)) list_type first second)))
(let list_compare_by_traits_factory_opt (lambda '(list_type compare first second limit) (Apply double_traits_factory_opt (lambda '(list_type first second) (Apply compare_traits_factory_list_raw list_type compare first second limit)) list_type first second)))
-
+
#deprecated
-(let compare_by_traits_factory (lambda '(list_type compare first second limit) (IfType limit (VoidType)
+(let compare_by_traits_factory (lambda '(list_type compare first second limit) (IfType limit (VoidType)
(lambda '() (Apply compare_by_traits_factory_opt list_type compare first second limit))
(lambda '() (Apply list_compare_by_traits_factory_opt list_type compare first second limit))
-)))
-
+)))
+
#deprecated
(let min_by_traits_factory (lambda '(list_type first second limit) (Apply compare_by_traits_factory list_type (lambda '(one two) (AggrLess one two)) first second limit)))
(let max_by_traits_factory (lambda '(list_type first second limit) (Apply compare_by_traits_factory list_type (lambda '(one two) (AggrLess two one)) first second limit)))
@@ -825,7 +825,7 @@
(Apply sum_traits_factory list_type (lambda '(value) (FlatOptionalIf (Coalesce (Apply predicate value) (Bool '0)) (block '(
(let pl (Apply payload value))
(return (MatchType pl 'Optional (lambda '() pl) (lambda '() (Just pl)))))))))))
-
+
# list_type:type init:lambda update:lambda finish:lambda
# support optional values
(let udaf_traits_factory_opt (lambda '(list_type init update finish defval) (Apply optional_traits_factory_parent list_type (lambda '(list_type) (WindowTraits (ListItemType list_type) init update (lambda '(value state) (Void)) finish defval)))))
@@ -853,59 +853,59 @@
(let bottom_by_traits_factory (lambda '(list_type key_extractor payload_extractor count)
(Apply top_bottom_by_traits_factory list_type key_extractor payload_extractor count '0)))
-(export min_traits_factory)
-(export max_traits_factory)
-(export sum_traits_factory)
+(export min_traits_factory)
+(export max_traits_factory)
+(export sum_traits_factory)
(export sum_if_traits_factory)
-(export count_traits_factory)
-(export count_all_traits_factory)
-(export count_if_traits_factory)
-(export some_traits_factory)
-(export bit_and_traits_factory)
-(export bit_or_traits_factory)
-(export bit_xor_traits_factory)
-(export and_traits_factory)
-(export or_traits_factory)
-(export xor_traits_factory)
-(export avg_traits_factory)
+(export count_traits_factory)
+(export count_all_traits_factory)
+(export count_if_traits_factory)
+(export some_traits_factory)
+(export bit_and_traits_factory)
+(export bit_or_traits_factory)
+(export bit_xor_traits_factory)
+(export and_traits_factory)
+(export or_traits_factory)
+(export xor_traits_factory)
+(export avg_traits_factory)
(export avg_if_traits_factory)
-(export list_traits_factory)
+(export list_traits_factory)
(export list2_traits_factory)
-(export min_by_traits_factory)
-(export max_by_traits_factory)
+(export min_by_traits_factory)
+(export max_by_traits_factory)
(export min_by_traits_factory1)
(export max_by_traits_factory1)
(export min_by_traits_factory2)
(export max_by_traits_factory2)
-(export variance_0_0_traits_factory)
-(export variance_1_0_traits_factory)
-(export variance_0_1_traits_factory)
-(export variance_1_1_traits_factory)
+(export variance_0_0_traits_factory)
+(export variance_1_0_traits_factory)
+(export variance_0_1_traits_factory)
+(export variance_1_1_traits_factory)
(export correlation_traits_factory)
(export covariance_population_traits_factory)
(export covariance_sample_traits_factory)
-(export histogram_adaptive_ward_traits_factory)
-(export histogram_adaptive_weight_traits_factory)
-(export histogram_adaptive_distance_traits_factory)
-(export histogram_block_ward_traits_factory)
-(export histogram_block_weight_traits_factory)
+(export histogram_adaptive_ward_traits_factory)
+(export histogram_adaptive_weight_traits_factory)
+(export histogram_adaptive_distance_traits_factory)
+(export histogram_block_ward_traits_factory)
+(export histogram_block_weight_traits_factory)
(export histogram_linear_traits_factory)
(export histogram_logarithmic_traits_factory)
-(export udwf_traits_factory)
-(export percentile_traits_factory)
+(export udwf_traits_factory)
+(export percentile_traits_factory)
(export set_traits_factory)
(export topfreq_traits_factory)
(export hyperloglog_traits_factory)
-(export rank_traits_factory)
-(export dense_rank_traits_factory)
-(export first_value_traits_factory)
-(export last_value_traits_factory)
-(export first_value_ignore_nulls_traits_factory)
-(export last_value_ignore_nulls_traits_factory)
+(export rank_traits_factory)
+(export dense_rank_traits_factory)
+(export first_value_traits_factory)
+(export last_value_traits_factory)
+(export first_value_ignore_nulls_traits_factory)
+(export last_value_ignore_nulls_traits_factory)
(export udaf_traits_factory)
(export top_traits_factory)
(export bottom_traits_factory)
(export top_by_traits_factory)
(export bottom_by_traits_factory)
-
-)
+
+)
diff --git a/ydb/library/yql/parser/proto_ast/proto_ast.h b/ydb/library/yql/parser/proto_ast/proto_ast.h
index e3e18a505c..5bb8a9f5f9 100644
--- a/ydb/library/yql/parser/proto_ast/proto_ast.h
+++ b/ydb/library/yql/parser/proto_ast/proto_ast.h
@@ -71,7 +71,7 @@ namespace NProtoAST {
public:
TProtoASTBuilder(TStringBuf data, const TString& queryName = "query", google::protobuf::Arena* arena = nullptr)
: QueryName(queryName)
- , InputStream((const TChar*)data.data(), antlr3::ENC_8BIT, data.length(), (TChar*)QueryName.begin()) // Why the hell antlr needs non-const ptr??
+ , InputStream((const TChar*)data.data(), antlr3::ENC_8BIT, data.length(), (TChar*)QueryName.begin()) // Why the hell antlr needs non-const ptr??
, Lexer(&InputStream, static_cast<google::protobuf::Arena*>(nullptr))
, TokenStream(ANTLR_SIZE_HINT, Lexer.get_tokSource())
, Parser(&TokenStream, arena)
diff --git a/ydb/library/yql/providers/common/mkql/yql_provider_mkql.cpp b/ydb/library/yql/providers/common/mkql/yql_provider_mkql.cpp
index 15fbee54d6..dd1f162d78 100644
--- a/ydb/library/yql/providers/common/mkql/yql_provider_mkql.cpp
+++ b/ydb/library/yql/providers/common/mkql/yql_provider_mkql.cpp
@@ -977,16 +977,16 @@ TMkqlCommonCallableCompiler::TShared::TShared() {
return MkqlBuildSplitLambda(*node.Child(2), ctx, {item, state});
});
});
-
+
AddCallable("Fold1Map", [](const TExprNode& node, TMkqlBuildContext& ctx) {
const auto list = MkqlBuildExpr(node.Head(), ctx);
return ctx.ProgramBuilder.Chain1Map(list, [&](TRuntimeNode item) {
return MkqlBuildSplitLambda(*node.Child(1), ctx, {item});
- }, [&](TRuntimeNode item, TRuntimeNode state) {
+ }, [&](TRuntimeNode item, TRuntimeNode state) {
return MkqlBuildSplitLambda(*node.Child(2), ctx, {item, state});
});
- });
-
+ });
+
AddCallable("Chain1Map", [](const TExprNode& node, TMkqlBuildContext& ctx) {
const auto list = MkqlBuildExpr(node.Head(), ctx);
return ctx.ProgramBuilder.Chain1Map(list,
@@ -2235,15 +2235,15 @@ TMkqlCommonCallableCompiler::TShared::TShared() {
const auto& args = GetArgumentsFrom<3U>(node, ctx);
const auto returnType = BuildType(node, *node.GetTypeAnn(), ctx.ProgramBuilder);
return ctx.ProgramBuilder.QueueCreate(initCapacity, initSize, args, returnType);
- });
-
+ });
+
AddCallable("QueuePeek", [](const TExprNode& node, TMkqlBuildContext& ctx) {
const auto resource = MkqlBuildExpr(node.Head(), ctx);
const auto index = MkqlBuildExpr(*node.Child(1), ctx);
const auto& args = GetArgumentsFrom<2U>(node, ctx);
const auto returnType = BuildType(node, *node.GetTypeAnn(), ctx.ProgramBuilder);
return ctx.ProgramBuilder.QueuePeek(resource, index, args, returnType);
- });
+ });
AddCallable("QueueRange", [](const TExprNode& node, TMkqlBuildContext& ctx) {
const auto resource = MkqlBuildExpr(node.Head(), ctx);
@@ -2264,16 +2264,16 @@ TMkqlCommonCallableCompiler::TShared::TShared() {
const auto input = MkqlBuildExpr(node.Head(), ctx);
const auto schemeType = ParseDataType(node, node.Child(1)->Content());
return ctx.ProgramBuilder.FromYsonSimpleType(input, schemeType);
- });
-
+ });
+
AddCallable("TryWeakMemberFromDict", [](const TExprNode& node, TMkqlBuildContext& ctx) {
const auto other = MkqlBuildExpr(node.Head(), ctx);
const auto rest = MkqlBuildExpr(*node.Child(1), ctx);
const auto schemeType = ParseDataType(node, node.Child(2)->Content());
const auto member = node.Child(3)->Content();
return ctx.ProgramBuilder.TryWeakMemberFromDict(other, rest, schemeType, member);
- });
-
+ });
+
AddCallable("DependsOn", [](const TExprNode& node, TMkqlBuildContext& ctx) {
return MkqlBuildExpr(node.Head(), ctx);
});
diff --git a/ydb/library/yql/providers/common/provider/yql_provider_names.h b/ydb/library/yql/providers/common/provider/yql_provider_names.h
index ad7d26fc62..7cf29b4c1d 100644
--- a/ydb/library/yql/providers/common/provider/yql_provider_names.h
+++ b/ydb/library/yql/providers/common/provider/yql_provider_names.h
@@ -1,6 +1,6 @@
#pragma once
-#include <array>
+#include <array>
#include <util/generic/strbuf.h>
namespace NYql {
@@ -23,5 +23,5 @@ constexpr std::array<const TStringBuf, 11> Providers = {
StatProviderName, SolomonProviderName, DqProviderName, ClickHouseProviderName, YdbProviderName,
PqProviderName}
};
-
+
} // namespace NYql
diff --git a/ydb/library/yql/providers/config/yql_config_provider.cpp b/ydb/library/yql/providers/config/yql_config_provider.cpp
index 41bf7cf3ff..6952e96cf0 100644
--- a/ydb/library/yql/providers/config/yql_config_provider.cpp
+++ b/ydb/library/yql/providers/config/yql_config_provider.cpp
@@ -223,7 +223,7 @@ namespace {
return res;
}
if (!EnsureAtom(*node->Child(i), ctx)) {
- return {};
+ return {};
}
args.push_back(node->Child(i)->Content());
}
@@ -989,7 +989,7 @@ namespace {
}
private:
- TTypeAnnotationContext& Types;
+ TTypeAnnotationContext& Types;
TAutoPtr<IGraphTransformer> TypeAnnotationTransformer;
TAutoPtr<IGraphTransformer> ConfigurationTransformer;
TAutoPtr<IGraphTransformer> CallableExecutionTransformer;
diff --git a/ydb/library/yql/public/issue/ya.make b/ydb/library/yql/public/issue/ya.make
index f318729f78..04a84bee88 100644
--- a/ydb/library/yql/public/issue/ya.make
+++ b/ydb/library/yql/public/issue/ya.make
@@ -23,7 +23,7 @@ PEERDIR(
)
GENERATE_ENUM_SERIALIZATION(yql_warning.h)
-
+
END()
RECURSE_FOR_TESTS(
diff --git a/ydb/library/yql/public/issue/yql_issue_manager.cpp b/ydb/library/yql/public/issue/yql_issue_manager.cpp
index 3dcae403ab..7375d2d30f 100644
--- a/ydb/library/yql/public/issue/yql_issue_manager.cpp
+++ b/ydb/library/yql/public/issue/yql_issue_manager.cpp
@@ -1,8 +1,8 @@
#include "yql_issue_manager.h"
-#include <util/string/cast.h>
+#include <util/string/cast.h>
#include <util/string/builder.h>
-
+
using namespace NYql;
void TIssueManager::AddScope(std::function<TIssuePtr()> fn) {
@@ -126,9 +126,9 @@ bool TIssueManager::RaiseWarning(TIssue issue) {
if (issue.GetSeverity() == ESeverity::TSeverityIds_ESeverityId_S_WARNING) {
const auto action = WarningPolicy_.GetAction(issue.GetCode());
switch (action) {
- case EWarningAction::DISABLE:
+ case EWarningAction::DISABLE:
return isWarning;
- case EWarningAction::ERROR:
+ case EWarningAction::ERROR:
issue.Severity = ESeverity::TSeverityIds_ESeverityId_S_ERROR;
if (WarningToErrorTreatMessage_) {
TIssue newIssue;
diff --git a/ydb/library/yql/public/udf/udf_helpers.h b/ydb/library/yql/public/udf/udf_helpers.h
index c0483f5491..2be9443559 100644
--- a/ydb/library/yql/public/udf/udf_helpers.h
+++ b/ydb/library/yql/public/udf/udf_helpers.h
@@ -5,7 +5,7 @@
#include "udf_value_builder.h"
#include "udf_terminator.h"
#include "udf_type_builder.h"
-#include "udf_type_inspection.h"
+#include "udf_type_inspection.h"
#include "udf_version.h"
#include <util/generic/yexception.h>
@@ -213,16 +213,16 @@ namespace NUdf {
template<bool CheckOptional, const char* TFuncName, template<class> class TFunc, typename... TUserTypes>
class TUserDataTypeFuncFactory : public ::NYql::NUdf::TBoxedValue {
-public:
+public:
typedef bool TTypeAwareMarker;
public:
static const ::NYql::NUdf::TStringRef& Name() {
static auto name = ::NYql::NUdf::TStringRef(TFuncName, std::strlen(TFuncName));
- return name;
- }
-
- template<typename TUserType>
+ return name;
+ }
+
+ template<typename TUserType>
static bool DeclareSignatureImpl(
TDataTypeId typeId,
::NYql::NUdf::TType* userType,
@@ -230,13 +230,13 @@ public:
bool typesOnly)
{
if (TDataType<TUserType>::Id != typeId) {
- return false;
- }
+ return false;
+ }
TFunc<TUserType>::DeclareSignature(userType, builder, typesOnly);
- return true;
- }
-
- template<typename TUserType, typename THead, typename... TTail>
+ return true;
+ }
+
+ template<typename TUserType, typename THead, typename... TTail>
static bool DeclareSignatureImpl(
TDataTypeId typeId,
::NYql::NUdf::TType* userType,
@@ -244,21 +244,21 @@ public:
bool typesOnly)
{
if (DeclareSignatureImpl<TUserType>(typeId, userType, builder, typesOnly)) {
- return true;
- }
+ return true;
+ }
return DeclareSignatureImpl<THead, TTail...>(typeId, userType, builder, typesOnly);
- }
-
- static bool DeclareSignature(
+ }
+
+ static bool DeclareSignature(
const ::NYql::NUdf::TStringRef& name,
::NYql::NUdf::TType* userType,
::NYql::NUdf::IFunctionTypeInfoBuilder& builder,
bool typesOnly)
- {
+ {
if (Name() != name) {
// the only case when we return false
- return false;
- }
+ return false;
+ }
if (!userType) {
builder.SetError("User type is not specified");
@@ -270,7 +270,7 @@ public:
if (!userTypeInspector || userTypeInspector.GetElementsCount() < 1) {
builder.SetError("Missing or invalid user type");
return true;
- }
+ }
auto argsTypeInspector = TTupleTypeInspector(*typeHelper, userTypeInspector.GetElementType(0));
if (!argsTypeInspector || argsTypeInspector.GetElementsCount() < 1) {
@@ -302,9 +302,9 @@ public:
}
return true;
- }
-};
-
+ }
+};
+
template<typename... TUdfs>
class TSimpleUdfModuleHelper : public IUdfModule
{
@@ -338,7 +338,7 @@ public:
{
Y_UNUSED(typeConfig);
bool typesOnly = (flags & TFlags::TypesOnly);
- return TUdfType::DeclareSignature(name, userType, builder, typesOnly);
+ return TUdfType::DeclareSignature(name, userType, builder, typesOnly);
}
template<typename THead1, typename THead2, typename... TTail>
diff --git a/ydb/library/yql/sql/v0/SQL.g b/ydb/library/yql/sql/v0/SQL.g
index 069a5aa96c..3b616b9c9f 100644
--- a/ydb/library/yql/sql/v0/SQL.g
+++ b/ydb/library/yql/sql/v0/SQL.g
@@ -1,43 +1,43 @@
grammar SQL;
options {
- language = Cpp;
- k = 4;
- memoize=true;
+ language = Cpp;
+ k = 4;
+ memoize=true;
}
// Input is a list of statements.
-sql_stmt_list: sql_stmt (SEMI sql_stmt)* SEMI? EOF;
-
-lambda_body: (lambda_stmt SEMI)* RETURN expr SEMI?;
-lambda_stmt:
- named_nodes_stmt
- | import_stmt
-;
-
+sql_stmt_list: sql_stmt (SEMI sql_stmt)* SEMI? EOF;
+
+lambda_body: (lambda_stmt SEMI)* RETURN expr SEMI?;
+lambda_stmt:
+ named_nodes_stmt
+ | import_stmt
+;
+
sql_stmt: (EXPLAIN (Q U E R Y PLAN)?)? sql_stmt_core;
-sql_stmt_core:
- pragma_stmt
+sql_stmt_core:
+ pragma_stmt
| select_stmt
- | named_nodes_stmt
+ | named_nodes_stmt
| create_table_stmt
| drop_table_stmt
| use_stmt
- | into_table_stmt
+ | into_table_stmt
| commit_stmt
- | update_stmt
- | delete_stmt
+ | update_stmt
+ | delete_stmt
| rollback_stmt
- | declare_stmt
- | import_stmt
- | export_stmt
+ | declare_stmt
+ | import_stmt
+ | export_stmt
| alter_table_stmt
| do_stmt
| define_action_or_subquery_stmt
| evaluate_if_stmt
| evaluate_for_stmt
-;
+;
expr: or_subexpr (OR or_subexpr)*;
@@ -47,19 +47,19 @@ and_subexpr: xor_subexpr (XOR xor_subexpr)*;
xor_subexpr: eq_subexpr cond_expr?;
-cond_expr:
- NOT? match_op eq_subexpr (ESCAPE eq_subexpr)?
+cond_expr:
+ NOT? match_op eq_subexpr (ESCAPE eq_subexpr)?
| NOT? IN COMPACT? in_expr
| (ISNULL | NOTNULL | IS NULL | (IS)? NOT NULL)
| NOT? BETWEEN eq_subexpr AND eq_subexpr
| ((EQUALS | EQUALS2 | NOT_EQUALS | NOT_EQUALS2) eq_subexpr)+ /* order of the eq subexpressions is reversed! */
-;
+;
match_op: LIKE | ILIKE | GLOB | REGEXP | RLIKE | MATCH;
eq_subexpr: neq_subexpr ((LESS | LESS_OR_EQ | GREATER | GREATER_OR_EQ) neq_subexpr)*;
-neq_subexpr: bit_subexpr ((SHIFT_LEFT | SHIFT_RIGHT | ROT_LEFT | ROT_RIGHT | AMPERSAND | PIPE | CARET) bit_subexpr)* (DOUBLE_QUESTION neq_subexpr)?;
+neq_subexpr: bit_subexpr ((SHIFT_LEFT | SHIFT_RIGHT | ROT_LEFT | ROT_RIGHT | AMPERSAND | PIPE | CARET) bit_subexpr)* (DOUBLE_QUESTION neq_subexpr)?;
bit_subexpr: add_subexpr ((PLUS | MINUS) add_subexpr)*;
@@ -75,17 +75,17 @@ unary_subexpr: (id_expr | atom_expr ) key_expr* (DOT (bind_parameter | D
in_unary_subexpr: (in_id_expr | in_atom_expr) key_expr* (DOT (bind_parameter | DIGITS | id_or_string) key_expr*)* (COLLATE id)?;
-atom_expr:
- literal_value
+atom_expr:
+ literal_value
| bind_parameter
- | window_function
- | lambda
+ | window_function
+ | lambda
| cast_expr
| exists_expr
| case_expr
| id_or_string NAMESPACE id_or_string
| bitcast_expr
-;
+;
in_atom_expr:
literal_value
@@ -106,163 +106,163 @@ exists_expr: EXISTS LPAREN select_stmt RPAREN;
case_expr: CASE expr? when_expr+ (ELSE expr)? END;
-lambda: smart_parenthesis (ARROW LBRACE_CURLY lambda_body RBRACE_CURLY)?;
-
+lambda: smart_parenthesis (ARROW LBRACE_CURLY lambda_body RBRACE_CURLY)?;
+
in_expr: in_unary_subexpr;
-
-// struct, tuple or named list
-smart_parenthesis: LPAREN named_expr_list? COMMA? RPAREN;
-
-expr_list: expr (COMMA expr)*;
-
-pure_column_list: LPAREN id_or_string (COMMA id_or_string)* RPAREN;
-
+
+// struct, tuple or named list
+smart_parenthesis: LPAREN named_expr_list? COMMA? RPAREN;
+
+expr_list: expr (COMMA expr)*;
+
+pure_column_list: LPAREN id_or_string (COMMA id_or_string)* RPAREN;
+
pure_column_or_named: bind_parameter | id_or_string;
pure_column_or_named_list: LPAREN pure_column_or_named (COMMA pure_column_or_named)* RPAREN;
-column_name: opt_id_prefix id_or_string;
-
-column_list: column_name (COMMA column_name)*;
-
-named_expr: expr (AS id_or_string)?;
-
-named_expr_list: named_expr (COMMA named_expr)*;
-
-named_column: column_name (AS id_or_string)?;
-
-named_column_list: named_column (COMMA named_column)*;
-
-call_expr: ((id_or_string NAMESPACE id_or_string) | id_expr | bind_parameter) LPAREN (opt_set_quantifier named_expr_list COMMA? | ASTERISK)? RPAREN;
-
+column_name: opt_id_prefix id_or_string;
+
+column_list: column_name (COMMA column_name)*;
+
+named_expr: expr (AS id_or_string)?;
+
+named_expr_list: named_expr (COMMA named_expr)*;
+
+named_column: column_name (AS id_or_string)?;
+
+named_column_list: named_column (COMMA named_column)*;
+
+call_expr: ((id_or_string NAMESPACE id_or_string) | id_expr | bind_parameter) LPAREN (opt_set_quantifier named_expr_list COMMA? | ASTERISK)? RPAREN;
+
in_call_expr: ((id_or_string NAMESPACE id_or_string) | in_id_expr | bind_parameter) LPAREN (opt_set_quantifier named_expr_list COMMA? | ASTERISK)? RPAREN;
-key_expr: LBRACE_CURLY expr RBRACE_CURLY;
+key_expr: LBRACE_CURLY expr RBRACE_CURLY;
when_expr: WHEN expr THEN expr;
-literal_value:
- integer
- | real
+literal_value:
+ integer
+ | real
| STRING
- | BLOB // it's unused right now
+ | BLOB // it's unused right now
| NULL
- | CURRENT_TIME // it's unused right now
- | CURRENT_DATE // it's unused right now
- | CURRENT_TIMESTAMP // it's unused right now
+ | CURRENT_TIME // it's unused right now
+ | CURRENT_DATE // it's unused right now
+ | CURRENT_TIMESTAMP // it's unused right now
| bool_value
| EMPTY_ACTION
-;
+;
-bind_parameter: DOLLAR id;
+bind_parameter: DOLLAR id;
-bind_parameter_list: bind_parameter (COMMA bind_parameter)*;
-named_bind_parameter: bind_parameter (AS bind_parameter)?;
-named_bind_parameter_list: named_bind_parameter (COMMA named_bind_parameter)*;
-
-unsigned_number: integer | real;
-signed_number: (PLUS | MINUS)? (integer | real);
+bind_parameter_list: bind_parameter (COMMA bind_parameter)*;
+named_bind_parameter: bind_parameter (AS bind_parameter)?;
+named_bind_parameter_list: named_bind_parameter (COMMA named_bind_parameter)*;
+
+unsigned_number: integer | real;
+signed_number: (PLUS | MINUS)? (integer | real);
type_name: id (LPAREN integer (COMMA integer)? RPAREN)?;
flex_type: STRING | type_name;
-
-declare_stmt: DECLARE bind_parameter AS flex_type (EQUALS literal_value)?;
-
-module_path: DOT? id (DOT id)*;
-import_stmt: IMPORT module_path SYMBOLS named_bind_parameter_list;
-export_stmt: EXPORT bind_parameter_list;
-
+
+declare_stmt: DECLARE bind_parameter AS flex_type (EQUALS literal_value)?;
+
+module_path: DOT? id (DOT id)*;
+import_stmt: IMPORT module_path SYMBOLS named_bind_parameter_list;
+export_stmt: EXPORT bind_parameter_list;
+
do_stmt: DO (bind_parameter | EMPTY_ACTION) LPAREN expr_list? RPAREN;
-pragma_stmt: PRAGMA opt_id_prefix id_or_string (EQUALS pragma_value | LPAREN pragma_value (COMMA pragma_value)* RPAREN)?;
+pragma_stmt: PRAGMA opt_id_prefix id_or_string (EQUALS pragma_value | LPAREN pragma_value (COMMA pragma_value)* RPAREN)?;
-pragma_value:
- signed_number
- | id
- | STRING
- | bool_value
+pragma_value:
+ signed_number
+ | id
+ | STRING
+ | bool_value
| bind_parameter
-;
+;
+
+/// TODO: NULLS FIRST\LAST?
+sort_specification: expr (ASC | DESC)?;
-/// TODO: NULLS FIRST\LAST?
-sort_specification: expr (ASC | DESC)?;
+sort_specification_list: sort_specification (COMMA sort_specification)*;
-sort_specification_list: sort_specification (COMMA sort_specification)*;
-
-select_stmt: select_kind_parenthesis (select_op select_kind_parenthesis)*;
+select_stmt: select_kind_parenthesis (select_op select_kind_parenthesis)*;
-select_kind_parenthesis: select_kind_partial | LPAREN select_kind_partial RPAREN;
+select_kind_parenthesis: select_kind_partial | LPAREN select_kind_partial RPAREN;
select_op: UNION (ALL)? | INTERSECT | EXCEPT;
-select_kind_partial: select_kind
+select_kind_partial: select_kind
(LIMIT expr ((OFFSET | COMMA) expr)?)?
- ;
-
+ ;
+
select_kind: (DISCARD)? (process_core | reduce_core | select_core) (INTO RESULT pure_column_or_named)?;
-process_core:
+process_core:
PROCESS STREAM? named_single_source (COMMA named_single_source)* (USING call_expr (AS id_or_string)?
(WHERE expr)? (HAVING expr)?)?
;
-reduce_core:
+reduce_core:
REDUCE named_single_source (COMMA named_single_source)* (PRESORT sort_specification_list)?
- ON column_list USING ALL? call_expr (AS id_or_string)?
- (WHERE expr)? (HAVING expr)?
-;
-
-opt_set_quantifier: (ALL | DISTINCT)?;
-
+ ON column_list USING ALL? call_expr (AS id_or_string)?
+ (WHERE expr)? (HAVING expr)?
+;
+
+opt_set_quantifier: (ALL | DISTINCT)?;
+
select_core:
(FROM join_source)? SELECT STREAM? opt_set_quantifier result_column (COMMA result_column)* (WITHOUT column_list)? (FROM join_source)? (WHERE expr)?
- group_by_clause? (HAVING expr)? window_clause? order_by_clause?
+ group_by_clause? (HAVING expr)? window_clause? order_by_clause?
;
-order_by_clause: ORDER BY sort_specification_list;
-
-group_by_clause: GROUP BY opt_set_quantifier grouping_element_list;
-
-grouping_element_list: grouping_element (COMMA grouping_element)*;
-
-grouping_element:
- ordinary_grouping_set
- | rollup_list
- | cube_list
- | grouping_sets_specification
-//empty_grouping_set inside smart_parenthesis
+order_by_clause: ORDER BY sort_specification_list;
+
+group_by_clause: GROUP BY opt_set_quantifier grouping_element_list;
+
+grouping_element_list: grouping_element (COMMA grouping_element)*;
+
+grouping_element:
+ ordinary_grouping_set
+ | rollup_list
+ | cube_list
+ | grouping_sets_specification
+//empty_grouping_set inside smart_parenthesis
| hopping_window_specification
-;
-
-/// expect column (named column), or parenthesis list columns, or expression (named expression), or list expression
-ordinary_grouping_set: named_expr;
-ordinary_grouping_set_list: ordinary_grouping_set (COMMA ordinary_grouping_set)*;
-
-rollup_list: ROLLUP LPAREN ordinary_grouping_set_list RPAREN;
-cube_list: CUBE LPAREN ordinary_grouping_set_list RPAREN;
-
-/// SQL2003 grouping_set_list == grouping_element_list
-grouping_sets_specification: GROUPING SETS LPAREN grouping_element_list RPAREN;
-
+;
+
+/// expect column (named column), or parenthesis list columns, or expression (named expression), or list expression
+ordinary_grouping_set: named_expr;
+ordinary_grouping_set_list: ordinary_grouping_set (COMMA ordinary_grouping_set)*;
+
+rollup_list: ROLLUP LPAREN ordinary_grouping_set_list RPAREN;
+cube_list: CUBE LPAREN ordinary_grouping_set_list RPAREN;
+
+/// SQL2003 grouping_set_list == grouping_element_list
+grouping_sets_specification: GROUPING SETS LPAREN grouping_element_list RPAREN;
+
hopping_window_specification: HOP LPAREN expr COMMA expr COMMA expr COMMA expr RPAREN;
-result_column:
- opt_id_prefix ASTERISK
- | expr (AS id_or_string)?
+result_column:
+ opt_id_prefix ASTERISK
+ | expr (AS id_or_string)?
;
-join_source: flatten_source (join_op flatten_source join_constraint?)*;
+join_source: flatten_source (join_op flatten_source join_constraint?)*;
+
+ordinary_named_column_list:
+ named_column
+ | LPAREN named_column_list RPAREN
+;
-ordinary_named_column_list:
- named_column
- | LPAREN named_column_list RPAREN
-;
-
flatten_source: named_single_source (FLATTEN ((OPTIONAL|LIST|DICT)? BY ordinary_named_column_list | COLUMNS))?;
-
+
named_single_source: single_source (AS id_or_string)? (sample_clause | tablesample_clause)?;
-
-single_source:
- table_ref
- | LPAREN select_stmt RPAREN
+
+single_source:
+ table_ref
+ | LPAREN select_stmt RPAREN
| AT? bind_parameter (LPAREN expr_list? RPAREN)?
;
@@ -274,36 +274,36 @@ sampling_mode: (BERNOULLI | SYSTEM);
repeatable_clause: REPEATABLE LPAREN expr RPAREN;
-join_op:
- COMMA
+join_op:
+ COMMA
| (NATURAL)? ((LEFT (ONLY | SEMI_JOIN)? | RIGHT (ONLY | SEMI_JOIN)? | EXCLUSION | FULL)? (OUTER)? | INNER | CROSS) JOIN
;
-join_constraint:
- ON expr
+join_constraint:
+ ON expr
| USING pure_column_or_named_list
;
into_table_stmt: (INSERT | INSERT OR ABORT | INSERT OR REVERT | INSERT OR IGNORE | UPSERT | REPLACE) INTO into_simple_table_ref into_values_source;
-
-into_values_source:
- pure_column_list? values_source
- | DEFAULT VALUES
+
+into_values_source:
+ pure_column_list? values_source
+ | DEFAULT VALUES
;
values_source: VALUES values_source_row_list | select_stmt;
values_source_row_list: values_source_row (COMMA values_source_row)*;
values_source_row: LPAREN expr_list RPAREN;
-
-simple_values_source: expr_list | select_stmt;
-
+
+simple_values_source: expr_list | select_stmt;
+
create_table_stmt: CREATE TABLE simple_table_ref LPAREN create_table_entry (COMMA create_table_entry)* RPAREN;
-create_table_entry: column_schema | table_constraint;
+create_table_entry: column_schema | table_constraint;
alter_table_stmt: ALTER TABLE simple_table_ref alter_table_action;
alter_table_action: alter_table_add_column | alter_table_drop_column;
alter_table_add_column: ADD COLUMN? column_schema (COMMA ADD COLUMN? column_schema)*;
-alter_table_drop_column: DROP COLUMN? id;
+alter_table_drop_column: DROP COLUMN? id;
column_schema: id_schema flex_type (NOT? NULL)?;
column_order_by_specification: id (ASC | DESC)?;
@@ -324,82 +324,82 @@ evaluate_for_stmt: EVALUATE FOR bind_parameter IN expr do_stmt (ELSE do_stmt)?;
table_ref: opt_id_prefix (table_key | id_expr LPAREN table_arg (COMMA table_arg)* RPAREN) table_hints?;
table_key: id_table_or_at (COLON id_or_string)?;
table_arg: AT? expr (COLON id_or_string)?;
-table_hints: WITH (id_or_string | pure_column_list);
+table_hints: WITH (id_or_string | pure_column_list);
simple_table_ref: ((opt_id_prefix id_or_at) | AT? bind_parameter) table_hints?;
into_simple_table_ref: simple_table_ref (ERASE BY pure_column_list)?;
-
+
delete_stmt: DELETE FROM simple_table_ref (WHERE expr | ON into_values_source)?;
update_stmt: UPDATE simple_table_ref (SET set_clause_choice (WHERE expr)? | ON into_values_source);
-/// out of 2003 standart
-set_clause_choice: set_clause_list | multiple_column_assignment;
-
-set_clause_list: set_clause (COMMA set_clause)*;
-set_clause: set_target EQUALS expr;
-set_target: column_name;
-multiple_column_assignment: set_target_list EQUALS LPAREN simple_values_source RPAREN;
-set_target_list: LPAREN set_target (COMMA set_target)* RPAREN;
-
-/// window function supp
-// differ from 2003 for resolve conflict
-window_function: call_expr (null_treatment? OVER window_name_or_specification)?;
-
+/// out of 2003 standart
+set_clause_choice: set_clause_list | multiple_column_assignment;
+
+set_clause_list: set_clause (COMMA set_clause)*;
+set_clause: set_target EQUALS expr;
+set_target: column_name;
+multiple_column_assignment: set_target_list EQUALS LPAREN simple_values_source RPAREN;
+set_target_list: LPAREN set_target (COMMA set_target)* RPAREN;
+
+/// window function supp
+// differ from 2003 for resolve conflict
+window_function: call_expr (null_treatment? OVER window_name_or_specification)?;
+
in_window_function: in_call_expr (null_treatment? OVER window_name_or_specification)?;
-null_treatment: RESPECT NULLS | IGNORE NULLS;
-
-window_name_or_specification: window_name | in_line_window_specification;
-
-in_line_window_specification: window_specification;
-
-window_name: id;
-
-window_clause: WINDOW window_definition_list;
-
-window_definition_list: window_definition (COMMA window_definition)*;
-
-window_definition: new_window_name AS window_specification;
-
-new_window_name: window_name;
-
-window_specification: LPAREN window_specification_details RPAREN;
-
-window_specification_details:
- existing_window_name?
- window_partition_clause?
- window_order_clause?
- window_frame_clause?
-;
-
-existing_window_name: window_name;
-window_partition_clause: PARTITION BY named_expr_list;
-window_order_clause: order_by_clause;
-
-window_frame_clause: window_frame_units window_frame_extent window_frame_exclusion?;
-window_frame_units: ROWS | RANGE;
-
-window_frame_extent: window_frame_start | window_frame_between;
-
-window_frame_start:
- UNBOUNDED PRECEDING
- | window_frame_preceding
- | CURRENT ROW
-;
-
-window_frame_preceding: unsigned_number PRECEDING;
-window_frame_following: unsigned_number FOLLOWING;
-window_frame_between: BETWEEN window_frame_bound AND window_frame_bound;
-window_frame_bound:
- window_frame_start
- | UNBOUNDED FOLLOWING
- | window_frame_following
-;
-
-window_frame_exclusion: EXCLUDE CURRENT ROW | EXCLUDE GROUP | EXCLUDE TIES | EXCLUDE NO OTHERS;
-
+null_treatment: RESPECT NULLS | IGNORE NULLS;
+
+window_name_or_specification: window_name | in_line_window_specification;
+
+in_line_window_specification: window_specification;
+
+window_name: id;
+
+window_clause: WINDOW window_definition_list;
+
+window_definition_list: window_definition (COMMA window_definition)*;
+
+window_definition: new_window_name AS window_specification;
+
+new_window_name: window_name;
+
+window_specification: LPAREN window_specification_details RPAREN;
+
+window_specification_details:
+ existing_window_name?
+ window_partition_clause?
+ window_order_clause?
+ window_frame_clause?
+;
+
+existing_window_name: window_name;
+window_partition_clause: PARTITION BY named_expr_list;
+window_order_clause: order_by_clause;
+
+window_frame_clause: window_frame_units window_frame_extent window_frame_exclusion?;
+window_frame_units: ROWS | RANGE;
+
+window_frame_extent: window_frame_start | window_frame_between;
+
+window_frame_start:
+ UNBOUNDED PRECEDING
+ | window_frame_preceding
+ | CURRENT ROW
+;
+
+window_frame_preceding: unsigned_number PRECEDING;
+window_frame_following: unsigned_number FOLLOWING;
+window_frame_between: BETWEEN window_frame_bound AND window_frame_bound;
+window_frame_bound:
+ window_frame_start
+ | UNBOUNDED FOLLOWING
+ | window_frame_following
+;
+
+window_frame_exclusion: EXCLUDE CURRENT ROW | EXCLUDE GROUP | EXCLUDE TIES | EXCLUDE NO OTHERS;
+
// EXTRAS
-use_stmt: USE id_or_string;
+use_stmt: USE id_or_string;
named_nodes_stmt: bind_parameter_list EQUALS (expr | LPAREN select_stmt RPAREN);
@@ -409,72 +409,72 @@ rollback_stmt: ROLLBACK;
// Special rules that allow to use certain keywords as identifiers.
-id_or_string: IDENTIFIER | STRING | keyword;
-id: IDENTIFIER | keyword;
-id_schema: IDENTIFIER | keyword_restricted;
+id_or_string: IDENTIFIER | STRING | keyword;
+id: IDENTIFIER | keyword;
+id_schema: IDENTIFIER | keyword_restricted;
id_expr: IDENTIFIER | keyword_compat | keyword_alter_uncompat | keyword_in_uncompat;
in_id_expr: IDENTIFIER | keyword_compat | keyword_alter_uncompat;
id_table: IDENTIFIER | keyword_restricted;
id_table_or_at: AT? id_table;
id_or_at: AT? id;
-opt_id_prefix: (id_or_string DOT)?;
-
+opt_id_prefix: (id_or_string DOT)?;
+
keyword: keyword_restricted | keyword_alter_uncompat | keyword_table_uncompat;
keyword_restricted: keyword_compat | keyword_expr_uncompat | keyword_select_uncompat | keyword_in_uncompat;
-
-keyword_expr_uncompat:
+
+keyword_expr_uncompat:
BITCAST
| CASE
- | CAST
- | CUBE
- | CURRENT_TIME
- | CURRENT_DATE
- | CURRENT_TIMESTAMP
+ | CAST
+ | CUBE
+ | CURRENT_TIME
+ | CURRENT_DATE
+ | CURRENT_TIMESTAMP
| EMPTY_ACTION
- | EXISTS
- | FROM
- | FULL
+ | EXISTS
+ | FROM
+ | FULL
| HOP
- | NOT
- | NULL
- | PROCESS
- | REDUCE
- | RETURN
- | ROLLUP
- | SELECT
- | WHEN
- | WHERE
-;
-
+ | NOT
+ | NULL
+ | PROCESS
+ | REDUCE
+ | RETURN
+ | ROLLUP
+ | SELECT
+ | WHEN
+ | WHERE
+;
+
keyword_table_uncompat:
ERASE
| STREAM
;
-keyword_select_uncompat:
- ALL
- | AS
- | DISTINCT
- | HAVING
-;
-
-keyword_alter_uncompat:
- COLUMN
-;
-
+keyword_select_uncompat:
+ ALL
+ | AS
+ | DISTINCT
+ | HAVING
+;
+
+keyword_alter_uncompat:
+ COLUMN
+;
+
keyword_in_uncompat:
COMPACT
;
-keyword_compat: (
+keyword_compat: (
ABORT
| ACTION
| ADD
| AFTER
| ALTER
| ANALYZE
- | AND
+ | AND
| ASC
| ATTACH
| AUTOINCREMENT
@@ -492,9 +492,9 @@ keyword_compat: (
| CONSTRAINT
| CREATE
| CROSS
- | CURRENT
+ | CURRENT
| DATABASE
- | DECLARE
+ | DECLARE
| DEFAULT
| DEFERRABLE
| DEFERRED
@@ -512,24 +512,24 @@ keyword_compat: (
| ESCAPE
| EVALUATE
| EXCEPT
- | EXCLUDE
+ | EXCLUDE
| EXCLUSIVE
| EXCLUSION
| EXPLAIN
- | EXPORT
+ | EXPORT
| FAIL
- | FLATTEN
- | FOLLOWING
+ | FLATTEN
+ | FOLLOWING
| FOR
| FOREIGN
| GLOB
| GROUP
- | GROUPING
+ | GROUPING
| IF
| IGNORE
| ILIKE
| IMMEDIATE
- | IMPORT
+ | IMPORT
| IN
| INDEX
| INDEXED
@@ -542,15 +542,15 @@ keyword_compat: (
| IS
| ISNULL
| JOIN
- | KEY
+ | KEY
| LEFT
| LIKE
| LIMIT
| LIST
| MATCH
| NATURAL
- | NULLS
- | NO
+ | NULLS
+ | NO
| NOTNULL
| OF
| OFFSET
@@ -559,63 +559,63 @@ keyword_compat: (
| OPTIONAL
| OR
| ORDER
- | OTHERS
+ | OTHERS
| OUTER
- | OVER
+ | OVER
| PLAN
- | PARTITION
+ | PARTITION
| PRAGMA
- | PRECEDING
- | PRESORT
+ | PRECEDING
+ | PRESORT
| PRIMARY
// | QUERY
| RAISE
- | RANGE
+ | RANGE
| REFERENCES
| REGEXP
| REINDEX
| RELEASE
| RENAME
| REPLACE
- | RESPECT
+ | RESPECT
| RESTRICT
| RESULT
| REVERT
- | RIGHT
- | RLIKE
+ | RIGHT
+ | RLIKE
| ROLLBACK
| ROW
- | ROWS
+ | ROWS
| SAMPLE
| SAVEPOINT
| SEMI_JOIN
| SET
- | SETS
+ | SETS
| SUBQUERY
- | SYMBOLS
+ | SYMBOLS
| SYSTEM
| TABLE
| TABLESAMPLE
| TEMPORARY
- | TIES
+ | TIES
| THEN
| TO
| TRANSACTION
| TRIGGER
- | UNBOUNDED
+ | UNBOUNDED
| UNION
| UNIQUE
| UPDATE
- | UPSERT
+ | UPSERT
| USING
| VACUUM
| VALUES
| VIEW
| VIRTUAL
- | WINDOW
+ | WINDOW
| WITH
- | WITHOUT
- | XOR
+ | WITHOUT
+ | XOR
);
bool_value: (TRUE | FALSE);
@@ -652,12 +652,12 @@ COMMA: ',';
LPAREN: '(';
RPAREN: ')';
QUESTION: '?';
-DOUBLE_QUESTION: '??';
+DOUBLE_QUESTION: '??';
COLON: ':';
AT: '@';
DOUBLE_AT: '@@';
DOLLAR: '$';
-QUOTE_DOUBLE: '"'; // This comment for fix syntax highlighting "
+QUOTE_DOUBLE: '"'; // This comment for fix syntax highlighting "
QUOTE_SINGLE: '\'';
APOSTROPHE: '`';
LBRACE_CURLY: '{';
@@ -665,9 +665,9 @@ RBRACE_CURLY: '}';
UNDERSCORE: '_';
CARET: '^';
NAMESPACE: '::';
-ARROW: '->';
-RBRACE_SQUARE: ']';
-LBRACE_SQUARE: '['; // pair ]
+ARROW: '->';
+RBRACE_SQUARE: ']';
+LBRACE_SQUARE: '['; // pair ]
// http://www.antlr.org/wiki/pages/viewpage.action?pageId=1782
fragment A:('a'|'A');
@@ -728,13 +728,13 @@ CONFLICT: C O N F L I C T;
CONSTRAINT: C O N S T R A I N T;
CREATE: C R E A T E;
CROSS: C R O S S;
-CUBE: C U B E;
-CURRENT: C U R R E N T;
+CUBE: C U B E;
+CURRENT: C U R R E N T;
CURRENT_TIME: C U R R E N T '_' T I M E;
CURRENT_DATE: C U R R E N T '_' D A T E;
CURRENT_TIMESTAMP: C U R R E N T '_' T I M E S T A M P;
DATABASE: D A T A B A S E;
-DECLARE: D E C L A R E;
+DECLARE: D E C L A R E;
DEFAULT: D E F A U L T;
DEFERRABLE: D E F E R R A B L E;
DEFERRED: D E F E R R E D;
@@ -755,29 +755,29 @@ ERASE: E R A S E;
ESCAPE: E S C A P E;
EVALUATE: E V A L U A T E;
EXCEPT: E X C E P T;
-EXCLUDE: E X C L U D E;
+EXCLUDE: E X C L U D E;
EXCLUSIVE: E X C L U S I V E;
EXCLUSION: E X C L U S I O N;
EXISTS: E X I S T S;
EXPLAIN: E X P L A I N;
-EXPORT: E X P O R T;
+EXPORT: E X P O R T;
FAIL: F A I L;
-FLATTEN: F L A T T E N;
-FOLLOWING: F O L L O W I N G;
+FLATTEN: F L A T T E N;
+FOLLOWING: F O L L O W I N G;
FOR: F O R;
FOREIGN: F O R E I G N;
FROM: F R O M;
FULL: F U L L;
GLOB: G L O B;
GROUP: G R O U P;
-GROUPING: G R O U P I N G;
+GROUPING: G R O U P I N G;
HAVING: H A V I N G;
HOP: H O P;
IF: I F;
IGNORE: I G N O R E;
ILIKE: I L I K E;
IMMEDIATE: I M M E D I A T E;
-IMPORT: I M P O R T;
+IMPORT: I M P O R T;
IN: I N;
INDEX: I N D E X;
INDEXED: I N D E X E D;
@@ -790,18 +790,18 @@ INTO: I N T O;
IS: I S;
ISNULL: I S N U L L;
JOIN: J O I N;
-KEY: K E Y;
+KEY: K E Y;
LEFT: L E F T;
LIKE: L I K E;
LIMIT: L I M I T;
LIST: L I S T;
MATCH: M A T C H;
NATURAL: N A T U R A L;
-NO: N O;
+NO: N O;
NOT: N O T;
NOTNULL: N O T N U L L;
NULL: N U L L;
-NULLS: N U L L S;
+NULLS: N U L L S;
OF: O F;
OFFSET: O F F S E T;
ON: O N;
@@ -809,19 +809,19 @@ ONLY: O N L Y;
OPTIONAL: O P T I O N A L;
OR: O R;
ORDER: O R D E R;
-OTHERS: O T H E R S;
+OTHERS: O T H E R S;
OUTER: O U T E R;
-OVER: O V E R;
-PARTITION: P A R T I T I O N;
+OVER: O V E R;
+PARTITION: P A R T I T I O N;
PLAN: P L A N;
PRAGMA: P R A G M A;
-PRECEDING: P R E C E D I N G;
-PRESORT: P R E S O R T;
+PRECEDING: P R E C E D I N G;
+PRESORT: P R E S O R T;
PRIMARY: P R I M A R Y;
PROCESS: P R O C E S S;
//QUERY: Q U E R Y;
RAISE: R A I S E;
-RANGE: R A N G E;
+RANGE: R A N G E;
REDUCE: R E D U C E;
REFERENCES: R E F E R E N C E S;
REGEXP: R E G E X P;
@@ -830,40 +830,40 @@ RELEASE: R E L E A S E;
RENAME: R E N A M E;
REPEATABLE: R E P E A T A B L E;
REPLACE: R E P L A C E;
-RESPECT: R E S P E C T;
+RESPECT: R E S P E C T;
RESTRICT: R E S T R I C T;
RESULT: R E S U L T;
-RETURN: R E T U R N;
+RETURN: R E T U R N;
REVERT: R E V E R T;
RIGHT: R I G H T;
-RLIKE: R L I K E;
+RLIKE: R L I K E;
ROLLBACK: R O L L B A C K;
-ROLLUP: R O L L U P;
+ROLLUP: R O L L U P;
ROW: R O W;
-ROWS: R O W S;
+ROWS: R O W S;
SAMPLE: S A M P L E;
SAVEPOINT: S A V E P O I N T;
SELECT: S E L E C T;
SEMI_JOIN: S E M I;
SET: S E T;
-SETS: S E T S;
+SETS: S E T S;
SUBQUERY: S U B Q U E R Y;
STREAM: S T R E A M;
-SYMBOLS: S Y M B O L S;
+SYMBOLS: S Y M B O L S;
SYSTEM: S Y S T E M;
TABLE: T A B L E;
TABLESAMPLE: T A B L E S A M P L E;
TEMPORARY: T E M P ( O R A R Y )?;
THEN: T H E N;
-TIES: T I E S;
+TIES: T I E S;
TO: T O;
TRANSACTION: T R A N S A C T I O N;
TRIGGER: T R I G G E R;
-UNBOUNDED: U N B O U N D E D;
+UNBOUNDED: U N B O U N D E D;
UNION: U N I O N;
UNIQUE: U N I Q U E;
UPDATE: U P D A T E;
-UPSERT: U P S E R T;
+UPSERT: U P S E R T;
USE: U S E;
USING: U S I N G;
VACUUM: V A C U U M;
@@ -872,9 +872,9 @@ VIEW: V I E W;
VIRTUAL: V I R T U A L;
WHEN: W H E N;
WHERE: W H E R E;
-WINDOW: W I N D O W;
+WINDOW: W I N D O W;
WITH: W I T H;
-WITHOUT: W I T H O U T;
+WITHOUT: W I T H O U T;
XOR: X O R;
TRUE: T R U E;
FALSE: F A L S E;
@@ -887,45 +887,45 @@ fragment STRING_MULTILINE: (DOUBLE_AT .* DOUBLE_AT)+ AT?;
STRING: (STRING_SINGLE | STRING_DOUBLE | STRING_MULTILINE);
-fragment ID_START: ('a'..'z' | 'A'..'Z' | UNDERSCORE);
-fragment ID_CORE: (ID_START | DIGIT | DOLLAR);
+fragment ID_START: ('a'..'z' | 'A'..'Z' | UNDERSCORE);
+fragment ID_CORE: (ID_START | DIGIT | DOLLAR);
fragment ID_PLAIN: ID_START (ID_CORE)*;
-
-fragment ID_QUOTED_ESCAPE_APOSTROPHE: BACKSLASH APOSTROPHE;
-fragment ID_QUOTED_ESCAPE_SQUARE: BACKSLASH (LBRACE_SQUARE | RBRACE_SQUARE);
-fragment ID_QUOTED_CORE_SQUARE: (~(LBRACE_SQUARE | RBRACE_SQUARE) | ID_QUOTED_ESCAPE_SQUARE)*;
-fragment ID_QUOTED_CORE_APOSTROPHE: (~APOSTROPHE | ID_QUOTED_ESCAPE_APOSTROPHE)*;
-fragment ID_QUOTED_SQUARE: LBRACE_SQUARE ID_QUOTED_CORE_SQUARE RBRACE_SQUARE;
-fragment ID_QUOTED_APOSTROPHE: APOSTROPHE ID_QUOTED_CORE_APOSTROPHE APOSTROPHE;
+
+fragment ID_QUOTED_ESCAPE_APOSTROPHE: BACKSLASH APOSTROPHE;
+fragment ID_QUOTED_ESCAPE_SQUARE: BACKSLASH (LBRACE_SQUARE | RBRACE_SQUARE);
+fragment ID_QUOTED_CORE_SQUARE: (~(LBRACE_SQUARE | RBRACE_SQUARE) | ID_QUOTED_ESCAPE_SQUARE)*;
+fragment ID_QUOTED_CORE_APOSTROPHE: (~APOSTROPHE | ID_QUOTED_ESCAPE_APOSTROPHE)*;
+fragment ID_QUOTED_SQUARE: LBRACE_SQUARE ID_QUOTED_CORE_SQUARE RBRACE_SQUARE;
+fragment ID_QUOTED_APOSTROPHE: APOSTROPHE ID_QUOTED_CORE_APOSTROPHE APOSTROPHE;
fragment ID_QUOTED: ID_QUOTED_SQUARE | ID_QUOTED_APOSTROPHE;
-IDENTIFIER: ID_PLAIN | ID_QUOTED;
+IDENTIFIER: ID_PLAIN | ID_QUOTED;
+
+fragment DIGIT: '0'..'9';
+fragment HEXDIGIT: '0'..'9' | 'a'..'f' | 'A'..'F';
+fragment HEXDIGITS: '0' X HEXDIGIT+;
+fragment OCTDIGITS: '0' O ('0'..'8')+;
+fragment BINDIGITS: '0' B ('0' | '1')+;
+fragment DECDIGITS: DIGIT+;
+DIGITS: DECDIGITS | HEXDIGITS | OCTDIGITS | BINDIGITS;
-fragment DIGIT: '0'..'9';
-fragment HEXDIGIT: '0'..'9' | 'a'..'f' | 'A'..'F';
-fragment HEXDIGITS: '0' X HEXDIGIT+;
-fragment OCTDIGITS: '0' O ('0'..'8')+;
-fragment BINDIGITS: '0' B ('0' | '1')+;
-fragment DECDIGITS: DIGIT+;
-DIGITS: DECDIGITS | HEXDIGITS | OCTDIGITS | BINDIGITS;
-
INTEGER: DIGITS (U? (L | S | T)?);
LEGACY_TINY_INTEGER: DIGITS (U? B?);
integer: DIGITS | INTEGER | LEGACY_TINY_INTEGER;
-
-fragment FLOAT_EXP : E (PLUS | MINUS)? DECDIGITS ;
-REAL:
- DECDIGITS DOT DIGIT* FLOAT_EXP? F?
- | DECDIGITS FLOAT_EXP F?
-// | DOT DECDIGITS FLOAT_EXP? // Conflicts with tuple element access through DOT
+
+fragment FLOAT_EXP : E (PLUS | MINUS)? DECDIGITS ;
+REAL:
+ DECDIGITS DOT DIGIT* FLOAT_EXP? F?
+ | DECDIGITS FLOAT_EXP F?
+// | DOT DECDIGITS FLOAT_EXP? // Conflicts with tuple element access through DOT
;
-real: REAL;
-
-BLOB: X QUOTE_SINGLE HEXDIGIT+ QUOTE_SINGLE;
-
+real: REAL;
+
+BLOB: X QUOTE_SINGLE HEXDIGIT+ QUOTE_SINGLE;
+
fragment MULTILINE_COMMENT: '/*' ( options {greedy=false;} : . )* '*/';
-fragment LINE_COMMENT: '--' ~('\n'|'\r')* ('\n' | '\r' | EOF);
+fragment LINE_COMMENT: '--' ~('\n'|'\r')* ('\n' | '\r' | EOF);
WS: (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;};
COMMENT: (MULTILINE_COMMENT|LINE_COMMENT) {$channel=HIDDEN;};
diff --git a/ydb/library/yql/sql/v0/aggregation.cpp b/ydb/library/yql/sql/v0/aggregation.cpp
index 371c7424b8..6440604881 100644
--- a/ydb/library/yql/sql/v0/aggregation.cpp
+++ b/ydb/library/yql/sql/v0/aggregation.cpp
@@ -79,7 +79,7 @@ protected:
return true;
}
- ctx.PushBlockShortcuts();
+ ctx.PushBlockShortcuts();
if (!Expr->Init(ctx, src)) {
return false;
}
@@ -98,22 +98,22 @@ protected:
if (src->GetJoin()) {
const auto sourcePtr = Expr->GetSourceName();
if (!sourcePtr || !*sourcePtr) {
- if (!src->IsGroupByColumn(DistinctKey)) {
- ctx.Error(Expr->GetPos()) << ErrorDistinctWithoutCorrelation(DistinctKey);
- return false;
- }
- } else {
- DistinctKey = DotJoin(*sourcePtr, DistinctKey);
- }
- }
- if (src->IsGroupByColumn(DistinctKey)) {
- ctx.Error(Expr->GetPos()) << ErrorDistinctByGroupKey(DistinctKey);
- return false;
- }
+ if (!src->IsGroupByColumn(DistinctKey)) {
+ ctx.Error(Expr->GetPos()) << ErrorDistinctWithoutCorrelation(DistinctKey);
+ return false;
+ }
+ } else {
+ DistinctKey = DotJoin(*sourcePtr, DistinctKey);
+ }
+ }
+ if (src->IsGroupByColumn(DistinctKey)) {
+ ctx.Error(Expr->GetPos()) << ErrorDistinctByGroupKey(DistinctKey);
+ return false;
+ }
Expr = AstNode("row");
- ctx.PopBlockShortcuts();
- } else {
- Expr = ctx.GroundBlockShortcutsForExpr(Expr);
+ ctx.PopBlockShortcuts();
+ } else {
+ Expr = ctx.GroundBlockShortcutsForExpr(Expr);
}
if (FakeSource) {
@@ -153,63 +153,63 @@ public:
TAggregationFactoryImpl(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode, bool multi)
: TAggregationFactory(pos, name, func, aggMode, multi)
{}
-
+
private:
TNodePtr DoClone() const final {
return new TAggregationFactoryImpl(Pos, Name, Func, AggMode, Multi);
- }
+ }
};
-
-class TAggregationFactoryWinAutoargImpl final : public TAggregationFactory {
-public:
- TAggregationFactoryWinAutoargImpl(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode)
- : TAggregationFactory(pos, name, func, aggMode)
- {}
-
+
+class TAggregationFactoryWinAutoargImpl final : public TAggregationFactory {
+public:
+ TAggregationFactoryWinAutoargImpl(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode)
+ : TAggregationFactory(pos, name, func, aggMode)
+ {}
+
bool InitAggr(TContext& ctx, bool isFactory, ISource* src, TAstListNode& node, const TVector<TNodePtr>& exprs) override {
Y_UNUSED(isFactory);
- if (!IsOverWindow()) {
- ctx.Error(Pos) << "Expected aggregation function: " << GetName() << " only as window function. You may have forgotten OVER instruction.";
- return false;
- }
+ if (!IsOverWindow()) {
+ ctx.Error(Pos) << "Expected aggregation function: " << GetName() << " only as window function. You may have forgotten OVER instruction.";
+ return false;
+ }
TVector<TNodePtr> exprsAuto;
- if (!exprs) {
- auto winNamePtr = src->GetWindowName();
- YQL_ENSURE(winNamePtr);
- auto winSpecPtr = src->FindWindowSpecification(ctx, *winNamePtr);
- if (!winSpecPtr) {
- return false;
- }
- const auto& orderSpec = winSpecPtr->OrderBy;
- if (!orderSpec) {
- ctx.Warning(Pos, TIssuesIds::YQL_AGGREGATE_BY_WIN_FUNC_WITHOUT_ORDER_BY) <<
- "Expected ORDER BY specification for window: '" << *winNamePtr <<
- "' used in aggregation function: '" << GetName() <<
- " You may have forgotten to ORDER BY in WINDOW specification or choose the wrong WINDOW.";
- }
- for (const auto& spec: orderSpec) {
- exprsAuto.push_back(spec->OrderExpr);
- }
- if (exprsAuto.size() > 1) {
- exprsAuto = {BuildTuple(GetPos(), exprsAuto)};
- }
- }
+ if (!exprs) {
+ auto winNamePtr = src->GetWindowName();
+ YQL_ENSURE(winNamePtr);
+ auto winSpecPtr = src->FindWindowSpecification(ctx, *winNamePtr);
+ if (!winSpecPtr) {
+ return false;
+ }
+ const auto& orderSpec = winSpecPtr->OrderBy;
+ if (!orderSpec) {
+ ctx.Warning(Pos, TIssuesIds::YQL_AGGREGATE_BY_WIN_FUNC_WITHOUT_ORDER_BY) <<
+ "Expected ORDER BY specification for window: '" << *winNamePtr <<
+ "' used in aggregation function: '" << GetName() <<
+ " You may have forgotten to ORDER BY in WINDOW specification or choose the wrong WINDOW.";
+ }
+ for (const auto& spec: orderSpec) {
+ exprsAuto.push_back(spec->OrderExpr);
+ }
+ if (exprsAuto.size() > 1) {
+ exprsAuto = {BuildTuple(GetPos(), exprsAuto)};
+ }
+ }
return TAggregationFactory::InitAggr(ctx, isFactory, src, node, exprsAuto ? exprsAuto : exprs);
- }
-private:
- TNodePtr DoClone() const final {
- return new TAggregationFactoryWinAutoargImpl(Pos, Name, Func, AggMode);
- }
-};
-
+ }
+private:
+ TNodePtr DoClone() const final {
+ return new TAggregationFactoryWinAutoargImpl(Pos, Name, Func, AggMode);
+ }
+};
+
TAggregationPtr BuildFactoryAggregation(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode, bool multi) {
return new TAggregationFactoryImpl(pos, name, func, aggMode, multi);
}
-TAggregationPtr BuildFactoryAggregationWinAutoarg(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode) {
- return new TAggregationFactoryWinAutoargImpl(pos, name, func, aggMode);
-}
-
+TAggregationPtr BuildFactoryAggregationWinAutoarg(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode) {
+ return new TAggregationFactoryWinAutoargImpl(pos, name, func, aggMode);
+}
+
class TKeyPayloadAggregationFactory final : public TAggregationFactory {
public:
TKeyPayloadAggregationFactory(TPosition pos, const TString& name, const TString& factory, EAggregateMode aggMode)
@@ -269,16 +269,16 @@ private:
return true;
}
- ctx.PushBlockShortcuts();
+ ctx.PushBlockShortcuts();
if (!Key->Init(ctx, src)) {
return false;
}
- Key = ctx.GroundBlockShortcutsForExpr(Key);
- ctx.PushBlockShortcuts();
+ Key = ctx.GroundBlockShortcutsForExpr(Key);
+ ctx.PushBlockShortcuts();
if (!Payload->Init(ctx, src)) {
return false;
}
- Payload = ctx.GroundBlockShortcutsForExpr(Payload);
+ Payload = ctx.GroundBlockShortcutsForExpr(Payload);
if (!Limit->Init(ctx, src)) {
return false;
}
@@ -347,16 +347,16 @@ private:
return true;
}
- ctx.PushBlockShortcuts();
+ ctx.PushBlockShortcuts();
if (!Predicate->Init(ctx, src)) {
return false;
}
- Predicate = ctx.GroundBlockShortcutsForExpr(Predicate);
- ctx.PushBlockShortcuts();
+ Predicate = ctx.GroundBlockShortcutsForExpr(Predicate);
+ ctx.PushBlockShortcuts();
if (!Payload->Init(ctx, src)) {
return false;
}
- Payload = ctx.GroundBlockShortcutsForExpr(Payload);
+ Payload = ctx.GroundBlockShortcutsForExpr(Payload);
if (Payload->IsAggregated()) {
ctx.Error(Pos) << "Aggregation of aggregated values is forbidden";
@@ -420,16 +420,16 @@ private:
return true;
}
- ctx.PushBlockShortcuts();
+ ctx.PushBlockShortcuts();
if (!One->Init(ctx, src)) {
return false;
}
- One = ctx.GroundBlockShortcutsForExpr(One);
- ctx.PushBlockShortcuts();
+ One = ctx.GroundBlockShortcutsForExpr(One);
+ ctx.PushBlockShortcuts();
if (!Two->Init(ctx, src)) {
return false;
}
- Two = ctx.GroundBlockShortcutsForExpr(Two);
+ Two = ctx.GroundBlockShortcutsForExpr(Two);
if ((One->IsAggregated() || Two->IsAggregated()) && !IsOverWindow()) {
ctx.Error(Pos) << "Aggregation of aggregated values is forbidden";
@@ -522,16 +522,16 @@ private:
}
bool DoInit(TContext& ctx, ISource* src) final {
- ctx.PushBlockShortcuts();
+ ctx.PushBlockShortcuts();
if (!Weight->Init(ctx, src)) {
return false;
}
- Weight = ctx.GroundBlockShortcutsForExpr(Weight);
- ctx.PushBlockShortcuts();
+ Weight = ctx.GroundBlockShortcutsForExpr(Weight);
+ ctx.PushBlockShortcuts();
if (!Intervals->Init(ctx, FakeSource.Get())) {
return false;
}
- Intervals = ctx.GroundBlockShortcutsForExpr(Intervals);
+ Intervals = ctx.GroundBlockShortcutsForExpr(Intervals);
return TAggregationFactory::DoInit(ctx, src);
}
@@ -1127,7 +1127,7 @@ private:
const auto j = adjustArgsCount + i;
Lambdas[i] = BuildLambda(Pos, Y("state"), j >= exprs.size() ? AstNode("state") : Y("Apply", exprs[j], "state"));
}
-
+
DefVal = (exprs.size() == (7 + adjustArgsCount)) ? exprs[adjustArgsCount + 6] : Y("Null");
return TAggregationFactory::InitAggr(ctx, isFactory, src, node, isFactory ? TVector<TNodePtr>() : TVector<TNodePtr>(1, exprs.front()));
}
@@ -1184,15 +1184,15 @@ private:
return true;
}
- if (Expr->IsAsterisk()) {
+ if (Expr->IsAsterisk()) {
Expr = Y("Void");
- }
- ctx.PushBlockShortcuts();
- if (!Expr->Init(ctx, src)) {
- return false;
- }
+ }
+ ctx.PushBlockShortcuts();
+ if (!Expr->Init(ctx, src)) {
+ return false;
+ }
Expr->SetCountHint(Expr->IsConstant());
- Expr = ctx.GroundBlockShortcutsForExpr(Expr);
+ Expr = ctx.GroundBlockShortcutsForExpr(Expr);
return TAggregationFactory::DoInit(ctx, src);
}
};
diff --git a/ydb/library/yql/sql/v0/builtin.cpp b/ydb/library/yql/sql/v0/builtin.cpp
index 5854e5b60c..a0945f9d05 100644
--- a/ydb/library/yql/sql/v0/builtin.cpp
+++ b/ydb/library/yql/sql/v0/builtin.cpp
@@ -14,7 +14,7 @@
#include <util/string/builder.h>
#include <util/string/cast.h>
#include <util/string/util.h>
-#include <util/string/join.h>
+#include <util/string/join.h>
#include <unordered_map>
@@ -22,51 +22,51 @@ using namespace NYql;
namespace NSQLTranslationV0 {
-class TGroupingNode final: public TAstListNode {
-public:
+class TGroupingNode final: public TAstListNode {
+public:
TGroupingNode(TPosition pos, const TVector<TNodePtr>& args)
- : TAstListNode(pos)
- , Args(args)
- {}
-
+ : TAstListNode(pos)
+ , Args(args)
+ {}
+
bool DoInit(TContext& ctx, ISource* src) final {
- if (!src) {
- ctx.Error(Pos) << "Grouping function should have source";
- return false;
- }
+ if (!src) {
+ ctx.Error(Pos) << "Grouping function should have source";
+ return false;
+ }
TVector<TString> columns;
- columns.reserve(Args.size());
- for (const auto& node: Args) {
- auto namePtr = node->GetColumnName();
- if (!namePtr || !*namePtr) {
- ctx.Error(Pos) << "Grouping function should use columns as arguments";
- return false;
- }
- const auto column = *namePtr;
- ISource* composite = src->GetCompositeSource();
- if (!src->IsGroupByColumn(column) && !src->IsAlias(EExprSeat::GroupBy, column) && (!composite || !composite->IsGroupByColumn(column))) {
- ctx.Error(node->GetPos()) << "Column '" << column << "' not used as grouping column";
- return false;
- }
- columns.emplace_back(column);
- }
- ui64 hint;
- if (!src->CalculateGroupingHint(ctx, columns, hint)) {
- return false;
- }
- Nodes.push_back(BuildAtom(Pos, "Uint64"));
- Nodes.push_back(BuildQuotedAtom(Pos, IntToString<10>(hint)));
- return TAstListNode::DoInit(ctx, src);
- }
-
+ columns.reserve(Args.size());
+ for (const auto& node: Args) {
+ auto namePtr = node->GetColumnName();
+ if (!namePtr || !*namePtr) {
+ ctx.Error(Pos) << "Grouping function should use columns as arguments";
+ return false;
+ }
+ const auto column = *namePtr;
+ ISource* composite = src->GetCompositeSource();
+ if (!src->IsGroupByColumn(column) && !src->IsAlias(EExprSeat::GroupBy, column) && (!composite || !composite->IsGroupByColumn(column))) {
+ ctx.Error(node->GetPos()) << "Column '" << column << "' not used as grouping column";
+ return false;
+ }
+ columns.emplace_back(column);
+ }
+ ui64 hint;
+ if (!src->CalculateGroupingHint(ctx, columns, hint)) {
+ return false;
+ }
+ Nodes.push_back(BuildAtom(Pos, "Uint64"));
+ Nodes.push_back(BuildQuotedAtom(Pos, IntToString<10>(hint)));
+ return TAstListNode::DoInit(ctx, src);
+ }
+
TNodePtr DoClone() const final {
- return new TGroupingNode(Pos, Args);
- }
-
-private:
+ return new TGroupingNode(Pos, Args);
+ }
+
+private:
const TVector<TNodePtr> Args;
-};
-
+};
+
class TBasicAggrFunc final: public TAstListNode {
public:
TBasicAggrFunc(TPosition pos, const TString& name, TAggregationPtr aggr, const TVector<TNodePtr>& args)
@@ -74,17 +74,17 @@ public:
, Name(name)
, Aggr(aggr)
, Args(args)
- {}
+ {}
TCiString GetName() const {
return Name;
}
bool DoInit(TContext& ctx, ISource* src) final {
- if (!src) {
- ctx.Error(Pos) << "Unable to use aggregation function '" << Name << "' without data source";
- return false;
- }
+ if (!src) {
+ ctx.Error(Pos) << "Unable to use aggregation function '" << Name << "' without data source";
+ return false;
+ }
if (!DoInitAggregation(ctx, src)) {
return false;
}
@@ -93,14 +93,14 @@ public:
}
TNodePtr DoClone() const final {
- TAggregationPtr aggrClone = static_cast<IAggregation*>(Aggr->Clone().Release());
- return new TBasicAggrFunc(Pos, Name, aggrClone, CloneContainer(Args));
- }
-
- TAggregationPtr GetAggregation() const override {
- return Aggr;
- }
-
+ TAggregationPtr aggrClone = static_cast<IAggregation*>(Aggr->Clone().Release());
+ return new TBasicAggrFunc(Pos, Name, aggrClone, CloneContainer(Args));
+ }
+
+ TAggregationPtr GetAggregation() const override {
+ return Aggr;
+ }
+
private:
bool DoInitAggregation(TContext& ctx, ISource* src) {
if (!Aggr->InitAggr(ctx, false, src, *this, Args)) {
@@ -111,9 +111,9 @@ private:
void DoUpdateState() const final {
State.Set(ENodeState::Const, Args.front()->IsConstant());
- State.Set(ENodeState::Aggregated);
- }
-
+ State.Set(ENodeState::Aggregated);
+ }
+
protected:
const TString Name;
TAggregationPtr Aggr;
@@ -182,7 +182,7 @@ protected:
TNodePtr Lambda;
};
-typedef THolder<TBasicAggrFunc> TAggrFuncPtr;
+typedef THolder<TBasicAggrFunc> TAggrFuncPtr;
class TLiteralStringAtom: public INode {
public:
@@ -193,8 +193,8 @@ public:
{
}
- bool DoInit(TContext& ctx, ISource* src) override {
- Y_UNUSED(src);
+ bool DoInit(TContext& ctx, ISource* src) override {
+ Y_UNUSED(src);
if (!Node) {
ctx.Error(Pos) << Info;
return false;
@@ -208,14 +208,14 @@ public:
return true;
}
- TAstNode* Translate(TContext& ctx) const override {
+ TAstNode* Translate(TContext& ctx) const override {
return Atom->Translate(ctx);
}
- TPtr DoClone() const final {
- return {};
- }
-
+ TPtr DoClone() const final {
+ return {};
+ }
+
private:
TNodePtr Node;
TNodePtr Atom;
@@ -512,7 +512,7 @@ public:
{}
bool DoInit(TContext& ctx, ISource* src) override {
- if (!ValidateArguments(ctx)) {
+ if (!ValidateArguments(ctx)) {
return false;
}
@@ -536,7 +536,7 @@ public:
{}
bool DoInit(TContext& ctx, ISource* src) override {
- if (!ValidateArguments(ctx)) {
+ if (!ValidateArguments(ctx)) {
return false;
}
@@ -578,7 +578,7 @@ public:
{}
bool DoInit(TContext& ctx, ISource* src) override {
- if (!ValidateArguments(ctx)) {
+ if (!ValidateArguments(ctx)) {
return false;
}
@@ -595,27 +595,27 @@ public:
}
};
-TNodePtr BuildFileNameArgument(TPosition pos, const TNodePtr& argument) {
- return new TLiteralStringAtom(pos, argument, "FilePath requires string literal as parameter");
-}
-
+TNodePtr BuildFileNameArgument(TPosition pos, const TNodePtr& argument) {
+ return new TLiteralStringAtom(pos, argument, "FilePath requires string literal as parameter");
+}
+
class TYqlAtom final: public TCallNode {
public:
TYqlAtom(TPosition pos, const TString& opName, const TVector<TNodePtr>& args)
- : TCallNode(pos, opName, 1, 1, args)
- {}
+ : TCallNode(pos, opName, 1, 1, args)
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
- if (!Args.empty()) {
- Args[0] = BuildFileNameArgument(ctx.Pos(), Args[0]);
- }
- return TCallNode::DoInit(ctx, src);
+ bool DoInit(TContext& ctx, ISource* src) override {
+ if (!Args.empty()) {
+ Args[0] = BuildFileNameArgument(ctx.Pos(), Args[0]);
+ }
+ return TCallNode::DoInit(ctx, src);
}
-
- TNodePtr DoClone() const final {
+
+ TNodePtr DoClone() const final {
return new TYqlAtom(Pos, OpName, Args);
- }
-};
+ }
+};
class TAddMember final: public TCallNode {
public:
@@ -733,68 +733,68 @@ TString NormalizeTypeString(const TString& str) {
static const TSet<TString> AvailableDataTypes = {"Bool", "String", "Uint32", "Uint64", "Int32", "Int64", "Float", "Double", "Utf8", "Yson", "Json",
"Date", "Datetime", "Timestamp", "Interval", "Uint8", "Int8", "Uint16", "Int16", "TzDate", "TzDatetime", "TzTimestamp", "Uuid", "Decimal"};
-TNodePtr GetDataTypeStringNode(TContext& ctx, TCallNode& node, unsigned argNum, TString* outTypeStrPtr = nullptr) {
- auto errMsgFunc = [&node, argNum]() {
+TNodePtr GetDataTypeStringNode(TContext& ctx, TCallNode& node, unsigned argNum, TString* outTypeStrPtr = nullptr) {
+ auto errMsgFunc = [&node, argNum]() {
static std::array<TString, 2> numToName = {{"first", "second"}};
- TStringBuilder sb;
- sb << "At " << numToName.at(argNum) << " argument of " << node.GetOpName() << " expected type string, available one of: "
- << JoinRange(", ", AvailableDataTypes.begin(), AvailableDataTypes.end()) << ";";
+ TStringBuilder sb;
+ sb << "At " << numToName.at(argNum) << " argument of " << node.GetOpName() << " expected type string, available one of: "
+ << JoinRange(", ", AvailableDataTypes.begin(), AvailableDataTypes.end()) << ";";
return TString(sb);
- };
- auto typeStringNode = node.GetArgs().at(argNum);
- auto typeStringPtr = typeStringNode->GetLiteral("String");
- TNodePtr dataTypeNode;
- if (typeStringPtr) {
+ };
+ auto typeStringNode = node.GetArgs().at(argNum);
+ auto typeStringPtr = typeStringNode->GetLiteral("String");
+ TNodePtr dataTypeNode;
+ if (typeStringPtr) {
TString typeString = NormalizeTypeString(*typeStringPtr);
if (!AvailableDataTypes.contains(typeString)) {
- ctx.Error(typeStringNode->GetPos()) << "Bad type string: '" << typeString << "'. " << errMsgFunc();
- return {};
- }
- if (outTypeStrPtr) {
- *outTypeStrPtr = typeString;
- }
- dataTypeNode = typeStringNode->Q(typeString);
- } else {
- ctx.Error(typeStringNode->GetPos()) << errMsgFunc();
- return {};
- }
- return dataTypeNode;
-}
-
-class TYqlParseFileOp final: public TCallNode {
-public:
+ ctx.Error(typeStringNode->GetPos()) << "Bad type string: '" << typeString << "'. " << errMsgFunc();
+ return {};
+ }
+ if (outTypeStrPtr) {
+ *outTypeStrPtr = typeString;
+ }
+ dataTypeNode = typeStringNode->Q(typeString);
+ } else {
+ ctx.Error(typeStringNode->GetPos()) << errMsgFunc();
+ return {};
+ }
+ return dataTypeNode;
+}
+
+class TYqlParseFileOp final: public TCallNode {
+public:
TYqlParseFileOp(TPosition pos, const TVector<TNodePtr>& args)
- : TCallNode(pos, "ParseFile", 2, 2, args)
- {}
-
- bool DoInit(TContext& ctx, ISource* src) override {
- if (!ValidateArguments(ctx)) {
- return false;
- }
-
- auto dataTypeStringNode = GetDataTypeStringNode(ctx, *this, 0);
- if (!dataTypeStringNode) {
- return false;
- }
- auto aliasNode = BuildFileNameArgument(Args[1]->GetPos(), Args[1]);
- OpName = "Apply";
+ : TCallNode(pos, "ParseFile", 2, 2, args)
+ {}
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ if (!ValidateArguments(ctx)) {
+ return false;
+ }
+
+ auto dataTypeStringNode = GetDataTypeStringNode(ctx, *this, 0);
+ if (!dataTypeStringNode) {
+ return false;
+ }
+ auto aliasNode = BuildFileNameArgument(Args[1]->GetPos(), Args[1]);
+ OpName = "Apply";
Args[0] = Y("Udf", Q("File.ByLines"), Y("Void"),
Y("TupleType",
Y("TupleType", Y("DataType", dataTypeStringNode)),
Y("StructType"),
Y("TupleType")));
- Args[1] = Y("FilePath", aliasNode);
- return TCallNode::DoInit(ctx, src);
+ Args[1] = Y("FilePath", aliasNode);
+ return TCallNode::DoInit(ctx, src);
}
-
+
TString GetOpName() const override {
- return "ParseFile";
- }
-
- TNodePtr DoClone() const final {
- return new TYqlParseFileOp(Pos, Args);
- }
+ return "ParseFile";
+ }
+
+ TNodePtr DoClone() const final {
+ return new TYqlParseFileOp(Pos, Args);
+ }
};
class TYqlDataType final : public TCallNode {
@@ -821,14 +821,14 @@ public:
}
};
-TNodePtr TryBuildDataType(TPosition pos, const TString& stringType) {
+TNodePtr TryBuildDataType(TPosition pos, const TString& stringType) {
auto normStringType = NormalizeTypeString(stringType);
if (!AvailableDataTypes.contains(normStringType)) {
- return {};
- }
- return new TYqlDataType(pos, {BuildLiteralRawString(pos, normStringType)});
-}
-
+ return {};
+ }
+ return new TYqlDataType(pos, {BuildLiteralRawString(pos, normStringType)});
+}
+
class TYqlResourceType final : public TCallNode {
public:
TYqlResourceType(TPosition pos, const TVector<TNodePtr>& args)
@@ -1019,22 +1019,22 @@ private:
};
template <bool IsStrict>
-class TYqlIf final: public TCallNode {
+class TYqlIf final: public TCallNode {
public:
TYqlIf(TPosition pos, const TVector<TNodePtr>& args)
: TCallNode(pos, IsStrict ? "IfStrict" : "If", 2, 3, args)
- {}
+ {}
private:
TCallNode::TPtr DoClone() const override {
- return new TYqlIf(GetPos(), CloneContainer(Args));
+ return new TYqlIf(GetPos(), CloneContainer(Args));
}
bool DoInit(TContext& ctx, ISource* src) override {
- if (!ValidateArguments(ctx)) {
- return false;
- }
-
+ if (!ValidateArguments(ctx)) {
+ return false;
+ }
+
Args[0] = Y("Coalesce", Args[0], Y("Bool", Q("false")));
if (Args.size() == 2) {
Args.push_back(Y("Null"));
@@ -1062,23 +1062,23 @@ private:
}
};
-class TYqlIn final: public TCallNode {
+class TYqlIn final: public TCallNode {
public:
TYqlIn(TPosition pos, const TVector<TNodePtr>& args)
: TCallNode(pos, "IN", 3, 3, args)
- {}
+ {}
private:
- TNodePtr DoClone() const final {
- return new TYqlIn(Pos, CloneContainer(Args));
- }
- bool DoInit(TContext& ctx, ISource* src) override {
- if (!ValidateArguments(ctx)) {
- return false;
- }
-
+ TNodePtr DoClone() const final {
+ return new TYqlIn(Pos, CloneContainer(Args));
+ }
+ bool DoInit(TContext& ctx, ISource* src) override {
+ if (!ValidateArguments(ctx)) {
+ return false;
+ }
+
auto key = Args[0];
- auto inNode = Args[1];
+ auto inNode = Args[1];
auto hints = Args[2];
if (!key->Init(ctx, src)) {
@@ -1089,11 +1089,11 @@ private:
return false;
}
- if (inNode->GetLiteral("String")) {
+ if (inNode->GetLiteral("String")) {
ctx.Error(inNode->GetPos()) << "Unable to use IN predicate with string argument, it won't search substring - "
"expecting tuple, list, dict or single column table source";
- return false;
- }
+ return false;
+ }
if (inNode->GetTupleSize() == 1) {
auto singleElement = inNode->GetTupleElement(0);
@@ -1120,35 +1120,35 @@ private:
OpName = "SqlIn";
MinArgs = MaxArgs = 3;
- Args = {
+ Args = {
inNode->GetSource() ? inNode->GetSource() : inNode,
- key,
+ key,
hints
- };
+ };
return TCallNode::DoInit(ctx, src);
}
-
- TString GetOpName() const override {
- return "IN predicate";
- }
+
+ TString GetOpName() const override {
+ return "IN predicate";
+ }
};
class TYqlUdfBase : public TCallNode {
public:
TYqlUdfBase(TPosition pos, const TString& name)
: TCallNode(pos, "Udf", 1, 1, UdfArgs(pos, name))
- {}
+ {}
TYqlUdfBase(TPosition pos, const TString& name, const TVector<TNodePtr>& args, ui32 argsCount = 2)
: TCallNode(pos, "Udf", argsCount, argsCount, UdfArgs(pos, name, &args))
- {}
+ {}
protected:
TYqlUdfBase(TPosition pos, const TString& opName, ui32 minArgs, ui32 maxArgs, const TVector<TNodePtr>& args)
: TCallNode(pos, opName, minArgs, maxArgs, args)
- {}
-
+ {}
+
private:
static TVector<TNodePtr> UdfArgs(TPosition pos, const TString& name, const TVector<TNodePtr>* args = nullptr) {
TVector<TNodePtr> res = { BuildQuotedAtom(pos, name) };
@@ -1158,12 +1158,12 @@ private:
return res;
}
- void DoUpdateState() const override {
- TCallNode::DoUpdateState();
- State.Set(ENodeState::Aggregated, false/*!RunConfig || RunConfig->IsAggregated()*/);
+ void DoUpdateState() const override {
+ TCallNode::DoUpdateState();
+ State.Set(ENodeState::Aggregated, false/*!RunConfig || RunConfig->IsAggregated()*/);
State.Set(ENodeState::Const, true /* FIXME: To avoid CheckAggregationLevel issue for non-const TypeOf. */);
- }
-
+ }
+
private:
TNodePtr RunConfig;
};
@@ -1221,26 +1221,26 @@ private:
}
};
-class TWeakFieldOp final: public TCallNode {
-public:
+class TWeakFieldOp final: public TCallNode {
+public:
TWeakFieldOp(TPosition pos, const TVector<TNodePtr>& args)
- : TCallNode(pos, "WeakField", 2, 3, args)
- {}
-
- bool DoInit(TContext& ctx, ISource* src) override {
- if (!src) {
- ctx.Error(Pos) << GetCallExplain() << " unable use without source";
- return false;
- }
-
- src->AllColumns();
-
- if (!ValidateArguments(ctx)) {
- return false;
- }
- PrecacheState();
-
- const auto memberPos = Args[0]->GetPos();
+ : TCallNode(pos, "WeakField", 2, 3, args)
+ {}
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ if (!src) {
+ ctx.Error(Pos) << GetCallExplain() << " unable use without source";
+ return false;
+ }
+
+ src->AllColumns();
+
+ if (!ValidateArguments(ctx)) {
+ return false;
+ }
+ PrecacheState();
+
+ const auto memberPos = Args[0]->GetPos();
TVector<TNodePtr> repackArgs = {BuildAtom(memberPos, "row", NYql::TNodeFlags::Default)};
if (auto literal = Args[1]->GetLiteral("String")) {
TString targetType;
@@ -1251,58 +1251,58 @@ public:
repackArgs.push_back(Args[1]->Q(targetType));
} else {
repackArgs.push_back(Args[1]);
- }
-
+ }
+
TVector<TNodePtr> column;
- auto namePtr = Args[0]->GetColumnName();
- if (!namePtr || !*namePtr) {
- ctx.Error(Pos) << GetCallExplain() << " expect as first argument column name";
- return false;
- }
- auto memberName = *namePtr;
- column.push_back(Args[0]->Q(*namePtr));
-
- if (src->GetJoin() && !src->IsJoinKeysInitializing()) {
- const auto sourcePtr = Args[0]->GetSourceName();
- if (!sourcePtr || !*sourcePtr) {
- ctx.Error(Pos) << GetOpName() << " required to have correlation name in case of JOIN for column at first parameter";
- return false;
- }
- column.push_back(Args[0]->Q(*sourcePtr));
- memberName = DotJoin(*sourcePtr, memberName);
- }
- if (!GetLabel()) {
- SetLabel(memberName);
- }
- repackArgs.push_back(BuildTuple(memberPos, column));
- if (Args.size() == 3) {
- repackArgs.push_back(Args[2]);
- }
- ++MinArgs;
- ++MaxArgs;
- Args.swap(repackArgs);
-
- return TCallNode::DoInit(ctx, src);
- }
-
- TNodePtr DoClone() const final {
- return new TWeakFieldOp(Pos, Args);
- }
-};
-
+ auto namePtr = Args[0]->GetColumnName();
+ if (!namePtr || !*namePtr) {
+ ctx.Error(Pos) << GetCallExplain() << " expect as first argument column name";
+ return false;
+ }
+ auto memberName = *namePtr;
+ column.push_back(Args[0]->Q(*namePtr));
+
+ if (src->GetJoin() && !src->IsJoinKeysInitializing()) {
+ const auto sourcePtr = Args[0]->GetSourceName();
+ if (!sourcePtr || !*sourcePtr) {
+ ctx.Error(Pos) << GetOpName() << " required to have correlation name in case of JOIN for column at first parameter";
+ return false;
+ }
+ column.push_back(Args[0]->Q(*sourcePtr));
+ memberName = DotJoin(*sourcePtr, memberName);
+ }
+ if (!GetLabel()) {
+ SetLabel(memberName);
+ }
+ repackArgs.push_back(BuildTuple(memberPos, column));
+ if (Args.size() == 3) {
+ repackArgs.push_back(Args[2]);
+ }
+ ++MinArgs;
+ ++MaxArgs;
+ Args.swap(repackArgs);
+
+ return TCallNode::DoInit(ctx, src);
+ }
+
+ TNodePtr DoClone() const final {
+ return new TWeakFieldOp(Pos, Args);
+ }
+};
+
class TTableRow final : public TAstAtomNode {
public:
TTableRow(TPosition pos, const TVector<TNodePtr>& args)
- : TTableRow(pos, args.size())
- {}
-
- TTableRow(TPosition pos, ui32 argsCount)
+ : TTableRow(pos, args.size())
+ {}
+
+ TTableRow(TPosition pos, ui32 argsCount)
: TAstAtomNode(pos, "row", 0)
- , ArgsCount(argsCount)
+ , ArgsCount(argsCount)
{}
bool DoInit(TContext& ctx, ISource* src) override {
- if (!src || src->IsFake()) {
+ if (!src || src->IsFake()) {
ctx.Error(Pos) << "TableRow requires FROM section";
return false;
}
@@ -1312,7 +1312,7 @@ public:
return false;
}
- src->AllColumns();
+ src->AllColumns();
return true;
}
@@ -1321,7 +1321,7 @@ public:
}
TNodePtr DoClone() const final {
- return MakeIntrusive<TTableRow>(Pos, ArgsCount);
+ return MakeIntrusive<TTableRow>(Pos, ArgsCount);
}
private:
@@ -1330,62 +1330,62 @@ private:
TNodePtr BuildUdfUserTypeArg(TPosition pos, const TVector<TNodePtr>& args, TNodePtr customUserType) {
TVector<TNodePtr> argsTypeItems;
- for (auto& arg : args) {
+ for (auto& arg : args) {
argsTypeItems.push_back(new TCallNodeImpl(pos, "TypeOf", TVector<TNodePtr>(1, arg)));
- }
-
+ }
+
TVector<TNodePtr> userTypeItems;
- userTypeItems.push_back(new TCallNodeImpl(pos, "TupleType", argsTypeItems));
- userTypeItems.push_back(new TCallNodeImpl(pos, "StructType", {}));
+ userTypeItems.push_back(new TCallNodeImpl(pos, "TupleType", argsTypeItems));
+ userTypeItems.push_back(new TCallNodeImpl(pos, "StructType", {}));
if (customUserType) {
userTypeItems.push_back(customUserType);
} else {
userTypeItems.push_back(new TCallNodeImpl(pos, "TupleType", {}));
}
-
- return new TCallNodeImpl(pos, "TupleType", userTypeItems);
-}
-
+
+ return new TCallNodeImpl(pos, "TupleType", userTypeItems);
+}
+
TNodePtr BuildUdfUserTypeArg(TPosition pos, TNodePtr positionalArgs, TNodePtr namedArgs, TNodePtr customUserType) {
TVector<TNodePtr> userTypeItems;
userTypeItems.reserve(3);
- userTypeItems.push_back(positionalArgs->Y("TypeOf", positionalArgs));
- userTypeItems.push_back(positionalArgs->Y("TypeOf", namedArgs));
+ userTypeItems.push_back(positionalArgs->Y("TypeOf", positionalArgs));
+ userTypeItems.push_back(positionalArgs->Y("TypeOf", namedArgs));
if (customUserType) {
userTypeItems.push_back(customUserType);
} else {
userTypeItems.push_back(new TCallNodeImpl(pos, "TupleType", {}));
}
-
- return new TCallNodeImpl(pos, "TupleType", userTypeItems);
-}
-
+
+ return new TCallNodeImpl(pos, "TupleType", userTypeItems);
+}
+
TVector<TNodePtr> BuildUdfArgs(const TContext& ctx, TPosition pos, const TVector<TNodePtr>& args,
TNodePtr positionalArgs, TNodePtr namedArgs, TNodePtr customUserType) {
if (!ctx.Settings.EnableGenericUdfs) {
- return {};
- }
+ return {};
+ }
TVector<TNodePtr> udfArgs;
- udfArgs.push_back(new TAstListNodeImpl(pos));
- udfArgs[0]->Add(new TAstAtomNodeImpl(pos, "Void", 0));
- if (namedArgs) {
+ udfArgs.push_back(new TAstListNodeImpl(pos));
+ udfArgs[0]->Add(new TAstAtomNodeImpl(pos, "Void", 0));
+ if (namedArgs) {
udfArgs.push_back(BuildUdfUserTypeArg(pos, positionalArgs, namedArgs, customUserType));
- } else {
+ } else {
udfArgs.push_back(BuildUdfUserTypeArg(pos, args, customUserType));
- }
- return udfArgs;
-}
-
-class TCallableNode final: public INode {
+ }
+ return udfArgs;
+}
+
+class TCallableNode final: public INode {
public:
TCallableNode(TPosition pos, const TString& module, const TString& name, const TVector<TNodePtr>& args)
: INode(pos)
, Module(module)
, Name(name)
, Args(args)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
if (Module == "yql") {
ui32 flags;
TString nameParseError;
@@ -1398,17 +1398,17 @@ public:
const TString yql("(" + parsedName + ")");
TAstParseResult ast = ParseAst(yql, ctx.Pool.get());
- /// TODO: do not drop warnings
+ /// TODO: do not drop warnings
if (ast.IsOk()) {
Node = AstNode(ast.Root->GetChild(0));
} else {
- ctx.Error(Pos) << "Failed to parse YQL: " << ast.Issues.ToString();
+ ctx.Error(Pos) << "Failed to parse YQL: " << ast.Issues.ToString();
return false;
}
- if (src) {
- src->AllColumns();
- }
+ if (src) {
+ src->AllColumns();
+ }
} else if (ctx.Settings.ModuleMapping.contains(Module)) {
Node = Y("bind", Module + "_module", Q(Name));
if (src) {
@@ -1430,21 +1430,21 @@ public:
return Node->Init(ctx, src);
}
- TAstNode* Translate(TContext& ctx) const override {
+ TAstNode* Translate(TContext& ctx) const override {
Y_VERIFY_DEBUG(Node);
return Node->Translate(ctx);
}
- void DoUpdateState() const override {
+ void DoUpdateState() const override {
YQL_ENSURE(Node);
- State.Set(ENodeState::Const, Node->IsConstant());
- State.Set(ENodeState::Aggregated, Node->IsAggregated());
- }
-
- TNodePtr DoClone() const override {
+ State.Set(ENodeState::Const, Node->IsConstant());
+ State.Set(ENodeState::Aggregated, Node->IsAggregated());
+ }
+
+ TNodePtr DoClone() const override {
return new TCallableNode(Pos, Module, Name, Args);
- }
-
+ }
+
private:
TCiString Module;
TString Name;
@@ -1467,16 +1467,16 @@ TNodePtr BuildUdf(TContext& ctx, TPosition pos, const TString& module, const TSt
}
}
-class TScriptUdf final: public INode {
+class TScriptUdf final: public INode {
public:
TScriptUdf(TPosition pos, const TString& moduleName, const TString& funcName, const TVector<TNodePtr>& args)
- : INode(pos)
+ : INode(pos)
, ModuleName(moduleName)
, FuncName(funcName)
, Args(args)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
const bool isPython = ModuleName.find(TStringBuf("Python")) != TString::npos;
if (!isPython) {
if (Args.size() != 2) {
@@ -1532,19 +1532,19 @@ public:
return true;
}
- TAstNode* Translate(TContext& ctx) const override {
+ TAstNode* Translate(TContext& ctx) const override {
Y_UNUSED(ctx);
Y_VERIFY_DEBUG(Node);
return Node->Translate(ctx);
}
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, true);
- }
-
- TNodePtr DoClone() const final {
- return new TScriptUdf(GetPos(), ModuleName, FuncName, CloneContainer(Args));
- }
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, true);
+ }
+
+ TNodePtr DoClone() const final {
+ return new TScriptUdf(GetPos(), ModuleName, FuncName, CloneContainer(Args));
+ }
private:
TString ModuleName;
TString FuncName;
@@ -1620,7 +1620,7 @@ private:
}
};
-class TInvalidBuiltin final: public INode {
+class TInvalidBuiltin final: public INode {
public:
TInvalidBuiltin(TPosition pos, const TString& info)
: INode(pos)
@@ -1628,25 +1628,25 @@ public:
{
}
- bool DoInit(TContext& ctx, ISource*) override {
+ bool DoInit(TContext& ctx, ISource*) override {
ctx.Error(Pos) << Info;
return false;
}
- TAstNode* Translate(TContext&) const override {
+ TAstNode* Translate(TContext&) const override {
return nullptr;
}
- TPtr DoClone() const override {
- return {};
- }
+ TPtr DoClone() const override {
+ return {};
+ }
private:
TString Info;
};
-enum EAggrFuncTypeCallback {
+enum EAggrFuncTypeCallback {
NORMAL,
- WINDOW_AUTOARGS,
+ WINDOW_AUTOARGS,
KEY_PAYLOAD,
PAYLOAD_PREDICATE,
TWO_ARGS,
@@ -1677,7 +1677,7 @@ using TCoreFuncMap = std::unordered_map<TString, TCoreFuncInfo, THash<TString>>;
TAggrFuncFactoryCallback BuildAggrFuncFactoryCallback(
const TString& functionName,
const TString& factoryName,
- EAggrFuncTypeCallback type = NORMAL,
+ EAggrFuncTypeCallback type = NORMAL,
const TString& functionNameOverride = TString(),
const TVector<EAggregateMode>& validModes = {}) {
@@ -1691,15 +1691,15 @@ TAggrFuncFactoryCallback BuildAggrFuncFactoryCallback(
}
}
TAggregationPtr factory = nullptr;
- switch (type) {
+ switch (type) {
case NORMAL:
- factory = BuildFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
+ factory = BuildFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
+ break;
+ case WINDOW_AUTOARGS:
+ factory = BuildFactoryAggregationWinAutoarg(pos, realFunctionName, factoryName, aggMode);
break;
- case WINDOW_AUTOARGS:
- factory = BuildFactoryAggregationWinAutoarg(pos, realFunctionName, factoryName, aggMode);
- break;
case KEY_PAYLOAD:
- factory = BuildKeyPayloadFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
+ factory = BuildKeyPayloadFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case PAYLOAD_PREDICATE:
factory = BuildPayloadPredicateFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
@@ -1708,16 +1708,16 @@ TAggrFuncFactoryCallback BuildAggrFuncFactoryCallback(
factory = BuildTwoArgsFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case COUNT:
- factory = BuildCountAggregation(pos, realFunctionName, factoryName, aggMode);
+ factory = BuildCountAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case HISTOGRAM:
- factory = BuildHistogramFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
+ factory = BuildHistogramFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case LINEAR_HISTOGRAM:
factory = BuildLinearHistogramFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case PERCENTILE:
- factory = BuildPercentileFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
+ factory = BuildPercentileFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case TOPFREQ:
factory = BuildTopFreqFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
@@ -1735,7 +1735,7 @@ TAggrFuncFactoryCallback BuildAggrFuncFactoryCallback(
factory = BuildListFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case UDAF:
- factory = BuildUserDefinedFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
+ factory = BuildUserDefinedFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
}
if (isFactory) {
@@ -1910,7 +1910,7 @@ struct TBuiltinFuncData {
// Atom builtins
{"asatom", BuildSimpleBuiltinFactoryCallback<TYqlAsAtom>()},
{"secureparam", BuildNamedBuiltinFactoryCallback<TYqlAtom>("SecureParam")},
-
+
{"void", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("Void", 0, 0)},
{"callable", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("Callable", 2, 2)},
{"way", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("Way", 1, 1) },
@@ -2012,7 +2012,7 @@ struct TBuiltinFuncData {
{"folderpath", BuildNamedBuiltinFactoryCallback<TYqlAtom>("FolderPath") },
{"files", BuildNamedBuiltinFactoryCallback<TYqlAtom>("Files")},
{"parsefile", BuildSimpleBuiltinFactoryCallback<TYqlParseFileOp>()},
-
+
// Misc builtins
{"coalesce", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("Coalesce", 1, -1)},
{"nvl", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("Coalesce", 1, -1) },
@@ -2109,9 +2109,9 @@ struct TBuiltinFuncData {
{"variance", BuildAggrFuncFactoryCallback("Variance", "variance_0_1_traits_factory")},
{"stddev", BuildAggrFuncFactoryCallback("StdDev", "variance_1_1_traits_factory")},
- {"populationvariance", BuildAggrFuncFactoryCallback("VariancePopulation", "variance_0_0_traits_factory")},
+ {"populationvariance", BuildAggrFuncFactoryCallback("VariancePopulation", "variance_0_0_traits_factory")},
{"variancepopulation", BuildAggrFuncFactoryCallback("VariancePopulation", "variance_0_0_traits_factory")},
- {"populationstddev", BuildAggrFuncFactoryCallback("StdDevPopulation", "variance_1_0_traits_factory")},
+ {"populationstddev", BuildAggrFuncFactoryCallback("StdDevPopulation", "variance_1_0_traits_factory")},
{"stddevpopulation", BuildAggrFuncFactoryCallback("StdDevPopulation", "variance_1_0_traits_factory")},
{"varpop", BuildAggrFuncFactoryCallback("VariancePopulation", "variance_0_0_traits_factory")},
{"stddevpop", BuildAggrFuncFactoryCallback("StdDevPopulation", "variance_1_0_traits_factory")},
@@ -2136,16 +2136,16 @@ struct TBuiltinFuncData {
{"covarp", BuildAggrFuncFactoryCallback("CovariancePopulation", "covariance_population_traits_factory", TWO_ARGS, "CovarP")},
{"udaf", BuildAggrFuncFactoryCallback("UDAF", "udaf_traits_factory", UDAF)},
-
+
// Window functions
- /// by SQL2011 should be with sort
- {"rank", BuildAggrFuncFactoryCallback("Rank", "rank_traits_factory", WINDOW_AUTOARGS)},
- {"denserank", BuildAggrFuncFactoryCallback("DenseRank", "dense_rank_traits_factory", WINDOW_AUTOARGS)},
- // \todo unsupported now, required count element in window
- //{"ntile", BuildAggrFuncFactoryCallback("Ntile", "ntile_traits_factory")},
- //{"percentrank", BuildAggrFuncFactoryCallback("PercentRank", "percent_rank_traits_factory")},
- //{"cumedist", BuildAggrFuncFactoryCallback("CumeDist", "cume_dist_traits_factory")},
-
+ /// by SQL2011 should be with sort
+ {"rank", BuildAggrFuncFactoryCallback("Rank", "rank_traits_factory", WINDOW_AUTOARGS)},
+ {"denserank", BuildAggrFuncFactoryCallback("DenseRank", "dense_rank_traits_factory", WINDOW_AUTOARGS)},
+ // \todo unsupported now, required count element in window
+ //{"ntile", BuildAggrFuncFactoryCallback("Ntile", "ntile_traits_factory")},
+ //{"percentrank", BuildAggrFuncFactoryCallback("PercentRank", "percent_rank_traits_factory")},
+ //{"cumedist", BuildAggrFuncFactoryCallback("CumeDist", "cume_dist_traits_factory")},
+
{"firstvalue", BuildAggrFuncFactoryCallback("FirstValue", "first_value_traits_factory", {OverWindow})},
{"lastvalue", BuildAggrFuncFactoryCallback("LastValue", "last_value_traits_factory", {OverWindow})},
{"firstvalueignorenulls", BuildAggrFuncFactoryCallback("FirstValueIgnoreNulls", "first_value_ignore_nulls_traits_factory", {OverWindow})},
@@ -2227,7 +2227,7 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
}
if (ns == "yql") {
- return new TCallNodeImpl(pos, name, -1, -1, args);
+ return new TCallNodeImpl(pos, name, -1, -1, args);
} else if (ns == "string" && name == "SplitToList") {
TNodePtr positionalArgs;
TNodePtr namedArgs;
@@ -2298,15 +2298,15 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
TVector<TNodePtr> applyArgs = { udfNode };
applyArgs.insert(applyArgs.end(), usedArgs.begin(), usedArgs.end());
return new TCallNodeImpl(pos, namedArgs ? "NamedApply" : "Apply", applyArgs);
- } else if (moduleResource) {
- auto exportName = ns == "core" ? name : "$" + name;
+ } else if (moduleResource) {
+ auto exportName = ns == "core" ? name : "$" + name;
TVector<TNodePtr> applyArgs = {
new TCallNodeImpl(pos, "bind", {
- BuildAtom(pos, ns + "_module", 0), BuildQuotedAtom(pos, exportName)
+ BuildAtom(pos, ns + "_module", 0), BuildQuotedAtom(pos, exportName)
})
- };
- applyArgs.insert(applyArgs.end(), args.begin(), args.end());
- return new TCallNodeImpl(pos, "Apply", applyArgs);
+ };
+ applyArgs.insert(applyArgs.end(), args.begin(), args.end());
+ return new TCallNodeImpl(pos, "Apply", applyArgs);
} else if (ns == "hyperscan" || ns == "pcre" || ns == "pire" || ns.StartsWith("re2")) {
TString moduleName(nameSpace);
moduleName.to_title();
@@ -2396,24 +2396,24 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
if (aggrCallback != aggrFuncs.end()) {
return (*aggrCallback).second(pos, args, aggMode, false).Release();
}
- if (aggMode == EAggregateMode::Distinct) {
+ if (aggMode == EAggregateMode::Distinct) {
return new TInvalidBuiltin(pos, "Only aggregation functions allow DISTINCT set specification");
}
auto builtinCallback = builtinFuncs.find(normalizedName);
if (builtinCallback != builtinFuncs.end()) {
- return (*builtinCallback).second(pos, args);
+ return (*builtinCallback).second(pos, args);
} else if (normalizedName == "asstruct" || normalizedName == "structtype") {
if (args.empty()) {
return new TCallNodeImpl(pos, normalizedName == "asstruct" ? "AsStruct" : "StructType", 0, 0, args);
}
- if (mustUseNamed && *mustUseNamed) {
- *mustUseNamed = false;
- YQL_ENSURE(args.size() == 2);
- Y_VERIFY_DEBUG(dynamic_cast<TTupleNode*>(args[0].Get()));
- auto posArgs = static_cast<TTupleNode*>(args[0].Get());
- if (posArgs->IsEmpty()) {
+ if (mustUseNamed && *mustUseNamed) {
+ *mustUseNamed = false;
+ YQL_ENSURE(args.size() == 2);
+ Y_VERIFY_DEBUG(dynamic_cast<TTupleNode*>(args[0].Get()));
+ auto posArgs = static_cast<TTupleNode*>(args[0].Get());
+ if (posArgs->IsEmpty()) {
if (normalizedName == "asstruct") {
return args[1];
} else {
@@ -2421,8 +2421,8 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
auto namedArgs = static_cast<TStructNode*>(args[1].Get());
return new TStructTypeNode(pos, namedArgs->GetExprs());
}
- }
- }
+ }
+ }
return new TInvalidBuiltin(pos, TStringBuilder() <<
(normalizedName == "asstruct" ? "AsStruct" : "StructType") <<
" requires all argument to be named");
@@ -2451,23 +2451,23 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
}
}
- TNodePtr positionalArgs;
- TNodePtr namedArgs;
- if (mustUseNamed && *mustUseNamed) {
- YQL_ENSURE(args.size() == 2);
- positionalArgs = args[0];
- namedArgs = args[1];
- *mustUseNamed = false;
- }
-
+ TNodePtr positionalArgs;
+ TNodePtr namedArgs;
+ if (mustUseNamed && *mustUseNamed) {
+ YQL_ENSURE(args.size() == 2);
+ positionalArgs = args[0];
+ namedArgs = args[1];
+ *mustUseNamed = false;
+ }
+
TVector<TNodePtr> reuseArgs;
- if (!namedArgs && args && funcPrepareNameNode) {
- TString reusedBaseName = TStringBuilder() << "Arg" << to_title(nameSpace) << to_title(name);
- reuseArgs.reserve(args.size());
- for (const auto& arg: args) {
- reuseArgs.push_back(funcPrepareNameNode(reusedBaseName, arg));
- }
- }
+ if (!namedArgs && args && funcPrepareNameNode) {
+ TString reusedBaseName = TStringBuilder() << "Arg" << to_title(nameSpace) << to_title(name);
+ reuseArgs.reserve(args.size());
+ for (const auto& arg: args) {
+ reuseArgs.push_back(funcPrepareNameNode(reusedBaseName, arg));
+ }
+ }
auto usedArgs = reuseArgs ? reuseArgs : args;
@@ -2489,8 +2489,8 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
const auto& udfArgs = BuildUdfArgs(ctx, pos, usedArgs, positionalArgs, namedArgs, customUserType);
TNodePtr udfNode = BuildUdf(ctx, pos, nameSpace, name, udfArgs);
TVector<TNodePtr> applyArgs = { udfNode };
- applyArgs.insert(applyArgs.end(), usedArgs.begin(), usedArgs.end());
- return new TCallNodeImpl(pos, namedArgs ? "NamedApply" : "Apply", applyArgs);
+ applyArgs.insert(applyArgs.end(), usedArgs.begin(), usedArgs.end());
+ return new TCallNodeImpl(pos, namedArgs ? "NamedApply" : "Apply", applyArgs);
}
} // namespace NSQLTranslationV0
diff --git a/ydb/library/yql/sql/v0/context.cpp b/ydb/library/yql/sql/v0/context.cpp
index ae1ade45eb..a3a9013f2b 100644
--- a/ydb/library/yql/sql/v0/context.cpp
+++ b/ydb/library/yql/sql/v0/context.cpp
@@ -4,7 +4,7 @@
#include <ydb/library/yql/utils/yql_panic.h>
#include <util/folder/pathsplit.h>
-#include <util/string/join.h>
+#include <util/string/join.h>
#include <util/stream/null.h>
#ifdef GetMessage
@@ -51,7 +51,7 @@ TContext::TContext(const NSQLTranslation::TTranslationSettings& settings,
, ClusterPathPrefixes(settings.ClusterPathPrefixes)
, Settings(settings)
, Pool(new TMemoryPool(4096))
- , Issues(issues)
+ , Issues(issues)
, IncrementMonCounterFunction(settings.IncrementCounter)
, CurrCluster(settings.DefaultCluster)
, HasPendingErrors(false)
@@ -82,14 +82,14 @@ const NYql::TPosition& TContext::Pos() const {
}
TString TContext::MakeName(const TString& name) {
- auto iter = GenIndexes.find(name);
- if (iter == GenIndexes.end()) {
- iter = GenIndexes.emplace(name, 0).first;
- }
- TStringBuilder str;
- str << name << iter->second;
- ++iter->second;
- return str;
+ auto iter = GenIndexes.find(name);
+ if (iter == GenIndexes.end()) {
+ iter = GenIndexes.emplace(name, 0).first;
+ }
+ TStringBuilder str;
+ str << name << iter->second;
+ ++iter->second;
+ return str;
}
IOutputStream& TContext::Error() {
@@ -98,18 +98,18 @@ IOutputStream& TContext::Error() {
IOutputStream& TContext::Error(NYql::TPosition pos) {
HasPendingErrors = true;
- return MakeIssue(TSeverityIds::S_ERROR, TIssuesIds::DEFAULT_ERROR, pos);
-}
-
-IOutputStream& TContext::Warning(NYql::TPosition pos, NYql::TIssueCode code) {
- return MakeIssue(TSeverityIds::S_WARNING, code, pos);
-}
-
-IOutputStream& TContext::Info(NYql::TPosition pos) {
- return MakeIssue(TSeverityIds::S_INFO, TIssuesIds::INFO, pos);
-}
-
-IOutputStream& TContext::MakeIssue(ESeverity severity, TIssueCode code, NYql::TPosition pos) {
+ return MakeIssue(TSeverityIds::S_ERROR, TIssuesIds::DEFAULT_ERROR, pos);
+}
+
+IOutputStream& TContext::Warning(NYql::TPosition pos, NYql::TIssueCode code) {
+ return MakeIssue(TSeverityIds::S_WARNING, code, pos);
+}
+
+IOutputStream& TContext::Info(NYql::TPosition pos) {
+ return MakeIssue(TSeverityIds::S_INFO, TIssuesIds::INFO, pos);
+}
+
+IOutputStream& TContext::MakeIssue(ESeverity severity, TIssueCode code, NYql::TPosition pos) {
if (severity == TSeverityIds::S_WARNING) {
auto action = WarningPolicy.GetAction(code);
if (action == EWarningAction::ERROR) {
@@ -138,13 +138,13 @@ IOutputStream& TContext::MakeIssue(ESeverity severity, TIssueCode code, NYql::TP
}
Issues.AddIssue(TIssue(pos, TString()));
- auto& curIssue = Issues.back();
- curIssue.Severity = severity;
- curIssue.IssueCode = code;
- IssueMsgHolder.Reset(new TStringOutput(Issues.back().Message));
- return *IssueMsgHolder;
-}
-
+ auto& curIssue = Issues.back();
+ curIssue.Severity = severity;
+ curIssue.IssueCode = code;
+ IssueMsgHolder.Reset(new TStringOutput(Issues.back().Message));
+ return *IssueMsgHolder;
+}
+
bool TContext::SetPathPrefix(const TString& value, TMaybe<TString> arg) {
if (arg.Defined()) {
if (*arg == YtProviderName
@@ -191,115 +191,115 @@ TNodePtr TContext::GetPrefixedPath(const TString& cluster, const TDeferredAtom&
}
TNodePtr TContext::UniversalAlias(const TString& baseName, TNodePtr&& node) {
- auto alias = MakeName(baseName);
- UniversalAliases.emplace(alias, node);
- return BuildAtom(node->GetPos(), alias, TNodeFlags::Default);
-}
-
-TString TContext::HasBlockShortcut(const TNodePtr& baseNode) {
- YQL_ENSURE(ShortcutCurrentLevel, "Push\\Pop shortcuts not balanced");
- auto shortIter = Shortcuts.find(ShortcutCurrentLevel);
- if (shortIter == Shortcuts.end()) {
- return {};
- }
- const auto& baseMap = shortIter->second.BaseMap;
- const auto iter = baseMap.find(baseNode.Get());
- if (iter == baseMap.end()) {
- return {};
- }
- return iter->second;
-}
-
-TString TContext::RegisterBlockShortcut(const TNodePtr& baseNode, const TNodePtr& node, const TString& baseName) {
- YQL_ENSURE(ShortcutCurrentLevel, "Push\\Pop shortcuts not balanced");
- YQL_ENSURE(node->HasState(ENodeState::Initialized));
- YQL_ENSURE(!HasBlockShortcut(baseNode));
- const auto alias = MakeName(baseName);
- auto& shortcuts = Shortcuts[ShortcutCurrentLevel];
- shortcuts.BaseMap.emplace(baseNode.Get(), alias);
- shortcuts.Goal.emplace_back(std::make_pair(alias, node));
- return alias;
-}
-
-TNodePtr TContext::GetBlockShortcut(const TString& alias) const {
- YQL_ENSURE(ShortcutCurrentLevel, "Push\\Pop shortcuts not balanced");
- auto shortIter = Shortcuts.find(ShortcutCurrentLevel);
- YQL_ENSURE(shortIter != Shortcuts.end(), "Expected block shortcut exist");
- for (const auto& shortcutPair: shortIter->second.Goal) {
- if (shortcutPair.first == alias) {
- return shortcutPair.second;
- }
- }
- Y_FAIL("Expected block shortcut exist");
-}
-
-TNodePtr TContext::GroundBlockShortcuts(NYql::TPosition pos, TNodePtr groundList) {
- YQL_ENSURE(ShortcutCurrentLevel, "Push\\Pop shortcuts not balanced");
- auto shortIter = Shortcuts.find(ShortcutCurrentLevel);
- TNodePtr result = groundList;
- if (shortIter != Shortcuts.end()) {
- if (!result) {
- result = new TAstListNodeImpl(pos);
- }
- for (const auto& shortcutPair: shortIter->second.Goal) {
- result = result->L(result, result->Y("let", shortcutPair.first, shortcutPair.second));
- }
- }
- PopBlockShortcuts();
- return result;
-}
-
-TNodePtr TContext::GroundBlockShortcutsForExpr(const TNodePtr& expr) {
- YQL_ENSURE(ShortcutCurrentLevel, "Push\\Pop shortcuts not balanced");
- YQL_ENSURE(expr);
- auto ground = GroundBlockShortcuts(expr->GetPos());
- return GroundWithExpr(ground, expr);
-}
-
-void TContext::PushBlockShortcuts() {
- ++ShortcutCurrentLevel;
-}
-
-void TContext::PopBlockShortcuts() {
- YQL_ENSURE(ShortcutCurrentLevel, "Push\\Pop shortcuts not balanced");
- auto shortcuts = Shortcuts.find(ShortcutCurrentLevel);
- --ShortcutCurrentLevel;
- if (shortcuts != Shortcuts.end()) {
- Shortcuts.erase(shortcuts);
- }
-}
-
-bool TContext::DeclareVariable(const TString& varName, const TNodePtr& typeNode) {
- Variables.emplace(varName, typeNode);
- return true;
-}
-
+ auto alias = MakeName(baseName);
+ UniversalAliases.emplace(alias, node);
+ return BuildAtom(node->GetPos(), alias, TNodeFlags::Default);
+}
+
+TString TContext::HasBlockShortcut(const TNodePtr& baseNode) {
+ YQL_ENSURE(ShortcutCurrentLevel, "Push\\Pop shortcuts not balanced");
+ auto shortIter = Shortcuts.find(ShortcutCurrentLevel);
+ if (shortIter == Shortcuts.end()) {
+ return {};
+ }
+ const auto& baseMap = shortIter->second.BaseMap;
+ const auto iter = baseMap.find(baseNode.Get());
+ if (iter == baseMap.end()) {
+ return {};
+ }
+ return iter->second;
+}
+
+TString TContext::RegisterBlockShortcut(const TNodePtr& baseNode, const TNodePtr& node, const TString& baseName) {
+ YQL_ENSURE(ShortcutCurrentLevel, "Push\\Pop shortcuts not balanced");
+ YQL_ENSURE(node->HasState(ENodeState::Initialized));
+ YQL_ENSURE(!HasBlockShortcut(baseNode));
+ const auto alias = MakeName(baseName);
+ auto& shortcuts = Shortcuts[ShortcutCurrentLevel];
+ shortcuts.BaseMap.emplace(baseNode.Get(), alias);
+ shortcuts.Goal.emplace_back(std::make_pair(alias, node));
+ return alias;
+}
+
+TNodePtr TContext::GetBlockShortcut(const TString& alias) const {
+ YQL_ENSURE(ShortcutCurrentLevel, "Push\\Pop shortcuts not balanced");
+ auto shortIter = Shortcuts.find(ShortcutCurrentLevel);
+ YQL_ENSURE(shortIter != Shortcuts.end(), "Expected block shortcut exist");
+ for (const auto& shortcutPair: shortIter->second.Goal) {
+ if (shortcutPair.first == alias) {
+ return shortcutPair.second;
+ }
+ }
+ Y_FAIL("Expected block shortcut exist");
+}
+
+TNodePtr TContext::GroundBlockShortcuts(NYql::TPosition pos, TNodePtr groundList) {
+ YQL_ENSURE(ShortcutCurrentLevel, "Push\\Pop shortcuts not balanced");
+ auto shortIter = Shortcuts.find(ShortcutCurrentLevel);
+ TNodePtr result = groundList;
+ if (shortIter != Shortcuts.end()) {
+ if (!result) {
+ result = new TAstListNodeImpl(pos);
+ }
+ for (const auto& shortcutPair: shortIter->second.Goal) {
+ result = result->L(result, result->Y("let", shortcutPair.first, shortcutPair.second));
+ }
+ }
+ PopBlockShortcuts();
+ return result;
+}
+
+TNodePtr TContext::GroundBlockShortcutsForExpr(const TNodePtr& expr) {
+ YQL_ENSURE(ShortcutCurrentLevel, "Push\\Pop shortcuts not balanced");
+ YQL_ENSURE(expr);
+ auto ground = GroundBlockShortcuts(expr->GetPos());
+ return GroundWithExpr(ground, expr);
+}
+
+void TContext::PushBlockShortcuts() {
+ ++ShortcutCurrentLevel;
+}
+
+void TContext::PopBlockShortcuts() {
+ YQL_ENSURE(ShortcutCurrentLevel, "Push\\Pop shortcuts not balanced");
+ auto shortcuts = Shortcuts.find(ShortcutCurrentLevel);
+ --ShortcutCurrentLevel;
+ if (shortcuts != Shortcuts.end()) {
+ Shortcuts.erase(shortcuts);
+ }
+}
+
+bool TContext::DeclareVariable(const TString& varName, const TNodePtr& typeNode) {
+ Variables.emplace(varName, typeNode);
+ return true;
+}
+
bool TContext::AddExports(const TVector<TString>& symbols) {
for (const auto& symbol: symbols) {
if (Exports.contains(symbol)) {
- Error() << "Duplicate export symbol: " << symbol;
- return false;
- }
- if (NamedNodes.find(symbol) == NamedNodes.end()) {
- Error() << "Unknown named node: " << symbol;
- return false;
- }
- Exports.emplace(symbol);
- }
- return true;
-}
-
+ Error() << "Duplicate export symbol: " << symbol;
+ return false;
+ }
+ if (NamedNodes.find(symbol) == NamedNodes.end()) {
+ Error() << "Unknown named node: " << symbol;
+ return false;
+ }
+ Exports.emplace(symbol);
+ }
+ return true;
+}
+
TString TContext::AddImport(const TVector<TString>& modulePath) {
- YQL_ENSURE(!modulePath.empty());
- const TString path = JoinRange("/", modulePath.cbegin(), modulePath.cend());
- auto iter = ImportModuleAliases.find(path);
- if (iter == ImportModuleAliases.end()) {
- const TString alias = MakeName(TStringBuilder() << modulePath.back() << "_module");
- iter = ImportModuleAliases.emplace(path, alias).first;
- }
- return iter->second;
-}
-
+ YQL_ENSURE(!modulePath.empty());
+ const TString path = JoinRange("/", modulePath.cbegin(), modulePath.cend());
+ auto iter = ImportModuleAliases.find(path);
+ if (iter == ImportModuleAliases.end()) {
+ const TString alias = MakeName(TStringBuilder() << modulePath.back() << "_module");
+ iter = ImportModuleAliases.emplace(path, alias).first;
+ }
+ return iter->second;
+}
+
TString TContext::AddSimpleUdf(const TString& udf) {
auto& name = SimpleUdfs[udf];
if (name.empty()) {
@@ -356,8 +356,8 @@ TNodePtr TTranslation::GetNamedNode(const TString& name) {
Ctx.Error() << "Unknown name: " << name;
return nullptr;
}
- Y_VERIFY_DEBUG(!mapIt->second.empty());
- return mapIt->second.top()->Clone();
+ Y_VERIFY_DEBUG(!mapIt->second.empty());
+ return mapIt->second.top()->Clone();
}
void TTranslation::PushNamedNode(const TString& name, TNodePtr node) {
@@ -383,16 +383,16 @@ void TTranslation::PopNamedNode(const TString& name) {
}
TString GetDescription(const google::protobuf::Message& node, const google::protobuf::FieldDescriptor* d) {
- const auto& field = node.GetReflection()->GetMessage(node, d);
- return field.GetReflection()->GetString(field, d->message_type()->FindFieldByName("Descr"));
-}
-
+ const auto& field = node.GetReflection()->GetMessage(node, d);
+ return field.GetReflection()->GetString(field, d->message_type()->FindFieldByName("Descr"));
+}
+
TString TTranslation::AltDescription(const google::protobuf::Message& node, ui32 altCase, const google::protobuf::Descriptor* descr) const {
- return GetDescription(node, descr->FindFieldByNumber(altCase));
-}
-
+ return GetDescription(node, descr->FindFieldByNumber(altCase));
+}
+
void TTranslation::AltNotImplemented(const TString& ruleName, ui32 altCase, const google::protobuf::Message& node, const google::protobuf::Descriptor* descr) {
- Error() << ruleName << ": alternative is not implemented yet: " << GetDescription(node, descr->FindFieldByNumber(altCase));
+ Error() << ruleName << ": alternative is not implemented yet: " << GetDescription(node, descr->FindFieldByNumber(altCase));
}
} // namespace NSQLTranslationV0
diff --git a/ydb/library/yql/sql/v0/context.h b/ydb/library/yql/sql/v0/context.h
index e03c226eba..45f40fae61 100644
--- a/ydb/library/yql/sql/v0/context.h
+++ b/ydb/library/yql/sql/v0/context.h
@@ -34,8 +34,8 @@ namespace NSQLTranslationV0 {
IOutputStream& Error();
IOutputStream& Error(NYql::TPosition pos);
- IOutputStream& Warning(NYql::TPosition pos, NYql::TIssueCode code);
- IOutputStream& Info(NYql::TPosition pos);
+ IOutputStream& Warning(NYql::TPosition pos, NYql::TIssueCode code);
+ IOutputStream& Info(NYql::TPosition pos);
template <typename TToken>
const TString& Token(const TToken& token) {
@@ -89,40 +89,40 @@ namespace NSQLTranslationV0 {
TNodePtr GetPrefixedPath(const TString& cluster, const TDeferredAtom& path);
TNodePtr UniversalAlias(const TString& baseName, TNodePtr&& node);
-
- TString HasBlockShortcut(const TNodePtr& baseNode);
- TString RegisterBlockShortcut(const TNodePtr& baseNode, const TNodePtr& node, const TString& baseName);
- TNodePtr GetBlockShortcut(const TString& alias) const;
- TNodePtr GroundBlockShortcuts(NYql::TPosition pos, TNodePtr groundList = {});
- TNodePtr GroundBlockShortcutsForExpr(const TNodePtr& expr);
-
- void PushBlockShortcuts();
- void PopBlockShortcuts();
-
- void BodyPart() {
- IntoHeading = false;
- }
-
- bool IsParseHeading() const {
- return IntoHeading;
- }
-
- bool DeclareVariable(const TString& varName, const TNodePtr& typeNode);
-
+
+ TString HasBlockShortcut(const TNodePtr& baseNode);
+ TString RegisterBlockShortcut(const TNodePtr& baseNode, const TNodePtr& node, const TString& baseName);
+ TNodePtr GetBlockShortcut(const TString& alias) const;
+ TNodePtr GroundBlockShortcuts(NYql::TPosition pos, TNodePtr groundList = {});
+ TNodePtr GroundBlockShortcutsForExpr(const TNodePtr& expr);
+
+ void PushBlockShortcuts();
+ void PopBlockShortcuts();
+
+ void BodyPart() {
+ IntoHeading = false;
+ }
+
+ bool IsParseHeading() const {
+ return IntoHeading;
+ }
+
+ bool DeclareVariable(const TString& varName, const TNodePtr& typeNode);
+
bool AddExports(const TVector<TString>& symbols);
TString AddImport(const TVector<TString>& modulePath);
TString AddSimpleUdf(const TString& udf);
private:
- IOutputStream& MakeIssue(NYql::ESeverity severity, NYql::TIssueCode code, NYql::TPosition pos);
+ IOutputStream& MakeIssue(NYql::ESeverity severity, NYql::TIssueCode code, NYql::TPosition pos);
private:
NYql::TPosition Position;
- THolder<TStringOutput> IssueMsgHolder;
+ THolder<TStringOutput> IssueMsgHolder;
NSQLTranslation::TClusterMapping ClusterMapping;
TString PathPrefix;
THashMap<TString, TString> ProviderPathPrefixes;
THashMap<TString, TString> ClusterPathPrefixes;
- bool IntoHeading = true;
+ bool IntoHeading = true;
public:
THashMap<TString, TNodePtr> Variables;
@@ -138,12 +138,12 @@ namespace NSQLTranslationV0 {
TString CurrCluster;
bool HasPendingErrors;
THashMap<TString, ui32> GenIndexes;
- bool PragmaRefSelect = false;
- bool PragmaSampleSelect = false;
- bool PragmaAllowDotInAlias = false;
+ bool PragmaRefSelect = false;
+ bool PragmaSampleSelect = false;
+ bool PragmaAllowDotInAlias = false;
bool PragmaInferSchema = false;
- bool PragmaAutoCommit = false;
- bool SimpleColumns = false;
+ bool PragmaAutoCommit = false;
+ bool SimpleColumns = false;
bool PragmaDirectRead = false;
bool PragmaYsonAutoConvert = false;
bool PragmaYsonStrict = false;
@@ -152,20 +152,20 @@ namespace NSQLTranslationV0 {
bool EnableSystemColumns = true;
ui32 ResultRowsLimit = 0;
ui64 ResultSizeLimit = 0;
- ui32 PragmaGroupByLimit = 1 << 5;
- ui32 PragmaGroupByCubeLimit = 5;
+ ui32 PragmaGroupByLimit = 1 << 5;
+ ui32 PragmaGroupByCubeLimit = 5;
THashSet<TString> Libraries;
NYql::TWarningPolicy WarningPolicy;
TVector<TString> AllResults;
TSet<TString> UsedClusters;
-
- struct ShortcutStore {
+
+ struct ShortcutStore {
THashMap<INode*, TString> BaseMap;
TVector<std::pair<TString, TNodePtr>> Goal;
- };
+ };
THashMap<ui32, ShortcutStore> Shortcuts;
- ui32 ShortcutCurrentLevel = 0;
-
+ ui32 ShortcutCurrentLevel = 0;
+
};
class TTranslation {
@@ -186,11 +186,11 @@ namespace NSQLTranslationV0 {
template <typename TToken>
TString Identifier(const TToken& token) {
- return IdContent(Ctx, Token(token));
+ return IdContent(Ctx, Token(token));
}
TString Identifier(const TString& str) const {
- return IdContent(Ctx, str);
+ return IdContent(Ctx, str);
}
TNodePtr GetNamedNode(const TString& name);
@@ -204,7 +204,7 @@ namespace NSQLTranslationV0 {
template <typename TNode>
TString AltDescription(const TNode& node) const {
- return AltDescription(node, node.Alt_case(), TNode::descriptor());
+ return AltDescription(node, node.Alt_case(), TNode::descriptor());
}
protected:
diff --git a/ydb/library/yql/sql/v0/insert.cpp b/ydb/library/yql/sql/v0/insert.cpp
index 97885842f8..1d8aec7134 100644
--- a/ydb/library/yql/sql/v0/insert.cpp
+++ b/ydb/library/yql/sql/v0/insert.cpp
@@ -12,22 +12,22 @@ static const TMap<ESQLWriteColumnMode, EWriteColumnMode> sqlIntoMode2WriteColumn
{ESQLWriteColumnMode::InsertOrAbortInto, EWriteColumnMode::InsertOrAbort},
{ESQLWriteColumnMode::InsertOrIgnoreInto, EWriteColumnMode::InsertOrIgnore},
{ESQLWriteColumnMode::InsertOrRevertInto, EWriteColumnMode::InsertOrRevert},
- {ESQLWriteColumnMode::UpsertInto, EWriteColumnMode::Upsert},
- {ESQLWriteColumnMode::ReplaceInto, EWriteColumnMode::Replace},
- {ESQLWriteColumnMode::InsertIntoWithTruncate, EWriteColumnMode::Renew},
- {ESQLWriteColumnMode::Update, EWriteColumnMode::Update},
- {ESQLWriteColumnMode::Delete, EWriteColumnMode::Delete},
-};
-
-class TModifySourceBase: public ISource {
+ {ESQLWriteColumnMode::UpsertInto, EWriteColumnMode::Upsert},
+ {ESQLWriteColumnMode::ReplaceInto, EWriteColumnMode::Replace},
+ {ESQLWriteColumnMode::InsertIntoWithTruncate, EWriteColumnMode::Renew},
+ {ESQLWriteColumnMode::Update, EWriteColumnMode::Update},
+ {ESQLWriteColumnMode::Delete, EWriteColumnMode::Delete},
+};
+
+class TModifySourceBase: public ISource {
public:
TModifySourceBase(TPosition pos, const TVector<TString>& columnsHint)
: ISource(pos)
- , ColumnsHint(columnsHint)
+ , ColumnsHint(columnsHint)
{
}
- bool AddFilter(TContext& ctx, TNodePtr filter) override {
+ bool AddFilter(TContext& ctx, TNodePtr filter) override {
Y_UNUSED(filter);
ctx.Error(Pos) << "Source does not allow filtering";
return false;
@@ -39,7 +39,7 @@ public:
return false;
}
- bool AddAggregation(TContext& ctx, TAggregationPtr aggr) override {
+ bool AddAggregation(TContext& ctx, TAggregationPtr aggr) override {
Y_UNUSED(aggr);
ctx.Error(Pos) << "Source does not allow aggregation";
return false;
@@ -48,7 +48,7 @@ public:
TNodePtr BuildFilter(TContext& ctx, const TString& label, const TNodePtr& groundNode) override {
Y_UNUSED(ctx);
Y_UNUSED(label);
- Y_UNUSED(groundNode);
+ Y_UNUSED(groundNode);
return nullptr;
}
@@ -57,33 +57,33 @@ public:
return nullptr;
}
-protected:
+protected:
TVector<TString> ColumnsHint;
TString OperationHumanName;
-};
-
-class TUpdateByValues: public TModifySourceBase {
-public:
+};
+
+class TUpdateByValues: public TModifySourceBase {
+public:
TUpdateByValues(TPosition pos, const TString& operationHumanName, const TVector<TString>& columnsHint, const TVector<TNodePtr>& values)
- : TModifySourceBase(pos, columnsHint)
+ : TModifySourceBase(pos, columnsHint)
, OperationHumanName(operationHumanName)
- , Values(values)
- {}
-
- bool DoInit(TContext& ctx, ISource* src) override {
- if (ColumnsHint.size() != Values.size()) {
+ , Values(values)
+ {}
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ if (ColumnsHint.size() != Values.size()) {
ctx.Error(Pos) << "VALUES have " << Values.size() << " columns, " << OperationHumanName << " expects: " << ColumnsHint.size();
- return false;
- }
- for (auto& value: Values) {
- if (!value->Init(ctx, src)) {
+ return false;
+ }
+ for (auto& value: Values) {
+ if (!value->Init(ctx, src)) {
return false;
}
- }
- return true;
- }
-
- TNodePtr Build(TContext& ctx) override {
+ }
+ return true;
+ }
+
+ TNodePtr Build(TContext& ctx) override {
Y_UNUSED(ctx);
YQL_ENSURE(Values.size() == ColumnsHint.size());
@@ -93,33 +93,33 @@ public:
TNodePtr value = Values[i];
structObj = L(structObj, Q(Y(Q(column), value)));
- }
+ }
auto updateRow = BuildLambda(Pos, Y("row"), structObj);
return updateRow;
- }
-
- TNodePtr DoClone() const final {
- return new TUpdateByValues(Pos, OperationHumanName, ColumnsHint, CloneContainer(Values));
- }
-private:
+ }
+
+ TNodePtr DoClone() const final {
+ return new TUpdateByValues(Pos, OperationHumanName, ColumnsHint, CloneContainer(Values));
+ }
+private:
TString OperationHumanName;
-
-protected:
+
+protected:
TVector<TNodePtr> Values;
-};
-
-class TModifyByValues: public TModifySourceBase {
-public:
+};
+
+class TModifyByValues: public TModifySourceBase {
+public:
TModifyByValues(TPosition pos, const TString& operationHumanName, const TVector<TString>& columnsHint, const TVector<TVector<TNodePtr>>& values)
- : TModifySourceBase(pos, columnsHint)
+ : TModifySourceBase(pos, columnsHint)
, OperationHumanName(operationHumanName)
- , Values(values)
+ , Values(values)
{
FakeSource = BuildFakeSource(pos);
}
-
- bool DoInit(TContext& ctx, ISource* src) override {
+
+ bool DoInit(TContext& ctx, ISource* src) override {
Y_UNUSED(src);
bool hasError = false;
for (const auto& row: Values) {
@@ -143,7 +143,7 @@ public:
return !hasError;
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
Y_UNUSED(ctx);
auto tuple = Y();
for (const auto& row: Values) {
@@ -157,46 +157,46 @@ public:
}
return Y("EnsurePersistable", Q(tuple));
}
-
- TNodePtr DoClone() const final {
+
+ TNodePtr DoClone() const final {
TVector<TVector<TNodePtr>> clonedValues;
- clonedValues.reserve(Values.size());
- for (auto cur: Values) {
- clonedValues.push_back(CloneContainer(cur));
- }
- return new TModifyByValues(Pos, OperationHumanName, ColumnsHint, clonedValues);
- }
-
+ clonedValues.reserve(Values.size());
+ for (auto cur: Values) {
+ clonedValues.push_back(CloneContainer(cur));
+ }
+ return new TModifyByValues(Pos, OperationHumanName, ColumnsHint, clonedValues);
+ }
+
private:
TString OperationHumanName;
TVector<TVector<TNodePtr>> Values;
TSourcePtr FakeSource;
};
-class TModifyBySource: public TModifySourceBase {
-public:
+class TModifyBySource: public TModifySourceBase {
+public:
TModifyBySource(TPosition pos, const TString& operationHumanName, const TVector<TString>& columnsHint, TSourcePtr source)
- : TModifySourceBase(pos, columnsHint)
+ : TModifySourceBase(pos, columnsHint)
, OperationHumanName(operationHumanName)
- , Source(std::move(source))
- {}
-
+ , Source(std::move(source))
+ {}
+
void GetInputTables(TTableList& tableList) const override {
- if (Source) {
+ if (Source) {
return Source->GetInputTables(tableList);
- }
- }
-
- bool DoInit(TContext& ctx, ISource* src) override {
- if (!Source->Init(ctx, src)) {
- return false;
- }
- const auto& sourceColumns = Source->GetColumns();
- const auto numColumns = !ColumnsHint.empty() && sourceColumns ? sourceColumns->List.size() : 0;
- if (ColumnsHint.size() != numColumns) {
+ }
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ if (!Source->Init(ctx, src)) {
+ return false;
+ }
+ const auto& sourceColumns = Source->GetColumns();
+ const auto numColumns = !ColumnsHint.empty() && sourceColumns ? sourceColumns->List.size() : 0;
+ if (ColumnsHint.size() != numColumns) {
ctx.Error(Pos) << "SELECT has " << numColumns << " columns, " << OperationHumanName << " expects: " << ColumnsHint.size();
- return false;
- }
+ return false;
+ }
if (numColumns) {
TStringStream str;
bool mismatchFound = false;
@@ -218,38 +218,38 @@ public:
ctx.Warning(Pos, TIssuesIds::YQL_SOURCE_SELECT_COLUMN_MISMATCH) << str.Str();
}
}
- return true;
- }
-
- TNodePtr Build(TContext& ctx) override {
- auto input = Source->Build(ctx);
- if (ColumnsHint.empty() || !Source->GetColumns()) {
- return input;
- }
- auto srcColumn = Source->GetColumns()->List.begin();
+ return true;
+ }
+
+ TNodePtr Build(TContext& ctx) override {
+ auto input = Source->Build(ctx);
+ if (ColumnsHint.empty() || !Source->GetColumns()) {
+ return input;
+ }
+ auto srcColumn = Source->GetColumns()->List.begin();
auto structObj = Y("AsStruct");
- for (auto column: ColumnsHint) {
+ for (auto column: ColumnsHint) {
structObj = L(structObj, Q(Y(BuildQuotedAtom(Pos, column),
- Y("Member", "row", BuildQuotedAtom(Pos, *srcColumn))
- )));
- ++srcColumn;
- }
+ Y("Member", "row", BuildQuotedAtom(Pos, *srcColumn))
+ )));
+ ++srcColumn;
+ }
return Y("OrderedMap", input, BuildLambda(Pos, Y("row"), structObj));
- }
-
- TNodePtr DoClone() const final {
- return new TModifyBySource(Pos, OperationHumanName, ColumnsHint, Source->CloneSource());
- }
-
+ }
+
+ TNodePtr DoClone() const final {
+ return new TModifyBySource(Pos, OperationHumanName, ColumnsHint, Source->CloneSource());
+ }
+
bool IsOrdered() const final {
return Source->IsOrdered();
}
-private:
+private:
TString OperationHumanName;
- TSourcePtr Source;
-};
-
+ TSourcePtr Source;
+};
+
TSourcePtr BuildWriteValues(TPosition pos, const TString& operationHumanName, const TVector<TString>& columnsHint, const TVector<TVector<TNodePtr>>& values) {
return new TModifyByValues(pos, operationHumanName, columnsHint, values);
}
@@ -259,40 +259,40 @@ TSourcePtr BuildWriteValues(TPosition pos, const TString& operationHumanName, co
}
TSourcePtr BuildWriteValues(TPosition pos, const TString& operationHumanName, const TVector<TString>& columnsHint, TSourcePtr source) {
- return new TModifyBySource(pos, operationHumanName, columnsHint, std::move(source));
+ return new TModifyBySource(pos, operationHumanName, columnsHint, std::move(source));
}
TSourcePtr BuildUpdateValues(TPosition pos, const TVector<TString>& columnsHint, const TVector<TNodePtr>& values) {
- return new TUpdateByValues(pos, "UPDATE", columnsHint, values);
-}
-
-class TWriteColumnsNode: public TAstListNode {
+ return new TUpdateByValues(pos, "UPDATE", columnsHint, values);
+}
+
+class TWriteColumnsNode: public TAstListNode {
public:
TWriteColumnsNode(TPosition pos, const TTableRef& table, EWriteColumnMode mode, TSourcePtr values = nullptr, TNodePtr options = nullptr)
: TAstListNode(pos)
, Table(table)
- , Mode(mode)
- , Values(std::move(values))
+ , Mode(mode)
+ , Values(std::move(values))
, Options(std::move(options))
{
FakeSource = BuildFakeSource(pos);
}
- void ResetSource(TSourcePtr source) {
- TableSource = std::move(source);
- }
-
- void ResetUpdate(TSourcePtr update) {
- Update = std::move(update);
+ void ResetSource(TSourcePtr source) {
+ TableSource = std::move(source);
+ }
+
+ void ResetUpdate(TSourcePtr update) {
+ Update = std::move(update);
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
if (!Table.Check(ctx)) {
return false;
}
TTableList tableList;
- TNodePtr values;
+ TNodePtr values;
auto options = Y();
if (Options) {
if (!Options->Init(ctx, src)) {
@@ -303,27 +303,27 @@ public:
ISource* underlyingSrc = src;
- if (TableSource) {
- ctx.PushBlockShortcuts();
- if (!TableSource->Init(ctx, src) || !TableSource->InitFilters(ctx)) {
+ if (TableSource) {
+ ctx.PushBlockShortcuts();
+ if (!TableSource->Init(ctx, src) || !TableSource->InitFilters(ctx)) {
return false;
}
options = L(options, Q(Y(Q("filter"), TableSource->BuildFilterLambda(ctx.GroundBlockShortcuts(Pos)))));
}
bool unordered = false;
- ctx.PushBlockShortcuts();
- if (Values) {
- if (!Values->Init(ctx, TableSource.Get())) {
- return false;
- }
+ ctx.PushBlockShortcuts();
+ if (Values) {
+ if (!Values->Init(ctx, TableSource.Get())) {
+ return false;
+ }
Values->GetInputTables(tableList);
underlyingSrc = Values.Get();
- values = Values->Build(ctx);
- if (!values) {
- return false;
- }
+ values = Values->Build(ctx);
+ if (!values) {
+ return false;
+ }
unordered = !Values->IsOrdered();
}
@@ -333,25 +333,25 @@ public:
}
if (Update) {
- if (!Update->Init(ctx, TableSource.Get()) || !Update->InitFilters(ctx)) {
- return false;
- }
+ if (!Update->Init(ctx, TableSource.Get()) || !Update->InitFilters(ctx)) {
+ return false;
+ }
options = L(options, Q(Y(Q("update"), Update->Build(ctx))));
}
-
+
auto write = BuildWriteTable(Pos, "values", Table, Mode, std::move(options));
if (!write->Init(ctx, FakeSource.Get())) {
return false;
}
- node = ctx.GroundBlockShortcuts(Pos, node);
- if (values) {
- node = L(node, Y("let", "values", values));
+ node = ctx.GroundBlockShortcuts(Pos, node);
+ if (values) {
+ node = L(node, Y("let", "values", values));
if (unordered && ctx.UseUnordered(Table)) {
node = L(node, Y("let", "values", Y("Unordered", "values")));
}
} else {
node = L(node, Y("let", "values", Y("Void")));
- }
+ }
node = L(node, Y("let", "world", write));
node = L(node, Y("return", "world"));
@@ -359,43 +359,43 @@ public:
return true;
}
- TNodePtr DoClone() const final {
- return {};
- }
-
+ TNodePtr DoClone() const final {
+ return {};
+ }
+
protected:
TTableRef Table;
- TSourcePtr TableSource;
- EWriteColumnMode Mode;
- TSourcePtr Values;
+ TSourcePtr TableSource;
+ EWriteColumnMode Mode;
+ TSourcePtr Values;
TSourcePtr Update;
TSourcePtr FakeSource;
TNodePtr Options;
};
-EWriteColumnMode ToWriteColumnsMode(ESQLWriteColumnMode sqlWriteColumnMode) {
- return sqlIntoMode2WriteColumn.at(sqlWriteColumnMode);
+EWriteColumnMode ToWriteColumnsMode(ESQLWriteColumnMode sqlWriteColumnMode) {
+ return sqlIntoMode2WriteColumn.at(sqlWriteColumnMode);
}
TNodePtr BuildWriteColumns(TPosition pos, const TTableRef& table, EWriteColumnMode mode, TSourcePtr values, TNodePtr options) {
- YQL_ENSURE(values, "Invalid values node");
+ YQL_ENSURE(values, "Invalid values node");
return new TWriteColumnsNode(pos, table, mode, std::move(values), std::move(options));
-}
-
-TNodePtr BuildUpdateColumns(TPosition pos, const TTableRef& table, TSourcePtr values, TSourcePtr source) {
- YQL_ENSURE(values, "Invalid values node");
+}
+
+TNodePtr BuildUpdateColumns(TPosition pos, const TTableRef& table, TSourcePtr values, TSourcePtr source) {
+ YQL_ENSURE(values, "Invalid values node");
TIntrusivePtr<TWriteColumnsNode> writeNode = new TWriteColumnsNode(pos, table, EWriteColumnMode::Update);
- writeNode->ResetSource(std::move(source));
- writeNode->ResetUpdate(std::move(values));
- return writeNode;
-}
-
-TNodePtr BuildDelete(TPosition pos, const TTableRef& table, TSourcePtr source) {
- TIntrusivePtr<TWriteColumnsNode> writeNode = new TWriteColumnsNode(pos, table, EWriteColumnMode::Delete);
- writeNode->ResetSource(std::move(source));
- return writeNode;
-}
-
+ writeNode->ResetSource(std::move(source));
+ writeNode->ResetUpdate(std::move(values));
+ return writeNode;
+}
+
+TNodePtr BuildDelete(TPosition pos, const TTableRef& table, TSourcePtr source) {
+ TIntrusivePtr<TWriteColumnsNode> writeNode = new TWriteColumnsNode(pos, table, EWriteColumnMode::Delete);
+ writeNode->ResetSource(std::move(source));
+ return writeNode;
+}
+
class TEraseColumnsNode: public TAstListNode {
public:
diff --git a/ydb/library/yql/sql/v0/join.cpp b/ydb/library/yql/sql/v0/join.cpp
index 89451d3946..78f5affb49 100644
--- a/ydb/library/yql/sql/v0/join.cpp
+++ b/ydb/library/yql/sql/v0/join.cpp
@@ -27,109 +27,109 @@ TString NormalizeJoinOp(const TString& joinOp) {
return JoinSeq("", joinOpsParts);
}
-struct TJoinDescr {
+struct TJoinDescr {
TString Op;
-
- struct TFullColumn {
- ui32 Source;
- TNodePtr Column;
- };
-
+
+ struct TFullColumn {
+ ui32 Source;
+ TNodePtr Column;
+ };
+
TVector<std::pair<TFullColumn, TFullColumn>> Keys;
-
+
TJoinDescr(const TString& op)
- : Op(op)
- {}
-};
-
+ : Op(op)
+ {}
+};
+
class TJoinBase: public IJoin {
public:
TJoinBase(TPosition pos, TVector<TSourcePtr>&& sources)
: IJoin(pos)
- , Sources(std::move(sources))
+ , Sources(std::move(sources))
{
}
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
- ISource* srcByName = nullptr;
- if (column.IsArtificial()) {
- return true;
- }
- if (const auto sourceName = *column.GetSourceName()) {
- for (auto& source: Sources) {
- if (sourceName == source->GetLabel()) {
- srcByName = source.Get();
- break;
- }
- }
- if (!srcByName) {
- if (column.IsAsterisk()) {
- ctx.Error(column.GetPos()) << "Unknown correlation name for asterisk: " << sourceName;
- return {};
- }
- // \todo add warning, either mistake in correlation name, either it's a column
- column.ResetColumn("", sourceName);
- column.SetUseSourceAsColumn();
- column.SetAsNotReliable();
- }
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ ISource* srcByName = nullptr;
+ if (column.IsArtificial()) {
+ return true;
+ }
+ if (const auto sourceName = *column.GetSourceName()) {
+ for (auto& source: Sources) {
+ if (sourceName == source->GetLabel()) {
+ srcByName = source.Get();
+ break;
+ }
+ }
+ if (!srcByName) {
+ if (column.IsAsterisk()) {
+ ctx.Error(column.GetPos()) << "Unknown correlation name for asterisk: " << sourceName;
+ return {};
+ }
+ // \todo add warning, either mistake in correlation name, either it's a column
+ column.ResetColumn("", sourceName);
+ column.SetUseSourceAsColumn();
+ column.SetAsNotReliable();
+ }
}
if (column.IsAsterisk()) {
if (!column.GetCountHint()) {
- if (srcByName) {
- srcByName->AllColumns();
+ if (srcByName) {
+ srcByName->AllColumns();
} else {
for (auto& source: Sources) {
source->AllColumns();
}
}
}
- return true;
- }
- if (srcByName) {
- column.ResetAsReliable();
- if (!srcByName->AddColumn(ctx, column)) {
- return {};
- }
- if (!KeysInitializing && !column.IsAsterisk()) {
- column.SetUseSource();
- }
- return true;
- } else {
- unsigned acceptedColumns = 0;
- TIntrusivePtr<TColumnNode> tryColumn = static_cast<TColumnNode*>(column.Clone().Get());
- tryColumn->SetAsNotReliable();
+ return true;
+ }
+ if (srcByName) {
+ column.ResetAsReliable();
+ if (!srcByName->AddColumn(ctx, column)) {
+ return {};
+ }
+ if (!KeysInitializing && !column.IsAsterisk()) {
+ column.SetUseSource();
+ }
+ return true;
+ } else {
+ unsigned acceptedColumns = 0;
+ TIntrusivePtr<TColumnNode> tryColumn = static_cast<TColumnNode*>(column.Clone().Get());
+ tryColumn->SetAsNotReliable();
TString lastAcceptedColumnSource;
- for (auto& source: Sources) {
- if (source->AddColumn(ctx, *tryColumn)) {
- ++acceptedColumns;
- lastAcceptedColumnSource = source->GetLabel();
- }
- }
- if (!acceptedColumns) {
- TStringBuilder sb;
- const auto& fullColumnName = FullColumnName(column);
- sb << "Column " << fullColumnName << " is not fit to any source";
- for (auto& source: Sources) {
- if (const auto mistype = source->FindColumnMistype(fullColumnName)) {
- sb << ". Did you mean " << mistype.GetRef() << "?";
- break;
- }
- }
- ctx.Error(column.GetPos()) << sb;
- return {};
- } else {
- column.SetAsNotReliable();
- }
+ for (auto& source: Sources) {
+ if (source->AddColumn(ctx, *tryColumn)) {
+ ++acceptedColumns;
+ lastAcceptedColumnSource = source->GetLabel();
+ }
+ }
+ if (!acceptedColumns) {
+ TStringBuilder sb;
+ const auto& fullColumnName = FullColumnName(column);
+ sb << "Column " << fullColumnName << " is not fit to any source";
+ for (auto& source: Sources) {
+ if (const auto mistype = source->FindColumnMistype(fullColumnName)) {
+ sb << ". Did you mean " << mistype.GetRef() << "?";
+ break;
+ }
+ }
+ ctx.Error(column.GetPos()) << sb;
+ return {};
+ } else {
+ column.SetAsNotReliable();
+ }
return false;
}
}
- const TColumns* GetColumns() const override {
- YQL_ENSURE(IsColumnDone, "Unable to GetColumns while it's not finished");
- return &JoinedColumns;
- }
-
+ const TColumns* GetColumns() const override {
+ YQL_ENSURE(IsColumnDone, "Unable to GetColumns while it's not finished");
+ return &JoinedColumns;
+ }
+
void GetInputTables(TTableList& tableList) const override {
for (auto& src: Sources) {
src->GetInputTables(tableList);
@@ -142,17 +142,17 @@ public:
TString what(Sources[n]->GetLabel());
static const TSet<TString> noRightSourceJoinOps = {"LeftOnly", "LeftSemi"};
for (size_t nn = n; nn > 0 && noRightSourceJoinOps.contains(JoinOps[nn-1]); --nn) {
- what = Sources[nn-1]->GetLabel();
- }
+ what = Sources[nn-1]->GetLabel();
+ }
const TString with(Sources[n + 1]->GetLabel());
- for (auto index = n; index <= n + 1; ++index) {
- const auto& label = Sources[index]->GetLabel();
- if (label.Contains('.')) {
- ctx.Error(Sources[index]->GetPos()) << "Invalid label: " << label << ", unable to use name with dot symbol, you should use AS <simple alias name>";
- return nullptr;
- }
- }
+ for (auto index = n; index <= n + 1; ++index) {
+ const auto& label = Sources[index]->GetLabel();
+ if (label.Contains('.')) {
+ ctx.Error(Sources[index]->GetPos()) << "Invalid label: " << label << ", unable to use name with dot symbol, you should use AS <simple alias name>";
+ return nullptr;
+ }
+ }
if (what.empty() && with.empty()) {
ctx.Error() << "At least one correlation name is required in join";
return nullptr;
@@ -182,7 +182,7 @@ public:
return expr;
}
- bool DoInit(TContext& ctx, ISource* src) override;
+ bool DoInit(TContext& ctx, ISource* src) override;
void SetupJoin(const TString& opName, TNodePtr expr) override {
JoinOps.push_back(opName);
@@ -191,9 +191,9 @@ public:
protected:
static TString FullColumnName(const TColumnNode& column) {
- auto sourceName = *column.GetSourceName();
- auto columnName = *column.GetColumnName();
- return sourceName ? DotJoin(sourceName, columnName) : columnName;
+ auto sourceName = *column.GetSourceName();
+ auto columnName = *column.GetColumnName();
+ return sourceName ? DotJoin(sourceName, columnName) : columnName;
}
bool InitKeysOrFilters(TContext& ctx, ui32 joinIdx, TNodePtr expr) {
@@ -207,8 +207,8 @@ protected:
}
op = dynamic_cast<const TCallNode*>(expr.Get());
- YQL_ENSURE(op, "Invalid JOIN equal operation node");
- YQL_ENSURE(op->GetArgs().size() == 2, "Invalid JOIN equal operation arguments");
+ YQL_ENSURE(op, "Invalid JOIN equal operation node");
+ YQL_ENSURE(op->GetArgs().size() == 2, "Invalid JOIN equal operation arguments");
}
ui32 idx = 0;
@@ -229,54 +229,54 @@ protected:
ui32 rightSourceIdx = 0;
const TString* leftSource = nullptr;
const TString* rightSource = nullptr;
- const TString* sameColumnNamePtr = nullptr;
+ const TString* sameColumnNamePtr = nullptr;
TSet<TString> joinedSources;
if (op) {
- const TString* columnNamePtr = nullptr;
+ const TString* columnNamePtr = nullptr;
for (auto& arg : op->GetArgs()) {
- const auto sourceNamePtr = arg->GetSourceName();
- if (!sourceNamePtr) {
+ const auto sourceNamePtr = arg->GetSourceName();
+ if (!sourceNamePtr) {
ctx.Error(expr->GetPos()) << "JOIN: equality predicate arguments must not be constant";
return false;
}
- const auto sourceName = *sourceNamePtr;
- if (sourceName.empty()) {
+ const auto sourceName = *sourceNamePtr;
+ if (sourceName.empty()) {
ctx.Error(expr->GetPos()) << "JOIN: column requires correlation name";
return false;
}
- auto it = sources.find(sourceName);
+ auto it = sources.find(sourceName);
if (it != sources.end()) {
- joinedSources.insert(sourceName);
+ joinedSources.insert(sourceName);
if (it->second == joinIdx + 1) {
rightArg = pos;
- rightSource = sourceNamePtr;
+ rightSource = sourceNamePtr;
rightSourceIdx = it->second;
}
else if (it->second > joinIdx + 1) {
- ctx.Error(expr->GetPos()) << "JOIN: can not use source: " << sourceName << " in equality predicate, it is out of current join scope";
+ ctx.Error(expr->GetPos()) << "JOIN: can not use source: " << sourceName << " in equality predicate, it is out of current join scope";
return false;
}
else {
leftArg = pos;
- leftSource = sourceNamePtr;
+ leftSource = sourceNamePtr;
leftSourceIdx = it->second;
}
}
else {
- ctx.Error(expr->GetPos()) << "JOIN: unknown corellation name: " << sourceName;
+ ctx.Error(expr->GetPos()) << "JOIN: unknown corellation name: " << sourceName;
return false;
}
- if (!columnNamePtr) {
- columnNamePtr = arg->GetColumnName();
- } else {
- auto curColumnNamePtr = arg->GetColumnName();
- if (curColumnNamePtr && *curColumnNamePtr == *columnNamePtr) {
- sameColumnNamePtr = columnNamePtr;
- }
- }
+ if (!columnNamePtr) {
+ columnNamePtr = arg->GetColumnName();
+ } else {
+ auto curColumnNamePtr = arg->GetColumnName();
+ if (curColumnNamePtr && *curColumnNamePtr == *columnNamePtr) {
+ sameColumnNamePtr = columnNamePtr;
+ }
+ }
++pos;
}
- } else {
+ } else {
for (auto& x : sources) {
if (x.second == joinIdx) {
leftArg = pos;
@@ -309,19 +309,19 @@ protected:
KeysInitializing = true;
if (op) {
- ctx.PushBlockShortcuts();
+ ctx.PushBlockShortcuts();
for (auto& arg : op->GetArgs()) {
if (!arg->Init(ctx, this)) {
return false;
}
}
- KeysGround = ctx.GroundBlockShortcuts(GetPos(), KeysGround);
+ KeysGround = ctx.GroundBlockShortcuts(GetPos(), KeysGround);
Y_VERIFY_DEBUG(leftSource);
- if (sameColumnNamePtr) {
- SameKeyMap[*sameColumnNamePtr].insert(*leftSource);
- SameKeyMap[*sameColumnNamePtr].insert(*rightSource);
- }
+ if (sameColumnNamePtr) {
+ SameKeyMap[*sameColumnNamePtr].insert(*leftSource);
+ SameKeyMap[*sameColumnNamePtr].insert(*rightSource);
+ }
}
if (joinIdx == JoinDescrs.size()) {
@@ -334,57 +334,57 @@ protected:
return true;
}
- bool IsJoinKeysInitializing() const override {
- return KeysInitializing;
- }
-
+ bool IsJoinKeysInitializing() const override {
+ return KeysInitializing;
+ }
+
protected:
TVector<TString> JoinOps;
TVector<TNodePtr> JoinExprs;
TVector<TJoinDescr> JoinDescrs;
- TNodePtr KeysGround;
+ TNodePtr KeysGround;
THashMap<TString, THashSet<TString>> SameKeyMap;
TVector<TSourcePtr> Sources;
- TColumns JoinedColumns;
- bool KeysInitializing = false;
- bool IsColumnDone = false;
-
- void FinishColumns() override {
- if (IsColumnDone) {
- return;
- }
- YQL_ENSURE(JoinOps.size()+1 == Sources.size());
- bool excludeNextSource = false;
- decltype(JoinOps)::const_iterator opIter = JoinOps.begin();
- for (auto& src: Sources) {
- if (excludeNextSource) {
- excludeNextSource = false;
- if (opIter != JoinOps.end()) {
- ++opIter;
- }
- continue;
- }
- if (opIter != JoinOps.end()) {
- auto joinOper = *opIter;
- ++opIter;
- if (joinOper == "LeftSemi" || joinOper == "LeftOnly") {
- excludeNextSource = true;
- }
- if (joinOper == "RightSemi" || joinOper == "RightOnly") {
- continue;
- }
- }
- auto columnsPtr = src->GetColumns();
- if (!columnsPtr) {
- continue;
- }
- TColumns upColumns;
- upColumns.Merge(*columnsPtr);
- upColumns.SetPrefix(src->GetLabel());
- JoinedColumns.Merge(upColumns);
- }
- IsColumnDone = true;
- }
+ TColumns JoinedColumns;
+ bool KeysInitializing = false;
+ bool IsColumnDone = false;
+
+ void FinishColumns() override {
+ if (IsColumnDone) {
+ return;
+ }
+ YQL_ENSURE(JoinOps.size()+1 == Sources.size());
+ bool excludeNextSource = false;
+ decltype(JoinOps)::const_iterator opIter = JoinOps.begin();
+ for (auto& src: Sources) {
+ if (excludeNextSource) {
+ excludeNextSource = false;
+ if (opIter != JoinOps.end()) {
+ ++opIter;
+ }
+ continue;
+ }
+ if (opIter != JoinOps.end()) {
+ auto joinOper = *opIter;
+ ++opIter;
+ if (joinOper == "LeftSemi" || joinOper == "LeftOnly") {
+ excludeNextSource = true;
+ }
+ if (joinOper == "RightSemi" || joinOper == "RightOnly") {
+ continue;
+ }
+ }
+ auto columnsPtr = src->GetColumns();
+ if (!columnsPtr) {
+ continue;
+ }
+ TColumns upColumns;
+ upColumns.Merge(*columnsPtr);
+ upColumns.SetPrefix(src->GetLabel());
+ JoinedColumns.Merge(upColumns);
+ }
+ IsColumnDone = true;
+ }
};
bool TJoinBase::DoInit(TContext& ctx, ISource* src) {
@@ -408,22 +408,22 @@ bool TJoinBase::DoInit(TContext& ctx, ISource* src) {
for (auto expr: JoinExprs) {
if (expr) {
TDeque<TNodePtr> conjQueue;
- conjQueue.push_back(expr);
- while (!conjQueue.empty()) {
- TNodePtr cur = conjQueue.front();
- conjQueue.pop_front();
- if (cur->GetOpName() == "And") {
- auto conj = dynamic_cast<const TCallNode*>(cur.Get());
- YQL_ENSURE(conj, "Invalid And operation node");
- conjQueue.insert(conjQueue.begin(), conj->GetArgs().begin(), conj->GetArgs().end());
- } else if (!InitKeysOrFilters(ctx, idx, cur)) {
+ conjQueue.push_back(expr);
+ while (!conjQueue.empty()) {
+ TNodePtr cur = conjQueue.front();
+ conjQueue.pop_front();
+ if (cur->GetOpName() == "And") {
+ auto conj = dynamic_cast<const TCallNode*>(cur.Get());
+ YQL_ENSURE(conj, "Invalid And operation node");
+ conjQueue.insert(conjQueue.begin(), conj->GetArgs().begin(), conj->GetArgs().end());
+ } else if (!InitKeysOrFilters(ctx, idx, cur)) {
return false;
}
}
- } else {
- if (!InitKeysOrFilters(ctx, idx, nullptr)) {
- return false;
- }
+ } else {
+ if (!InitKeysOrFilters(ctx, idx, nullptr)) {
+ return false;
+ }
}
++idx;
}
@@ -448,11 +448,11 @@ bool TJoinBase::DoInit(TContext& ctx, ISource* src) {
class TEquiJoin: public TJoinBase {
public:
TEquiJoin(TPosition pos, TVector<TSourcePtr>&& sources)
- : TJoinBase(pos, std::move(sources))
+ : TJoinBase(pos, std::move(sources))
{
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
TMap<std::pair<TString, TString>, TNodePtr> extraColumns;
TNodePtr joinTree;
for (auto& descr: JoinDescrs) {
@@ -491,19 +491,19 @@ public:
source->BuildFlattenColumns("row");
if (!flatten) {
- return nullptr;
- }
- auto block = Y(Y("let", "flatten", sourceNode));
+ return nullptr;
+ }
+ auto block = Y(Y("let", "flatten", sourceNode));
block = L(block, Y("let", "flatten", Y(useOrderedForSource ? "OrderedFlatMap" : "FlatMap", "flatten", BuildLambda(Pos, Y("row"), flatten, "res"))));
- sourceNode = Y("block", Q(L(block, Y("return", "flatten"))));
- }
+ sourceNode = Y("block", Q(L(block, Y("return", "flatten"))));
+ }
TNodePtr extraMembers;
for (auto it = extraColumns.lower_bound({ source->GetLabel(), "" }); it != extraColumns.end(); ++it) {
if (it->first.first != source->GetLabel()) {
break;
}
if (!extraMembers) {
- extraMembers = KeysGround ? KeysGround : Y();
+ extraMembers = KeysGround ? KeysGround : Y();
}
extraMembers = L(
extraMembers,
@@ -525,11 +525,11 @@ public:
}
removeMembers = L(
removeMembers,
- Y("let", "row", Y("ForceRemoveMember", "row", BuildQuotedAtom(Pos, DotJoin(it.first.first, it.first.second))))
+ Y("let", "row", Y("ForceRemoveMember", "row", BuildQuotedAtom(Pos, DotJoin(it.first.first, it.first.second))))
);
}
- auto options = Y();
- equiJoin = L(equiJoin, joinTree, Q(options));
+ auto options = Y();
+ equiJoin = L(equiJoin, joinTree, Q(options));
if (removeMembers) {
equiJoin = Y(ordered ? "OrderedMap" : "Map", equiJoin, BuildLambda(Pos, Y("row"), removeMembers, "row"));
}
@@ -537,30 +537,30 @@ public:
}
const THashMap<TString, THashSet<TString>>& GetSameKeysMap() const override {
- return SameKeyMap;
- }
-
+ return SameKeyMap;
+ }
+
const TSet<TString> GetJoinLabels() const override {
TSet<TString> labels;
- for (auto& source: Sources) {
- const auto label = source->GetLabel();
- YQL_ENSURE(label);
- labels.emplace(label);
- }
- return labels;
- }
-
- TPtr DoClone() const final {
+ for (auto& source: Sources) {
+ const auto label = source->GetLabel();
+ YQL_ENSURE(label);
+ labels.emplace(label);
+ }
+ return labels;
+ }
+
+ TPtr DoClone() const final {
TVector<TSourcePtr> clonedSources;
- for (auto& cur: Sources) {
- clonedSources.push_back(cur->CloneSource());
- }
- auto newSource = MakeIntrusive<TEquiJoin>(Pos, std::move(clonedSources));
- newSource->JoinOps = JoinOps;
- newSource->JoinExprs = CloneContainer(JoinExprs);
- return newSource;
- }
-
+ for (auto& cur: Sources) {
+ clonedSources.push_back(cur->CloneSource());
+ }
+ auto newSource = MakeIntrusive<TEquiJoin>(Pos, std::move(clonedSources));
+ newSource->JoinOps = JoinOps;
+ newSource->JoinExprs = CloneContainer(JoinExprs);
+ return newSource;
+ }
+
private:
TNodePtr GetColumnNames(
TContext& ctx,
@@ -596,7 +596,7 @@ private:
};
TSourcePtr BuildEquiJoin(TPosition pos, TVector<TSourcePtr>&& sources) {
- return new TEquiJoin(pos, std::move(sources));
+ return new TEquiJoin(pos, std::move(sources));
}
} // namespace NSQLTranslationV0
diff --git a/ydb/library/yql/sql/v0/list_builtin.h b/ydb/library/yql/sql/v0/list_builtin.h
index 21effebd74..9fc4f22ce6 100644
--- a/ydb/library/yql/sql/v0/list_builtin.h
+++ b/ydb/library/yql/sql/v0/list_builtin.h
@@ -22,11 +22,11 @@ public:
: TCallNode(pos, opName, args.size(), args.size(), args)
, OpName(opName)
, Args(args)
- {}
+ {}
bool DoInit(TContext& ctx, ISource* src) override = 0;
- TAstNode* Translate(TContext& ctx) const override;
+ TAstNode* Translate(TContext& ctx) const override;
protected:
const TString OpName;
@@ -36,40 +36,40 @@ protected:
inline TNodePtr GetIdentityLambda();
inline TNodePtr SkipEmpty(TNodePtr arg);
-
- void DoUpdateState() const override {
- State.Set(ENodeState::Aggregated, Args[0]->IsAggregated());
- }
+
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Aggregated, Args[0]->IsAggregated());
+ }
};
-class TListSortBuiltin final: public TListBuiltin {
+class TListSortBuiltin final: public TListBuiltin {
public:
TListSortBuiltin(TPosition pos, const TVector<TNodePtr>& args, bool asc)
: TListBuiltin(pos, "Sort", args)
, Asc(asc)
- {}
-
- bool DoInit(TContext& ctx, ISource* src) override;
-
- TNodePtr DoClone() const final {
- return new TListSortBuiltin(Pos, CloneContainer(Args), Asc);
+ {}
+
+ bool DoInit(TContext& ctx, ISource* src) override;
+
+ TNodePtr DoClone() const final {
+ return new TListSortBuiltin(Pos, CloneContainer(Args), Asc);
}
private:
bool Asc;
};
-class TListExtractBuiltin final: public TListBuiltin {
+class TListExtractBuiltin final: public TListBuiltin {
public:
TListExtractBuiltin(TPosition pos, const TVector<TNodePtr>& args)
: TListBuiltin(pos, "OrderedExtract", args)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override;
+ bool DoInit(TContext& ctx, ISource* src) override;
- TNodePtr DoClone() const final {
- return new TListExtractBuiltin(Pos, CloneContainer(Args));
- }
+ TNodePtr DoClone() const final {
+ return new TListExtractBuiltin(Pos, CloneContainer(Args));
+ }
};
class TListProcessBuiltin: public TListBuiltin {
@@ -88,39 +88,39 @@ protected:
const TString* OpLiteral;
};
-class TListMapBuiltin final: public TListProcessBuiltin {
+class TListMapBuiltin final: public TListProcessBuiltin {
public:
TListMapBuiltin(TPosition pos,
const TVector<TNodePtr>& args,
bool flat)
: TListProcessBuiltin(pos, flat ? "OrderedFlatMap" : "OrderedMap", args)
, Flat(flat)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override;
+ bool DoInit(TContext& ctx, ISource* src) override;
- TNodePtr DoClone() const final {
- return new TListMapBuiltin(Pos, CloneContainer(Args), Flat);
- }
+ TNodePtr DoClone() const final {
+ return new TListMapBuiltin(Pos, CloneContainer(Args), Flat);
+ }
protected:
virtual TNodePtr GetMapLambda();
private:
bool Flat;
};
-class TListFilterBuiltin final: public TListProcessBuiltin {
+class TListFilterBuiltin final: public TListProcessBuiltin {
public:
TListFilterBuiltin(TPosition pos,
const TVector<TNodePtr>& args)
: TListProcessBuiltin(pos, "OrderedFilter", args)
- {}
+ {}
bool DoInit(TContext& ctx, ISource* src) override;
-
- TNodePtr DoClone() const final {
- return new TListFilterBuiltin(Pos, CloneContainer(Args));
- }
+
+ TNodePtr DoClone() const final {
+ return new TListFilterBuiltin(Pos, CloneContainer(Args));
+ }
protected:
virtual TNodePtr GetFilterLambda();
};
@@ -151,41 +151,41 @@ protected:
virtual TNodePtr GetUpdateLambda();
};
-class TListFoldBuiltinImpl final: public TListFoldBuiltin {
+class TListFoldBuiltinImpl final: public TListFoldBuiltin {
public:
TListFoldBuiltinImpl(TPosition pos, const TString& opName, const TString& stateType, const TString& stateValue,
const ui32 argCount, const TVector<TNodePtr>& args)
- : TListFoldBuiltin(pos, opName, stateType, stateValue, argCount, args)
- {}
-
- TNodePtr DoClone() const final {
- return new TListFoldBuiltinImpl(Pos, OpName, StateType, StateValue, ArgCount, CloneContainer(Args));
- }
-};
-
-class TListCountBuiltin final: public TListFoldBuiltin {
-public:
+ : TListFoldBuiltin(pos, opName, stateType, stateValue, argCount, args)
+ {}
+
+ TNodePtr DoClone() const final {
+ return new TListFoldBuiltinImpl(Pos, OpName, StateType, StateValue, ArgCount, CloneContainer(Args));
+ }
+};
+
+class TListCountBuiltin final: public TListFoldBuiltin {
+public:
TListCountBuiltin(TPosition pos, const TVector<TNodePtr>& args)
: TListFoldBuiltin(pos, "Inc", "Uint64", "0", 1, args)
- {}
-
- TNodePtr DoClone() const final {
- return new TListCountBuiltin(Pos, CloneContainer(Args));
+ {}
+
+ TNodePtr DoClone() const final {
+ return new TListCountBuiltin(Pos, CloneContainer(Args));
}
private:
virtual TNodePtr GetUpdateLambda();
};
-class TListAvgBuiltin final: public TListFoldBuiltin {
+class TListAvgBuiltin final: public TListFoldBuiltin {
public:
TListAvgBuiltin(TPosition pos, const TVector<TNodePtr>& args)
: TListFoldBuiltin(pos, "Avg", "", "", 1, args)
{
}
- TNodePtr DoClone() const final {
- return new TListAvgBuiltin(Pos, CloneContainer(Args));
- }
+ TNodePtr DoClone() const final {
+ return new TListAvgBuiltin(Pos, CloneContainer(Args));
+ }
private:
bool DoInit(TContext& ctx, ISource* src) override;
@@ -194,32 +194,32 @@ private:
TNodePtr GetUpdateLambda() override;
};
-class TListHasBuiltin final: public TListFoldBuiltin {
+class TListHasBuiltin final: public TListFoldBuiltin {
public:
TListHasBuiltin(TPosition pos, const TVector<TNodePtr>& args)
: TListFoldBuiltin(pos, "==", "Bool", "false", 2, args)
{
}
- TNodePtr DoClone() const final {
- return new TListHasBuiltin(Pos, CloneContainer(Args));
- }
+ TNodePtr DoClone() const final {
+ return new TListHasBuiltin(Pos, CloneContainer(Args));
+ }
private:
TNodePtr GetUpdateLambda() override;
-
- void DoUpdateState() const override {
- bool isAggregated = true;
- for (const auto& arg: Args) {
- if (!arg->IsAggregated()) {
- isAggregated = false;
- break;
- }
- }
- State.Set(ENodeState::Aggregated, isAggregated);
- }
+
+ void DoUpdateState() const override {
+ bool isAggregated = true;
+ for (const auto& arg: Args) {
+ if (!arg->IsAggregated()) {
+ isAggregated = false;
+ break;
+ }
+ }
+ State.Set(ENodeState::Aggregated, isAggregated);
+ }
};
-class TListFold1Builtin final: public TListBuiltin {
+class TListFold1Builtin final: public TListBuiltin {
public:
TListFold1Builtin(TPosition pos,
const TString& opName,
@@ -231,10 +231,10 @@ public:
bool DoInit(TContext& ctx, ISource* src) override;
- TNodePtr DoClone() const final {
- return new TListFold1Builtin(Pos, OpName, CloneContainer(Args));
- }
-
+ TNodePtr DoClone() const final {
+ return new TListFold1Builtin(Pos, OpName, CloneContainer(Args));
+ }
+
protected:
virtual TNodePtr GetInitLambda();
@@ -251,7 +251,7 @@ public:
bool DoInit(TContext& ctx, ISource* src) override;
TNodePtr DoClone() const final {
- return new TListUniqBuiltin(Pos, CloneContainer(Args));
+ return new TListUniqBuiltin(Pos, CloneContainer(Args));
}
};
@@ -265,7 +265,7 @@ public:
bool DoInit(TContext& ctx, ISource* src) override;
TNodePtr DoClone() const final {
- return new TListCreateBuiltin(Pos, CloneContainer(Args));
+ return new TListCreateBuiltin(Pos, CloneContainer(Args));
}
};
diff --git a/ydb/library/yql/sql/v0/node.cpp b/ydb/library/yql/sql/v0/node.cpp
index 64ac60cdbc..57f0c6a561 100644
--- a/ydb/library/yql/sql/v0/node.cpp
+++ b/ydb/library/yql/sql/v0/node.cpp
@@ -17,15 +17,15 @@ using namespace NYql;
namespace NSQLTranslationV0 {
-TString ErrorDistinctWithoutCorrelation(const TString& column) {
- return TStringBuilder() << "DISTINCT columns for JOIN in SELECT should have table aliases (correlation name),"
- " add it if necessary to FROM section over 'AS <alias>' keyword and put it like '<alias>." << column << "'";
-}
-
-TString ErrorDistinctByGroupKey(const TString& column) {
- return TStringBuilder() << "Unable to use DISTINCT by grouping column: " << column << ". You should leave one of them.";
-}
-
+TString ErrorDistinctWithoutCorrelation(const TString& column) {
+ return TStringBuilder() << "DISTINCT columns for JOIN in SELECT should have table aliases (correlation name),"
+ " add it if necessary to FROM section over 'AS <alias>' keyword and put it like '<alias>." << column << "'";
+}
+
+TString ErrorDistinctByGroupKey(const TString& column) {
+ return TStringBuilder() << "Unable to use DISTINCT by grouping column: " << column << ". You should leave one of them.";
+}
+
TTableRef::TTableRef(const TString& refName, const TString& cluster, TNodePtr keys)
: RefName(refName)
, Cluster(cluster)
@@ -106,43 +106,43 @@ void INode::SetLabel(const TString& label) {
}
void INode::SetCountHint(bool isCount) {
- State.Set(ENodeState::CountHint, isCount);
+ State.Set(ENodeState::CountHint, isCount);
}
bool INode::GetCountHint() const {
- return State.Test(ENodeState::CountHint);
+ return State.Test(ENodeState::CountHint);
}
-bool INode::IsConstant() const {
- return HasState(ENodeState::Const);
+bool INode::IsConstant() const {
+ return HasState(ENodeState::Const);
}
-bool INode::IsAggregated() const {
- return HasState(ENodeState::Aggregated);
+bool INode::IsAggregated() const {
+ return HasState(ENodeState::Aggregated);
}
bool INode::IsAggregationKey() const {
return HasState(ENodeState::AggregationKey);
}
-bool INode::IsOverWindow() const {
- return HasState(ENodeState::OverWindow);
-}
-
-bool INode::IsNull() const {
+bool INode::IsOverWindow() const {
+ return HasState(ENodeState::OverWindow);
+}
+
+bool INode::IsNull() const {
+ return false;
+}
+
+bool INode::IsIntegerLiteral() const {
return false;
}
-bool INode::IsIntegerLiteral() const {
- return false;
-}
-
-bool INode::IsAsterisk() const {
+bool INode::IsAsterisk() const {
return false;
}
-const TString* INode::SubqueryAlias() const {
- return nullptr;
+const TString* INode::SubqueryAlias() const {
+ return nullptr;
}
TString INode::GetOpName() const {
@@ -165,10 +165,10 @@ const TString* INode::GetSourceName() const {
return nullptr;
}
-const TString* INode::GetAtomContent() const {
- return nullptr;
-}
-
+const TString* INode::GetAtomContent() const {
+ return nullptr;
+}
+
size_t INode::GetTupleSize() const {
return 0;
}
@@ -187,20 +187,20 @@ ISource* INode::GetSource() {
}
TVector<TNodePtr>* INode::ContentListPtr() {
- return nullptr;
-}
-
+ return nullptr;
+}
+
bool INode::Init(TContext& ctx, ISource* src) {
if (State.Test(ENodeState::Failed)) {
return false;
}
- if (!State.Test(ENodeState::Initialized)) {
- if (!DoInit(ctx, src)) {
+ if (!State.Test(ENodeState::Initialized)) {
+ if (!DoInit(ctx, src)) {
State.Set(ENodeState::Failed);
- return false;
- }
- State.Set(ENodeState::Initialized);
+ return false;
+ }
+ State.Set(ENodeState::Initialized);
}
return true;
}
@@ -212,7 +212,7 @@ bool INode::DoInit(TContext& ctx, ISource* src) {
}
TNodePtr INode::AstNode() const {
- return new TAstListNodeImpl(Pos);
+ return new TAstListNodeImpl(Pos);
}
TNodePtr INode::AstNode(TNodePtr node) const {
@@ -220,41 +220,41 @@ TNodePtr INode::AstNode(TNodePtr node) const {
}
TNodePtr INode::AstNode(const TString& str) const {
- return new TAstAtomNodeImpl(Pos, str, TNodeFlags::Default);
+ return new TAstAtomNodeImpl(Pos, str, TNodeFlags::Default);
}
TNodePtr INode::AstNode(TAstNode* node) const {
return new TAstDirectNode(node);
}
-TNodePtr INode::Clone() const {
- TNodePtr clone = DoClone();
- if (!clone) {
- clone = const_cast<INode*>(this);
- } else {
- YQL_ENSURE(!State.Test(ENodeState::Initialized), "Clone shold be for uninitialized or persistent node");
- clone->SetLabel(Label);
- }
- return clone;
-}
-
-TAggregationPtr INode::GetAggregation() const {
- return {};
-}
-
-INode::TPtr INode::WindowSpecFunc(const TPtr& type) const {
+TNodePtr INode::Clone() const {
+ TNodePtr clone = DoClone();
+ if (!clone) {
+ clone = const_cast<INode*>(this);
+ } else {
+ YQL_ENSURE(!State.Test(ENodeState::Initialized), "Clone shold be for uninitialized or persistent node");
+ clone->SetLabel(Label);
+ }
+ return clone;
+}
+
+TAggregationPtr INode::GetAggregation() const {
+ return {};
+}
+
+INode::TPtr INode::WindowSpecFunc(const TPtr& type) const {
Y_UNUSED(type);
- return {};
-}
-
-void INode::UseAsInner() {
+ return {};
+}
+
+void INode::UseAsInner() {
AsInner = true;
-}
-
-bool INode::UsedSubquery() const {
- return false;
-}
-
+}
+
+bool INode::UsedSubquery() const {
+ return false;
+}
+
bool INode::IsSelect() const {
return false;
}
@@ -264,24 +264,24 @@ TNodePtr INode::ShallowCopy() const {
return nullptr;
}
-void INode::DoUpdateState() const {
-}
-
-void INode::PrecacheState() const {
+void INode::DoUpdateState() const {
+}
+
+void INode::PrecacheState() const {
if (State.Test(ENodeState::Failed)) {
return;
}
- /// Not work right now! It's better use Init at first, because some kind of update depend on it
- /// \todo turn on and remove all issues
- //Y_VERIFY_DEBUG(State.Test(ENodeState::Initialized));
- if (State.Test(ENodeState::Precached)) {
- return;
- }
- DoUpdateState();
- State.Set(ENodeState::Precached);
-}
-
+ /// Not work right now! It's better use Init at first, because some kind of update depend on it
+ /// \todo turn on and remove all issues
+ //Y_VERIFY_DEBUG(State.Test(ENodeState::Initialized));
+ if (State.Test(ENodeState::Precached)) {
+ return;
+ }
+ DoUpdateState();
+ State.Set(ENodeState::Precached);
+}
+
void INode::DoAdd(TNodePtr node) {
Y_UNUSED(node);
Y_VERIFY_DEBUG(false, "Node is not expandable");
@@ -298,18 +298,18 @@ TAstAtomNode::~TAstAtomNode()
{
}
-void TAstAtomNode::DoUpdateState() const {
- State.Set(ENodeState::Const);
+void TAstAtomNode::DoUpdateState() const {
+ State.Set(ENodeState::Const);
}
TAstNode* TAstAtomNode::Translate(TContext& ctx) const {
return TAstNode::NewAtom(Pos, Content, *ctx.Pool, Flags);
}
-const TString* TAstAtomNode::GetAtomContent() const {
- return &Content;
-}
-
+const TString* TAstAtomNode::GetAtomContent() const {
+ return &Content;
+}
+
TAstDirectNode::TAstDirectNode(TAstNode* node)
: INode(node->GetPosition())
, Node(node)
@@ -322,7 +322,7 @@ TAstNode* TAstDirectNode::Translate(TContext& ctx) const {
}
TNodePtr BuildAtom(TPosition pos, const TString& content, ui32 flags) {
- return new TAstAtomNodeImpl(pos, content, flags);
+ return new TAstAtomNodeImpl(pos, content, flags);
}
TAstListNode::TAstListNode(TPosition pos)
@@ -364,50 +364,50 @@ TAstNode* TAstListNode::Translate(TContext& ctx) const {
}
void TAstListNode::UpdateStateByListNodes(const TVector<TNodePtr>& nodes) const {
- bool isConst = true;
- struct TAttributesFlags {
- bool has = false;
- bool all = true;
- };
- std::array<ENodeState, 3> checkStates = {{ENodeState::Aggregated, ENodeState::AggregationKey, ENodeState::OverWindow}};
- std::map<ENodeState, TAttributesFlags> flags;
- for (auto& node: nodes) {
- const bool isNodeConst = node->IsConstant();
- for (auto state: checkStates) {
- if (node->HasState(state)) {
- flags[state].has = true;
- } else if (!isNodeConst) {
- isConst = false;
- flags[state].all = false;
- }
- }
- }
- State.Set(ENodeState::Const, isConst);
- for (auto& flag: flags) {
- State.Set(flag.first, flag.second.has && flag.second.all);
- }
-}
-
-void TAstListNode::DoUpdateState() const {
- UpdateStateByListNodes(Nodes);
-}
-
+ bool isConst = true;
+ struct TAttributesFlags {
+ bool has = false;
+ bool all = true;
+ };
+ std::array<ENodeState, 3> checkStates = {{ENodeState::Aggregated, ENodeState::AggregationKey, ENodeState::OverWindow}};
+ std::map<ENodeState, TAttributesFlags> flags;
+ for (auto& node: nodes) {
+ const bool isNodeConst = node->IsConstant();
+ for (auto state: checkStates) {
+ if (node->HasState(state)) {
+ flags[state].has = true;
+ } else if (!isNodeConst) {
+ isConst = false;
+ flags[state].all = false;
+ }
+ }
+ }
+ State.Set(ENodeState::Const, isConst);
+ for (auto& flag: flags) {
+ State.Set(flag.first, flag.second.has && flag.second.all);
+ }
+}
+
+void TAstListNode::DoUpdateState() const {
+ UpdateStateByListNodes(Nodes);
+}
+
TAstListNode::TAstListNode(const TAstListNode& node)
: INode(node.Pos)
, Nodes(node.Nodes)
{
Label = node.Label;
- State = node.State;
+ State = node.State;
}
TAstListNode::TAstListNode(TPosition pos, TVector<TNodePtr>&& nodes)
- : INode(pos)
- , Nodes(std::move(nodes))
-{
-}
-
+ : INode(pos)
+ , Nodes(std::move(nodes))
+{
+}
+
TNodePtr TAstListNode::ShallowCopy() const {
- return new TAstListNodeImpl(Pos, Nodes);
+ return new TAstListNodeImpl(Pos, Nodes);
}
void TAstListNode::DoAdd(TNodePtr node) {
@@ -416,26 +416,26 @@ void TAstListNode::DoAdd(TNodePtr node) {
Nodes.push_back(node);
}
-TAstListNodeImpl::TAstListNodeImpl(TPosition pos)
- : TAstListNode(pos)
-{}
-
+TAstListNodeImpl::TAstListNodeImpl(TPosition pos)
+ : TAstListNode(pos)
+{}
+
TAstListNodeImpl::TAstListNodeImpl(TPosition pos, TVector<TNodePtr> nodes)
- : TAstListNode(pos)
-{
- Nodes.swap(nodes);
-}
-
-TNodePtr TAstListNodeImpl::DoClone() const {
- return new TAstListNodeImpl(Pos, CloneContainer(Nodes));
-}
-
+ : TAstListNode(pos)
+{
+ Nodes.swap(nodes);
+}
+
+TNodePtr TAstListNodeImpl::DoClone() const {
+ return new TAstListNodeImpl(Pos, CloneContainer(Nodes));
+}
+
bool ValidateAllNodesForAggregation(TContext& ctx, const TVector<TNodePtr>& nodes) {
for (auto& node: nodes) {
if (node->IsConstant()) {
continue;
}
- if (!node->IsAggregated() && !node->IsOverWindow()) {
+ if (!node->IsAggregated() && !node->IsOverWindow()) {
ctx.Error(node->GetPos()) << "Expression has to be an aggregation function or key column, because aggregation is used elsewhere in this subquery";
return false;
}
@@ -475,45 +475,45 @@ const TVector<TNodePtr>& TCallNode::GetArgs() const {
return Args;
}
-void TCallNode::DoUpdateState() const {
- UpdateStateByListNodes(Args);
-}
-
+void TCallNode::DoUpdateState() const {
+ UpdateStateByListNodes(Args);
+}
+
TString TCallNode::GetCallExplain() const {
- auto derivedName = GetOpName();
- TStringBuilder sb;
- sb << derivedName << "()";
- if (derivedName != OpName) {
- sb << ", converted to " << OpName << "()";
- }
+ auto derivedName = GetOpName();
+ TStringBuilder sb;
+ sb << derivedName << "()";
+ if (derivedName != OpName) {
+ sb << ", converted to " << OpName << "()";
+ }
return std::move(sb);
-}
-
-bool TCallNode::ValidateArguments(TContext& ctx) const {
+}
+
+bool TCallNode::ValidateArguments(TContext& ctx) const {
const auto argsCount = static_cast<i32>(Args.size());
if (MinArgs >= 0 && MaxArgs == MinArgs && argsCount != MinArgs) {
- ctx.Error(Pos) << GetCallExplain() << " requires exactly " << MinArgs << " arguments, given: " << Args.size();
+ ctx.Error(Pos) << GetCallExplain() << " requires exactly " << MinArgs << " arguments, given: " << Args.size();
return false;
}
if (MinArgs >= 0 && argsCount < MinArgs) {
- ctx.Error(Pos) << GetCallExplain() << " requires at least " << MinArgs << " arguments, given: " << Args.size();
+ ctx.Error(Pos) << GetCallExplain() << " requires at least " << MinArgs << " arguments, given: " << Args.size();
return false;
}
if (MaxArgs >= 0 && argsCount > MaxArgs) {
- ctx.Error(Pos) << GetCallExplain() << " requires at most " << MaxArgs << " arguments, given: " << Args.size();
+ ctx.Error(Pos) << GetCallExplain() << " requires at most " << MaxArgs << " arguments, given: " << Args.size();
+ return false;
+ }
+
+ return true;
+}
+
+bool TCallNode::DoInit(TContext& ctx, ISource* src) {
+ if (!ValidateArguments(ctx)) {
return false;
}
- return true;
-}
-
-bool TCallNode::DoInit(TContext& ctx, ISource* src) {
- if (!ValidateArguments(ctx)) {
- return false;
- }
-
bool hasError = false;
for (auto& arg: Args) {
if (!arg->Init(ctx, src)) {
@@ -521,7 +521,7 @@ bool TCallNode::DoInit(TContext& ctx, ISource* src) {
continue;
}
}
-
+
if (hasError) {
return false;
}
@@ -532,17 +532,17 @@ bool TCallNode::DoInit(TContext& ctx, ISource* src) {
}
TCallNodeImpl::TCallNodeImpl(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args)
- : TCallNode(pos, opName, minArgs, maxArgs, args)
-{}
-
+ : TCallNode(pos, opName, minArgs, maxArgs, args)
+{}
+
TCallNodeImpl::TCallNodeImpl(TPosition pos, const TString& opName, const TVector<TNodePtr>& args)
- : TCallNode(pos, opName, args.size(), args.size(), args)
-{}
-
-TCallNode::TPtr TCallNodeImpl::DoClone() const {
- return new TCallNodeImpl(GetPos(), OpName, MinArgs, MaxArgs, CloneContainer(Args));
-}
-
+ : TCallNode(pos, opName, args.size(), args.size(), args)
+{}
+
+TCallNode::TPtr TCallNodeImpl::DoClone() const {
+ return new TCallNodeImpl(GetPos(), OpName, MinArgs, MaxArgs, CloneContainer(Args));
+}
+
TCallNodeDepArgs::TCallNodeDepArgs(ui32 reqArgsCount, TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args)
: TCallNode(pos, opName, minArgs, maxArgs, args)
, ReqArgsCount(reqArgsCount)
@@ -568,43 +568,43 @@ bool TCallNodeDepArgs::DoInit(TContext& ctx, ISource* src) {
return true;
}
-TCallDirectRow::TPtr TCallDirectRow::DoClone() const {
- return new TCallDirectRow(Pos, OpName, CloneContainer(Args));
-}
-
+TCallDirectRow::TPtr TCallDirectRow::DoClone() const {
+ return new TCallDirectRow(Pos, OpName, CloneContainer(Args));
+}
+
TCallDirectRow::TCallDirectRow(TPosition pos, const TString& opName, const TVector<TNodePtr>& args)
- : TCallNode(pos, opName, 0, 0, args)
-{}
-
-bool TCallDirectRow::DoInit(TContext& ctx, ISource* src) {
- if (!src) {
- ctx.Error(Pos) << "Unable to use function: " << OpName << " without source";
- return false;
- }
- if (src->IsCompositeSource() || src->GetJoin() || src->HasAggregations() || src->IsFlattenByColumns() || src->IsOverWindowSource()) {
- ctx.Error(Pos) << "Failed to use function: " << OpName << " with aggregation, join, flatten by or window functions";
- return false;
- }
+ : TCallNode(pos, opName, 0, 0, args)
+{}
+
+bool TCallDirectRow::DoInit(TContext& ctx, ISource* src) {
+ if (!src) {
+ ctx.Error(Pos) << "Unable to use function: " << OpName << " without source";
+ return false;
+ }
+ if (src->IsCompositeSource() || src->GetJoin() || src->HasAggregations() || src->IsFlattenByColumns() || src->IsOverWindowSource()) {
+ ctx.Error(Pos) << "Failed to use function: " << OpName << " with aggregation, join, flatten by or window functions";
+ return false;
+ }
if (!TCallNode::DoInit(ctx, src)) {
return false;
}
Nodes.push_back(Y("DependsOn", "row"));
return true;
-}
-
-void TCallDirectRow::DoUpdateState() const {
- State.Set(ENodeState::Const, false);
-}
-
-void TWinAggrEmulation::DoUpdateState() const {
- State.Set(ENodeState::OverWindow, true);
-}
-
-bool TWinAggrEmulation::DoInit(TContext& ctx, ISource* src) {
+}
+
+void TCallDirectRow::DoUpdateState() const {
+ State.Set(ENodeState::Const, false);
+}
+
+void TWinAggrEmulation::DoUpdateState() const {
+ State.Set(ENodeState::OverWindow, true);
+}
+
+bool TWinAggrEmulation::DoInit(TContext& ctx, ISource* src) {
if (!src) {
ctx.Error(Pos) << "Unable to use window function: " << OpName << " without source";
return false;
- }
+ }
if (!src->IsOverWindowSource()) {
ctx.Error(Pos) << "Failed to use window function: " << OpName << " without window specification";
@@ -617,53 +617,53 @@ bool TWinAggrEmulation::DoInit(TContext& ctx, ISource* src) {
FuncAlias = "_yql_" + src->MakeLocalName(OpName);
src->AddTmpWindowColumn(FuncAlias);
- ctx.PushBlockShortcuts();
- if (!TCallNode::DoInit(ctx, src)) {
- return false;
- }
- WinAggrGround = ctx.GroundBlockShortcuts(Pos);
- Nodes.clear();
- Add("Member", "row", Q(FuncAlias));
- return true;
-}
-
-INode::TPtr TWinAggrEmulation::WindowSpecFunc(const TPtr& type) const {
- auto result = Y(OpName, type);
- for (const auto& arg: Args) {
- result = L(result, arg);
- }
- return Q(Y(Q(FuncAlias), result));
-}
-
+ ctx.PushBlockShortcuts();
+ if (!TCallNode::DoInit(ctx, src)) {
+ return false;
+ }
+ WinAggrGround = ctx.GroundBlockShortcuts(Pos);
+ Nodes.clear();
+ Add("Member", "row", Q(FuncAlias));
+ return true;
+}
+
+INode::TPtr TWinAggrEmulation::WindowSpecFunc(const TPtr& type) const {
+ auto result = Y(OpName, type);
+ for (const auto& arg: Args) {
+ result = L(result, arg);
+ }
+ return Q(Y(Q(FuncAlias), result));
+}
+
TWinAggrEmulation::TWinAggrEmulation(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args)
- : TCallNode(pos, opName, minArgs, maxArgs, args)
- , FuncAlias(opName)
-{}
-
+ : TCallNode(pos, opName, minArgs, maxArgs, args)
+ , FuncAlias(opName)
+{}
+
TWinRowNumber::TWinRowNumber(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args)
- : TWinAggrEmulation(pos, opName, minArgs, maxArgs, args)
-{}
-
+ : TWinAggrEmulation(pos, opName, minArgs, maxArgs, args)
+{}
+
TWinLeadLag::TWinLeadLag(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args)
- : TWinAggrEmulation(pos, opName, minArgs, maxArgs, args)
-{}
-
-bool TWinLeadLag::DoInit(TContext& ctx, ISource* src) {
- if (Args.size() >= 2) {
- if (!Args[1]->IsIntegerLiteral()) {
- ctx.Error(Args[1]->GetPos()) << "Expected integer literal as second parameter of " << OpName << "( ) function";
- return false;
- }
- }
- if (!TWinAggrEmulation::DoInit(ctx, src)) {
- return false;
- }
- if (Args.size() >= 1) {
- Args[0] = BuildLambda(Pos, Y("row"), GroundWithExpr(WinAggrGround, Args[0]));
- }
- return true;
-}
-
+ : TWinAggrEmulation(pos, opName, minArgs, maxArgs, args)
+{}
+
+bool TWinLeadLag::DoInit(TContext& ctx, ISource* src) {
+ if (Args.size() >= 2) {
+ if (!Args[1]->IsIntegerLiteral()) {
+ ctx.Error(Args[1]->GetPos()) << "Expected integer literal as second parameter of " << OpName << "( ) function";
+ return false;
+ }
+ }
+ if (!TWinAggrEmulation::DoInit(ctx, src)) {
+ return false;
+ }
+ if (Args.size() >= 1) {
+ Args[0] = BuildLambda(Pos, Y("row"), GroundWithExpr(WinAggrGround, Args[0]));
+ }
+ return true;
+}
+
class TQuotedAtomNode: public TAstListNode {
public:
TQuotedAtomNode(TPosition pos, const TString& content, ui32 flags)
@@ -672,15 +672,15 @@ public:
Add("quote", BuildAtom(pos, content, flags));
}
-protected:
- TQuotedAtomNode(const TQuotedAtomNode& other)
- : TAstListNode(other.Pos)
+protected:
+ TQuotedAtomNode(const TQuotedAtomNode& other)
+ : TAstListNode(other.Pos)
{
- Nodes = CloneContainer(other.Nodes);
+ Nodes = CloneContainer(other.Nodes);
+ }
+ TPtr DoClone() const final {
+ return new TQuotedAtomNode(*this);
}
- TPtr DoClone() const final {
- return new TQuotedAtomNode(*this);
- }
};
TNodePtr BuildQuotedAtom(TPosition pos, const TString& content, ui32 flags) {
@@ -692,25 +692,25 @@ bool TColumns::Add(const TString* column, bool countHint, bool isArtificial, boo
if (!countHint) {
SetAll();
}
- } else if (!All) {
+ } else if (!All) {
if (column->EndsWith('*')) {
QualifiedAll = true;
}
- bool inserted = false;
- if (isArtificial) {
+ bool inserted = false;
+ if (isArtificial) {
inserted = Artificial.insert(*column).second;
- } else {
+ } else {
inserted = Real.insert(*column).second;
- }
- if (!isReliable) {
- HasUnreliable = true;
- }
+ }
+ if (!isReliable) {
+ HasUnreliable = true;
+ }
if (std::find(List.begin(), List.end(), *column) == List.end()) {
List.push_back(*column);
NamedColumns.push_back(hasName);
- }
- return inserted;
+ }
+ return inserted;
}
return All;
}
@@ -722,84 +722,84 @@ void TColumns::Merge(const TColumns& columns) {
for (auto& c: columns.List) {
if (columns.Real.contains(c)) {
Add(&c, false, false);
- }
+ }
if (columns.Artificial.contains(c)) {
Add(&c, false, true);
- }
+ }
}
- HasUnreliable |= columns.HasUnreliable;
+ HasUnreliable |= columns.HasUnreliable;
}
}
void TColumns::SetPrefix(const TString& prefix) {
- Y_VERIFY_DEBUG(!prefix.empty());
+ Y_VERIFY_DEBUG(!prefix.empty());
auto addPrefixFunc = [&prefix](const TString& str) {
- return prefix + "." + str;
- };
+ return prefix + "." + str;
+ };
TSet<TString> newReal;
TSet<TString> newArtificial;
TVector<TString> newList;
- std::transform(Real.begin(), Real.end(), std::inserter(newReal, newReal.begin()), addPrefixFunc);
- std::transform(Artificial.begin(), Artificial.end(), std::inserter(newArtificial, newArtificial.begin()), addPrefixFunc);
- std::transform(List.begin(), List.end(), std::back_inserter(newList), addPrefixFunc);
- newReal.swap(Real);
- newArtificial.swap(Artificial);
- newList.swap(List);
-}
-
+ std::transform(Real.begin(), Real.end(), std::inserter(newReal, newReal.begin()), addPrefixFunc);
+ std::transform(Artificial.begin(), Artificial.end(), std::inserter(newArtificial, newArtificial.begin()), addPrefixFunc);
+ std::transform(List.begin(), List.end(), std::back_inserter(newList), addPrefixFunc);
+ newReal.swap(Real);
+ newArtificial.swap(Artificial);
+ newList.swap(List);
+}
+
void TColumns::SetAll() {
All = true;
- Real.clear();
+ Real.clear();
List.clear();
- Artificial.clear();
+ Artificial.clear();
}
-bool TColumns::IsColumnPossible(TContext& ctx, const TString& name) {
+bool TColumns::IsColumnPossible(TContext& ctx, const TString& name) {
if (All || Real.contains(name) || Artificial.contains(name)) {
- return true;
- }
- if (QualifiedAll) {
- if (ctx.SimpleColumns) {
- return true;
- }
+ return true;
+ }
+ if (QualifiedAll) {
+ if (ctx.SimpleColumns) {
+ return true;
+ }
for (const auto& real: Real) {
- const auto pos = real.find_first_of("*");
- if (pos == TString::npos) {
- continue;
- }
- if (name.StartsWith(real.substr(0, pos))) {
- return true;
- }
- }
- }
- return false;
-}
-
-TSortSpecificationPtr TSortSpecification::Clone() const {
- auto res = MakeIntrusive<TSortSpecification>();
- res->OrderExpr = OrderExpr->Clone();
- res->Ascending = Ascending;
- return res;
-}
-
-TWindowSpecificationPtr TWindowSpecification::Clone() const {
- auto res = MakeIntrusive<TWindowSpecification>();
- res->ExistingWindowName = ExistingWindowName;
- res->Partitions = CloneContainer(Partitions);
- res->OrderBy = CloneContainer(OrderBy);
- res->Frame = Frame;
- return res;
-}
-
-THoppingWindowSpecPtr THoppingWindowSpec::Clone() const {
- auto res = MakeIntrusive<THoppingWindowSpec>();
- res->TimeExtractor = TimeExtractor->Clone();
+ const auto pos = real.find_first_of("*");
+ if (pos == TString::npos) {
+ continue;
+ }
+ if (name.StartsWith(real.substr(0, pos))) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+TSortSpecificationPtr TSortSpecification::Clone() const {
+ auto res = MakeIntrusive<TSortSpecification>();
+ res->OrderExpr = OrderExpr->Clone();
+ res->Ascending = Ascending;
+ return res;
+}
+
+TWindowSpecificationPtr TWindowSpecification::Clone() const {
+ auto res = MakeIntrusive<TWindowSpecification>();
+ res->ExistingWindowName = ExistingWindowName;
+ res->Partitions = CloneContainer(Partitions);
+ res->OrderBy = CloneContainer(OrderBy);
+ res->Frame = Frame;
+ return res;
+}
+
+THoppingWindowSpecPtr THoppingWindowSpec::Clone() const {
+ auto res = MakeIntrusive<THoppingWindowSpec>();
+ res->TimeExtractor = TimeExtractor->Clone();
res->Hop = Hop->Clone();
res->Interval = Interval->Clone();
res->Delay = Delay->Clone();
- return res;
-}
-
+ return res;
+}
+
TColumnNode::TColumnNode(TPosition pos, const TString& column, const TString& source)
: INode(pos)
, ColumnName(column)
@@ -822,26 +822,26 @@ bool TColumnNode::IsAsterisk() const {
return ColumnName == "*";
}
-bool TColumnNode::IsArtificial() const {
- return Artificial;
-}
-
+bool TColumnNode::IsArtificial() const {
+ return Artificial;
+}
+
const TString* TColumnNode::GetColumnName() const {
return UseSourceAsColumn ? &Source : (ColumnExpr ? nullptr : &ColumnName);
}
const TString* TColumnNode::GetSourceName() const {
- return UseSourceAsColumn ? &Empty : &Source;
+ return UseSourceAsColumn ? &Empty : &Source;
}
bool TColumnNode::DoInit(TContext& ctx, ISource* src) {
- if (src) {
- YQL_ENSURE(!State.Test(ENodeState::Initialized)); /// should be not initialized or Aggregated already invalid
- if (src->ShouldUseSourceAsColumn(*GetSourceName())) {
- if (!IsAsterisk() && IsReliable()) {
- SetUseSourceAsColumn();
- }
- }
+ if (src) {
+ YQL_ENSURE(!State.Test(ENodeState::Initialized)); /// should be not initialized or Aggregated already invalid
+ if (src->ShouldUseSourceAsColumn(*GetSourceName())) {
+ if (!IsAsterisk() && IsReliable()) {
+ SetUseSourceAsColumn();
+ }
+ }
if (GetColumnName()) {
auto fullName = Source ? DotJoin(Source, *GetColumnName()) : *GetColumnName();
@@ -850,84 +850,84 @@ bool TColumnNode::DoInit(TContext& ctx, ISource* src) {
ResetColumn(alias, {});
}
Artificial = !Source && src->IsExprAlias(*GetColumnName());
- }
+ }
- if (!src->AddColumn(ctx, *this)) {
- return false;
- }
+ if (!src->AddColumn(ctx, *this)) {
+ return false;
+ }
if (GetColumnName()) {
if (src->GetJoin() && Source) {
GroupKey = src->IsGroupByColumn(DotJoin(Source, *GetColumnName()));
} else {
GroupKey = src->IsGroupByColumn(*GetColumnName()) || src->IsAlias(EExprSeat::GroupBy, *GetColumnName());
}
- }
+ }
}
if (IsAsterisk()) {
Node = AstNode("row");
} else {
Node = Y(Reliable && !UseSource ? "Member" : "SqlColumn", "row", ColumnExpr ?
Y("EvaluateAtom", ColumnExpr) : BuildQuotedAtom(Pos, *GetColumnName()));
- if (UseSource) {
- YQL_ENSURE(Source);
- Node = L(Node, BuildQuotedAtom(Pos, Source));
- }
+ if (UseSource) {
+ YQL_ENSURE(Source);
+ Node = L(Node, BuildQuotedAtom(Pos, Source));
+ }
}
return Node->Init(ctx, src);
}
-void TColumnNode::SetUseSourceAsColumn() {
- YQL_ENSURE(!State.Test(ENodeState::Initialized)); /// should be not initialized or Aggregated already invalid
- YQL_ENSURE(!IsAsterisk());
- UseSourceAsColumn = true;
-}
-
-void TColumnNode::ResetAsReliable() {
- Reliable = true;
-}
-
-void TColumnNode::SetAsNotReliable() {
- Reliable = false;
-}
-
-void TColumnNode::SetUseSource() {
- UseSource = true;
-}
-
-bool TColumnNode::IsUseSourceAsColumn() const {
- return UseSourceAsColumn;
-}
-
-bool TColumnNode::IsReliable() const {
- return Reliable;
-}
-
-TNodePtr TColumnNode::DoClone() const {
- YQL_ENSURE(!Node, "TColumnNode::Clone: Node should not be initialized");
+void TColumnNode::SetUseSourceAsColumn() {
+ YQL_ENSURE(!State.Test(ENodeState::Initialized)); /// should be not initialized or Aggregated already invalid
+ YQL_ENSURE(!IsAsterisk());
+ UseSourceAsColumn = true;
+}
+
+void TColumnNode::ResetAsReliable() {
+ Reliable = true;
+}
+
+void TColumnNode::SetAsNotReliable() {
+ Reliable = false;
+}
+
+void TColumnNode::SetUseSource() {
+ UseSource = true;
+}
+
+bool TColumnNode::IsUseSourceAsColumn() const {
+ return UseSourceAsColumn;
+}
+
+bool TColumnNode::IsReliable() const {
+ return Reliable;
+}
+
+TNodePtr TColumnNode::DoClone() const {
+ YQL_ENSURE(!Node, "TColumnNode::Clone: Node should not be initialized");
auto copy = ColumnExpr ? new TColumnNode(Pos, ColumnExpr, Source) : new TColumnNode(Pos, ColumnName, Source);
- copy->GroupKey = GroupKey;
- copy->Artificial = Artificial;
- copy->Reliable = Reliable;
- copy->UseSource = UseSource;
- copy->UseSourceAsColumn = UseSourceAsColumn;
- return copy;
-}
-
-void TColumnNode::DoUpdateState() const {
- State.Set(ENodeState::Const, false);
- State.Set(ENodeState::Aggregated, GroupKey);
- State.Set(ENodeState::AggregationKey, GroupKey);
-}
-
+ copy->GroupKey = GroupKey;
+ copy->Artificial = Artificial;
+ copy->Reliable = Reliable;
+ copy->UseSource = UseSource;
+ copy->UseSourceAsColumn = UseSourceAsColumn;
+ return copy;
+}
+
+void TColumnNode::DoUpdateState() const {
+ State.Set(ENodeState::Const, false);
+ State.Set(ENodeState::Aggregated, GroupKey);
+ State.Set(ENodeState::AggregationKey, GroupKey);
+}
+
TAstNode* TColumnNode::Translate(TContext& ctx) const {
return Node->Translate(ctx);
}
void TColumnNode::ResetColumn(const TString& column, const TString& source) {
- YQL_ENSURE(!State.Test(ENodeState::Initialized)); /// should be not initialized
- Reliable = true;
- UseSource = false;
- UseSourceAsColumn = false;
+ YQL_ENSURE(!State.Test(ENodeState::Initialized)); /// should be not initialized
+ Reliable = true;
+ UseSource = false;
+ UseSourceAsColumn = false;
ColumnName = column;
ColumnExpr = nullptr;
Source = source;
@@ -944,7 +944,7 @@ void TColumnNode::ResetColumn(const TNodePtr& column, const TString& source) {
}
const TString TColumnNode::Empty;
-
+
TNodePtr BuildColumn(TPosition pos, const TString& column, const TString& source) {
return new TColumnNode(pos, column, source);
}
@@ -981,11 +981,11 @@ bool IAggregation::IsDistinct() const {
return !DistinctKey.empty();
}
-void IAggregation::DoUpdateState() const {
- State.Set(ENodeState::Aggregated, AggMode == EAggregateMode::Normal);
- State.Set(ENodeState::OverWindow, AggMode == EAggregateMode::OverWindow);
-}
-
+void IAggregation::DoUpdateState() const {
+ State.Set(ENodeState::Aggregated, AggMode == EAggregateMode::Normal);
+ State.Set(ENodeState::OverWindow, AggMode == EAggregateMode::OverWindow);
+}
+
const TString* IAggregation::GetGenericKey() const {
return nullptr;
}
@@ -999,7 +999,7 @@ const TString& IAggregation::GetName() const {
}
IAggregation::IAggregation(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode)
- : INode(pos), Name(name), Func(func), AggMode(aggMode)
+ : INode(pos), Name(name), Func(func), AggMode(aggMode)
{}
TAstNode* IAggregation::Translate(TContext& ctx) const {
@@ -1008,10 +1008,10 @@ TAstNode* IAggregation::Translate(TContext& ctx) const {
return nullptr;
}
-TNodePtr IAggregation::AggregationTraits(const TNodePtr& type) const {
- const bool distinct = AggMode == EAggregateMode::Distinct;
- const auto listType = distinct ? Y("ListType", Y("StructMemberType", Y("ListItemType", type), BuildQuotedAtom(Pos, DistinctKey))) : type;
- return distinct ? Q(Y(Q(Name), GetApply(listType), BuildQuotedAtom(Pos, DistinctKey))): Q(Y(Q(Name), GetApply(listType)));
+TNodePtr IAggregation::AggregationTraits(const TNodePtr& type) const {
+ const bool distinct = AggMode == EAggregateMode::Distinct;
+ const auto listType = distinct ? Y("ListType", Y("StructMemberType", Y("ListItemType", type), BuildQuotedAtom(Pos, DistinctKey))) : type;
+ return distinct ? Q(Y(Q(Name), GetApply(listType), BuildQuotedAtom(Pos, DistinctKey))): Q(Y(Q(Name), GetApply(listType)));
}
void IAggregation::AddFactoryArguments(TNodePtr& apply) const {
@@ -1022,11 +1022,11 @@ std::vector<ui32> IAggregation::GetFactoryColumnIndices() const {
return {0u};
}
-TNodePtr IAggregation::WindowTraits(const TNodePtr& type) const {
- YQL_ENSURE(AggMode == EAggregateMode::OverWindow, "Windows traits is unavailable");
- return Q(Y(Q(Name), GetApply(type)));
-}
-
+TNodePtr IAggregation::WindowTraits(const TNodePtr& type) const {
+ YQL_ENSURE(AggMode == EAggregateMode::OverWindow, "Windows traits is unavailable");
+ return Q(Y(Q(Name), GetApply(type)));
+}
+
ISource::ISource(TPosition pos)
: INode(pos)
{
@@ -1036,19 +1036,19 @@ ISource::~ISource()
{
}
-TSourcePtr ISource::CloneSource() const {
- Y_VERIFY_DEBUG(dynamic_cast<ISource*>(Clone().Get()), "Cloned node is no source");
- TSourcePtr result = static_cast<ISource*>(Clone().Get());
- for (auto curFilter: Filters) {
- result->Filters.emplace_back(curFilter->Clone());
- }
- for (int i = 0; i < static_cast<int>(EExprSeat::Max); ++i) {
- result->NamedExprs[i] = CloneContainer(NamedExprs[i]);
- }
- result->FlattenColumns = FlattenColumns;
- return result;
-}
-
+TSourcePtr ISource::CloneSource() const {
+ Y_VERIFY_DEBUG(dynamic_cast<ISource*>(Clone().Get()), "Cloned node is no source");
+ TSourcePtr result = static_cast<ISource*>(Clone().Get());
+ for (auto curFilter: Filters) {
+ result->Filters.emplace_back(curFilter->Clone());
+ }
+ for (int i = 0; i < static_cast<int>(EExprSeat::Max); ++i) {
+ result->NamedExprs[i] = CloneContainer(NamedExprs[i]);
+ }
+ result->FlattenColumns = FlattenColumns;
+ return result;
+}
+
bool ISource::IsFake() const {
return false;
}
@@ -1062,23 +1062,23 @@ const TColumns* ISource::GetColumns() const {
}
void ISource::GetInputTables(TTableList& tableList) const {
- for (auto srcPtr: UsedSources) {
+ for (auto srcPtr: UsedSources) {
srcPtr->GetInputTables(tableList);
- }
+ }
return;
}
-TMaybe<bool> ISource::AddColumn(TContext& ctx, TColumnNode& column) {
- if (column.IsReliable()) {
- ctx.Error(Pos) << "Source does not allow column references";
- }
- return {};
+TMaybe<bool> ISource::AddColumn(TContext& ctx, TColumnNode& column) {
+ if (column.IsReliable()) {
+ ctx.Error(Pos) << "Source does not allow column references";
+ }
+ return {};
+}
+
+void ISource::FinishColumns() {
}
-void ISource::FinishColumns() {
-}
-
-
+
bool ISource::AddFilter(TContext& ctx, TNodePtr filter) {
Y_UNUSED(ctx);
Filters.push_back(filter);
@@ -1086,59 +1086,59 @@ bool ISource::AddFilter(TContext& ctx, TNodePtr filter) {
}
bool ISource::AddGroupKey(TContext& ctx, const TString& column) {
- if (!GroupKeys.insert(column).second) {
+ if (!GroupKeys.insert(column).second) {
ctx.Error() << "Duplicate grouping column: " << column;
return false;
}
- OrderedGroupKeys.push_back(column);
+ OrderedGroupKeys.push_back(column);
return true;
}
bool ISource::AddExpressions(TContext& ctx, const TVector<TNodePtr>& expressions, EExprSeat exprSeat) {
- YQL_ENSURE(exprSeat < EExprSeat::Max);
+ YQL_ENSURE(exprSeat < EExprSeat::Max);
TSet<TString> names;
- for (const auto& expr: expressions) {
- const auto& alias = expr->GetLabel();
- const auto& columnNamePtr = expr->GetColumnName();
- if (alias) {
- if (!ExprAliases.emplace(alias).second) {
- ctx.Error(expr->GetPos()) << "Duplicate alias found: " << alias << " in " << exprSeat << " section";
- return false;
- }
+ for (const auto& expr: expressions) {
+ const auto& alias = expr->GetLabel();
+ const auto& columnNamePtr = expr->GetColumnName();
+ if (alias) {
+ if (!ExprAliases.emplace(alias).second) {
+ ctx.Error(expr->GetPos()) << "Duplicate alias found: " << alias << " in " << exprSeat << " section";
+ return false;
+ }
if (names.contains(alias)) {
- ctx.Error(expr->GetPos()) << "Collision between alias and column name: " << alias << " in " << exprSeat << " section";
- return false;
- }
- }
- if (columnNamePtr) {
- const auto& sourceName = *expr->GetSourceName();
- auto columnName = *columnNamePtr;
- if (sourceName) {
- columnName = DotJoin(sourceName, columnName);
- }
- if (!names.emplace(columnName).second) {
- ctx.Error(expr->GetPos()) << "Duplicate column name found: " << columnName << " in " << exprSeat << " section";
- return false;
- }
+ ctx.Error(expr->GetPos()) << "Collision between alias and column name: " << alias << " in " << exprSeat << " section";
+ return false;
+ }
+ }
+ if (columnNamePtr) {
+ const auto& sourceName = *expr->GetSourceName();
+ auto columnName = *columnNamePtr;
+ if (sourceName) {
+ columnName = DotJoin(sourceName, columnName);
+ }
+ if (!names.emplace(columnName).second) {
+ ctx.Error(expr->GetPos()) << "Duplicate column name found: " << columnName << " in " << exprSeat << " section";
+ return false;
+ }
if (!alias && ExprAliases.contains(columnName)) {
- ctx.Error(expr->GetPos()) << "Collision between alias and column name: " << columnName << " in " << exprSeat << " section";
- return false;
- }
- if (alias && exprSeat == EExprSeat::GroupBy) {
- auto columnAlias = GroupByColumnAliases.emplace(columnName, alias);
- auto oldAlias = columnAlias.first->second;
- if (columnAlias.second && oldAlias != alias) {
- ctx.Error(expr->GetPos()) << "Alias for column not same, column: " << columnName <<
- ", exist alias: " << oldAlias << ", another alias: " << alias;
- return false;
- }
- }
- }
- Expressions(exprSeat).emplace_back(expr);
- }
- return true;
-}
-
+ ctx.Error(expr->GetPos()) << "Collision between alias and column name: " << columnName << " in " << exprSeat << " section";
+ return false;
+ }
+ if (alias && exprSeat == EExprSeat::GroupBy) {
+ auto columnAlias = GroupByColumnAliases.emplace(columnName, alias);
+ auto oldAlias = columnAlias.first->second;
+ if (columnAlias.second && oldAlias != alias) {
+ ctx.Error(expr->GetPos()) << "Alias for column not same, column: " << columnName <<
+ ", exist alias: " << oldAlias << ", another alias: " << alias;
+ return false;
+ }
+ }
+ }
+ Expressions(exprSeat).emplace_back(expr);
+ }
+ return true;
+}
+
void ISource::SetFlattenByMode(const TString& mode) {
FlattenMode = mode;
}
@@ -1172,16 +1172,16 @@ bool ISource::HasAggregations() const {
return !Aggregations.empty() || !GroupKeys.empty();
}
-void ISource::AddWindowSpecs(TWinSpecs winSpecs) {
- WinSpecs = winSpecs;
-}
-
-bool ISource::AddFuncOverWindow(TContext& ctx, TNodePtr expr) {
+void ISource::AddWindowSpecs(TWinSpecs winSpecs) {
+ WinSpecs = winSpecs;
+}
+
+bool ISource::AddFuncOverWindow(TContext& ctx, TNodePtr expr) {
Y_UNUSED(ctx);
Y_UNUSED(expr);
- return false;
-}
-
+ return false;
+}
+
void ISource::AddTmpWindowColumn(const TString& column) {
TmpWindowColumns.push_back(column);
}
@@ -1198,129 +1198,129 @@ THoppingWindowSpecPtr ISource::GetHoppingWindowSpec() const {
return HoppingWindowSpec;
}
-TWindowSpecificationPtr ISource::FindWindowSpecification(TContext& ctx, const TString& windowName) const {
- auto winIter = WinSpecs.find(windowName);
- if (winIter == WinSpecs.end()) {
- ctx.Error(Pos) << "Can't refer to the window specification with name: " << windowName;
- return {};
- }
- auto winSpec = winIter->second;
- if (winSpec->Frame) {
- ctx.Error(Pos) << "Frame that not default is not supported yet for window: " << windowName;
- return {};
- }
- return winSpec;
-}
-
+TWindowSpecificationPtr ISource::FindWindowSpecification(TContext& ctx, const TString& windowName) const {
+ auto winIter = WinSpecs.find(windowName);
+ if (winIter == WinSpecs.end()) {
+ ctx.Error(Pos) << "Can't refer to the window specification with name: " << windowName;
+ return {};
+ }
+ auto winSpec = winIter->second;
+ if (winSpec->Frame) {
+ ctx.Error(Pos) << "Frame that not default is not supported yet for window: " << windowName;
+ return {};
+ }
+ return winSpec;
+}
+
inline TVector<TNodePtr>& ISource::Expressions(EExprSeat exprSeat) {
- return NamedExprs[static_cast<size_t>(exprSeat)];
-}
-
+ return NamedExprs[static_cast<size_t>(exprSeat)];
+}
+
inline const TVector<TNodePtr>& ISource::Expressions(EExprSeat exprSeat) const {
- return NamedExprs[static_cast<size_t>(exprSeat)];
-}
-
-inline TNodePtr ISource::AliasOrColumn(const TNodePtr& node, bool withSource) {
- auto result = node->GetLabel();
- if (!result) {
- const auto columnNamePtr = node->GetColumnName();
- YQL_ENSURE(columnNamePtr);
- result = *columnNamePtr;
- if (withSource) {
- const auto sourceNamePtr = node->GetSourceName();
- if (sourceNamePtr) {
- result = DotJoin(*sourceNamePtr, result);
- }
- }
- }
- return node->Q(result);
-}
-
+ return NamedExprs[static_cast<size_t>(exprSeat)];
+}
+
+inline TNodePtr ISource::AliasOrColumn(const TNodePtr& node, bool withSource) {
+ auto result = node->GetLabel();
+ if (!result) {
+ const auto columnNamePtr = node->GetColumnName();
+ YQL_ENSURE(columnNamePtr);
+ result = *columnNamePtr;
+ if (withSource) {
+ const auto sourceNamePtr = node->GetSourceName();
+ if (sourceNamePtr) {
+ result = DotJoin(*sourceNamePtr, result);
+ }
+ }
+ }
+ return node->Q(result);
+}
+
bool ISource::AddAggregationOverWindow(TContext& ctx, const TString& windowName, TAggregationPtr func) {
- if (func->IsDistinct()) {
- ctx.Error(func->GetPos()) << "Aggregation with distinct is not allowed over window: " << windowName;
- return false;
- }
- if (!FindWindowSpecification(ctx, windowName)) {
- return false;
- }
- AggregationOverWindow.emplace(windowName, func);
- return true;
-}
-
+ if (func->IsDistinct()) {
+ ctx.Error(func->GetPos()) << "Aggregation with distinct is not allowed over window: " << windowName;
+ return false;
+ }
+ if (!FindWindowSpecification(ctx, windowName)) {
+ return false;
+ }
+ AggregationOverWindow.emplace(windowName, func);
+ return true;
+}
+
bool ISource::AddFuncOverWindow(TContext& ctx, const TString& windowName, TNodePtr func) {
- if (!FindWindowSpecification(ctx, windowName)) {
- return false;
- }
- FuncOverWindow.emplace(windowName, func);
- return true;
-}
-
-bool ISource::IsCompositeSource() const {
+ if (!FindWindowSpecification(ctx, windowName)) {
+ return false;
+ }
+ FuncOverWindow.emplace(windowName, func);
+ return true;
+}
+
+bool ISource::IsCompositeSource() const {
return false;
}
bool ISource::IsGroupByColumn(const TString& column) const {
return GroupKeys.contains(column);
-}
-
-bool ISource::IsFlattenByColumns() const {
- return !Expressions(EExprSeat::FlattenBy).empty();
-}
-
+}
+
+bool ISource::IsFlattenByColumns() const {
+ return !Expressions(EExprSeat::FlattenBy).empty();
+}
+
bool ISource::IsAlias(EExprSeat exprSeat, const TString& column) const {
- for (const auto& exprNode: Expressions(exprSeat)) {
- const auto& labelName = exprNode->GetLabel();
- if (labelName && labelName == column) {
- return true;
- }
- }
- return false;
-}
-
+ for (const auto& exprNode: Expressions(exprSeat)) {
+ const auto& labelName = exprNode->GetLabel();
+ if (labelName && labelName == column) {
+ return true;
+ }
+ }
+ return false;
+}
+
bool ISource::IsExprAlias(const TString& column) const {
- std::array<EExprSeat, 3> exprSeats = {{EExprSeat::FlattenBy, EExprSeat::GroupBy, EExprSeat::WindowPartitionBy}};
- for (auto seat: exprSeats) {
- if (IsAlias(seat, column)) {
- return true;
- }
- }
- return false;
-}
-
-bool ISource::IsExprSeat(EExprSeat exprSeat, EExprType type) const {
- auto expressions = Expressions(exprSeat);
- if (!expressions) {
- return false;
- }
- for (const auto& exprNode: expressions) {
- if (exprNode->GetLabel()) {
- return type == EExprType::WithExpression;
- }
- }
- return type == EExprType::ColumnOnly;
-}
-
-TString ISource::GetGroupByColumnAlias(const TString& column) const {
- auto iter = GroupByColumnAliases.find(column);
- if (iter == GroupByColumnAliases.end()) {
- return {};
- }
- return iter->second;
-}
-
-const TString* ISource::GetWindowName() const {
- return {};
-}
-
-bool ISource::IsCalcOverWindow() const {
- return !AggregationOverWindow.empty() || !FuncOverWindow.empty();
-}
-
-bool ISource::IsOverWindowSource() const {
- return !WinSpecs.empty();
-}
-
+ std::array<EExprSeat, 3> exprSeats = {{EExprSeat::FlattenBy, EExprSeat::GroupBy, EExprSeat::WindowPartitionBy}};
+ for (auto seat: exprSeats) {
+ if (IsAlias(seat, column)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool ISource::IsExprSeat(EExprSeat exprSeat, EExprType type) const {
+ auto expressions = Expressions(exprSeat);
+ if (!expressions) {
+ return false;
+ }
+ for (const auto& exprNode: expressions) {
+ if (exprNode->GetLabel()) {
+ return type == EExprType::WithExpression;
+ }
+ }
+ return type == EExprType::ColumnOnly;
+}
+
+TString ISource::GetGroupByColumnAlias(const TString& column) const {
+ auto iter = GroupByColumnAliases.find(column);
+ if (iter == GroupByColumnAliases.end()) {
+ return {};
+ }
+ return iter->second;
+}
+
+const TString* ISource::GetWindowName() const {
+ return {};
+}
+
+bool ISource::IsCalcOverWindow() const {
+ return !AggregationOverWindow.empty() || !FuncOverWindow.empty();
+}
+
+bool ISource::IsOverWindowSource() const {
+ return !WinSpecs.empty();
+}
+
bool ISource::IsStream() const {
return false;
}
@@ -1349,81 +1349,81 @@ bool ISource::SetSamplingOptions(TContext& ctx,
bool ISource::CalculateGroupingHint(TContext& ctx, const TVector<TString>& columns, ui64& hint) const {
Y_UNUSED(columns);
Y_UNUSED(hint);
- ctx.Error() << "Source not support grouping hint";
- return false;
-}
-
+ ctx.Error() << "Source not support grouping hint";
+ return false;
+}
+
TNodePtr ISource::BuildFilter(TContext& ctx, const TString& label, const TNodePtr& groundNode) {
return Filters.empty() ? nullptr : Y(ctx.UseUnordered(*this) ? "OrderedFilter" : "Filter", label, BuildFilterLambda(groundNode));
-}
-
-TNodePtr ISource::BuildFilterLambda(const TNodePtr& groundNode) {
- if (Filters.empty()) {
- return BuildLambda(Pos, Y("row"), Y("Bool", Q("true")));
- }
- YQL_ENSURE(Filters[0]->HasState(ENodeState::Initialized));
- TNodePtr filter(Filters[0]);
- for (ui32 i = 1; i < Filters.size(); ++i) {
- YQL_ENSURE(Filters[i]->HasState(ENodeState::Initialized));
- filter = Y("And", filter, Filters[i]);
- }
- filter = Y("Coalesce", filter, Y("Bool", Q("false")));
- if (groundNode) {
- filter = Y("block", Q(L(groundNode, Y("return", filter))));
- }
- return BuildLambda(Pos, Y("row"), filter);
+}
+
+TNodePtr ISource::BuildFilterLambda(const TNodePtr& groundNode) {
+ if (Filters.empty()) {
+ return BuildLambda(Pos, Y("row"), Y("Bool", Q("true")));
+ }
+ YQL_ENSURE(Filters[0]->HasState(ENodeState::Initialized));
+ TNodePtr filter(Filters[0]);
+ for (ui32 i = 1; i < Filters.size(); ++i) {
+ YQL_ENSURE(Filters[i]->HasState(ENodeState::Initialized));
+ filter = Y("And", filter, Filters[i]);
+ }
+ filter = Y("Coalesce", filter, Y("Bool", Q("false")));
+ if (groundNode) {
+ filter = Y("block", Q(L(groundNode, Y("return", filter))));
+ }
+ return BuildLambda(Pos, Y("row"), filter);
}
TNodePtr ISource::BuildFlattenByColumns(const TString& label) {
auto columnsList = Y("FlattenByColumns", Q(FlattenMode), label);
- for (const auto& column: Expressions(EExprSeat::FlattenBy)) {
- const auto columnNamePtr = column->GetColumnName();
- YQL_ENSURE(columnNamePtr);
- if (column->GetLabel().empty()) {
- columnsList = L(columnsList, Q(*columnNamePtr));
- } else {
- columnsList = L(columnsList, Q(Y(Q(*columnNamePtr), Q(column->GetLabel()))));
- }
- }
- return Y(Y("let", "res", columnsList));
-}
-
+ for (const auto& column: Expressions(EExprSeat::FlattenBy)) {
+ const auto columnNamePtr = column->GetColumnName();
+ YQL_ENSURE(columnNamePtr);
+ if (column->GetLabel().empty()) {
+ columnsList = L(columnsList, Q(*columnNamePtr));
+ } else {
+ columnsList = L(columnsList, Q(Y(Q(*columnNamePtr), Q(column->GetLabel()))));
+ }
+ }
+ return Y(Y("let", "res", columnsList));
+}
+
TNodePtr ISource::BuildFlattenColumns(const TString& label) {
return Y(Y("let", "res", Y("Just", Y("FlattenStructs", label))));
}
-TNodePtr ISource::BuildPreaggregatedMap(TContext& ctx) {
- const TColumns* columnsPtr = GetColumns();
- if (!columnsPtr) {
- ctx.Error(GetPos()) << "Missed columns for preaggregated map";
- return nullptr;
- }
+TNodePtr ISource::BuildPreaggregatedMap(TContext& ctx) {
+ const TColumns* columnsPtr = GetColumns();
+ if (!columnsPtr) {
+ ctx.Error(GetPos()) << "Missed columns for preaggregated map";
+ return nullptr;
+ }
auto structObj = BuildAtom(Pos, "row", TNodeFlags::Default);
- for (const auto& exprNode: Expressions(EExprSeat::GroupBy)) {
- const auto name = exprNode->GetLabel();
- if (name) {
+ for (const auto& exprNode: Expressions(EExprSeat::GroupBy)) {
+ const auto name = exprNode->GetLabel();
+ if (name) {
structObj = Y("ForceRemoveMember", structObj, Q(name));
structObj = Y("AddMember", structObj, Q(name), exprNode);
- }
- }
+ }
+ }
auto block = Y("AsList", structObj);
- return block;
-}
-
-TNodePtr ISource::BuildPrewindowMap(TContext& ctx, const TNodePtr& groundNode) {
- Y_UNUSED(ctx);
- auto feed = BuildAtom(Pos, "row", TNodeFlags::Default);
- for (const auto& exprNode: Expressions(EExprSeat::WindowPartitionBy)) {
- const auto name = exprNode->GetLabel();
- if (name) {
- feed = Y("AddMember", feed, Q(name), GroundWithExpr(groundNode, exprNode));
- }
- }
+ return block;
+}
+
+TNodePtr ISource::BuildPrewindowMap(TContext& ctx, const TNodePtr& groundNode) {
+ Y_UNUSED(ctx);
+ auto feed = BuildAtom(Pos, "row", TNodeFlags::Default);
+ for (const auto& exprNode: Expressions(EExprSeat::WindowPartitionBy)) {
+ const auto name = exprNode->GetLabel();
+ if (name) {
+ feed = Y("AddMember", feed, Q(name), GroundWithExpr(groundNode, exprNode));
+ }
+ }
return Y(ctx.UseUnordered(*this) ? "OrderedFlatMap" : "FlatMap", "core", BuildLambda(Pos, Y("row"), Y("AsList", feed)));
-}
-
+}
+
TNodePtr ISource::BuildAggregation(const TString& label) {
- if (GroupKeys.empty() && Aggregations.empty() && !IsCompositeSource()) {
+ if (GroupKeys.empty() && Aggregations.empty() && !IsCompositeSource()) {
return nullptr;
}
@@ -1448,7 +1448,7 @@ TNodePtr ISource::BuildAggregation(const TString& label) {
const auto listType = Y("TypeOf", label);
auto aggrArgs = Y();
for (const auto& aggr: Aggregations) {
- if (const auto traits = aggr->AggregationTraits(listType))
+ if (const auto traits = aggr->AggregationTraits(listType))
aggrArgs = L(aggrArgs, traits);
}
@@ -1470,225 +1470,225 @@ TNodePtr ISource::BuildAggregation(const TString& label) {
}
TMaybe<TString> ISource::FindColumnMistype(const TString& name) const {
- auto result = FindMistypeIn(GroupKeys, name);
- return result ? result : FindMistypeIn(ExprAliases, name);
-}
-
-void ISource::AddDependentSource(ISource* usedSource) {
- UsedSources.push_back(usedSource);
-}
-
-/// \todo fill it
-struct TWinFrame {
-};
-
-struct TWinPartition {
+ auto result = FindMistypeIn(GroupKeys, name);
+ return result ? result : FindMistypeIn(ExprAliases, name);
+}
+
+void ISource::AddDependentSource(ISource* usedSource) {
+ UsedSources.push_back(usedSource);
+}
+
+/// \todo fill it
+struct TWinFrame {
+};
+
+struct TWinPartition {
TString ParentLabel;
size_t Id = 0;
TVector<size_t> FrameIds;
TVector<TSortSpecificationPtr> OrderBy;
TVector<TNodePtr> Partitions;
-};
-
-/// \todo use few levels of grouping (got from group by cube, etc)
-class WindowFuncSupp {
-public:
- struct EvalOverWindow {
+};
+
+/// \todo use few levels of grouping (got from group by cube, etc)
+class WindowFuncSupp {
+public:
+ struct EvalOverWindow {
TVector<TAggregationPtr> Aggregations;
TVector<TNodePtr> Functions;
- };
-
+ };
+
size_t GetWindowByName(const TString& windowName) {
- auto iter = WindowMap.find(windowName);
- return iter != WindowMap.end() ? iter->second : 0;
- }
+ auto iter = WindowMap.find(windowName);
+ return iter != WindowMap.end() ? iter->second : 0;
+ }
size_t CreateWindowBySpec(const TString& windowName, const TWindowSpecificationPtr& winSpec) {
Y_UNUSED(windowName);
- auto curPartitions = winSpec->Partitions;
- auto curOrderBy = winSpec->OrderBy;
- auto partition = std::find_if(Partitions.begin(), Partitions.end(), [&curPartitions, &curOrderBy](const TWinPartition& other) {
- /// \todo this compare is too strong;
- if (curPartitions != other.Partitions) {
- return false;
- }
- if (curOrderBy.size() != other.OrderBy.size()) {
- return false;
- }
- for (unsigned i = 0; i < curOrderBy.size(); ++i) {
- // failed in common case
- if (curOrderBy[i]->OrderExpr != other.OrderBy[i]->OrderExpr) {
- return false;
- }
- if (curOrderBy[i]->Ascending != other.OrderBy[i]->Ascending) {
- return false;
- }
- }
- return true;
- });
- if (partition == Partitions.end()) {
- TWinPartition newPartition;
- newPartition.Partitions = curPartitions;
- newPartition.OrderBy = curOrderBy;
- Partitions.emplace_back(newPartition);
- partition = Partitions.end() - 1;
- }
- /// \todo add smart frame search and creation
- auto frame = partition->FrameIds.begin();
- if (frame == partition->FrameIds.end()) {
- YQL_ENSURE(!winSpec->Frame, "Supported only default frame yet!");
- Evals.push_back({});
- const size_t curEval = Evals.size();
- partition->FrameIds.push_back(curEval);
- frame = partition->FrameIds.end() - 1;
- }
- return *frame;
- }
- void AddAggregationFunc(size_t windowId, TAggregationPtr func) {
- Evals[windowId-1].Aggregations.push_back(func);
- }
-
- void AddSimpleFunc(size_t windowId, TNodePtr func) {
- Evals[windowId-1].Functions.push_back(func);
- }
-
+ auto curPartitions = winSpec->Partitions;
+ auto curOrderBy = winSpec->OrderBy;
+ auto partition = std::find_if(Partitions.begin(), Partitions.end(), [&curPartitions, &curOrderBy](const TWinPartition& other) {
+ /// \todo this compare is too strong;
+ if (curPartitions != other.Partitions) {
+ return false;
+ }
+ if (curOrderBy.size() != other.OrderBy.size()) {
+ return false;
+ }
+ for (unsigned i = 0; i < curOrderBy.size(); ++i) {
+ // failed in common case
+ if (curOrderBy[i]->OrderExpr != other.OrderBy[i]->OrderExpr) {
+ return false;
+ }
+ if (curOrderBy[i]->Ascending != other.OrderBy[i]->Ascending) {
+ return false;
+ }
+ }
+ return true;
+ });
+ if (partition == Partitions.end()) {
+ TWinPartition newPartition;
+ newPartition.Partitions = curPartitions;
+ newPartition.OrderBy = curOrderBy;
+ Partitions.emplace_back(newPartition);
+ partition = Partitions.end() - 1;
+ }
+ /// \todo add smart frame search and creation
+ auto frame = partition->FrameIds.begin();
+ if (frame == partition->FrameIds.end()) {
+ YQL_ENSURE(!winSpec->Frame, "Supported only default frame yet!");
+ Evals.push_back({});
+ const size_t curEval = Evals.size();
+ partition->FrameIds.push_back(curEval);
+ frame = partition->FrameIds.end() - 1;
+ }
+ return *frame;
+ }
+ void AddAggregationFunc(size_t windowId, TAggregationPtr func) {
+ Evals[windowId-1].Aggregations.push_back(func);
+ }
+
+ void AddSimpleFunc(size_t windowId, TNodePtr func) {
+ Evals[windowId-1].Functions.push_back(func);
+ }
+
const TVector<TWinPartition>& GetPartitions() {
- return Partitions;
- }
- const EvalOverWindow& GetEvals(size_t frameId) {
- YQL_ENSURE(frameId && frameId <= Evals.size());
- return Evals[frameId-1];
- }
- TNodePtr BuildFrame(TPosition pos, size_t frameId) {
+ return Partitions;
+ }
+ const EvalOverWindow& GetEvals(size_t frameId) {
+ YQL_ENSURE(frameId && frameId <= Evals.size());
+ return Evals[frameId-1];
+ }
+ TNodePtr BuildFrame(TPosition pos, size_t frameId) {
Y_UNUSED(frameId);
- /// \todo support not default frame
+ /// \todo support not default frame
return BuildLiteralVoid(pos);
- }
-
-private:
+ }
+
+private:
TVector<TWinPartition> Partitions;
TMap<TString, size_t> WindowMap;
TVector<EvalOverWindow> Evals;
-};
-
-TNodePtr ISource::BuildCalcOverWindow(TContext& ctx, const TString& label, const TNodePtr& ground) {
- if (AggregationOverWindow.empty() && FuncOverWindow.empty()) {
- return {};
- }
-
- WindowFuncSupp winSupp;
- for (auto iter: AggregationOverWindow) {
- auto windowId = winSupp.GetWindowByName(iter.first);
- if (!windowId) {
- windowId = winSupp.CreateWindowBySpec(iter.first, WinSpecs.at(iter.first));
- }
- winSupp.AddAggregationFunc(windowId, iter.second);
- }
- for (auto iter: FuncOverWindow) {
- auto windowId = winSupp.GetWindowByName(iter.first);
- if (!windowId) {
- windowId = winSupp.CreateWindowBySpec(iter.first, WinSpecs.at(iter.first));
- }
- winSupp.AddSimpleFunc(windowId, iter.second);
- }
-
- auto partitions = winSupp.GetPartitions();
- const bool onePartition = partitions.size() == 1;
- const auto useLabel = onePartition ? label : "partitioning";
- const auto listType = Y("TypeOf", useLabel);
- auto framesProcess = Y();
- auto resultNode = onePartition ? Y() : Y(Y("let", "partitioning", label));
- for (auto partition: partitions) {
- if (!partition.ParentLabel.empty()) {
- ctx.Error(GetPos()) << "Dependent partition for Window function unsupported yet!";
- return nullptr;
- }
- auto keysTuple = Y();
+};
+
+TNodePtr ISource::BuildCalcOverWindow(TContext& ctx, const TString& label, const TNodePtr& ground) {
+ if (AggregationOverWindow.empty() && FuncOverWindow.empty()) {
+ return {};
+ }
+
+ WindowFuncSupp winSupp;
+ for (auto iter: AggregationOverWindow) {
+ auto windowId = winSupp.GetWindowByName(iter.first);
+ if (!windowId) {
+ windowId = winSupp.CreateWindowBySpec(iter.first, WinSpecs.at(iter.first));
+ }
+ winSupp.AddAggregationFunc(windowId, iter.second);
+ }
+ for (auto iter: FuncOverWindow) {
+ auto windowId = winSupp.GetWindowByName(iter.first);
+ if (!windowId) {
+ windowId = winSupp.CreateWindowBySpec(iter.first, WinSpecs.at(iter.first));
+ }
+ winSupp.AddSimpleFunc(windowId, iter.second);
+ }
+
+ auto partitions = winSupp.GetPartitions();
+ const bool onePartition = partitions.size() == 1;
+ const auto useLabel = onePartition ? label : "partitioning";
+ const auto listType = Y("TypeOf", useLabel);
+ auto framesProcess = Y();
+ auto resultNode = onePartition ? Y() : Y(Y("let", "partitioning", label));
+ for (auto partition: partitions) {
+ if (!partition.ParentLabel.empty()) {
+ ctx.Error(GetPos()) << "Dependent partition for Window function unsupported yet!";
+ return nullptr;
+ }
+ auto keysTuple = Y();
for (const auto& key: partition.Partitions) {
- keysTuple = L(keysTuple, AliasOrColumn(key, GetJoin()));
- }
- auto frames = Y();
- for (auto frameId: partition.FrameIds) {
- auto callOnFrame = Y("WinOnRows", winSupp.BuildFrame(ctx.Pos(), frameId));
- const auto& evals = winSupp.GetEvals(frameId);
- for (auto eval: evals.Aggregations) {
- if (!eval->IsOverWindow()) {
- ctx.Error(eval->GetPos()) << "Aggregation over window is not supported for function: " << eval->GetName();
- return nullptr;
- }
- auto winTraits = eval->WindowTraits(listType);
- callOnFrame = L(callOnFrame, winTraits);
- }
- for (auto eval: evals.Functions) {
- auto winSpec = eval->WindowSpecFunc(listType);
- callOnFrame = L(callOnFrame, winSpec);
- }
- /// \todo some smart frame building not "WinOnRows" hardcode
- frames = L(frames, callOnFrame);
- }
- auto sortSpec = partition.OrderBy.empty() ? BuildLiteralVoid(ctx.Pos()) : BuildSortSpec(partition.OrderBy, useLabel, ground, true);
- framesProcess = Y("CalcOverWindow", useLabel, Q(keysTuple), sortSpec, Q(frames));
- if (!onePartition) {
- resultNode = L(resultNode, Y("let", "partitioning", framesProcess));
- }
- }
- if (onePartition) {
- return framesProcess;
- } else {
- return Y("block", Q(L(resultNode, Y("return", "partitioning"))));
- }
-}
-
+ keysTuple = L(keysTuple, AliasOrColumn(key, GetJoin()));
+ }
+ auto frames = Y();
+ for (auto frameId: partition.FrameIds) {
+ auto callOnFrame = Y("WinOnRows", winSupp.BuildFrame(ctx.Pos(), frameId));
+ const auto& evals = winSupp.GetEvals(frameId);
+ for (auto eval: evals.Aggregations) {
+ if (!eval->IsOverWindow()) {
+ ctx.Error(eval->GetPos()) << "Aggregation over window is not supported for function: " << eval->GetName();
+ return nullptr;
+ }
+ auto winTraits = eval->WindowTraits(listType);
+ callOnFrame = L(callOnFrame, winTraits);
+ }
+ for (auto eval: evals.Functions) {
+ auto winSpec = eval->WindowSpecFunc(listType);
+ callOnFrame = L(callOnFrame, winSpec);
+ }
+ /// \todo some smart frame building not "WinOnRows" hardcode
+ frames = L(frames, callOnFrame);
+ }
+ auto sortSpec = partition.OrderBy.empty() ? BuildLiteralVoid(ctx.Pos()) : BuildSortSpec(partition.OrderBy, useLabel, ground, true);
+ framesProcess = Y("CalcOverWindow", useLabel, Q(keysTuple), sortSpec, Q(frames));
+ if (!onePartition) {
+ resultNode = L(resultNode, Y("let", "partitioning", framesProcess));
+ }
+ }
+ if (onePartition) {
+ return framesProcess;
+ } else {
+ return Y("block", Q(L(resultNode, Y("return", "partitioning"))));
+ }
+}
+
TNodePtr ISource::BuildSort(TContext& ctx, const TString& label) {
Y_UNUSED(ctx);
Y_UNUSED(label);
- return nullptr;
-}
-
+ return nullptr;
+}
+
IJoin* ISource::GetJoin() {
return nullptr;
}
-ISource* ISource::GetCompositeSource() {
- return nullptr;
-}
-
-bool ISource::IsSelect() const {
- return true;
-}
-
+ISource* ISource::GetCompositeSource() {
+ return nullptr;
+}
+
+bool ISource::IsSelect() const {
+ return true;
+}
+
bool ISource::IsTableSource() const {
return false;
}
-bool ISource::ShouldUseSourceAsColumn(const TString& source) {
- Y_UNUSED(source);
- return false;
-}
-
-bool ISource::IsJoinKeysInitializing() const {
- return false;
-}
-
+bool ISource::ShouldUseSourceAsColumn(const TString& source) {
+ Y_UNUSED(source);
+ return false;
+}
+
+bool ISource::IsJoinKeysInitializing() const {
+ return false;
+}
+
bool ISource::DoInit(TContext& ctx, ISource* src) {
- for (auto& column: Expressions(EExprSeat::FlattenBy)) {
- if (!column->Init(ctx, this)) {
- return false;
- }
- }
+ for (auto& column: Expressions(EExprSeat::FlattenBy)) {
+ if (!column->Init(ctx, this)) {
+ return false;
+ }
+ }
if (IsFlattenColumns() && src) {
src->AllColumns();
}
- return true;
-}
-
-bool ISource::InitFilters(TContext& ctx) {
+ return true;
+}
+
+bool ISource::InitFilters(TContext& ctx) {
for (auto& filter: Filters) {
if (!filter->Init(ctx, this)) {
return false;
}
- if (filter->IsAggregated() && !filter->IsConstant() && !filter->HasState(ENodeState::AggregationKey)) {
+ if (filter->IsAggregated() && !filter->IsConstant() && !filter->HasState(ENodeState::AggregationKey)) {
ctx.Error(filter->GetPos()) << "Can not use aggregated values in filtering";
return false;
}
@@ -1703,42 +1703,42 @@ TAstNode* ISource::Translate(TContext& ctx) const {
}
void ISource::FillSortParts(const TVector<TSortSpecificationPtr>& orderBy, TNodePtr& sortDirection, TNodePtr& sortKeySelector) {
- TNodePtr expr;
- if (orderBy.empty()) {
- YQL_ENSURE(!sortKeySelector);
- sortDirection = sortKeySelector = Y("Void");
- return;
- } else if (orderBy.size() == 1) {
- auto& sortSpec = orderBy.front();
+ TNodePtr expr;
+ if (orderBy.empty()) {
+ YQL_ENSURE(!sortKeySelector);
+ sortDirection = sortKeySelector = Y("Void");
+ return;
+ } else if (orderBy.size() == 1) {
+ auto& sortSpec = orderBy.front();
expr = Y("EnsurePersistable", sortSpec->OrderExpr);
- sortDirection = Y("Bool", Q(sortSpec->Ascending ? "true" : "false"));
- } else {
- auto exprList = Y();
- sortDirection = Y();
- for (const auto& sortSpec: orderBy) {
- const auto asc = sortSpec->Ascending;
- sortDirection = L(sortDirection, Y("Bool", Q(asc ? "true" : "false")));
+ sortDirection = Y("Bool", Q(sortSpec->Ascending ? "true" : "false"));
+ } else {
+ auto exprList = Y();
+ sortDirection = Y();
+ for (const auto& sortSpec: orderBy) {
+ const auto asc = sortSpec->Ascending;
+ sortDirection = L(sortDirection, Y("Bool", Q(asc ? "true" : "false")));
exprList = L(exprList, Y("EnsurePersistable", sortSpec->OrderExpr));
- }
- sortDirection = Q(sortDirection);
- expr = Q(exprList);
+ }
+ sortDirection = Q(sortDirection);
+ expr = Q(exprList);
}
- expr = sortKeySelector ? expr->Y("block", expr->Q(expr->L(sortKeySelector, expr->Y("return", expr)))) : expr;
- sortKeySelector = BuildLambda(Pos, Y("row"), expr);
+ expr = sortKeySelector ? expr->Y("block", expr->Q(expr->L(sortKeySelector, expr->Y("return", expr)))) : expr;
+ sortKeySelector = BuildLambda(Pos, Y("row"), expr);
}
TNodePtr ISource::BuildSortSpec(const TVector<TSortSpecificationPtr>& orderBy, const TString& label, const TNodePtr& ground, bool traits) {
- YQL_ENSURE(!orderBy.empty());
- TNodePtr dirsNode;
- auto keySelectorNode = ground;
- FillSortParts(orderBy, dirsNode, keySelectorNode);
- if (traits) {
- return Y("SortTraits", Y("TypeOf", label), dirsNode, keySelectorNode);
- } else {
- return Y("Sort", label, dirsNode, keySelectorNode);
- }
-}
-
+ YQL_ENSURE(!orderBy.empty());
+ TNodePtr dirsNode;
+ auto keySelectorNode = ground;
+ FillSortParts(orderBy, dirsNode, keySelectorNode);
+ if (traits) {
+ return Y("SortTraits", Y("TypeOf", label), dirsNode, keySelectorNode);
+ } else {
+ return Y("Sort", label, dirsNode, keySelectorNode);
+ }
+}
+
IJoin::IJoin(TPosition pos)
: ISource(pos)
{
@@ -1800,39 +1800,39 @@ TString StringContent(TContext& ctx, const TString& str) {
return result;
}
-TString IdContent(TContext& ctx, const TString& s) {
- YQL_ENSURE(!s.empty(), "Empty identifier not expected");
- if (!s.StartsWith('[') && !s.StartsWith('`')) {
- return s;
- }
- auto endSym = s.StartsWith('[') ? ']' : '`';
- if (s.size() < 2 || !s.EndsWith(endSym)) {
- ctx.Error() << "The identifier that starts with: '" << s[0] << "' should ends with: '" << endSym << "'";
- return {};
- }
- size_t skipSymbols = 1;
-
- /// @TODO: temporary back compatibility case
- if (s.StartsWith('[') && s[1] == '"') {
- ctx.Warning(ctx.Pos(), TIssuesIds::YQL_DEPRECATED_DOUBLE_QUOTE_IN_BRACKETS) <<
- "The use of double quotes in the identifier in square brackets is deprecated."
- " Either simply remove the double quotes or use backticks."
- " If you need quotes they can be escaped by '\\'.";
- if (s.size() < 4 || s[s.size() - 2] != '"') {
- ctx.Error() << "Missed closed quote for identifier, either remove double quote after '[', "
- " or put double quote before ']'";
- return {};
- }
- endSym = '"';
- skipSymbols += 1;
- }
-
+TString IdContent(TContext& ctx, const TString& s) {
+ YQL_ENSURE(!s.empty(), "Empty identifier not expected");
+ if (!s.StartsWith('[') && !s.StartsWith('`')) {
+ return s;
+ }
+ auto endSym = s.StartsWith('[') ? ']' : '`';
+ if (s.size() < 2 || !s.EndsWith(endSym)) {
+ ctx.Error() << "The identifier that starts with: '" << s[0] << "' should ends with: '" << endSym << "'";
+ return {};
+ }
+ size_t skipSymbols = 1;
+
+ /// @TODO: temporary back compatibility case
+ if (s.StartsWith('[') && s[1] == '"') {
+ ctx.Warning(ctx.Pos(), TIssuesIds::YQL_DEPRECATED_DOUBLE_QUOTE_IN_BRACKETS) <<
+ "The use of double quotes in the identifier in square brackets is deprecated."
+ " Either simply remove the double quotes or use backticks."
+ " If you need quotes they can be escaped by '\\'.";
+ if (s.size() < 4 || s[s.size() - 2] != '"') {
+ ctx.Error() << "Missed closed quote for identifier, either remove double quote after '[', "
+ " or put double quote before ']'";
+ return {};
+ }
+ endSym = '"';
+ skipSymbols += 1;
+ }
+
TStringBuf atom(s.data() + skipSymbols, s.size() - 2 * skipSymbols + 1);
- TString unescapedStr;
- TStringOutput sout(unescapedStr);
- unescapedStr.reserve(s.size());
-
- size_t readBytes = 0;
+ TString unescapedStr;
+ TStringOutput sout(unescapedStr);
+ unescapedStr.reserve(s.size());
+
+ size_t readBytes = 0;
TPosition pos = ctx.Pos();
pos.Column += skipSymbols - 1;
@@ -1841,15 +1841,15 @@ TString IdContent(TContext& ctx, const TString& s) {
TTextWalker walker(pos);
walker.Advance(atom.Trunc(readBytes));
ctx.Error(pos) << "Cannot parse broken identifier: " << UnescapeResultToString(unescapeResult);
- return {};
- }
+ return {};
+ }
if (readBytes != atom.size()) {
- ctx.Error() << "The identifier not parsed completely";
- return {};
- }
-
- return unescapedStr;
+ ctx.Error() << "The identifier not parsed completely";
+ return {};
+ }
+
+ return unescapedStr;
}
namespace {
@@ -1879,84 +1879,84 @@ public:
}
TLiteralNode::TLiteralNode(TPosition pos, bool isNull)
- : TAstListNode(pos)
+ : TAstListNode(pos)
, Null(isNull)
, Void(!isNull)
-{
+{
Add(isNull ? "Null" : "Void");
-}
+}
TLiteralNode::TLiteralNode(TPosition pos, const TString& type, const TString& value)
- : TAstListNode(pos)
- , Null(false)
+ : TAstListNode(pos)
+ , Null(false)
, Void(false)
- , Type(type)
- , Value(value)
-{
- Add(Type, BuildQuotedAtom(Pos, Value));
-}
+ , Type(type)
+ , Value(value)
+{
+ Add(Type, BuildQuotedAtom(Pos, Value));
+}
TLiteralNode::TLiteralNode(TPosition pos, const TString& value, ui32 nodeFlags)
- : TAstListNode(pos)
- , Null(false)
+ : TAstListNode(pos)
+ , Null(false)
, Void(false)
- , Type("String")
+ , Type("String")
, Value(value)
-{
+{
Add(Type, BuildQuotedAtom(pos, Value, nodeFlags));
-}
+}
-bool TLiteralNode::IsNull() const {
- return Null;
-}
+bool TLiteralNode::IsNull() const {
+ return Null;
+}
const TString* TLiteralNode::GetLiteral(const TString& type) const {
- return type == Type ? &Value : nullptr;
-}
-
-void TLiteralNode::DoUpdateState() const {
- State.Set(ENodeState::Const);
-}
-
-TNodePtr TLiteralNode::DoClone() const {
+ return type == Type ? &Value : nullptr;
+}
+
+void TLiteralNode::DoUpdateState() const {
+ State.Set(ENodeState::Const);
+}
+
+TNodePtr TLiteralNode::DoClone() const {
auto res = (Null || Void) ? MakeIntrusive<TLiteralNode>(Pos, Null) : MakeIntrusive<TLiteralNode>(Pos, Type, Value);
- res->Nodes = Nodes;
- return res;
-}
-
-template<typename T>
+ res->Nodes = Nodes;
+ return res;
+}
+
+template<typename T>
TLiteralNumberNode<T>::TLiteralNumberNode(TPosition pos, const TString& type, const TString& value)
- : TLiteralNode(pos, type, value)
-{}
+ : TLiteralNode(pos, type, value)
+{}
-template<typename T>
-TNodePtr TLiteralNumberNode<T>::DoClone() const {
- return new TLiteralNumberNode<T>(Pos, Type, Value);
-}
+template<typename T>
+TNodePtr TLiteralNumberNode<T>::DoClone() const {
+ return new TLiteralNumberNode<T>(Pos, Type, Value);
+}
-template<typename T>
-bool TLiteralNumberNode<T>::DoInit(TContext& ctx, ISource* src) {
+template<typename T>
+bool TLiteralNumberNode<T>::DoInit(TContext& ctx, ISource* src) {
Y_UNUSED(src);
- T val;
- if (!TryFromString(Value, val)) {
- ctx.Error(Pos) << "Failed to convert string: " << Value << " to " << Type << " value";
- return false;
- }
- return true;
-}
-
-template<typename T>
-bool TLiteralNumberNode<T>::IsIntegerLiteral() const {
- return std::numeric_limits<T>::is_integer;
-}
-
-template class TLiteralNumberNode<i32>;
-template class TLiteralNumberNode<i64>;
-template class TLiteralNumberNode<ui32>;
-template class TLiteralNumberNode<ui64>;
-template class TLiteralNumberNode<float>;
-template class TLiteralNumberNode<double>;
-template class TLiteralNumberNode<ui8>;
+ T val;
+ if (!TryFromString(Value, val)) {
+ ctx.Error(Pos) << "Failed to convert string: " << Value << " to " << Type << " value";
+ return false;
+ }
+ return true;
+}
+
+template<typename T>
+bool TLiteralNumberNode<T>::IsIntegerLiteral() const {
+ return std::numeric_limits<T>::is_integer;
+}
+
+template class TLiteralNumberNode<i32>;
+template class TLiteralNumberNode<i64>;
+template class TLiteralNumberNode<ui32>;
+template class TLiteralNumberNode<ui64>;
+template class TLiteralNumberNode<float>;
+template class TLiteralNumberNode<double>;
+template class TLiteralNumberNode<ui8>;
template class TLiteralNumberNode<i8>;
template class TLiteralNumberNode<ui16>;
template class TLiteralNumberNode<i16>;
@@ -1984,10 +1984,10 @@ TNodePtr BuildLiteralSmartString(TContext& ctx, const TString& value) {
}
}
-TNodePtr BuildLiteralRawString(TPosition pos, const TString& value) {
- return new TLiteralNode(pos, "String", value);
-}
-
+TNodePtr BuildLiteralRawString(TPosition pos, const TString& value) {
+ return new TLiteralNode(pos, "String", value);
+}
+
TNodePtr BuildLiteralBool(TPosition pos, const TString& value) {
return new TLiteralNode(pos, "Bool", value);
}
@@ -2032,96 +2032,96 @@ bool TDeferredAtom::Empty() const {
}
TTupleNode::TTupleNode(TPosition pos, const TVector<TNodePtr>& exprs)
- : TAstListNode(pos)
- , Exprs(exprs)
-{}
-
-bool TTupleNode::IsEmpty() const {
- return Exprs.empty();
-}
-
+ : TAstListNode(pos)
+ , Exprs(exprs)
+{}
+
+bool TTupleNode::IsEmpty() const {
+ return Exprs.empty();
+}
+
const TVector<TNodePtr>& TTupleNode::Elements() const {
- return Exprs;
-}
-
-bool TTupleNode::DoInit(TContext& ctx, ISource* src) {
- auto node(Y());
- for (auto& expr: Exprs) {
- if (expr->GetLabel()) {
- ctx.Error(expr->GetPos()) << "Tuple does not allow named members";
- return false;
- }
- node = L(node, expr);
- }
- Add("quote", node);
- return TAstListNode::DoInit(ctx, src);
-}
-
-size_t TTupleNode::GetTupleSize() const {
- return Exprs.size();
-}
-
-TNodePtr TTupleNode::GetTupleElement(size_t index) const {
- return Exprs[index];
-}
-
-TNodePtr TTupleNode::DoClone() const {
- return new TTupleNode(Pos, CloneContainer(Exprs));
-}
+ return Exprs;
+}
+
+bool TTupleNode::DoInit(TContext& ctx, ISource* src) {
+ auto node(Y());
+ for (auto& expr: Exprs) {
+ if (expr->GetLabel()) {
+ ctx.Error(expr->GetPos()) << "Tuple does not allow named members";
+ return false;
+ }
+ node = L(node, expr);
+ }
+ Add("quote", node);
+ return TAstListNode::DoInit(ctx, src);
+}
+
+size_t TTupleNode::GetTupleSize() const {
+ return Exprs.size();
+}
+
+TNodePtr TTupleNode::GetTupleElement(size_t index) const {
+ return Exprs[index];
+}
+
+TNodePtr TTupleNode::DoClone() const {
+ return new TTupleNode(Pos, CloneContainer(Exprs));
+}
TNodePtr BuildTuple(TPosition pos, const TVector<TNodePtr>& exprs) {
return new TTupleNode(pos, exprs);
}
TStructNode::TStructNode(TPosition pos, const TVector<TNodePtr>& exprs)
- : TAstListNode(pos)
- , Exprs(exprs)
-{}
-
-bool TStructNode::DoInit(TContext& ctx, ISource* src) {
- Nodes.push_back(BuildAtom(Pos, "AsStruct", TNodeFlags::Default));
- for (const auto& expr : Exprs) {
- const auto& label = expr->GetLabel();
- if (!label) {
- ctx.Error(expr->GetPos()) << "Structure does not allow anonymous members";
- return false;
+ : TAstListNode(pos)
+ , Exprs(exprs)
+{}
+
+bool TStructNode::DoInit(TContext& ctx, ISource* src) {
+ Nodes.push_back(BuildAtom(Pos, "AsStruct", TNodeFlags::Default));
+ for (const auto& expr : Exprs) {
+ const auto& label = expr->GetLabel();
+ if (!label) {
+ ctx.Error(expr->GetPos()) << "Structure does not allow anonymous members";
+ return false;
}
Nodes.push_back(Q(Y(BuildQuotedAtom(expr->GetPos(), label), expr)));
}
- return TAstListNode::DoInit(ctx, src);
-}
-
-TNodePtr TStructNode::DoClone() const {
- return new TStructNode(Pos, CloneContainer(Exprs));
-}
+ return TAstListNode::DoInit(ctx, src);
+}
+
+TNodePtr TStructNode::DoClone() const {
+ return new TStructNode(Pos, CloneContainer(Exprs));
+}
TNodePtr BuildStructure(TPosition pos, const TVector<TNodePtr>& exprs) {
- return new TStructNode(pos, exprs);
+ return new TStructNode(pos, exprs);
}
TListOfNamedNodes::TListOfNamedNodes(TPosition pos, TVector<TNodePtr>&& exprs)
- : INode(pos)
- , Exprs(std::move(exprs))
-{}
-
+ : INode(pos)
+ , Exprs(std::move(exprs))
+{}
+
TVector<TNodePtr>* TListOfNamedNodes::ContentListPtr() {
- return &Exprs;
-}
-
-TAstNode* TListOfNamedNodes::Translate(TContext& ctx) const {
- YQL_ENSURE(!"Unexpected usage");
- Y_UNUSED(ctx);
- return nullptr;
-}
-
-TNodePtr TListOfNamedNodes::DoClone() const {
- return {};
-}
-
+ return &Exprs;
+}
+
+TAstNode* TListOfNamedNodes::Translate(TContext& ctx) const {
+ YQL_ENSURE(!"Unexpected usage");
+ Y_UNUSED(ctx);
+ return nullptr;
+}
+
+TNodePtr TListOfNamedNodes::DoClone() const {
+ return {};
+}
+
TNodePtr BuildListOfNamedNodes(TPosition pos, TVector<TNodePtr>&& exprs) {
- return new TListOfNamedNodes(pos, std::move(exprs));
-}
-
+ return new TListOfNamedNodes(pos, std::move(exprs));
+}
+
const char* const TArgPlaceholderNode::ProcessRows = "$ROWS";
const char* const TArgPlaceholderNode::ProcessRow = "$ROW";
@@ -2146,10 +2146,10 @@ TString TArgPlaceholderNode::GetName() const {
return Name;
}
-TNodePtr TArgPlaceholderNode::DoClone() const {
- return {};
-}
-
+TNodePtr TArgPlaceholderNode::DoClone() const {
+ return {};
+}
+
TNodePtr BuildArgPlaceholder(TPosition pos, const TString& name) {
return new TArgPlaceholderNode(pos, name);
}
@@ -2253,16 +2253,16 @@ public:
return Ids[0].Expr->GetSourceName();
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
auto expr = Ids[0].Expr;
const TPosition pos(expr->GetPos());
if (expr->IsAsterisk()) {
ctx.Error(pos) << "Asterisk column does not allow any access";
return false;
}
- if (!expr->Init(ctx, src)) {
- return false;
- }
+ if (!expr->Init(ctx, src)) {
+ return false;
+ }
for (auto& id: Ids) {
if (id.Expr && !id.Expr->Init(ctx, src)) {
return false;
@@ -2271,8 +2271,8 @@ public:
ui32 idx = 1;
auto column = dynamic_cast<TColumnNode*>(expr.Get());
if (column) {
- const bool useSourceAsColumn = column->IsUseSourceAsColumn();
- ColumnOnly &= !useSourceAsColumn;
+ const bool useSourceAsColumn = column->IsUseSourceAsColumn();
+ ColumnOnly &= !useSourceAsColumn;
if (IsColumnRequired && !ColumnOnly) {
ctx.Error(pos) << "Please use a full form (corellation.struct.field) or an alias (struct.field as alias) to access struct's field in the GROUP BY";
return false;
@@ -2284,24 +2284,24 @@ public:
}
++idx;
}
- if (!useSourceAsColumn) {
+ if (!useSourceAsColumn) {
if (!IsLookup && !CheckColumnId(pos, ctx, Ids[idx], ColumnOnly ? "Column" : "Member", false)) {
- return false;
- }
- ++idx;
+ return false;
+ }
+ ++idx;
}
}
for (; idx < Ids.size(); ++idx) {
const auto& id = Ids[idx];
if (!id.Name.empty()) {
expr = Y("SqlAccess", Q("struct"), expr, id.Expr ? Y("EvaluateAtom", id.Expr) : BuildQuotedAtom(Pos, id.Name));
- AccessOpName = "AccessStructMember";
+ AccessOpName = "AccessStructMember";
} else if (id.Expr) {
expr = Y("SqlAccess", Q("dict"), expr, id.Expr);
- AccessOpName = "AccessDictMember";
+ AccessOpName = "AccessDictMember";
} else if (id.Pos >= 0) {
expr = Y("SqlAccess", Q("tuple"), expr, Q(ToString(id.Pos)));
- AccessOpName = "AccessTupleElement";
+ AccessOpName = "AccessTupleElement";
} else {
continue;
}
@@ -2321,31 +2321,31 @@ public:
return true;
}
- TAstNode* Translate(TContext& ctx) const override {
+ TAstNode* Translate(TContext& ctx) const override {
Y_VERIFY_DEBUG(Node);
return Node->Translate(ctx);
}
- TPtr DoClone() const override {
- YQL_ENSURE(!Node, "TAccessNode::Clone: Node should not be initialized");
+ TPtr DoClone() const override {
+ YQL_ENSURE(!Node, "TAccessNode::Clone: Node should not be initialized");
TVector<TIdPart> cloneIds;
- cloneIds.reserve(Ids.size());
+ cloneIds.reserve(Ids.size());
for (const auto& id: Ids) {
- cloneIds.emplace_back(id.Clone());
- }
+ cloneIds.emplace_back(id.Clone());
+ }
auto copy = new TAccessNode(Pos, cloneIds, IsLookup);
- copy->ColumnOnly = ColumnOnly;
- return copy;
- }
-
+ copy->ColumnOnly = ColumnOnly;
+ return copy;
+ }
+
protected:
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, Ids[0].Expr->IsConstant());
- State.Set(ENodeState::Aggregated, Ids[0].Expr->IsAggregated());
- State.Set(ENodeState::AggregationKey, Ids[0].Expr->HasState(ENodeState::AggregationKey));
- State.Set(ENodeState::OverWindow, Ids[0].Expr->IsOverWindow());
- }
-
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, Ids[0].Expr->IsConstant());
+ State.Set(ENodeState::Aggregated, Ids[0].Expr->IsAggregated());
+ State.Set(ENodeState::AggregationKey, Ids[0].Expr->HasState(ENodeState::AggregationKey));
+ State.Set(ENodeState::OverWindow, Ids[0].Expr->IsOverWindow());
+ }
+
bool CheckColumnId(TPosition pos, TContext& ctx, const TIdPart& id, const TString& where, bool checkLookup) {
if (id.Name.empty()) {
ctx.Error(pos) << where << " name can not be empty";
@@ -2362,17 +2362,17 @@ protected:
return true;
}
- TString GetOpName() const override {
- return AccessOpName;
- }
-
+ TString GetOpName() const override {
+ return AccessOpName;
+ }
+
private:
TNodePtr Node;
TVector<TIdPart> Ids;
bool IsLookup;
bool ColumnOnly;
bool IsColumnRequired;
- TString AccessOpName;
+ TString AccessOpName;
};
TNodePtr BuildAccess(TPosition pos, const TVector<INode::TIdPart>& ids, bool isLookup) {
@@ -2386,10 +2386,10 @@ public:
{
Add("bind", AstNode(module), BuildQuotedAtom(pos, alias));
}
-
- TPtr DoClone() const final {
- return {};
- }
+
+ TPtr DoClone() const final {
+ return {};
+ }
};
TNodePtr BuildBind(TPosition pos, const TString& module, const TString& alias) {
@@ -2407,8 +2407,8 @@ public:
Add("lambda", Q(params), body);
}
- TPtr DoClone() const final {
- return {};
+ TPtr DoClone() const final {
+ return {};
}
};
@@ -2428,33 +2428,33 @@ public:
{}
const TString* GetSourceName() const override {
- return Expr->GetSourceName();
+ return Expr->GetSourceName();
}
-
+
TString GetOpName() const override {
return Bit ? "BitCast" : "Cast";
- }
-
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, Expr->IsConstant());
- State.Set(ENodeState::Aggregated, Expr->IsAggregated());
- State.Set(ENodeState::OverWindow, Expr->IsOverWindow());
- }
-
- TPtr DoClone() const final {
+ }
+
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, Expr->IsConstant());
+ State.Set(ENodeState::Aggregated, Expr->IsAggregated());
+ State.Set(ENodeState::OverWindow, Expr->IsOverWindow());
+ }
+
+ TPtr DoClone() const final {
return new TCastNode(Pos, Expr->Clone(), NormalizedTypeName, ParamOne, ParamTwo);
- }
-
- bool DoInit(TContext& ctx, ISource* src) override;
-private:
- TNodePtr Expr;
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) override;
+private:
+ TNodePtr Expr;
const TString NormalizedTypeName;
const TString ParamOne, ParamTwo;
};
template <>
bool TCastNode<false>::DoInit(TContext& ctx, ISource* src) {
- if (Expr->IsNull()) {
+ if (Expr->IsNull()) {
if (ParamOne.empty() && ParamTwo.empty()) {
Add("Nothing", Y("OptionalType", Y("DataType", Q(NormalizedTypeName))));
} else if (ParamTwo.empty()) {
@@ -2462,7 +2462,7 @@ bool TCastNode<false>::DoInit(TContext& ctx, ISource* src) {
} else {
Add("Nothing", Y("OptionalType", Y("DataType", Q(NormalizedTypeName), Q(ParamOne), Q(ParamTwo))));
}
- } else {
+ } else {
if (ParamOne.empty() && ParamTwo.empty()) {
Add("Cast", Expr, Q(NormalizedTypeName));
} else if (ParamTwo.empty()) {
@@ -2471,7 +2471,7 @@ bool TCastNode<false>::DoInit(TContext& ctx, ISource* src) {
Add("Cast", Expr, Q(NormalizedTypeName), Q(ParamOne), Q(ParamTwo));
}
}
- return TAstListNode::DoInit(ctx, src);
+ return TAstListNode::DoInit(ctx, src);
}
template <>
@@ -2524,8 +2524,8 @@ TString TypeByAlias(const TString& alias, bool normalize) {
} else if (typeAlias == "smallint") {
type = "Int16";
} else if (typeAlias == "int" || typeAlias == "integer") {
- type = "Int32";
- } else if (typeAlias == "bigint") {
+ type = "Int32";
+ } else if (typeAlias == "bigint") {
type = "Int64";
}
return normalize ? NormalizeTypeString(type) : type;
@@ -2538,7 +2538,7 @@ TNodePtr BuildIsNullOp(TPosition pos, TNodePtr a) {
if (a->IsNull()) {
return BuildLiteralBool(pos, "true");
}
- return new TCallNodeImpl(pos, "Not", {new TCallNodeImpl(pos, "Exists", {a})});
+ return new TCallNodeImpl(pos, "Not", {new TCallNodeImpl(pos, "Exists", {a})});
}
TNodePtr BuildUnaryOp(TPosition pos, const TString& opName, TNodePtr a) {
@@ -2548,16 +2548,16 @@ TNodePtr BuildUnaryOp(TPosition pos, const TString& opName, TNodePtr a) {
if (a->IsNull()) {
return BuildLiteralNull(pos);
}
- return new TCallNodeImpl(pos, opName, {a});
+ return new TCallNodeImpl(pos, opName, {a});
}
-class TBinaryOpNode final: public TCallNode {
+class TBinaryOpNode final: public TCallNode {
public:
TBinaryOpNode(TPosition pos, const TString& opName, TNodePtr a, TNodePtr b);
- TNodePtr DoClone() const final {
- YQL_ENSURE(Args.size() == 2);
- return new TBinaryOpNode(Pos, OpName, Args[0]->Clone(), Args[1]->Clone());
+ TNodePtr DoClone() const final {
+ YQL_ENSURE(Args.size() == 2);
+ return new TBinaryOpNode(Pos, OpName, Args[0]->Clone(), Args[1]->Clone());
}
};
@@ -2576,45 +2576,45 @@ TNodePtr BuildBinaryOp(TPosition pos, const TString& opName, TNodePtr a, TNodePt
return new TBinaryOpNode(pos, opName, a, b);
}
-class TCalcOverWindow final: public INode {
-public:
+class TCalcOverWindow final: public INode {
+public:
TCalcOverWindow(TPosition pos, const TString& windowName, TNodePtr node)
- : INode(pos)
- , WindowName(windowName)
- , FuncNode(node)
- {}
-
- TAstNode* Translate(TContext& ctx) const override {
- return FuncNode->Translate(ctx);
- }
-
- bool DoInit(TContext& ctx, ISource* src) override {
- YQL_ENSURE(src);
- TSourcePtr overWindowSource = BuildOverWindowSource(ctx.Pos(), WindowName, src);
- if (!FuncNode->Init(ctx, overWindowSource.Get())) {
- return false;
- }
- return true;
- }
-
- TPtr DoClone() const final {
- return new TCalcOverWindow(Pos, WindowName, SafeClone(FuncNode));
- }
-
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, FuncNode->IsConstant());
- State.Set(ENodeState::Aggregated, FuncNode->IsAggregated());
- State.Set(ENodeState::OverWindow, true);
- }
-protected:
+ : INode(pos)
+ , WindowName(windowName)
+ , FuncNode(node)
+ {}
+
+ TAstNode* Translate(TContext& ctx) const override {
+ return FuncNode->Translate(ctx);
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ YQL_ENSURE(src);
+ TSourcePtr overWindowSource = BuildOverWindowSource(ctx.Pos(), WindowName, src);
+ if (!FuncNode->Init(ctx, overWindowSource.Get())) {
+ return false;
+ }
+ return true;
+ }
+
+ TPtr DoClone() const final {
+ return new TCalcOverWindow(Pos, WindowName, SafeClone(FuncNode));
+ }
+
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, FuncNode->IsConstant());
+ State.Set(ENodeState::Aggregated, FuncNode->IsAggregated());
+ State.Set(ENodeState::OverWindow, true);
+ }
+protected:
const TString WindowName;
- TNodePtr FuncNode;
-};
-
+ TNodePtr FuncNode;
+};
+
TNodePtr BuildCalcOverWindow(TPosition pos, const TString& windowName, TNodePtr call) {
- return new TCalcOverWindow(pos, windowName, call);
-}
-
+ return new TCalcOverWindow(pos, windowName, call);
+}
+
class TYsonOptionsNode final: public INode {
public:
TYsonOptionsNode(TPosition pos, bool autoConvert, bool strict)
@@ -2656,53 +2656,53 @@ TNodePtr BuildYsonOptionsNode(TPosition pos, bool autoConvert, bool strict) {
return new TYsonOptionsNode(pos, autoConvert, strict);
}
-class TShortcutNode: public TAstAtomNode {
- TNodePtr ShortcutNode;
- TNodePtr SameNode;
- const TString BaseName;
-public:
- TShortcutNode(const TNodePtr& node, const TString& baseName)
- : TAstAtomNode(node->GetPos(), TStringBuilder() << "Shortcut" << baseName, TNodeFlags::Default)
- , ShortcutNode(node)
- , BaseName(baseName)
- {}
-
- bool DoInit(TContext& ctx, ISource* src) override {
- auto shortcut = ctx.HasBlockShortcut(ShortcutNode);
- if (!shortcut) {
- SameNode = ShortcutNode->Clone();
- if (!SameNode->Init(ctx, src)) {
- return false;
- }
- shortcut = ctx.RegisterBlockShortcut(ShortcutNode, SameNode, BaseName);
- YQL_ENSURE(shortcut);
- } else {
- SameNode = ctx.GetBlockShortcut(shortcut);
- }
- Content = shortcut;
- return true;
- }
-
- const TString* GetSourceName() const override {
- return ShortcutNode->GetSourceName();
- }
-
- void DoUpdateState() const override {
- auto& workedNode = SameNode ? SameNode : ShortcutNode;
- State.Set(ENodeState::Const, workedNode->IsConstant());
- State.Set(ENodeState::Aggregated, workedNode->IsAggregated());
- State.Set(ENodeState::OverWindow, workedNode->IsOverWindow());
- }
-
- TNodePtr DoClone() const final {
- return new TShortcutNode(ShortcutNode, BaseName);
- }
-};
-
-TNodePtr BuildShortcutNode(const TNodePtr& node, const TString& baseName) {
- return new TShortcutNode(node, baseName);
-}
-
+class TShortcutNode: public TAstAtomNode {
+ TNodePtr ShortcutNode;
+ TNodePtr SameNode;
+ const TString BaseName;
+public:
+ TShortcutNode(const TNodePtr& node, const TString& baseName)
+ : TAstAtomNode(node->GetPos(), TStringBuilder() << "Shortcut" << baseName, TNodeFlags::Default)
+ , ShortcutNode(node)
+ , BaseName(baseName)
+ {}
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ auto shortcut = ctx.HasBlockShortcut(ShortcutNode);
+ if (!shortcut) {
+ SameNode = ShortcutNode->Clone();
+ if (!SameNode->Init(ctx, src)) {
+ return false;
+ }
+ shortcut = ctx.RegisterBlockShortcut(ShortcutNode, SameNode, BaseName);
+ YQL_ENSURE(shortcut);
+ } else {
+ SameNode = ctx.GetBlockShortcut(shortcut);
+ }
+ Content = shortcut;
+ return true;
+ }
+
+ const TString* GetSourceName() const override {
+ return ShortcutNode->GetSourceName();
+ }
+
+ void DoUpdateState() const override {
+ auto& workedNode = SameNode ? SameNode : ShortcutNode;
+ State.Set(ENodeState::Const, workedNode->IsConstant());
+ State.Set(ENodeState::Aggregated, workedNode->IsAggregated());
+ State.Set(ENodeState::OverWindow, workedNode->IsOverWindow());
+ }
+
+ TNodePtr DoClone() const final {
+ return new TShortcutNode(ShortcutNode, BaseName);
+ }
+};
+
+TNodePtr BuildShortcutNode(const TNodePtr& node, const TString& baseName) {
+ return new TShortcutNode(node, baseName);
+}
+
class TDoCall final : public INode {
public:
TDoCall(TPosition pos, const TNodePtr& node)
@@ -2756,10 +2756,10 @@ bool Parseui32(TNodePtr from, ui32& to) {
return TryFromString(*val, to);
}
-TNodePtr GroundWithExpr(const TNodePtr& ground, const TNodePtr& expr) {
- return ground ? expr->Y("block", expr->Q(expr->L(ground, expr->Y("return", expr)))) : expr;
-}
-
+TNodePtr GroundWithExpr(const TNodePtr& ground, const TNodePtr& expr) {
+ return ground ? expr->Y("block", expr->Q(expr->L(ground, expr->Y("return", expr)))) : expr;
+}
+
TSourcePtr TryMakeSourceFromExpression(TContext& ctx, TNodePtr node, const TString& view) {
if (auto literal = node->GetLiteral("String")) {
if (ctx.CurrCluster.empty()) {
diff --git a/ydb/library/yql/sql/v0/node.h b/ydb/library/yql/sql/v0/node.h
index c6f4f9f3fa..4c7cfc273b 100644
--- a/ydb/library/yql/sql/v0/node.h
+++ b/ydb/library/yql/sql/v0/node.h
@@ -1,6 +1,6 @@
#pragma once
-#include <array>
+#include <array>
#include <google/protobuf/message.h>
#include <ydb/library/yql/parser/proto_ast/proto_ast.h>
#include <ydb/library/yql/ast/yql_ast.h>
@@ -8,60 +8,60 @@
#include <util/generic/vector.h>
#include <util/generic/set.h>
#include <util/generic/map.h>
-#include <util/generic/hash.h>
-#include <util/generic/hash_set.h>
-#include <util/generic/maybe.h>
-#include <util/string/builder.h>
+#include <util/generic/hash.h>
+#include <util/generic/hash_set.h>
+#include <util/generic/maybe.h>
+#include <util/string/builder.h>
#include <library/cpp/enumbitset/enumbitset.h>
-
+
namespace NSQLTranslationV0 {
- constexpr const size_t SQL_MAX_INLINE_SCRIPT_LEN = 24;
-
+ constexpr const size_t SQL_MAX_INLINE_SCRIPT_LEN = 24;
+
using NYql::TPosition;
using NYql::TAstNode;
- enum class ENodeState {
- Begin,
- Precached = Begin,
- Initialized,
- CountHint,
- Const,
- Aggregated,
- AggregationKey,
- OverWindow,
+ enum class ENodeState {
+ Begin,
+ Precached = Begin,
+ Initialized,
+ CountHint,
+ Const,
+ Aggregated,
+ AggregationKey,
+ OverWindow,
Failed,
- End,
- };
- typedef TEnumBitSet<ENodeState, static_cast<int>(ENodeState::Begin), static_cast<int>(ENodeState::End)> TNodeState;
-
- enum class ESQLWriteColumnMode {
- InsertInto,
+ End,
+ };
+ typedef TEnumBitSet<ENodeState, static_cast<int>(ENodeState::Begin), static_cast<int>(ENodeState::End)> TNodeState;
+
+ enum class ESQLWriteColumnMode {
+ InsertInto,
InsertOrAbortInto,
InsertOrIgnoreInto,
InsertOrRevertInto,
- UpsertInto,
- ReplaceInto,
- InsertIntoWithTruncate,
- Update,
- Delete,
- };
-
- enum class EWriteColumnMode {
- Default,
+ UpsertInto,
+ ReplaceInto,
+ InsertIntoWithTruncate,
+ Update,
+ Delete,
+ };
+
+ enum class EWriteColumnMode {
+ Default,
Insert,
InsertOrAbort,
InsertOrIgnore,
InsertOrRevert,
- Upsert,
- Replace,
- Renew,
- Update,
+ Upsert,
+ Replace,
+ Renew,
+ Update,
UpdateOn,
- Delete,
+ Delete,
DeleteOn,
- };
-
+ };
+
enum class EAlterTableIntentnt {
AddColumn,
DropColumn
@@ -70,18 +70,18 @@ namespace NSQLTranslationV0 {
class TContext;
class ITableKeys;
class ISource;
- class IAggregation;
- typedef TIntrusivePtr<IAggregation> TAggregationPtr;
-
+ class IAggregation;
+ typedef TIntrusivePtr<IAggregation> TAggregationPtr;
+
inline TString DotJoin(const TString& lhs, const TString& rhs) {
- TStringBuilder sb;
- sb << lhs << "." << rhs;
- return sb;
- }
-
- TString ErrorDistinctByGroupKey(const TString& column);
- TString ErrorDistinctWithoutCorrelation(const TString& column);
-
+ TStringBuilder sb;
+ sb << lhs << "." << rhs;
+ return sb;
+ }
+
+ TString ErrorDistinctByGroupKey(const TString& column);
+ TString ErrorDistinctWithoutCorrelation(const TString& column);
+
class INode: public TSimpleRefCount<INode> {
public:
typedef TIntrusivePtr<INode> TPtr;
@@ -103,12 +103,12 @@ namespace NSQLTranslationV0 {
: Pos(pos)
{
}
- TIdPart Clone() const {
- TIdPart res(Name);
- res.Pos = Pos;
- res.Expr = Expr ? Expr->Clone() : nullptr;
- return res;
- }
+ TIdPart Clone() const {
+ TIdPart res(Name);
+ res.Pos = Pos;
+ res.Expr = Expr ? Expr->Clone() : nullptr;
+ return res;
+ }
};
public:
@@ -123,35 +123,35 @@ namespace NSQLTranslationV0 {
bool GetCountHint() const;
bool Init(TContext& ctx, ISource* src);
- bool IsConstant() const;
- bool IsAggregated() const;
+ bool IsConstant() const;
+ bool IsAggregated() const;
bool IsAggregationKey() const;
- bool IsOverWindow() const;
- bool HasState(ENodeState state) const {
- PrecacheState();
- return State.Test(state);
- }
-
+ bool IsOverWindow() const;
+ bool HasState(ENodeState state) const {
+ PrecacheState();
+ return State.Test(state);
+ }
+
virtual bool IsNull() const;
- virtual bool IsIntegerLiteral() const;
+ virtual bool IsIntegerLiteral() const;
virtual bool IsAsterisk() const;
- virtual const TString* SubqueryAlias() const;
+ virtual const TString* SubqueryAlias() const;
virtual TString GetOpName() const;
virtual const TString* GetLiteral(const TString& type) const;
virtual const TString* GetColumnName() const;
virtual void AssumeColumn();
virtual const TString* GetSourceName() const;
- virtual const TString* GetAtomContent() const;
+ virtual const TString* GetAtomContent() const;
virtual size_t GetTupleSize() const;
virtual TPtr GetTupleElement(size_t index) const;
virtual ITableKeys* GetTableKeys();
virtual ISource* GetSource();
virtual TVector<INode::TPtr>* ContentListPtr();
virtual TAstNode* Translate(TContext& ctx) const = 0;
- virtual TAggregationPtr GetAggregation() const;
- virtual TPtr WindowSpecFunc(const TPtr& type) const;
+ virtual TAggregationPtr GetAggregation() const;
+ virtual TPtr WindowSpecFunc(const TPtr& type) const;
void UseAsInner();
- virtual bool UsedSubquery() const;
+ virtual bool UsedSubquery() const;
virtual bool IsSelect() const;
TPtr AstNode() const;
@@ -192,12 +192,12 @@ namespace NSQLTranslationV0 {
return copy;
}
- TPtr Clone() const;
+ TPtr Clone() const;
protected:
virtual TPtr ShallowCopy() const;
- virtual void DoUpdateState() const;
- virtual TPtr DoClone() const = 0;
- void PrecacheState() const;
+ virtual void DoUpdateState() const;
+ virtual TPtr DoClone() const = 0;
+ void PrecacheState() const;
private:
virtual bool DoInit(TContext& ctx, ISource* src);
@@ -206,66 +206,66 @@ namespace NSQLTranslationV0 {
protected:
TPosition Pos;
TString Label;
- mutable TNodeState State;
+ mutable TNodeState State;
bool AsInner = false;
};
typedef INode::TPtr TNodePtr;
- template<class T>
- inline T SafeClone(const T& node) {
- return node ? node->Clone() : nullptr;
- }
-
- template<class T>
+ template<class T>
+ inline T SafeClone(const T& node) {
+ return node ? node->Clone() : nullptr;
+ }
+
+ template<class T>
inline TVector<T> CloneContainer(const TVector<T>& args) {
TVector<T> cloneArgs;
- cloneArgs.reserve(args.size());
- for (const auto& arg: args) {
- cloneArgs.emplace_back(SafeClone(arg));
- }
- return cloneArgs;
- }
-
+ cloneArgs.reserve(args.size());
+ for (const auto& arg: args) {
+ cloneArgs.emplace_back(SafeClone(arg));
+ }
+ return cloneArgs;
+ }
+
class TAstAtomNode: public INode {
public:
TAstAtomNode(TPosition pos, const TString& content, ui32 flags);
- ~TAstAtomNode() override;
+ ~TAstAtomNode() override;
- TAstNode* Translate(TContext& ctx) const override;
+ TAstNode* Translate(TContext& ctx) const override;
const TString& GetContent() const {
return Content;
}
- const TString* GetAtomContent() const override;
-
+ const TString* GetAtomContent() const override;
+
protected:
TString Content;
ui32 Flags;
-
- void DoUpdateState() const override;
+
+ void DoUpdateState() const override;
};
- class TAstAtomNodeImpl final: public TAstAtomNode {
+ class TAstAtomNodeImpl final: public TAstAtomNode {
public:
TAstAtomNodeImpl(TPosition pos, const TString& content, ui32 flags)
- : TAstAtomNode(pos, content, flags)
- {}
-
- TNodePtr DoClone() const final {
+ : TAstAtomNode(pos, content, flags)
+ {}
+
+ TNodePtr DoClone() const final {
return new TAstAtomNodeImpl(Pos, Content, Flags);
- }
- };
-
- class TAstDirectNode final: public INode {
- public:
+ }
+ };
+
+ class TAstDirectNode final: public INode {
+ public:
TAstDirectNode(TAstNode* node);
- TAstNode* Translate(TContext& ctx) const override;
+ TAstNode* Translate(TContext& ctx) const override;
- TPtr DoClone() const final {
+ TPtr DoClone() const final {
return new TAstDirectNode(Node);
- }
+ }
protected:
TAstNode* Node;
};
@@ -280,28 +280,28 @@ namespace NSQLTranslationV0 {
protected:
explicit TAstListNode(const TAstListNode& node);
explicit TAstListNode(TPosition pos, TVector<TNodePtr>&& nodes);
- TPtr ShallowCopy() const override;
- bool DoInit(TContext& ctx, ISource* src) override;
- void DoAdd(TNodePtr node) override;
+ TPtr ShallowCopy() const override;
+ bool DoInit(TContext& ctx, ISource* src) override;
+ void DoAdd(TNodePtr node) override;
+
+ void DoUpdateState() const override;
- void DoUpdateState() const override;
-
void UpdateStateByListNodes(const TVector<TNodePtr>& Nodes) const;
-
+
protected:
TVector<TNodePtr> Nodes;
- mutable TMaybe<bool> CacheGroupKey;
+ mutable TMaybe<bool> CacheGroupKey;
};
- class TAstListNodeImpl final: public TAstListNode {
- public:
- TAstListNodeImpl(TPosition pos);
+ class TAstListNodeImpl final: public TAstListNode {
+ public:
+ TAstListNodeImpl(TPosition pos);
TAstListNodeImpl(TPosition pos, TVector<TNodePtr> nodes);
-
- protected:
- TNodePtr DoClone() const final;
- };
-
+
+ protected:
+ TNodePtr DoClone() const final;
+ };
+
class TCallNode: public TAstListNode {
public:
TCallNode(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args);
@@ -315,8 +315,8 @@ namespace NSQLTranslationV0 {
const TVector<TNodePtr>& GetArgs() const;
protected:
- bool DoInit(TContext& ctx, ISource* src) override;
- bool ValidateArguments(TContext& ctx) const;
+ bool DoInit(TContext& ctx, ISource* src) override;
+ bool ValidateArguments(TContext& ctx) const;
TString GetCallExplain() const;
protected:
@@ -324,18 +324,18 @@ namespace NSQLTranslationV0 {
i32 MinArgs;
i32 MaxArgs;
TVector<TNodePtr> Args;
- mutable TMaybe<bool> CacheGroupKey;
-
- void DoUpdateState() const override;
+ mutable TMaybe<bool> CacheGroupKey;
+
+ void DoUpdateState() const override;
};
- class TCallNodeImpl final: public TCallNode {
- TPtr DoClone() const final;
- public:
+ class TCallNodeImpl final: public TCallNode {
+ TPtr DoClone() const final;
+ public:
TCallNodeImpl(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args);
TCallNodeImpl(TPosition pos, const TString& opName, const TVector<TNodePtr>& args);
- };
-
+ };
+
class TCallNodeDepArgs final : public TCallNode {
TPtr DoClone() const final;
public:
@@ -348,48 +348,48 @@ namespace NSQLTranslationV0 {
const ui32 ReqArgsCount;
};
- class TCallDirectRow final : public TCallNode {
- TPtr DoClone() const final;
- public:
+ class TCallDirectRow final : public TCallNode {
+ TPtr DoClone() const final;
+ public:
TCallDirectRow(TPosition pos, const TString& opName, const TVector<TNodePtr>& args);
- protected:
- bool DoInit(TContext& ctx, ISource* src) override;
- void DoUpdateState() const override;
- };
-
- class TWinAggrEmulation: public TCallNode {
- protected:
- void DoUpdateState() const override;
- bool DoInit(TContext& ctx, ISource* src) override;
+ protected:
+ bool DoInit(TContext& ctx, ISource* src) override;
+ void DoUpdateState() const override;
+ };
+
+ class TWinAggrEmulation: public TCallNode {
+ protected:
+ void DoUpdateState() const override;
+ bool DoInit(TContext& ctx, ISource* src) override;
TPtr WindowSpecFunc(const TNodePtr& type) const override;
- public:
+ public:
TWinAggrEmulation(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args);
- protected:
- template<class TNodeType>
- TPtr CallNodeClone() const {
- return new TNodeType(GetPos(), OpName, MinArgs, MaxArgs, CloneContainer(Args));
- }
+ protected:
+ template<class TNodeType>
+ TPtr CallNodeClone() const {
+ return new TNodeType(GetPos(), OpName, MinArgs, MaxArgs, CloneContainer(Args));
+ }
TString FuncAlias;
- TNodePtr WinAggrGround;
- };
-
- class TWinRowNumber final: public TWinAggrEmulation {
- TPtr DoClone() const final {
- return CallNodeClone<TWinRowNumber>();
- }
- public:
+ TNodePtr WinAggrGround;
+ };
+
+ class TWinRowNumber final: public TWinAggrEmulation {
+ TPtr DoClone() const final {
+ return CallNodeClone<TWinRowNumber>();
+ }
+ public:
TWinRowNumber(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args);
- };
-
- class TWinLeadLag final: public TWinAggrEmulation {
- TPtr DoClone() const final {
- return CallNodeClone<TWinLeadLag>();
- }
- bool DoInit(TContext& ctx, ISource* src) override;
- public:
+ };
+
+ class TWinLeadLag final: public TWinAggrEmulation {
+ TPtr DoClone() const final {
+ return CallNodeClone<TWinLeadLag>();
+ }
+ bool DoInit(TContext& ctx, ISource* src) override;
+ public:
TWinLeadLag(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args);
- };
-
+ };
+
class ITableKeys: public INode {
public:
enum class EBuildKeysMode {
@@ -404,13 +404,13 @@ namespace NSQLTranslationV0 {
virtual TNodePtr BuildKeys(TContext& ctx, EBuildKeysMode mode) = 0;
private:
- /// all TableKeys no clonnable
- TPtr DoClone() const final {
- return {};
- }
-
- ITableKeys* GetTableKeys() override;
- TAstNode* Translate(TContext& ctx) const override;
+ /// all TableKeys no clonnable
+ TPtr DoClone() const final {
+ return {};
+ }
+
+ ITableKeys* GetTableKeys() override;
+ TAstNode* Translate(TContext& ctx) const override;
};
enum class ESampleMode {
@@ -460,65 +460,65 @@ namespace NSQLTranslationV0 {
TVector<TString> List;
TVector<bool> NamedColumns;
bool All = false;
- bool QualifiedAll = false;
- bool HasUnreliable = false;
+ bool QualifiedAll = false;
+ bool HasUnreliable = false;
bool Add(const TString* column, bool countHint, bool isArtificial = false, bool isReliable = true, bool hasName = true);
void Merge(const TColumns& columns);
void SetPrefix(const TString& prefix);
void SetAll();
- bool IsColumnPossible(TContext& ctx, const TString& column);
+ bool IsColumnPossible(TContext& ctx, const TString& column);
+ };
+
+ struct TSortSpecification: public TSimpleRefCount<TSortSpecification> {
+ TNodePtr OrderExpr;
+ bool Ascending;
+ TIntrusivePtr<TSortSpecification> Clone() const;
+ ~TSortSpecification() {}
+ };
+ typedef TIntrusivePtr<TSortSpecification> TSortSpecificationPtr;
+
+ enum EFrameType {
+ FrameByRows,
+ FrameByRange,
+ };
+ enum EFrameExclusions {
+ FrameExclNone,
+ FrameExclCurRow,
+ FrameExclGroup,
+ FrameExclTies,
+ FrameExclNoOthers,
+ };
+ struct TFrameSpecification {
+ EFrameType FrameType;
+ TNodePtr FrameBegin;
+ TNodePtr FrameEnd;
+ EFrameExclusions FrameExclusion = FrameExclNone;
};
- struct TSortSpecification: public TSimpleRefCount<TSortSpecification> {
- TNodePtr OrderExpr;
- bool Ascending;
- TIntrusivePtr<TSortSpecification> Clone() const;
- ~TSortSpecification() {}
- };
- typedef TIntrusivePtr<TSortSpecification> TSortSpecificationPtr;
-
- enum EFrameType {
- FrameByRows,
- FrameByRange,
- };
- enum EFrameExclusions {
- FrameExclNone,
- FrameExclCurRow,
- FrameExclGroup,
- FrameExclTies,
- FrameExclNoOthers,
- };
- struct TFrameSpecification {
- EFrameType FrameType;
- TNodePtr FrameBegin;
- TNodePtr FrameEnd;
- EFrameExclusions FrameExclusion = FrameExclNone;
- };
-
- struct TWindowSpecification: public TSimpleRefCount<TWindowSpecification> {
+ struct TWindowSpecification: public TSimpleRefCount<TWindowSpecification> {
TMaybe<TString> ExistingWindowName;
TVector<TNodePtr> Partitions;
TVector<TSortSpecificationPtr> OrderBy;
- TMaybe<TFrameSpecification> Frame;
-
- TIntrusivePtr<TWindowSpecification> Clone() const;
- ~TWindowSpecification() {}
- };
-
+ TMaybe<TFrameSpecification> Frame;
+
+ TIntrusivePtr<TWindowSpecification> Clone() const;
+ ~TWindowSpecification() {}
+ };
+
struct THoppingWindowSpec: public TSimpleRefCount<THoppingWindowSpec> {
TNodePtr TimeExtractor;
TNodePtr Hop;
TNodePtr Interval;
TNodePtr Delay;
-
- TIntrusivePtr<THoppingWindowSpec> Clone() const;
- ~THoppingWindowSpec() {}
+
+ TIntrusivePtr<THoppingWindowSpec> Clone() const;
+ ~THoppingWindowSpec() {}
};
- typedef TIntrusivePtr<TWindowSpecification> TWindowSpecificationPtr;
+ typedef TIntrusivePtr<TWindowSpecification> TWindowSpecificationPtr;
typedef TMap<TString, TWindowSpecificationPtr> TWinSpecs;
-
+
typedef TVector<TTableRef> TTableList;
typedef TIntrusivePtr<THoppingWindowSpec> THoppingWindowSpecPtr;
@@ -546,47 +546,47 @@ namespace NSQLTranslationV0 {
TDeferredAtom Label;
};
- class TColumnNode final: public INode {
+ class TColumnNode final: public INode {
public:
TColumnNode(TPosition pos, const TString& column, const TString& source);
TColumnNode(TPosition pos, const TNodePtr& column, const TString& source);
-
+
virtual ~TColumnNode();
bool IsAsterisk() const override;
- virtual bool IsArtificial() const;
+ virtual bool IsArtificial() const;
const TString* GetColumnName() const override;
const TString* GetSourceName() const override;
TAstNode* Translate(TContext& ctx) const override;
void ResetColumn(const TString& column, const TString& source);
void ResetColumn(const TNodePtr& column, const TString& source);
- void SetUseSourceAsColumn();
- void SetUseSource();
- void ResetAsReliable();
- void SetAsNotReliable();
- bool IsReliable() const;
- bool IsUseSourceAsColumn() const;
-
+ void SetUseSourceAsColumn();
+ void SetUseSource();
+ void ResetAsReliable();
+ void SetAsNotReliable();
+ bool IsReliable() const;
+ bool IsUseSourceAsColumn() const;
+
private:
- bool DoInit(TContext& ctx, ISource* src) override;
- TPtr DoClone() const final;
+ bool DoInit(TContext& ctx, ISource* src) override;
+ TPtr DoClone() const final;
+
+ void DoUpdateState() const override;
- void DoUpdateState() const override;
-
private:
static const TString Empty;
TNodePtr Node;
TString ColumnName;
TNodePtr ColumnExpr;
TString Source;
- bool GroupKey = false;
- bool Artificial = false;
- bool Reliable = true;
- bool UseSource = false;
- bool UseSourceAsColumn = false;
+ bool GroupKey = false;
+ bool Artificial = false;
+ bool Reliable = true;
+ bool UseSource = false;
+ bool UseSourceAsColumn = false;
};
- class TArgPlaceholderNode final: public INode
+ class TArgPlaceholderNode final: public INode
{
public:
static const char* const ProcessRows;
@@ -594,63 +594,63 @@ namespace NSQLTranslationV0 {
public:
TArgPlaceholderNode(TPosition pos, const TString &name);
- TAstNode* Translate(TContext& ctx) const override;
+ TAstNode* Translate(TContext& ctx) const override;
TString GetName() const;
- TNodePtr DoClone() const final;
+ TNodePtr DoClone() const final;
protected:
- bool DoInit(TContext& ctx, ISource* src) override;
+ bool DoInit(TContext& ctx, ISource* src) override;
private:
TString Name;
};
- enum class EAggregateMode {
- Normal,
- Distinct,
- OverWindow,
- };
-
- class TTupleNode: public TAstListNode {
- public:
+ enum class EAggregateMode {
+ Normal,
+ Distinct,
+ OverWindow,
+ };
+
+ class TTupleNode: public TAstListNode {
+ public:
TTupleNode(TPosition pos, const TVector<TNodePtr>& exprs);
-
- bool IsEmpty() const;
+
+ bool IsEmpty() const;
const TVector<TNodePtr>& Elements() const;
- bool DoInit(TContext& ctx, ISource* src) override;
- size_t GetTupleSize() const override;
- TPtr GetTupleElement(size_t index) const override;
- TNodePtr DoClone() const final;
- private:
+ bool DoInit(TContext& ctx, ISource* src) override;
+ size_t GetTupleSize() const override;
+ TPtr GetTupleElement(size_t index) const override;
+ TNodePtr DoClone() const final;
+ private:
const TVector<TNodePtr> Exprs;
- };
-
- class TStructNode: public TAstListNode {
- public:
+ };
+
+ class TStructNode: public TAstListNode {
+ public:
TStructNode(TPosition pos, const TVector<TNodePtr>& exprs);
-
- bool DoInit(TContext& ctx, ISource* src) override;
- TNodePtr DoClone() const final;
+
+ bool DoInit(TContext& ctx, ISource* src) override;
+ TNodePtr DoClone() const final;
const TVector<TNodePtr>& GetExprs() {
return Exprs;
}
- private:
+ private:
const TVector<TNodePtr> Exprs;
- };
-
+ };
+
class IAggregation: public INode {
public:
bool IsDistinct() const;
- void DoUpdateState() const override;
-
+ void DoUpdateState() const override;
+
virtual const TString* GetGenericKey() const;
virtual bool InitAggr(TContext& ctx, bool isFactory, ISource* src, TAstListNode& node, const TVector<TNodePtr>& exprs) = 0;
- virtual TNodePtr AggregationTraits(const TNodePtr& type) const;
+ virtual TNodePtr AggregationTraits(const TNodePtr& type) const;
virtual TNodePtr AggregationTraitsFactory() const = 0;
@@ -658,8 +658,8 @@ namespace NSQLTranslationV0 {
virtual void AddFactoryArguments(TNodePtr& apply) const;
- virtual TNodePtr WindowTraits(const TNodePtr& type) const;
-
+ virtual TNodePtr WindowTraits(const TNodePtr& type) const;
+
const TString& GetName() const;
virtual void Join(IAggregation* aggr);
@@ -673,24 +673,24 @@ namespace NSQLTranslationV0 {
TString Name;
const TString Func;
- const EAggregateMode AggMode;
+ const EAggregateMode AggMode;
TString DistinctKey;
};
- enum class EExprSeat: int {
- Open = 0,
- FlattenBy,
- GroupBy,
- Projection,
- WindowPartitionBy,
- Max
- };
-
- enum class EExprType: int {
- WithExpression,
- ColumnOnly,
- };
-
+ enum class EExprSeat: int {
+ Open = 0,
+ FlattenBy,
+ GroupBy,
+ Projection,
+ WindowPartitionBy,
+ Max
+ };
+
+ enum class EExprType: int {
+ WithExpression,
+ ColumnOnly,
+ };
+
class IJoin;
class ISource: public INode {
public:
@@ -700,9 +700,9 @@ namespace NSQLTranslationV0 {
virtual void AllColumns();
virtual const TColumns* GetColumns() const;
virtual void GetInputTables(TTableList& tableList) const;
- /// in case of error unfilled, flag show if ensure column name
- virtual TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column);
- virtual void FinishColumns();
+ /// in case of error unfilled, flag show if ensure column name
+ virtual TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column);
+ virtual void FinishColumns();
virtual bool AddExpressions(TContext& ctx, const TVector<TNodePtr>& columns, EExprSeat exprSeat);
virtual void SetFlattenByMode(const TString& mode);
virtual void MarkFlattenColumns();
@@ -711,68 +711,68 @@ namespace NSQLTranslationV0 {
virtual bool AddGroupKey(TContext& ctx, const TString& column);
virtual TString MakeLocalName(const TString& name);
virtual bool AddAggregation(TContext& ctx, TAggregationPtr aggr);
- virtual bool AddFuncOverWindow(TContext& ctx, TNodePtr expr);
+ virtual bool AddFuncOverWindow(TContext& ctx, TNodePtr expr);
virtual void AddTmpWindowColumn(const TString& column);
virtual const TVector<TString>& GetTmpWindowColumns() const;
virtual bool HasAggregations() const;
- virtual void AddWindowSpecs(TWinSpecs winSpecs);
+ virtual void AddWindowSpecs(TWinSpecs winSpecs);
virtual bool AddAggregationOverWindow(TContext& ctx, const TString& windowName, TAggregationPtr func);
virtual bool AddFuncOverWindow(TContext& ctx, const TString& windowName, TNodePtr func);
virtual void SetHoppingWindowSpec(THoppingWindowSpecPtr spec);
virtual THoppingWindowSpecPtr GetHoppingWindowSpec() const;
- virtual bool IsCompositeSource() const;
+ virtual bool IsCompositeSource() const;
virtual bool IsGroupByColumn(const TString& column) const;
- virtual bool IsFlattenByColumns() const;
- virtual bool IsCalcOverWindow() const;
- virtual bool IsOverWindowSource() const;
+ virtual bool IsFlattenByColumns() const;
+ virtual bool IsCalcOverWindow() const;
+ virtual bool IsOverWindowSource() const;
virtual bool IsStream() const;
virtual bool IsOrdered() const;
virtual TWriteSettings GetWriteSettings() const;
virtual bool SetSamplingOptions(TContext& ctx, TPosition pos, ESampleMode mode, TNodePtr samplingRate, TNodePtr samplingSeed);
virtual bool CalculateGroupingHint(TContext& ctx, const TVector<TString>& columns, ui64& hint) const;
virtual TNodePtr BuildFilter(TContext& ctx, const TString& label, const TNodePtr& groundNode);
- virtual TNodePtr BuildFilterLambda(const TNodePtr& groundNode);
+ virtual TNodePtr BuildFilterLambda(const TNodePtr& groundNode);
virtual TNodePtr BuildFlattenByColumns(const TString& label);
virtual TNodePtr BuildFlattenColumns(const TString& label);
- virtual TNodePtr BuildPreaggregatedMap(TContext& ctx);
- virtual TNodePtr BuildPrewindowMap(TContext& ctx, const TNodePtr& groundNode);
+ virtual TNodePtr BuildPreaggregatedMap(TContext& ctx);
+ virtual TNodePtr BuildPrewindowMap(TContext& ctx, const TNodePtr& groundNode);
virtual TNodePtr BuildAggregation(const TString& label);
- virtual TNodePtr BuildCalcOverWindow(TContext& ctx, const TString& label, const TNodePtr& ground);
+ virtual TNodePtr BuildCalcOverWindow(TContext& ctx, const TString& label, const TNodePtr& ground);
virtual TNodePtr BuildSort(TContext& ctx, const TString& label);
virtual IJoin* GetJoin();
- virtual ISource* GetCompositeSource();
- virtual bool IsSelect() const;
+ virtual ISource* GetCompositeSource();
+ virtual bool IsSelect() const;
virtual bool IsTableSource() const;
- virtual bool ShouldUseSourceAsColumn(const TString& source);
- virtual bool IsJoinKeysInitializing() const;
- virtual const TString* GetWindowName() const;
+ virtual bool ShouldUseSourceAsColumn(const TString& source);
+ virtual bool IsJoinKeysInitializing() const;
+ virtual const TString* GetWindowName() const;
virtual bool DoInit(TContext& ctx, ISource* src);
virtual TNodePtr Build(TContext& ctx) = 0;
virtual TMaybe<TString> FindColumnMistype(const TString& name) const;
-
- virtual bool InitFilters(TContext& ctx);
- void AddDependentSource(ISource* usedSource);
+
+ virtual bool InitFilters(TContext& ctx);
+ void AddDependentSource(ISource* usedSource);
bool IsAlias(EExprSeat exprSeat, const TString& label) const;
bool IsExprAlias(const TString& label) const;
- bool IsExprSeat(EExprSeat exprSeat, EExprType type = EExprType::WithExpression) const;
- TString GetGroupByColumnAlias(const TString& column) const;
-
- virtual TWindowSpecificationPtr FindWindowSpecification(TContext& ctx, const TString& windowName) const;
-
- TIntrusivePtr<ISource> CloneSource() const;
-
+ bool IsExprSeat(EExprSeat exprSeat, EExprType type = EExprType::WithExpression) const;
+ TString GetGroupByColumnAlias(const TString& column) const;
+
+ virtual TWindowSpecificationPtr FindWindowSpecification(TContext& ctx, const TString& windowName) const;
+
+ TIntrusivePtr<ISource> CloneSource() const;
+
protected:
ISource(TPosition pos);
virtual TAstNode* Translate(TContext& ctx) const;
void FillSortParts(const TVector<TSortSpecificationPtr>& orderBy, TNodePtr& sortKeySelector, TNodePtr& sortDirection);
TNodePtr BuildSortSpec(const TVector<TSortSpecificationPtr>& orderBy, const TString& label, const TNodePtr& ground, bool traits = false);
-
+
TVector<TNodePtr>& Expressions(EExprSeat exprSeat);
const TVector<TNodePtr>& Expressions(EExprSeat exprSeat) const;
- TNodePtr AliasOrColumn(const TNodePtr& node, bool withSource);
+ TNodePtr AliasOrColumn(const TNodePtr& node, bool withSource);
THashSet<TString> ExprAliases;
THashMap<TString, TString> GroupByColumnAliases;
@@ -783,7 +783,7 @@ namespace NSQLTranslationV0 {
TVector<TAggregationPtr> Aggregations;
TMultiMap<TString, TAggregationPtr> AggregationOverWindow;
TMultiMap<TString, TNodePtr> FuncOverWindow;
- TWinSpecs WinSpecs;
+ TWinSpecs WinSpecs;
THoppingWindowSpecPtr HoppingWindowSpec;
TVector<ISource*> UsedSources;
TString FlattenMode;
@@ -792,16 +792,16 @@ namespace NSQLTranslationV0 {
TVector<TString> TmpWindowColumns;
};
- typedef TIntrusivePtr<ISource> TSourcePtr;
- template<>
+ typedef TIntrusivePtr<ISource> TSourcePtr;
+ template<>
inline TVector<TSourcePtr> CloneContainer<TSourcePtr>(const TVector<TSourcePtr>& args) {
TVector<TSourcePtr> cloneArgs;
- cloneArgs.reserve(args.size());
- for (const auto& arg: args) {
- cloneArgs.emplace_back(arg ? arg->CloneSource() : nullptr);
- }
- return cloneArgs;
- }
+ cloneArgs.reserve(args.size());
+ for (const auto& arg: args) {
+ cloneArgs.emplace_back(arg ? arg->CloneSource() : nullptr);
+ }
+ return cloneArgs;
+ }
class IJoin: public ISource {
public:
@@ -817,43 +817,43 @@ namespace NSQLTranslationV0 {
IJoin(TPosition pos);
};
- class TListOfNamedNodes final: public INode {
- public:
+ class TListOfNamedNodes final: public INode {
+ public:
TListOfNamedNodes(TPosition pos, TVector<TNodePtr>&& exprs);
-
+
TVector<TNodePtr>* ContentListPtr() override;
- TAstNode* Translate(TContext& ctx) const override;
- TPtr DoClone() const final;
- private:
+ TAstNode* Translate(TContext& ctx) const override;
+ TPtr DoClone() const final;
+ private:
TVector<TNodePtr> Exprs;
TString Meaning;
- };
-
- class TLiteralNode: public TAstListNode {
- public:
+ };
+
+ class TLiteralNode: public TAstListNode {
+ public:
TLiteralNode(TPosition pos, bool isNull);
TLiteralNode(TPosition pos, const TString& type, const TString& value);
TLiteralNode(TPosition pos, const TString& value, ui32 nodeFlags);
- bool IsNull() const override;
+ bool IsNull() const override;
const TString* GetLiteral(const TString& type) const override;
- void DoUpdateState() const override;
- TPtr DoClone() const override;
- protected:
- bool Null;
+ void DoUpdateState() const override;
+ TPtr DoClone() const override;
+ protected:
+ bool Null;
bool Void;
TString Type;
TString Value;
- };
-
- template<typename T>
- class TLiteralNumberNode: public TLiteralNode {
- public:
+ };
+
+ template<typename T>
+ class TLiteralNumberNode: public TLiteralNode {
+ public:
TLiteralNumberNode(TPosition pos, const TString& type, const TString& value);
- TPtr DoClone() const override final;
- bool DoInit(TContext& ctx, ISource* src) override;
- bool IsIntegerLiteral() const override;
- };
-
+ TPtr DoClone() const override final;
+ bool DoInit(TContext& ctx, ISource* src) override;
+ bool IsIntegerLiteral() const override;
+ };
+
struct TTableArg {
bool HasAt = false;
TNodePtr Expr;
@@ -863,7 +863,7 @@ namespace NSQLTranslationV0 {
TString StringContent(TContext& ctx, const TString& str);
bool TryStringContent(const TString& input, TString& result, ui32& flags, TString& error, TPosition& pos);
- TString IdContent(TContext& ctx, const TString& str);
+ TString IdContent(TContext& ctx, const TString& str);
TVector<TString> GetContextHints(TContext& ctx);
TString TypeByAlias(const TString& alias, bool normalize = true);
@@ -873,9 +873,9 @@ namespace NSQLTranslationV0 {
TNodePtr BuildLiteralNull(TPosition pos);
TNodePtr BuildLiteralVoid(TPosition pos);
- /// String is checked as quotable, support escaping and multiline
+ /// String is checked as quotable, support escaping and multiline
TNodePtr BuildLiteralSmartString(TContext& ctx, const TString& value);
- TNodePtr BuildLiteralRawString(TPosition pos, const TString& value);
+ TNodePtr BuildLiteralRawString(TPosition pos, const TString& value);
TNodePtr BuildLiteralBool(TPosition pos, const TString& value);
TNodePtr BuildEmptyAction(TPosition pos);
@@ -899,14 +899,14 @@ namespace NSQLTranslationV0 {
TNodePtr BuildCalcOverWindow(TPosition pos, const TString& windowName, TNodePtr call);
TNodePtr BuildYsonOptionsNode(TPosition pos, bool autoConvert, bool strict);
-
- TNodePtr BuildShortcutNode(const TNodePtr& node, const TString& baseName);
+
+ TNodePtr BuildShortcutNode(const TNodePtr& node, const TString& baseName);
TNodePtr BuildDoCall(TPosition pos, const TNodePtr& node);
TNodePtr BuildTupleResult(TNodePtr tuple, int ensureTupleSize);
-
+
// Implemented in aggregation.cpp
TAggregationPtr BuildFactoryAggregation(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode, bool multi = false);
- TAggregationPtr BuildFactoryAggregationWinAutoarg(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode);
+ TAggregationPtr BuildFactoryAggregationWinAutoarg(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode);
TAggregationPtr BuildKeyPayloadFactoryAggregation(TPosition pos, const TString& name, const TString& factory, EAggregateMode aggMode);
TAggregationPtr BuildPayloadPredicateFactoryAggregation(TPosition pos, const TString& name, const TString& factory, EAggregateMode aggMode);
TAggregationPtr BuildTwoArgsFactoryAggregation(TPosition pos, const TString& name, const TString& factory, EAggregateMode aggMode);
@@ -921,22 +921,22 @@ namespace NSQLTranslationV0 {
TAggregationPtr BuildCountAggregation(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode);
TAggregationPtr BuildUserDefinedFactoryAggregation(TPosition pos, const TString& name, const TString& factory, EAggregateMode aggMode);
-
- typedef std::function<TNodePtr (const TString& baseName, const TNodePtr& node)> TFuncPrepareNameNode;
+
+ typedef std::function<TNodePtr (const TString& baseName, const TNodePtr& node)> TFuncPrepareNameNode;
// Implemented in builtin.cpp
TNodePtr BuildCallable(TPosition pos, const TString& module, const TString& name, const TVector<TNodePtr>& args);
TNodePtr BuildUdf(TContext& ctx, TPosition pos, const TString& module, const TString& name, const TVector<TNodePtr>& args);
TNodePtr BuildBuiltinFunc(
- TContext& ctx,
- TPosition pos,
+ TContext& ctx,
+ TPosition pos,
TString name,
const TVector<TNodePtr>& args,
const TString& nameSpace = TString(),
- EAggregateMode aggMode = EAggregateMode::Normal,
- bool* mustUseNamed = nullptr,
- TFuncPrepareNameNode funcPrepareNameNode = {}
+ EAggregateMode aggMode = EAggregateMode::Normal,
+ bool* mustUseNamed = nullptr,
+ TFuncPrepareNameNode funcPrepareNameNode = {}
);
- TNodePtr TryBuildDataType(TPosition pos, const TString& stringType);
+ TNodePtr TryBuildDataType(TPosition pos, const TString& stringType);
// Implemented in join.cpp
TString NormalizeJoinOp(const TString& joinOp);
@@ -945,7 +945,7 @@ namespace NSQLTranslationV0 {
// Implemented in select.cpp
TNodePtr BuildSubquery(TSourcePtr source, const TString& alias, bool inSubquery, int ensureTupleSize = -1);
TNodePtr BuildSubqueryRef(TNodePtr subquery, const TString& alias, int tupleIndex = -1);
- TNodePtr BuildSourceNode(TPosition pos, TSourcePtr source, bool checkExist = false);
+ TNodePtr BuildSourceNode(TPosition pos, TSourcePtr source, bool checkExist = false);
TSourcePtr BuildMuxSource(TPosition pos, TVector<TSourcePtr>&& sources);
TSourcePtr BuildFakeSource(TPosition pos);
TSourcePtr BuildNodeSource(TPosition pos, const TNodePtr& node);
@@ -956,18 +956,18 @@ namespace NSQLTranslationV0 {
TSourcePtr BuildOverWindowSource(TPosition pos, const TString& windowName, ISource* origSource);
TNodePtr BuildOrderBy(TPosition pos, const TVector<TNodePtr>& keys, const TVector<bool>& order);
- TNodePtr BuildSkipTake(TPosition pos, const TNodePtr& skip, const TNodePtr& take);
+ TNodePtr BuildSkipTake(TPosition pos, const TNodePtr& skip, const TNodePtr& take);
+
-
TSourcePtr BuildSelectCore(
- TContext& ctx,
+ TContext& ctx,
TPosition pos,
TSourcePtr source,
const TVector<TNodePtr>& groupByExpr,
const TVector<TNodePtr>& groupBy,
const TVector<TSortSpecificationPtr>& orderBy,
TNodePtr having,
- TWinSpecs&& windowSpec,
+ TWinSpecs&& windowSpec,
THoppingWindowSpecPtr hoppingWindowSpec,
TVector<TNodePtr>&& terms,
bool distinct,
@@ -975,17 +975,17 @@ namespace NSQLTranslationV0 {
bool stream,
const TWriteSettings& settings
);
- TSourcePtr BuildSelect(TPosition pos, TSourcePtr source, TNodePtr skipTake);
+ TSourcePtr BuildSelect(TPosition pos, TSourcePtr source, TNodePtr skipTake);
-
- enum class ReduceMode {
- ByPartition,
- ByAll,
- };
+
+ enum class ReduceMode {
+ ByPartition,
+ ByAll,
+ };
TSourcePtr BuildReduce(TPosition pos, ReduceMode mode, TSourcePtr source, TVector<TSortSpecificationPtr>&& orderBy,
TVector<TNodePtr>&& keys, TVector<TNodePtr>&& args, TNodePtr udf, TNodePtr having, const TWriteSettings& settings);
TSourcePtr BuildProcess(TPosition pos, TSourcePtr source, TNodePtr with, TVector<TNodePtr>&& terms, bool listCall, bool stream, const TWriteSettings& settings);
-
+
TNodePtr BuildSelectResult(TPosition pos, TSourcePtr source, bool writeResult, bool inSubquery);
// Implemented in insert.cpp
@@ -993,12 +993,12 @@ namespace NSQLTranslationV0 {
TSourcePtr BuildWriteValues(TPosition pos, const TString& opertationHumanName, const TVector<TString>& columnsHint, const TVector<TNodePtr>& values);
TSourcePtr BuildWriteValues(TPosition pos, const TString& opertationHumanName, const TVector<TString>& columnsHint, TSourcePtr source);
TSourcePtr BuildUpdateValues(TPosition pos, const TVector<TString>& columnsHint, const TVector<TNodePtr>& values);
-
- EWriteColumnMode ToWriteColumnsMode(ESQLWriteColumnMode sqlWriteColumnMode);
+
+ EWriteColumnMode ToWriteColumnsMode(ESQLWriteColumnMode sqlWriteColumnMode);
TNodePtr BuildEraseColumns(TPosition pos, const TVector<TString>& columns);
TNodePtr BuildWriteColumns(TPosition pos, const TTableRef& table, EWriteColumnMode mode, TSourcePtr values, TNodePtr options = nullptr);
- TNodePtr BuildUpdateColumns(TPosition pos, const TTableRef& table, TSourcePtr values, TSourcePtr source);
- TNodePtr BuildDelete(TPosition pos, const TTableRef& table, TSourcePtr source);
+ TNodePtr BuildUpdateColumns(TPosition pos, const TTableRef& table, TSourcePtr values, TSourcePtr source);
+ TNodePtr BuildDelete(TPosition pos, const TTableRef& table, TSourcePtr source);
// Implemented in query.cpp
TNodePtr BuildTableKey(TPosition pos, const TString& cluster, const TDeferredAtom& name, const TString& view);
@@ -1019,19 +1019,19 @@ namespace NSQLTranslationV0 {
TNodePtr BuildSqlLambda(TPosition pos, TVector<TString>&& args, TVector<TNodePtr>&& exprSeq);
TNodePtr BuildEvaluateIfNode(TPosition pos, TNodePtr predicate, TNodePtr thenNode, TNodePtr elseNode);
TNodePtr BuildEvaluateForNode(TPosition pos, TNodePtr list, TNodePtr bodyNode, TNodePtr elseNode);
-
- template<class TContainer>
- TMaybe<TString> FindMistypeIn(const TContainer& container, const TString& name) {
- for (auto& item: container) {
+
+ template<class TContainer>
+ TMaybe<TString> FindMistypeIn(const TContainer& container, const TString& name) {
+ for (auto& item: container) {
if (NLevenshtein::Distance(name, item) < NYql::DefaultMistypeDistance) {
- return item;
- }
- }
- return {};
- }
-
+ return item;
+ }
+ }
+ return {};
+ }
+
bool Parseui32(TNodePtr from, ui32& to);
- TNodePtr GroundWithExpr(const TNodePtr& ground, const TNodePtr& expr);
+ TNodePtr GroundWithExpr(const TNodePtr& ground, const TNodePtr& expr);
TSourcePtr TryMakeSourceFromExpression(TContext& ctx, TNodePtr node, const TString& view = {});
void MakeTableFromExpression(TContext& ctx, TNodePtr node, TDeferredAtom& table);
TDeferredAtom MakeAtomFromExpression(TContext& ctx, TNodePtr node);
diff --git a/ydb/library/yql/sql/v0/query.cpp b/ydb/library/yql/sql/v0/query.cpp
index e7d9e1288b..7752b28b01 100644
--- a/ydb/library/yql/sql/v0/query.cpp
+++ b/ydb/library/yql/sql/v0/query.cpp
@@ -315,7 +315,7 @@ TNodePtr BuildTableKeys(TPosition pos, const TString& cluster, const TString& fu
return new TPrepTableKeys(pos, cluster, func, args);
}
-class TInputOptions final: public TAstListNode {
+class TInputOptions final: public TAstListNode {
public:
TInputOptions(TPosition pos, const TVector<TString>& hints)
: TAstListNode(pos)
@@ -323,7 +323,7 @@ public:
{
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
Y_UNUSED(src);
TSet<TString> used;
for (auto& hint: Hints) {
@@ -344,10 +344,10 @@ public:
return true;
}
- TPtr DoClone() const final {
- return {};
- }
-
+ TPtr DoClone() const final {
+ return {};
+ }
+
private:
TVector<TString> Hints;
};
@@ -360,15 +360,15 @@ TNodePtr BuildInputOptions(TPosition pos, const TVector<TString>& hints) {
return new TInputOptions(pos, hints);
}
-class TInputTablesNode final: public TAstListNode {
+class TInputTablesNode final: public TAstListNode {
public:
TInputTablesNode(TPosition pos, const TTableList& tables, bool inSubquery)
: TAstListNode(pos)
, Tables(tables)
, InSubquery(inSubquery)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
THashSet<TString> tables;
for (auto& tr: Tables) {
if (!tables.insert(tr.RefName).second) {
@@ -380,13 +380,13 @@ public:
}
auto tableKeys = tr.Keys->GetTableKeys();
auto keys = tableKeys->BuildKeys(ctx, ITableKeys::EBuildKeysMode::INPUT);
- ctx.PushBlockShortcuts();
- if (!keys || !keys->Init(ctx, src)) {
+ ctx.PushBlockShortcuts();
+ if (!keys || !keys->Init(ctx, src)) {
return false;
}
- keys = ctx.GroundBlockShortcutsForExpr(keys);
+ keys = ctx.GroundBlockShortcutsForExpr(keys);
auto service = tr.ServiceName(ctx);
- auto fields = Y("Void");
+ auto fields = Y("Void");
auto source = Y("DataSource", BuildQuotedAtom(Pos, service), BuildQuotedAtom(Pos, tr.Cluster));
auto options = tr.Options ? Q(tr.Options) : Q(Y());
Add(Y("let", "x", keys->Y(TString(ReadName), "world", source, keys, fields, options)));
@@ -405,10 +405,10 @@ public:
return TAstListNode::DoInit(ctx, src);
}
- TPtr DoClone() const final {
- return {};
- }
-
+ TPtr DoClone() const final {
+ return {};
+ }
+
private:
TTableList Tables;
const bool InSubquery;
@@ -418,7 +418,7 @@ TNodePtr BuildInputTables(TPosition pos, const TTableList& tables, bool inSubque
return new TInputTablesNode(pos, tables, inSubquery);
}
-class TCreateTableNode final: public TAstListNode {
+class TCreateTableNode final: public TAstListNode {
public:
TCreateTableNode(TPosition pos, const TTableRef& tr, const TVector<TColumnSchema>& columns,
const TVector<TIdentifier>& pkColumns, const TVector<TIdentifier>& partitionByColumns,
@@ -429,18 +429,18 @@ public:
, PkColumns(pkColumns)
, PartitionByColumns(partitionByColumns)
, OrderByColumns(orderByColumns)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
if (!Table.Check(ctx)) {
return false;
}
auto keys = Table.Keys->GetTableKeys()->BuildKeys(ctx, ITableKeys::EBuildKeysMode::CREATE);
- ctx.PushBlockShortcuts();
- if (!keys || !keys->Init(ctx, src)) {
+ ctx.PushBlockShortcuts();
+ if (!keys || !keys->Init(ctx, src)) {
return false;
}
- keys = ctx.GroundBlockShortcutsForExpr(keys);
+ keys = ctx.GroundBlockShortcutsForExpr(keys);
if (!PkColumns.empty() || !PartitionByColumns.empty() || !OrderByColumns.empty()) {
THashSet<TString> columnsSet;
@@ -557,9 +557,9 @@ public:
return TAstListNode::DoInit(ctx, src);
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
private:
TTableRef Table;
TVector<TColumnSchema> Columns;
@@ -663,7 +663,7 @@ TNodePtr BuildAlterTable(TPosition pos, const TTableRef& tr, const TVector<TColu
return new TAlterTableNode(pos, tr, columns, intent);
}
-class TDropTableNode final: public TAstListNode {
+class TDropTableNode final: public TAstListNode {
public:
TDropTableNode(TPosition pos, const TTableRef& tr)
: TAstListNode(pos)
@@ -672,18 +672,18 @@ public:
FakeSource = BuildFakeSource(pos);
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
Y_UNUSED(src);
if (!Table.Check(ctx)) {
return false;
}
auto keys = Table.Keys->GetTableKeys()->BuildKeys(ctx, ITableKeys::EBuildKeysMode::DROP);
- ctx.PushBlockShortcuts();
+ ctx.PushBlockShortcuts();
if (!keys || !keys->Init(ctx, FakeSource.Get())) {
return false;
}
- keys = ctx.GroundBlockShortcutsForExpr(keys);
-
+ keys = ctx.GroundBlockShortcutsForExpr(keys);
+
Add("block", Q(Y(
Y("let", "sink", Y("DataSink", BuildQuotedAtom(Pos, Table.ServiceName(ctx)), BuildQuotedAtom(Pos, Table.Cluster))),
Y("let", "world", Y(TString(WriteName), "world", "sink", keys, Y("Void"), Q(Y(Q(Y(Q("mode"), Q("drop"))))))),
@@ -694,9 +694,9 @@ public:
return TAstListNode::DoInit(ctx, FakeSource.Get());
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
private:
TTableRef Table;
TSourcePtr FakeSource;
@@ -707,11 +707,11 @@ TNodePtr BuildDropTable(TPosition pos, const TTableRef& tr) {
}
static const TMap<EWriteColumnMode, TString> columnModeToStrMapMR {
- {EWriteColumnMode::Default, ""},
+ {EWriteColumnMode::Default, ""},
{EWriteColumnMode::Insert, "append"},
{EWriteColumnMode::Renew, "renew"}
-};
-
+};
+
static const TMap<EWriteColumnMode, TString> columnModeToStrMapStat {
{EWriteColumnMode::Upsert, "upsert"}
};
@@ -730,27 +730,27 @@ static const TMap<EWriteColumnMode, TString> columnModeToStrMapKikimr {
{EWriteColumnMode::DeleteOn, "delete_on"},
};
-class TWriteTableNode final: public TAstListNode {
+class TWriteTableNode final: public TAstListNode {
public:
TWriteTableNode(TPosition pos, const TString& label, const TTableRef& table, EWriteColumnMode mode,
TNodePtr options)
: TAstListNode(pos)
, Label(label)
, Table(table)
- , Mode(mode)
+ , Mode(mode)
, Options(options)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
if (!Table.Check(ctx)) {
return false;
}
auto keys = Table.Keys->GetTableKeys()->BuildKeys(ctx, ITableKeys::EBuildKeysMode::WRITE);
- ctx.PushBlockShortcuts();
- if (!keys || !keys->Init(ctx, src)) {
+ ctx.PushBlockShortcuts();
+ if (!keys || !keys->Init(ctx, src)) {
return false;
}
- keys = ctx.GroundBlockShortcutsForExpr(keys);
+ keys = ctx.GroundBlockShortcutsForExpr(keys);
const auto serviceName = to_lower(Table.ServiceName(ctx));
auto getModesMap = [] (const TString& serviceName) -> const TMap<EWriteColumnMode, TString>& {
@@ -788,13 +788,13 @@ public:
return TAstListNode::DoInit(ctx, src);
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
private:
TString Label;
TTableRef Table;
- EWriteColumnMode Mode;
+ EWriteColumnMode Mode;
TNodePtr Options;
};
@@ -824,10 +824,10 @@ protected:
for (auto& cluster: *clusters) {
TString normalizedClusterName;
auto service = ctx.GetClusterProvider(cluster, normalizedClusterName);
- if (!service) {
- ctx.Error(ctx.Pos()) << "Unknown cluster: " << cluster;
- return false;
- }
+ if (!service) {
+ ctx.Error(ctx.Pos()) << "Unknown cluster: " << cluster;
+ return false;
+ }
auto sinkName = normalizedClusterName + "_sink";
@@ -847,9 +847,9 @@ protected:
return TAstListNode::DoInit(ctx, src);
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
private:
TSet<TString> Clusters;
};
@@ -889,16 +889,16 @@ TNodePtr BuildRollbackClusters(TPosition pos, const TSet<TString>& clusters) {
return new TRollbackClustersNode(pos, clusters);
}
-class TWriteResultNode final: public TAstListNode {
+class TWriteResultNode final: public TAstListNode {
public:
TWriteResultNode(TPosition pos, const TString& label, TNodePtr settings, const TSet<TString>& clusters)
: TAstListNode(pos)
, Label(label)
, Settings(settings)
, CommitClusters(BuildCommitClusters(Pos, clusters))
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
auto block(Y(
Y("let", "result_sink", Y("DataSink", Q(TString(ResultProviderName)))),
Y("let", "world", Y(TString(WriteName), "world", "result_sink", Y("Key"), Label, Q(Settings)))
@@ -912,9 +912,9 @@ public:
return TAstListNode::DoInit(ctx, src);
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
private:
TString Label;
TNodePtr Settings;
@@ -931,9 +931,9 @@ public:
: TAstListNode(pos)
, Blocks(blocks)
, TopLevel(topLevel)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
bool hasError = false;
if (TopLevel) {
for (auto& var: ctx.Variables) {
@@ -942,8 +942,8 @@ public:
continue;
}
Add(Y("declare", var.first, var.second));
- }
-
+ }
+
for (const auto& lib : ctx.Libraries) {
Add(Y("library",
new TAstAtomNodeImpl(Pos, lib, TNodeFlags::ArbitraryContent)));
@@ -959,7 +959,7 @@ public:
for (const auto& moduleAlias : ctx.ImportModuleAliases) {
Add(Y("import", moduleAlias.second, BuildQuotedAtom(Pos, moduleAlias.first)));
}
-
+
for (const auto& x : ctx.SimpleUdfs) {
Add(Y("let", x.second, Y("Udf", BuildQuotedAtom(Pos, x.first))));
}
@@ -978,7 +978,7 @@ public:
if (node->IsConstant() || ctx.Exports.contains(nodes.first)) {
Add(Y("let", BuildAtom(node->GetPos(), nodes.first), node));
}
- }
+ }
}
if (ctx.Settings.Mode != NSQLTranslation::ESqlMode::LIBRARY) {
@@ -1004,25 +1004,25 @@ public:
}
for (auto& block: Blocks) {
- if (block->SubqueryAlias()) {
- continue;
- }
+ if (block->SubqueryAlias()) {
+ continue;
+ }
if (!block->Init(ctx, nullptr)) {
hasError = true;
continue;
}
- }
-
- for (auto& block: Blocks) {
- const auto subqueryAliasPtr = block->SubqueryAlias();
- if (subqueryAliasPtr) {
- if (block->UsedSubquery()) {
- const auto& ref = block->GetLabel();
- YQL_ENSURE(!ref.empty());
- Add(block);
- Add(Y("let", "world", Y("Nth", *subqueryAliasPtr, Q("0"))));
- Add(Y("let", ref, Y("Nth", *subqueryAliasPtr, Q("1"))));
- }
+ }
+
+ for (auto& block: Blocks) {
+ const auto subqueryAliasPtr = block->SubqueryAlias();
+ if (subqueryAliasPtr) {
+ if (block->UsedSubquery()) {
+ const auto& ref = block->GetLabel();
+ YQL_ENSURE(!ref.empty());
+ Add(block);
+ Add(Y("let", "world", Y("Nth", *subqueryAliasPtr, Q("0"))));
+ Add(Y("let", ref, Y("Nth", *subqueryAliasPtr, Q("1"))));
+ }
} else {
const auto& ref = block->GetLabel();
Add(Y("let", ref ? ref : "world", block));
@@ -1037,13 +1037,13 @@ public:
Add(Y("let", aliasPair.first, aliasPair.second));
}
Nodes.insert(Nodes.end(), preparedNodes.begin(), preparedNodes.end());
- }
+ }
for (const auto& symbol: ctx.Exports) {
Add(Y("export", symbol));
}
- }
-
+ }
+
if (!TopLevel || ctx.Settings.Mode != NSQLTranslation::ESqlMode::LIBRARY) {
Add(Y("return", "world"));
}
@@ -1079,7 +1079,7 @@ public:
Y_UNUSED(src);
TString serviceName;
TString cluster;
- if (std::find(Providers.cbegin(), Providers.cend(), Prefix) != Providers.cend()) {
+ if (std::find(Providers.cbegin(), Providers.cend(), Prefix) != Providers.cend()) {
cluster = "$all";
serviceName = Prefix;
} else {
@@ -1132,9 +1132,9 @@ public:
return Node->Translate(ctx);
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
private:
TString Prefix;
@@ -1149,63 +1149,63 @@ TNodePtr BuildPragma(TPosition pos, const TString& prefix, const TString& name,
return new TPragmaNode(pos, prefix, name, values, valueDefault);
}
-class TSqlLambda final: public TAstListNode {
-public:
+class TSqlLambda final: public TAstListNode {
+public:
TSqlLambda(TPosition pos, TVector<TString>&& args, TVector<TNodePtr>&& exprSeq)
- : TAstListNode(pos)
- , Args(args)
- , ExprSeq(exprSeq)
+ : TAstListNode(pos)
+ , Args(args)
+ , ExprSeq(exprSeq)
{
FakeSource = BuildFakeSource(pos);
}
-
- bool DoInit(TContext& ctx, ISource* src) override {
+
+ bool DoInit(TContext& ctx, ISource* src) override {
Y_UNUSED(src);
- for (auto& exprPtr: ExprSeq) {
- ctx.PushBlockShortcuts();
+ for (auto& exprPtr: ExprSeq) {
+ ctx.PushBlockShortcuts();
if (!exprPtr->Init(ctx, FakeSource.Get())) {
- return {};
- }
- const auto label = exprPtr->GetLabel();
- exprPtr = ctx.GroundBlockShortcutsForExpr(exprPtr);
- exprPtr->SetLabel(label);
- }
- YQL_ENSURE(!ExprSeq.empty());
- auto body = Y();
- auto end = ExprSeq.end() - 1;
- for (auto iter = ExprSeq.begin(); iter != end; ++iter) {
- auto exprPtr = *iter;
- const auto& label = exprPtr->GetLabel();
- YQL_ENSURE(label);
- body = L(body, Y("let", label, exprPtr));
- }
- body = Y("block", Q(L(body, Y("return", *end))));
- auto args = Y();
- for (const auto& arg: Args) {
- args = L(args, BuildAtom(GetPos(), arg, NYql::TNodeFlags::Default));
- }
- Add("lambda", Q(args), body);
- return TAstListNode::DoInit(ctx, src);
- }
-
- TPtr DoClone() const final {
- return {};
- }
-
+ return {};
+ }
+ const auto label = exprPtr->GetLabel();
+ exprPtr = ctx.GroundBlockShortcutsForExpr(exprPtr);
+ exprPtr->SetLabel(label);
+ }
+ YQL_ENSURE(!ExprSeq.empty());
+ auto body = Y();
+ auto end = ExprSeq.end() - 1;
+ for (auto iter = ExprSeq.begin(); iter != end; ++iter) {
+ auto exprPtr = *iter;
+ const auto& label = exprPtr->GetLabel();
+ YQL_ENSURE(label);
+ body = L(body, Y("let", label, exprPtr));
+ }
+ body = Y("block", Q(L(body, Y("return", *end))));
+ auto args = Y();
+ for (const auto& arg: Args) {
+ args = L(args, BuildAtom(GetPos(), arg, NYql::TNodeFlags::Default));
+ }
+ Add("lambda", Q(args), body);
+ return TAstListNode::DoInit(ctx, src);
+ }
+
+ TPtr DoClone() const final {
+ return {};
+ }
+
void DoUpdateState() const override {
State.Set(ENodeState::Const);
}
-private:
+private:
TVector<TString> Args;
TVector<TNodePtr> ExprSeq;
TSourcePtr FakeSource;
-};
-
+};
+
TNodePtr BuildSqlLambda(TPosition pos, TVector<TString>&& args, TVector<TNodePtr>&& exprSeq) {
- return new TSqlLambda(pos, std::move(args), std::move(exprSeq));
-}
-
+ return new TSqlLambda(pos, std::move(args), std::move(exprSeq));
+}
+
class TEvaluateIf final : public TAstListNode {
public:
TEvaluateIf(TPosition pos, TNodePtr predicate, TNodePtr thenNode, TNodePtr elseNode)
diff --git a/ydb/library/yql/sql/v0/select.cpp b/ydb/library/yql/sql/v0/select.cpp
index d000adac72..ef47023be1 100644
--- a/ydb/library/yql/sql/v0/select.cpp
+++ b/ydb/library/yql/sql/v0/select.cpp
@@ -1,6 +1,6 @@
-#include "sql.h"
+#include "sql.h"
#include "node.h"
-
+
#include "context.h"
#include <ydb/library/yql/utils/yql_panic.h>
@@ -11,165 +11,165 @@ using namespace NYql;
namespace NSQLTranslationV0 {
-class TSubqueryNode: public INode {
-public:
+class TSubqueryNode: public INode {
+public:
TSubqueryNode(TSourcePtr&& source, const TString& alias, bool inSubquery, int ensureTupleSize)
- : INode(source->GetPos())
- , Source(std::move(source))
- , Alias(alias)
+ : INode(source->GetPos())
+ , Source(std::move(source))
+ , Alias(alias)
, InSubquery(inSubquery)
, EnsureTupleSize(ensureTupleSize)
- {
- YQL_ENSURE(!Alias.empty());
- }
-
- ISource* GetSource() override {
- return Source.Get();
- }
-
- bool DoInit(TContext& ctx, ISource* src) override {
- YQL_ENSURE(!src, "Source not expected for subquery node");
+ {
+ YQL_ENSURE(!Alias.empty());
+ }
+
+ ISource* GetSource() override {
+ return Source.Get();
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ YQL_ENSURE(!src, "Source not expected for subquery node");
Source->UseAsInner();
- if (!Source->Init(ctx, nullptr)) {
- return false;
- }
-
+ if (!Source->Init(ctx, nullptr)) {
+ return false;
+ }
+
TTableList tableList;
Source->GetInputTables(tableList);
-
+
auto tables = BuildInputTables(Pos, tableList, InSubquery);
- if (!tables->Init(ctx, Source.Get())) {
- return false;
- }
-
- auto source = Source->Build(ctx);
- if (!source) {
- return false;
- }
+ if (!tables->Init(ctx, Source.Get())) {
+ return false;
+ }
+
+ auto source = Source->Build(ctx);
+ if (!source) {
+ return false;
+ }
if (EnsureTupleSize != -1) {
source = Y("EnsureTupleSize", source, Q(ToString(EnsureTupleSize)));
}
-
- Node = Y("let", Alias, Y("block", Q(L(tables, Y("return", Q(Y("world", source)))))));
- IsUsed = true;
- return true;
- }
-
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, true);
- }
-
- bool UsedSubquery() const override {
- return IsUsed;
- }
-
- TAstNode* Translate(TContext& ctx) const override {
- Y_VERIFY_DEBUG(Node);
- return Node->Translate(ctx);
- }
-
- const TString* SubqueryAlias() const override {
- return &Alias;
- }
-
- TPtr DoClone() const final {
- return {};
- }
-
-protected:
- TSourcePtr Source;
- TNodePtr Node;
- const TString Alias;
+
+ Node = Y("let", Alias, Y("block", Q(L(tables, Y("return", Q(Y("world", source)))))));
+ IsUsed = true;
+ return true;
+ }
+
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, true);
+ }
+
+ bool UsedSubquery() const override {
+ return IsUsed;
+ }
+
+ TAstNode* Translate(TContext& ctx) const override {
+ Y_VERIFY_DEBUG(Node);
+ return Node->Translate(ctx);
+ }
+
+ const TString* SubqueryAlias() const override {
+ return &Alias;
+ }
+
+ TPtr DoClone() const final {
+ return {};
+ }
+
+protected:
+ TSourcePtr Source;
+ TNodePtr Node;
+ const TString Alias;
const bool InSubquery;
const int EnsureTupleSize;
- bool IsUsed = false;
-};
-
+ bool IsUsed = false;
+};
+
TNodePtr BuildSubquery(TSourcePtr source, const TString& alias, bool inSubquery, int ensureTupleSize) {
return new TSubqueryNode(std::move(source), alias, inSubquery, ensureTupleSize);
-}
-
+}
+
class TSourceNode: public INode {
public:
- TSourceNode(TPosition pos, TSourcePtr&& source, bool checkExist)
+ TSourceNode(TPosition pos, TSourcePtr&& source, bool checkExist)
: INode(pos)
- , Source(std::move(source))
- , CheckExist(checkExist)
- {}
+ , Source(std::move(source))
+ , CheckExist(checkExist)
+ {}
- ISource* GetSource() override {
- return Source.Get();
+ ISource* GetSource() override {
+ return Source.Get();
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
if (AsInner) {
Source->UseAsInner();
}
- if (!Source->Init(ctx, src)) {
+ if (!Source->Init(ctx, src)) {
return false;
}
- Node = Source->Build(ctx);
- if (!Node) {
- return false;
- }
- if (src) {
- if (IsSubquery()) {
- /// should be not used?
- auto columnsPtr = Source->GetColumns();
- if (!columnsPtr || columnsPtr->All || columnsPtr->QualifiedAll || columnsPtr->List.size() != 1) {
- ctx.Error(Pos) << "Source used in expression should contain one concrete column";
- return false;
- }
+ Node = Source->Build(ctx);
+ if (!Node) {
+ return false;
+ }
+ if (src) {
+ if (IsSubquery()) {
+ /// should be not used?
+ auto columnsPtr = Source->GetColumns();
+ if (!columnsPtr || columnsPtr->All || columnsPtr->QualifiedAll || columnsPtr->List.size() != 1) {
+ ctx.Error(Pos) << "Source used in expression should contain one concrete column";
+ return false;
+ }
Node = Y("Member", Y("SqlAccess", Q("dict"), Y("Take", Node, Y("Uint64", Q("1"))), Y("Uint64", Q("0"))), Q(columnsPtr->List.front()));
- }
- src->AddDependentSource(Source.Get());
- }
- return true;
- }
-
- bool IsSubquery() const {
- return !AsInner && Source->IsSelect() && !CheckExist;
- }
-
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, IsSubquery());
- }
-
- TAstNode* Translate(TContext& ctx) const override {
+ }
+ src->AddDependentSource(Source.Get());
+ }
+ return true;
+ }
+
+ bool IsSubquery() const {
+ return !AsInner && Source->IsSelect() && !CheckExist;
+ }
+
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, IsSubquery());
+ }
+
+ TAstNode* Translate(TContext& ctx) const override {
Y_VERIFY_DEBUG(Node);
return Node->Translate(ctx);
}
- TPtr DoClone() const final {
- return new TSourceNode(Pos, Source->CloneSource(), CheckExist);
- }
-protected:
- TSourcePtr Source;
+ TPtr DoClone() const final {
+ return new TSourceNode(Pos, Source->CloneSource(), CheckExist);
+ }
+protected:
+ TSourcePtr Source;
TNodePtr Node;
- bool CheckExist;
+ bool CheckExist;
};
-TNodePtr BuildSourceNode(TPosition pos, TSourcePtr source, bool checkExist) {
- return new TSourceNode(pos, std::move(source), checkExist);
+TNodePtr BuildSourceNode(TPosition pos, TSourcePtr source, bool checkExist) {
+ return new TSourceNode(pos, std::move(source), checkExist);
}
class TFakeSource: public ISource {
public:
TFakeSource(TPosition pos)
: ISource(pos)
- {}
+ {}
bool IsFake() const override {
return true;
}
-
- bool AddFilter(TContext& ctx, TNodePtr filter) override {
+
+ bool AddFilter(TContext& ctx, TNodePtr filter) override {
Y_UNUSED(filter);
ctx.Error(Pos) << "Source does not allow filtering";
return false;
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
Y_UNUSED(ctx);
return Y("AsList", Y("Uint32", Q("0")));
}
@@ -180,7 +180,7 @@ public:
return false;
}
- bool AddAggregation(TContext& ctx, TAggregationPtr aggr) override {
+ bool AddAggregation(TContext& ctx, TAggregationPtr aggr) override {
Y_UNUSED(aggr);
ctx.Error(Pos) << "Source does not allow aggregation";
return false;
@@ -194,7 +194,7 @@ public:
TNodePtr BuildFilter(TContext& ctx, const TString& label, const TNodePtr& groundNode) override {
Y_UNUSED(ctx);
Y_UNUSED(label);
- Y_UNUSED(groundNode);
+ Y_UNUSED(groundNode);
return nullptr;
}
@@ -202,10 +202,10 @@ public:
Y_UNUSED(label);
return nullptr;
}
-
- TPtr DoClone() const final {
- return new TFakeSource(Pos);
- }
+
+ TPtr DoClone() const final {
+ return new TFakeSource(Pos);
+ }
};
TSourcePtr BuildFakeSource(TPosition pos) {
@@ -282,14 +282,14 @@ protected:
IProxySource(TPosition pos, ISource* src)
: ISource(pos)
, Source(src)
- {}
+ {}
- void AllColumns() override {
+ void AllColumns() override {
Y_VERIFY_DEBUG(Source);
return Source->AllColumns();
}
- const TColumns* GetColumns() const override {
+ const TColumns* GetColumns() const override {
Y_VERIFY_DEBUG(Source);
return Source->GetColumns();
}
@@ -299,19 +299,19 @@ protected:
ISource::GetInputTables(tableList);
}
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
Y_VERIFY_DEBUG(Source);
const TString label(Source->GetLabel());
Source->SetLabel(Label);
- const auto ret = Source->AddColumn(ctx, column);
+ const auto ret = Source->AddColumn(ctx, column);
Source->SetLabel(label);
return ret;
}
- bool ShouldUseSourceAsColumn(const TString& source) override {
- return Source->ShouldUseSourceAsColumn(source);
- }
-
+ bool ShouldUseSourceAsColumn(const TString& source) override {
+ return Source->ShouldUseSourceAsColumn(source);
+ }
+
bool IsStream() const override {
Y_VERIFY_DEBUG(Source);
return Source->IsStream();
@@ -342,48 +342,48 @@ protected:
{
}
- void AllColumns() override {
+ void AllColumns() override {
Columns.SetAll();
}
- const TColumns* GetColumns() const override {
+ const TColumns* GetColumns() const override {
return &Columns;
}
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
auto& label = *column.GetSourceName();
if (!label.empty() && label != GetLabel()) {
- if (column.IsReliable()) {
- ctx.Error(column.GetPos()) << "Unknown correlation name: " << label;
- }
- return {};
+ if (column.IsReliable()) {
+ ctx.Error(column.GetPos()) << "Unknown correlation name: " << label;
+ }
+ return {};
}
if (column.IsAsterisk()) {
return true;
}
const auto* name = column.GetColumnName();
if (name && !Columns.IsColumnPossible(ctx, *name) && !IsAlias(EExprSeat::GroupBy, *name)) {
- if (column.IsReliable()) {
- TStringBuilder sb;
+ if (column.IsReliable()) {
+ TStringBuilder sb;
sb << "Column " << *name << " is not in source column set";
if (const auto mistype = FindColumnMistype(*name)) {
- sb << ". Did you mean " << mistype.GetRef() << "?";
- }
- ctx.Error(column.GetPos()) << sb;
- }
- return {};
+ sb << ". Did you mean " << mistype.GetRef() << "?";
+ }
+ ctx.Error(column.GetPos()) << sb;
+ }
+ return {};
}
return true;
}
TMaybe<TString> FindColumnMistype(const TString& name) const override {
- auto result = FindMistypeIn(Columns.Real, name);
- if (!result) {
- auto result = FindMistypeIn(Columns.Artificial, name);
- }
- return result ? result : ISource::FindColumnMistype(name);
- }
-
+ auto result = FindMistypeIn(Columns.Real, name);
+ if (!result) {
+ auto result = FindMistypeIn(Columns.Artificial, name);
+ }
+ return result ? result : ISource::FindColumnMistype(name);
+ }
+
protected:
TColumns Columns;
};
@@ -490,79 +490,79 @@ TSourcePtr BuildMuxSource(TPosition pos, TVector<TSourcePtr>&& sources) {
return new TMuxSource(pos, std::move(sources));
}
-class TSubqueryRefNode: public IRealSource {
-public:
+class TSubqueryRefNode: public IRealSource {
+public:
TSubqueryRefNode(const TNodePtr& subquery, const TString& alias, int tupleIndex)
- : IRealSource(subquery->GetPos())
- , Subquery(subquery)
- , Alias(alias)
+ : IRealSource(subquery->GetPos())
+ , Subquery(subquery)
+ , Alias(alias)
, TupleIndex(tupleIndex)
- {
- YQL_ENSURE(subquery->GetSource());
- }
-
- ISource* GetSource() override {
- return this;
- }
-
- bool DoInit(TContext& ctx, ISource* src) override {
- // independent subquery should not connect source
+ {
+ YQL_ENSURE(subquery->GetSource());
+ }
+
+ ISource* GetSource() override {
+ return this;
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ // independent subquery should not connect source
Subquery->UseAsInner();
- if (!Subquery->Init(ctx, nullptr)) {
- return false;
- }
- Columns = *Subquery->GetSource()->GetColumns();
- Node = BuildAtom(Pos, Alias, TNodeFlags::Default);
+ if (!Subquery->Init(ctx, nullptr)) {
+ return false;
+ }
+ Columns = *Subquery->GetSource()->GetColumns();
+ Node = BuildAtom(Pos, Alias, TNodeFlags::Default);
if (TupleIndex != -1) {
Node = Y("Nth", Node, Q(ToString(TupleIndex)));
}
- if (!Node->Init(ctx, src)) {
- return false;
- }
- if (src && Subquery->GetSource()->IsSelect()) {
- auto columnsPtr = &Columns;
- if (!columnsPtr || columnsPtr->All || columnsPtr->QualifiedAll || columnsPtr->List.size() != 1) {
- ctx.Error(Pos) << "Source used in expression should contain one concrete column";
- return false;
- }
- Node = Y("Member", Y("SqlAccess", Q("dict"), Y("Take", Node, Y("Uint64", Q("1"))), Y("Uint64", Q("0"))), Q(columnsPtr->List.front()));
- }
- return true;
- }
-
- TNodePtr Build(TContext& ctx) override {
- Y_UNUSED(ctx);
- return Node;
- }
-
+ if (!Node->Init(ctx, src)) {
+ return false;
+ }
+ if (src && Subquery->GetSource()->IsSelect()) {
+ auto columnsPtr = &Columns;
+ if (!columnsPtr || columnsPtr->All || columnsPtr->QualifiedAll || columnsPtr->List.size() != 1) {
+ ctx.Error(Pos) << "Source used in expression should contain one concrete column";
+ return false;
+ }
+ Node = Y("Member", Y("SqlAccess", Q("dict"), Y("Take", Node, Y("Uint64", Q("1"))), Y("Uint64", Q("0"))), Q(columnsPtr->List.front()));
+ }
+ return true;
+ }
+
+ TNodePtr Build(TContext& ctx) override {
+ Y_UNUSED(ctx);
+ return Node;
+ }
+
bool IsStream() const override {
return Subquery->GetSource()->IsStream();
}
-
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, true);
- }
-
- TAstNode* Translate(TContext& ctx) const override {
- Y_VERIFY_DEBUG(Node);
- return Node->Translate(ctx);
- }
-
- TPtr DoClone() const final {
+
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, true);
+ }
+
+ TAstNode* Translate(TContext& ctx) const override {
+ Y_VERIFY_DEBUG(Node);
+ return Node->Translate(ctx);
+ }
+
+ TPtr DoClone() const final {
return new TSubqueryRefNode(Subquery, Alias, TupleIndex);
- }
-
-protected:
- TNodePtr Subquery;
- const TString Alias;
+ }
+
+protected:
+ TNodePtr Subquery;
+ const TString Alias;
const int TupleIndex;
- TNodePtr Node;
-};
-
+ TNodePtr Node;
+};
+
TNodePtr BuildSubqueryRef(TNodePtr subquery, const TString& alias, int tupleIndex) {
return new TSubqueryRefNode(std::move(subquery), alias, tupleIndex);
-}
-
+}
+
class TTableSource: public IRealSource {
public:
TTableSource(TPosition pos, const TTableRef& table, bool stream, const TString& label)
@@ -578,16 +578,16 @@ public:
ISource::GetInputTables(tableList);
}
- bool ShouldUseSourceAsColumn(const TString& source) override {
- return source && source != GetLabel();
- }
-
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ bool ShouldUseSourceAsColumn(const TString& source) override {
+ return source && source != GetLabel();
+ }
+
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
Columns.Add(column.GetColumnName(), column.GetCountHint(), column.IsArtificial(), column.IsReliable());
- if (!IRealSource::AddColumn(ctx, column)) {
- return {};
- }
- return false;
+ if (!IRealSource::AddColumn(ctx, column)) {
+ return {};
+ }
+ return false;
}
bool SetSamplingOptions(
@@ -630,7 +630,7 @@ public:
return true;
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
if (!Table.Keys->Init(ctx, nullptr)) {
return nullptr;
}
@@ -641,16 +641,16 @@ public:
return Stream;
}
- TPtr DoClone() const final {
- return new TTableSource(Pos, Table, Stream, GetLabel());
- }
+ TPtr DoClone() const final {
+ return new TTableSource(Pos, Table, Stream, GetLabel());
+ }
bool IsTableSource() const override {
return true;
}
protected:
TTableRef Table;
- const bool Stream;
+ const bool Stream;
};
TSourcePtr BuildTableSource(TPosition pos, const TTableRef& table, bool stream, const TString& label) {
@@ -666,20 +666,20 @@ public:
SetLabel(label);
}
- bool ShouldUseSourceAsColumn(const TString& source) override {
- return source && source != GetLabel();
- }
-
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ bool ShouldUseSourceAsColumn(const TString& source) override {
+ return source && source != GetLabel();
+ }
+
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
if (const TString* columnName = column.GetColumnName()) {
if (columnName && IsExprAlias(*columnName)) {
- return true;
- }
- }
+ return true;
+ }
+ }
return IProxySource::AddColumn(ctx, column);
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
auto source = Node->GetSource();
if (!source) {
NewSource = TryMakeSourceFromExpression(ctx, Node);
@@ -706,16 +706,16 @@ public:
return ISource::DoInit(ctx, source);
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
Y_UNUSED(ctx);
return NewSource ? NewSource->Build(ctx) : Node;
}
- TPtr DoClone() const final {
- return new TInnerSource(Pos, SafeClone(Node), GetLabel());
- }
-protected:
- TNodePtr Node;
+ TPtr DoClone() const final {
+ return new TInnerSource(Pos, SafeClone(Node), GetLabel());
+ }
+protected:
+ TNodePtr Node;
TSourcePtr NewSource;
};
@@ -723,9 +723,9 @@ TSourcePtr BuildInnerSource(TPosition pos, TNodePtr node, const TString& label)
return new TInnerSource(pos, node, label);
}
-/// \todo move to reduce.cpp? or mapreduce.cpp?
-class TReduceSource: public IRealSource {
-public:
+/// \todo move to reduce.cpp? or mapreduce.cpp?
+class TReduceSource: public IRealSource {
+public:
TReduceSource(TPosition pos,
ReduceMode mode,
TSourcePtr source,
@@ -735,175 +735,175 @@ public:
TNodePtr udf,
TNodePtr having,
const TWriteSettings& settings)
- : IRealSource(pos)
- , Mode(mode)
- , Source(std::move(source))
- , OrderBy(std::move(orderBy))
- , Keys(std::move(keys))
- , Args(std::move(args))
- , Udf(udf)
- , Having(having)
+ : IRealSource(pos)
+ , Mode(mode)
+ , Source(std::move(source))
+ , OrderBy(std::move(orderBy))
+ , Keys(std::move(keys))
+ , Args(std::move(args))
+ , Udf(udf)
+ , Having(having)
, Settings(settings)
- {
- YQL_ENSURE(!Keys.empty());
- YQL_ENSURE(Source);
- }
-
+ {
+ YQL_ENSURE(!Keys.empty());
+ YQL_ENSURE(Source);
+ }
+
void GetInputTables(TTableList& tableList) const override {
Source->GetInputTables(tableList);
ISource::GetInputTables(tableList);
- }
-
- bool DoInit(TContext& ctx, ISource* src) final {
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) final {
if (AsInner) {
Source->UseAsInner();
}
- ctx.PushBlockShortcuts();
- YQL_ENSURE(!src);
- if (!Source->Init(ctx, src)) {
- return false;
- }
- if (!Source->InitFilters(ctx)) {
- return false;
- }
- FiltersGround = ctx.GroundBlockShortcuts(Pos);
- src = Source.Get();
- for (auto& key: Keys) {
- if (!key->Init(ctx, src)) {
- return false;
- }
- auto keyNamePtr = key->GetColumnName();
- YQL_ENSURE(keyNamePtr);
- if (!src->AddGroupKey(ctx, *keyNamePtr)) {
- return false;
- }
- }
- ctx.PushBlockShortcuts();
- if (Having && !Having->Init(ctx, nullptr)) {
- return false;
- }
- HavingGround = ctx.GroundBlockShortcuts(Pos);
-
- /// SIN: verify reduce one argument
- if (Args.size() != 1) {
- ctx.Error(Pos) << "REDUCE requires exactly one UDF argument";
- return false;
- }
- ctx.PushBlockShortcuts();
- if (!Args[0]->Init(ctx, src)) {
- return false;
- }
- ExprGround = ctx.GroundBlockShortcuts(Pos);
-
- ctx.PushBlockShortcuts();
- for (auto orderSpec: OrderBy) {
- if (!orderSpec->OrderExpr->Init(ctx, src)) {
- return false;
- }
- }
- OrderByGround = ctx.GroundBlockShortcuts(Pos);
-
- if (!Udf->Init(ctx, src)) {
- return false;
- }
- if (Udf->GetLabel().empty()) {
- Columns.SetAll();
- } else {
+ ctx.PushBlockShortcuts();
+ YQL_ENSURE(!src);
+ if (!Source->Init(ctx, src)) {
+ return false;
+ }
+ if (!Source->InitFilters(ctx)) {
+ return false;
+ }
+ FiltersGround = ctx.GroundBlockShortcuts(Pos);
+ src = Source.Get();
+ for (auto& key: Keys) {
+ if (!key->Init(ctx, src)) {
+ return false;
+ }
+ auto keyNamePtr = key->GetColumnName();
+ YQL_ENSURE(keyNamePtr);
+ if (!src->AddGroupKey(ctx, *keyNamePtr)) {
+ return false;
+ }
+ }
+ ctx.PushBlockShortcuts();
+ if (Having && !Having->Init(ctx, nullptr)) {
+ return false;
+ }
+ HavingGround = ctx.GroundBlockShortcuts(Pos);
+
+ /// SIN: verify reduce one argument
+ if (Args.size() != 1) {
+ ctx.Error(Pos) << "REDUCE requires exactly one UDF argument";
+ return false;
+ }
+ ctx.PushBlockShortcuts();
+ if (!Args[0]->Init(ctx, src)) {
+ return false;
+ }
+ ExprGround = ctx.GroundBlockShortcuts(Pos);
+
+ ctx.PushBlockShortcuts();
+ for (auto orderSpec: OrderBy) {
+ if (!orderSpec->OrderExpr->Init(ctx, src)) {
+ return false;
+ }
+ }
+ OrderByGround = ctx.GroundBlockShortcuts(Pos);
+
+ if (!Udf->Init(ctx, src)) {
+ return false;
+ }
+ if (Udf->GetLabel().empty()) {
+ Columns.SetAll();
+ } else {
Columns.Add(&Udf->GetLabel(), false);
- }
- return true;
- }
-
- TNodePtr Build(TContext& ctx) final {
- auto input = Source->Build(ctx);
- if (!input) {
- return nullptr;
- }
-
+ }
+ return true;
+ }
+
+ TNodePtr Build(TContext& ctx) final {
+ auto input = Source->Build(ctx);
+ if (!input) {
+ return nullptr;
+ }
+
auto keysTuple = Y();
if (Keys.size() == 1) {
keysTuple = Y("Member", "row", BuildQuotedAtom(Pos, *Keys.back()->GetColumnName()));
}
else {
- for (const auto& key: Keys) {
- keysTuple = L(keysTuple, Y("Member", "row", BuildQuotedAtom(Pos, *key->GetColumnName())));
- }
- keysTuple = Q(keysTuple);
- }
+ for (const auto& key: Keys) {
+ keysTuple = L(keysTuple, Y("Member", "row", BuildQuotedAtom(Pos, *key->GetColumnName())));
+ }
+ keysTuple = Q(keysTuple);
+ }
auto extractKey = Y("SqlExtractKey", "row", BuildLambda(Pos, Y("row"), keysTuple));
auto extractKeyLambda = BuildLambda(Pos, Y("row"), extractKey);
-
- TNodePtr processPartitions;
- switch (Mode) {
- case ReduceMode::ByAll: {
- auto columnPtr = Args[0]->GetColumnName();
- TNodePtr expr = BuildAtom(Pos, "partitionStream");
- if (!columnPtr || *columnPtr != "*") {
- expr = Y("Map", "partitionStream", BuildLambda(Pos, Y("keyPair"), Q(L(Y(),\
- Y("Nth", "keyPair", Q(ToString("0"))),\
- Y("Map", Y("Nth", "keyPair", Q(ToString("1"))), BuildLambda(Pos, Y("row"),
- GroundWithExpr(ExprGround, Args[0])))))));
- }
- processPartitions = Y("ToSequence", Y("Apply", Udf, expr));
- break;
- }
- case ReduceMode::ByPartition: {
+
+ TNodePtr processPartitions;
+ switch (Mode) {
+ case ReduceMode::ByAll: {
+ auto columnPtr = Args[0]->GetColumnName();
+ TNodePtr expr = BuildAtom(Pos, "partitionStream");
+ if (!columnPtr || *columnPtr != "*") {
+ expr = Y("Map", "partitionStream", BuildLambda(Pos, Y("keyPair"), Q(L(Y(),\
+ Y("Nth", "keyPair", Q(ToString("0"))),\
+ Y("Map", Y("Nth", "keyPair", Q(ToString("1"))), BuildLambda(Pos, Y("row"),
+ GroundWithExpr(ExprGround, Args[0])))))));
+ }
+ processPartitions = Y("ToSequence", Y("Apply", Udf, expr));
+ break;
+ }
+ case ReduceMode::ByPartition: {
processPartitions = Y("SqlReduce", "partitionStream", extractKeyLambda, Udf,
BuildLambda(Pos, Y("row"), GroundWithExpr(ExprGround, Args[0])));
- break;
- }
- default:
- YQL_ENSURE(false, "Unexpected REDUCE mode");
- }
-
- TNodePtr sortDirection;
- auto sortKeySelector = OrderByGround;
- FillSortParts(OrderBy, sortDirection, sortKeySelector);
+ break;
+ }
+ default:
+ YQL_ENSURE(false, "Unexpected REDUCE mode");
+ }
+
+ TNodePtr sortDirection;
+ auto sortKeySelector = OrderByGround;
+ FillSortParts(OrderBy, sortDirection, sortKeySelector);
if (!OrderBy.empty()) {
sortKeySelector = BuildLambda(Pos, Y("row"), Y("SqlExtractKey", "row", sortKeySelector));
}
-
+
auto partitionByKey = Y(Mode == ReduceMode::ByAll ? "PartitionByKey" : "PartitionsByKeys", "core", extractKeyLambda,
- sortDirection, sortKeySelector, BuildLambda(Pos, Y("partitionStream"), processPartitions));
-
- auto block(Y(Y("let", "core", input)));
+ sortDirection, sortKeySelector, BuildLambda(Pos, Y("partitionStream"), processPartitions));
+
+ auto block(Y(Y("let", "core", input)));
auto filter = Source->BuildFilter(ctx, "core", FiltersGround);
- if (filter) {
- block = L(block, Y("let", "core", filter));
- }
+ if (filter) {
+ block = L(block, Y("let", "core", filter));
+ }
block = L(block, Y("let", "core", Y("AutoDemuxList", partitionByKey)));
- if (Having) {
- block = L(block, Y("let", "core",
- Y("Filter", "core", BuildLambda(Pos, Y("row"), GroundWithExpr(HavingGround, Y("Coalesce", Having, Y("Bool", Q("false"))))))
- ));
- }
- return Y("block", Q(L(block, Y("return", "core"))));
- }
-
+ if (Having) {
+ block = L(block, Y("let", "core",
+ Y("Filter", "core", BuildLambda(Pos, Y("row"), GroundWithExpr(HavingGround, Y("Coalesce", Having, Y("Bool", Q("false"))))))
+ ));
+ }
+ return Y("block", Q(L(block, Y("return", "core"))));
+ }
+
TWriteSettings GetWriteSettings() const final {
return Settings;
}
- TPtr DoClone() const final {
- return new TReduceSource(Pos, Mode, Source->CloneSource(), CloneContainer(OrderBy),
+ TPtr DoClone() const final {
+ return new TReduceSource(Pos, Mode, Source->CloneSource(), CloneContainer(OrderBy),
CloneContainer(Keys), CloneContainer(Args), SafeClone(Udf), SafeClone(Having), Settings);
- }
-private:
- ReduceMode Mode;
- TSourcePtr Source;
+ }
+private:
+ ReduceMode Mode;
+ TSourcePtr Source;
TVector<TSortSpecificationPtr> OrderBy;
TVector<TNodePtr> Keys;
TVector<TNodePtr> Args;
- TNodePtr Udf;
- TNodePtr Having;
+ TNodePtr Udf;
+ TNodePtr Having;
const TWriteSettings Settings;
- TNodePtr ExprGround;
- TNodePtr FiltersGround;
- TNodePtr OrderByGround;
- TNodePtr HavingGround;
-};
-
+ TNodePtr ExprGround;
+ TNodePtr FiltersGround;
+ TNodePtr OrderByGround;
+ TNodePtr HavingGround;
+};
+
TSourcePtr BuildReduce(TPosition pos,
ReduceMode mode,
TSourcePtr source,
@@ -914,131 +914,131 @@ TSourcePtr BuildReduce(TPosition pos,
TNodePtr having,
const TWriteSettings& settings) {
return new TReduceSource(pos, mode, std::move(source), std::move(orderBy), std::move(keys), std::move(args), udf, having, settings);
-}
-
-class TCompositeSelect: public IRealSource {
-public:
+}
+
+class TCompositeSelect: public IRealSource {
+public:
TCompositeSelect(TPosition pos, TSourcePtr source, const TWriteSettings& settings)
- : IRealSource(pos)
- , Source(std::move(source))
+ : IRealSource(pos)
+ , Source(std::move(source))
, Settings(settings)
- {
- YQL_ENSURE(Source);
- }
-
+ {
+ YQL_ENSURE(Source);
+ }
+
void SetSubselects(TVector<TSourcePtr>&& subselects, TSet<TString>&& groupingCols) {
- Subselects = std::move(subselects);
- GroupingCols = std::move(groupingCols);
- Y_VERIFY_DEBUG(Subselects.size() > 1);
- }
-
+ Subselects = std::move(subselects);
+ GroupingCols = std::move(groupingCols);
+ Y_VERIFY_DEBUG(Subselects.size() > 1);
+ }
+
void GetInputTables(TTableList& tableList) const override {
- for (const auto& select: Subselects) {
+ for (const auto& select: Subselects) {
select->GetInputTables(tableList);
- }
+ }
ISource::GetInputTables(tableList);
- }
-
- bool DoInit(TContext& ctx, ISource* src) override {
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) override {
if (AsInner) {
Source->UseAsInner();
}
- ctx.PushBlockShortcuts();
- if (src) {
- src->AddDependentSource(Source.Get());
- }
- if (!Source->Init(ctx, src)) {
- return false;
- }
- if (!Source->InitFilters(ctx)) {
- return false;
- }
- FiltersGround = ctx.GroundBlockShortcuts(Pos);
- for (const auto& select: Subselects) {
- select->SetLabel(Label);
+ ctx.PushBlockShortcuts();
+ if (src) {
+ src->AddDependentSource(Source.Get());
+ }
+ if (!Source->Init(ctx, src)) {
+ return false;
+ }
+ if (!Source->InitFilters(ctx)) {
+ return false;
+ }
+ FiltersGround = ctx.GroundBlockShortcuts(Pos);
+ for (const auto& select: Subselects) {
+ select->SetLabel(Label);
if (AsInner) {
select->UseAsInner();
}
- if (!select->Init(ctx, Source.Get())) {
- return false;
- }
- }
- return true;
- }
-
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
- for (const auto& select: Subselects) {
- if (!select->AddColumn(ctx, column)) {
- return {};
- }
- }
- return true;
- }
-
- TNodePtr Build(TContext& ctx) override {
- auto input = Source->Build(ctx);
- auto block(Y(Y("let", "composite", input)));
+ if (!select->Init(ctx, Source.Get())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ for (const auto& select: Subselects) {
+ if (!select->AddColumn(ctx, column)) {
+ return {};
+ }
+ }
+ return true;
+ }
+
+ TNodePtr Build(TContext& ctx) override {
+ auto input = Source->Build(ctx);
+ auto block(Y(Y("let", "composite", input)));
auto filter = Source->BuildFilter(ctx, "composite", FiltersGround);
- if (filter) {
- block = L(block, Y("let", "composite", filter));
- }
-
- TNodePtr compositeNode = Y("UnionAll");
- for (const auto& select: Subselects) {
- auto addNode = select->Build(ctx);
- if (!addNode) {
- return nullptr;
- }
- compositeNode->Add(addNode);
- }
-
- return GroundWithExpr(block, compositeNode);
- }
-
- bool IsGroupByColumn(const TString& column) const override {
+ if (filter) {
+ block = L(block, Y("let", "composite", filter));
+ }
+
+ TNodePtr compositeNode = Y("UnionAll");
+ for (const auto& select: Subselects) {
+ auto addNode = select->Build(ctx);
+ if (!addNode) {
+ return nullptr;
+ }
+ compositeNode->Add(addNode);
+ }
+
+ return GroundWithExpr(block, compositeNode);
+ }
+
+ bool IsGroupByColumn(const TString& column) const override {
return GroupingCols.contains(column);
- }
-
+ }
+
const TSet<TString>& GetGroupingCols() const {
return GroupingCols;
}
- TNodePtr BuildSort(TContext& ctx, const TString& label) override {
- return Subselects.front()->BuildSort(ctx, label);
- }
-
+ TNodePtr BuildSort(TContext& ctx, const TString& label) override {
+ return Subselects.front()->BuildSort(ctx, label);
+ }
+
bool IsOrdered() const override {
return Subselects.front()->IsOrdered();
}
- const TColumns* GetColumns() const override{
- return Subselects.front()->GetColumns();
- }
-
- ISource* RealSource() const {
- return Source.Get();
- }
-
+ const TColumns* GetColumns() const override{
+ return Subselects.front()->GetColumns();
+ }
+
+ ISource* RealSource() const {
+ return Source.Get();
+ }
+
TWriteSettings GetWriteSettings() const override {
return Settings;
}
- TNodePtr DoClone() const final {
+ TNodePtr DoClone() const final {
auto newSource = MakeIntrusive<TCompositeSelect>(Pos, Source->CloneSource(), Settings);
newSource->SetSubselects(CloneContainer(Subselects), TSet<TString>(GroupingCols));
- return newSource;
- }
-private:
- TSourcePtr Source;
+ return newSource;
+ }
+private:
+ TSourcePtr Source;
const TWriteSettings Settings;
TVector<TSourcePtr> Subselects;
TSet<TString> GroupingCols;
- TNodePtr FiltersGround;
-};
-
-/// \todo simplify class
+ TNodePtr FiltersGround;
+};
+
+/// \todo simplify class
class TSelectCore: public IRealSource {
public:
TSelectCore(
@@ -1048,7 +1048,7 @@ public:
const TVector<TNodePtr>& groupBy,
const TVector<TSortSpecificationPtr>& orderBy,
TNodePtr having,
- TWinSpecs& winSpecs,
+ TWinSpecs& winSpecs,
THoppingWindowSpecPtr hoppingWindowSpec,
const TVector<TNodePtr>& terms,
bool distinct,
@@ -1057,14 +1057,14 @@ public:
const TWriteSettings& settings
)
: IRealSource(pos)
- , Source(std::move(source))
- , GroupByExpr(groupByExpr)
+ , Source(std::move(source))
+ , GroupByExpr(groupByExpr)
, GroupBy(groupBy)
- , OrderBy(orderBy)
+ , OrderBy(orderBy)
, Having(having)
- , WinSpecs(winSpecs)
+ , WinSpecs(winSpecs)
, Terms(terms)
- , Without(without)
+ , Without(without)
, Distinct(distinct)
, HoppingWindowSpec(hoppingWindowSpec)
, Stream(stream)
@@ -1077,116 +1077,116 @@ public:
ISource::GetInputTables(tableList);
}
- bool IsComparableExpression(TContext& ctx, const TNodePtr& expr, const char* sqlConstruction) {
- if (expr->IsConstant()) {
- ctx.Error(expr->GetPos()) << "Unable to " << sqlConstruction << " constant expression";
- return false;
- }
- if (expr->IsAggregated() && !expr->HasState(ENodeState::AggregationKey)) {
- ctx.Error(expr->GetPos()) << "Unable to " << sqlConstruction << " aggregated values";
- return false;
- }
- if (expr->GetSourceName()) {
- return true;
- }
- if (expr->GetOpName().empty()) {
- ctx.Error(expr->GetPos()) << "You should use in " << sqlConstruction << " column name, qualified field, callable function or expression";
- return false;
- }
- return true;
- }
-
- bool DoInit(TContext& ctx, ISource* initSrc) override {
+ bool IsComparableExpression(TContext& ctx, const TNodePtr& expr, const char* sqlConstruction) {
+ if (expr->IsConstant()) {
+ ctx.Error(expr->GetPos()) << "Unable to " << sqlConstruction << " constant expression";
+ return false;
+ }
+ if (expr->IsAggregated() && !expr->HasState(ENodeState::AggregationKey)) {
+ ctx.Error(expr->GetPos()) << "Unable to " << sqlConstruction << " aggregated values";
+ return false;
+ }
+ if (expr->GetSourceName()) {
+ return true;
+ }
+ if (expr->GetOpName().empty()) {
+ ctx.Error(expr->GetPos()) << "You should use in " << sqlConstruction << " column name, qualified field, callable function or expression";
+ return false;
+ }
+ return true;
+ }
+
+ bool DoInit(TContext& ctx, ISource* initSrc) override {
if (AsInner) {
Source->UseAsInner();
}
- if (!Source->Init(ctx, initSrc)) {
+ if (!Source->Init(ctx, initSrc)) {
return false;
}
if (Stream && !Source->IsStream()) {
ctx.Error(Pos) << "SELECT STREAM is unsupported for non-streaming sources";
return false;
}
- if (!Stream && Source->IsStream() && !ctx.PragmaDirectRead) {
+ if (!Stream && Source->IsStream() && !ctx.PragmaDirectRead) {
ctx.Error(Pos) << "SELECT STREAM must be used for streaming sources";
return false;
}
- ctx.PushBlockShortcuts();
- auto src = Source.Get();
+ ctx.PushBlockShortcuts();
+ auto src = Source.Get();
bool hasError = false;
- for (auto& expr: GroupByExpr) {
+ for (auto& expr: GroupByExpr) {
if (!expr->Init(ctx, src) || !IsComparableExpression(ctx, expr, "GROUP BY")) {
hasError = true;
continue;
- }
- }
- if (!src->AddExpressions(ctx, GroupByExpr, EExprSeat::GroupBy)) {
+ }
+ }
+ if (!src->AddExpressions(ctx, GroupByExpr, EExprSeat::GroupBy)) {
hasError = true;
- }
- GroupByExprGround = ctx.GroundBlockShortcuts(Pos);
- /// grouped expressions are available in filters
- ctx.PushBlockShortcuts();
- if (!Source->InitFilters(ctx)) {
+ }
+ GroupByExprGround = ctx.GroundBlockShortcuts(Pos);
+ /// grouped expressions are available in filters
+ ctx.PushBlockShortcuts();
+ if (!Source->InitFilters(ctx)) {
hasError = true;
- }
- FiltersGround = ctx.GroundBlockShortcuts(Pos);
- const bool isJoin = Source->GetJoin();
- for (auto& expr: GroupBy) {
- if (!expr->Init(ctx, src)) {
+ }
+ FiltersGround = ctx.GroundBlockShortcuts(Pos);
+ const bool isJoin = Source->GetJoin();
+ for (auto& expr: GroupBy) {
+ if (!expr->Init(ctx, src)) {
hasError = true;
continue;
}
- auto keyNamePtr = expr->GetColumnName();
- if (keyNamePtr && expr->GetLabel().empty()) {
- auto usedColumn = *keyNamePtr;
- auto sourceNamePtr = expr->GetSourceName();
- auto columnNode = dynamic_cast<TColumnNode*>(expr.Get());
- if (isJoin && (!columnNode || !columnNode->IsArtificial())) {
- if (!sourceNamePtr || sourceNamePtr->empty()) {
- ctx.Error(expr->GetPos()) << "Columns in GROUP BY should have correlation name, error in key: " << usedColumn;
+ auto keyNamePtr = expr->GetColumnName();
+ if (keyNamePtr && expr->GetLabel().empty()) {
+ auto usedColumn = *keyNamePtr;
+ auto sourceNamePtr = expr->GetSourceName();
+ auto columnNode = dynamic_cast<TColumnNode*>(expr.Get());
+ if (isJoin && (!columnNode || !columnNode->IsArtificial())) {
+ if (!sourceNamePtr || sourceNamePtr->empty()) {
+ ctx.Error(expr->GetPos()) << "Columns in GROUP BY should have correlation name, error in key: " << usedColumn;
hasError = true;
continue;
- }
- usedColumn = DotJoin(*sourceNamePtr, usedColumn);
- }
- if (!src->AddGroupKey(ctx, usedColumn)) {
+ }
+ usedColumn = DotJoin(*sourceNamePtr, usedColumn);
+ }
+ if (!src->AddGroupKey(ctx, usedColumn)) {
hasError = true;
continue;
- }
+ }
}
}
- ctx.PushBlockShortcuts();
+ ctx.PushBlockShortcuts();
if (Having && !Having->Init(ctx, src)) {
hasError = true;
}
- HavingGround = ctx.GroundBlockShortcuts(Pos);
- src->AddWindowSpecs(WinSpecs);
+ HavingGround = ctx.GroundBlockShortcuts(Pos);
+ src->AddWindowSpecs(WinSpecs);
if (!InitSelect(ctx, src, isJoin, hasError)) {
return false;
}
- src->FinishColumns();
+ src->FinishColumns();
Aggregate = src->BuildAggregation("core");
if (src->IsFlattenByColumns() || src->IsFlattenColumns()) {
Flatten = src->IsFlattenByColumns() ?
src->BuildFlattenByColumns("row") :
src->BuildFlattenColumns("row");
- if (!Flatten || !Flatten->Init(ctx, src)) {
+ if (!Flatten || !Flatten->Init(ctx, src)) {
hasError = true;
- }
- }
- if (GroupByExpr) {
- auto sourcePreaggregate = src->BuildPreaggregatedMap(ctx);
- if (!sourcePreaggregate) {
+ }
+ }
+ if (GroupByExpr) {
+ auto sourcePreaggregate = src->BuildPreaggregatedMap(ctx);
+ if (!sourcePreaggregate) {
hasError = true;
} else {
PreaggregatedMap = !GroupByExprGround ? sourcePreaggregate :
Y("block", Q(L(GroupByExprGround, Y("return", sourcePreaggregate))));
- }
- }
+ }
+ }
if (Aggregate) {
if (!Aggregate->Init(ctx, src)) {
hasError = true;
@@ -1195,32 +1195,32 @@ public:
Aggregate = Y(
"Filter",
Aggregate,
- BuildLambda(Pos, Y("row"), GroundWithExpr(HavingGround, Y("Coalesce", Having, Y("Bool", Q("false")))))
+ BuildLambda(Pos, Y("row"), GroundWithExpr(HavingGround, Y("Coalesce", Having, Y("Bool", Q("false")))))
);
}
- } else if (Having) {
+ } else if (Having) {
ctx.Error(Having->GetPos()) << "HAVING with meaning GROUP BY () should be with aggregation function.";
hasError = true;
} else if (!Distinct && !GroupBy.empty()) {
ctx.Error(Pos) << "No aggregations were specified";
hasError = true;
}
- if (hasError) {
- return false;
- }
-
- if (src->IsCalcOverWindow()) {
- if (src->IsExprSeat(EExprSeat::WindowPartitionBy, EExprType::WithExpression)) {
- PrewindowMap = src->BuildPrewindowMap(ctx, WinSpecsPartitionByGround);
- if (!PrewindowMap) {
+ if (hasError) {
+ return false;
+ }
+
+ if (src->IsCalcOverWindow()) {
+ if (src->IsExprSeat(EExprSeat::WindowPartitionBy, EExprType::WithExpression)) {
+ PrewindowMap = src->BuildPrewindowMap(ctx, WinSpecsPartitionByGround);
+ if (!PrewindowMap) {
hasError = true;
- }
- }
- CalcOverWindow = src->BuildCalcOverWindow(ctx, "core", WinSpecsOrderByGround);
- if (!CalcOverWindow) {
+ }
+ }
+ CalcOverWindow = src->BuildCalcOverWindow(ctx, "core", WinSpecsOrderByGround);
+ if (!CalcOverWindow) {
hasError = true;
- }
- }
+ }
+ }
if (hasError) {
return false;
}
@@ -1228,7 +1228,7 @@ public:
return true;
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
auto input = Source->Build(ctx);
if (!input) {
return nullptr;
@@ -1525,11 +1525,11 @@ private:
}
} else if (!Columns.List.empty()) {
Y_VERIFY_DEBUG(Columns.List.size() == Terms.size());
- const bool isJoin = Source->GetJoin();
-
- terms = TermsGround ? TermsGround : Y();
- if (Source->IsCompositeSource() && !Columns.QualifiedAll) {
- auto compositeSrcPtr = static_cast<TCompositeSelect*>(Source->GetCompositeSource());
+ const bool isJoin = Source->GetJoin();
+
+ terms = TermsGround ? TermsGround : Y();
+ if (Source->IsCompositeSource() && !Columns.QualifiedAll) {
+ auto compositeSrcPtr = static_cast<TCompositeSelect*>(Source->GetCompositeSource());
if (compositeSrcPtr) {
const auto& groupings = compositeSrcPtr->GetGroupingCols();
for (const auto& column: groupings) {
@@ -1542,43 +1542,43 @@ private:
}
}
if (isAggregated) {
- continue;
- }
+ continue;
+ }
const TString tableName = PreaggregatedMap ? "preaggregated" : "origcore";
terms = L(terms, Y("let", "row", Y("AddMember", "row", BuildQuotedAtom(Pos, column), Y("Nothing", Y("MatchType",
Y("StructMemberType", Y("ListItemType", Y("TypeOf", tableName)), Q(column)),
Q("Optional"), Y("lambda", Q(Y("item")), "item"), Y("lambda", Q(Y("item")), Y("OptionalType", "item")))))));
- }
- }
- }
-
- TNodePtr structObj = nullptr;
- auto column = Columns.List.begin();
- for (auto& term: Terms) {
- if (!term->IsAsterisk()) {
- if (!structObj) {
- structObj = Y("AsStruct");
- }
- structObj = L(structObj, Q(Y(BuildQuotedAtom(Pos, *column), term)));
- }
- ++column;
- }
- terms = structObj ? L(terms, Y("let", "res", structObj)) : Y(Y("let", "res", Y("AsStruct")));
- terms = PrepareWithout(terms);
- if (Columns.QualifiedAll) {
- if (ctx.SimpleColumns && !isJoin) {
- terms = L(terms, Y("let", "res", Y("FlattenMembers", Q(Y(BuildQuotedAtom(Pos, ""), "res")),
- Q(Y(BuildQuotedAtom(Pos, ""), "row")))));
- } else {
- if (isJoin && ctx.SimpleColumns) {
- const auto& sameKeyMap = Source->GetJoin()->GetSameKeysMap();
- if (sameKeyMap) {
- terms = L(terms, Y("let", "flatSameKeys", "row"));
- for (const auto& sameKeysPair: sameKeyMap) {
- const auto& column = sameKeysPair.first;
+ }
+ }
+ }
+
+ TNodePtr structObj = nullptr;
+ auto column = Columns.List.begin();
+ for (auto& term: Terms) {
+ if (!term->IsAsterisk()) {
+ if (!structObj) {
+ structObj = Y("AsStruct");
+ }
+ structObj = L(structObj, Q(Y(BuildQuotedAtom(Pos, *column), term)));
+ }
+ ++column;
+ }
+ terms = structObj ? L(terms, Y("let", "res", structObj)) : Y(Y("let", "res", Y("AsStruct")));
+ terms = PrepareWithout(terms);
+ if (Columns.QualifiedAll) {
+ if (ctx.SimpleColumns && !isJoin) {
+ terms = L(terms, Y("let", "res", Y("FlattenMembers", Q(Y(BuildQuotedAtom(Pos, ""), "res")),
+ Q(Y(BuildQuotedAtom(Pos, ""), "row")))));
+ } else {
+ if (isJoin && ctx.SimpleColumns) {
+ const auto& sameKeyMap = Source->GetJoin()->GetSameKeysMap();
+ if (sameKeyMap) {
+ terms = L(terms, Y("let", "flatSameKeys", "row"));
+ for (const auto& sameKeysPair: sameKeyMap) {
+ const auto& column = sameKeysPair.first;
auto keys = Y("Coalesce");
- auto sameSourceIter = sameKeysPair.second.begin();
- for (auto end = sameKeysPair.second.end(); sameSourceIter != end; ++sameSourceIter) {
+ auto sameSourceIter = sameKeysPair.second.begin();
+ for (auto end = sameKeysPair.second.end(); sameSourceIter != end; ++sameSourceIter) {
auto addKeyNode = Q(DotJoin(*sameSourceIter, column));
keys = L(keys, Y("TryMember", "row", addKeyNode, Y("Null")));
}
@@ -1586,71 +1586,71 @@ private:
terms = L(terms, Y("let", "flatSameKeys", Y("AddMember", "flatSameKeys", Q(column), keys)));
sameSourceIter = sameKeysPair.second.begin();
for (auto end = sameKeysPair.second.end(); sameSourceIter != end; ++sameSourceIter) {
- auto removeKeyNode = Q(DotJoin(*sameSourceIter, column));
+ auto removeKeyNode = Q(DotJoin(*sameSourceIter, column));
terms = L(terms, Y("let", "flatSameKeys", Y("ForceRemoveMember", "flatSameKeys", removeKeyNode)));
- }
- }
- terms = L(terms, Y("let", "row", "flatSameKeys"));
- }
- }
-
- auto members = isJoin ? Y() : Y("FlattenMembers");
- for (auto& term: Terms) {
- if (term->IsAsterisk()) {
- auto sourceName = term->GetSourceName();
+ }
+ }
+ terms = L(terms, Y("let", "row", "flatSameKeys"));
+ }
+ }
+
+ auto members = isJoin ? Y() : Y("FlattenMembers");
+ for (auto& term: Terms) {
+ if (term->IsAsterisk()) {
+ auto sourceName = term->GetSourceName();
YQL_ENSURE(*sourceName && !sourceName->empty());
- if (isJoin) {
- members = L(members, BuildQuotedAtom(Pos, *sourceName + "."));
- } else {
- auto prefix = ctx.SimpleColumns ? "" : *sourceName + ".";
- members = L(members, Q(Y(Q(prefix), "row")));
- }
- }
- }
- if (isJoin) {
- members = Y(ctx.SimpleColumns ? "DivePrefixMembers" : "SelectMembers", "row", Q(members));
- }
- terms = L(terms, Y("let", "res", Y("FlattenMembers", Q(Y(BuildQuotedAtom(Pos, ""), "res")),
- Q(Y(BuildQuotedAtom(Pos, ""), members)))));
- if (isJoin && ctx.SimpleColumns) {
- for (const auto& sameKeysPair: Source->GetJoin()->GetSameKeysMap()) {
- const auto& column = sameKeysPair.first;
- auto addMemberKeyNode = Y("Member", "row", Q(column));
- terms = L(terms, Y("let", "res", Y("AddMember", "res", Q(column), addMemberKeyNode)));
- }
- }
- }
- }
+ if (isJoin) {
+ members = L(members, BuildQuotedAtom(Pos, *sourceName + "."));
+ } else {
+ auto prefix = ctx.SimpleColumns ? "" : *sourceName + ".";
+ members = L(members, Q(Y(Q(prefix), "row")));
+ }
+ }
+ }
+ if (isJoin) {
+ members = Y(ctx.SimpleColumns ? "DivePrefixMembers" : "SelectMembers", "row", Q(members));
+ }
+ terms = L(terms, Y("let", "res", Y("FlattenMembers", Q(Y(BuildQuotedAtom(Pos, ""), "res")),
+ Q(Y(BuildQuotedAtom(Pos, ""), members)))));
+ if (isJoin && ctx.SimpleColumns) {
+ for (const auto& sameKeysPair: Source->GetJoin()->GetSameKeysMap()) {
+ const auto& column = sameKeysPair.first;
+ auto addMemberKeyNode = Y("Member", "row", Q(column));
+ terms = L(terms, Y("let", "res", Y("AddMember", "res", Q(column), addMemberKeyNode)));
+ }
+ }
+ }
+ }
terms = L(terms, Y("let", "res", Y("AsList", "res")));
}
- return terms;
- }
-
+ return terms;
+ }
+
private:
TSourcePtr Source;
TVector<TNodePtr> GroupByExpr;
TVector<TNodePtr> GroupBy;
TVector<TSortSpecificationPtr> OrderBy;
TNodePtr Having;
- TWinSpecs WinSpecs;
+ TWinSpecs WinSpecs;
TNodePtr Flatten;
- TNodePtr PreaggregatedMap;
- TNodePtr PrewindowMap;
+ TNodePtr PreaggregatedMap;
+ TNodePtr PrewindowMap;
TNodePtr Aggregate;
- TNodePtr CalcOverWindow;
- TNodePtr FiltersGround;
- TNodePtr TermsGround;
- TNodePtr GroupByExprGround;
- TNodePtr HavingGround;
- TNodePtr OrderByGround;
- TNodePtr WinSpecsPartitionByGround;
- TNodePtr WinSpecsOrderByGround;
+ TNodePtr CalcOverWindow;
+ TNodePtr FiltersGround;
+ TNodePtr TermsGround;
+ TNodePtr GroupByExprGround;
+ TNodePtr HavingGround;
+ TNodePtr OrderByGround;
+ TNodePtr WinSpecsPartitionByGround;
+ TNodePtr WinSpecsOrderByGround;
TVector<TNodePtr> Terms;
TVector<TNodePtr> Without;
- const bool Distinct;
- bool OrderByInit = false;
+ const bool Distinct;
+ bool OrderByInit = false;
THoppingWindowSpecPtr HoppingWindowSpec;
- const bool Stream;
+ const bool Stream;
const TWriteSettings Settings;
};
@@ -1873,93 +1873,93 @@ TSourcePtr BuildProcess(
return new TProcessSource(pos, std::move(source), with, std::move(terms), listCall, stream, settings);
}
-class TNestedProxySource: public IProxySource {
-public:
+class TNestedProxySource: public IProxySource {
+public:
TNestedProxySource(TPosition pos, const TVector<TNodePtr>& groupBy, TSourcePtr source)
- : IProxySource(pos, source.Get())
- , CompositeSelect(nullptr)
- , Holder(std::move(source))
- , GroupBy(groupBy)
- {}
-
+ : IProxySource(pos, source.Get())
+ , CompositeSelect(nullptr)
+ , Holder(std::move(source))
+ , GroupBy(groupBy)
+ {}
+
TNestedProxySource(TCompositeSelect* compositeSelect, const TVector<TNodePtr>& groupBy)
- : IProxySource(compositeSelect->GetPos(), compositeSelect->RealSource())
- , CompositeSelect(compositeSelect)
- , GroupBy(groupBy)
- {}
-
- bool DoInit(TContext& ctx, ISource* src) override {
- return Source->Init(ctx, src);
- }
-
- TNodePtr Build(TContext& ctx) override {
- return CompositeSelect ? BuildAtom(Pos, "composite", TNodeFlags::Default) : Source->Build(ctx);
- }
-
- bool InitFilters(TContext& ctx) override {
- return CompositeSelect ? true : Source->InitFilters(ctx);
- }
-
+ : IProxySource(compositeSelect->GetPos(), compositeSelect->RealSource())
+ , CompositeSelect(compositeSelect)
+ , GroupBy(groupBy)
+ {}
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ return Source->Init(ctx, src);
+ }
+
+ TNodePtr Build(TContext& ctx) override {
+ return CompositeSelect ? BuildAtom(Pos, "composite", TNodeFlags::Default) : Source->Build(ctx);
+ }
+
+ bool InitFilters(TContext& ctx) override {
+ return CompositeSelect ? true : Source->InitFilters(ctx);
+ }
+
TNodePtr BuildFilter(TContext& ctx, const TString& label, const TNodePtr& groundNode) override {
return CompositeSelect ? nullptr : Source->BuildFilter(ctx, label, groundNode);
- }
-
- bool IsCompositeSource() const override {
- return true;
- }
-
- ISource* GetCompositeSource() override {
- return CompositeSelect;
- }
-
+ }
+
+ bool IsCompositeSource() const override {
+ return true;
+ }
+
+ ISource* GetCompositeSource() override {
+ return CompositeSelect;
+ }
+
bool CalculateGroupingHint(TContext& ctx, const TVector<TString>& columns, ui64& hint) const override {
Y_UNUSED(ctx);
- hint = 0;
- if (GroupByColumns.empty()) {
+ hint = 0;
+ if (GroupByColumns.empty()) {
for (const auto& groupByNode: GroupBy) {
- auto namePtr = groupByNode->GetColumnName();
- YQL_ENSURE(namePtr);
- GroupByColumns.insert(*namePtr);
- }
- }
- for (const auto& column: columns) {
- hint <<= 1;
+ auto namePtr = groupByNode->GetColumnName();
+ YQL_ENSURE(namePtr);
+ GroupByColumns.insert(*namePtr);
+ }
+ }
+ for (const auto& column: columns) {
+ hint <<= 1;
if (!GroupByColumns.contains(column)) {
- hint += 1;
- }
- }
- return true;
- }
-
- void FinishColumns() override {
- Source->FinishColumns();
- }
-
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
- return Source->AddColumn(ctx, column);
- }
-
- TPtr DoClone() const final {
- return Holder.Get() ? new TNestedProxySource(Pos, CloneContainer(GroupBy), Holder->CloneSource()) :
- new TNestedProxySource(CompositeSelect, CloneContainer(GroupBy));
- }
-
-private:
- TCompositeSelect* CompositeSelect;
- TSourcePtr Holder;
+ hint += 1;
+ }
+ }
+ return true;
+ }
+
+ void FinishColumns() override {
+ Source->FinishColumns();
+ }
+
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ return Source->AddColumn(ctx, column);
+ }
+
+ TPtr DoClone() const final {
+ return Holder.Get() ? new TNestedProxySource(Pos, CloneContainer(GroupBy), Holder->CloneSource()) :
+ new TNestedProxySource(CompositeSelect, CloneContainer(GroupBy));
+ }
+
+private:
+ TCompositeSelect* CompositeSelect;
+ TSourcePtr Holder;
TVector<TNodePtr> GroupBy;
mutable TSet<TString> GroupByColumns;
-};
-
+};
+
TSourcePtr BuildSelectCore(
- TContext& ctx,
+ TContext& ctx,
TPosition pos,
TSourcePtr source,
const TVector<TNodePtr>& groupByExpr,
const TVector<TNodePtr>& groupBy,
const TVector<TSortSpecificationPtr>& orderBy,
TNodePtr having,
- TWinSpecs&& winSpecs,
+ TWinSpecs&& winSpecs,
THoppingWindowSpecPtr hoppingWindowSpec,
TVector<TNodePtr>&& terms,
bool distinct,
@@ -1967,54 +1967,54 @@ TSourcePtr BuildSelectCore(
bool stream,
const TWriteSettings& settings
) {
- if (groupBy.empty() || !groupBy.front()->ContentListPtr()) {
+ if (groupBy.empty() || !groupBy.front()->ContentListPtr()) {
return new TSelectCore(pos, std::move(source), groupByExpr, groupBy, orderBy, having, winSpecs, hoppingWindowSpec, terms, distinct, without, stream, settings);
- }
- if (groupBy.size() == 1) {
- /// actualy no big idea to use grouping function in this case (result allways 0)
- auto contentPtr = groupBy.front()->ContentListPtr();
- TSourcePtr proxySource = new TNestedProxySource(pos, *contentPtr, std::move(source));
+ }
+ if (groupBy.size() == 1) {
+ /// actualy no big idea to use grouping function in this case (result allways 0)
+ auto contentPtr = groupBy.front()->ContentListPtr();
+ TSourcePtr proxySource = new TNestedProxySource(pos, *contentPtr, std::move(source));
return BuildSelectCore(ctx, pos, std::move(proxySource), groupByExpr, *contentPtr, orderBy, having, std::move(winSpecs),
hoppingWindowSpec, std::move(terms), distinct, std::move(without), stream, settings);
- }
- /// \todo some smart merge logic, generalize common part of grouping (expr, flatten, etc)?
+ }
+ /// \todo some smart merge logic, generalize common part of grouping (expr, flatten, etc)?
TIntrusivePtr<TCompositeSelect> compositeSelect = new TCompositeSelect(pos, std::move(source), settings);
- size_t totalGroups = 0;
+ size_t totalGroups = 0;
TVector<TSourcePtr> subselects;
TSet<TString> groupingCols;
- for (auto& grouping: groupBy) {
- auto contentPtr = grouping->ContentListPtr();
+ for (auto& grouping: groupBy) {
+ auto contentPtr = grouping->ContentListPtr();
TVector<TNodePtr> cache(1, nullptr);
- if (!contentPtr) {
- cache[0] = grouping;
- contentPtr = &cache;
- }
- for (const auto& elem: *contentPtr) {
- auto namePtr = elem->GetColumnName();
- if (namePtr && !namePtr->empty()) {
- groupingCols.insert(*namePtr);
- }
- }
- TSourcePtr proxySource = new TNestedProxySource(compositeSelect.Get(), *contentPtr);
- if (!subselects.empty()) {
- /// clone terms for others usage
+ if (!contentPtr) {
+ cache[0] = grouping;
+ contentPtr = &cache;
+ }
+ for (const auto& elem: *contentPtr) {
+ auto namePtr = elem->GetColumnName();
+ if (namePtr && !namePtr->empty()) {
+ groupingCols.insert(*namePtr);
+ }
+ }
+ TSourcePtr proxySource = new TNestedProxySource(compositeSelect.Get(), *contentPtr);
+ if (!subselects.empty()) {
+ /// clone terms for others usage
TVector<TNodePtr> termsCopy;
- for (const auto& term: terms) {
- termsCopy.emplace_back(term->Clone());
- }
- std::swap(terms, termsCopy);
- }
- totalGroups += contentPtr->size();
+ for (const auto& term: terms) {
+ termsCopy.emplace_back(term->Clone());
+ }
+ std::swap(terms, termsCopy);
+ }
+ totalGroups += contentPtr->size();
TSelectCore* selectCore = new TSelectCore(pos, std::move(proxySource), CloneContainer(groupByExpr),
*contentPtr, orderBy, SafeClone(having), winSpecs, hoppingWindowSpec, terms, distinct, without, stream, settings);
- subselects.emplace_back(selectCore);
- }
- if (totalGroups > ctx.PragmaGroupByLimit) {
- ctx.Error(pos) << "Unable to GROUP BY more than " << ctx.PragmaGroupByLimit << " groups, you try use " << totalGroups << " groups";
- return nullptr;
- }
- compositeSelect->SetSubselects(std::move(subselects), std::move(groupingCols));
- return compositeSelect;
+ subselects.emplace_back(selectCore);
+ }
+ if (totalGroups > ctx.PragmaGroupByLimit) {
+ ctx.Error(pos) << "Unable to GROUP BY more than " << ctx.PragmaGroupByLimit << " groups, you try use " << totalGroups << " groups";
+ return nullptr;
+ }
+ compositeSelect->SetSubselects(std::move(subselects), std::move(groupingCols));
+ return compositeSelect;
}
class TUnionAll: public IRealSource {
@@ -2022,10 +2022,10 @@ public:
TUnionAll(TPosition pos, TVector<TSourcePtr>&& sources)
: IRealSource(pos)
, Sources(std::move(sources))
- {
- }
+ {
+ }
- const TColumns* GetColumns() const override {
+ const TColumns* GetColumns() const override {
return IRealSource::GetColumns();
}
@@ -2037,7 +2037,7 @@ public:
ISource::GetInputTables(tableList);
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
for (auto& s: Sources) {
s->UseAsInner();
if (!s->Init(ctx, src)) {
@@ -2050,7 +2050,7 @@ public:
return true;
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
auto res = Y("UnionAll");
for (auto& s: Sources) {
auto input = s->Build(ctx);
@@ -2062,20 +2062,20 @@ public:
return res;
}
-
- bool IsStream() const override {
- for (auto& s: Sources) {
- if (!s->IsStream()) {
- return false;
- }
- }
- return true;
- }
-
- TNodePtr DoClone() const final {
- return MakeIntrusive<TUnionAll>(Pos, CloneContainer(Sources));
- }
-
+
+ bool IsStream() const override {
+ for (auto& s: Sources) {
+ if (!s->IsStream()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ TNodePtr DoClone() const final {
+ return MakeIntrusive<TUnionAll>(Pos, CloneContainer(Sources));
+ }
+
private:
TVector<TSourcePtr> Sources;
};
@@ -2084,15 +2084,15 @@ TSourcePtr BuildUnionAll(TPosition pos, TVector<TSourcePtr>&& sources) {
return new TUnionAll(pos, std::move(sources));
}
-class TOverWindowSource: public IProxySource {
-public:
+class TOverWindowSource: public IProxySource {
+public:
TOverWindowSource(TPosition pos, const TString& windowName, ISource* origSource)
- : IProxySource(pos, origSource)
- , WindowName(windowName)
- {
- Source->SetLabel(origSource->GetLabel());
- }
-
+ : IProxySource(pos, origSource)
+ , WindowName(windowName)
+ {
+ Source->SetLabel(origSource->GetLabel());
+ }
+
TString MakeLocalName(const TString& name) override {
return Source->MakeLocalName(name);
}
@@ -2101,80 +2101,80 @@ public:
return Source->AddTmpWindowColumn(column);
}
- bool AddAggregation(TContext& ctx, TAggregationPtr aggr) override {
- if (aggr->IsOverWindow()) {
- return Source->AddAggregationOverWindow(ctx, WindowName, aggr);
- }
- return Source->AddAggregation(ctx, aggr);
- }
-
- bool AddFuncOverWindow(TContext& ctx, TNodePtr expr) override {
- return Source->AddFuncOverWindow(ctx, WindowName, expr);
- }
-
- bool IsOverWindowSource() const override {
- return true;
- }
-
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
- return Source->AddColumn(ctx, column);
- }
-
- TNodePtr Build(TContext& ctx) override {
+ bool AddAggregation(TContext& ctx, TAggregationPtr aggr) override {
+ if (aggr->IsOverWindow()) {
+ return Source->AddAggregationOverWindow(ctx, WindowName, aggr);
+ }
+ return Source->AddAggregation(ctx, aggr);
+ }
+
+ bool AddFuncOverWindow(TContext& ctx, TNodePtr expr) override {
+ return Source->AddFuncOverWindow(ctx, WindowName, expr);
+ }
+
+ bool IsOverWindowSource() const override {
+ return true;
+ }
+
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ return Source->AddColumn(ctx, column);
+ }
+
+ TNodePtr Build(TContext& ctx) override {
Y_UNUSED(ctx);
- Y_FAIL("Unexpected call");
- }
-
- const TString* GetWindowName() const override {
- return &WindowName;
- }
-
- TWindowSpecificationPtr FindWindowSpecification(TContext& ctx, const TString& windowName) const override {
- return Source->FindWindowSpecification(ctx, windowName);
- }
-
- TNodePtr DoClone() const final {
- return {};
- }
-
-private:
+ Y_FAIL("Unexpected call");
+ }
+
+ const TString* GetWindowName() const override {
+ return &WindowName;
+ }
+
+ TWindowSpecificationPtr FindWindowSpecification(TContext& ctx, const TString& windowName) const override {
+ return Source->FindWindowSpecification(ctx, windowName);
+ }
+
+ TNodePtr DoClone() const final {
+ return {};
+ }
+
+private:
const TString WindowName;
-};
-
+};
+
TSourcePtr BuildOverWindowSource(TPosition pos, const TString& windowName, ISource* origSource) {
- return new TOverWindowSource(pos, windowName, origSource);
-}
-
-class TSkipTakeNode final: public TAstListNode {
+ return new TOverWindowSource(pos, windowName, origSource);
+}
+
+class TSkipTakeNode final: public TAstListNode {
public:
- TSkipTakeNode(TPosition pos, const TNodePtr& skip, const TNodePtr& take)
+ TSkipTakeNode(TPosition pos, const TNodePtr& skip, const TNodePtr& take)
: TAstListNode(pos)
{
TNodePtr select(AstNode("select"));
- if (skip) {
- select = Y("Skip", select, skip);
+ if (skip) {
+ select = Y("Skip", select, skip);
}
- Add("let", "select", Y("Take", select, take));
+ Add("let", "select", Y("Take", select, take));
}
- TPtr DoClone() const final {
- return {};
+ TPtr DoClone() const final {
+ return {};
}
};
-TNodePtr BuildSkipTake(TPosition pos, const TNodePtr& skip, const TNodePtr& take) {
+TNodePtr BuildSkipTake(TPosition pos, const TNodePtr& skip, const TNodePtr& take) {
return new TSkipTakeNode(pos, skip, take);
}
class TSelect: public IProxySource {
public:
- TSelect(TPosition pos, TSourcePtr source, TNodePtr skipTake)
+ TSelect(TPosition pos, TSourcePtr source, TNodePtr skipTake)
: IProxySource(pos, source.Get())
- , Source(std::move(source))
+ , Source(std::move(source))
, SkipTake(skipTake)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
Source->SetLabel(Label);
if (AsInner) {
Source->UseAsInner();
@@ -2197,18 +2197,18 @@ public:
return true;
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
auto input = Source->Build(ctx);
if (!input) {
return nullptr;
}
- const auto label = "select";
- auto block(Y(Y("let", label, input)));
+ const auto label = "select";
+ auto block(Y(Y("let", label, input)));
- auto sortNode = Source->BuildSort(ctx, label);
- if (sortNode) {
+ auto sortNode = Source->BuildSort(ctx, label);
+ if (sortNode) {
if (AsInner && !SkipTake) {
- ctx.Warning(sortNode->GetPos(), TIssuesIds::YQL_ORDER_BY_WITHOUT_LIMIT_IN_SUBQUERY) << "ORDER BY without LIMIT in subquery will be ignored";
+ ctx.Warning(sortNode->GetPos(), TIssuesIds::YQL_ORDER_BY_WITHOUT_LIMIT_IN_SUBQUERY) << "ORDER BY without LIMIT in subquery will be ignored";
} else {
block = L(block, sortNode);
}
@@ -2222,17 +2222,17 @@ public:
block = L(block, SkipTake);
}
}
- block = L(block, Y("return", label));
+ block = L(block, Y("return", label));
return Y("block", Q(block));
}
- bool IsSelect() const override {
- return Source->IsSelect();
- }
-
- TPtr DoClone() const final {
- return MakeIntrusive<TSelect>(Pos, Source->CloneSource(), SafeClone(SkipTake));
- }
+ bool IsSelect() const override {
+ return Source->IsSelect();
+ }
+
+ TPtr DoClone() const final {
+ return MakeIntrusive<TSelect>(Pos, Source->CloneSource(), SafeClone(SkipTake));
+ }
protected:
TSourcePtr Source;
TNodePtr SkipTake;
@@ -2240,15 +2240,15 @@ protected:
THolder<TFakeSource> FakeSource;
};
-TSourcePtr BuildSelect(TPosition pos, TSourcePtr source, TNodePtr skipTake) {
- return new TSelect(pos, std::move(source), skipTake);
+TSourcePtr BuildSelect(TPosition pos, TSourcePtr source, TNodePtr skipTake) {
+ return new TSelect(pos, std::move(source), skipTake);
}
-class TSelectResultNode final: public TAstListNode {
+class TSelectResultNode final: public TAstListNode {
public:
TSelectResultNode(TPosition pos, TSourcePtr source, bool writeResult, bool inSubquery)
: TAstListNode(pos)
- , Source(std::move(source))
+ , Source(std::move(source))
, WriteResult(writeResult)
, InSubquery(inSubquery)
{
@@ -2260,12 +2260,12 @@ public:
return true;
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
if (!Source->Init(ctx, src)) {
return false;
}
- src = Source.Get();
+ src = Source.Get();
TTableList tableList;
Source->GetInputTables(tableList);
@@ -2314,7 +2314,7 @@ public:
}
auto columns = Source->GetColumns();
- if (columns && !columns->All && !(columns->QualifiedAll && ctx.SimpleColumns)) {
+ if (columns && !columns->All && !(columns->QualifiedAll && ctx.SimpleColumns)) {
auto list = Y();
for (auto& c: columns->List) {
if (c.EndsWith('*')) {
@@ -2353,12 +2353,12 @@ public:
return true;
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
protected:
- TSourcePtr Source;
-
+ TSourcePtr Source;
+
const bool WriteResult;
const bool InSubquery;
TSourcePtr FakeSource;
diff --git a/ydb/library/yql/sql/v0/sql.cpp b/ydb/library/yql/sql/v0/sql.cpp
index fdcc49fd8d..b028fc0439 100644
--- a/ydb/library/yql/sql/v0/sql.cpp
+++ b/ydb/library/yql/sql/v0/sql.cpp
@@ -22,9 +22,9 @@
#include <util/string/ascii.h>
#include <util/string/cast.h>
#include <util/string/reverse.h>
-#include <util/string/split.h>
+#include <util/string/split.h>
#include <util/string/hex.h>
-#include <util/string/join.h>
+#include <util/string/join.h>
#if defined(_tsan_enabled_)
#include <util/system/mutex.h>
@@ -46,33 +46,33 @@ static TPosition GetPos(const TToken& token) {
return TPosition(token.GetColumn(), token.GetLine());
}
-template <typename TToken>
-TIdentifier GetIdentifier(TTranslation& ctx, const TToken& node) {
- auto token = node.GetToken1();
- return TIdentifier(TPosition(token.GetColumn(), token.GetLine()), ctx.Identifier(token));
-}
-
-inline TIdentifier GetKeywordId(TTranslation& ctx, const TRule_keyword_restricted& node) {
- switch (node.Alt_case()) {
- case TRule_keyword_restricted::kAltKeywordRestricted1:
- return GetIdentifier(ctx, node.GetAlt_keyword_restricted1().GetRule_keyword_compat1());
- case TRule_keyword_restricted::kAltKeywordRestricted2:
- return GetIdentifier(ctx, node.GetAlt_keyword_restricted2().GetRule_keyword_expr_uncompat1());
- case TRule_keyword_restricted::kAltKeywordRestricted3:
- return GetIdentifier(ctx, node.GetAlt_keyword_restricted3().GetRule_keyword_select_uncompat1());
+template <typename TToken>
+TIdentifier GetIdentifier(TTranslation& ctx, const TToken& node) {
+ auto token = node.GetToken1();
+ return TIdentifier(TPosition(token.GetColumn(), token.GetLine()), ctx.Identifier(token));
+}
+
+inline TIdentifier GetKeywordId(TTranslation& ctx, const TRule_keyword_restricted& node) {
+ switch (node.Alt_case()) {
+ case TRule_keyword_restricted::kAltKeywordRestricted1:
+ return GetIdentifier(ctx, node.GetAlt_keyword_restricted1().GetRule_keyword_compat1());
+ case TRule_keyword_restricted::kAltKeywordRestricted2:
+ return GetIdentifier(ctx, node.GetAlt_keyword_restricted2().GetRule_keyword_expr_uncompat1());
+ case TRule_keyword_restricted::kAltKeywordRestricted3:
+ return GetIdentifier(ctx, node.GetAlt_keyword_restricted3().GetRule_keyword_select_uncompat1());
case TRule_keyword_restricted::kAltKeywordRestricted4:
return GetIdentifier(ctx, node.GetAlt_keyword_restricted4().GetRule_keyword_in_uncompat1());
- default:
- Y_FAIL("You should change implementation according grammar changes");
- }
-}
-
-inline TIdentifier GetKeywordId(TTranslation& ctx, const TRule_keyword& node) {
+ default:
+ Y_FAIL("You should change implementation according grammar changes");
+ }
+}
+
+inline TIdentifier GetKeywordId(TTranslation& ctx, const TRule_keyword& node) {
switch (node.Alt_case()) {
- case TRule_keyword::kAltKeyword1:
- return GetKeywordId(ctx, node.GetAlt_keyword1().GetRule_keyword_restricted1());
- case TRule_keyword::kAltKeyword2:
- return GetIdentifier(ctx, node.GetAlt_keyword2().GetRule_keyword_alter_uncompat1());
+ case TRule_keyword::kAltKeyword1:
+ return GetKeywordId(ctx, node.GetAlt_keyword1().GetRule_keyword_restricted1());
+ case TRule_keyword::kAltKeyword2:
+ return GetIdentifier(ctx, node.GetAlt_keyword2().GetRule_keyword_alter_uncompat1());
case TRule_keyword::kAltKeyword3:
return GetIdentifier(ctx, node.GetAlt_keyword3().GetRule_keyword_table_uncompat1());
default:
@@ -80,10 +80,10 @@ inline TIdentifier GetKeywordId(TTranslation& ctx, const TRule_keyword& node) {
}
}
-inline TString GetKeyword(TTranslation& ctx, const TRule_keyword& node) {
- return GetKeywordId(ctx, node).Name;
-}
-
+inline TString GetKeyword(TTranslation& ctx, const TRule_keyword& node) {
+ return GetKeywordId(ctx, node).Name;
+}
+
inline TString GetKeyword(TTranslation& ctx, const TRule_keyword_restricted& node) {
return GetKeywordId(ctx, node).Name;
}
@@ -91,21 +91,21 @@ inline TString GetKeyword(TTranslation& ctx, const TRule_keyword_restricted& nod
static TString Id(const TRule_id& node, TTranslation& ctx) {
// id: IDENTIFIER | keyword;
switch (node.Alt_case()) {
- case TRule_id::kAltId1:
- return ctx.Identifier(node.GetAlt_id1().GetToken1());
- case TRule_id::kAltId2:
- return GetKeyword(ctx, node.GetAlt_id2().GetRule_keyword1());
- default:
- Y_FAIL("You should change implementation according grammar changes");
- }
-}
-
-static TString Id(const TRule_id_schema& node, TTranslation& ctx) {
+ case TRule_id::kAltId1:
+ return ctx.Identifier(node.GetAlt_id1().GetToken1());
+ case TRule_id::kAltId2:
+ return GetKeyword(ctx, node.GetAlt_id2().GetRule_keyword1());
+ default:
+ Y_FAIL("You should change implementation according grammar changes");
+ }
+}
+
+static TString Id(const TRule_id_schema& node, TTranslation& ctx) {
switch (node.Alt_case()) {
- case TRule_id_schema::kAltIdSchema1:
- return ctx.Identifier(node.GetAlt_id_schema1().GetToken1());
- case TRule_id_schema::kAltIdSchema2:
- return GetKeyword(ctx, node.GetAlt_id_schema2().GetRule_keyword_restricted1());
+ case TRule_id_schema::kAltIdSchema1:
+ return ctx.Identifier(node.GetAlt_id_schema1().GetToken1());
+ case TRule_id_schema::kAltIdSchema2:
+ return GetKeyword(ctx, node.GetAlt_id_schema2().GetRule_keyword_restricted1());
default:
Y_FAIL("You should change implementation according grammar changes");
}
@@ -134,21 +134,21 @@ static std::pair<bool, TString> Id(const TRule_id_table_or_at& node, TTranslatio
return std::make_pair(hasAt, Id(node.GetRule_id_table2(), ctx));
}
-static TString Id(const TRule_id_expr& node, TTranslation& ctx) {
- switch (node.Alt_case()) {
- case TRule_id_expr::kAltIdExpr1:
- return ctx.Identifier(node.GetAlt_id_expr1().GetToken1());
- case TRule_id_expr::kAltIdExpr2:
- return ctx.Token(node.GetAlt_id_expr2().GetRule_keyword_compat1().GetToken1());
- case TRule_id_expr::kAltIdExpr3:
- return ctx.Token(node.GetAlt_id_expr3().GetRule_keyword_alter_uncompat1().GetToken1());
+static TString Id(const TRule_id_expr& node, TTranslation& ctx) {
+ switch (node.Alt_case()) {
+ case TRule_id_expr::kAltIdExpr1:
+ return ctx.Identifier(node.GetAlt_id_expr1().GetToken1());
+ case TRule_id_expr::kAltIdExpr2:
+ return ctx.Token(node.GetAlt_id_expr2().GetRule_keyword_compat1().GetToken1());
+ case TRule_id_expr::kAltIdExpr3:
+ return ctx.Token(node.GetAlt_id_expr3().GetRule_keyword_alter_uncompat1().GetToken1());
case TRule_id_expr::kAltIdExpr4:
return ctx.Token(node.GetAlt_id_expr4().GetRule_keyword_in_uncompat1().GetToken1());
- default:
- Y_FAIL("You should change implementation according grammar changes");
- }
-}
-
+ default:
+ Y_FAIL("You should change implementation according grammar changes");
+ }
+}
+
static TString Id(const TRule_in_id_expr& node, TTranslation& ctx) {
switch (node.Alt_case()) {
case TRule_in_id_expr::kAltInIdExpr1:
@@ -174,20 +174,20 @@ static TIdentifier IdEx(const TRule_id& node, TTranslation& ctx) {
}
static TString IdOrString(const TRule_id_or_string& node, TTranslation& ctx, bool rawString = false) {
- switch (node.Alt_case()) {
- case TRule_id_or_string::kAltIdOrString1: {
- return ctx.Identifier(node.GetAlt_id_or_string1().GetToken1());
- }
- case TRule_id_or_string::kAltIdOrString2: {
+ switch (node.Alt_case()) {
+ case TRule_id_or_string::kAltIdOrString1: {
+ return ctx.Identifier(node.GetAlt_id_or_string1().GetToken1());
+ }
+ case TRule_id_or_string::kAltIdOrString2: {
auto raw = ctx.Token(node.GetAlt_id_or_string2().GetToken1());
return rawString ? raw : StringContent(ctx.Context(), raw);
}
- case TRule_id_or_string::kAltIdOrString3:
- return GetKeyword(ctx, node.GetAlt_id_or_string3().GetRule_keyword1());
- default:
- break;
+ case TRule_id_or_string::kAltIdOrString3:
+ return GetKeyword(ctx, node.GetAlt_id_or_string3().GetRule_keyword1());
+ default:
+ break;
}
- Y_FAIL("You should change implementation according grammar changes");
+ Y_FAIL("You should change implementation according grammar changes");
}
static TString IdOrStringAsCluster(const TRule_id_or_string& node, TTranslation& ctx) {
@@ -201,12 +201,12 @@ static TString IdOrStringAsCluster(const TRule_id_or_string& node, TTranslation&
}
static TString OptIdPrefixAsStr(const TRule_opt_id_prefix& node, TTranslation& ctx, const TString& defaultStr = {}) {
- if (!node.HasBlock1()) {
- return defaultStr;
- }
- return IdOrString(node.GetBlock1().GetRule_id_or_string1(), ctx);
-}
-
+ if (!node.HasBlock1()) {
+ return defaultStr;
+ }
+ return IdOrString(node.GetBlock1().GetRule_id_or_string1(), ctx);
+}
+
static TString OptIdPrefixAsClusterStr(const TRule_opt_id_prefix& node, TTranslation& ctx, const TString& defaultStr = {}) {
if (!node.HasBlock1()) {
return defaultStr;
@@ -215,12 +215,12 @@ static TString OptIdPrefixAsClusterStr(const TRule_opt_id_prefix& node, TTransla
}
static void PureColumnListStr(const TRule_pure_column_list& node, TTranslation& ctx, TVector<TString>& outList) {
- outList.push_back(IdOrString(node.GetRule_id_or_string2(), ctx));
- for (auto& block: node.GetBlock3()) {
- outList.push_back(IdOrString(block.GetRule_id_or_string2(), ctx));
- }
-}
-
+ outList.push_back(IdOrString(node.GetRule_id_or_string2(), ctx));
+ for (auto& block: node.GetBlock3()) {
+ outList.push_back(IdOrString(block.GetRule_id_or_string2(), ctx));
+ }
+}
+
static TString NamedNodeImpl(const TRule_bind_parameter& node, TTranslation& ctx) {
// bind_parameter: DOLLAR id;
auto id = Id(node.GetRule_id2(), ctx);
@@ -264,10 +264,10 @@ static bool PureColumnOrNamedListStr(const TRule_pure_column_or_named_list& node
namespace {
-bool IsDistinctOptSet(const TRule_opt_set_quantifier& node) {
- return node.HasBlock1() && node.GetBlock1().GetToken1().GetId() == SQLLexerTokens::TOKEN_DISTINCT;
-}
-
+bool IsDistinctOptSet(const TRule_opt_set_quantifier& node) {
+ return node.HasBlock1() && node.GetBlock1().GetToken1().GetId() == SQLLexerTokens::TOKEN_DISTINCT;
+}
+
std::pair<TString, bool> FlexType(const TRule_flex_type& node, TTranslation& ctx) {
switch (node.Alt_case()) {
case TRule_flex_type::kAltFlexType1:
@@ -293,7 +293,7 @@ std::pair<TString, bool> FlexType(const TRule_flex_type& node, TTranslation& ctx
static TColumnSchema ColumnSchemaImpl(const TRule_column_schema& node, TTranslation& ctx) {
const bool nullable = !node.HasBlock3() || !node.GetBlock3().HasBlock1();
- const TString name(Id(node.GetRule_id_schema1(), ctx));
+ const TString name(Id(node.GetRule_id_schema1(), ctx));
const TPosition pos(ctx.Context().Pos());
const auto& type = FlexType(node.GetRule_flex_type2(), ctx);
return TColumnSchema(pos, name, type.first, nullable, type.second);
@@ -303,12 +303,12 @@ static bool CreateTableEntry(const TRule_create_table_entry& node, TTranslation&
TVector<TColumnSchema>& columns, TVector<TIdentifier>& pkColumns,
TVector<TIdentifier>& partitionByColumns, TVector<std::pair<TIdentifier, bool>>& orderByColumns)
{
- switch (node.Alt_case()) {
- case TRule_create_table_entry::kAltCreateTableEntry1:
- columns.push_back(ColumnSchemaImpl(node.GetAlt_create_table_entry1().GetRule_column_schema1(), ctx));
- break;
+ switch (node.Alt_case()) {
+ case TRule_create_table_entry::kAltCreateTableEntry1:
+ columns.push_back(ColumnSchemaImpl(node.GetAlt_create_table_entry1().GetRule_column_schema1(), ctx));
+ break;
- case TRule_create_table_entry::kAltCreateTableEntry2:
+ case TRule_create_table_entry::kAltCreateTableEntry2:
{
auto& constraint = node.GetAlt_create_table_entry2().GetRule_table_constraint1();
switch (constraint.Alt_case()) {
@@ -371,13 +371,13 @@ static bool CreateTableEntry(const TRule_create_table_entry& node, TTranslation&
}
break;
}
- default:
- ctx.AltNotImplemented("create_table_entry", node);
- return false;
- }
- return true;
-}
-
+ default:
+ ctx.AltNotImplemented("create_table_entry", node);
+ return false;
+ }
+ return true;
+}
+
static std::pair<TString, TString> TableKeyImpl(const std::pair<bool, TString>& nameWithAt, TString view, TTranslation& ctx) {
if (nameWithAt.first) {
view = "@";
@@ -403,11 +403,11 @@ static TVector<TString> TableHintsImpl(const TRule_table_hints& node, TTranslati
auto& block = node.GetBlock2();
switch (block.Alt_case()) {
case TRule_table_hints::TBlock2::kAlt1: {
- hints.push_back(IdOrString(block.GetAlt1().GetRule_id_or_string1(), ctx));
+ hints.push_back(IdOrString(block.GetAlt1().GetRule_id_or_string1(), ctx));
break;
}
case TRule_table_hints::TBlock2::kAlt2: {
- PureColumnListStr(block.GetAlt2().GetRule_pure_column_list1(), ctx, hints);
+ PureColumnListStr(block.GetAlt2().GetRule_pure_column_list1(), ctx, hints);
break;
}
default:
@@ -416,25 +416,25 @@ static TVector<TString> TableHintsImpl(const TRule_table_hints& node, TTranslati
return hints;
}
-/// \return optional prefix
+/// \return optional prefix
static TString ColumnNameAsStr(TTranslation& ctx, const TRule_column_name& node, TString& id) {
- id = IdOrString(node.GetRule_id_or_string2(), ctx);
- return OptIdPrefixAsStr(node.GetRule_opt_id_prefix1(), ctx);
-}
-
+ id = IdOrString(node.GetRule_id_or_string2(), ctx);
+ return OptIdPrefixAsStr(node.GetRule_opt_id_prefix1(), ctx);
+}
+
static TString ColumnNameAsSingleStr(TTranslation& ctx, const TRule_column_name& node) {
TString body;
const TString prefix = ColumnNameAsStr(ctx, node, body);
- return prefix ? prefix + '.' + body : body;
-}
-
+ return prefix ? prefix + '.' + body : body;
+}
+
static void FillTargetList(TTranslation& ctx, const TRule_set_target_list& node, TVector<TString>& targetList) {
- targetList.push_back(ColumnNameAsSingleStr(ctx, node.GetRule_set_target2().GetRule_column_name1()));
- for (auto& block: node.GetBlock3()) {
- targetList.push_back(ColumnNameAsSingleStr(ctx, block.GetRule_set_target2().GetRule_column_name1()));
- }
-}
-
+ targetList.push_back(ColumnNameAsSingleStr(ctx, node.GetRule_set_target2().GetRule_column_name1()));
+ for (auto& block: node.GetBlock3()) {
+ targetList.push_back(ColumnNameAsSingleStr(ctx, block.GetRule_set_target2().GetRule_column_name1()));
+ }
+}
+
TVector<TString> GetContextHints(TContext& ctx) {
TVector<TString> hints;
if (ctx.PragmaInferSchema) {
@@ -529,14 +529,14 @@ static bool ValidateForCounters(const TString& input) {
}
static bool IsColumnsOnly(const TVector<TSortSpecificationPtr>& container) {
- for (const auto& elem: container) {
- if (!elem->OrderExpr->GetColumnName()) {
- return false;
- }
- }
- return true;
-}
-
+ for (const auto& elem: container) {
+ if (!elem->OrderExpr->GetColumnName()) {
+ return false;
+ }
+ }
+ return true;
+}
+
class TSqlTranslation: public TTranslation {
protected:
TSqlTranslation(TContext& ctx, NSQLTranslation::ESqlMode mode)
@@ -544,23 +544,23 @@ protected:
, Mode(mode)
{
/// \todo remove NSQLTranslation::ESqlMode params
- YQL_ENSURE(ctx.Settings.Mode == mode);
+ YQL_ENSURE(ctx.Settings.Mode == mode);
}
protected:
- enum class EExpr {
- Regular,
- GroupBy,
- SqlLambdaParams,
- };
- TNodePtr NamedExpr(const TRule_named_expr& node, EExpr exprMode = EExpr::Regular);
+ enum class EExpr {
+ Regular,
+ GroupBy,
+ SqlLambdaParams,
+ };
+ TNodePtr NamedExpr(const TRule_named_expr& node, EExpr exprMode = EExpr::Regular);
bool NamedExprList(const TRule_named_expr_list& node, TVector<TNodePtr>& exprs, EExpr exprMode = EExpr::Regular);
bool BindList(const TRule_bind_parameter_list& node, TVector<TString>& bindNames);
bool ModulePath(const TRule_module_path& node, TVector<TString>& path);
bool NamedBindList(const TRule_named_bind_parameter_list& node, TVector<TNodePtr>& bindNames);
- TNodePtr NamedBindParam(const TRule_named_bind_parameter& node);
+ TNodePtr NamedBindParam(const TRule_named_bind_parameter& node);
TNodePtr NamedNode(const TRule_named_nodes_stmt& rule, TVector<TString>& names);
-
+
bool ImportStatement(const TRule_import_stmt& stmt, TVector<TString>* namesPtr = nullptr);
TNodePtr DoStatement(const TRule_do_stmt& stmt, bool makeLambda, const TVector<TString>& args = {});
bool DefineActionOrSubqueryStatement(const TRule_define_action_or_subquery_stmt& stmt);
@@ -569,19 +569,19 @@ protected:
TMaybe<TTableArg> TableArgImpl(const TRule_table_arg& node);
TTableRef TableRefImpl(const TRule_table_ref& node);
TMaybe<TSourcePtr> AsTableImpl(const TRule_table_ref& node);
-
+
NSQLTranslation::ESqlMode Mode;
};
class TSqlExpression: public TSqlTranslation {
public:
- enum class ESmartParenthesis {
- Default,
- GroupBy,
- InStatement,
- SqlLambdaParams,
- };
-
+ enum class ESmartParenthesis {
+ Default,
+ GroupBy,
+ InStatement,
+ SqlLambdaParams,
+ };
+
TSqlExpression(TContext& ctx, NSQLTranslation::ESqlMode mode)
: TSqlTranslation(ctx, mode)
{
@@ -590,34 +590,34 @@ public:
TNodePtr Build(const TRule_expr& node) {
// expr: or_subexpr (OR or_subexpr)*;
auto getNode = [](const TRule_expr::TBlock2& b) -> const TRule_or_subexpr& { return b.GetRule_or_subexpr2(); };
- return BinOper("Or", node.GetRule_or_subexpr1(), getNode, node.GetBlock2().begin(), node.GetBlock2().end());
- }
-
- TNodePtr WrapExprShortcuts(const TNodePtr& node) {
- return node;
- //if (!ExprShortcuts || !node) {
- //return node;
- //}
- //TIntrusivePtr<TAstListNodeImpl> prepareNode = new TAstListNodeImpl(Ctx.Pos());
- //for (const auto& aliasPair: ExprShortcuts) {
- //prepareNode->Add(prepareNode->Y("let", aliasPair.first, aliasPair.second));
- //}
- //prepareNode->Add(prepareNode->Y("return", node));
- //return prepareNode->Y("block", prepareNode->Q(prepareNode));
- }
-
- void SetSmartParenthesisMode(ESmartParenthesis mode) {
- SmartParenthesisMode = mode;
- }
-
- TNodePtr ExprShortcut(const TString& baseName, const TNodePtr& node) {
- return BuildShortcutNode(node, baseName);
- //auto alias = Ctx.MakeName(baseName);
- //ExprShortcuts.emplace(alias, node);
- //return BuildAtom(node->GetPos(), alias, TNodeFlags::Default);
- }
-
- TNodePtr LiteralExpr(const TRule_literal_value& node);
+ return BinOper("Or", node.GetRule_or_subexpr1(), getNode, node.GetBlock2().begin(), node.GetBlock2().end());
+ }
+
+ TNodePtr WrapExprShortcuts(const TNodePtr& node) {
+ return node;
+ //if (!ExprShortcuts || !node) {
+ //return node;
+ //}
+ //TIntrusivePtr<TAstListNodeImpl> prepareNode = new TAstListNodeImpl(Ctx.Pos());
+ //for (const auto& aliasPair: ExprShortcuts) {
+ //prepareNode->Add(prepareNode->Y("let", aliasPair.first, aliasPair.second));
+ //}
+ //prepareNode->Add(prepareNode->Y("return", node));
+ //return prepareNode->Y("block", prepareNode->Q(prepareNode));
+ }
+
+ void SetSmartParenthesisMode(ESmartParenthesis mode) {
+ SmartParenthesisMode = mode;
+ }
+
+ TNodePtr ExprShortcut(const TString& baseName, const TNodePtr& node) {
+ return BuildShortcutNode(node, baseName);
+ //auto alias = Ctx.MakeName(baseName);
+ //ExprShortcuts.emplace(alias, node);
+ //return BuildAtom(node->GetPos(), alias, TNodeFlags::Default);
+ }
+
+ TNodePtr LiteralExpr(const TRule_literal_value& node);
private:
template<typename TWindowFunctionRule>
TNodePtr WindowFunctionRule(const TWindowFunctionRule& rule);
@@ -636,10 +636,10 @@ private:
bool SqlLambdaParams(const TNodePtr& node, TVector<TString>& args);
bool SqlLambdaExprBody(TContext& ctx, const TRule_lambda_body& node, TVector<TNodePtr>& exprSeq);
-
+
TNodePtr KeyExpr(const TRule_key_expr& node) {
TSqlExpression expr(Ctx, Mode);
- return expr.WrapExprShortcuts(expr.Build(node.GetRule_expr2()));
+ return expr.WrapExprShortcuts(expr.Build(node.GetRule_expr2()));
}
TNodePtr SubExpr(const TRule_con_subexpr& node);
@@ -648,7 +648,7 @@ private:
TNodePtr SubExpr(const TRule_mul_subexpr& node) {
// mul_subexpr: con_subexpr (DOUBLE_PIPE con_subexpr)*;
auto getNode = [](const TRule_mul_subexpr::TBlock2& b) -> const TRule_con_subexpr& { return b.GetRule_con_subexpr2(); };
- return BinOper("Concat", node.GetRule_con_subexpr1(), getNode, node.GetBlock2().begin(), node.GetBlock2().end());
+ return BinOper("Concat", node.GetRule_con_subexpr1(), getNode, node.GetBlock2().begin(), node.GetBlock2().end());
}
TNodePtr SubExpr(const TRule_add_subexpr& node) {
@@ -666,22 +666,22 @@ private:
TNodePtr SubExpr(const TRule_neq_subexpr& node) {
// neq_subexpr: bit_subexpr ((SHIFT_LEFT | SHIFT_RIGHT | ROT_LEFT | ROT_RIGHT | AMPERSAND | PIPE | CARET) bit_subexpr)* (DOUBLE_QUESTION neq_subexpr)?;
auto getNode = [](const TRule_neq_subexpr::TBlock2& b) -> const TRule_bit_subexpr& { return b.GetRule_bit_subexpr2(); };
- auto result = BinOpList(node.GetRule_bit_subexpr1(), getNode, node.GetBlock2().begin(), node.GetBlock2().end());
- if (!result) {
- return nullptr;
- }
- if (node.HasBlock3()) {
- auto block = node.GetBlock3();
- TSqlExpression altExpr(Ctx, Mode);
- auto altResult = altExpr.WrapExprShortcuts(SubExpr(block.GetRule_neq_subexpr2()));
- if (!altResult) {
- return nullptr;
- }
+ auto result = BinOpList(node.GetRule_bit_subexpr1(), getNode, node.GetBlock2().begin(), node.GetBlock2().end());
+ if (!result) {
+ return nullptr;
+ }
+ if (node.HasBlock3()) {
+ auto block = node.GetBlock3();
+ TSqlExpression altExpr(Ctx, Mode);
+ auto altResult = altExpr.WrapExprShortcuts(SubExpr(block.GetRule_neq_subexpr2()));
+ if (!altResult) {
+ return nullptr;
+ }
const TVector<TNodePtr> args({result, altResult});
- Token(block.GetToken1());
- result = BuildBuiltinFunc(Ctx, Ctx.Pos(), "Coalesce", args);
- }
- return result;
+ Token(block.GetToken1());
+ result = BuildBuiltinFunc(Ctx, Ctx.Pos(), "Coalesce", args);
+ }
+ return result;
}
TNodePtr SubExpr(const TRule_eq_subexpr& node) {
@@ -693,199 +693,199 @@ private:
TNodePtr SubExpr(const TRule_or_subexpr& node) {
// or_subexpr: and_subexpr (AND and_subexpr)*;
auto getNode = [](const TRule_or_subexpr::TBlock2& b) -> const TRule_and_subexpr& { return b.GetRule_and_subexpr2(); };
- return BinOper("And", node.GetRule_and_subexpr1(), getNode, node.GetBlock2().begin(), node.GetBlock2().end());
+ return BinOper("And", node.GetRule_and_subexpr1(), getNode, node.GetBlock2().begin(), node.GetBlock2().end());
}
TNodePtr SubExpr(const TRule_and_subexpr& node) {
// and_subexpr: xor_subexpr (XOR xor_subexpr)*;
auto getNode = [](const TRule_and_subexpr::TBlock2& b) -> const TRule_xor_subexpr& { return b.GetRule_xor_subexpr2(); };
- return BinOper("Xor", node.GetRule_xor_subexpr1(), getNode, node.GetBlock2().begin(), node.GetBlock2().end());
+ return BinOper("Xor", node.GetRule_xor_subexpr1(), getNode, node.GetBlock2().begin(), node.GetBlock2().end());
}
template <typename TNode, typename TGetNode, typename TIter>
TNodePtr BinOpList(const TNode& node, TGetNode getNode, TIter begin, TIter end);
-
+
TNodePtr BinOperList(const TString& opName, TVector<TNodePtr>::const_iterator begin, TVector<TNodePtr>::const_iterator end) const;
-
- template <typename TNode, typename TGetNode, typename TIter>
+
+ template <typename TNode, typename TGetNode, typename TIter>
TNodePtr BinOper(const TString& operName, const TNode& node, TGetNode getNode, TIter begin, TIter end);
-
- TNodePtr SqlInExpr(const TRule_in_expr& node);
- TNodePtr SmartParenthesis(const TRule_smart_parenthesis& node);
-
- ESmartParenthesis SmartParenthesisMode = ESmartParenthesis::Default;
-
+
+ TNodePtr SqlInExpr(const TRule_in_expr& node);
+ TNodePtr SmartParenthesis(const TRule_smart_parenthesis& node);
+
+ ESmartParenthesis SmartParenthesisMode = ESmartParenthesis::Default;
+
THashMap<TString, TNodePtr> ExprShortcuts;
};
-class TSqlCallExpr: public TSqlTranslation {
-public:
+class TSqlCallExpr: public TSqlTranslation {
+public:
TSqlCallExpr(TContext& ctx, NSQLTranslation::ESqlMode mode, TSqlExpression* usedExpr = nullptr)
- : TSqlTranslation(ctx, mode)
- , UsedExpr(usedExpr)
- {
- }
-
+ : TSqlTranslation(ctx, mode)
+ , UsedExpr(usedExpr)
+ {
+ }
+
TSqlCallExpr(const TSqlCallExpr& call, const TVector<TNodePtr>& args)
- : TSqlTranslation(call.Ctx, call.Mode)
- , Pos(call.Pos)
- , Func(call.Func)
- , Module(call.Module)
- , Node(call.Node)
- , Args(args)
- , AggMode(call.AggMode)
- {
- }
-
+ : TSqlTranslation(call.Ctx, call.Mode)
+ , Pos(call.Pos)
+ , Func(call.Func)
+ , Module(call.Module)
+ , Node(call.Node)
+ , Args(args)
+ , AggMode(call.AggMode)
+ {
+ }
+
template<typename TCallExprRule>
bool Init(const TCallExprRule& node);
- void IncCounters();
-
- TNodePtr BuildUdf(bool withArgsType) {
+ void IncCounters();
+
+ TNodePtr BuildUdf(bool withArgsType) {
auto result = Node ? Node : BuildCallable(Pos, Module, Func, withArgsType ? Args : TVector<TNodePtr>());
if (to_lower(Module) == "tensorflow" && Func == "RunBatch") {
Args.erase(Args.begin() + 2);
}
return result;
- }
-
- TNodePtr BuildCall() {
+ }
+
+ TNodePtr BuildCall() {
TVector<TNodePtr> args;
- if (Node) {
- Module = "YQL";
- Func = NamedArgs.empty() ? "Apply" : "NamedApply";
- args.push_back(Node);
- }
- bool mustUseNamed = !NamedArgs.empty();
- if (mustUseNamed) {
- if (Node) {
- mustUseNamed = false;
- }
- args.emplace_back(BuildTuple(Pos, PositionalArgs));
- args.emplace_back(BuildStructure(Pos, NamedArgs));
- } else {
- args.insert(args.end(), Args.begin(), Args.end());
- }
- TFuncPrepareNameNode funcPrepareNameNode;
- if (UsedExpr) {
- funcPrepareNameNode = [this](const TString& baseName, const TNodePtr& node) {
- return UsedExpr->ExprShortcut(baseName, node);
- };
- }
- auto result = BuildBuiltinFunc(Ctx, Pos, Func, args, Module, AggMode, &mustUseNamed, funcPrepareNameNode);
- if (mustUseNamed) {
- Error() << "Named args are used for call, but unsupported by function: " << Func;
- return nullptr;
- }
- return result;
- }
-
- TPosition GetPos() const {
- return Pos;
- }
-
+ if (Node) {
+ Module = "YQL";
+ Func = NamedArgs.empty() ? "Apply" : "NamedApply";
+ args.push_back(Node);
+ }
+ bool mustUseNamed = !NamedArgs.empty();
+ if (mustUseNamed) {
+ if (Node) {
+ mustUseNamed = false;
+ }
+ args.emplace_back(BuildTuple(Pos, PositionalArgs));
+ args.emplace_back(BuildStructure(Pos, NamedArgs));
+ } else {
+ args.insert(args.end(), Args.begin(), Args.end());
+ }
+ TFuncPrepareNameNode funcPrepareNameNode;
+ if (UsedExpr) {
+ funcPrepareNameNode = [this](const TString& baseName, const TNodePtr& node) {
+ return UsedExpr->ExprShortcut(baseName, node);
+ };
+ }
+ auto result = BuildBuiltinFunc(Ctx, Pos, Func, args, Module, AggMode, &mustUseNamed, funcPrepareNameNode);
+ if (mustUseNamed) {
+ Error() << "Named args are used for call, but unsupported by function: " << Func;
+ return nullptr;
+ }
+ return result;
+ }
+
+ TPosition GetPos() const {
+ return Pos;
+ }
+
const TVector<TNodePtr>& GetArgs() const {
- return Args;
- }
-
- bool EnsureNotDistinct(const TString& request) const {
- if (AggMode == EAggregateMode::Distinct) {
- Ctx.Error() << request << " does not allow DISTINCT arguments";
- return false;
- }
- return true;
- }
-
- void SetOverWindow() {
- YQL_ENSURE(AggMode == EAggregateMode::Normal);
- AggMode = EAggregateMode::OverWindow;
- }
-
- void SetIgnoreNulls() {
- Func += "_IgnoreNulls";
- }
-
-private:
- TPosition Pos;
- TString Func;
- TString Module;
- TNodePtr Node;
+ return Args;
+ }
+
+ bool EnsureNotDistinct(const TString& request) const {
+ if (AggMode == EAggregateMode::Distinct) {
+ Ctx.Error() << request << " does not allow DISTINCT arguments";
+ return false;
+ }
+ return true;
+ }
+
+ void SetOverWindow() {
+ YQL_ENSURE(AggMode == EAggregateMode::Normal);
+ AggMode = EAggregateMode::OverWindow;
+ }
+
+ void SetIgnoreNulls() {
+ Func += "_IgnoreNulls";
+ }
+
+private:
+ TPosition Pos;
+ TString Func;
+ TString Module;
+ TNodePtr Node;
TVector<TNodePtr> Args;
TVector<TNodePtr> PositionalArgs;
TVector<TNodePtr> NamedArgs;
- EAggregateMode AggMode = EAggregateMode::Normal;
+ EAggregateMode AggMode = EAggregateMode::Normal;
TSqlExpression* UsedExpr = nullptr;
-};
-
-TNodePtr TSqlTranslation::NamedExpr(const TRule_named_expr& node, EExpr exprMode) {
- TSqlExpression expr(Ctx, Mode);
- if (exprMode == EExpr::GroupBy) {
- expr.SetSmartParenthesisMode(TSqlExpression::ESmartParenthesis::GroupBy);
- } else if (exprMode == EExpr::SqlLambdaParams) {
- expr.SetSmartParenthesisMode(TSqlExpression::ESmartParenthesis::SqlLambdaParams);
- }
- TNodePtr exprNode(expr.WrapExprShortcuts(expr.Build(node.GetRule_expr1())));
- if (!exprNode) {
- Ctx.IncrementMonCounter("sql_errors", "NamedExprInvalid");
- return nullptr;
- }
- if (node.HasBlock2()) {
+};
+
+TNodePtr TSqlTranslation::NamedExpr(const TRule_named_expr& node, EExpr exprMode) {
+ TSqlExpression expr(Ctx, Mode);
+ if (exprMode == EExpr::GroupBy) {
+ expr.SetSmartParenthesisMode(TSqlExpression::ESmartParenthesis::GroupBy);
+ } else if (exprMode == EExpr::SqlLambdaParams) {
+ expr.SetSmartParenthesisMode(TSqlExpression::ESmartParenthesis::SqlLambdaParams);
+ }
+ TNodePtr exprNode(expr.WrapExprShortcuts(expr.Build(node.GetRule_expr1())));
+ if (!exprNode) {
+ Ctx.IncrementMonCounter("sql_errors", "NamedExprInvalid");
+ return nullptr;
+ }
+ if (node.HasBlock2()) {
exprNode = SafeClone(exprNode);
- exprNode->SetLabel(IdOrString(node.GetBlock2().GetRule_id_or_string2(), *this));
- }
- return exprNode;
-}
-
+ exprNode->SetLabel(IdOrString(node.GetBlock2().GetRule_id_or_string2(), *this));
+ }
+ return exprNode;
+}
+
bool TSqlTranslation::NamedExprList(const TRule_named_expr_list& node, TVector<TNodePtr>& exprs, EExpr exprMode) {
- exprs.emplace_back(NamedExpr(node.GetRule_named_expr1(), exprMode));
- if (!exprs.back()) {
- return false;
- }
- for (auto& b: node.GetBlock2()) {
- exprs.emplace_back(NamedExpr(b.GetRule_named_expr2(), exprMode));
- if (!exprs.back()) {
- return false;
- }
- }
- return true;
-}
-
+ exprs.emplace_back(NamedExpr(node.GetRule_named_expr1(), exprMode));
+ if (!exprs.back()) {
+ return false;
+ }
+ for (auto& b: node.GetBlock2()) {
+ exprs.emplace_back(NamedExpr(b.GetRule_named_expr2(), exprMode));
+ if (!exprs.back()) {
+ return false;
+ }
+ }
+ return true;
+}
+
bool TSqlTranslation::BindList(const TRule_bind_parameter_list& node, TVector<TString>& bindNames) {
- bindNames.emplace_back(NamedNodeImpl(node.GetRule_bind_parameter1(), *this));
- for (auto& b: node.GetBlock2()) {
- bindNames.emplace_back(NamedNodeImpl(b.GetRule_bind_parameter2(), *this));
- }
- return true;
-}
-
+ bindNames.emplace_back(NamedNodeImpl(node.GetRule_bind_parameter1(), *this));
+ for (auto& b: node.GetBlock2()) {
+ bindNames.emplace_back(NamedNodeImpl(b.GetRule_bind_parameter2(), *this));
+ }
+ return true;
+}
+
bool TSqlTranslation::ModulePath(const TRule_module_path& node, TVector<TString>& path) {
- if (node.HasBlock1()) {
- path.emplace_back(TString());
- }
- path.emplace_back(Id(node.GetRule_id2(), *this));
- for (auto& b: node.GetBlock3()) {
- path.emplace_back(Id(b.GetRule_id2(), *this));
- }
- return true;
-}
-
+ if (node.HasBlock1()) {
+ path.emplace_back(TString());
+ }
+ path.emplace_back(Id(node.GetRule_id2(), *this));
+ for (auto& b: node.GetBlock3()) {
+ path.emplace_back(Id(b.GetRule_id2(), *this));
+ }
+ return true;
+}
+
bool TSqlTranslation::NamedBindList(const TRule_named_bind_parameter_list& node, TVector<TNodePtr>& bindNames) {
- bindNames.emplace_back(NamedBindParam(node.GetRule_named_bind_parameter1()));
- for (auto& b: node.GetBlock2()) {
- bindNames.emplace_back(NamedBindParam(b.GetRule_named_bind_parameter2()));
- }
- return std::find(bindNames.begin(), bindNames.end(), nullptr) == bindNames.end();
-}
-
-TNodePtr TSqlTranslation::NamedBindParam(const TRule_named_bind_parameter& node) {
- auto bindName = NamedNodeImpl(node.GetRule_bind_parameter1(), *this);
- auto result = BuildAtom(Ctx.Pos(), bindName, NYql::TNodeFlags::Default);
- if (node.HasBlock2()) {
- result->SetLabel(NamedNodeImpl(node.GetBlock2().GetRule_bind_parameter2(), *this));
- }
- return result;
-}
-
+ bindNames.emplace_back(NamedBindParam(node.GetRule_named_bind_parameter1()));
+ for (auto& b: node.GetBlock2()) {
+ bindNames.emplace_back(NamedBindParam(b.GetRule_named_bind_parameter2()));
+ }
+ return std::find(bindNames.begin(), bindNames.end(), nullptr) == bindNames.end();
+}
+
+TNodePtr TSqlTranslation::NamedBindParam(const TRule_named_bind_parameter& node) {
+ auto bindName = NamedNodeImpl(node.GetRule_bind_parameter1(), *this);
+ auto result = BuildAtom(Ctx.Pos(), bindName, NYql::TNodeFlags::Default);
+ if (node.HasBlock2()) {
+ result->SetLabel(NamedNodeImpl(node.GetBlock2().GetRule_bind_parameter2(), *this));
+ }
+ return result;
+}
+
TMaybe<TTableArg> TSqlTranslation::TableArgImpl(const TRule_table_arg& node) {
TTableArg ret;
ret.HasAt = node.HasBlock1();
@@ -1001,27 +1001,27 @@ TMaybe<TSourcePtr> TSqlTranslation::AsTableImpl(const TRule_table_ref& node) {
}
bool Expr(TSqlExpression& sqlExpr, TVector<TNodePtr>& exprNodes, const TRule_expr& node) {
- TNodePtr exprNode = sqlExpr.Build(node);
- if (!exprNode) {
- return false;
- }
- exprNodes.push_back(exprNode);
- return true;
-}
-
+ TNodePtr exprNode = sqlExpr.Build(node);
+ if (!exprNode) {
+ return false;
+ }
+ exprNodes.push_back(exprNode);
+ return true;
+}
+
bool ExprList(TSqlExpression& sqlExpr, TVector<TNodePtr>& exprNodes, const TRule_expr_list& node) {
- if (!Expr(sqlExpr, exprNodes, node.GetRule_expr1())) {
- return false;
- }
- for (auto b: node.GetBlock2()) {
- sqlExpr.Token(b.GetToken1());
- if (!Expr(sqlExpr, exprNodes, b.GetRule_expr2())) {
- return false;
- }
- }
- return true;
-}
-
+ if (!Expr(sqlExpr, exprNodes, node.GetRule_expr1())) {
+ return false;
+ }
+ for (auto b: node.GetBlock2()) {
+ sqlExpr.Token(b.GetToken1());
+ if (!Expr(sqlExpr, exprNodes, b.GetRule_expr2())) {
+ return false;
+ }
+ }
+ return true;
+}
+
template<typename TCallExprRule>
bool TSqlCallExpr::Init(const TCallExprRule& node) {
// call_expr: ((id_or_string NAMESPACE id_or_string) | id_expr | bind_parameter) LPAREN (opt_set_quantifier named_expr_list COMMA? | ASTERISK)? RPAREN;
@@ -1030,9 +1030,9 @@ bool TSqlCallExpr::Init(const TCallExprRule& node) {
const auto& block = node.GetBlock1();
switch (block.Alt_case()) {
case TCallExprRule::TBlock1::kAlt1: {
- auto& subblock = block.GetAlt1().GetBlock1();
- Module = IdOrString(subblock.GetRule_id_or_string1(), *this);
- Func = IdOrString(subblock.GetRule_id_or_string3(), *this);
+ auto& subblock = block.GetAlt1().GetBlock1();
+ Module = IdOrString(subblock.GetRule_id_or_string1(), *this);
+ Func = IdOrString(subblock.GetRule_id_or_string3(), *this);
break;
}
case TCallExprRule::TBlock1::kAlt2: {
@@ -1041,7 +1041,7 @@ bool TSqlCallExpr::Init(const TCallExprRule& node) {
} else {
Func = Id(block.GetAlt2().GetRule_in_id_expr1(), *this);
}
- break;
+ break;
}
case TCallExprRule::TBlock1::kAlt3:
Node = GetNamedNode(NamedNodeImpl(block.GetAlt3().GetRule_bind_parameter1(), *this));
@@ -1056,26 +1056,26 @@ bool TSqlCallExpr::Init(const TCallExprRule& node) {
if (node.HasBlock3()) {
switch (node.GetBlock3().Alt_case()) {
case TCallExprRule::TBlock3::kAlt1: {
- const auto& alt = node.GetBlock3().GetAlt1();
- if (IsDistinctOptSet(alt.GetRule_opt_set_quantifier1())) {
- YQL_ENSURE(AggMode == EAggregateMode::Normal);
- AggMode = EAggregateMode::Distinct;
- Ctx.IncrementMonCounter("sql_features", "DistinctInCallExpr");
- }
- if (!NamedExprList(alt.GetRule_named_expr_list2(), Args)) {
- return false;
+ const auto& alt = node.GetBlock3().GetAlt1();
+ if (IsDistinctOptSet(alt.GetRule_opt_set_quantifier1())) {
+ YQL_ENSURE(AggMode == EAggregateMode::Normal);
+ AggMode = EAggregateMode::Distinct;
+ Ctx.IncrementMonCounter("sql_features", "DistinctInCallExpr");
+ }
+ if (!NamedExprList(alt.GetRule_named_expr_list2(), Args)) {
+ return false;
+ }
+ for (const auto& arg: Args) {
+ if (arg->GetLabel()) {
+ NamedArgs.push_back(arg);
+ } else {
+ PositionalArgs.push_back(arg);
+ if (!NamedArgs.empty()) {
+ Ctx.Error(arg->GetPos()) << "Unnamed arguments can not follow after named one";
+ return false;
+ }
+ }
}
- for (const auto& arg: Args) {
- if (arg->GetLabel()) {
- NamedArgs.push_back(arg);
- } else {
- PositionalArgs.push_back(arg);
- if (!NamedArgs.empty()) {
- Ctx.Error(arg->GetPos()) << "Unnamed arguments can not follow after named one";
- return false;
- }
- }
- }
break;
}
case TCallExprRule::TBlock3::kAlt2:
@@ -1127,202 +1127,202 @@ private:
bool SortSpecification(const TRule_sort_specification& node, TVector<TSortSpecificationPtr>& sortSpecs);
bool SortSpecificationList(const TRule_sort_specification_list& node, TVector<TSortSpecificationPtr>& sortSpecs);
TSourcePtr SingleSource(const TRule_single_source& node);
- TSourcePtr NamedSingleSource(const TRule_named_single_source& node);
+ TSourcePtr NamedSingleSource(const TRule_named_single_source& node);
TVector<TNodePtr> OrdinaryNamedColumnList(const TRule_ordinary_named_column_list& node);
- TSourcePtr FlattenSource(const TRule_flatten_source& node);
+ TSourcePtr FlattenSource(const TRule_flatten_source& node);
TSourcePtr JoinSource(const TRule_join_source& node);
bool JoinOp(ISource* join, const TRule_join_source::TBlock2& block);
TNodePtr JoinExpr(ISource*, const TRule_join_constraint& node);
TSourcePtr ProcessCore(const TRule_process_core& node, const TWriteSettings& settings, TPosition& selectPos);
TSourcePtr ReduceCore(const TRule_reduce_core& node, const TWriteSettings& settings, TPosition& selectPos);
TSourcePtr SelectCore(const TRule_select_core& node, const TWriteSettings& settings, TPosition& selectPos);
- bool FrameStart(const TRule_window_frame_start& rule, TNodePtr& node, bool beginBound);
- bool FrameBound(const TRule_window_frame_bound& rule, TNodePtr& node, bool beginBound);
- bool FrameClause(const TRule_window_frame_clause& node, TMaybe<TFrameSpecification>& winSpecPtr);
- TWindowSpecificationPtr WindowSpecification(const TRule_window_specification_details& rule);
- bool WindowDefenition(const TRule_window_definition& node, TWinSpecs& winSpecs);
- bool WindowClause(const TRule_window_clause& node, TWinSpecs& winSpecs);
+ bool FrameStart(const TRule_window_frame_start& rule, TNodePtr& node, bool beginBound);
+ bool FrameBound(const TRule_window_frame_bound& rule, TNodePtr& node, bool beginBound);
+ bool FrameClause(const TRule_window_frame_clause& node, TMaybe<TFrameSpecification>& winSpecPtr);
+ TWindowSpecificationPtr WindowSpecification(const TRule_window_specification_details& rule);
+ bool WindowDefenition(const TRule_window_definition& node, TWinSpecs& winSpecs);
+ bool WindowClause(const TRule_window_clause& node, TWinSpecs& winSpecs);
bool OrderByClause(const TRule_order_by_clause& node, TVector<TSortSpecificationPtr>& orderBy);
TSourcePtr SelectKind(const TRule_select_kind& node, TPosition& selectPos);
TSourcePtr SelectKind(const TRule_select_kind_partial& node, TPosition& selectPos);
TSourcePtr SelectKind(const TRule_select_kind_parenthesis& node, TPosition& selectPos);
};
-class TGroupByClause: public TSqlTranslation {
- enum class EGroupByFeatures {
- Begin,
- Ordinary = Begin,
- Expression,
- Rollup,
- Cube,
- GroupingSet,
- Empty,
- End,
- };
- typedef TEnumBitSet<EGroupByFeatures, static_cast<int>(EGroupByFeatures::Begin), static_cast<int>(EGroupByFeatures::End)> TGroupingSetFeatures;
-
- class TGroupByClauseCtx: public TSimpleRefCount<TGroupByClauseCtx> {
- public:
- typedef TIntrusivePtr<TGroupByClauseCtx> TPtr;
-
- TGroupingSetFeatures GroupFeatures;
+class TGroupByClause: public TSqlTranslation {
+ enum class EGroupByFeatures {
+ Begin,
+ Ordinary = Begin,
+ Expression,
+ Rollup,
+ Cube,
+ GroupingSet,
+ Empty,
+ End,
+ };
+ typedef TEnumBitSet<EGroupByFeatures, static_cast<int>(EGroupByFeatures::Begin), static_cast<int>(EGroupByFeatures::End)> TGroupingSetFeatures;
+
+ class TGroupByClauseCtx: public TSimpleRefCount<TGroupByClauseCtx> {
+ public:
+ typedef TIntrusivePtr<TGroupByClauseCtx> TPtr;
+
+ TGroupingSetFeatures GroupFeatures;
TMap<TString, TNodePtr> NodeAliases;
- size_t UnnamedCount = 0;
- };
-
-public:
+ size_t UnnamedCount = 0;
+ };
+
+public:
TGroupByClause(TContext& ctx, NSQLTranslation::ESqlMode mode, TGroupByClauseCtx::TPtr groupSetContext = {})
- : TSqlTranslation(ctx, mode)
- , GroupSetContext(groupSetContext ? groupSetContext : TGroupByClauseCtx::TPtr(new TGroupByClauseCtx()))
- {}
-
+ : TSqlTranslation(ctx, mode)
+ , GroupSetContext(groupSetContext ? groupSetContext : TGroupByClauseCtx::TPtr(new TGroupByClauseCtx()))
+ {}
+
bool Build(const TRule_group_by_clause& node, bool stream);
- bool ParseList(const TRule_grouping_element_list& groupingListNode);
-
+ bool ParseList(const TRule_grouping_element_list& groupingListNode);
+
void SetFeatures(const TString& field) const;
TVector<TNodePtr>& Content();
TMap<TString, TNodePtr>& Aliases();
THoppingWindowSpecPtr GetHoppingWindow();
-private:
+private:
TVector<TNodePtr> MultiplyGroupingSets(const TVector<TNodePtr>& lhs, const TVector<TNodePtr>& rhs) const;
- void ResolveGroupByAndGrouping();
- bool GroupingElement(const TRule_grouping_element& node);
+ void ResolveGroupByAndGrouping();
+ bool GroupingElement(const TRule_grouping_element& node);
void FeedCollection(const TNodePtr& elem, TVector<TNodePtr>& collection, bool& hasEmpty) const;
- bool OrdinaryGroupingSet(const TRule_ordinary_grouping_set& node);
- bool OrdinaryGroupingSetList(const TRule_ordinary_grouping_set_list& node);
+ bool OrdinaryGroupingSet(const TRule_ordinary_grouping_set& node);
+ bool OrdinaryGroupingSetList(const TRule_ordinary_grouping_set_list& node);
bool HoppingWindow(const TRule_hopping_window_specification& node);
-
+
bool IsNodeColumnsOrNamedExpression(const TVector<TNodePtr>& content, const TString& construction) const;
-
- TGroupingSetFeatures& Features();
- const TGroupingSetFeatures& Features() const;
+
+ TGroupingSetFeatures& Features();
+ const TGroupingSetFeatures& Features() const;
bool AddAlias(const TString& label, const TNodePtr& node);
TString GenerateGroupByExprName();
bool IsAutogenerated(const TString* name) const;
-
+
TVector<TNodePtr> GroupBySet;
- TGroupByClauseCtx::TPtr GroupSetContext;
+ TGroupByClauseCtx::TPtr GroupSetContext;
THoppingWindowSpecPtr HoppingWindowSpec; // stream queries
static const TString AutogenerateNamePrefix;
-};
-
+};
+
const TString TGroupByClause::AutogenerateNamePrefix = "group";
-
+
bool ParseNumbers(TContext& ctx, const TString& strOrig, ui64& value, TString& suffix) {
- const auto str = to_lower(strOrig);
+ const auto str = to_lower(strOrig);
const auto strLen = str.size();
- ui64 base = 10;
- if (strLen > 2 && str[0] == '0') {
- const auto formatChar = str[1];
- if (formatChar == 'x') {
- base = 16;
- } else if (formatChar == 'o') {
- base = 8;
- } else if (formatChar == 'b') {
- base = 2;
- }
- }
- if (strLen > 1) {
- auto iter = str.cend() - 1;
+ ui64 base = 10;
+ if (strLen > 2 && str[0] == '0') {
+ const auto formatChar = str[1];
+ if (formatChar == 'x') {
+ base = 16;
+ } else if (formatChar == 'o') {
+ base = 8;
+ } else if (formatChar == 'b') {
+ base = 2;
+ }
+ }
+ if (strLen > 1) {
+ auto iter = str.cend() - 1;
if (*iter == 'l' || *iter == 's' || *iter == 't' || /* deprecated */ *iter == 'b') {
- --iter;
- }
+ --iter;
+ }
if (*iter == 'u') {
- --iter;
- }
+ --iter;
+ }
suffix = TString(++iter, str.cend());
- }
- value = 0;
+ }
+ value = 0;
const TString digString(str.begin() + (base == 10 ? 0 : 2), str.end() - suffix.size());
- for (const char& cur: digString) {
+ for (const char& cur: digString) {
const ui64 curDigit = Char2DigitTable[static_cast<int>(cur)];
if (curDigit >= base) {
- ctx.Error(ctx.Pos()) << "Failed to parse number from string: " << strOrig << ", char: '" << cur <<
- "' is out of base: " << base;
- return false;
- }
- const auto curValue = value;
- value *= base;
- value += curDigit;
- if (curValue > value) {
- ctx.Error(ctx.Pos()) << "Failed to parse number from string: " << strOrig << ", number limit overflow";
- return false;
- }
- }
- return true;
-}
-
-TNodePtr LiteralNumber(TContext& ctx, const TRule_integer& node) {
+ ctx.Error(ctx.Pos()) << "Failed to parse number from string: " << strOrig << ", char: '" << cur <<
+ "' is out of base: " << base;
+ return false;
+ }
+ const auto curValue = value;
+ value *= base;
+ value += curDigit;
+ if (curValue > value) {
+ ctx.Error(ctx.Pos()) << "Failed to parse number from string: " << strOrig << ", number limit overflow";
+ return false;
+ }
+ }
+ return true;
+}
+
+TNodePtr LiteralNumber(TContext& ctx, const TRule_integer& node) {
const TString intergerString = ctx.Token(node.GetToken1());
- ui64 value;
+ ui64 value;
TString suffix;
- if (!ParseNumbers(ctx, intergerString, value, suffix)) {
- return {};
- }
+ if (!ParseNumbers(ctx, intergerString, value, suffix)) {
+ return {};
+ }
if (suffix == "ub" || suffix == "b") {
ctx.Warning(ctx.Pos(), TIssuesIds::YQL_DEPRECATED_TINY_INT_LITERAL_SUFFIX) << "Deprecated suffix 'b' - please use 't' suffix for 8-bit integers";
}
- const bool noSpaceForInt32 = value >> 31;
- const bool noSpaceForInt64 = value >> 63;
- if (suffix == "") {
- if (noSpaceForInt64) {
- return new TLiteralNumberNode<ui64>(ctx.Pos(), "Uint64", ToString(value));
- } else if (noSpaceForInt32) {
- return new TLiteralNumberNode<i64>(ctx.Pos(), "Int64", ToString(value));
- }
- return new TLiteralNumberNode<i32>(ctx.Pos(), "Int32", ToString(value));
- } else if (suffix == "u") {
- return new TLiteralNumberNode<ui32>(ctx.Pos(), "Uint32", ToString(value));
- } else if (suffix == "ul") {
- return new TLiteralNumberNode<ui64>(ctx.Pos(), "Uint64", ToString(value));
+ const bool noSpaceForInt32 = value >> 31;
+ const bool noSpaceForInt64 = value >> 63;
+ if (suffix == "") {
+ if (noSpaceForInt64) {
+ return new TLiteralNumberNode<ui64>(ctx.Pos(), "Uint64", ToString(value));
+ } else if (noSpaceForInt32) {
+ return new TLiteralNumberNode<i64>(ctx.Pos(), "Int64", ToString(value));
+ }
+ return new TLiteralNumberNode<i32>(ctx.Pos(), "Int32", ToString(value));
+ } else if (suffix == "u") {
+ return new TLiteralNumberNode<ui32>(ctx.Pos(), "Uint32", ToString(value));
+ } else if (suffix == "ul") {
+ return new TLiteralNumberNode<ui64>(ctx.Pos(), "Uint64", ToString(value));
} else if (suffix == "ut" || suffix == "ub") {
return new TLiteralNumberNode<ui8>(ctx.Pos(), "Uint8", ToString(value));
} else if (suffix == "t" || suffix == "b") {
return new TLiteralNumberNode<i8>(ctx.Pos(), "Int8", ToString(value));
- } else if (suffix == "l") {
- return new TLiteralNumberNode<i64>(ctx.Pos(), "Int64", ToString(value));
+ } else if (suffix == "l") {
+ return new TLiteralNumberNode<i64>(ctx.Pos(), "Int64", ToString(value));
} else if (suffix == "us") {
return new TLiteralNumberNode<ui16>(ctx.Pos(), "Uint16", ToString(value));
} else if (suffix == "s") {
return new TLiteralNumberNode<i16>(ctx.Pos(), "Int16", ToString(value));
- } else {
- ctx.Error(ctx.Pos()) << "Failed to parse number from string: " << intergerString << ", invalid suffix: " << suffix;
- return {};
- }
-}
-
-TNodePtr LiteralReal(TContext& ctx, const TRule_real& node) {
+ } else {
+ ctx.Error(ctx.Pos()) << "Failed to parse number from string: " << intergerString << ", invalid suffix: " << suffix;
+ return {};
+ }
+}
+
+TNodePtr LiteralReal(TContext& ctx, const TRule_real& node) {
const TString value(ctx.Token(node.GetToken1()));
- YQL_ENSURE(!value.empty());
+ YQL_ENSURE(!value.empty());
const auto lastValue = value[value.size() - 1];
- if (lastValue == 'f' || lastValue == 'F') {
+ if (lastValue == 'f' || lastValue == 'F') {
return new TLiteralNumberNode<float>(ctx.Pos(), "Float", value.substr(0, value.size()-1));
- } else {
- return new TLiteralNumberNode<double>(ctx.Pos(), "Double", value);
- }
-}
-
-TNodePtr Literal(TContext& ctx, const TRule_unsigned_number& rule) {
- switch (rule.Alt_case()) {
- case TRule_unsigned_number::kAltUnsignedNumber1:
- return LiteralNumber(ctx, rule.GetAlt_unsigned_number1().GetRule_integer1());
- case TRule_unsigned_number::kAltUnsignedNumber2:
- return LiteralReal(ctx, rule.GetAlt_unsigned_number2().GetRule_real1());
- default:
- Y_FAIL("Unsigned number: you should change implementation according grammar changes");
- }
-}
-
+ } else {
+ return new TLiteralNumberNode<double>(ctx.Pos(), "Double", value);
+ }
+}
+
+TNodePtr Literal(TContext& ctx, const TRule_unsigned_number& rule) {
+ switch (rule.Alt_case()) {
+ case TRule_unsigned_number::kAltUnsignedNumber1:
+ return LiteralNumber(ctx, rule.GetAlt_unsigned_number1().GetRule_integer1());
+ case TRule_unsigned_number::kAltUnsignedNumber2:
+ return LiteralReal(ctx, rule.GetAlt_unsigned_number2().GetRule_real1());
+ default:
+ Y_FAIL("Unsigned number: you should change implementation according grammar changes");
+ }
+}
+
TNodePtr TSqlExpression::LiteralExpr(const TRule_literal_value& node) {
switch (node.Alt_case()) {
case TRule_literal_value::kAltLiteralValue1: {
- return LiteralNumber(Ctx, node.GetAlt_literal_value1().GetRule_integer1());
+ return LiteralNumber(Ctx, node.GetAlt_literal_value1().GetRule_integer1());
}
case TRule_literal_value::kAltLiteralValue2: {
- return LiteralReal(Ctx, node.GetAlt_literal_value2().GetRule_real1());
+ return LiteralReal(Ctx, node.GetAlt_literal_value2().GetRule_real1());
}
case TRule_literal_value::kAltLiteralValue3: {
const TString value(Token(node.GetAlt_literal_value3().GetToken1()));
@@ -1384,8 +1384,8 @@ TNodePtr TSqlExpression::UnaryExpr(const TUnarySubExprType& node) {
Y_FAIL("You should change implementation according grammar changes");
}
bool isLookup = false;
- for (auto& b: node.GetBlock2()) {
- auto expr = KeyExpr(b.GetRule_key_expr1());
+ for (auto& b: node.GetBlock2()) {
+ auto expr = KeyExpr(b.GetRule_key_expr1());
if (!expr) {
Ctx.IncrementMonCounter("sql_errors", "BadKeyExpr");
return nullptr;
@@ -1394,8 +1394,8 @@ TNodePtr TSqlExpression::UnaryExpr(const TUnarySubExprType& node) {
isLookup = true;
}
TPosition pos(Ctx.Pos());
- for (auto& dotBlock: node.GetBlock3()) {
- auto bb = dotBlock.GetBlock2();
+ for (auto& dotBlock: node.GetBlock3()) {
+ auto bb = dotBlock.GetBlock2();
switch (bb.Alt_case()) {
case TUnarySubExprType::TBlock3::TBlock2::kAlt1: {
auto named = NamedNodeImpl(bb.GetAlt1().GetRule_bind_parameter1(), *this);
@@ -1426,10 +1426,10 @@ TNodePtr TSqlExpression::UnaryExpr(const TUnarySubExprType& node) {
default:
Y_FAIL("You should change implementation according grammar changes");
}
- for (auto& b: dotBlock.GetBlock3()) {
- auto expr = KeyExpr(b.GetRule_key_expr1());
+ for (auto& b: dotBlock.GetBlock3()) {
+ auto expr = KeyExpr(b.GetRule_key_expr1());
if (!expr) {
- Ctx.IncrementMonCounter("sql_errors", "BadKeyExpr");
+ Ctx.IncrementMonCounter("sql_errors", "BadKeyExpr");
return nullptr;
}
ids.push_back(expr);
@@ -1568,8 +1568,8 @@ TNodePtr TSqlExpression::WindowFunctionRule(const TWindowFunctionType& rule) {
// window_function: call_expr (null_treatment? OVER window_name_or_specification)?;
// OR
// in_window_function: in_call_expr (null_treatment? OVER window_name_or_specification)?;
- const bool overWindow = rule.HasBlock2();
- TSqlCallExpr call(Ctx, Mode, this);
+ const bool overWindow = rule.HasBlock2();
+ TSqlCallExpr call(Ctx, Mode, this);
bool initResult;
if constexpr (std::is_same_v<TWindowFunctionType, TRule_window_function>) {
@@ -1578,28 +1578,28 @@ TNodePtr TSqlExpression::WindowFunctionRule(const TWindowFunctionType& rule) {
initResult = call.Init(rule.GetRule_in_call_expr1());
}
if (!initResult) {
- return {};
- }
-
- call.IncCounters();
- if (!overWindow) {
- return call.BuildCall();
- }
- auto funcSpec = rule.GetBlock2();
- call.SetOverWindow();
- auto winRule = funcSpec.GetRule_window_name_or_specification3();
- if (winRule.Alt_case() != TRule_window_name_or_specification::kAltWindowNameOrSpecification1) {
- Error() << "Inline window specification is not supported yet! You can define window function in WINDOW clause.";
- return {};
- }
- if (funcSpec.HasBlock1() && funcSpec.GetBlock1().GetRule_null_treatment1().Alt_case() == TRule_null_treatment::kAltNullTreatment2) {
- call.SetIgnoreNulls();
- }
+ return {};
+ }
+
+ call.IncCounters();
+ if (!overWindow) {
+ return call.BuildCall();
+ }
+ auto funcSpec = rule.GetBlock2();
+ call.SetOverWindow();
+ auto winRule = funcSpec.GetRule_window_name_or_specification3();
+ if (winRule.Alt_case() != TRule_window_name_or_specification::kAltWindowNameOrSpecification1) {
+ Error() << "Inline window specification is not supported yet! You can define window function in WINDOW clause.";
+ return {};
+ }
+ if (funcSpec.HasBlock1() && funcSpec.GetBlock1().GetRule_null_treatment1().Alt_case() == TRule_null_treatment::kAltNullTreatment2) {
+ call.SetIgnoreNulls();
+ }
const TString windowName = Id(winRule.GetAlt_window_name_or_specification1().GetRule_window_name1().GetRule_id1(), *this);
- Ctx.IncrementMonCounter("sql_features", "WindowFunctionOver");
- return BuildCalcOverWindow(Ctx.Pos(), windowName, call.BuildCall());
-}
-
+ Ctx.IncrementMonCounter("sql_features", "WindowFunctionOver");
+ return BuildCalcOverWindow(Ctx.Pos(), windowName, call.BuildCall());
+}
+
TNodePtr TSqlExpression::AtomExpr(const TRule_atom_expr& node) {
// atom_expr:
// literal_value
@@ -1618,8 +1618,8 @@ TNodePtr TSqlExpression::AtomExpr(const TRule_atom_expr& node) {
return LiteralExpr(node.GetAlt_atom_expr1().GetRule_literal_value1());
case TRule_atom_expr::kAltAtomExpr2:
return BindParameterRule(node.GetAlt_atom_expr2().GetRule_bind_parameter1());
- case TRule_atom_expr::kAltAtomExpr3:
- return WindowFunctionRule(node.GetAlt_atom_expr3().GetRule_window_function1());
+ case TRule_atom_expr::kAltAtomExpr3:
+ return WindowFunctionRule(node.GetAlt_atom_expr3().GetRule_window_function1());
case TRule_atom_expr::kAltAtomExpr4:
return LambdaRule(node.GetAlt_atom_expr4().GetRule_lambda1());
case TRule_atom_expr::kAltAtomExpr5:
@@ -1690,46 +1690,46 @@ TNodePtr TSqlExpression::InAtomExpr(const TRule_in_atom_expr& node) {
}
bool TSqlExpression::SqlLambdaParams(const TNodePtr& node, TVector<TString>& args) {
- auto errMsg = TStringBuf("Invalid lambda arguments syntax. Lambda arguments should starts with '$' as named value.");
- auto tupleNodePtr = dynamic_cast<TTupleNode*>(node.Get());
- if (!tupleNodePtr) {
- Ctx.Error(node->GetPos()) << errMsg;
- return false;
- }
+ auto errMsg = TStringBuf("Invalid lambda arguments syntax. Lambda arguments should starts with '$' as named value.");
+ auto tupleNodePtr = dynamic_cast<TTupleNode*>(node.Get());
+ if (!tupleNodePtr) {
+ Ctx.Error(node->GetPos()) << errMsg;
+ return false;
+ }
THashSet<TString> dupArgsChecker;
- for (const auto& argPtr: tupleNodePtr->Elements()) {
- auto contentPtr = argPtr->GetAtomContent();
- if (!contentPtr || !contentPtr->StartsWith("$")) {
- Ctx.Error(argPtr->GetPos()) << errMsg;
- return false;
- }
- if (!dupArgsChecker.insert(*contentPtr).second) {
- Ctx.Error(argPtr->GetPos()) << "Duplicate lambda argument parametr: '" << *contentPtr << "'.";
- return false;
- }
- args.push_back(*contentPtr);
- }
- return true;
-}
-
+ for (const auto& argPtr: tupleNodePtr->Elements()) {
+ auto contentPtr = argPtr->GetAtomContent();
+ if (!contentPtr || !contentPtr->StartsWith("$")) {
+ Ctx.Error(argPtr->GetPos()) << errMsg;
+ return false;
+ }
+ if (!dupArgsChecker.insert(*contentPtr).second) {
+ Ctx.Error(argPtr->GetPos()) << "Duplicate lambda argument parametr: '" << *contentPtr << "'.";
+ return false;
+ }
+ args.push_back(*contentPtr);
+ }
+ return true;
+}
+
bool TSqlExpression::SqlLambdaExprBody(TContext& ctx, const TRule_lambda_body& node, TVector<TNodePtr>& exprSeq) {
- TSqlExpression expr(ctx, ctx.Settings.Mode);
+ TSqlExpression expr(ctx, ctx.Settings.Mode);
TVector<TString> localNames;
bool hasError = false;
- for (auto& block: node.GetBlock1()) {
- const auto& rule = block.GetRule_lambda_stmt1();
- switch (rule.Alt_case()) {
- case TRule_lambda_stmt::kAltLambdaStmt1: {
+ for (auto& block: node.GetBlock1()) {
+ const auto& rule = block.GetRule_lambda_stmt1();
+ switch (rule.Alt_case()) {
+ case TRule_lambda_stmt::kAltLambdaStmt1: {
TVector<TString> names;
auto nodeExpr = NamedNode(rule.GetAlt_lambda_stmt1().GetRule_named_nodes_stmt1(), names);
- if (!nodeExpr) {
+ if (!nodeExpr) {
hasError = true;
continue;
- } else if (nodeExpr->GetSource()) {
- ctx.Error() << "SELECT is not supported inside lambda body";
+ } else if (nodeExpr->GetSource()) {
+ ctx.Error() << "SELECT is not supported inside lambda body";
hasError = true;
continue;
- }
+ }
if (names.size() > 1) {
auto ref = ctx.MakeName("tie");
@@ -1748,18 +1748,18 @@ bool TSqlExpression::SqlLambdaExprBody(TContext& ctx, const TRule_lambda_body& n
PushNamedNode(names.front(), BuildAtom(nodeExpr->GetPos(), names.front(), NYql::TNodeFlags::Default));
exprSeq.push_back(nodeExpr);
}
- break;
- }
- case TRule_lambda_stmt::kAltLambdaStmt2: {
- if (!ImportStatement(rule.GetAlt_lambda_stmt2().GetRule_import_stmt1(), &localNames)) {
+ break;
+ }
+ case TRule_lambda_stmt::kAltLambdaStmt2: {
+ if (!ImportStatement(rule.GetAlt_lambda_stmt2().GetRule_import_stmt1(), &localNames)) {
hasError = true;
- }
- break;
- }
- default:
+ }
+ break;
+ }
+ default:
Y_FAIL("SampleClause: does not correspond to grammar changes");
- }
- }
+ }
+ }
TNodePtr nodeExpr;
if (!hasError) {
@@ -1770,13 +1770,13 @@ bool TSqlExpression::SqlLambdaExprBody(TContext& ctx, const TRule_lambda_body& n
PopNamedNode(name);
}
- if (!nodeExpr) {
- return false;
- }
- exprSeq.push_back(nodeExpr);
- return true;
-}
-
+ if (!nodeExpr) {
+ return false;
+ }
+ exprSeq.push_back(nodeExpr);
+ return true;
+}
+
TNodePtr TSqlExpression::SubExpr(const TRule_con_subexpr& node) {
// con_subexpr: unary_subexpr | unary_op unary_subexpr;
switch (node.Alt_case()) {
@@ -1810,9 +1810,9 @@ TNodePtr TSqlExpression::SubExpr(const TRule_con_subexpr& node) {
TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node) {
// xor_subexpr: eq_subexpr cond_expr?;
TNodePtr res(SubExpr(node.GetRule_eq_subexpr1()));
- if (!res) {
- return {};
- }
+ if (!res) {
+ return {};
+ }
TPosition pos(Ctx.Pos());
if (node.HasBlock2()) {
auto cond = node.GetBlock2().GetRule_cond_expr1();
@@ -1822,9 +1822,9 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node) {
const bool notMatch = matchOp.HasBlock1();
const TCiString& opName = Token(matchOp.GetRule_match_op2().GetToken1());
const auto& pattern = SubExpr(cond.GetAlt_cond_expr1().GetRule_eq_subexpr3());
- if (!pattern) {
- return {};
- }
+ if (!pattern) {
+ return {};
+ }
TNodePtr isMatch;
if (opName == "like" || opName == "ilike") {
const TString* escapeLiteral = nullptr;
@@ -1834,10 +1834,10 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node) {
if (matchOp.HasBlock4()) {
const auto& escapeBlock = matchOp.GetBlock4();
- TNodePtr escapeExpr = SubExpr(escapeBlock.GetRule_eq_subexpr2());
- if (!escapeExpr) {
- return {};
- }
+ TNodePtr escapeExpr = SubExpr(escapeBlock.GetRule_eq_subexpr2());
+ if (!escapeExpr) {
+ return {};
+ }
escapeLiteral = escapeExpr->GetLiteral("String");
escapeNode = escapeExpr;
if (escapeLiteral) {
@@ -1853,7 +1853,7 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node) {
Error() << "please choose any other character";
return nullptr;
}
- escaperArgs.push_back(BuildLiteralRawString(pos, *escapeLiteral));
+ escaperArgs.push_back(BuildLiteralRawString(pos, *escapeLiteral));
} else {
Ctx.IncrementMonCounter("sql_errors", "LikeNotLiteralEscape");
Error() << "ESCAPE clause requires String literal argument";
@@ -1874,12 +1874,12 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node) {
auto csOption = BuildStructure(pos, { csModeLiteral });
auto optionsApply = new TCallNodeImpl(pos, "NamedApply", { re2options, BuildTuple(pos, {}), csOption });
- const TNodePtr escapedPattern = new TCallNodeImpl(pos, "Apply", { escaperArgs });
+ const TNodePtr escapedPattern = new TCallNodeImpl(pos, "Apply", { escaperArgs });
auto list = new TAstListNodeImpl(pos, { escapedPattern, optionsApply });
auto runConfig = new TAstListNodeImpl(pos, { new TAstAtomNodeImpl(pos, "quote", 0), list });
const auto& matcher = BuildUdf(Ctx, pos, "Re2", "Match", { runConfig });
- isMatch = new TCallNodeImpl(pos, "Apply", { matcher, res });
+ isMatch = new TCallNodeImpl(pos, "Apply", { matcher, res });
const TString* literalPattern = pattern->GetLiteral("String");
if (literalPattern) {
@@ -1967,7 +1967,7 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node) {
}
const auto& matcher = BuildUdf(Ctx, pos, "Pcre", opName == "match" ? "BacktrackingMatch" : "BacktrackingGrep", { pattern });
- isMatch = new TCallNodeImpl(pos, "Apply", { matcher, res });
+ isMatch = new TCallNodeImpl(pos, "Apply", { matcher, res });
if (opName != "match") {
Ctx.IncrementMonCounter("sql_features", notMatch ? "NotRegexp" : "Regexp");
} else {
@@ -1981,15 +1981,15 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node) {
return notMatch ? BuildUnaryOp(pos, "Not", isMatch) : isMatch;
}
case TRule_cond_expr::kAltCondExpr2: {
- auto altInExpr = cond.GetAlt_cond_expr2();
- const bool notIn = altInExpr.HasBlock1();
+ auto altInExpr = cond.GetAlt_cond_expr2();
+ const bool notIn = altInExpr.HasBlock1();
auto hints = BuildTuple(pos, {});
if (altInExpr.HasBlock3()) {
Ctx.IncrementMonCounter("sql_features", "IsCompactHint");
auto sizeHint = BuildTuple(pos, { BuildQuotedAtom(pos, "isCompact", NYql::TNodeFlags::Default) });
hints = BuildTuple(pos, { sizeHint });
}
- TSqlExpression inSubexpr(Ctx, Mode);
+ TSqlExpression inSubexpr(Ctx, Mode);
auto inRight = inSubexpr.SqlInExpr(altInExpr.GetRule_in_expr4());
auto isIn = BuildBuiltinFunc(Ctx, pos, "In", {res, inRight, hints});
Ctx.IncrementMonCounter("sql_features", notIn ? "NotIn" : "In");
@@ -2047,36 +2047,36 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node) {
}
TNodePtr TSqlExpression::BinOperList(const TString& opName, TVector<TNodePtr>::const_iterator begin, TVector<TNodePtr>::const_iterator end) const {
- TPosition pos(Ctx.Pos());
- const size_t opCount = end - begin;
- Y_VERIFY_DEBUG(opCount >= 2);
- if (opCount == 2) {
- return BuildBinaryOp(pos, opName, *begin, *(begin+1));
- } if (opCount == 3) {
- return BuildBinaryOp(pos, opName, BuildBinaryOp(pos, opName, *begin, *(begin+1)), *(begin+2));
- } else {
- auto mid = begin + opCount / 2;
- return BuildBinaryOp(pos, opName, BinOperList(opName, begin, mid), BinOperList(opName, mid, end));
- }
-}
-
+ TPosition pos(Ctx.Pos());
+ const size_t opCount = end - begin;
+ Y_VERIFY_DEBUG(opCount >= 2);
+ if (opCount == 2) {
+ return BuildBinaryOp(pos, opName, *begin, *(begin+1));
+ } if (opCount == 3) {
+ return BuildBinaryOp(pos, opName, BuildBinaryOp(pos, opName, *begin, *(begin+1)), *(begin+2));
+ } else {
+ auto mid = begin + opCount / 2;
+ return BuildBinaryOp(pos, opName, BinOperList(opName, begin, mid), BinOperList(opName, mid, end));
+ }
+}
+
template <typename TNode, typename TGetNode, typename TIter>
TNodePtr TSqlExpression::BinOper(const TString& opName, const TNode& node, TGetNode getNode, TIter begin, TIter end) {
- if (begin == end) {
- return SubExpr(node);
- }
- Ctx.IncrementMonCounter("sql_binary_operations", opName);
- const size_t listSize = end - begin;
+ if (begin == end) {
+ return SubExpr(node);
+ }
+ Ctx.IncrementMonCounter("sql_binary_operations", opName);
+ const size_t listSize = end - begin;
TVector<TNodePtr> nodes;
- nodes.reserve(1 + listSize);
- nodes.push_back(SubExpr(node));
- for (; begin != end; ++begin) {
- nodes.push_back(SubExpr(getNode(*begin)));
- }
- return BinOperList(opName, nodes.begin(), nodes.end());
-}
-
-template <typename TNode, typename TGetNode, typename TIter>
+ nodes.reserve(1 + listSize);
+ nodes.push_back(SubExpr(node));
+ for (; begin != end; ++begin) {
+ nodes.push_back(SubExpr(getNode(*begin)));
+ }
+ return BinOperList(opName, nodes.begin(), nodes.end());
+}
+
+template <typename TNode, typename TGetNode, typename TIter>
TNodePtr TSqlExpression::BinOpList(const TNode& node, TGetNode getNode, TIter begin, TIter end) {
TNodePtr partialResult = SubExpr(node);
while (begin != end) {
@@ -2180,115 +2180,115 @@ TNodePtr TSqlExpression::BinOpList(const TNode& node, TGetNode getNode, TIter be
return partialResult;
}
-TNodePtr TSqlExpression::SqlInExpr(const TRule_in_expr& node) {
- TSqlExpression expr(Ctx, Mode);
- expr.SetSmartParenthesisMode(TSqlExpression::ESmartParenthesis::InStatement);
+TNodePtr TSqlExpression::SqlInExpr(const TRule_in_expr& node) {
+ TSqlExpression expr(Ctx, Mode);
+ expr.SetSmartParenthesisMode(TSqlExpression::ESmartParenthesis::InStatement);
auto result = expr.WrapExprShortcuts(expr.UnaryExpr(node.GetRule_in_unary_subexpr1()));
- return result;
-}
-
-TNodePtr TSqlExpression::SmartParenthesis(const TRule_smart_parenthesis& node) {
+ return result;
+}
+
+TNodePtr TSqlExpression::SmartParenthesis(const TRule_smart_parenthesis& node) {
TVector<TNodePtr> exprs;
- Token(node.GetToken1());
- const TPosition pos(Ctx.Pos());
- const bool isTuple = node.HasBlock3();
- bool expectTuple = SmartParenthesisMode == ESmartParenthesis::InStatement;
- EExpr mode = EExpr::Regular;
- if (SmartParenthesisMode == ESmartParenthesis::GroupBy) {
- mode = EExpr::GroupBy;
- } else if (SmartParenthesisMode == ESmartParenthesis::SqlLambdaParams) {
- mode = EExpr::SqlLambdaParams;
- expectTuple = true;
- }
- if (node.HasBlock2() && !NamedExprList(node.GetBlock2().GetRule_named_expr_list1(), exprs, mode)) {
- return {};
- }
-
- bool hasAliases = false;
- bool hasUnnamed = false;
+ Token(node.GetToken1());
+ const TPosition pos(Ctx.Pos());
+ const bool isTuple = node.HasBlock3();
+ bool expectTuple = SmartParenthesisMode == ESmartParenthesis::InStatement;
+ EExpr mode = EExpr::Regular;
+ if (SmartParenthesisMode == ESmartParenthesis::GroupBy) {
+ mode = EExpr::GroupBy;
+ } else if (SmartParenthesisMode == ESmartParenthesis::SqlLambdaParams) {
+ mode = EExpr::SqlLambdaParams;
+ expectTuple = true;
+ }
+ if (node.HasBlock2() && !NamedExprList(node.GetBlock2().GetRule_named_expr_list1(), exprs, mode)) {
+ return {};
+ }
+
+ bool hasAliases = false;
+ bool hasUnnamed = false;
for (const auto& expr: exprs) {
- if (expr->GetLabel()) {
- hasAliases = true;
- } else {
- hasUnnamed = true;
- }
- if (hasAliases && hasUnnamed && SmartParenthesisMode != ESmartParenthesis::GroupBy) {
- Ctx.IncrementMonCounter("sql_errors", "AnonymousStructMembers");
- Ctx.Error(pos) << "Structure does not allow anonymous members";
- return nullptr;
- }
- }
- if (exprs.size() == 1 && hasUnnamed && !isTuple && !expectTuple) {
- return exprs.back();
- }
- if (SmartParenthesisMode == ESmartParenthesis::GroupBy) {
- /// \todo support nested tuple\struct
- if (isTuple) {
- Ctx.IncrementMonCounter("sql_errors", "SimpleTupleInGroupBy");
- Ctx.Error(pos) << "Unable to use tuple in group by clause";
- return nullptr;
- }
- Ctx.IncrementMonCounter("sql_features", "ListOfNamedNode");
- return BuildListOfNamedNodes(pos, std::move(exprs));
- }
- Ctx.IncrementMonCounter("sql_features", hasUnnamed ? "SimpleTuple" : "SimpleStruct");
- return hasUnnamed || expectTuple ? BuildTuple(pos, exprs) : BuildStructure(pos, exprs);
-}
-
+ if (expr->GetLabel()) {
+ hasAliases = true;
+ } else {
+ hasUnnamed = true;
+ }
+ if (hasAliases && hasUnnamed && SmartParenthesisMode != ESmartParenthesis::GroupBy) {
+ Ctx.IncrementMonCounter("sql_errors", "AnonymousStructMembers");
+ Ctx.Error(pos) << "Structure does not allow anonymous members";
+ return nullptr;
+ }
+ }
+ if (exprs.size() == 1 && hasUnnamed && !isTuple && !expectTuple) {
+ return exprs.back();
+ }
+ if (SmartParenthesisMode == ESmartParenthesis::GroupBy) {
+ /// \todo support nested tuple\struct
+ if (isTuple) {
+ Ctx.IncrementMonCounter("sql_errors", "SimpleTupleInGroupBy");
+ Ctx.Error(pos) << "Unable to use tuple in group by clause";
+ return nullptr;
+ }
+ Ctx.IncrementMonCounter("sql_features", "ListOfNamedNode");
+ return BuildListOfNamedNodes(pos, std::move(exprs));
+ }
+ Ctx.IncrementMonCounter("sql_features", hasUnnamed ? "SimpleTuple" : "SimpleStruct");
+ return hasUnnamed || expectTuple ? BuildTuple(pos, exprs) : BuildStructure(pos, exprs);
+}
+
TNodePtr TSqlTranslation::NamedNode(const TRule_named_nodes_stmt& rule, TVector<TString>& names) {
// named_nodes_stmt: bind_parameter_list EQUALS (expr | LPAREN select_stmt RPAREN);
BindList(rule.GetRule_bind_parameter_list1(), names);
- TNodePtr nodeExpr = nullptr;
+ TNodePtr nodeExpr = nullptr;
switch (rule.GetBlock3().Alt_case()) {
case TRule_named_nodes_stmt::TBlock3::kAlt1: {
- TSqlExpression expr(Ctx, Mode);
- return expr.Build(rule.GetBlock3().GetAlt1().GetRule_expr1());
+ TSqlExpression expr(Ctx, Mode);
+ return expr.Build(rule.GetBlock3().GetAlt1().GetRule_expr1());
}
case TRule_named_nodes_stmt::TBlock3::kAlt2: {
- TSqlSelect expr(Ctx, Mode);
+ TSqlSelect expr(Ctx, Mode);
TPosition pos;
auto source = expr.Build(rule.GetBlock3().GetAlt2().GetRule_select_stmt2(), pos);
- if (!source) {
- return {};
- }
+ if (!source) {
+ return {};
+ }
return BuildSourceNode(pos, std::move(source));
- }
+ }
default:
AltNotImplemented("named_node", rule.GetBlock3());
Ctx.IncrementMonCounter("sql_errors", "UnknownNamedNode");
return nullptr;
}
-}
-
+}
+
bool TSqlTranslation::ImportStatement(const TRule_import_stmt& stmt, TVector<TString>* namesPtr) {
TVector<TString> modulePath;
- if (!ModulePath(stmt.GetRule_module_path2(), modulePath)) {
- return false;
- }
+ if (!ModulePath(stmt.GetRule_module_path2(), modulePath)) {
+ return false;
+ }
TVector<TNodePtr> bindNames;
- if (!NamedBindList(stmt.GetRule_named_bind_parameter_list4(), bindNames)) {
- return false;
- }
- const TString moduleAlias = Ctx.AddImport(std::move(modulePath));
- if (!moduleAlias) {
- return false;
- }
- for (const TNodePtr& name: bindNames) {
- const TString* contentPtr = name->GetAtomContent();
- YQL_ENSURE(contentPtr);
- const TString& nameAlias = name->GetLabel();
- const auto varName = nameAlias ? nameAlias : *contentPtr;
- PushNamedNode(varName, name->Y("bind", moduleAlias, name->Q(*contentPtr)));
- if (namesPtr) {
- namesPtr->push_back(varName);
- }
- }
- return true;
-}
-
+ if (!NamedBindList(stmt.GetRule_named_bind_parameter_list4(), bindNames)) {
+ return false;
+ }
+ const TString moduleAlias = Ctx.AddImport(std::move(modulePath));
+ if (!moduleAlias) {
+ return false;
+ }
+ for (const TNodePtr& name: bindNames) {
+ const TString* contentPtr = name->GetAtomContent();
+ YQL_ENSURE(contentPtr);
+ const TString& nameAlias = name->GetLabel();
+ const auto varName = nameAlias ? nameAlias : *contentPtr;
+ PushNamedNode(varName, name->Y("bind", moduleAlias, name->Q(*contentPtr)));
+ if (namesPtr) {
+ namesPtr->push_back(varName);
+ }
+ }
+ return true;
+}
+
TNodePtr TSqlTranslation::DoStatement(const TRule_do_stmt& stmt, bool makeLambda, const TVector<TString>& args) {
TNodePtr action;
switch (stmt.GetBlock2().GetAltCase()) {
@@ -2308,7 +2308,7 @@ TNodePtr TSqlTranslation::DoStatement(const TRule_do_stmt& stmt, bool makeLambda
AltNotImplemented("do_stmt", stmt.GetBlock2());
return nullptr;
}
-
+
TVector<TNodePtr> values;
values.push_back(new TAstAtomNodeImpl(Ctx.Pos(), "Apply", TNodeFlags::Default));
values.push_back(action);
@@ -2463,31 +2463,31 @@ TNodePtr TSqlSelect::JoinExpr(ISource* join, const TRule_join_constraint& node)
TVector<TNodePtr> TSqlSelect::OrdinaryNamedColumnList(const TRule_ordinary_named_column_list& node) {
TVector<TNodePtr> result;
- switch (node.Alt_case()) {
- case TRule_ordinary_named_column_list::kAltOrdinaryNamedColumnList1:
- if (!NamedColumn(result, node.GetAlt_ordinary_named_column_list1().GetRule_named_column1())) {
- return {};
- }
- break;
- case TRule_ordinary_named_column_list::kAltOrdinaryNamedColumnList2:
- if (!NamedColumnList(result, node.GetAlt_ordinary_named_column_list2().GetRule_named_column_list2())) {
- return {};
- }
- break;
- default:
- Ctx.IncrementMonCounter("sql_errors", "UnknownOrdinaryNamedColumn");
- AltNotImplemented("ordinary_named_column_list", node);
- }
- return result;
-}
-
-TSourcePtr TSqlSelect::FlattenSource(const TRule_flatten_source& node) {
- auto source = NamedSingleSource(node.GetRule_named_single_source1());
- if (!source) {
- return nullptr;
- }
- if (node.HasBlock2()) {
- auto flatten = node.GetBlock2();
+ switch (node.Alt_case()) {
+ case TRule_ordinary_named_column_list::kAltOrdinaryNamedColumnList1:
+ if (!NamedColumn(result, node.GetAlt_ordinary_named_column_list1().GetRule_named_column1())) {
+ return {};
+ }
+ break;
+ case TRule_ordinary_named_column_list::kAltOrdinaryNamedColumnList2:
+ if (!NamedColumnList(result, node.GetAlt_ordinary_named_column_list2().GetRule_named_column_list2())) {
+ return {};
+ }
+ break;
+ default:
+ Ctx.IncrementMonCounter("sql_errors", "UnknownOrdinaryNamedColumn");
+ AltNotImplemented("ordinary_named_column_list", node);
+ }
+ return result;
+}
+
+TSourcePtr TSqlSelect::FlattenSource(const TRule_flatten_source& node) {
+ auto source = NamedSingleSource(node.GetRule_named_single_source1());
+ if (!source) {
+ return nullptr;
+ }
+ if (node.HasBlock2()) {
+ auto flatten = node.GetBlock2();
auto flatten2 = flatten.GetBlock2();
switch (flatten2.Alt_case()) {
case TRule_flatten_source::TBlock2::TBlock2::kAlt1: {
@@ -2508,38 +2508,38 @@ TSourcePtr TSqlSelect::FlattenSource(const TRule_flatten_source& node) {
source->SetFlattenByMode(mode);
break;
- }
+ }
case TRule_flatten_source::TBlock2::TBlock2::kAlt2: {
Ctx.IncrementMonCounter("sql_features", "FlattenColumns");
source->MarkFlattenColumns();
break;
- }
+ }
default:
Ctx.IncrementMonCounter("sql_errors", "UnknownOrdinaryNamedColumn");
AltNotImplemented("flatten_source", flatten2);
}
- }
- return source;
-}
-
+ }
+ return source;
+}
+
TSourcePtr TSqlSelect::JoinSource(const TRule_join_source& node) {
- TSourcePtr source(FlattenSource(node.GetRule_flatten_source1()));
+ TSourcePtr source(FlattenSource(node.GetRule_flatten_source1()));
if (!source) {
return nullptr;
}
if (node.Block2Size()) {
TPosition pos(Ctx.Pos());
TVector<TSourcePtr> sources;
- sources.emplace_back(std::move(source));
+ sources.emplace_back(std::move(source));
for (auto& block: node.GetBlock2()) {
- sources.emplace_back(FlattenSource(block.GetRule_flatten_source2()));
+ sources.emplace_back(FlattenSource(block.GetRule_flatten_source2()));
if (!sources.back()) {
Ctx.IncrementMonCounter("sql_errors", "NoJoinWith");
return nullptr;
}
}
- source = BuildEquiJoin(pos, std::move(sources));
+ source = BuildEquiJoin(pos, std::move(sources));
for (auto& block: node.GetBlock2()) {
if (!JoinOp(source.Get(), block)) {
Ctx.IncrementMonCounter("sql_errors", "NoJoinOp");
@@ -2556,15 +2556,15 @@ bool TSqlSelect::SelectTerm(TVector<TNodePtr>& terms, const TRule_result_column&
// | expr (AS id_or_string)?
// ;
switch (node.Alt_case()) {
- case TRule_result_column::kAltResultColumn1: {
- auto alt = node.GetAlt_result_column1();
-
- Token(alt.GetToken2());
- auto idAsteriskQualify = OptIdPrefixAsStr(alt.GetRule_opt_id_prefix1(), *this);
- Ctx.IncrementMonCounter("sql_features", idAsteriskQualify ? "QualifyAsterisk" : "Asterisk");
- terms.push_back(BuildColumn(Ctx.Pos(), "*", idAsteriskQualify));
+ case TRule_result_column::kAltResultColumn1: {
+ auto alt = node.GetAlt_result_column1();
+
+ Token(alt.GetToken2());
+ auto idAsteriskQualify = OptIdPrefixAsStr(alt.GetRule_opt_id_prefix1(), *this);
+ Ctx.IncrementMonCounter("sql_features", idAsteriskQualify ? "QualifyAsterisk" : "Asterisk");
+ terms.push_back(BuildColumn(Ctx.Pos(), "*", idAsteriskQualify));
break;
- }
+ }
case TRule_result_column::kAltResultColumn2: {
auto alt = node.GetAlt_result_column2();
TSqlExpression expr(Ctx, Mode);
@@ -2574,7 +2574,7 @@ bool TSqlSelect::SelectTerm(TVector<TNodePtr>& terms, const TRule_result_column&
return false;
}
if (alt.HasBlock2()) {
- term->SetLabel(IdOrString(alt.GetBlock2().GetRule_id_or_string2(), *this));
+ term->SetLabel(IdOrString(alt.GetBlock2().GetRule_id_or_string2(), *this));
}
terms.push_back(term);
break;
@@ -2590,42 +2590,42 @@ bool TSqlSelect::SelectTerm(TVector<TNodePtr>& terms, const TRule_result_column&
bool TSqlSelect::ValidateSelectColumns(const TVector<TNodePtr>& terms) {
TSet<TString> labels;
TSet<TString> asteriskSources;
- for (const auto& term: terms) {
- const auto& label = term->GetLabel();
+ for (const auto& term: terms) {
+ const auto& label = term->GetLabel();
if (!Ctx.PragmaAllowDotInAlias && label.find('.') != TString::npos) {
- Ctx.Error(term->GetPos()) << "Unable to use '.' in column name. Invalid column name: " << label;
- return false;
- }
- if (!label.empty()) {
- if (!labels.insert(label).second) {
- Ctx.Error(term->GetPos()) << "Unable to use duplicate column names. Collision in name: " << label;
- return false;
- }
- }
- if (term->IsAsterisk()) {
- const auto& source = *term->GetSourceName();
- if (source.empty() && terms.ysize() > 1) {
- Ctx.Error(term->GetPos()) << "Unable to use general '*' with other columns, either specify concrete table like '<table>.*', either specify concrete columns.";
- return false;
- } else if (!asteriskSources.insert(source).second) {
- Ctx.Error(term->GetPos()) << "Unable to use twice same quialified asterisk. Invalid source: " << source;
- return false;
- }
- } else if (label.empty()) {
- const auto* column = term->GetColumnName();
- if (column && !column->empty()) {
- const auto& source = *term->GetSourceName();
- const auto usedName = source.empty() ? *column : source + '.' + *column;
- if (!labels.insert(usedName).second) {
- Ctx.Error(term->GetPos()) << "Unable to use duplicate column names. Collision in name: " << usedName;
- return false;
- }
- }
- }
- }
- return true;
-}
-
+ Ctx.Error(term->GetPos()) << "Unable to use '.' in column name. Invalid column name: " << label;
+ return false;
+ }
+ if (!label.empty()) {
+ if (!labels.insert(label).second) {
+ Ctx.Error(term->GetPos()) << "Unable to use duplicate column names. Collision in name: " << label;
+ return false;
+ }
+ }
+ if (term->IsAsterisk()) {
+ const auto& source = *term->GetSourceName();
+ if (source.empty() && terms.ysize() > 1) {
+ Ctx.Error(term->GetPos()) << "Unable to use general '*' with other columns, either specify concrete table like '<table>.*', either specify concrete columns.";
+ return false;
+ } else if (!asteriskSources.insert(source).second) {
+ Ctx.Error(term->GetPos()) << "Unable to use twice same quialified asterisk. Invalid source: " << source;
+ return false;
+ }
+ } else if (label.empty()) {
+ const auto* column = term->GetColumnName();
+ if (column && !column->empty()) {
+ const auto& source = *term->GetSourceName();
+ const auto usedName = source.empty() ? *column : source + '.' + *column;
+ if (!labels.insert(usedName).second) {
+ Ctx.Error(term->GetPos()) << "Unable to use duplicate column names. Collision in name: " << usedName;
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+}
+
TSourcePtr TSqlSelect::SingleSource(const TRule_single_source& node) {
switch (node.Alt_case()) {
case TRule_single_source::kAltSingleSource1: {
@@ -2665,10 +2665,10 @@ TSourcePtr TSqlSelect::SingleSource(const TRule_single_source& node) {
if (!source) {
return nullptr;
}
- return BuildInnerSource(pos, BuildSourceNode(pos, std::move(source)));
+ return BuildInnerSource(pos, BuildSourceNode(pos, std::move(source)));
}
- case TRule_single_source::kAltSingleSource3: {
- const auto& alt = node.GetAlt_single_source3();
+ case TRule_single_source::kAltSingleSource3: {
+ const auto& alt = node.GetAlt_single_source3();
Ctx.IncrementMonCounter("sql_features", "NamedNodeUseSource");
auto named = NamedNodeImpl(alt.GetRule_bind_parameter2(), *this);
auto at = alt.HasBlock1();
@@ -2711,7 +2711,7 @@ TSourcePtr TSqlSelect::SingleSource(const TRule_single_source& node) {
return BuildNodeSource(Ctx.Pos(), apply);
}
- return BuildInnerSource(Ctx.Pos(), node);
+ return BuildInnerSource(Ctx.Pos(), node);
}
default:
AltNotImplemented("single_source", node);
@@ -2720,15 +2720,15 @@ TSourcePtr TSqlSelect::SingleSource(const TRule_single_source& node) {
}
}
-TSourcePtr TSqlSelect::NamedSingleSource(const TRule_named_single_source& node) {
- auto singleSource = SingleSource(node.GetRule_single_source1());
- if (!singleSource) {
- return nullptr;
- }
- if (node.HasBlock2()) {
- const auto label = IdOrString(node.GetBlock2().GetRule_id_or_string2(), *this);
- singleSource->SetLabel(label);
- }
+TSourcePtr TSqlSelect::NamedSingleSource(const TRule_named_single_source& node) {
+ auto singleSource = SingleSource(node.GetRule_single_source1());
+ if (!singleSource) {
+ return nullptr;
+ }
+ if (node.HasBlock2()) {
+ const auto label = IdOrString(node.GetBlock2().GetRule_id_or_string2(), *this);
+ singleSource->SetLabel(label);
+ }
if (node.HasBlock3()) {
ESampleMode mode = ESampleMode::Auto;
TSqlExpression expr(Ctx, Mode);
@@ -2786,99 +2786,99 @@ TSourcePtr TSqlSelect::NamedSingleSource(const TRule_named_single_source& node)
return nullptr;
}
}
- return singleSource;
-}
-
+ return singleSource;
+}
+
bool TSqlSelect::ColumnName(TVector<TNodePtr>& keys, const TRule_column_name& node) {
- const auto sourceName = OptIdPrefixAsStr(node.GetRule_opt_id_prefix1(), *this);
- const auto columnName = IdOrString(node.GetRule_id_or_string2(), *this);
- YQL_ENSURE(!columnName.empty());
- keys.push_back(BuildColumn(Ctx.Pos(), columnName, sourceName));
- return true;
-}
+ const auto sourceName = OptIdPrefixAsStr(node.GetRule_opt_id_prefix1(), *this);
+ const auto columnName = IdOrString(node.GetRule_id_or_string2(), *this);
+ YQL_ENSURE(!columnName.empty());
+ keys.push_back(BuildColumn(Ctx.Pos(), columnName, sourceName));
+ return true;
+}
bool TSqlSelect::ColumnList(TVector<TNodePtr>& keys, const TRule_column_list& node) {
- if (!ColumnName(keys, node.GetRule_column_name1())) {
- return false;
- }
- for (auto b: node.GetBlock2()) {
- Token(b.GetToken1());
- if (!ColumnName(keys, b.GetRule_column_name2())) {
- return false;
- }
+ if (!ColumnName(keys, node.GetRule_column_name1())) {
+ return false;
+ }
+ for (auto b: node.GetBlock2()) {
+ Token(b.GetToken1());
+ if (!ColumnName(keys, b.GetRule_column_name2())) {
+ return false;
+ }
}
- return true;
+ return true;
}
bool TSqlSelect::NamedColumn(TVector<TNodePtr>& columnList, const TRule_named_column& node) {
- if (!ColumnName(columnList, node.GetRule_column_name1())) {
- return false;
- }
- if (node.HasBlock2()) {
- const auto label = IdOrString(node.GetBlock2().GetRule_id_or_string2(), *this);
- columnList.back()->SetLabel(label);
- }
- return true;
-}
-
+ if (!ColumnName(columnList, node.GetRule_column_name1())) {
+ return false;
+ }
+ if (node.HasBlock2()) {
+ const auto label = IdOrString(node.GetBlock2().GetRule_id_or_string2(), *this);
+ columnList.back()->SetLabel(label);
+ }
+ return true;
+}
+
bool TSqlSelect::NamedColumnList(TVector<TNodePtr>& columnList, const TRule_named_column_list& node) {
- if (!NamedColumn(columnList, node.GetRule_named_column1())) {
- return false;
- }
- for (auto b: node.GetBlock2()) {
- if (!NamedColumn(columnList, b.GetRule_named_column2())) {
- return false;
- }
- }
- return true;
-}
-
+ if (!NamedColumn(columnList, node.GetRule_named_column1())) {
+ return false;
+ }
+ for (auto b: node.GetBlock2()) {
+ if (!NamedColumn(columnList, b.GetRule_named_column2())) {
+ return false;
+ }
+ }
+ return true;
+}
+
bool TSqlSelect::SortSpecification(const TRule_sort_specification& node, TVector<TSortSpecificationPtr>& sortSpecs) {
- bool asc = true;
- TSqlExpression expr(Ctx, Mode);
- TNodePtr exprNode = expr.Build(node.GetRule_expr1());
- if (!exprNode) {
- return false;
- }
- if (node.HasBlock2()) {
- const auto& token = node.GetBlock2().GetToken1();
- Token(token);
- switch (token.GetId()) {
- case SQLLexerTokens::TOKEN_ASC:
- Ctx.IncrementMonCounter("sql_features", "OrderByAsc");
- break;
- case SQLLexerTokens::TOKEN_DESC:
- asc = false;
- Ctx.IncrementMonCounter("sql_features", "OrderByDesc");
- break;
- default:
- Ctx.IncrementMonCounter("sql_errors", "UnknownOrderBy");
- Error() << "Unsupported direction token: " << token.GetId();
- return false;
- }
- } else {
- Ctx.IncrementMonCounter("sql_features", "OrderByDefault");
- }
- auto sortSpecPtr = MakeIntrusive<TSortSpecification>();
- sortSpecPtr->OrderExpr = exprNode;
- sortSpecPtr->Ascending = asc;
- sortSpecs.emplace_back(sortSpecPtr);
- return true;
-}
-
+ bool asc = true;
+ TSqlExpression expr(Ctx, Mode);
+ TNodePtr exprNode = expr.Build(node.GetRule_expr1());
+ if (!exprNode) {
+ return false;
+ }
+ if (node.HasBlock2()) {
+ const auto& token = node.GetBlock2().GetToken1();
+ Token(token);
+ switch (token.GetId()) {
+ case SQLLexerTokens::TOKEN_ASC:
+ Ctx.IncrementMonCounter("sql_features", "OrderByAsc");
+ break;
+ case SQLLexerTokens::TOKEN_DESC:
+ asc = false;
+ Ctx.IncrementMonCounter("sql_features", "OrderByDesc");
+ break;
+ default:
+ Ctx.IncrementMonCounter("sql_errors", "UnknownOrderBy");
+ Error() << "Unsupported direction token: " << token.GetId();
+ return false;
+ }
+ } else {
+ Ctx.IncrementMonCounter("sql_features", "OrderByDefault");
+ }
+ auto sortSpecPtr = MakeIntrusive<TSortSpecification>();
+ sortSpecPtr->OrderExpr = exprNode;
+ sortSpecPtr->Ascending = asc;
+ sortSpecs.emplace_back(sortSpecPtr);
+ return true;
+}
+
bool TSqlSelect::SortSpecificationList(const TRule_sort_specification_list& node, TVector<TSortSpecificationPtr>& sortSpecs) {
- if (!SortSpecification(node.GetRule_sort_specification1(), sortSpecs)) {
- return false;
- }
- for (auto sortSpec: node.GetBlock2()) {
- Token(sortSpec.GetToken1());
- if (!SortSpecification(sortSpec.GetRule_sort_specification2(), sortSpecs)) {
- return false;
- }
- }
- return true;
-}
-
+ if (!SortSpecification(node.GetRule_sort_specification1(), sortSpecs)) {
+ return false;
+ }
+ for (auto sortSpec: node.GetBlock2()) {
+ Token(sortSpec.GetToken1());
+ if (!SortSpecification(sortSpec.GetRule_sort_specification2(), sortSpecs)) {
+ return false;
+ }
+ }
+ return true;
+}
+
TSourcePtr TSqlSelect::ProcessCore(const TRule_process_core& node, const TWriteSettings& settings, TPosition& selectPos) {
// PROCESS STREAM? named_single_source (COMMA named_single_source)* (USING call_expr (AS id_or_string)?
// (WHERE expr)? (HAVING expr)?)?
@@ -2892,9 +2892,9 @@ TSourcePtr TSqlSelect::ProcessCore(const TRule_process_core& node, const TWriteS
}
TSourcePtr source(NamedSingleSource(node.GetRule_named_single_source3()));
- if (!source) {
- return nullptr;
- }
+ if (!source) {
+ return nullptr;
+ }
if (node.GetBlock4().size()) {
TVector<TSourcePtr> sources(1, source);
for (auto& s: node.GetBlock4()) {
@@ -2919,19 +2919,19 @@ TSourcePtr TSqlSelect::ProcessCore(const TRule_process_core& node, const TWriteS
if (!where || !source->AddFilter(Ctx, where)) {
return nullptr;
}
- Ctx.IncrementMonCounter("sql_features", "ProcessWhere");
- } else {
+ Ctx.IncrementMonCounter("sql_features", "ProcessWhere");
+ } else {
Ctx.IncrementMonCounter("sql_features", stream ? "ProcessStream" : "Process");
}
if (block5.HasBlock5()) {
- Ctx.Error() << "PROCESS does not allow HAVING yet! You may request it on yql@ maillist.";
+ Ctx.Error() << "PROCESS does not allow HAVING yet! You may request it on yql@ maillist.";
return nullptr;
}
- /// \todo other solution
- PushNamedNode(TArgPlaceholderNode::ProcessRows, BuildArgPlaceholder(Ctx.Pos(), TArgPlaceholderNode::ProcessRows));
- PushNamedNode(TArgPlaceholderNode::ProcessRow, BuildArgPlaceholder(Ctx.Pos(), TArgPlaceholderNode::ProcessRow));
+ /// \todo other solution
+ PushNamedNode(TArgPlaceholderNode::ProcessRows, BuildArgPlaceholder(Ctx.Pos(), TArgPlaceholderNode::ProcessRows));
+ PushNamedNode(TArgPlaceholderNode::ProcessRow, BuildArgPlaceholder(Ctx.Pos(), TArgPlaceholderNode::ProcessRow));
bool listCall = false;
TSqlCallExpr call(Ctx, Mode);
@@ -2948,54 +2948,54 @@ TSourcePtr TSqlSelect::ProcessCore(const TRule_process_core& node, const TWriteS
auto args = call.GetArgs();
- /// SIN: special processing of binds
- for (auto& arg: args) {
- auto placeholder = dynamic_cast<TArgPlaceholderNode*>(arg.Get());
- if (placeholder) {
- auto name = placeholder->GetName();
- if (name == TArgPlaceholderNode::ProcessRows) {
- if (listCall) {
- Ctx.Error(arg->GetPos()) << "Only single instance of " << name << " is allowed.";
- return nullptr;
+ /// SIN: special processing of binds
+ for (auto& arg: args) {
+ auto placeholder = dynamic_cast<TArgPlaceholderNode*>(arg.Get());
+ if (placeholder) {
+ auto name = placeholder->GetName();
+ if (name == TArgPlaceholderNode::ProcessRows) {
+ if (listCall) {
+ Ctx.Error(arg->GetPos()) << "Only single instance of " << name << " is allowed.";
+ return nullptr;
}
- listCall = true;
- arg = new TAstAtomNodeImpl(arg->GetPos(), "inputRowsList", 0);
- } else if (name == TArgPlaceholderNode::ProcessRow) {
- arg = BuildColumn(arg->GetPos(), "*");
+ listCall = true;
+ arg = new TAstAtomNodeImpl(arg->GetPos(), "inputRowsList", 0);
+ } else if (name == TArgPlaceholderNode::ProcessRow) {
+ arg = BuildColumn(arg->GetPos(), "*");
}
}
}
TSqlCallExpr finalCall(call, args);
- TNodePtr with(finalCall.BuildUdf(true));
- if (!with || !finalCall.EnsureNotDistinct("PROCESS")) {
- return {};
+ TNodePtr with(finalCall.BuildUdf(true));
+ if (!with || !finalCall.EnsureNotDistinct("PROCESS")) {
+ return {};
- }
+ }
args = finalCall.GetArgs();
-
+
if (block5.HasBlock3()) {
with->SetLabel(IdOrString(block5.GetBlock3().GetRule_id_or_string2(), *this));
- }
-
+ }
+
return BuildProcess(startPos, std::move(source), with, std::move(args), listCall, stream, settings);
-}
-
+}
+
TSourcePtr TSqlSelect::ReduceCore(const TRule_reduce_core& node, const TWriteSettings& settings, TPosition& selectPos) {
// REDUCE named_single_source (COMMA named_single_source)* (PRESORT sort_specification_list)?
// ON column_list USING ALL? call_expr (AS id_or_string)?
// (WHERE expr)? (HAVING expr)?
Token(node.GetToken1());
- TPosition startPos(Ctx.Pos());
+ TPosition startPos(Ctx.Pos());
if (!selectPos) {
selectPos = startPos;
}
-
- TSourcePtr source(NamedSingleSource(node.GetRule_named_single_source2()));
- if (!source) {
- return {};
- }
+
+ TSourcePtr source(NamedSingleSource(node.GetRule_named_single_source2()));
+ if (!source) {
+ return {};
+ }
if (node.GetBlock3().size()) {
TVector<TSourcePtr> sources(1, source);
for (auto& s: node.GetBlock3()) {
@@ -3007,65 +3007,65 @@ TSourcePtr TSqlSelect::ReduceCore(const TRule_reduce_core& node, const TWriteSet
auto pos = source->GetPos();
source = BuildMuxSource(pos, std::move(sources));
}
-
+
TVector<TSortSpecificationPtr> orderBy;
if (node.HasBlock4()) {
if (!SortSpecificationList(node.GetBlock4().GetRule_sort_specification_list2(), orderBy)) {
- return {};
- }
- }
-
+ return {};
+ }
+ }
+
TVector<TNodePtr> keys;
if (!ColumnList(keys, node.GetRule_column_list6())) {
return nullptr;
}
-
+
if (node.HasBlock11()) {
- TSqlExpression expr(Ctx, Mode);
+ TSqlExpression expr(Ctx, Mode);
TNodePtr where = expr.Build(node.GetBlock11().GetRule_expr2());
- if (!where || !source->AddFilter(Ctx, where)) {
- return nullptr;
- }
- Ctx.IncrementMonCounter("sql_features", "ReduceWhere");
- } else {
- Ctx.IncrementMonCounter("sql_features", "Reduce");
- }
-
- TNodePtr having;
+ if (!where || !source->AddFilter(Ctx, where)) {
+ return nullptr;
+ }
+ Ctx.IncrementMonCounter("sql_features", "ReduceWhere");
+ } else {
+ Ctx.IncrementMonCounter("sql_features", "Reduce");
+ }
+
+ TNodePtr having;
if (node.HasBlock12()) {
- TSqlExpression expr(Ctx, Mode);
+ TSqlExpression expr(Ctx, Mode);
having = expr.Build(node.GetBlock12().GetRule_expr2());
- if (!having) {
- return nullptr;
- }
- }
-
- PushNamedNode(TArgPlaceholderNode::ProcessRow, BuildColumn(Ctx.Pos(), "*"));
-
- TSqlCallExpr call(Ctx, Mode);
+ if (!having) {
+ return nullptr;
+ }
+ }
+
+ PushNamedNode(TArgPlaceholderNode::ProcessRow, BuildColumn(Ctx.Pos(), "*"));
+
+ TSqlCallExpr call(Ctx, Mode);
bool initRet = call.Init(node.GetRule_call_expr9());
if (initRet) {
call.IncCounters();
}
- PopNamedNode(TArgPlaceholderNode::ProcessRow);
+ PopNamedNode(TArgPlaceholderNode::ProcessRow);
if (!initRet) {
return nullptr;
}
-
- auto args = call.GetArgs();
-
- TSqlCallExpr finalCall(call, args);
-
- TNodePtr udf(finalCall.BuildUdf(false));
- if (!udf || !finalCall.EnsureNotDistinct("REDUCE")) {
- return {};
- }
-
+
+ auto args = call.GetArgs();
+
+ TSqlCallExpr finalCall(call, args);
+
+ TNodePtr udf(finalCall.BuildUdf(false));
+ if (!udf || !finalCall.EnsureNotDistinct("REDUCE")) {
+ return {};
+ }
+
if (node.HasBlock10()) {
udf->SetLabel(IdOrString(node.GetBlock10().GetRule_id_or_string2(), *this));
- }
-
+ }
+
const auto reduceMode = node.HasBlock8() ? ReduceMode::ByAll : ReduceMode::ByPartition;
return BuildReduce(startPos, reduceMode, std::move(source), std::move(orderBy), std::move(keys), std::move(args), udf, having, settings);
}
@@ -3086,8 +3086,8 @@ TSourcePtr TSqlSelect::SelectCore(const TRule_select_core& node, const TWriteSet
const bool stream = node.HasBlock3();
const bool distinct = IsDistinctOptSet(node.GetRule_opt_set_quantifier4());
- if (distinct) {
- Ctx.IncrementMonCounter("sql_features", "DistinctInSelect");
+ if (distinct) {
+ Ctx.IncrementMonCounter("sql_features", "DistinctInSelect");
}
TSourcePtr source(BuildFakeSource(selectPos));
@@ -3103,83 +3103,83 @@ TSourcePtr TSqlSelect::SelectCore(const TRule_select_core& node, const TWriteSet
} else if (node.HasBlock8()) {
source = JoinSource(node.GetBlock8().GetRule_join_source2());
}
- if (!source) {
- return nullptr;
- }
+ if (!source) {
+ return nullptr;
+ }
TVector<TNodePtr> without;
if (node.HasBlock7()) {
if (!ColumnList(without, node.GetBlock7().GetRule_column_list2())) {
- return nullptr;
- }
- }
+ return nullptr;
+ }
+ }
if (node.HasBlock9()) {
auto block = node.GetBlock9();
Token(block.GetToken1());
TPosition pos(Ctx.Pos());
TSqlExpression expr(Ctx, Mode);
- TNodePtr where = expr.WrapExprShortcuts(expr.Build(block.GetRule_expr2()));
- if (!where) {
- Ctx.IncrementMonCounter("sql_errors", "WhereInvalid");
+ TNodePtr where = expr.WrapExprShortcuts(expr.Build(block.GetRule_expr2()));
+ if (!where) {
+ Ctx.IncrementMonCounter("sql_errors", "WhereInvalid");
+ return nullptr;
+ }
+ if (!source->AddFilter(Ctx, where)) {
+ Ctx.IncrementMonCounter("sql_errors", "WhereNotSupportedBySource");
return nullptr;
}
- if (!source->AddFilter(Ctx, where)) {
- Ctx.IncrementMonCounter("sql_errors", "WhereNotSupportedBySource");
- return nullptr;
- }
Ctx.IncrementMonCounter("sql_features", "Where");
}
- /// \todo merge gtoupByExpr and groupBy in one
+ /// \todo merge gtoupByExpr and groupBy in one
TVector<TNodePtr> groupByExpr, groupBy;
THoppingWindowSpecPtr hoppingWindowSpec;
if (node.HasBlock10()) {
- TGroupByClause clause(Ctx, Mode);
+ TGroupByClause clause(Ctx, Mode);
if (!clause.Build(node.GetBlock10().GetRule_group_by_clause1(), stream)) {
return nullptr;
}
for (const auto& exprAlias: clause.Aliases()) {
- YQL_ENSURE(exprAlias.first == exprAlias.second->GetLabel());
- groupByExpr.emplace_back(exprAlias.second);
+ YQL_ENSURE(exprAlias.first == exprAlias.second->GetLabel());
+ groupByExpr.emplace_back(exprAlias.second);
}
- groupBy = std::move(clause.Content());
- clause.SetFeatures("sql_features");
+ groupBy = std::move(clause.Content());
+ clause.SetFeatures("sql_features");
hoppingWindowSpec = clause.GetHoppingWindow();
}
-
- TNodePtr having;
+
+ TNodePtr having;
if (node.HasBlock11()) {
- TSqlExpression expr(Ctx, Mode);
+ TSqlExpression expr(Ctx, Mode);
having = expr.Build(node.GetBlock11().GetRule_expr2());
- if (!having) {
- return nullptr;
- }
- Ctx.IncrementMonCounter("sql_features", "Having");
- }
-
- TWinSpecs windowSpec;
+ if (!having) {
+ return nullptr;
+ }
+ Ctx.IncrementMonCounter("sql_features", "Having");
+ }
+
+ TWinSpecs windowSpec;
if (node.HasBlock12()) {
if (stream) {
Ctx.Error() << "WINDOW is not allowed in streaming queries";
- return nullptr;
- }
+ return nullptr;
+ }
if (!WindowClause(node.GetBlock12().GetRule_window_clause1(), windowSpec)) {
return nullptr;
}
- Ctx.IncrementMonCounter("sql_features", "WindowClause");
- }
-
+ Ctx.IncrementMonCounter("sql_features", "WindowClause");
+ }
+
TVector<TSortSpecificationPtr> orderBy;
if (node.HasBlock13()) {
if (stream) {
Ctx.Error() << "ORDER BY is not allowed in streaming queries";
- return nullptr;
- }
+ return nullptr;
+ }
if (!OrderByClause(node.GetBlock13().GetRule_order_by_clause1(), orderBy)) {
return nullptr;
}
- Ctx.IncrementMonCounter("sql_features", IsColumnsOnly(orderBy) ? "OrderBy" : "OrderByExpr");
- }
+ Ctx.IncrementMonCounter("sql_features", IsColumnsOnly(orderBy) ? "OrderBy" : "OrderByExpr");
+ }
TVector<TNodePtr> terms;
if (!SelectTerm(terms, node.GetRule_result_column5())) {
return nullptr;
@@ -3189,185 +3189,185 @@ TSourcePtr TSqlSelect::SelectCore(const TRule_select_core& node, const TWriteSet
return nullptr;
}
}
- if (!ValidateSelectColumns(terms)) {
- return nullptr;
- }
+ if (!ValidateSelectColumns(terms)) {
+ return nullptr;
+ }
return BuildSelectCore(Ctx, startPos, std::move(source), groupByExpr, groupBy, orderBy, having,
std::move(windowSpec), hoppingWindowSpec, std::move(terms), distinct, std::move(without), stream, settings);
}
-bool TSqlSelect::FrameStart(const TRule_window_frame_start& rule, TNodePtr& node, bool beginBound) {
- switch (rule.Alt_case()) {
- case TRule_window_frame_start::kAltWindowFrameStart1:
- if (!beginBound) {
- Ctx.Error() << "Unable to use UNBOUNDED PRECEDING after BETWEEN ... AND";
- return false;
- }
+bool TSqlSelect::FrameStart(const TRule_window_frame_start& rule, TNodePtr& node, bool beginBound) {
+ switch (rule.Alt_case()) {
+ case TRule_window_frame_start::kAltWindowFrameStart1:
+ if (!beginBound) {
+ Ctx.Error() << "Unable to use UNBOUNDED PRECEDING after BETWEEN ... AND";
+ return false;
+ }
node = BuildLiteralVoid(Ctx.Pos());
- return true;
- case TRule_window_frame_start::kAltWindowFrameStart2:
- if (beginBound) {
- Ctx.Error() << "Unable to use FOLLOWING before AND in BETWEEN ... AND syntax";
- return false;
- }
- {
- auto precedingRule = rule.GetAlt_window_frame_start2().GetRule_window_frame_preceding1();
- node = Literal(Ctx, precedingRule.GetRule_unsigned_number1());
- return true;
- }
- case TRule_window_frame_start::kAltWindowFrameStart3:
- return new TLiteralNumberNode<i32>(Ctx.Pos(), "Int32", ToString("0"));
- return true;
- default:
- Y_FAIL("FrameClause: frame start not corresond to grammar changes");
- }
-}
-
-bool TSqlSelect::FrameBound(const TRule_window_frame_bound& rule, TNodePtr& node, bool beginBound) {
- switch (rule.Alt_case()) {
- case TRule_window_frame_bound::kAltWindowFrameBound1:
- return FrameStart(rule.GetAlt_window_frame_bound1().GetRule_window_frame_start1(), node, beginBound);
- case TRule_window_frame_bound::kAltWindowFrameBound2:
- if (beginBound) {
- Ctx.Error() << "Unable to use UNBOUNDED FOLLOWING before AND";
- return false;
- }
+ return true;
+ case TRule_window_frame_start::kAltWindowFrameStart2:
+ if (beginBound) {
+ Ctx.Error() << "Unable to use FOLLOWING before AND in BETWEEN ... AND syntax";
+ return false;
+ }
+ {
+ auto precedingRule = rule.GetAlt_window_frame_start2().GetRule_window_frame_preceding1();
+ node = Literal(Ctx, precedingRule.GetRule_unsigned_number1());
+ return true;
+ }
+ case TRule_window_frame_start::kAltWindowFrameStart3:
+ return new TLiteralNumberNode<i32>(Ctx.Pos(), "Int32", ToString("0"));
+ return true;
+ default:
+ Y_FAIL("FrameClause: frame start not corresond to grammar changes");
+ }
+}
+
+bool TSqlSelect::FrameBound(const TRule_window_frame_bound& rule, TNodePtr& node, bool beginBound) {
+ switch (rule.Alt_case()) {
+ case TRule_window_frame_bound::kAltWindowFrameBound1:
+ return FrameStart(rule.GetAlt_window_frame_bound1().GetRule_window_frame_start1(), node, beginBound);
+ case TRule_window_frame_bound::kAltWindowFrameBound2:
+ if (beginBound) {
+ Ctx.Error() << "Unable to use UNBOUNDED FOLLOWING before AND";
+ return false;
+ }
node = BuildLiteralVoid(Ctx.Pos());
- return true;
- case TRule_window_frame_bound::kAltWindowFrameBound3:
- if (beginBound) {
- Ctx.Error() << "Unable to use FOLLOWING before AND";
- return false;
- }
- {
- auto followRule = rule.GetAlt_window_frame_bound3().GetRule_window_frame_following1();
- node = Literal(Ctx, followRule.GetRule_unsigned_number1());
- return true;
- }
- default:
- Y_FAIL("FrameClause: frame bound not corresond to grammar changes");
- }
-}
-
-bool TSqlSelect::FrameClause(const TRule_window_frame_clause& rule, TMaybe<TFrameSpecification>& frameSpecLink) {
- TFrameSpecification frameSpec;
+ return true;
+ case TRule_window_frame_bound::kAltWindowFrameBound3:
+ if (beginBound) {
+ Ctx.Error() << "Unable to use FOLLOWING before AND";
+ return false;
+ }
+ {
+ auto followRule = rule.GetAlt_window_frame_bound3().GetRule_window_frame_following1();
+ node = Literal(Ctx, followRule.GetRule_unsigned_number1());
+ return true;
+ }
+ default:
+ Y_FAIL("FrameClause: frame bound not corresond to grammar changes");
+ }
+}
+
+bool TSqlSelect::FrameClause(const TRule_window_frame_clause& rule, TMaybe<TFrameSpecification>& frameSpecLink) {
+ TFrameSpecification frameSpec;
const TString frameUnitStr = to_lower(Token(rule.GetRule_window_frame_units1().GetToken1()));
- if (frameUnitStr == "rows") {
- frameSpec.FrameType = EFrameType::FrameByRows;
- } else if (frameUnitStr == "range") {
- frameSpec.FrameType = EFrameType::FrameByRange;
- } else {
- Ctx.Error() << "Unknown frame type in window specification: " << frameUnitStr;
- return false;
- }
- auto frameExtent = rule.GetRule_window_frame_extent2();
- switch (frameExtent.Alt_case()) {
- case TRule_window_frame_extent::kAltWindowFrameExtent1:
- if (!FrameStart(frameExtent.GetAlt_window_frame_extent1().GetRule_window_frame_start1(), frameSpec.FrameBegin, true)) {
- return false;
- }
- break;
- case TRule_window_frame_extent::kAltWindowFrameExtent2: {
- auto between = frameExtent.GetAlt_window_frame_extent2().GetRule_window_frame_between1();
- if (!FrameBound(between.GetRule_window_frame_bound2(), frameSpec.FrameBegin, true)) {
- return false;
- }
- if (!FrameBound(between.GetRule_window_frame_bound4(), frameSpec.FrameEnd, false)) {
- return false;
- }
- break;
- }
- default:
- Y_FAIL("FrameClause: frame extent not corresond to grammar changes");
- }
- if (rule.HasBlock3()) {
- switch (rule.GetBlock3().GetRule_window_frame_exclusion1().Alt_case()) {
- case TRule_window_frame_exclusion::kAltWindowFrameExclusion1:
- frameSpec.FrameExclusion = FrameExclCurRow;
- break;
- case TRule_window_frame_exclusion::kAltWindowFrameExclusion2:
- frameSpec.FrameExclusion = FrameExclGroup;
- break;
- case TRule_window_frame_exclusion::kAltWindowFrameExclusion3:
- frameSpec.FrameExclusion = FrameExclTies;
- break;
- case TRule_window_frame_exclusion::kAltWindowFrameExclusion4:
- frameSpec.FrameExclusion = FrameExclNoOthers;
- break;
- default:
- Y_FAIL("FrameClause: frame exclusion not corresond to grammar changes");
- }
- }
- frameSpecLink = frameSpec;
- return true;
-}
-
-TWindowSpecificationPtr TSqlSelect::WindowSpecification(const TRule_window_specification_details& rule) {
- TWindowSpecificationPtr winSpecPtr = new TWindowSpecification;
- if (rule.HasBlock1()) {
- Ctx.Error() << "Existing window name is not supported in window specification yet!";
- return {};
- }
- if (rule.HasBlock2()) {
- if (!NamedExprList(rule.GetBlock2().GetRule_window_partition_clause1().GetRule_named_expr_list3(), winSpecPtr->Partitions)) {
- return {};
- }
- }
- if (rule.HasBlock3()) {
- if (!OrderByClause(rule.GetBlock3().GetRule_window_order_clause1().GetRule_order_by_clause1(), winSpecPtr->OrderBy)) {
- return {};
- }
- }
- if (rule.HasBlock4()) {
- if (!FrameClause(rule.GetBlock4().GetRule_window_frame_clause1(), winSpecPtr->Frame)) {
- return {};
- }
- }
- return winSpecPtr;
-}
-
-bool TSqlSelect::WindowDefenition(const TRule_window_definition& rule, TWinSpecs& winSpecs) {
+ if (frameUnitStr == "rows") {
+ frameSpec.FrameType = EFrameType::FrameByRows;
+ } else if (frameUnitStr == "range") {
+ frameSpec.FrameType = EFrameType::FrameByRange;
+ } else {
+ Ctx.Error() << "Unknown frame type in window specification: " << frameUnitStr;
+ return false;
+ }
+ auto frameExtent = rule.GetRule_window_frame_extent2();
+ switch (frameExtent.Alt_case()) {
+ case TRule_window_frame_extent::kAltWindowFrameExtent1:
+ if (!FrameStart(frameExtent.GetAlt_window_frame_extent1().GetRule_window_frame_start1(), frameSpec.FrameBegin, true)) {
+ return false;
+ }
+ break;
+ case TRule_window_frame_extent::kAltWindowFrameExtent2: {
+ auto between = frameExtent.GetAlt_window_frame_extent2().GetRule_window_frame_between1();
+ if (!FrameBound(between.GetRule_window_frame_bound2(), frameSpec.FrameBegin, true)) {
+ return false;
+ }
+ if (!FrameBound(between.GetRule_window_frame_bound4(), frameSpec.FrameEnd, false)) {
+ return false;
+ }
+ break;
+ }
+ default:
+ Y_FAIL("FrameClause: frame extent not corresond to grammar changes");
+ }
+ if (rule.HasBlock3()) {
+ switch (rule.GetBlock3().GetRule_window_frame_exclusion1().Alt_case()) {
+ case TRule_window_frame_exclusion::kAltWindowFrameExclusion1:
+ frameSpec.FrameExclusion = FrameExclCurRow;
+ break;
+ case TRule_window_frame_exclusion::kAltWindowFrameExclusion2:
+ frameSpec.FrameExclusion = FrameExclGroup;
+ break;
+ case TRule_window_frame_exclusion::kAltWindowFrameExclusion3:
+ frameSpec.FrameExclusion = FrameExclTies;
+ break;
+ case TRule_window_frame_exclusion::kAltWindowFrameExclusion4:
+ frameSpec.FrameExclusion = FrameExclNoOthers;
+ break;
+ default:
+ Y_FAIL("FrameClause: frame exclusion not corresond to grammar changes");
+ }
+ }
+ frameSpecLink = frameSpec;
+ return true;
+}
+
+TWindowSpecificationPtr TSqlSelect::WindowSpecification(const TRule_window_specification_details& rule) {
+ TWindowSpecificationPtr winSpecPtr = new TWindowSpecification;
+ if (rule.HasBlock1()) {
+ Ctx.Error() << "Existing window name is not supported in window specification yet!";
+ return {};
+ }
+ if (rule.HasBlock2()) {
+ if (!NamedExprList(rule.GetBlock2().GetRule_window_partition_clause1().GetRule_named_expr_list3(), winSpecPtr->Partitions)) {
+ return {};
+ }
+ }
+ if (rule.HasBlock3()) {
+ if (!OrderByClause(rule.GetBlock3().GetRule_window_order_clause1().GetRule_order_by_clause1(), winSpecPtr->OrderBy)) {
+ return {};
+ }
+ }
+ if (rule.HasBlock4()) {
+ if (!FrameClause(rule.GetBlock4().GetRule_window_frame_clause1(), winSpecPtr->Frame)) {
+ return {};
+ }
+ }
+ return winSpecPtr;
+}
+
+bool TSqlSelect::WindowDefenition(const TRule_window_definition& rule, TWinSpecs& winSpecs) {
const TString windowName = Id(rule.GetRule_new_window_name1().GetRule_window_name1().GetRule_id1(), *this);
if (winSpecs.contains(windowName)) {
- Ctx.Error() << "Unable to declare window with same name: " << windowName;
- return false;
- }
- auto windowSpec = WindowSpecification(rule.GetRule_window_specification3().GetRule_window_specification_details2());
- if (!windowSpec) {
- return false;
- }
- winSpecs.emplace(windowName, std::move(windowSpec));
- return true;
-}
-
-bool TSqlSelect::WindowClause(const TRule_window_clause& rule, TWinSpecs& winSpecs) {
- auto windowList = rule.GetRule_window_definition_list2();
- if (!WindowDefenition(windowList.GetRule_window_definition1(), winSpecs)) {
- return false;
- }
- for (auto& block: windowList.GetBlock2()) {
- if (!WindowDefenition(block.GetRule_window_definition2(), winSpecs)) {
- return false;
- }
- }
- return true;
-}
-
+ Ctx.Error() << "Unable to declare window with same name: " << windowName;
+ return false;
+ }
+ auto windowSpec = WindowSpecification(rule.GetRule_window_specification3().GetRule_window_specification_details2());
+ if (!windowSpec) {
+ return false;
+ }
+ winSpecs.emplace(windowName, std::move(windowSpec));
+ return true;
+}
+
+bool TSqlSelect::WindowClause(const TRule_window_clause& rule, TWinSpecs& winSpecs) {
+ auto windowList = rule.GetRule_window_definition_list2();
+ if (!WindowDefenition(windowList.GetRule_window_definition1(), winSpecs)) {
+ return false;
+ }
+ for (auto& block: windowList.GetBlock2()) {
+ if (!WindowDefenition(block.GetRule_window_definition2(), winSpecs)) {
+ return false;
+ }
+ }
+ return true;
+}
+
bool TSqlSelect::OrderByClause(const TRule_order_by_clause& node, TVector<TSortSpecificationPtr>& orderBy) {
- return SortSpecificationList(node.GetRule_sort_specification_list3(), orderBy);
-}
-
+ return SortSpecificationList(node.GetRule_sort_specification_list3(), orderBy);
+}
+
bool TGroupByClause::Build(const TRule_group_by_clause& node, bool stream) {
- const bool distinct = IsDistinctOptSet(node.GetRule_opt_set_quantifier3());
- if (distinct) {
+ const bool distinct = IsDistinctOptSet(node.GetRule_opt_set_quantifier3());
+ if (distinct) {
Ctx.Error() << "DISTINCT is not supported in GROUP BY clause yet!";
- Ctx.IncrementMonCounter("sql_errors", "DistinctInGroupByNotSupported");
- return false;
- }
- if (!ParseList(node.GetRule_grouping_element_list4())) {
- return false;
- }
- ResolveGroupByAndGrouping();
+ Ctx.IncrementMonCounter("sql_errors", "DistinctInGroupByNotSupported");
+ return false;
+ }
+ if (!ParseList(node.GetRule_grouping_element_list4())) {
+ return false;
+ }
+ ResolveGroupByAndGrouping();
if (stream && !HoppingWindowSpec) {
Ctx.Error() << "Streaming group by query must have a hopping window specification.";
return false;
@@ -3376,52 +3376,52 @@ bool TGroupByClause::Build(const TRule_group_by_clause& node, bool stream) {
Ctx.Error() << "Hopping window specification is not supported in a non-streaming query.";
return false;
}
- return true;
-}
-
-bool TGroupByClause::ParseList(const TRule_grouping_element_list& groupingListNode) {
- if (!GroupingElement(groupingListNode.GetRule_grouping_element1())) {
- return false;
- }
- for (auto b: groupingListNode.GetBlock2()) {
- if (!GroupingElement(b.GetRule_grouping_element2())) {
- return false;
- }
- }
- return true;
-}
-
+ return true;
+}
+
+bool TGroupByClause::ParseList(const TRule_grouping_element_list& groupingListNode) {
+ if (!GroupingElement(groupingListNode.GetRule_grouping_element1())) {
+ return false;
+ }
+ for (auto b: groupingListNode.GetBlock2()) {
+ if (!GroupingElement(b.GetRule_grouping_element2())) {
+ return false;
+ }
+ }
+ return true;
+}
+
void TGroupByClause::SetFeatures(const TString& field) const {
- Ctx.IncrementMonCounter(field, "GroupBy");
- const auto& features = Features();
- if (features.Test(EGroupByFeatures::Ordinary)) {
- Ctx.IncrementMonCounter(field, "GroupByOrdinary");
- }
- if (features.Test(EGroupByFeatures::Expression)) {
- Ctx.IncrementMonCounter(field, "GroupByExpression");
- }
- if (features.Test(EGroupByFeatures::Rollup)) {
- Ctx.IncrementMonCounter(field, "GroupByRollup");
- }
- if (features.Test(EGroupByFeatures::Cube)) {
- Ctx.IncrementMonCounter(field, "GroupByCube");
- }
- if (features.Test(EGroupByFeatures::GroupingSet)) {
- Ctx.IncrementMonCounter(field, "GroupByGroupingSet");
- }
- if (features.Test(EGroupByFeatures::Empty)) {
- Ctx.IncrementMonCounter(field, "GroupByEmpty");
- }
-}
-
+ Ctx.IncrementMonCounter(field, "GroupBy");
+ const auto& features = Features();
+ if (features.Test(EGroupByFeatures::Ordinary)) {
+ Ctx.IncrementMonCounter(field, "GroupByOrdinary");
+ }
+ if (features.Test(EGroupByFeatures::Expression)) {
+ Ctx.IncrementMonCounter(field, "GroupByExpression");
+ }
+ if (features.Test(EGroupByFeatures::Rollup)) {
+ Ctx.IncrementMonCounter(field, "GroupByRollup");
+ }
+ if (features.Test(EGroupByFeatures::Cube)) {
+ Ctx.IncrementMonCounter(field, "GroupByCube");
+ }
+ if (features.Test(EGroupByFeatures::GroupingSet)) {
+ Ctx.IncrementMonCounter(field, "GroupByGroupingSet");
+ }
+ if (features.Test(EGroupByFeatures::Empty)) {
+ Ctx.IncrementMonCounter(field, "GroupByEmpty");
+ }
+}
+
TVector<TNodePtr>& TGroupByClause::Content() {
- return GroupBySet;
-}
-
+ return GroupBySet;
+}
+
TMap<TString, TNodePtr>& TGroupByClause::Aliases() {
- return GroupSetContext->NodeAliases;
-}
-
+ return GroupSetContext->NodeAliases;
+}
+
THoppingWindowSpecPtr TGroupByClause::GetHoppingWindow() {
return HoppingWindowSpec;
}
@@ -3429,136 +3429,136 @@ THoppingWindowSpecPtr TGroupByClause::GetHoppingWindow() {
TVector<TNodePtr> TGroupByClause::MultiplyGroupingSets(const TVector<TNodePtr>& lhs, const TVector<TNodePtr>& rhs) const {
TVector<TNodePtr> content;
for (const auto& leftNode: lhs) {
- auto leftPtr = leftNode->ContentListPtr();
- YQL_ENSURE(leftPtr, "Unable to multiply grouping sets");
+ auto leftPtr = leftNode->ContentListPtr();
+ YQL_ENSURE(leftPtr, "Unable to multiply grouping sets");
for (const auto& rightNode: rhs) {
TVector<TNodePtr> mulItem(leftPtr->begin(), leftPtr->end());
- auto rightPtr = rightNode->ContentListPtr();
- YQL_ENSURE(rightPtr, "Unable to multiply grouping sets");
- mulItem.insert(mulItem.end(), rightPtr->begin(), rightPtr->end());
- content.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(mulItem)));
- }
- }
- return content;
-}
-
-void TGroupByClause::ResolveGroupByAndGrouping() {
- auto listPos = std::find_if(GroupBySet.begin(), GroupBySet.end(), [](const TNodePtr& node) {
- return node->ContentListPtr();
- });
- if (listPos == GroupBySet.end()) {
- return;
- }
- auto curContent = *(*listPos)->ContentListPtr();
- if (listPos != GroupBySet.begin()) {
+ auto rightPtr = rightNode->ContentListPtr();
+ YQL_ENSURE(rightPtr, "Unable to multiply grouping sets");
+ mulItem.insert(mulItem.end(), rightPtr->begin(), rightPtr->end());
+ content.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(mulItem)));
+ }
+ }
+ return content;
+}
+
+void TGroupByClause::ResolveGroupByAndGrouping() {
+ auto listPos = std::find_if(GroupBySet.begin(), GroupBySet.end(), [](const TNodePtr& node) {
+ return node->ContentListPtr();
+ });
+ if (listPos == GroupBySet.end()) {
+ return;
+ }
+ auto curContent = *(*listPos)->ContentListPtr();
+ if (listPos != GroupBySet.begin()) {
TVector<TNodePtr> emulate(GroupBySet.begin(), listPos);
TVector<TNodePtr> emulateContent(1, BuildListOfNamedNodes(Ctx.Pos(), std::move(emulate)));
- curContent = MultiplyGroupingSets(emulateContent, curContent);
- }
- for (++listPos; listPos != GroupBySet.end(); ++listPos) {
- auto newElem = (*listPos)->ContentListPtr();
- if (newElem) {
- curContent = MultiplyGroupingSets(curContent, *newElem);
- } else {
+ curContent = MultiplyGroupingSets(emulateContent, curContent);
+ }
+ for (++listPos; listPos != GroupBySet.end(); ++listPos) {
+ auto newElem = (*listPos)->ContentListPtr();
+ if (newElem) {
+ curContent = MultiplyGroupingSets(curContent, *newElem);
+ } else {
TVector<TNodePtr> emulate(1, *listPos);
TVector<TNodePtr> emulateContent(1, BuildListOfNamedNodes(Ctx.Pos(), std::move(emulate)));
- curContent = MultiplyGroupingSets(curContent, emulateContent);
- }
- }
+ curContent = MultiplyGroupingSets(curContent, emulateContent);
+ }
+ }
TVector<TNodePtr> result(1, BuildListOfNamedNodes(Ctx.Pos(), std::move(curContent)));
- std::swap(result, GroupBySet);
-}
-
-bool TGroupByClause::GroupingElement(const TRule_grouping_element& node) {
- TSourcePtr res;
+ std::swap(result, GroupBySet);
+}
+
+bool TGroupByClause::GroupingElement(const TRule_grouping_element& node) {
+ TSourcePtr res;
TVector<TNodePtr> emptyContent;
- switch (node.Alt_case()) {
- case TRule_grouping_element::kAltGroupingElement1:
- if (!OrdinaryGroupingSet(node.GetAlt_grouping_element1().GetRule_ordinary_grouping_set1())) {
- return false;
- }
- Features().Set(EGroupByFeatures::Ordinary);
- break;
- case TRule_grouping_element::kAltGroupingElement2: {
- TGroupByClause subClause(Ctx, Mode, GroupSetContext);
- if (!subClause.OrdinaryGroupingSetList(node.GetAlt_grouping_element2().GetRule_rollup_list1().GetRule_ordinary_grouping_set_list3())) {
- return false;
- }
- auto& content = subClause.Content();
- if (!IsNodeColumnsOrNamedExpression(content, "ROLLUP")) {
- return false;
- }
+ switch (node.Alt_case()) {
+ case TRule_grouping_element::kAltGroupingElement1:
+ if (!OrdinaryGroupingSet(node.GetAlt_grouping_element1().GetRule_ordinary_grouping_set1())) {
+ return false;
+ }
+ Features().Set(EGroupByFeatures::Ordinary);
+ break;
+ case TRule_grouping_element::kAltGroupingElement2: {
+ TGroupByClause subClause(Ctx, Mode, GroupSetContext);
+ if (!subClause.OrdinaryGroupingSetList(node.GetAlt_grouping_element2().GetRule_rollup_list1().GetRule_ordinary_grouping_set_list3())) {
+ return false;
+ }
+ auto& content = subClause.Content();
+ if (!IsNodeColumnsOrNamedExpression(content, "ROLLUP")) {
+ return false;
+ }
TVector<TNodePtr> collection;
- for (auto limit = content.end(), begin = content.begin(); limit != begin; --limit) {
+ for (auto limit = content.end(), begin = content.begin(); limit != begin; --limit) {
TVector<TNodePtr> grouping(begin, limit);
- collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(grouping)));
- }
- collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(emptyContent)));
- GroupBySet.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(collection)));
- Ctx.IncrementMonCounter("sql_features", TStringBuilder() << "GroupByRollup" << content.size());
- Features().Set(EGroupByFeatures::Rollup);
- break;
- }
- case TRule_grouping_element::kAltGroupingElement3: {
- TGroupByClause subClause(Ctx, Mode, GroupSetContext);
- if (!subClause.OrdinaryGroupingSetList(node.GetAlt_grouping_element3().GetRule_cube_list1().GetRule_ordinary_grouping_set_list3())) {
- return false;
- }
- auto& content = subClause.Content();
- if (!IsNodeColumnsOrNamedExpression(content, "CUBE")) {
- return false;
- }
- if (content.size() > Ctx.PragmaGroupByCubeLimit) {
- Ctx.Error() << "GROUP BY CUBE is allowed only for " << Ctx.PragmaGroupByCubeLimit << " columns, but you use " << content.size();
- return false;
- }
+ collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(grouping)));
+ }
+ collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(emptyContent)));
+ GroupBySet.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(collection)));
+ Ctx.IncrementMonCounter("sql_features", TStringBuilder() << "GroupByRollup" << content.size());
+ Features().Set(EGroupByFeatures::Rollup);
+ break;
+ }
+ case TRule_grouping_element::kAltGroupingElement3: {
+ TGroupByClause subClause(Ctx, Mode, GroupSetContext);
+ if (!subClause.OrdinaryGroupingSetList(node.GetAlt_grouping_element3().GetRule_cube_list1().GetRule_ordinary_grouping_set_list3())) {
+ return false;
+ }
+ auto& content = subClause.Content();
+ if (!IsNodeColumnsOrNamedExpression(content, "CUBE")) {
+ return false;
+ }
+ if (content.size() > Ctx.PragmaGroupByCubeLimit) {
+ Ctx.Error() << "GROUP BY CUBE is allowed only for " << Ctx.PragmaGroupByCubeLimit << " columns, but you use " << content.size();
+ return false;
+ }
TVector<TNodePtr> collection;
- for (unsigned mask = (1 << content.size()) - 1; mask > 0; --mask) {
+ for (unsigned mask = (1 << content.size()) - 1; mask > 0; --mask) {
TVector<TNodePtr> grouping;
- for (unsigned index = 0; index < content.size(); ++index) {
- if (mask & (1 << index)) {
- grouping.push_back(content[content.size() - index - 1]);
- }
- }
- collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(grouping)));
- }
- collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(emptyContent)));
- GroupBySet.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(collection)));
- Ctx.IncrementMonCounter("sql_features", TStringBuilder() << "GroupByCube" << content.size());
- Features().Set(EGroupByFeatures::Cube);
- break;
- }
- case TRule_grouping_element::kAltGroupingElement4: {
- auto listNode = node.GetAlt_grouping_element4().GetRule_grouping_sets_specification1().GetRule_grouping_element_list4();
- TGroupByClause subClause(Ctx, Mode, GroupSetContext);
- if (!subClause.ParseList(listNode)) {
- return false;
- }
- auto& content = subClause.Content();
- if (!IsNodeColumnsOrNamedExpression(content, "GROUPING SETS")) {
- return false;
- }
+ for (unsigned index = 0; index < content.size(); ++index) {
+ if (mask & (1 << index)) {
+ grouping.push_back(content[content.size() - index - 1]);
+ }
+ }
+ collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(grouping)));
+ }
+ collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(emptyContent)));
+ GroupBySet.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(collection)));
+ Ctx.IncrementMonCounter("sql_features", TStringBuilder() << "GroupByCube" << content.size());
+ Features().Set(EGroupByFeatures::Cube);
+ break;
+ }
+ case TRule_grouping_element::kAltGroupingElement4: {
+ auto listNode = node.GetAlt_grouping_element4().GetRule_grouping_sets_specification1().GetRule_grouping_element_list4();
+ TGroupByClause subClause(Ctx, Mode, GroupSetContext);
+ if (!subClause.ParseList(listNode)) {
+ return false;
+ }
+ auto& content = subClause.Content();
+ if (!IsNodeColumnsOrNamedExpression(content, "GROUPING SETS")) {
+ return false;
+ }
TVector<TNodePtr> collection;
- bool hasEmpty = false;
- for (auto& elem: content) {
- auto elemContent = elem->ContentListPtr();
- if (elemContent) {
- if (!elemContent->empty() && elemContent->front()->ContentListPtr()) {
- for (auto& sub: *elemContent) {
- FeedCollection(sub, collection, hasEmpty);
- }
- } else {
- FeedCollection(elem, collection, hasEmpty);
- }
- } else {
+ bool hasEmpty = false;
+ for (auto& elem: content) {
+ auto elemContent = elem->ContentListPtr();
+ if (elemContent) {
+ if (!elemContent->empty() && elemContent->front()->ContentListPtr()) {
+ for (auto& sub: *elemContent) {
+ FeedCollection(sub, collection, hasEmpty);
+ }
+ } else {
+ FeedCollection(elem, collection, hasEmpty);
+ }
+ } else {
TVector<TNodePtr> elemList(1, std::move(elem));
- collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(elemList)));
- }
- }
- GroupBySet.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(collection)));
- Features().Set(EGroupByFeatures::GroupingSet);
- break;
- }
+ collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(elemList)));
+ }
+ }
+ GroupBySet.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(collection)));
+ Features().Set(EGroupByFeatures::GroupingSet);
+ break;
+ }
case TRule_grouping_element::kAltGroupingElement5: {
if (!HoppingWindow(node.GetAlt_grouping_element5().GetRule_hopping_window_specification1())) {
return false;
@@ -3567,80 +3567,80 @@ bool TGroupByClause::GroupingElement(const TRule_grouping_element& node) {
}
default:
Y_FAIL("You should change implementation according grammar changes");
- }
- return true;
-}
-
+ }
+ return true;
+}
+
void TGroupByClause::FeedCollection(const TNodePtr& elem, TVector<TNodePtr>& collection, bool& hasEmpty) const {
- auto elemContentPtr = elem->ContentListPtr();
- if (elemContentPtr && elemContentPtr->empty()) {
- if (hasEmpty) {
- return;
- }
- hasEmpty = true;
- }
- collection.push_back(elem);
-}
-
-bool TGroupByClause::OrdinaryGroupingSet(const TRule_ordinary_grouping_set& node) {
- auto namedExprNode = NamedExpr(node.GetRule_named_expr1(), EExpr::GroupBy);
- if (!namedExprNode) {
- return false;
- }
- auto nodeLabel = namedExprNode->GetLabel();
- auto contentPtr = namedExprNode->ContentListPtr();
- if (contentPtr) {
- if (nodeLabel && (contentPtr->size() != 1 || contentPtr->front()->GetLabel())) {
- Ctx.Error() << "Unable to use aliases for list of named expressions";
- Ctx.IncrementMonCounter("sql_errors", "GroupByAliasForListOfExpressions");
- return false;
- }
- for (auto& content: *contentPtr) {
- auto label = content->GetLabel();
- if (!label) {
+ auto elemContentPtr = elem->ContentListPtr();
+ if (elemContentPtr && elemContentPtr->empty()) {
+ if (hasEmpty) {
+ return;
+ }
+ hasEmpty = true;
+ }
+ collection.push_back(elem);
+}
+
+bool TGroupByClause::OrdinaryGroupingSet(const TRule_ordinary_grouping_set& node) {
+ auto namedExprNode = NamedExpr(node.GetRule_named_expr1(), EExpr::GroupBy);
+ if (!namedExprNode) {
+ return false;
+ }
+ auto nodeLabel = namedExprNode->GetLabel();
+ auto contentPtr = namedExprNode->ContentListPtr();
+ if (contentPtr) {
+ if (nodeLabel && (contentPtr->size() != 1 || contentPtr->front()->GetLabel())) {
+ Ctx.Error() << "Unable to use aliases for list of named expressions";
+ Ctx.IncrementMonCounter("sql_errors", "GroupByAliasForListOfExpressions");
+ return false;
+ }
+ for (auto& content: *contentPtr) {
+ auto label = content->GetLabel();
+ if (!label) {
if (content->GetColumnName()) {
namedExprNode->AssumeColumn();
continue;
}
- content->SetLabel(label = GenerateGroupByExprName());
- }
- if (!AddAlias(label, content)) {
- return false;
- }
- content = BuildColumn(content->GetPos(), label);
- }
- } else {
+ content->SetLabel(label = GenerateGroupByExprName());
+ }
+ if (!AddAlias(label, content)) {
+ return false;
+ }
+ content = BuildColumn(content->GetPos(), label);
+ }
+ } else {
if (!nodeLabel && namedExprNode->GetColumnName()) {
namedExprNode->AssumeColumn();
}
if (!nodeLabel && !namedExprNode->GetColumnName()) {
- namedExprNode->SetLabel(nodeLabel = GenerateGroupByExprName());
- }
- if (nodeLabel) {
- if (!AddAlias(nodeLabel, namedExprNode)) {
- return false;
- }
- namedExprNode = BuildColumn(namedExprNode->GetPos(), nodeLabel);
- }
- }
- GroupBySet.emplace_back(std::move(namedExprNode));
- return true;
-}
-
-bool TGroupByClause::OrdinaryGroupingSetList(const TRule_ordinary_grouping_set_list& node) {
- if (!OrdinaryGroupingSet(node.GetRule_ordinary_grouping_set1())) {
- return false;
- }
- for (auto& block: node.GetBlock2()) {
- if (!OrdinaryGroupingSet(block.GetRule_ordinary_grouping_set2())) {
- return false;
- }
- }
- return true;
-}
-
+ namedExprNode->SetLabel(nodeLabel = GenerateGroupByExprName());
+ }
+ if (nodeLabel) {
+ if (!AddAlias(nodeLabel, namedExprNode)) {
+ return false;
+ }
+ namedExprNode = BuildColumn(namedExprNode->GetPos(), nodeLabel);
+ }
+ }
+ GroupBySet.emplace_back(std::move(namedExprNode));
+ return true;
+}
+
+bool TGroupByClause::OrdinaryGroupingSetList(const TRule_ordinary_grouping_set_list& node) {
+ if (!OrdinaryGroupingSet(node.GetRule_ordinary_grouping_set1())) {
+ return false;
+ }
+ for (auto& block: node.GetBlock2()) {
+ if (!OrdinaryGroupingSet(block.GetRule_ordinary_grouping_set2())) {
+ return false;
+ }
+ }
+ return true;
+}
+
bool TGroupByClause::HoppingWindow(const TRule_hopping_window_specification& node) {
if (HoppingWindowSpec) {
Ctx.Error() << "Duplicate hopping window specification.";
@@ -3705,83 +3705,83 @@ bool TGroupByClause::HoppingWindow(const TRule_hopping_window_specification& nod
}
bool TGroupByClause::IsNodeColumnsOrNamedExpression(const TVector<TNodePtr>& content, const TString& construction) const {
- for (const auto& node: content) {
- if (IsAutogenerated(node->GetColumnName())) {
- Ctx.Error() << "You should use in " << construction << " either expression with required alias either column name or used alias.";
- Ctx.IncrementMonCounter("sql_errors", "GroupBySetNoAliasOrColumn");
- return false;
- }
- }
- return true;
-}
-
-TGroupByClause::TGroupingSetFeatures& TGroupByClause::Features() {
- return GroupSetContext->GroupFeatures;
-}
-
-const TGroupByClause::TGroupingSetFeatures& TGroupByClause::Features() const {
- return GroupSetContext->GroupFeatures;
-}
-
+ for (const auto& node: content) {
+ if (IsAutogenerated(node->GetColumnName())) {
+ Ctx.Error() << "You should use in " << construction << " either expression with required alias either column name or used alias.";
+ Ctx.IncrementMonCounter("sql_errors", "GroupBySetNoAliasOrColumn");
+ return false;
+ }
+ }
+ return true;
+}
+
+TGroupByClause::TGroupingSetFeatures& TGroupByClause::Features() {
+ return GroupSetContext->GroupFeatures;
+}
+
+const TGroupByClause::TGroupingSetFeatures& TGroupByClause::Features() const {
+ return GroupSetContext->GroupFeatures;
+}
+
bool TGroupByClause::AddAlias(const TString& label, const TNodePtr& node) {
if (Aliases().contains(label)) {
- Ctx.Error() << "Duplicated aliases not allowed";
- Ctx.IncrementMonCounter("sql_errors", "GroupByDuplicateAliases");
- return false;
- }
- Aliases().emplace(label, node);
- return true;
-}
-
+ Ctx.Error() << "Duplicated aliases not allowed";
+ Ctx.IncrementMonCounter("sql_errors", "GroupByDuplicateAliases");
+ return false;
+ }
+ Aliases().emplace(label, node);
+ return true;
+}
+
TString TGroupByClause::GenerateGroupByExprName() {
- return TStringBuilder() << AutogenerateNamePrefix << GroupSetContext->UnnamedCount++;
-}
-
+ return TStringBuilder() << AutogenerateNamePrefix << GroupSetContext->UnnamedCount++;
+}
+
bool TGroupByClause::IsAutogenerated(const TString* name) const {
return name && name->StartsWith(AutogenerateNamePrefix);
-}
-
+}
+
TSourcePtr TSqlSelect::SelectKind(const TRule_select_kind_partial& node, TPosition& selectPos) {
auto source = SelectKind(node.GetRule_select_kind1(), selectPos);
- if (!source) {
- return {};
- }
- TPosition startPos(Ctx.Pos());
- /// LIMIT INTEGER block
- TNodePtr skipTake;
- if (node.HasBlock2()) {
- auto block = node.GetBlock2();
-
- Token(block.GetToken1());
- TPosition pos(Ctx.Pos());
-
+ if (!source) {
+ return {};
+ }
+ TPosition startPos(Ctx.Pos());
+ /// LIMIT INTEGER block
+ TNodePtr skipTake;
+ if (node.HasBlock2()) {
+ auto block = node.GetBlock2();
+
+ Token(block.GetToken1());
+ TPosition pos(Ctx.Pos());
+
TSqlExpression takeExpr(Ctx, Mode);
auto take = takeExpr.Build(block.GetRule_expr2());
- if (!take) {
+ if (!take) {
return{};
- }
+ }
- TNodePtr skip;
- if (block.HasBlock3()) {
+ TNodePtr skip;
+ if (block.HasBlock3()) {
TSqlExpression skipExpr(Ctx, Mode);
skip = skipExpr.Build(block.GetBlock3().GetRule_expr2());
- if (!skip) {
- return {};
- }
- if (Token(block.GetBlock3().GetToken1()) == ",") {
- // LIMIT skip, take
- skip.Swap(take);
- Ctx.IncrementMonCounter("sql_features", "LimitSkipTake");
- } else {
- Ctx.IncrementMonCounter("sql_features", "LimitOffset");
- }
- }
- skipTake = BuildSkipTake(pos, skip, take);
- Ctx.IncrementMonCounter("sql_features", "Limit");
- }
- return BuildSelect(startPos, std::move(source), skipTake);
-}
-
+ if (!skip) {
+ return {};
+ }
+ if (Token(block.GetBlock3().GetToken1()) == ",") {
+ // LIMIT skip, take
+ skip.Swap(take);
+ Ctx.IncrementMonCounter("sql_features", "LimitSkipTake");
+ } else {
+ Ctx.IncrementMonCounter("sql_features", "LimitOffset");
+ }
+ }
+ skipTake = BuildSkipTake(pos, skip, take);
+ Ctx.IncrementMonCounter("sql_features", "Limit");
+ }
+ return BuildSelect(startPos, std::move(source), skipTake);
+}
+
TSourcePtr TSqlSelect::SelectKind(const TRule_select_kind& node, TPosition& selectPos) {
const bool discard = node.HasBlock1();
const bool hasLabel = node.HasBlock3();
@@ -3815,7 +3815,7 @@ TSourcePtr TSqlSelect::SelectKind(const TRule_select_kind& node, TPosition& sele
break;
case TRule_select_kind_TBlock2::kAlt3:
res = SelectCore(node.GetBlock2().GetAlt3().GetRule_select_core1(), settings, selectPos);
- break;
+ break;
default:
Y_FAIL("You should change implementation according grammar changes");
}
@@ -3824,13 +3824,13 @@ TSourcePtr TSqlSelect::SelectKind(const TRule_select_kind& node, TPosition& sele
}
TSourcePtr TSqlSelect::SelectKind(const TRule_select_kind_parenthesis& node, TPosition& selectPos) {
- if (node.Alt_case() == TRule_select_kind_parenthesis::kAltSelectKindParenthesis1) {
+ if (node.Alt_case() == TRule_select_kind_parenthesis::kAltSelectKindParenthesis1) {
return SelectKind(node.GetAlt_select_kind_parenthesis1().GetRule_select_kind_partial1(), selectPos);
- } else {
+ } else {
return SelectKind(node.GetAlt_select_kind_parenthesis2().GetRule_select_kind_partial2(), selectPos);
- }
-}
-
+ }
+}
+
TSourcePtr TSqlSelect::Build(const TRule_select_stmt& node, TPosition& selectPos) {
auto res = SelectKind(node.GetRule_select_kind_parenthesis1(), selectPos);
if (!res) {
@@ -3846,17 +3846,17 @@ TSourcePtr TSqlSelect::Build(const TRule_select_stmt& node, TPosition& selectPos
return nullptr;
}
switch (b.GetRule_select_op1().Alt_case()) {
- case TRule_select_op::kAltSelectOp1: {
- const bool isUnionAll = b.GetRule_select_op1().GetAlt_select_op1().HasBlock2();
- if (!isUnionAll) {
- Token(b.GetRule_select_op1().GetAlt_select_op1().GetToken1());
- Ctx.Error() << "UNION without quantifier ALL is not supported yet. Did you mean UNION ALL?";
- return nullptr;
- } else {
+ case TRule_select_op::kAltSelectOp1: {
+ const bool isUnionAll = b.GetRule_select_op1().GetAlt_select_op1().HasBlock2();
+ if (!isUnionAll) {
+ Token(b.GetRule_select_op1().GetAlt_select_op1().GetToken1());
+ Ctx.Error() << "UNION without quantifier ALL is not supported yet. Did you mean UNION ALL?";
+ return nullptr;
+ } else {
sources.emplace_back(std::move(next));
- }
+ }
break;
- }
+ }
default:
Ctx.Error() << "INTERSECT and EXCEPT are not implemented yet";
return nullptr;
@@ -3911,15 +3911,15 @@ bool TSqlIntoValues::BuildValuesRow(const TRule_values_source_row& inRow, TVecto
TSourcePtr TSqlIntoValues::ValuesSource(const TRule_values_source& node, TVector<TString>& columnsHint,
const TString& operationName)
{
- Ctx.IncrementMonCounter("sql_features", "ValuesSource");
+ Ctx.IncrementMonCounter("sql_features", "ValuesSource");
TPosition pos(Ctx.Pos());
- switch (node.Alt_case()) {
- case TRule_values_source::kAltValuesSource1: {
+ switch (node.Alt_case()) {
+ case TRule_values_source::kAltValuesSource1: {
TVector<TVector<TNodePtr>> rows {{}};
const auto& rowList = node.GetAlt_values_source1().GetRule_values_source_row_list2();
if (!BuildValuesRow(rowList.GetRule_values_source_row1(), rows.back())) {
- return nullptr;
+ return nullptr;
}
for (const auto& valuesSourceRow: rowList.GetBlock2()) {
@@ -3931,19 +3931,19 @@ TSourcePtr TSqlIntoValues::ValuesSource(const TRule_values_source& node, TVector
return BuildWriteValues(pos, operationName, columnsHint, rows);
}
- case TRule_values_source::kAltValuesSource2: {
+ case TRule_values_source::kAltValuesSource2: {
TSqlSelect select(Ctx, Mode);
TPosition selectPos;
auto source = select.Build(node.GetAlt_values_source2().GetRule_select_stmt1(), selectPos);
if (!source) {
return nullptr;
}
- return BuildWriteValues(pos, "UPDATE", columnsHint, std::move(source));
+ return BuildWriteValues(pos, "UPDATE", columnsHint, std::move(source));
}
- default:
- Ctx.IncrementMonCounter("sql_errors", "UnknownValuesSource");
- AltNotImplemented("values_source", node);
- return nullptr;
+ default:
+ Ctx.IncrementMonCounter("sql_errors", "UnknownValuesSource");
+ AltNotImplemented("values_source", node);
+ return nullptr;
}
}
@@ -3967,16 +3967,16 @@ private:
TString SqlIntoUserModeStr;
};
-TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) {
+TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) {
static const TMap<TString, ESQLWriteColumnMode> str2Mode = {
- {"InsertInto", ESQLWriteColumnMode::InsertInto},
+ {"InsertInto", ESQLWriteColumnMode::InsertInto},
{"InsertOrAbortInto", ESQLWriteColumnMode::InsertOrAbortInto},
{"InsertOrIgnoreInto", ESQLWriteColumnMode::InsertOrIgnoreInto},
{"InsertOrRevertInto", ESQLWriteColumnMode::InsertOrRevertInto},
- {"UpsertInto", ESQLWriteColumnMode::UpsertInto},
- {"ReplaceInto", ESQLWriteColumnMode::ReplaceInto},
+ {"UpsertInto", ESQLWriteColumnMode::UpsertInto},
+ {"ReplaceInto", ESQLWriteColumnMode::ReplaceInto},
{"InsertIntoWithTruncate", ESQLWriteColumnMode::InsertIntoWithTruncate}
- };
+ };
auto& modeBlock = node.GetBlock1();
@@ -4109,18 +4109,18 @@ TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) {
);
}
- if (withTruncate) {
- if (SqlIntoModeStr != "InsertInto") {
- Error() << "Unable " << SqlIntoUserModeStr << " with truncate mode";
- return nullptr;
- }
- SqlIntoModeStr += "WithTruncate";
- SqlIntoUserModeStr += " ... WITH TRUNCATE";
- }
- const auto iterMode = str2Mode.find(SqlIntoModeStr);
- YQL_ENSURE(iterMode != str2Mode.end(), "Invalid sql write mode string: " << SqlIntoModeStr);
+ if (withTruncate) {
+ if (SqlIntoModeStr != "InsertInto") {
+ Error() << "Unable " << SqlIntoUserModeStr << " with truncate mode";
+ return nullptr;
+ }
+ SqlIntoModeStr += "WithTruncate";
+ SqlIntoUserModeStr += " ... WITH TRUNCATE";
+ }
+ const auto iterMode = str2Mode.find(SqlIntoModeStr);
+ YQL_ENSURE(iterMode != str2Mode.end(), "Invalid sql write mode string: " << SqlIntoModeStr);
const auto SqlIntoMode = iterMode->second;
-
+
TPosition pos(Ctx.Pos());
TNodePtr tableKey = BuildTableKey(pos, cluster, nameOrAt.second, nameOrAt.first ? "@" : "");
@@ -4128,13 +4128,13 @@ TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) {
Ctx.IncrementMonCounter("sql_insert_clusters", table.Cluster);
auto values = TSqlIntoValues(Ctx, Mode).Build(node.GetRule_into_values_source4(), SqlIntoUserModeStr);
- if (!values) {
- return nullptr;
- }
+ if (!values) {
+ return nullptr;
+ }
if (!ValidateServiceName(node, table, SqlIntoMode, GetPos(modeTokens[0]))) {
- return nullptr;
- }
- Ctx.IncrementMonCounter("sql_features", SqlIntoModeStr);
+ return nullptr;
+ }
+ Ctx.IncrementMonCounter("sql_features", SqlIntoModeStr);
TNodePtr options;
if (eraseColumns) {
@@ -4142,8 +4142,8 @@ TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) {
}
return BuildWriteColumns(pos, table, ToWriteColumnsMode(SqlIntoMode), std::move(values), std::move(options));
-}
-
+}
+
bool TSqlIntoTable::ValidateServiceName(const TRule_into_table_stmt& node, const TTableRef& table,
ESQLWriteColumnMode mode, const TPosition& pos) {
Y_UNUSED(node);
@@ -4152,7 +4152,7 @@ bool TSqlIntoTable::ValidateServiceName(const TRule_into_table_stmt& node, const
}
auto serviceName = to_lower(table.ServiceName(Ctx));
const bool isMapReduce = serviceName == YtProviderName;
- const bool isKikimr = serviceName == KikimrProviderName;
+ const bool isKikimr = serviceName == KikimrProviderName;
const bool isRtmr = serviceName == RtmrProviderName;
const bool isStat = serviceName == StatProviderName;
@@ -4168,18 +4168,18 @@ bool TSqlIntoTable::ValidateServiceName(const TRule_into_table_stmt& node, const
}
}
- if (isMapReduce) {
- if (mode == ESQLWriteColumnMode::ReplaceInto) {
+ if (isMapReduce) {
+ if (mode == ESQLWriteColumnMode::ReplaceInto) {
Ctx.Error(pos) << "Meaning of REPLACE INTO has been changed, now you should use INSERT INTO <table> WITH TRUNCATE ... for " << serviceName;
- Ctx.IncrementMonCounter("sql_errors", "ReplaceIntoConflictUsage");
+ Ctx.IncrementMonCounter("sql_errors", "ReplaceIntoConflictUsage");
return false;
- }
- } else if (isKikimr) {
+ }
+ } else if (isKikimr) {
if (mode == ESQLWriteColumnMode::InsertIntoWithTruncate) {
Ctx.Error(pos) << "INSERT INTO WITH TRUNCATE is not supported for " << serviceName << " tables";
- Ctx.IncrementMonCounter("sql_errors", TStringBuilder() << SqlIntoUserModeStr << "UnsupportedFor" << serviceName);
- return false;
- }
+ Ctx.IncrementMonCounter("sql_errors", TStringBuilder() << SqlIntoUserModeStr << "UnsupportedFor" << serviceName);
+ return false;
+ }
} else if (isRtmr) {
if (mode != ESQLWriteColumnMode::InsertInto) {
Ctx.Error(pos) << SqlIntoUserModeStr << " is unsupported for " << serviceName;
@@ -4192,11 +4192,11 @@ bool TSqlIntoTable::ValidateServiceName(const TRule_into_table_stmt& node, const
Ctx.IncrementMonCounter("sql_errors", TStringBuilder() << SqlIntoUserModeStr << "UnsupportedFor" << serviceName);
return false;
}
- }
+ }
+
+ return true;
+}
- return true;
-}
-
class TSqlQuery: public TSqlTranslation {
public:
TSqlQuery(TContext& ctx, NSQLTranslation::ESqlMode mode, bool topLevel)
@@ -4209,42 +4209,42 @@ public:
bool Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& core);
private:
- bool DeclareStatement(const TRule_declare_stmt& stmt);
- bool ExportStatement(const TRule_export_stmt& stmt);
+ bool DeclareStatement(const TRule_declare_stmt& stmt);
+ bool ExportStatement(const TRule_export_stmt& stmt);
bool AlterTableAddColumns(TVector<TNodePtr>& blocks, const TRule_alter_table_add_column& node, const TTableRef& tr);
bool AlterTableDropColumn(TVector<TNodePtr>& blocks, const TRule_alter_table_drop_column& node, const TTableRef& tr);
TNodePtr PragmaStatement(const TRule_pragma_stmt& stmt, bool& success);
void AddStatementToBlocks(TVector<TNodePtr>& blocks, TNodePtr node);
- TNodePtr Build(const TRule_delete_stmt& stmt);
-
- TNodePtr Build(const TRule_update_stmt& stmt);
- TSourcePtr Build(const TRule_set_clause_choice& stmt);
+ TNodePtr Build(const TRule_delete_stmt& stmt);
+
+ TNodePtr Build(const TRule_update_stmt& stmt);
+ TSourcePtr Build(const TRule_set_clause_choice& stmt);
bool FillSetClause(const TRule_set_clause& node, TVector<TString>& targetList, TVector<TNodePtr>& values);
- TSourcePtr Build(const TRule_set_clause_list& stmt);
- TSourcePtr Build(const TRule_multiple_column_assignment& stmt);
- TNodePtr FlexType(TTranslation& ctx, const TRule_flex_type& node);
-
- template<class TNode>
+ TSourcePtr Build(const TRule_set_clause_list& stmt);
+ TSourcePtr Build(const TRule_multiple_column_assignment& stmt);
+ TNodePtr FlexType(TTranslation& ctx, const TRule_flex_type& node);
+
+ template<class TNode>
void ParseStatementName(const TNode& node, TString& internalStatementName, TString& humanStatementName) {
internalStatementName.clear();
humanStatementName.clear();
- const auto& descr = AltDescription(node);
+ const auto& descr = AltDescription(node);
TVector<TString> parts;
- const auto pos = descr.find(": ");
+ const auto pos = descr.find(": ");
Y_VERIFY_DEBUG(pos != TString::npos);
Split(TString(descr.begin() + pos + 2, descr.end()), "_", parts);
- Y_VERIFY_DEBUG(parts.size() > 1);
- parts.pop_back();
- for (auto& part: parts) {
- part.to_upper(0, 1);
+ Y_VERIFY_DEBUG(parts.size() > 1);
+ parts.pop_back();
+ for (auto& part: parts) {
+ part.to_upper(0, 1);
internalStatementName += part;
if (!humanStatementName.empty()) {
humanStatementName += ' ';
- }
+ }
humanStatementName += to_upper(part);
- }
- }
+ }
+ }
const bool TopLevel;
};
@@ -4258,12 +4258,12 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
TString internalStatementName;
TString humanStatementName;
ParseStatementName(core, internalStatementName, humanStatementName);
- const auto& altCase = core.Alt_case();
+ const auto& altCase = core.Alt_case();
if (Mode == NSQLTranslation::ESqlMode::LIMITED_VIEW && (altCase >= TRule_sql_stmt_core::kAltSqlStmtCore4 &&
altCase != TRule_sql_stmt_core::kAltSqlStmtCore13)) {
Error() << humanStatementName << " statement is not supported in limited views";
- return false;
- }
+ return false;
+ }
if (Mode == NSQLTranslation::ESqlMode::SUBQUERY && (altCase >= TRule_sql_stmt_core::kAltSqlStmtCore4 &&
altCase != TRule_sql_stmt_core::kAltSqlStmtCore13 && altCase != TRule_sql_stmt_core::kAltSqlStmtCore6 &&
@@ -4271,12 +4271,12 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
Error() << humanStatementName << " statement is not supported in subqueries";
return false;
}
- switch (altCase) {
+ switch (altCase) {
case TRule_sql_stmt_core::kAltSqlStmtCore1: {
bool success = false;
TNodePtr nodeExpr = PragmaStatement(core.GetAlt_sql_stmt_core1().GetRule_pragma_stmt1(), success);
if (!success) {
- return false;
+ return false;
}
if (nodeExpr) {
AddStatementToBlocks(blocks, nodeExpr);
@@ -4284,7 +4284,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
break;
}
case TRule_sql_stmt_core::kAltSqlStmtCore2: {
- Ctx.BodyPart();
+ Ctx.BodyPart();
TSqlSelect select(Ctx, Mode);
TPosition pos;
auto source = select.Build(core.GetAlt_sql_stmt_core2().GetRule_select_stmt1(), pos);
@@ -4296,19 +4296,19 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
break;
}
case TRule_sql_stmt_core::kAltSqlStmtCore3: {
- Ctx.BodyPart();
+ Ctx.BodyPart();
TVector<TString> names;
auto nodeExpr = NamedNode(core.GetAlt_sql_stmt_core3().GetRule_named_nodes_stmt1(), names);
- if (!nodeExpr) {
+ if (!nodeExpr) {
return false;
}
TVector<TNodePtr> nodes;
- auto subquery = nodeExpr->GetSource();
- if (subquery) {
- const auto alias = Ctx.MakeName("subquerynode");
- const auto ref = Ctx.MakeName("subquery");
+ auto subquery = nodeExpr->GetSource();
+ if (subquery) {
+ const auto alias = Ctx.MakeName("subquerynode");
+ const auto ref = Ctx.MakeName("subquery");
blocks.push_back(BuildSubquery(subquery, alias, Mode == NSQLTranslation::ESqlMode::SUBQUERY, names.size() == 1 ? -1 : names.size()));
- blocks.back()->SetLabel(ref);
+ blocks.back()->SetLabel(ref);
for (size_t i = 0; i < names.size(); ++i) {
nodes.push_back(BuildSubqueryRef(blocks.back(), ref, names.size() == 1 ? -1 : i));
@@ -4324,7 +4324,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
} else {
nodes.push_back(std::move(nodeExpr));
}
- }
+ }
for (size_t i = 0; i < names.size(); ++i) {
PushNamedNode(names[i], nodes[i]);
@@ -4332,7 +4332,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
break;
}
case TRule_sql_stmt_core::kAltSqlStmtCore4: {
- Ctx.BodyPart();
+ Ctx.BodyPart();
const auto& rule = core.GetAlt_sql_stmt_core4().GetRule_create_table_stmt1();
TTableRef tr(SimpleTableRefImpl(rule.GetRule_simple_table_ref3(), Mode, *this));
@@ -4342,19 +4342,19 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
TVector<std::pair<TIdentifier, bool>> orderByColumns;
if (!CreateTableEntry(rule.GetRule_create_table_entry5(), *this, columns, pkColumns, partitionByColumns, orderByColumns)) {
- return false;
- }
+ return false;
+ }
for (auto& block: rule.GetBlock6()) {
if (!CreateTableEntry(block.GetRule_create_table_entry2(), *this, columns, pkColumns, partitionByColumns, orderByColumns)) {
- return false;
- }
+ return false;
+ }
}
AddStatementToBlocks(blocks, BuildCreateTable(Ctx.Pos(), tr, columns, pkColumns, partitionByColumns, orderByColumns));
break;
}
case TRule_sql_stmt_core::kAltSqlStmtCore5: {
- Ctx.BodyPart();
+ Ctx.BodyPart();
const auto& rule = core.GetAlt_sql_stmt_core5().GetRule_drop_table_stmt1();
if (rule.HasBlock3()) {
Context().Error(GetPos(rule.GetToken1())) << "IF EXISTS in " << humanStatementName
@@ -4365,72 +4365,72 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
AddStatementToBlocks(blocks, BuildDropTable(Ctx.Pos(), tr));
break;
}
- case TRule_sql_stmt_core::kAltSqlStmtCore6: {
- const auto& rule = core.GetAlt_sql_stmt_core6().GetRule_use_stmt1();
- Token(rule.GetToken1());
+ case TRule_sql_stmt_core::kAltSqlStmtCore6: {
+ const auto& rule = core.GetAlt_sql_stmt_core6().GetRule_use_stmt1();
+ Token(rule.GetToken1());
Ctx.CurrCluster = IdOrStringAsCluster(rule.GetRule_id_or_string2(), *this);
if (!Ctx.CurrCluster) {
return false;
}
- break;
- }
- case TRule_sql_stmt_core::kAltSqlStmtCore7: {
- Ctx.BodyPart();
- TSqlIntoTable intoTable(Ctx, Mode);
- TNodePtr block(intoTable.Build(core.GetAlt_sql_stmt_core7().GetRule_into_table_stmt1()));
- if (!block) {
+ break;
+ }
+ case TRule_sql_stmt_core::kAltSqlStmtCore7: {
+ Ctx.BodyPart();
+ TSqlIntoTable intoTable(Ctx, Mode);
+ TNodePtr block(intoTable.Build(core.GetAlt_sql_stmt_core7().GetRule_into_table_stmt1()));
+ if (!block) {
return false;
}
- blocks.emplace_back(block);
- break;
- }
- case TRule_sql_stmt_core::kAltSqlStmtCore8: {
- Ctx.BodyPart();
+ blocks.emplace_back(block);
+ break;
+ }
+ case TRule_sql_stmt_core::kAltSqlStmtCore8: {
+ Ctx.BodyPart();
const auto& rule = core.GetAlt_sql_stmt_core8().GetRule_commit_stmt1();
Token(rule.GetToken1());
- blocks.emplace_back(BuildCommitClusters(Ctx.Pos()));
+ blocks.emplace_back(BuildCommitClusters(Ctx.Pos()));
break;
}
- case TRule_sql_stmt_core::kAltSqlStmtCore9: {
- Ctx.BodyPart();
- auto updateNode = Build(core.GetAlt_sql_stmt_core9().GetRule_update_stmt1());
- if (!updateNode) {
- return false;
- }
+ case TRule_sql_stmt_core::kAltSqlStmtCore9: {
+ Ctx.BodyPart();
+ auto updateNode = Build(core.GetAlt_sql_stmt_core9().GetRule_update_stmt1());
+ if (!updateNode) {
+ return false;
+ }
AddStatementToBlocks(blocks, updateNode);
- break;
- }
- case TRule_sql_stmt_core::kAltSqlStmtCore10: {
- Ctx.BodyPart();
- auto deleteNode = Build(core.GetAlt_sql_stmt_core10().GetRule_delete_stmt1());
- if (!deleteNode) {
- return false;
- }
- blocks.emplace_back(deleteNode);
- break;
- }
+ break;
+ }
+ case TRule_sql_stmt_core::kAltSqlStmtCore10: {
+ Ctx.BodyPart();
+ auto deleteNode = Build(core.GetAlt_sql_stmt_core10().GetRule_delete_stmt1());
+ if (!deleteNode) {
+ return false;
+ }
+ blocks.emplace_back(deleteNode);
+ break;
+ }
case TRule_sql_stmt_core::kAltSqlStmtCore11: {
- Ctx.BodyPart();
+ Ctx.BodyPart();
const auto& rule = core.GetAlt_sql_stmt_core11().GetRule_rollback_stmt1();
Token(rule.GetToken1());
- blocks.emplace_back(BuildRollbackClusters(Ctx.Pos()));
+ blocks.emplace_back(BuildRollbackClusters(Ctx.Pos()));
break;
}
- case TRule_sql_stmt_core::kAltSqlStmtCore12:
- if (!DeclareStatement(core.GetAlt_sql_stmt_core12().GetRule_declare_stmt1())) {
- return false;
- }
- break;
- case TRule_sql_stmt_core::kAltSqlStmtCore13:
- if (!ImportStatement(core.GetAlt_sql_stmt_core13().GetRule_import_stmt1())) {
- return false;
- }
- break;
- case TRule_sql_stmt_core::kAltSqlStmtCore14:
- if (!ExportStatement(core.GetAlt_sql_stmt_core14().GetRule_export_stmt1())) {
- return false;
- }
- break;
+ case TRule_sql_stmt_core::kAltSqlStmtCore12:
+ if (!DeclareStatement(core.GetAlt_sql_stmt_core12().GetRule_declare_stmt1())) {
+ return false;
+ }
+ break;
+ case TRule_sql_stmt_core::kAltSqlStmtCore13:
+ if (!ImportStatement(core.GetAlt_sql_stmt_core13().GetRule_import_stmt1())) {
+ return false;
+ }
+ break;
+ case TRule_sql_stmt_core::kAltSqlStmtCore14:
+ if (!ExportStatement(core.GetAlt_sql_stmt_core14().GetRule_export_stmt1())) {
+ return false;
+ }
+ break;
case TRule_sql_stmt_core::kAltSqlStmtCore15: {
Ctx.BodyPart();
const auto& rule = core.GetAlt_sql_stmt_core15().GetRule_alter_table_stmt1();
@@ -4505,48 +4505,48 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
return !Ctx.HasPendingErrors;
}
-bool TSqlQuery::DeclareStatement(const TRule_declare_stmt& stmt) {
- TNodePtr defaultValue;
- if (stmt.HasBlock5()) {
- TSqlExpression sqlExpr(Ctx, Mode);
- if (!(defaultValue = sqlExpr.LiteralExpr(stmt.GetBlock5().GetRule_literal_value2()))) {
- return false;
- }
- }
- if (defaultValue) {
- Error() << "DEFAULT value not supported yet";
- return false;
- }
- if (!Ctx.IsParseHeading()) {
- Error() << "DECLARE statement should be in beginning of query, but it's possible to use PRAGMA or USE before it";
- return false;
- }
- const auto varName = NamedNodeImpl(stmt.GetRule_bind_parameter2(), *this);
- const auto varPos = Ctx.Pos();
- const auto typeNode = FlexType(*this, stmt.GetRule_flex_type4());
- if (!typeNode) {
- return false;
- }
- if (!Ctx.DeclareVariable(varName, typeNode)) {
- return false;
- }
- PushNamedNode(varName, BuildAtom(varPos, varName));
- return true;
-}
-
-bool TSqlQuery::ExportStatement(const TRule_export_stmt& stmt) {
+bool TSqlQuery::DeclareStatement(const TRule_declare_stmt& stmt) {
+ TNodePtr defaultValue;
+ if (stmt.HasBlock5()) {
+ TSqlExpression sqlExpr(Ctx, Mode);
+ if (!(defaultValue = sqlExpr.LiteralExpr(stmt.GetBlock5().GetRule_literal_value2()))) {
+ return false;
+ }
+ }
+ if (defaultValue) {
+ Error() << "DEFAULT value not supported yet";
+ return false;
+ }
+ if (!Ctx.IsParseHeading()) {
+ Error() << "DECLARE statement should be in beginning of query, but it's possible to use PRAGMA or USE before it";
+ return false;
+ }
+ const auto varName = NamedNodeImpl(stmt.GetRule_bind_parameter2(), *this);
+ const auto varPos = Ctx.Pos();
+ const auto typeNode = FlexType(*this, stmt.GetRule_flex_type4());
+ if (!typeNode) {
+ return false;
+ }
+ if (!Ctx.DeclareVariable(varName, typeNode)) {
+ return false;
+ }
+ PushNamedNode(varName, BuildAtom(varPos, varName));
+ return true;
+}
+
+bool TSqlQuery::ExportStatement(const TRule_export_stmt& stmt) {
if (Mode != NSQLTranslation::ESqlMode::LIBRARY || !TopLevel) {
Error() << "EXPORT statement should be used only in a library on the top level";
return false;
}
TVector<TString> bindNames;
- if (!BindList(stmt.GetRule_bind_parameter_list2(), bindNames)) {
- return false;
- }
- return Ctx.AddExports(bindNames);
-}
-
+ if (!BindList(stmt.GetRule_bind_parameter_list2(), bindNames)) {
+ return false;
+ }
+ return Ctx.AddExports(bindNames);
+}
+
bool TSqlQuery::AlterTableAddColumns(TVector<TNodePtr>& blocks, const TRule_alter_table_add_column& rule, const TTableRef& tr) {
TVector<TColumnSchema> columns;
@@ -4560,14 +4560,14 @@ bool TSqlQuery::AlterTableAddColumns(TVector<TNodePtr>& blocks, const TRule_alte
}
bool TSqlQuery::AlterTableDropColumn(TVector<TNodePtr>& blocks, const TRule_alter_table_drop_column& node, const TTableRef& tr) {
- TString name = Id(node.GetRule_id3(), *this);
+ TString name = Id(node.GetRule_id3(), *this);
TColumnSchema column(Ctx.Pos(), name, "", false, false);
AddStatementToBlocks(blocks, BuildAlterTable(Ctx.Pos(), tr, TVector<TColumnSchema>{column}, EAlterTableIntentnt::DropColumn));
return true;
}
TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success) {
- success = false;
+ success = false;
const TString& prefix = OptIdPrefixAsStr(stmt.GetRule_opt_id_prefix2(), *this);
const TString& lowerPrefix = to_lower(prefix);
const TString pragma(IdOrString(stmt.GetRule_id_or_string3(), *this));
@@ -4578,29 +4578,29 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
Ctx.IncrementMonCounter("sql_errors", "NormalizePragmaError");
return {};
}
-
+
TVector<TDeferredAtom> values;
TVector<const TRule_pragma_value*> pragmaValues;
bool pragmaValueDefault = false;
- if (stmt.GetBlock4().HasAlt1()) {
- pragmaValues.push_back(&stmt.GetBlock4().GetAlt1().GetRule_pragma_value2());
- }
- else if (stmt.GetBlock4().HasAlt2()) {
- pragmaValues.push_back(&stmt.GetBlock4().GetAlt2().GetRule_pragma_value2());
- for (auto& additionalValue : stmt.GetBlock4().GetAlt2().GetBlock3()) {
- pragmaValues.push_back(&additionalValue.GetRule_pragma_value2());
- }
- }
-
+ if (stmt.GetBlock4().HasAlt1()) {
+ pragmaValues.push_back(&stmt.GetBlock4().GetAlt1().GetRule_pragma_value2());
+ }
+ else if (stmt.GetBlock4().HasAlt2()) {
+ pragmaValues.push_back(&stmt.GetBlock4().GetAlt2().GetRule_pragma_value2());
+ for (auto& additionalValue : stmt.GetBlock4().GetAlt2().GetBlock3()) {
+ pragmaValues.push_back(&additionalValue.GetRule_pragma_value2());
+ }
+ }
+
const bool withConfigure = prefix || normalizedPragma == "file" || normalizedPragma == "folder" || normalizedPragma == "udf";
const bool hasLexicalScope = withConfigure || normalizedPragma == "classicdivision";
- for (auto pragmaValue : pragmaValues) {
- if (pragmaValue->HasAlt_pragma_value3()) {
+ for (auto pragmaValue : pragmaValues) {
+ if (pragmaValue->HasAlt_pragma_value3()) {
values.push_back(TDeferredAtom(Ctx.Pos(), StringContent(Ctx, pragmaValue->GetAlt_pragma_value3().GetToken1().GetValue())));
}
else if (pragmaValue->HasAlt_pragma_value2()
&& pragmaValue->GetAlt_pragma_value2().GetRule_id1().HasAlt_id2()
- && "default" == Id(pragmaValue->GetAlt_pragma_value2().GetRule_id1(), *this))
+ && "default" == Id(pragmaValue->GetAlt_pragma_value2().GetRule_id1(), *this))
{
pragmaValueDefault = true;
}
@@ -4616,11 +4616,11 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
values.push_back(atom);
} else {
Error() << "Expected string" << (withConfigure ? ", named parameter" : "") << " or 'default' keyword as pragma value for pragma: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
- }
-
+ }
+ }
+
if (prefix.empty()) {
if (!TopLevel && !hasLexicalScope) {
Error() << "This pragma '" << pragma << "' is not allowed to be used in actions or subqueries";
@@ -4629,25 +4629,25 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
}
if (normalizedPragma == "refselect") {
- Ctx.PragmaRefSelect = true;
- Ctx.IncrementMonCounter("sql_pragma", "RefSelect");
- } else if (normalizedPragma == "sampleselect") {
- Ctx.PragmaSampleSelect = true;
- Ctx.IncrementMonCounter("sql_pragma", "SampleSelect");
- } else if (normalizedPragma == "allowdotinalias") {
- Ctx.PragmaAllowDotInAlias = true;
- Ctx.IncrementMonCounter("sql_pragma", "AllowDotInAlias");
- } else if (normalizedPragma == "udf") {
+ Ctx.PragmaRefSelect = true;
+ Ctx.IncrementMonCounter("sql_pragma", "RefSelect");
+ } else if (normalizedPragma == "sampleselect") {
+ Ctx.PragmaSampleSelect = true;
+ Ctx.IncrementMonCounter("sql_pragma", "SampleSelect");
+ } else if (normalizedPragma == "allowdotinalias") {
+ Ctx.PragmaAllowDotInAlias = true;
+ Ctx.IncrementMonCounter("sql_pragma", "AllowDotInAlias");
+ } else if (normalizedPragma == "udf") {
if (values.size() != 1 || pragmaValueDefault) {
Error() << "Expected file alias as pragma value";
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
-
- Ctx.IncrementMonCounter("sql_pragma", "udf");
+ }
+
+ Ctx.IncrementMonCounter("sql_pragma", "udf");
success = true;
return BuildPragma(Ctx.Pos(), TString(ConfigProviderName), "ImportUdfs", values, false);
- } else if (normalizedPragma == "file") {
+ } else if (normalizedPragma == "file") {
if (values.size() != 2U || pragmaValueDefault) {
Error() << "Expected file alias and url as pragma values";
Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
@@ -4682,46 +4682,46 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
} else if (normalizedPragma == "directread") {
Ctx.PragmaDirectRead = true;
Ctx.IncrementMonCounter("sql_pragma", "DirectRead");
- } else if (normalizedPragma == "equijoin") {
- Ctx.IncrementMonCounter("sql_pragma", "EquiJoin");
- } else if (normalizedPragma == "autocommit") {
- Ctx.PragmaAutoCommit = true;
- Ctx.IncrementMonCounter("sql_pragma", "AutoCommit");
- } else if (normalizedPragma == "tablepathprefix") {
- if (values.size() == 1) {
+ } else if (normalizedPragma == "equijoin") {
+ Ctx.IncrementMonCounter("sql_pragma", "EquiJoin");
+ } else if (normalizedPragma == "autocommit") {
+ Ctx.PragmaAutoCommit = true;
+ Ctx.IncrementMonCounter("sql_pragma", "AutoCommit");
+ } else if (normalizedPragma == "tablepathprefix") {
+ if (values.size() == 1) {
if (!Ctx.SetPathPrefix(*values[0].GetLiteral())) {
return {};
- }
- } else if (values.size() == 2) {
+ }
+ } else if (values.size() == 2) {
if (!Ctx.SetPathPrefix(*values[1].GetLiteral(), *values[0].GetLiteral())) {
return {};
- }
- } else {
- Error() << "Expected path prefix or tuple of (Provider, PathPrefix) or"
- << " (Cluster, PathPrefix) as pragma value";
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ }
+ } else {
+ Error() << "Expected path prefix or tuple of (Provider, PathPrefix) or"
+ << " (Cluster, PathPrefix) as pragma value";
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
-
- Ctx.IncrementMonCounter("sql_pragma", "PathPrefix");
- } else if (normalizedPragma == "groupbylimit") {
+ }
+
+ Ctx.IncrementMonCounter("sql_pragma", "PathPrefix");
+ } else if (normalizedPragma == "groupbylimit") {
if (values.size() != 1 || !TryFromString(*values[0].GetLiteral(), Ctx.PragmaGroupByLimit)) {
- Error() << "Expected single unsigned integer argument for: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ Error() << "Expected single unsigned integer argument for: " << pragma;
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
- Ctx.IncrementMonCounter("sql_pragma", "GroupByLimit");
- } else if (normalizedPragma == "groupbycubelimit") {
+ }
+ Ctx.IncrementMonCounter("sql_pragma", "GroupByLimit");
+ } else if (normalizedPragma == "groupbycubelimit") {
if (values.size() != 1 || !TryFromString(*values[0].GetLiteral(), Ctx.PragmaGroupByCubeLimit)) {
- Error() << "Expected single unsigned integer argument for: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ Error() << "Expected single unsigned integer argument for: " << pragma;
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
- Ctx.IncrementMonCounter("sql_pragma", "GroupByCubeLimit");
+ }
+ Ctx.IncrementMonCounter("sql_pragma", "GroupByCubeLimit");
}
else if (normalizedPragma == "simplecolumns") {
- Ctx.SimpleColumns = true;
- Ctx.IncrementMonCounter("sql_pragma", "SimpleColumns");
+ Ctx.SimpleColumns = true;
+ Ctx.IncrementMonCounter("sql_pragma", "SimpleColumns");
}
else if (normalizedPragma == "disablesimplecolumns") {
Ctx.SimpleColumns = false;
@@ -4773,31 +4773,31 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
return {};
default:
Y_ENSURE(false, "Unknown parse result");
- }
+ }
Ctx.IncrementMonCounter("sql_pragma", "warning");
- } else if (normalizedPragma == "greetings") {
- if (values.size() > 1) {
- Error() << "Not expect few arguments for: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
- return {};
- } else if (values.empty()) {
+ } else if (normalizedPragma == "greetings") {
+ if (values.size() > 1) {
+ Error() << "Not expect few arguments for: " << pragma;
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ return {};
+ } else if (values.empty()) {
values.emplace_back(TDeferredAtom(Ctx.Pos(), "Hello, world! And best wishes from the YQL Team!"));
- }
+ }
Ctx.Info(Ctx.Pos()) << *values[0].GetLiteral();
- } else if (normalizedPragma == "warningmsg") {
- if (values.size() != 1) {
- Error() << "Expected single string argument for: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
- return {};
- }
+ } else if (normalizedPragma == "warningmsg") {
+ if (values.size() != 1) {
+ Error() << "Expected single string argument for: " << pragma;
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ return {};
+ }
Ctx.Warning(Ctx.Pos(), TIssuesIds::YQL_PRAGMA_WARNING_MSG) << *values[0].GetLiteral();
- } else if (normalizedPragma == "errormsg") {
- if (values.size() != 1) {
- Error() << "Expected single string argument for: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
- return {};
- }
+ } else if (normalizedPragma == "errormsg") {
+ if (values.size() != 1) {
+ Error() << "Expected single string argument for: " << pragma;
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ return {};
+ }
Ctx.Error(Ctx.Pos()) << *values[0].GetLiteral();
} else if (normalizedPragma == "classicdivision") {
if (values.size() != 1 || !TryFromString(*values[0].GetLiteral(), Ctx.PragmaClassicDivision)) {
@@ -4822,12 +4822,12 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
return {};
}
Ctx.IncrementMonCounter("sql_pragma", "EnableSystemColumns");
- } else {
- Error() << "Unknown pragma: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "UnknownPragma");
+ } else {
+ Error() << "Unknown pragma: " << pragma;
+ Ctx.IncrementMonCounter("sql_errors", "UnknownPragma");
return {};
- }
- } else {
+ }
+ } else {
if (lowerPrefix == "yson") {
if (!TopLevel) {
Error() << "This pragma '" << pragma << "' is not allowed to be used in actions";
@@ -4853,37 +4853,37 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
}
} else if (std::find(Providers.cbegin(), Providers.cend(), lowerPrefix) == Providers.cend()) {
- if (!Ctx.HasCluster(lowerPrefix)) {
- Error() << "Unknown pragma prefix: " << prefix << ", please use cluster name or one of provider " <<
- JoinRange(", ", Providers.cbegin(), Providers.cend());
- Ctx.IncrementMonCounter("sql_errors", "UnknownPragma");
+ if (!Ctx.HasCluster(lowerPrefix)) {
+ Error() << "Unknown pragma prefix: " << prefix << ", please use cluster name or one of provider " <<
+ JoinRange(", ", Providers.cbegin(), Providers.cend());
+ Ctx.IncrementMonCounter("sql_errors", "UnknownPragma");
return {};
- }
- }
-
- if (normalizedPragma != "flags") {
- if (values.size() > 1) {
- Error() << "Expected at most one value in the pragma";
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ }
+ }
+
+ if (normalizedPragma != "flags") {
+ if (values.size() > 1) {
+ Error() << "Expected at most one value in the pragma";
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
- } else {
+ }
+ } else {
if (pragmaValueDefault || values.size() < 1) {
- Error() << "Expected at least one value in the pragma";
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ Error() << "Expected at least one value in the pragma";
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
- }
-
- success = true;
- Ctx.IncrementMonCounter("sql_pragma", pragma);
+ }
+ }
+
+ success = true;
+ Ctx.IncrementMonCounter("sql_pragma", pragma);
return BuildPragma(Ctx.Pos(), lowerPrefix, normalizedPragma, values, pragmaValueDefault);
- }
- success = true;
+ }
+ success = true;
return {};
-}
-
-TNodePtr TSqlQuery::Build(const TRule_delete_stmt& stmt) {
+}
+
+TNodePtr TSqlQuery::Build(const TRule_delete_stmt& stmt) {
TTableRef table = SimpleTableRefImpl(stmt.GetRule_simple_table_ref3(), Mode, *this);
if (!table.Check(Ctx)) {
return nullptr;
@@ -4899,7 +4899,7 @@ TNodePtr TSqlQuery::Build(const TRule_delete_stmt& stmt) {
TSourcePtr source = BuildTableSource(Ctx.Pos(), table, false);
- if (stmt.HasBlock4()) {
+ if (stmt.HasBlock4()) {
switch (stmt.GetBlock4().Alt_case()) {
case TRule_delete_stmt_TBlock4::kAlt1: {
const auto& alt = stmt.GetBlock4().GetAlt1();
@@ -4926,13 +4926,13 @@ TNodePtr TSqlQuery::Build(const TRule_delete_stmt& stmt) {
default:
return nullptr;
- }
- }
+ }
+ }
- return BuildDelete(Ctx.Pos(), table, std::move(source));
-}
-
-TNodePtr TSqlQuery::Build(const TRule_update_stmt& stmt) {
+ return BuildDelete(Ctx.Pos(), table, std::move(source));
+}
+
+TNodePtr TSqlQuery::Build(const TRule_update_stmt& stmt) {
TTableRef table = SimpleTableRefImpl(stmt.GetRule_simple_table_ref2(), Mode, *this);
if (!table.Check(Ctx)) {
return nullptr;
@@ -4976,77 +4976,77 @@ TNodePtr TSqlQuery::Build(const TRule_update_stmt& stmt) {
}
default:
- return nullptr;
- }
-}
-
-TSourcePtr TSqlQuery::Build(const TRule_set_clause_choice& stmt) {
- switch (stmt.Alt_case()) {
- case TRule_set_clause_choice::kAltSetClauseChoice1:
- return Build(stmt.GetAlt_set_clause_choice1().GetRule_set_clause_list1());
- case TRule_set_clause_choice::kAltSetClauseChoice2:
- return Build(stmt.GetAlt_set_clause_choice2().GetRule_multiple_column_assignment1());
- default:
- AltNotImplemented("set_clause_choice", stmt);
- return nullptr;
- }
-}
-
+ return nullptr;
+ }
+}
+
+TSourcePtr TSqlQuery::Build(const TRule_set_clause_choice& stmt) {
+ switch (stmt.Alt_case()) {
+ case TRule_set_clause_choice::kAltSetClauseChoice1:
+ return Build(stmt.GetAlt_set_clause_choice1().GetRule_set_clause_list1());
+ case TRule_set_clause_choice::kAltSetClauseChoice2:
+ return Build(stmt.GetAlt_set_clause_choice2().GetRule_multiple_column_assignment1());
+ default:
+ AltNotImplemented("set_clause_choice", stmt);
+ return nullptr;
+ }
+}
+
bool TSqlQuery::FillSetClause(const TRule_set_clause& node, TVector<TString>& targetList, TVector<TNodePtr>& values) {
- targetList.push_back(ColumnNameAsSingleStr(*this, node.GetRule_set_target1().GetRule_column_name1()));
- TSqlExpression sqlExpr(Ctx, Mode);
- if (!Expr(sqlExpr, values, node.GetRule_expr3())) {
- return false;
- }
- return true;
-}
-
-TSourcePtr TSqlQuery::Build(const TRule_set_clause_list& stmt) {
+ targetList.push_back(ColumnNameAsSingleStr(*this, node.GetRule_set_target1().GetRule_column_name1()));
+ TSqlExpression sqlExpr(Ctx, Mode);
+ if (!Expr(sqlExpr, values, node.GetRule_expr3())) {
+ return false;
+ }
+ return true;
+}
+
+TSourcePtr TSqlQuery::Build(const TRule_set_clause_list& stmt) {
TVector<TString> targetList;
TVector<TNodePtr> values;
- const TPosition pos(Ctx.Pos());
- if (!FillSetClause(stmt.GetRule_set_clause1(), targetList, values)) {
- return nullptr;
- }
- for (auto& block: stmt.GetBlock2()) {
- if (!FillSetClause(block.GetRule_set_clause2(), targetList, values)) {
- return nullptr;
- }
- }
- Y_VERIFY_DEBUG(targetList.size() == values.size());
- return BuildUpdateValues(pos, targetList, values);
-}
-
-TSourcePtr TSqlQuery::Build(const TRule_multiple_column_assignment& stmt) {
+ const TPosition pos(Ctx.Pos());
+ if (!FillSetClause(stmt.GetRule_set_clause1(), targetList, values)) {
+ return nullptr;
+ }
+ for (auto& block: stmt.GetBlock2()) {
+ if (!FillSetClause(block.GetRule_set_clause2(), targetList, values)) {
+ return nullptr;
+ }
+ }
+ Y_VERIFY_DEBUG(targetList.size() == values.size());
+ return BuildUpdateValues(pos, targetList, values);
+}
+
+TSourcePtr TSqlQuery::Build(const TRule_multiple_column_assignment& stmt) {
TVector<TString> targetList;
- FillTargetList(*this, stmt.GetRule_set_target_list1(), targetList);
- auto simpleValuesNode = stmt.GetRule_simple_values_source4();
- const TPosition pos(Ctx.Pos());
- switch (simpleValuesNode.Alt_case()) {
- case TRule_simple_values_source::kAltSimpleValuesSource1: {
+ FillTargetList(*this, stmt.GetRule_set_target_list1(), targetList);
+ auto simpleValuesNode = stmt.GetRule_simple_values_source4();
+ const TPosition pos(Ctx.Pos());
+ switch (simpleValuesNode.Alt_case()) {
+ case TRule_simple_values_source::kAltSimpleValuesSource1: {
TVector<TNodePtr> values;
- TSqlExpression sqlExpr(Ctx, Mode);
- if (!ExprList(sqlExpr, values, simpleValuesNode.GetAlt_simple_values_source1().GetRule_expr_list1())) {
- return nullptr;
- }
- return BuildUpdateValues(pos, targetList, values);
- }
- case TRule_simple_values_source::kAltSimpleValuesSource2: {
- TSqlSelect select(Ctx, Mode);
+ TSqlExpression sqlExpr(Ctx, Mode);
+ if (!ExprList(sqlExpr, values, simpleValuesNode.GetAlt_simple_values_source1().GetRule_expr_list1())) {
+ return nullptr;
+ }
+ return BuildUpdateValues(pos, targetList, values);
+ }
+ case TRule_simple_values_source::kAltSimpleValuesSource2: {
+ TSqlSelect select(Ctx, Mode);
TPosition selectPos;
auto source = select.Build(simpleValuesNode.GetAlt_simple_values_source2().GetRule_select_stmt1(), selectPos);
- if (!source) {
- return nullptr;
- }
- return BuildWriteValues(pos, "UPDATE", targetList, std::move(source));
- }
- default:
- Ctx.IncrementMonCounter("sql_errors", "UnknownSimpleValuesSourceAlt");
- AltNotImplemented("simple_values_source", simpleValuesNode);
- return nullptr;
- }
-}
-
+ if (!source) {
+ return nullptr;
+ }
+ return BuildWriteValues(pos, "UPDATE", targetList, std::move(source));
+ }
+ default:
+ Ctx.IncrementMonCounter("sql_errors", "UnknownSimpleValuesSourceAlt");
+ AltNotImplemented("simple_values_source", simpleValuesNode);
+ return nullptr;
+ }
+}
+
TNodePtr TSqlQuery::Build(const TSQLParserAST& ast) {
const auto& statements = ast.GetRule_sql_stmt_list();
TVector<TNodePtr> blocks;
@@ -5070,7 +5070,7 @@ TNodePtr TSqlQuery::Build(const TSQLParserAST& ast) {
if (!Statement(blocks, statements.GetRule_sql_stmt1().GetRule_sql_stmt_core2())) {
return nullptr;
}
- for (auto block: statements.GetBlock2()) {
+ for (auto block: statements.GetBlock2()) {
if (!Statement(blocks, block.GetRule_sql_stmt2().GetRule_sql_stmt_core2())) {
return nullptr;
}
@@ -5095,15 +5095,15 @@ TNodePtr TSqlQuery::Build(const TSQLParserAST& ast) {
return BuildQuery(Ctx.Pos(), blocks, true);
}
-TNodePtr TSqlQuery::FlexType(TTranslation& ctx, const TRule_flex_type& node) {
+TNodePtr TSqlQuery::FlexType(TTranslation& ctx, const TRule_flex_type& node) {
const auto& stringType = NSQLTranslationV0::FlexType(node, ctx);
auto res = TryBuildDataType(Ctx.Pos(), TypeByAlias(stringType.first, !stringType.second));
- if (!res) {
+ if (!res) {
res = BuildBuiltinFunc(Ctx, Ctx.Pos(), "ParseType", {BuildLiteralRawString(Ctx.Pos(), stringType.first)});
- }
- return res;
-}
-
+ }
+ return res;
+}
+
bool TSqlTranslation::DefineActionOrSubqueryStatement(const TRule_define_action_or_subquery_stmt& stmt) {
auto kind = Ctx.Token(stmt.GetToken2());
const bool isSubquery = to_lower(kind) == "subquery";
@@ -5267,29 +5267,29 @@ TAstNode* SqlASTToYql(const google::protobuf::Message& protoAst, TContext& ctx)
return nullptr;
}
-void SqlASTToYqlImpl(NYql::TAstParseResult& res, const google::protobuf::Message& protoAst,
- TContext& ctx) {
+void SqlASTToYqlImpl(NYql::TAstParseResult& res, const google::protobuf::Message& protoAst,
+ TContext& ctx) {
YQL_ENSURE(!ctx.Issues.Size());
- res.Root = SqlASTToYql(protoAst, ctx);
+ res.Root = SqlASTToYql(protoAst, ctx);
res.Pool = std::move(ctx.Pool);
- if (!res.Root) {
+ if (!res.Root) {
if (ctx.Issues.Size()) {
- ctx.IncrementMonCounter("sql_errors", "AstToYqlError");
- } else {
- ctx.IncrementMonCounter("sql_errors", "AstToYqlSilentError");
+ ctx.IncrementMonCounter("sql_errors", "AstToYqlError");
+ } else {
+ ctx.IncrementMonCounter("sql_errors", "AstToYqlSilentError");
ctx.Error() << "Error occurred on parse SQL query, but no error is collected" <<
- ", please send this request over bug report into YQL interface or write on yql@ maillist";
- }
- }
-}
-
-NYql::TAstParseResult SqlASTToYql(const google::protobuf::Message& protoAst,
+ ", please send this request over bug report into YQL interface or write on yql@ maillist";
+ }
+ }
+}
+
+NYql::TAstParseResult SqlASTToYql(const google::protobuf::Message& protoAst,
const NSQLTranslation::TTranslationSettings& settings)
{
YQL_ENSURE(IsQueryMode(settings.Mode));
TAstParseResult res;
- TContext ctx(settings, res.Issues);
- SqlASTToYqlImpl(res, protoAst, ctx);
+ TContext ctx(settings, res.Issues);
+ SqlASTToYqlImpl(res, protoAst, ctx);
return res;
}
@@ -5297,19 +5297,19 @@ NYql::TAstParseResult SqlASTToYql(const google::protobuf::Message& protoAst,
NYql::TAstParseResult SqlToYql(const TString& query, const NSQLTranslation::TTranslationSettings& settings, NYql::TWarningRules* warningRules)
{
TAstParseResult res;
- TContext ctx(settings, res.Issues);
+ TContext ctx(settings, res.Issues);
NSQLTranslation::TErrorCollectorOverIssues collector(res.Issues, settings.MaxErrors, settings.File);
google::protobuf::Message* ast(SqlAST(query, "query", collector, settings.Arena));
if (ast) {
- SqlASTToYqlImpl(res, *ast, ctx);
+ SqlASTToYqlImpl(res, *ast, ctx);
} else {
ctx.IncrementMonCounter("sql_errors", "AstError");
}
if (warningRules) {
*warningRules = ctx.WarningPolicy.GetRules();
ctx.WarningPolicy.Clear();
- }
+ }
return res;
}
diff --git a/ydb/library/yql/sql/v0/sql.h b/ydb/library/yql/sql/v0/sql.h
index c893c6cfd9..fda4387c27 100644
--- a/ydb/library/yql/sql/v0/sql.h
+++ b/ydb/library/yql/sql/v0/sql.h
@@ -9,7 +9,7 @@
#include <google/protobuf/message.h>
namespace NSQLTranslationV0 {
-
+
NYql::TAstParseResult SqlToYql(const TString& query, const NSQLTranslation::TTranslationSettings& settings, NYql::TWarningRules* warningRules = nullptr);
google::protobuf::Message* SqlAST(const TString& query, const TString& queryName, NYql::TIssues& err, size_t maxErrors, google::protobuf::Arena* arena = nullptr);
NYql::TAstParseResult SqlASTToYql(const google::protobuf::Message& protoAst, const NSQLTranslation::TTranslationSettings& settings);
diff --git a/ydb/library/yql/sql/v0/sql_ut.cpp b/ydb/library/yql/sql/v0/sql_ut.cpp
index 8f2122977e..3a70aef93c 100644
--- a/ydb/library/yql/sql/v0/sql_ut.cpp
+++ b/ydb/library/yql/sql/v0/sql_ut.cpp
@@ -5,25 +5,25 @@
#include <library/cpp/testing/unittest/registar.h>
-#include <util/string/split.h>
+#include <util/string/split.h>
using namespace NSQLTranslationV0;
-enum class EDebugOutput {
- None,
- ToCerr,
-};
+enum class EDebugOutput {
+ None,
+ ToCerr,
+};
TString Err2Str(NYql::TAstParseResult& res, EDebugOutput debug = EDebugOutput::None) {
- TStringStream s;
- res.Issues.PrintTo(s);
-
- if (debug == EDebugOutput::ToCerr) {
- Cerr << s.Str() << Endl;
- }
- return s.Str();
-}
-
+ TStringStream s;
+ res.Issues.PrintTo(s);
+
+ if (debug == EDebugOutput::ToCerr) {
+ Cerr << s.Str() << Endl;
+ }
+ return s.Str();
+}
+
NYql::TAstParseResult SqlToYqlWithMode(const TString& query, NSQLTranslation::ESqlMode mode = NSQLTranslation::ESqlMode::QUERY, size_t maxErrors = 10, const TString& provider = {}, EDebugOutput debug = EDebugOutput::None) {
google::protobuf::Arena arena;
const auto service = provider ? provider : TString(NYql::YtProviderName);
@@ -36,26 +36,26 @@ NYql::TAstParseResult SqlToYqlWithMode(const TString& query, NSQLTranslation::ES
settings.V0Behavior = NSQLTranslation::EV0Behavior::Report;
settings.WarnOnV0 = false;
auto res = SqlToYql(query, settings);
- if (debug == EDebugOutput::ToCerr) {
- Err2Str(res, debug);
- }
- return res;
-}
-
+ if (debug == EDebugOutput::ToCerr) {
+ Err2Str(res, debug);
+ }
+ return res;
+}
+
NYql::TAstParseResult SqlToYql(const TString& query, size_t maxErrors = 10, const TString& provider = {}, EDebugOutput debug = EDebugOutput::None) {
return SqlToYqlWithMode(query, NSQLTranslation::ESqlMode::QUERY, maxErrors, provider, debug);
}
TString GetPrettyPrint(const NYql::TAstParseResult& res) {
- TStringStream yqlProgram;
- res.Root->PrettyPrintTo(yqlProgram, NYql::TAstPrintFlags::PerLine | NYql::TAstPrintFlags::ShortQuote);
- return yqlProgram.Str();
-}
-
+ TStringStream yqlProgram;
+ res.Root->PrettyPrintTo(yqlProgram, NYql::TAstPrintFlags::PerLine | NYql::TAstPrintFlags::ShortQuote);
+ return yqlProgram.Str();
+}
+
TString Quote(const char* str) {
- return TStringBuilder() << "'\"" << str << "\"";
-}
-
+ return TStringBuilder() << "'\"" << str << "\"";
+}
+
class TWordCountHive: public TMap<TString, unsigned> {
public:
TWordCountHive(std::initializer_list<TString> strings) {
@@ -71,25 +71,25 @@ public:
};
typedef std::function<void (const TString& word, const TString& line)> TVerifyLineFunc;
-
+
TString VerifyProgram(const NYql::TAstParseResult& res, TWordCountHive& wordCounter, TVerifyLineFunc verifyLine = TVerifyLineFunc()) {
- const auto programm = GetPrettyPrint(res);
+ const auto programm = GetPrettyPrint(res);
TVector<TString> yqlProgram;
- Split(programm, "\n", yqlProgram);
- for (const auto& line: yqlProgram) {
- for (auto& counterIter: wordCounter) {
- const auto& word = counterIter.first;
+ Split(programm, "\n", yqlProgram);
+ for (const auto& line: yqlProgram) {
+ for (auto& counterIter: wordCounter) {
+ const auto& word = counterIter.first;
if (line.find(word) != TString::npos) {
- ++counterIter.second;
- if (verifyLine) {
- verifyLine(word, line);
- }
- }
- }
- }
- return programm;
-}
-
+ ++counterIter.second;
+ if (verifyLine) {
+ verifyLine(word, line);
+ }
+ }
+ }
+ }
+ return programm;
+}
+
Y_UNIT_TEST_SUITE(SqlParsingOnly) {
Y_UNIT_TEST(V0) {
NYql::TAstParseResult res = SqlToYql("select null;");
@@ -160,15 +160,15 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
Y_UNIT_TEST(Jubilee) {
NYql::TAstParseResult res = SqlToYql("USE plato; INSERT INTO Arcadia (r2000000) VALUES (\"2M GET!!!\");");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(QualifiedAsteriskBefore) {
NYql::TAstParseResult res = SqlToYql("select interested_table.*, LENGTH(value) AS megahelpful_len from plato.Input as interested_table;");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "FlattenMembers") {
+ if (word == "FlattenMembers") {
static ui32 count1 = 0;
if (++count1 == 1) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("interested_table."));
@@ -178,20 +178,20 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
if (++count2 == 2) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("megahelpful_len"));
}
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("FlattenMembers"), 0}, {TString("AsStruct"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["FlattenMembers"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["FlattenMembers"]);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
+ }
+
Y_UNIT_TEST(QualifiedAsteriskAfter) {
NYql::TAstParseResult res = SqlToYql("select LENGTH(value) AS megahelpful_len, interested_table.* from plato.Input as interested_table;");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "FlattenMembers") {
+ if (word == "FlattenMembers") {
static ui32 count1 = 0;
if (++count1 == 1) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("interested_table."));
@@ -201,47 +201,47 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
if (++count2 == 2) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("megahelpful_len"));
}
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("FlattenMembers"), 0}, {TString("AsStruct"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["FlattenMembers"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["FlattenMembers"]);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
+ }
+
Y_UNIT_TEST(QualifiedMembers) {
NYql::TAstParseResult res = SqlToYql("select interested_table.key, interested_table.value from plato.Input as interested_table;");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
const bool fieldKey = TString::npos != line.find(Quote("key"));
const bool fieldValue = TString::npos != line.find(Quote("value"));
const bool refOnTable = TString::npos != line.find("interested_table.");
if (word == "AsStruct") {
- UNIT_ASSERT(fieldKey || fieldValue);
- UNIT_ASSERT(!refOnTable);
- } else if (word == "Write!") {
- UNIT_ASSERT(fieldKey && fieldValue && !refOnTable);
- }
- };
+ UNIT_ASSERT(fieldKey || fieldValue);
+ UNIT_ASSERT(!refOnTable);
+ } else if (word == "Write!") {
+ UNIT_ASSERT(fieldKey && fieldValue && !refOnTable);
+ }
+ };
TWordCountHive elementStat = {{TString("FlattenMembers"), 0}, {TString("AsStruct"), 0}, {TString("Write!"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
- UNIT_ASSERT_VALUES_EQUAL(0, elementStat["FlattenMembers"]);
+ VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(0, elementStat["FlattenMembers"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
+ }
+
Y_UNIT_TEST(JoinParseCorrect) {
NYql::TAstParseResult res = SqlToYql(
- " SELECT table_bb.*, table_aa.key as megakey"
+ " SELECT table_bb.*, table_aa.key as megakey"
" FROM plato.Input AS table_aa"
" JOIN plato.Input AS table_bb"
- " ON table_aa.value == table_bb.value;"
+ " ON table_aa.value == table_bb.value;"
);
UNIT_ASSERT(res.Root);
-
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "SelectMembers") {
+ if (word == "SelectMembers") {
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("table_aa."));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("table_bb."));
} else if (word == "AsStruct") {
@@ -249,247 +249,247 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("table_aa")));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("key")));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("megakey")));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("FlattenMembers"), 0}, {TString("SelectMembers"), 0}, {TString("AsStruct"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
+ VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["FlattenMembers"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SelectMembers"]);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SelectMembers"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
}
Y_UNIT_TEST(Join3Table) {
NYql::TAstParseResult res = SqlToYql(
- " SELECT table_bb.*, table_aa.key as gigakey, table_cc.* "
+ " SELECT table_bb.*, table_aa.key as gigakey, table_cc.* "
" FROM plato.Input AS table_aa"
" JOIN plato.Input AS table_bb ON table_aa.key == table_bb.key"
" JOIN plato.Input AS table_cc ON table_aa.subkey == table_cc.subkey;"
);
- Err2Str(res);
+ Err2Str(res);
UNIT_ASSERT(res.Root);
-
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "SelectMembers") {
+ if (word == "SelectMembers") {
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("table_aa."));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("table_bb."));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("table_cc."));
} else if (word == "AsStruct") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("SqlColumn"));
- const auto posTableAA = line.find(Quote("table_aa"));
+ const auto posTableAA = line.find(Quote("table_aa"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, posTableAA);
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("key")));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("gigakey")));
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("table_aa", posTableAA + 3));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("FlattenMembers"), 0}, {TString("SelectMembers"), 0}, {TString("AsStruct"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
+ VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["FlattenMembers"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SelectMembers"]);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SelectMembers"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
}
-
+
Y_UNIT_TEST(JoinWithoutConcreteColumns) {
- NYql::TAstParseResult res = SqlToYql(
+ NYql::TAstParseResult res = SqlToYql(
" use plato;"
- " SELECT a.v, b.value"
- " FROM [Input1]:[ksv] AS a"
- " JOIN [Input2] AS b"
- " ON a.k == b.key;"
- );
- UNIT_ASSERT(res.Root);
-
+ " SELECT a.v, b.value"
+ " FROM [Input1]:[ksv] AS a"
+ " JOIN [Input2] AS b"
+ " ON a.k == b.key;"
+ );
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
if (word == "AsStruct") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("SqlColumn"));
- const auto posTableA = line.find(Quote("a"));
- const auto posTableB = line.find(Quote("b"));
+ const auto posTableA = line.find(Quote("a"));
+ const auto posTableB = line.find(Quote("b"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, posTableA);
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, posTableB);
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find(Quote("a"), posTableA + 1));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("v")));
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find(Quote("b"), posTableB + 1));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("value")));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("FlattenMembers"), 0}, {TString("AsStruct"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
- UNIT_ASSERT_VALUES_EQUAL(0, elementStat["FlattenMembers"]);
+ VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(0, elementStat["FlattenMembers"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
- }
-
+ }
+
Y_UNIT_TEST(JoinWithSameValues) {
NYql::TAstParseResult res = SqlToYql("SELECT a.value, b.value FROM plato.Input AS a JOIN plato.Input as b ON a.key == b.key;");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
if (word == "AsStruct") {
const bool isValueFromA = TString::npos != line.find(Quote("a.value"));
const bool isValueFromB = TString::npos != line.find(Quote("b.value"));
- UNIT_ASSERT(isValueFromA || isValueFromB);
- } if (word == "Write!") {
+ UNIT_ASSERT(isValueFromA || isValueFromB);
+ } if (word == "Write!") {
const bool noDuplicateSourceInA = TString::npos == line.find("a.a.");
const bool noDuplicateSourceInB = TString::npos == line.find("b.b.");
- UNIT_ASSERT(noDuplicateSourceInA || noDuplicateSourceInB);
- }
- };
+ UNIT_ASSERT(noDuplicateSourceInA || noDuplicateSourceInB);
+ }
+ };
TWordCountHive elementStat = {{TString("FlattenMembers"), 0}, {TString("AsStruct"), 0}, {"Write!", 0}};
- VerifyProgram(res, elementStat, verifyLine);
- UNIT_ASSERT_VALUES_EQUAL(0, elementStat["FlattenMembers"]);
+ VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(0, elementStat["FlattenMembers"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
+ }
+
Y_UNIT_TEST(SameColumnsForDifferentTables) {
NYql::TAstParseResult res = SqlToYql("SELECT a.key, b.key FROM plato.Input as a JOIN plato.Input as b on a.key==b.key;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(SameColumnsForDifferentTablesFullJoin) {
NYql::TAstParseResult res = SqlToYql("SELECT a.key, b.key, a.value, b.value FROM plato.Input AS a FULL JOIN plato.Input AS b USING(key);");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(ReverseLabels) {
NYql::TAstParseResult res = SqlToYql("select in.key as subkey, subkey as key from plato.Input as in;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(AutogenerationAliasWithoutCollisionConflict1) {
NYql::TAstParseResult res = SqlToYql("select LENGTH(Value), key as column1 from plato.Input;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(AutogenerationAliasWithoutCollision2Conflict2) {
NYql::TAstParseResult res = SqlToYql("select key as column0, LENGTH(Value) from plato.Input;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(InputAliasForQualifiedAsterisk) {
NYql::TAstParseResult res = SqlToYql("use plato; select zyuzya.*, key from plato.Input as zyuzya;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(SelectOrderByLabeledColumn) {
NYql::TAstParseResult res = SqlToYql("select key as goal from plato.Input order by goal");
- UNIT_ASSERT(res.Root);
+ UNIT_ASSERT(res.Root);
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
if (word == "DataSource" && TString::npos == line.find("SQL")) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("plato"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("Input"));
-
+
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("goal"));
- } else if (word == "Sort") {
+ } else if (word == "Sort") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("goal"));
-
+
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("key"));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("DataSource"), 0}, {TString("Sort"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
+ VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT_VALUES_EQUAL(2, elementStat["DataSource"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
+ }
+
Y_UNIT_TEST(SelectOrderBySimpleExpr) {
NYql::TAstParseResult res = SqlToYql("select a from plato.Input order by a + a");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(SelectOrderByDuplicateLabels) {
NYql::TAstParseResult res = SqlToYql("select a from plato.Input order by a, a");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(SelectOrderByExpression) {
NYql::TAstParseResult res = SqlToYql("select * from plato.Input as i order by cast(key as uint32) + cast(subkey as uint32)");
- UNIT_ASSERT(res.Root);
+ UNIT_ASSERT(res.Root);
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Sort") {
+ if (word == "Sort") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"+\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("key"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("subkey"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("(Bool 'true)"));
-
+
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("i.key"));
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("i.subkey"));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("Sort"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
+ }
+
Y_UNIT_TEST(SelectOrderByExpressionDesc) {
NYql::TAstParseResult res = SqlToYql("select i.*, key, subkey from plato.Input as i order by cast(i.key as uint32) - cast(i.subkey as uint32) desc");
- UNIT_ASSERT(res.Root);
+ UNIT_ASSERT(res.Root);
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Sort") {
+ if (word == "Sort") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"-\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"key\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"subkey\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("(Bool 'false)"));
- } else if (word == "Write!") {
+ } else if (word == "Write!") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("'columns"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"key\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"subkey\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("prefix"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"i.\""));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("Sort"), 0}, {TString("Write!"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
+ }
+
Y_UNIT_TEST(SelectOrderByExpressionAsc) {
NYql::TAstParseResult res = SqlToYql("select i.key, i.subkey from plato.Input as i order by cast(key as uint32) % cast(i.subkey as uint32) asc");
- UNIT_ASSERT(res.Root);
+ UNIT_ASSERT(res.Root);
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Sort") {
+ if (word == "Sort") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"%\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"key\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"subkey\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("(Bool 'true)"));
- } else if (word == "Write!") {
+ } else if (word == "Write!") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("'columns"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"key\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"subkey\""));
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("i."));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("Sort"), 0}, {TString("Write!"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
+ }
+
Y_UNIT_TEST(ReferenceToKeyInSubselect) {
NYql::TAstParseResult res = SqlToYql("select b.key from (select a.key from plato.Input as a) as b;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(OrderByCastValue) {
NYql::TAstParseResult res = SqlToYql("select i.key, i.subkey from plato.Input as i order by cast(key as uint32) desc;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(GroupByCastValue) {
NYql::TAstParseResult res = SqlToYql("select count(1) from plato.Input as i group by cast(key as uint8);");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(KeywordInSelectColumns) {
- NYql::TAstParseResult res = SqlToYql("select in, s.check from (select 1 as in, \"test\" as check) as s;");
- UNIT_ASSERT(res.Root);
- }
+ NYql::TAstParseResult res = SqlToYql("select in, s.check from (select 1 as in, \"test\" as check) as s;");
+ UNIT_ASSERT(res.Root);
+ }
Y_UNIT_TEST(SelectAllGroupBy) {
NYql::TAstParseResult res = SqlToYql("select * from plato.Input group by subkey;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(PrimaryKeyParseCorrect) {
NYql::TAstParseResult res = SqlToYql("USE plato; CREATE TABLE tableName (Key Uint32, Subkey Int64, Value String, PRIMARY KEY (Key, Subkey));");
UNIT_ASSERT(res.Root);
@@ -507,39 +507,39 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["primarykey"]);
}
-
+
Y_UNIT_TEST(DeleteFromTableByKey) {
NYql::TAstParseResult res = SqlToYql("delete from plato.Input where key = 200;", 10, "kikimr");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Write") {
+ if (word == "Write") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("('mode 'delete)"));
- }
- };
-
+ }
+ };
+
TWordCountHive elementStat = {{TString("Write"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
-
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
+ }
+
Y_UNIT_TEST(DeleteFromTable) {
NYql::TAstParseResult res = SqlToYql("delete from plato.Input;", 10, "kikimr");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Write") {
+ if (word == "Write") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("('mode 'delete)"));
- }
- };
-
+ }
+ };
+
TWordCountHive elementStat = {{TString("Write"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
-
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
+ }
+
Y_UNIT_TEST(DeleteFromTableOnValues) {
NYql::TAstParseResult res = SqlToYql("delete from plato.Input on (key) values (1);",
10, "kikimr");
@@ -576,107 +576,107 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
Y_UNIT_TEST(UpdateByValues) {
NYql::TAstParseResult res = SqlToYql("update plato.Input set key = 777, value = 'cool' where key = 200;", 10, "kikimr");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Write") {
+ if (word == "Write") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("('mode 'update)"));
} else if (word == "AsStruct") {
const bool isKey = line.find("key") != TString::npos;
const bool isValue = line.find("value") != TString::npos;
- UNIT_ASSERT(isKey || isValue);
- if (isKey) {
+ UNIT_ASSERT(isKey || isValue);
+ if (isKey) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("777")));
- } else if (isValue) {
+ } else if (isValue) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("cool")));
- }
- }
- };
-
+ }
+ }
+ };
+
TWordCountHive elementStat = {{TString("Write"), 0}, {TString("AsStruct"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
-
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
+ VerifyProgram(res, elementStat, verifyLine);
+
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
- }
-
+ }
+
Y_UNIT_TEST(UpdateByMultiValues) {
NYql::TAstParseResult res = SqlToYql("update plato.Input set (key, value, subkey) = ('2','ddd',':') where key = 200;", 10, "kikimr");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Write") {
+ if (word == "Write") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("('mode 'update)"));
} else if (word == "AsStruct") {
const bool isKey = line.find("key") != TString::npos;
const bool isSubkey = line.find("subkey") != TString::npos;
const bool isValue = line.find("value") != TString::npos;
- UNIT_ASSERT(isKey || isSubkey || isValue);
+ UNIT_ASSERT(isKey || isSubkey || isValue);
if (isKey && !isSubkey) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("2")));
- } else if (isSubkey) {
+ } else if (isSubkey) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote(":")));
- } else if (isValue) {
+ } else if (isValue) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("ddd")));
- }
- }
- };
-
+ }
+ }
+ };
+
TWordCountHive elementStat = {{TString("Write"), 0}, {TString("AsStruct"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
-
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
+ VerifyProgram(res, elementStat, verifyLine);
+
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
- }
-
+ }
+
Y_UNIT_TEST(UpdateBySelect) {
NYql::TAstParseResult res = SqlToYql("update plato.Input set (key, value, subkey) = (select key, value, subkey from plato.Input where key = 911) where key = 200;", 10, "kikimr");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
int lineIndex = 0;
int writeLineIndex = -1;
bool found = false;
TVerifyLineFunc verifyLine = [&lineIndex, &writeLineIndex, &found](const TString& word, const TString& line) {
- if (word == "Write") {
+ if (word == "Write") {
writeLineIndex = lineIndex;
found = line.find("('mode 'update)") != TString::npos;
} else if (word == "mode") {
found |= lineIndex == writeLineIndex + 1 && line.find("('mode 'update)") != TString::npos;
UNIT_ASSERT(found);
- }
+ }
++lineIndex;
- };
-
+ };
+
TWordCountHive elementStat = {{TString("Write"), 0}, {TString("mode"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
-
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
+ }
+
Y_UNIT_TEST(UpdateSelfModifyAll) {
NYql::TAstParseResult res = SqlToYql("update plato.Input set subkey = subkey + 's';", 10, "kikimr");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Write") {
+ if (word == "Write") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("('mode 'update)"));
} else if (word == "AsStruct") {
const bool isSubkey = line.find("subkey") != TString::npos;
- UNIT_ASSERT(isSubkey);
+ UNIT_ASSERT(isSubkey);
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("subkey")));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("s")));
- }
- };
-
+ }
+ };
+
TWordCountHive elementStat = {{TString("Write"), 0}, {TString("AsStruct"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
-
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
+ VerifyProgram(res, elementStat, verifyLine);
+
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
- }
-
+ }
+
Y_UNIT_TEST(UpdateOnValues) {
NYql::TAstParseResult res = SqlToYql("update plato.Input on (key, value) values (5, 'cool')", 10, "kikimr");
UNIT_ASSERT(res.Root);
@@ -712,13 +712,13 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
Y_UNIT_TEST(UnionAllTest) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input UNION ALL select subkey FROM plato.Input;");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TWordCountHive elementStat = {{TString("UnionAll"), 0}};
- VerifyProgram(res, elementStat, {});
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["UnionAll"]);
- }
-
+ VerifyProgram(res, elementStat, {});
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["UnionAll"]);
+ }
+
Y_UNIT_TEST(DeclareDecimalParameter) {
NYql::TAstParseResult res = SqlToYql("declare $value as Decimal(22,9); select $value as cnt;");
UNIT_ASSERT(res.Root);
@@ -726,15 +726,15 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
Y_UNIT_TEST(SimpleGroupBy) {
NYql::TAstParseResult res = SqlToYql("select count(1),z from plato.Input group by key as z order by z;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(EmptyColumnName0) {
/// Now it's parsed well and error occur on validate step like "4:31:Empty struct member name is not allowed" in "4:31:Function: AddMember"
NYql::TAstParseResult res = SqlToYql("insert into plato.Output ([], list1) values (0, AsList(0, 1, 2));");
- /// Verify that parsed well without crash
- UNIT_ASSERT(res.Root);
- }
+ /// Verify that parsed well without crash
+ UNIT_ASSERT(res.Root);
+ }
Y_UNIT_TEST(KikimrRollback) {
NYql::TAstParseResult res = SqlToYql("use plato; rollback;", 10, "kikimr");
@@ -753,11 +753,11 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
VerifyProgram(res, elementStat);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat.cbegin()->second);
}
-
+
Y_UNIT_TEST(DoNotCrashOnNamedInFilter) {
- NYql::TAstParseResult res = SqlToYql("USE plato; $all = YQL::@@(lambda '(table_name) (Bool 'true))@@; SELECT * FROM FILTER(Input, $all)");
- UNIT_ASSERT(res.Root);
- }
+ NYql::TAstParseResult res = SqlToYql("USE plato; $all = YQL::@@(lambda '(table_name) (Bool 'true))@@; SELECT * FROM FILTER(Input, $all)");
+ UNIT_ASSERT(res.Root);
+ }
Y_UNIT_TEST(PragmasFileAndUdfOrder) {
NYql::TAstParseResult res = SqlToYql(R"(
@@ -771,23 +771,23 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
const auto udfs = programm.find("ImportUdfs");
UNIT_ASSERT(file < udfs);
}
-
+
Y_UNIT_TEST(ProcessUserType) {
- NYql::TAstParseResult res = SqlToYql("process plato.Input using Kikimr::PushData($ROWS);", 1, TString(NYql::KikimrProviderName));
- UNIT_ASSERT(res.Root);
-
- TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Kikimr.PushData") {
- UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("TupleType"));
- UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("TypeOf"));
- UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("inputRowsList"));
- }
- };
-
- TWordCountHive elementStat = {{TString("Kikimr.PushData"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
+ NYql::TAstParseResult res = SqlToYql("process plato.Input using Kikimr::PushData($ROWS);", 1, TString(NYql::KikimrProviderName));
+ UNIT_ASSERT(res.Root);
+
+ TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
+ if (word == "Kikimr.PushData") {
+ UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("TupleType"));
+ UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("TypeOf"));
+ UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("inputRowsList"));
+ }
+ };
+
+ TWordCountHive elementStat = {{TString("Kikimr.PushData"), 0}};
+ VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Kikimr.PushData"]);
- }
+ }
Y_UNIT_TEST(ProcessUserTypeAuth) {
NYql::TAstParseResult res = SqlToYql("process plato.Input using YDB::PushData($ROWS, AsTuple('oauth', SecureParam('api:oauth')));", 1, TString(NYql::KikimrProviderName));
@@ -898,7 +898,7 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
}
}
-
+
Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
Y_UNIT_TEST(StrayUTF8) {
/// 'c' in plato is russian here
@@ -959,13 +959,13 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(WrongTokenTrivial) {
- NYql::TAstParseResult res = SqlToYql("foo");
+ NYql::TAstParseResult res = SqlToYql("foo");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:0: Error: Unexpected token 'foo' : cannot match to any predicted input...\n\n");
}
Y_UNIT_TEST(InvalidDoubleAtString) {
- NYql::TAstParseResult res = SqlToYql("select @@@@@@");
+ NYql::TAstParseResult res = SqlToYql("select @@@@@@");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:13: Error: Unexpected character : syntax error...\n\n"
"<main>:1:0: Error: Unexpected token absence : cannot match to any predicted input...\n\n" );
@@ -991,13 +991,13 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(SelectInvalidSyntax) {
- NYql::TAstParseResult res = SqlToYql("select 1 form Wat");
+ NYql::TAstParseResult res = SqlToYql("select 1 form Wat");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:9: Error: Unexpected token 'form' : syntax error...\n\n");
}
Y_UNIT_TEST(SelectNoCluster) {
- NYql::TAstParseResult res = SqlToYql("select foo from bar");
+ NYql::TAstParseResult res = SqlToYql("select foo from bar");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: No cluster name given and no default cluster is selected\n");
}
@@ -1015,9 +1015,9 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(SelectCaseWithoutThen) {
- NYql::TAstParseResult res = SqlToYql("select case when true 1;");
+ NYql::TAstParseResult res = SqlToYql("select case when true 1;");
UNIT_ASSERT(!res.Root);
- UNIT_ASSERT_NO_DIFF(Err2Str(res),
+ UNIT_ASSERT_NO_DIFF(Err2Str(res),
"<main>:1:22: Error: Unexpected token absence : Missing THEN \n\n"
"<main>:1:23: Error: Unexpected token absence : Missing END \n\n"
);
@@ -1029,7 +1029,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
"FROM plato.Input AS a\n"
"WHERE CASE WHEN a.key = \"foo\" a.subkey ELSE a.value END\n"
);
- UNIT_ASSERT_NO_DIFF(Err2Str(res),
+ UNIT_ASSERT_NO_DIFF(Err2Str(res),
"<main>:3:24: Error: Unexpected token '\"foo\"' : cannot match to any predicted input...\n\n"
"<main>:3:39: Error: Unexpected token absence : Missing THEN \n\n"
);
@@ -1042,7 +1042,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(SelectWithBadAggregationNoInput) {
- NYql::TAstParseResult res = SqlToYql("select a, Min(b), c");
+ NYql::TAstParseResult res = SqlToYql("select a, Min(b), c");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Source does not allow column references\n"
"<main>:1:1: Error: Source does not allow column references\n"
@@ -1074,7 +1074,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(SelectWithBadAggregationInGrouping) {
- NYql::TAstParseResult res = SqlToYql("select a, Min(b), c group by c");
+ NYql::TAstParseResult res = SqlToYql("select a, Min(b), c group by c");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Source does not allow column references\n"
"<main>:1:1: Error: Source does not allow column references\n"
@@ -1115,10 +1115,10 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
Y_UNIT_TEST(ErrorInOrderByExpresison) {
NYql::TAstParseResult res = SqlToYql("select key, value from plato.Input order by (key as zey)");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:45: Error: You should use in ORDER BY column name, qualified field, callable function or expression\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectAggregatedWhere) {
NYql::TAstParseResult res = SqlToYql("select * from plato.Input where count(key)");
UNIT_ASSERT(!res.Root);
@@ -1141,7 +1141,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
NYql::TAstParseResult res = SqlToYql(
"$left = (SELECT * FROM plato.Input1 LIMIT 2);\n"
"$right = (SELECT * FROM plato.Input2 LIMIT 2);\n"
- "SELECT * FROM $left FULL JOIN $right USING (key);\n"
+ "SELECT * FROM $left FULL JOIN $right USING (key);\n"
);
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:3:45: Error: At least one correlation name is required in join\n");
@@ -1214,7 +1214,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(BuiltinFileOpNoArgs) {
- NYql::TAstParseResult res = SqlToYql("select FilePath()");
+ NYql::TAstParseResult res = SqlToYql("select FilePath()");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: FilePath() requires exactly 1 arguments, given: 0\n");
}
@@ -1270,24 +1270,24 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
Y_UNIT_TEST(ProcessRowsPlaceholderOutOfScope) {
NYql::TAstParseResult res = SqlToYql(
"$data = (process plato.Input using some::udf($ROWS));\n"
- "SELECT * FROM $ROWS;\n"
+ "SELECT * FROM $ROWS;\n"
);
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:2:15: Error: Unknown name: $ROWS\n");
}
Y_UNIT_TEST(ProcessWithInvalidSource) {
- NYql::TAstParseResult res = SqlToYql("PROCESS $input USING YQL::AsList($ROWS);");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("PROCESS $input USING YQL::AsList($ROWS);");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:9: Error: Unknown name: $input\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectWithUnknownBind) {
NYql::TAstParseResult res = SqlToYql("select * from plato.Input where $value like 'Hell!';");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:33: Error: Unknown name: $value\n");
- }
-
+ }
+
Y_UNIT_TEST(CreateTableWithView) {
NYql::TAstParseResult res = SqlToYql("CREATE TABLE plato.foo:bar (key INT);");
UNIT_ASSERT(!res.Root);
@@ -1298,141 +1298,141 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
NYql::TAstParseResult res = SqlToYql("CREATE TABLE plato.foo (key \"Int32?\");");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:25: Error: CREATE TABLE clause requires non-optional column types in scheme\n");
- }
+ }
Y_UNIT_TEST(AsteriskWithSomethingAfter) {
NYql::TAstParseResult res = SqlToYql("select *, LENGTH(value) from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Unable to use general '*' with other columns, either specify concrete table like '<table>.*', either specify concrete columns.\n");
- }
+ }
Y_UNIT_TEST(AsteriskWithSomethingBefore) {
NYql::TAstParseResult res = SqlToYql("select LENGTH(value), * from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:23: Error: Unable to use general '*' with other columns, either specify concrete table like '<table>.*', either specify concrete columns.\n");
}
-
+
Y_UNIT_TEST(DuplicatedQualifiedAsterisk) {
NYql::TAstParseResult res = SqlToYql("select in.*, key, in.* from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:19: Error: Unable to use twice same quialified asterisk. Invalid source: in\n");
- }
-
+ }
+
Y_UNIT_TEST(BrokenLabel) {
NYql::TAstParseResult res = SqlToYql("select in.*, key as [funny.label] from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:14: Error: Unable to use '.' in column name. Invalid column name: funny.label\n");
- }
-
+ }
+
Y_UNIT_TEST(KeyConflictDetect0) {
NYql::TAstParseResult res = SqlToYql("select key, in.key as key from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:13: Error: Unable to use duplicate column names. Collision in name: key\n");
- }
-
+ }
+
Y_UNIT_TEST(KeyConflictDetect1) {
NYql::TAstParseResult res = SqlToYql("select length(key) as key, key from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:28: Error: Unable to use duplicate column names. Collision in name: key\n");
- }
-
+ }
+
Y_UNIT_TEST(KeyConflictDetect2) {
NYql::TAstParseResult res = SqlToYql("select key, in.key from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: key\n");
- }
-
+ }
+
Y_UNIT_TEST(AutogenerationAliasWithCollisionConflict1) {
NYql::TAstParseResult res = SqlToYql("select LENGTH(Value), key as column0 from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: column0\n");
- }
-
+ }
+
Y_UNIT_TEST(AutogenerationAliasWithCollisionConflict2) {
NYql::TAstParseResult res = SqlToYql("select key as column1, LENGTH(Value) from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: column1\n");
- }
-
+ }
+
Y_UNIT_TEST(MissedSourceTableForQualifiedAsteriskOnSimpleSelect) {
NYql::TAstParseResult res = SqlToYql("use plato; select Intop.*, Input.key from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:19: Error: Unknown correlation name: Intop\n");
- }
-
+ }
+
Y_UNIT_TEST(MissedSourceTableForQualifiedAsteriskOnJoin) {
NYql::TAstParseResult res = SqlToYql("use plato; select tmissed.*, t2.*, t1.key from plato.Input as t1 join plato.Input as t2 on t1.key==t2.key;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:19: Error: Unknown correlation name for asterisk: tmissed\n");
- }
-
+ }
+
Y_UNIT_TEST(UnableToReferenceOnNotExistSubcolumn) {
NYql::TAstParseResult res = SqlToYql("select b.subkey from (select key from plato.Input as a) as b;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Column subkey is not in source column set\n");
- }
-
+ }
+
Y_UNIT_TEST(ConflictOnSameNameWithQualify0) {
NYql::TAstParseResult res = SqlToYql("select in.key, in.key as key from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: key\n");
- }
-
+ }
+
Y_UNIT_TEST(ConflictOnSameNameWithQualify1) {
NYql::TAstParseResult res = SqlToYql("select in.key, length(key) as key from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: key\n");
- }
-
+ }
+
Y_UNIT_TEST(ConflictOnSameNameWithQualify2) {
NYql::TAstParseResult res = SqlToYql("select key, in.key from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: key\n");
- }
-
+ }
+
Y_UNIT_TEST(ConflictOnSameNameWithQualify3) {
NYql::TAstParseResult res = SqlToYql("select in.key, subkey as key from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: key\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectOrderByUnknownLabel) {
NYql::TAstParseResult res = SqlToYql("select a from plato.Input order by b");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:36: Error: Column b is not in source column set. Did you mean a?\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectFlattenBySameColumns) {
NYql::TAstParseResult res = SqlToYql("select key from plato.Input flatten by (key, key as kk)");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:46: Error: Duplicate column name found: key in FlattenBy section\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectFlattenBySameAliases) {
NYql::TAstParseResult res = SqlToYql("select key from plato.Input flatten by (key as kk, subkey as kk);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:52: Error: Duplicate alias found: kk in FlattenBy section\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectFlattenByConflictNameAndAlias0) {
NYql::TAstParseResult res = SqlToYql("select key from plato.Input flatten by (key, subkey as key);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:46: Error: Collision between alias and column name: key in FlattenBy section\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectFlattenByConflictNameAndAlias1) {
NYql::TAstParseResult res = SqlToYql("select key from plato.Input flatten by (key as kk, subkey as key);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:52: Error: Collision between alias and column name: key in FlattenBy section\n");
- }
-
+ }
+
Y_UNIT_TEST(UseInOnStrings) {
NYql::TAstParseResult res = SqlToYql("select * from plato.Input where \"foo\" in \"foovalue\";");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:42: Error: Unable to use IN predicate with string argument, it won't search substring - "
"expecting tuple, list, dict or single column table source\n");
}
-
+
Y_UNIT_TEST(UseSubqueryInScalarContextInsideIn) {
NYql::TAstParseResult res = SqlToYql("$q = (select key from plato.Input); select * from plato.Input where subkey in ($q);");
UNIT_ASSERT(res.Root);
@@ -1447,17 +1447,17 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(ErrorColumnPosition) {
- NYql::TAstParseResult res = SqlToYql(
+ NYql::TAstParseResult res = SqlToYql(
"USE plato;\n"
- "SELECT \n"
- "value FROM (\n"
- "select key from Input\n"
- ");\n"
- );
- UNIT_ASSERT(!res.Root);
+ "SELECT \n"
+ "value FROM (\n"
+ "select key from Input\n"
+ ");\n"
+ );
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:3:1: Error: Column value is not in source column set\n");
- }
-
+ }
+
Y_UNIT_TEST(InsertAbortMapReduce) {
NYql::TAstParseResult res = SqlToYql("INSERT OR ABORT INTO plato.Output SELECT key FROM plato.Input");
UNIT_ASSERT(!res.Root);
@@ -1468,14 +1468,14 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
NYql::TAstParseResult res = SqlToYql("REPLACE INTO plato.Output SELECT key FROM plato.Input");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:0: Error: Meaning of REPLACE INTO has been changed, now you should use INSERT INTO <table> WITH TRUNCATE ... for yt\n");
- }
-
+ }
+
Y_UNIT_TEST(UpsertIntoMapReduce) {
NYql::TAstParseResult res = SqlToYql("UPSERT INTO plato.Output SELECT key FROM plato.Input");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:0: Error: UPSERT INTO is not supported for yt tables\n");
- }
-
+ }
+
Y_UNIT_TEST(UpdateMapReduce) {
NYql::TAstParseResult res = SqlToYql("UPDATE plato.Output SET value = value + 1 WHERE key < 1");
UNIT_ASSERT(!res.Root);
@@ -1490,132 +1490,132 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
Y_UNIT_TEST(ReplaceIntoWithTruncate) {
NYql::TAstParseResult res = SqlToYql("REPLACE INTO plato.Output WITH TRUNCATE SELECT key FROM plato.Input");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:32: Error: Unable REPLACE INTO with truncate mode\n");
- }
-
+ }
+
Y_UNIT_TEST(UpsertIntoWithTruncate) {
NYql::TAstParseResult res = SqlToYql("UPSERT INTO plato.Output WITH TRUNCATE SELECT key FROM plato.Input");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:31: Error: Unable UPSERT INTO with truncate mode\n");
- }
-
+ }
+
Y_UNIT_TEST(InsertIntoWithTruncateKikimr) {
NYql::TAstParseResult res = SqlToYql("INSERT INTO plato.Output WITH TRUNCATE SELECT key FROM plato.Input", 10, TString(NYql::KikimrProviderName));
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:0: Error: INSERT INTO WITH TRUNCATE is not supported for kikimr tables\n");
- }
-
+ }
+
Y_UNIT_TEST(InsertIntoWithWrongArgumentCount) {
NYql::TAstParseResult res = SqlToYql("insert into plato.Output with truncate (key, value, subkey) values (5, '1', '2', '3');");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:53: Error: VALUES have 4 columns, INSERT INTO ... WITH TRUNCATE expects: 3\n");
- }
-
+ }
+
Y_UNIT_TEST(UpsertWithWrongArgumentCount) {
NYql::TAstParseResult res = SqlToYql("upsert into plato.Output (key, value, subkey) values (2, '3');", 10, TString(NYql::KikimrProviderName));
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:39: Error: VALUES have 2 columns, UPSERT INTO expects: 3\n");
- }
-
+ }
+
Y_UNIT_TEST(UnionNotSupported) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input UNION select subkey FROM plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:29: Error: UNION without quantifier ALL is not supported yet. Did you mean UNION ALL?\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupingSetByExprWithoutAlias) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY GROUPING SETS (cast(key as uint32), subkey);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:74: Error: You should use in GROUPING SETS either expression with required alias either column name or used alias.\n");
- }
-
+ }
+
Y_UNIT_TEST(CubeByExprWithoutAlias) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY CUBE (key, subkey / key);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:58: Error: You should use in CUBE either expression with required alias either column name or used alias.\n");
- }
-
+ }
+
Y_UNIT_TEST(RollupByExprWithoutAlias) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY ROLLUP (subkey / key);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:55: Error: You should use in ROLLUP either expression with required alias either column name or used alias.\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupByHugeCubeDeniedNoPragma) {
- NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY CUBE (key, subkey, value, key + subkey as sum, key - subkey as sub, key + val as keyval);");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY CUBE (key, subkey, value, key + subkey as sum, key - subkey as sub, key + val as keyval);");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:119: Error: GROUP BY CUBE is allowed only for 5 columns, but you use 6\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupByInvalidPragma) {
- NYql::TAstParseResult res = SqlToYql("PRAGMA GroupByCubeLimit = '-4';");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("PRAGMA GroupByCubeLimit = '-4';");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Expected single unsigned integer argument for: GroupByCubeLimit\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupByHugeCubeDeniedPragme) {
- NYql::TAstParseResult res = SqlToYql("PRAGMA GroupByCubeLimit = '4'; SELECT key FROM plato.Input GROUP BY CUBE (key, subkey, value, key + subkey as sum, key - subkey as sub);");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("PRAGMA GroupByCubeLimit = '4'; SELECT key FROM plato.Input GROUP BY CUBE (key, subkey, value, key + subkey as sum, key - subkey as sub);");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:132: Error: GROUP BY CUBE is allowed only for 4 columns, but you use 5\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupByFewBigCubes) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY CUBE(key, subkey, key + subkey as sum), CUBE(value, value + key + subkey as total);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Unable to GROUP BY more than 32 groups, you try use 80 groups\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupByFewBigCubesWithPragmaLimit) {
- NYql::TAstParseResult res = SqlToYql("PRAGMA GroupByLimit = '16'; SELECT key FROM plato.Input GROUP BY GROUPING SETS(key, subkey, key + subkey as sum), ROLLUP(value, value + key + subkey as total);");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("PRAGMA GroupByLimit = '16'; SELECT key FROM plato.Input GROUP BY GROUPING SETS(key, subkey, key + subkey as sum), ROLLUP(value, value + key + subkey as total);");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:29: Error: Unable to GROUP BY more than 16 groups, you try use 18 groups\n");
- }
-
+ }
+
Y_UNIT_TEST(NoGroupingColumn0) {
- NYql::TAstParseResult res = SqlToYql(
- "select count(1), key_first, val_first, grouping(key_first, val_first, nomind) as group\n"
+ NYql::TAstParseResult res = SqlToYql(
+ "select count(1), key_first, val_first, grouping(key_first, val_first, nomind) as group\n"
"from plato.Input group by grouping sets (cast(key as uint32) /100 as key_first, Substring(value, 1, 1) as val_first);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:71: Error: Column 'nomind' not used as grouping column\n");
- }
-
+ }
+
Y_UNIT_TEST(NoGroupingColumn1) {
NYql::TAstParseResult res = SqlToYql("select count(1), grouping(key, value) as group_duo from plato.Input group by cube (key, subkey);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:32: Error: Column 'value' not used as grouping column\n");
- }
-
+ }
+
Y_UNIT_TEST(EmptyAccess0) {
NYql::TAstParseResult res = SqlToYql("insert into plato.Output (list0, list1) values (AsList(0, 1, 2), AsList([]));");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:34: Error: Source does not allow column references\n");
- }
-
+ }
+
Y_UNIT_TEST(EmptyAccess1) {
NYql::TAstParseResult res = SqlToYql("insert into plato.Output (list0, list1) values (AsList(0, 1, 2), []);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:34: Error: Source does not allow column references\n");
- }
-
+ }
+
Y_UNIT_TEST(UseUnknownColumnInInsert) {
NYql::TAstParseResult res = SqlToYql("insert into plato.Output (list0, list1) values (AsList(0, 1, 2), AsList([test]));");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:34: Error: Source does not allow column references\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupByEmptyColumn) {
NYql::TAstParseResult res = SqlToYql("select count(1) from plato.Input group by [];");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:43: Error: Column name can not be empty\n");
- }
+ }
Y_UNIT_TEST(RollbackUnsupported) {
NYql::TAstParseResult res = SqlToYql("insert into plato.Output (v0, v1) values (0, 1); rollback;");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:50: Error: ROLLBACK isn't supported for provider: yt\n");
}
-
+
Y_UNIT_TEST(ShouldFailAsTruncatedBinaryNotSucceedAsLegacyTinyZeroInt) {
NYql::TAstParseResult res = SqlToYql("select 0b;");
UNIT_ASSERT(!res.Root);
@@ -1626,40 +1626,40 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(ConvertNumberFailed0) {
- NYql::TAstParseResult res = SqlToYql("select 0o80l;");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("select 0o80l;");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Failed to parse number from string: 0o80l, char: '8' is out of base: 8\n");
- }
-
+ }
+
Y_UNIT_TEST(ConvertNumberFailed1) {
- NYql::TAstParseResult res = SqlToYql("select 0xc000000000000000l;");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("select 0xc000000000000000l;");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Failed to convert string: 13835058055282163712 to Int64 value\n");
- }
-
+ }
+
Y_UNIT_TEST(ConvertNumberFailed2) {
- NYql::TAstParseResult res = SqlToYql("select 0xc0000000000000000l;");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("select 0xc0000000000000000l;");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Failed to parse number from string: 0xc0000000000000000l, number limit overflow\n");
- }
-
+ }
+
Y_UNIT_TEST(InvaildUsageReal0) {
- NYql::TAstParseResult res = SqlToYql("select .0;");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("select .0;");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:7: Error: Unexpected token '.' : cannot match to any predicted input...\n\n");
- }
-
+ }
+
Y_UNIT_TEST(InvaildUsageReal1) {
- NYql::TAstParseResult res = SqlToYql("select .0f;");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("select .0f;");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:7: Error: Unexpected token '.' : cannot match to any predicted input...\n\n");
- }
-
+ }
+
Y_UNIT_TEST(InvaildUsageWinFunctionWithoutWindow) {
- NYql::TAstParseResult res = SqlToYql("select lead(key, 2) from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("select lead(key, 2) from plato.Input;");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Failed to use window function: Lead without window specification\n");
- }
+ }
Y_UNIT_TEST(DropTableWithIfExists) {
NYql::TAstParseResult res = SqlToYql("DROP TABLE IF EXISTS plato.foo;");
diff --git a/ydb/library/yql/sql/v0/ya.make b/ydb/library/yql/sql/v0/ya.make
index e9a236cf3e..c7410eadfd 100644
--- a/ydb/library/yql/sql/v0/ya.make
+++ b/ydb/library/yql/sql/v0/ya.make
@@ -34,8 +34,8 @@ SRCS(
YQL_LAST_ABI_VERSION()
-GENERATE_ENUM_SERIALIZATION(node.h)
-
+GENERATE_ENUM_SERIALIZATION(node.h)
+
END()
RECURSE_FOR_TESTS(
diff --git a/ydb/library/yql/sql/v1/SQLv1.g.in b/ydb/library/yql/sql/v1/SQLv1.g.in
index c869ba4bcb..ef394c7a00 100644
--- a/ydb/library/yql/sql/v1/SQLv1.g.in
+++ b/ydb/library/yql/sql/v1/SQLv1.g.in
@@ -1,7 +1,7 @@
grammar SQLv1;
options {
- language = Cpp;
+ language = Cpp;
memoize = true;
}
@@ -11,28 +11,28 @@ sql_stmt_list: SEMICOLON* sql_stmt (SEMICOLON+ sql_stmt)* SEMICOLON* EOF;
ansi_sql_stmt_list: SEMICOLON* EOF;
lambda_body: SEMICOLON* (lambda_stmt SEMICOLON+)* RETURN expr SEMICOLON*;
-lambda_stmt:
- named_nodes_stmt
- | import_stmt
-;
-
+lambda_stmt:
+ named_nodes_stmt
+ | import_stmt
+;
+
sql_stmt: (EXPLAIN (Q U E R Y PLAN)?)? sql_stmt_core;
-sql_stmt_core:
- pragma_stmt
+sql_stmt_core:
+ pragma_stmt
| select_stmt
- | named_nodes_stmt
+ | named_nodes_stmt
| create_table_stmt
| drop_table_stmt
| use_stmt
- | into_table_stmt
+ | into_table_stmt
| commit_stmt
- | update_stmt
- | delete_stmt
+ | update_stmt
+ | delete_stmt
| rollback_stmt
- | declare_stmt
- | import_stmt
- | export_stmt
+ | declare_stmt
+ | import_stmt
+ | export_stmt
| alter_table_stmt
| do_stmt
| define_action_or_subquery_stmt
@@ -44,7 +44,7 @@ sql_stmt_core:
| create_group_stmt
| alter_group_stmt
| drop_role_stmt
-;
+;
expr:
or_subexpr (OR or_subexpr)*
@@ -58,13 +58,13 @@ xor_subexpr: eq_subexpr cond_expr?;
distinct_from_op: IS NOT? DISTINCT FROM;
-cond_expr:
- NOT? match_op eq_subexpr (ESCAPE eq_subexpr)?
+cond_expr:
+ NOT? match_op eq_subexpr (ESCAPE eq_subexpr)?
| NOT? IN COMPACT? in_expr
| (ISNULL | NOTNULL | IS NULL | (IS)? NOT NULL)
| NOT? BETWEEN eq_subexpr AND eq_subexpr
| ((EQUALS | EQUALS2 | NOT_EQUALS | NOT_EQUALS2 | distinct_from_op) eq_subexpr)+ /* order of the eq subexpressions is reversed! */
-;
+;
match_op: LIKE | ILIKE | GLOB | REGEXP | RLIKE | MATCH;
@@ -109,10 +109,10 @@ expr_struct_list: expr COLON expr (COMMA expr COLON expr)*;
struct_literal: STRUCT_OPEN expr_struct_list? COMMA? STRUCT_CLOSE;
-atom_expr:
- literal_value
+atom_expr:
+ literal_value
| bind_parameter
- | lambda
+ | lambda
| cast_expr
| exists_expr
| case_expr
@@ -122,7 +122,7 @@ atom_expr:
| list_literal
| dict_literal
| struct_literal
-;
+;
in_atom_expr:
literal_value
@@ -150,9 +150,9 @@ exists_expr: EXISTS LPAREN (select_stmt | values_stmt) RPAREN;
case_expr: CASE expr? when_expr+ (ELSE expr)? END;
lambda: smart_parenthesis (ARROW ((LPAREN expr RPAREN) | (LBRACE_CURLY lambda_body RBRACE_CURLY)) )?;
-
+
in_expr: in_unary_subexpr;
-
+
// ANSI SQL JSON support
json_api_expr: json_value | json_exists | json_query;
@@ -191,28 +191,28 @@ json_query: JSON_QUERY LPAREN
(json_query_handler ON ERROR)?
RPAREN;
-// struct, tuple or named list
-smart_parenthesis: LPAREN named_expr_list? COMMA? RPAREN;
-
-expr_list: expr (COMMA expr)*;
+// struct, tuple or named list
+smart_parenthesis: LPAREN named_expr_list? COMMA? RPAREN;
+
+expr_list: expr (COMMA expr)*;
pure_column_list: LPAREN an_id (COMMA an_id)* RPAREN;
-
+
pure_column_or_named: bind_parameter | an_id;
pure_column_or_named_list: LPAREN pure_column_or_named (COMMA pure_column_or_named)* RPAREN;
column_name: opt_id_prefix an_id;
without_column_name: (an_id DOT an_id) | an_id_without;
-
+
column_list: column_name (COMMA column_name)* COMMA?;
without_column_list: without_column_name (COMMA without_column_name)* COMMA?;
-
+
named_expr: expr (AS an_id_or_type)?;
-
-named_expr_list: named_expr (COMMA named_expr)*;
-
+
+named_expr_list: named_expr (COMMA named_expr)*;
+
invoke_expr: LPAREN (opt_set_quantifier named_expr_list COMMA? | ASTERISK)? RPAREN invoke_expr_tail;
-
+
// null_treatment can only happen after window functions LAG/LEAD/NTH/FIRST_VALUE/LAST_VALUE
// filter_clause can only happen after aggregation functions
invoke_expr_tail:
@@ -225,30 +225,30 @@ key_expr: LBRACE_SQUARE expr RBRACE_SQUARE;
when_expr: WHEN expr THEN expr;
-literal_value:
- integer
- | real
+literal_value:
+ integer
+ | real
| STRING_VALUE
- | BLOB // it's unused right now
+ | BLOB // it's unused right now
| NULL
- | CURRENT_TIME // it's unused right now
- | CURRENT_DATE // it's unused right now
- | CURRENT_TIMESTAMP // it's unused right now
+ | CURRENT_TIME // it's unused right now
+ | CURRENT_DATE // it's unused right now
+ | CURRENT_TIMESTAMP // it's unused right now
| bool_value
| EMPTY_ACTION
-;
+;
bind_parameter: DOLLAR an_id_or_type;
opt_bind_parameter: bind_parameter QUESTION?;
-bind_parameter_list: bind_parameter (COMMA bind_parameter)*;
-named_bind_parameter: bind_parameter (AS bind_parameter)?;
-named_bind_parameter_list: named_bind_parameter (COMMA named_bind_parameter)*;
-
-signed_number: (PLUS | MINUS)? (integer | real);
+bind_parameter_list: bind_parameter (COMMA bind_parameter)*;
+named_bind_parameter: bind_parameter (AS bind_parameter)?;
+named_bind_parameter_list: named_bind_parameter (COMMA named_bind_parameter)*;
+
+signed_number: (PLUS | MINUS)? (integer | real);
type_name_simple: an_id_pure;
-
+
integer_or_bind: integer | bind_parameter;
type_name_tag: id | STRING_VALUE | bind_parameter;
@@ -305,42 +305,42 @@ value_constructor:
declare_stmt: DECLARE bind_parameter AS type_name (EQUALS literal_value)?;
module_path: DOT? an_id (DOT an_id)*;
-import_stmt: IMPORT module_path SYMBOLS named_bind_parameter_list;
-export_stmt: EXPORT bind_parameter_list;
-
+import_stmt: IMPORT module_path SYMBOLS named_bind_parameter_list;
+export_stmt: EXPORT bind_parameter_list;
+
call_action: (bind_parameter | EMPTY_ACTION) LPAREN expr_list? RPAREN;
inline_action: BEGIN define_action_or_subquery_body END DO;
do_stmt: DO (call_action | inline_action);
pragma_stmt: PRAGMA opt_id_prefix_or_type an_id (EQUALS pragma_value | LPAREN pragma_value (COMMA pragma_value)* RPAREN)?;
-pragma_value:
- signed_number
- | id
+pragma_value:
+ signed_number
+ | id
| STRING_VALUE
- | bool_value
+ | bool_value
| bind_parameter
-;
+;
+
+/// TODO: NULLS FIRST\LAST?
+sort_specification: expr (ASC | DESC)?;
-/// TODO: NULLS FIRST\LAST?
-sort_specification: expr (ASC | DESC)?;
+sort_specification_list: sort_specification (COMMA sort_specification)*;
-sort_specification_list: sort_specification (COMMA sort_specification)*;
-
-select_stmt: select_kind_parenthesis (select_op select_kind_parenthesis)*;
+select_stmt: select_kind_parenthesis (select_op select_kind_parenthesis)*;
select_unparenthesized_stmt: select_kind_partial (select_op select_kind_parenthesis)*;
-select_kind_parenthesis: select_kind_partial | LPAREN select_kind_partial RPAREN;
+select_kind_parenthesis: select_kind_partial | LPAREN select_kind_partial RPAREN;
select_op: UNION (ALL)? | INTERSECT | EXCEPT;
-select_kind_partial: select_kind
+select_kind_partial: select_kind
(LIMIT expr ((OFFSET | COMMA) expr)?)?
- ;
-
+ ;
+
select_kind: (DISCARD)? (process_core | reduce_core | select_core) (INTO RESULT pure_column_or_named)?;
-process_core:
+process_core:
PROCESS STREAM? named_single_source (COMMA named_single_source)* (USING using_call_expr (AS an_id)?
(WITH external_call_settings)?
(WHERE expr)? (HAVING expr)? (ASSUME order_by_clause)?)?
@@ -349,50 +349,50 @@ process_core:
external_call_param: an_id EQUALS expr;
external_call_settings: external_call_param (COMMA external_call_param)*;
-reduce_core:
+reduce_core:
REDUCE named_single_source (COMMA named_single_source)* (PRESORT sort_specification_list)?
ON column_list USING ALL? using_call_expr (AS an_id)?
(WHERE expr)? (HAVING expr)? (ASSUME order_by_clause)?
-;
-
-opt_set_quantifier: (ALL | DISTINCT)?;
-
+;
+
+opt_set_quantifier: (ALL | DISTINCT)?;
+
select_core:
(FROM join_source)? SELECT STREAM? opt_set_quantifier result_column (COMMA result_column)* COMMA? (WITHOUT without_column_list)? (FROM join_source)? (WHERE expr)?
group_by_clause? (HAVING expr)? window_clause? ext_order_by_clause?
;
-order_by_clause: ORDER BY sort_specification_list;
-
+order_by_clause: ORDER BY sort_specification_list;
+
ext_order_by_clause: ASSUME? order_by_clause;
group_by_clause: GROUP COMPACT? BY opt_set_quantifier grouping_element_list;
-
-grouping_element_list: grouping_element (COMMA grouping_element)*;
-
-grouping_element:
- ordinary_grouping_set
- | rollup_list
- | cube_list
- | grouping_sets_specification
-//empty_grouping_set inside smart_parenthesis
+
+grouping_element_list: grouping_element (COMMA grouping_element)*;
+
+grouping_element:
+ ordinary_grouping_set
+ | rollup_list
+ | cube_list
+ | grouping_sets_specification
+//empty_grouping_set inside smart_parenthesis
| hopping_window_specification
-;
-
-/// expect column (named column), or parenthesis list columns, or expression (named expression), or list expression
-ordinary_grouping_set: named_expr;
-ordinary_grouping_set_list: ordinary_grouping_set (COMMA ordinary_grouping_set)*;
-
-rollup_list: ROLLUP LPAREN ordinary_grouping_set_list RPAREN;
-cube_list: CUBE LPAREN ordinary_grouping_set_list RPAREN;
-
-/// SQL2003 grouping_set_list == grouping_element_list
-grouping_sets_specification: GROUPING SETS LPAREN grouping_element_list RPAREN;
-
+;
+
+/// expect column (named column), or parenthesis list columns, or expression (named expression), or list expression
+ordinary_grouping_set: named_expr;
+ordinary_grouping_set_list: ordinary_grouping_set (COMMA ordinary_grouping_set)*;
+
+rollup_list: ROLLUP LPAREN ordinary_grouping_set_list RPAREN;
+cube_list: CUBE LPAREN ordinary_grouping_set_list RPAREN;
+
+/// SQL2003 grouping_set_list == grouping_element_list
+grouping_sets_specification: GROUPING SETS LPAREN grouping_element_list RPAREN;
+
hopping_window_specification: HOP LPAREN expr COMMA expr COMMA expr COMMA expr RPAREN;
-result_column:
- opt_id_prefix ASTERISK
+result_column:
+ opt_id_prefix ASTERISK
| expr ((AS an_id_or_type) | an_id_pure)?
;
@@ -401,17 +401,17 @@ join_source: ANY? flatten_source (join_op ANY? flatten_source join_constraint?)*
named_column: column_name (AS an_id)?;
flatten_by_arg:
- named_column
+ named_column
| LPAREN named_expr_list COMMA? RPAREN
-;
-
+;
+
flatten_source: named_single_source (FLATTEN ((OPTIONAL|LIST|DICT)? BY flatten_by_arg | COLUMNS))?;
-
+
named_single_source: single_source (((AS an_id) | an_id_pure) pure_column_list?)? (sample_clause | tablesample_clause)?;
-
-single_source:
- table_ref
- | LPAREN select_stmt RPAREN
+
+single_source:
+ table_ref
+ | LPAREN select_stmt RPAREN
| LPAREN values_stmt RPAREN
;
@@ -423,21 +423,21 @@ sampling_mode: (BERNOULLI | SYSTEM);
repeatable_clause: REPEATABLE LPAREN expr RPAREN;
-join_op:
- COMMA
+join_op:
+ COMMA
| (NATURAL)? ((LEFT (ONLY | SEMI)? | RIGHT (ONLY | SEMI)? | EXCLUSION | FULL)? (OUTER)? | INNER | CROSS) SORTED? JOIN
;
-join_constraint:
- ON expr
+join_constraint:
+ ON expr
| USING pure_column_or_named_list
;
into_table_stmt: (INSERT | INSERT OR ABORT | INSERT OR REVERT | INSERT OR IGNORE | UPSERT | REPLACE) INTO into_simple_table_ref into_values_source;
-
-into_values_source:
- pure_column_list? values_source
- | DEFAULT VALUES
+
+into_values_source:
+ pure_column_list? values_source
+ | DEFAULT VALUES
;
values_stmt: VALUES values_source_row_list;
@@ -445,9 +445,9 @@ values_stmt: VALUES values_source_row_list;
values_source: values_stmt | select_stmt;
values_source_row_list: values_source_row (COMMA values_source_row)*;
values_source_row: LPAREN expr_list RPAREN;
-
-simple_values_source: expr_list | select_stmt;
-
+
+simple_values_source: expr_list | select_stmt;
+
create_table_stmt: CREATE TABLE simple_table_ref LPAREN create_table_entry (COMMA create_table_entry)* RPAREN
with_table_settings?;
create_table_entry:
@@ -582,64 +582,64 @@ table_hint:
simple_table_ref: (((cluster_expr DOT)? id_or_at) | AT? bind_parameter) table_hints?;
into_simple_table_ref: simple_table_ref (ERASE BY pure_column_list)?;
-
+
delete_stmt: DELETE FROM simple_table_ref (WHERE expr | ON into_values_source)?;
update_stmt: UPDATE simple_table_ref (SET set_clause_choice (WHERE expr)? | ON into_values_source);
-/// out of 2003 standart
-set_clause_choice: set_clause_list | multiple_column_assignment;
-
-set_clause_list: set_clause (COMMA set_clause)*;
-set_clause: set_target EQUALS expr;
-set_target: column_name;
-multiple_column_assignment: set_target_list EQUALS LPAREN simple_values_source RPAREN;
-set_target_list: LPAREN set_target (COMMA set_target)* RPAREN;
-
-/// window function supp
-// differ from 2003 for resolve conflict
-null_treatment: RESPECT NULLS | IGNORE NULLS;
-
+/// out of 2003 standart
+set_clause_choice: set_clause_list | multiple_column_assignment;
+
+set_clause_list: set_clause (COMMA set_clause)*;
+set_clause: set_target EQUALS expr;
+set_target: column_name;
+multiple_column_assignment: set_target_list EQUALS LPAREN simple_values_source RPAREN;
+set_target_list: LPAREN set_target (COMMA set_target)* RPAREN;
+
+/// window function supp
+// differ from 2003 for resolve conflict
+null_treatment: RESPECT NULLS | IGNORE NULLS;
+
filter_clause: FILTER LPAREN WHERE expr RPAREN;
window_name_or_specification: window_name | window_specification;
-
+
window_name: an_id_window;
-
-window_clause: WINDOW window_definition_list;
-
-window_definition_list: window_definition (COMMA window_definition)*;
-
-window_definition: new_window_name AS window_specification;
-
-new_window_name: window_name;
-
-window_specification: LPAREN window_specification_details RPAREN;
-
-window_specification_details:
- existing_window_name?
- window_partition_clause?
- window_order_clause?
- window_frame_clause?
-;
-
-existing_window_name: window_name;
+
+window_clause: WINDOW window_definition_list;
+
+window_definition_list: window_definition (COMMA window_definition)*;
+
+window_definition: new_window_name AS window_specification;
+
+new_window_name: window_name;
+
+window_specification: LPAREN window_specification_details RPAREN;
+
+window_specification_details:
+ existing_window_name?
+ window_partition_clause?
+ window_order_clause?
+ window_frame_clause?
+;
+
+existing_window_name: window_name;
window_partition_clause: PARTITION COMPACT? BY named_expr_list;
window_order_clause: order_by_clause;
-window_frame_clause: window_frame_units window_frame_extent window_frame_exclusion?;
+window_frame_clause: window_frame_units window_frame_extent window_frame_exclusion?;
window_frame_units: ROWS | RANGE | GROUPS;
-
+
window_frame_extent: window_frame_bound | window_frame_between;
-
+
window_frame_between: BETWEEN window_frame_bound AND window_frame_bound;
window_frame_bound:
CURRENT ROW
| (expr | UNBOUNDED) (PRECEDING | FOLLOWING)
-;
-
-window_frame_exclusion: EXCLUDE CURRENT ROW | EXCLUDE GROUP | EXCLUDE TIES | EXCLUDE NO OTHERS;
-
+;
+
+window_frame_exclusion: EXCLUDE CURRENT ROW | EXCLUDE GROUP | EXCLUDE TIES | EXCLUDE NO OTHERS;
+
// EXTRAS
use_stmt: USE cluster_expr;
@@ -780,61 +780,61 @@ keyword:
| keyword_hint_uncompat
| keyword_schema_uncompat
;
-
-keyword_expr_uncompat:
+
+keyword_expr_uncompat:
BETWEEN
| BITCAST
| CASE
- | CAST
- | CUBE
+ | CAST
+ | CUBE
| CURRENT_DATE
- | CURRENT_TIME
- | CURRENT_TIMESTAMP
+ | CURRENT_TIME
+ | CURRENT_TIMESTAMP
| EMPTY_ACTION
- | EXISTS
- | FROM
- | FULL
+ | EXISTS
+ | FROM
+ | FULL
| HOP
| JSON_EXISTS
| JSON_VALUE
| JSON_QUERY
| LOCAL
- | NOT
- | NULL
- | PROCESS
- | REDUCE
- | RETURN
- | ROLLUP
- | SELECT
+ | NOT
+ | NULL
+ | PROCESS
+ | REDUCE
+ | RETURN
+ | ROLLUP
+ | SELECT
| UNBOUNDED
- | WHEN
- | WHERE
-;
-
+ | WHEN
+ | WHERE
+;
+
keyword_table_uncompat:
ANY
| ERASE
| STREAM
;
-keyword_select_uncompat:
- ALL
- | AS
+keyword_select_uncompat:
+ ALL
+ | AS
| ASSUME
- | DISTINCT
+ | DISTINCT
| EXCEPT
- | HAVING
+ | HAVING
| INTERSECT
| LIMIT
| UNION
| WINDOW
| WITHOUT
-;
-
-keyword_alter_uncompat:
- COLUMN
-;
-
+;
+
+keyword_alter_uncompat:
+ COLUMN
+;
+
keyword_in_uncompat:
COMPACT
;
@@ -854,14 +854,14 @@ keyword_schema_uncompat:
FAMILY
;
-keyword_compat: (
+keyword_compat: (
ABORT
| ACTION
| ADD
| AFTER
| ALTER
| ANALYZE
- | AND
+ | AND
| ANSI
| ARRAY
| ASC
@@ -883,10 +883,10 @@ keyword_compat: (
| COVER
| CREATE
| CROSS
- | CURRENT
+ | CURRENT
| DATABASE
| DECIMAL
- | DECLARE
+ | DECLARE
| DEFAULT
| DEFERRABLE
| DEFERRED
@@ -906,27 +906,27 @@ keyword_compat: (
| ERROR
| ESCAPE
| EVALUATE
- | EXCLUDE
+ | EXCLUDE
| EXCLUSION
| EXCLUSIVE
| EXPLAIN
- | EXPORT
+ | EXPORT
| EXTERNAL
| FAIL
| FILTER
- | FLATTEN
- | FOLLOWING
+ | FLATTEN
+ | FOLLOWING
| FOR
| FOREIGN
| FUNCTION
| GLOB
| GROUP
- | GROUPING
+ | GROUPING
| IF
| IGNORE
| ILIKE
| IMMEDIATE
- | IMPORT
+ | IMPORT
| IN
| INDEX
| INDEXED
@@ -938,12 +938,12 @@ keyword_compat: (
| IS
| ISNULL
| JOIN
- | KEY
+ | KEY
| LEFT
| LIKE
| MATCH
| NATURAL
- | NO
+ | NO
| NOTNULL
| NULLS
| OBJECT
@@ -953,16 +953,16 @@ keyword_compat: (
| ONLY
| OR
| ORDER
- | OTHERS
+ | OTHERS
| OUTER
- | OVER
+ | OVER
| PARTITION
| PASSING
| PASSWORD
| PLAN
| PRAGMA
- | PRECEDING
- | PRESORT
+ | PRECEDING
+ | PRESORT
| PRIMARY
// | QUERY
| RAISE
@@ -973,22 +973,22 @@ keyword_compat: (
| RENAME
| REPLACE
| RESET
- | RESPECT
+ | RESPECT
| RESTRICT
| RESULT
| RETURNING
| REVERT
- | RIGHT
- | RLIKE
+ | RIGHT
+ | RLIKE
| ROLLBACK
| ROW
| SAMPLE
| SAVEPOINT
| SEMI
- | SETS
+ | SETS
| SORTED
| SUBQUERY
- | SYMBOLS
+ | SYMBOLS
| SYNC
| SYSTEM
| TABLE
@@ -996,7 +996,7 @@ keyword_compat: (
| TEMP
| TEMPORARY
| THEN
- | TIES
+ | TIES
| TO
| TRANSACTION
| TRIGGER
@@ -1004,7 +1004,7 @@ keyword_compat: (
| UNIQUE
| UNKNOWN
| UPDATE
- | UPSERT
+ | UPSERT
| USER
| USING
| VACUUM
@@ -1013,7 +1013,7 @@ keyword_compat: (
| VIRTUAL
| WITH
| WRAPPER
- | XOR
+ | XOR
);
type_id:
@@ -1072,16 +1072,16 @@ COLON: ':';
AT: '@';
DOUBLE_AT: '@@';
DOLLAR: '$';
-QUOTE_DOUBLE: '"'; // This comment for fix syntax highlighting "
+QUOTE_DOUBLE: '"'; // This comment for fix syntax highlighting "
QUOTE_SINGLE: '\'';
BACKTICK: '`';
LBRACE_CURLY: '{';
RBRACE_CURLY: '}';
CARET: '^';
NAMESPACE: '::';
-ARROW: '->';
-RBRACE_SQUARE: ']';
-LBRACE_SQUARE: '['; // pair ]
+ARROW: '->';
+RBRACE_SQUARE: ']';
+LBRACE_SQUARE: '['; // pair ]
// http://www.antlr.org/wiki/pages/viewpage.action?pageId=1782
fragment A:('a'|'A');
@@ -1152,14 +1152,14 @@ CONSTRAINT: C O N S T R A I N T;
COVER: C O V E R;
CREATE: C R E A T E;
CROSS: C R O S S;
-CUBE: C U B E;
-CURRENT: C U R R E N T;
+CUBE: C U B E;
+CURRENT: C U R R E N T;
CURRENT_TIME: C U R R E N T '_' T I M E;
CURRENT_DATE: C U R R E N T '_' D A T E;
CURRENT_TIMESTAMP: C U R R E N T '_' T I M E S T A M P;
DATABASE: D A T A B A S E;
DECIMAL: D E C I M A L;
-DECLARE: D E C L A R E;
+DECLARE: D E C L A R E;
DEFAULT: D E F A U L T;
DEFERRABLE: D E F E R R A B L E;
DEFERRED: D E F E R R E D;
@@ -1185,19 +1185,19 @@ ERASE: E R A S E;
ESCAPE: E S C A P E;
EVALUATE: E V A L U A T E;
EXCEPT: E X C E P T;
-EXCLUDE: E X C L U D E;
+EXCLUDE: E X C L U D E;
EXCLUSIVE: E X C L U S I V E;
EXCLUSION: E X C L U S I O N;
EXISTS: E X I S T S;
EXPLAIN: E X P L A I N;
-EXPORT: E X P O R T;
+EXPORT: E X P O R T;
EXTERNAL: E X T E R N A L;
FAIL: F A I L;
FAMILY: F A M I L Y;
FILTER: F I L T E R;
-FLATTEN: F L A T T E N;
+FLATTEN: F L A T T E N;
FLOW: F L O W;
-FOLLOWING: F O L L O W I N G;
+FOLLOWING: F O L L O W I N G;
FOR: F O R;
FOREIGN: F O R E I G N;
FROM: F R O M;
@@ -1206,7 +1206,7 @@ FUNCTION: F U N C T I O N;
GLOB: G L O B;
GLOBAL: G L O B A L;
GROUP: G R O U P;
-GROUPING: G R O U P I N G;
+GROUPING: G R O U P I N G;
GROUPS: G R O U P S;
HAVING: H A V I N G;
HOP: H O P;
@@ -1214,7 +1214,7 @@ IF: I F;
IGNORE: I G N O R E;
ILIKE: I L I K E;
IMMEDIATE: I M M E D I A T E;
-IMPORT: I M P O R T;
+IMPORT: I M P O R T;
IN: I N;
INDEX: I N D E X;
INDEXED: I N D E X E D;
@@ -1230,7 +1230,7 @@ JOIN: J O I N;
JSON_EXISTS: J S O N '_' E X I S T S;
JSON_VALUE: J S O N '_' V A L U E;
JSON_QUERY: J S O N '_' Q U E R Y;
-KEY: K E Y;
+KEY: K E Y;
LEFT: L E F T;
LIKE: L I K E;
LIMIT: L I M I T;
@@ -1238,11 +1238,11 @@ LIST: L I S T;
LOCAL: L O C A L;
MATCH: M A T C H;
NATURAL: N A T U R A L;
-NO: N O;
+NO: N O;
NOT: N O T;
NOTNULL: N O T N U L L;
NULL: N U L L;
-NULLS: N U L L S;
+NULLS: N U L L S;
OBJECT: O B J E C T;
OF: O F;
OFFSET: O F F S E T;
@@ -1251,21 +1251,21 @@ ONLY: O N L Y;
OPTIONAL: O P T I O N A L;
OR: O R;
ORDER: O R D E R;
-OTHERS: O T H E R S;
+OTHERS: O T H E R S;
OUTER: O U T E R;
-OVER: O V E R;
-PARTITION: P A R T I T I O N;
+OVER: O V E R;
+PARTITION: P A R T I T I O N;
PASSING: P A S S I N G;
PASSWORD: P A S S W O R D;
PLAN: P L A N;
PRAGMA: P R A G M A;
-PRECEDING: P R E C E D I N G;
-PRESORT: P R E S O R T;
+PRECEDING: P R E C E D I N G;
+PRESORT: P R E S O R T;
PRIMARY: P R I M A R Y;
PROCESS: P R O C E S S;
//QUERY: Q U E R Y;
RAISE: R A I S E;
-RANGE: R A N G E;
+RANGE: R A N G E;
REDUCE: R E D U C E;
REFERENCES: R E F E R E N C E S;
REGEXP: R E G E X P;
@@ -1276,30 +1276,30 @@ REPEATABLE: R E P E A T A B L E;
REPLACE: R E P L A C E;
RESET: R E S E T;
RESOURCE: R E S O U R C E;
-RESPECT: R E S P E C T;
+RESPECT: R E S P E C T;
RESTRICT: R E S T R I C T;
RESULT: R E S U L T;
-RETURN: R E T U R N;
+RETURN: R E T U R N;
RETURNING: R E T U R N I N G;
REVERT: R E V E R T;
RIGHT: R I G H T;
-RLIKE: R L I K E;
+RLIKE: R L I K E;
ROLLBACK: R O L L B A C K;
-ROLLUP: R O L L U P;
+ROLLUP: R O L L U P;
ROW: R O W;
-ROWS: R O W S;
+ROWS: R O W S;
SAMPLE: S A M P L E;
SAVEPOINT: S A V E P O I N T;
SCHEMA: S C H E M A;
SELECT: S E L E C T;
SEMI: S E M I;
SET: S E T;
-SETS: S E T S;
+SETS: S E T S;
SORTED: S O R T E D;
STREAM: S T R E A M;
STRUCT: S T R U C T;
SUBQUERY: S U B Q U E R Y;
-SYMBOLS: S Y M B O L S;
+SYMBOLS: S Y M B O L S;
SYNC: S Y N C;
SYSTEM: S Y S T E M;
TABLE: T A B L E;
@@ -1308,18 +1308,18 @@ TAGGED: T A G G E D;
TEMP: T E M P;
TEMPORARY: T E M P O R A R Y;
THEN: T H E N;
-TIES: T I E S;
+TIES: T I E S;
TO: T O;
TRANSACTION: T R A N S A C T I O N;
TRIGGER: T R I G G E R;
TUPLE: T U P L E;
-UNBOUNDED: U N B O U N D E D;
+UNBOUNDED: U N B O U N D E D;
UNCONDITIONAL: U N C O N D I T I O N A L;
UNION: U N I O N;
UNIQUE: U N I Q U E;
UNKNOWN: U N K N O W N;
UPDATE: U P D A T E;
-UPSERT: U P S E R T;
+UPSERT: U P S E R T;
USE: U S E;
USER: U S E R;
USING: U S I N G;
@@ -1330,9 +1330,9 @@ VIEW: V I E W;
VIRTUAL: V I R T U A L;
WHEN: W H E N;
WHERE: W H E R E;
-WINDOW: W I N D O W;
+WINDOW: W I N D O W;
WITH: W I T H;
-WITHOUT: W I T H O U T;
+WITHOUT: W I T H O U T;
WRAPPER: W R A P P E R;
XOR: X O R;
TRUE: T R U E;
@@ -1360,25 +1360,25 @@ ID_PLAIN: ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | DIGIT)*;
fragment ID_QUOTED_CORE: '``' | '\\`' | ~'`';
ID_QUOTED: BACKTICK ID_QUOTED_CORE* BACKTICK;
-fragment DIGIT: '0'..'9';
-fragment HEXDIGIT: '0'..'9' | 'a'..'f' | 'A'..'F';
-fragment HEXDIGITS: '0' X HEXDIGIT+;
-fragment OCTDIGITS: '0' O ('0'..'8')+;
-fragment BINDIGITS: '0' B ('0' | '1')+;
-fragment DECDIGITS: DIGIT+;
-DIGITS: DECDIGITS | HEXDIGITS | OCTDIGITS | BINDIGITS;
-
+fragment DIGIT: '0'..'9';
+fragment HEXDIGIT: '0'..'9' | 'a'..'f' | 'A'..'F';
+fragment HEXDIGITS: '0' X HEXDIGIT+;
+fragment OCTDIGITS: '0' O ('0'..'8')+;
+fragment BINDIGITS: '0' B ('0' | '1')+;
+fragment DECDIGITS: DIGIT+;
+DIGITS: DECDIGITS | HEXDIGITS | OCTDIGITS | BINDIGITS;
+
INTEGER_VALUE: DIGITS (U? (L | S | T)?);
-
-fragment FLOAT_EXP : E (PLUS | MINUS)? DECDIGITS ;
-REAL:
- DECDIGITS DOT DIGIT* FLOAT_EXP? F?
- | DECDIGITS FLOAT_EXP F?
-// | DOT DECDIGITS FLOAT_EXP? // Conflicts with tuple element access through DOT
+
+fragment FLOAT_EXP : E (PLUS | MINUS)? DECDIGITS ;
+REAL:
+ DECDIGITS DOT DIGIT* FLOAT_EXP? F?
+ | DECDIGITS FLOAT_EXP F?
+// | DOT DECDIGITS FLOAT_EXP? // Conflicts with tuple element access through DOT
;
-BLOB: X QUOTE_SINGLE HEXDIGIT+ QUOTE_SINGLE;
-
+BLOB: X QUOTE_SINGLE HEXDIGIT+ QUOTE_SINGLE;
+
// YQL Default Lexer:
// GRAMMAR_MULTILINE_COMMENT_CORE = .
// ANSI Lexer:
diff --git a/ydb/library/yql/sql/v1/aggregation.cpp b/ydb/library/yql/sql/v1/aggregation.cpp
index d8929ee25d..850e0e5056 100644
--- a/ydb/library/yql/sql/v1/aggregation.cpp
+++ b/ydb/library/yql/sql/v1/aggregation.cpp
@@ -117,18 +117,18 @@ protected:
if (!IsGeneratedKeyColumn && src->GetJoin()) {
const auto sourcePtr = Expr->GetSourceName();
if (!sourcePtr || !*sourcePtr) {
- if (!src->IsGroupByColumn(DistinctKey)) {
- ctx.Error(Expr->GetPos()) << ErrorDistinctWithoutCorrelation(DistinctKey);
- return false;
- }
- } else {
- DistinctKey = DotJoin(*sourcePtr, DistinctKey);
- }
- }
- if (src->IsGroupByColumn(DistinctKey)) {
- ctx.Error(Expr->GetPos()) << ErrorDistinctByGroupKey(DistinctKey);
- return false;
- }
+ if (!src->IsGroupByColumn(DistinctKey)) {
+ ctx.Error(Expr->GetPos()) << ErrorDistinctWithoutCorrelation(DistinctKey);
+ return false;
+ }
+ } else {
+ DistinctKey = DotJoin(*sourcePtr, DistinctKey);
+ }
+ }
+ if (src->IsGroupByColumn(DistinctKey)) {
+ ctx.Error(Expr->GetPos()) << ErrorDistinctByGroupKey(DistinctKey);
+ return false;
+ }
Expr = AstNode("row");
}
@@ -169,13 +169,13 @@ public:
TAggregationFactoryImpl(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode, bool multi)
: TAggregationFactory(pos, name, func, aggMode, multi)
{}
-
+
private:
TNodePtr DoClone() const final {
return new TAggregationFactoryImpl(Pos, Name, Func, AggMode, Multi);
- }
+ }
};
-
+
TAggregationPtr BuildFactoryAggregation(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode, bool multi) {
return new TAggregationFactoryImpl(pos, name, func, aggMode, multi);
}
@@ -1132,7 +1132,7 @@ private:
const auto j = adjustArgsCount + i;
Lambdas[i] = BuildLambda(Pos, Y("state"), j >= exprs.size() ? AstNode("state") : Y("Apply", exprs[j], "state"));
}
-
+
DefVal = (exprs.size() == (7 + adjustArgsCount)) ? exprs[adjustArgsCount + 6] : Y("Null");
return TAggregationFactory::InitAggr(ctx, isFactory, src, node, isFactory ? TVector<TNodePtr>() : TVector<TNodePtr>(1, exprs.front()));
}
@@ -1189,12 +1189,12 @@ private:
return true;
}
- if (Expr->IsAsterisk()) {
+ if (Expr->IsAsterisk()) {
Expr = Y("Void");
- }
- if (!Expr->Init(ctx, src)) {
- return false;
- }
+ }
+ if (!Expr->Init(ctx, src)) {
+ return false;
+ }
Expr->SetCountHint(Expr->IsConstant());
return TAggregationFactory::DoInit(ctx, src);
}
diff --git a/ydb/library/yql/sql/v1/builtin.cpp b/ydb/library/yql/sql/v1/builtin.cpp
index 516f3b9086..43ef1243f1 100644
--- a/ydb/library/yql/sql/v1/builtin.cpp
+++ b/ydb/library/yql/sql/v1/builtin.cpp
@@ -16,7 +16,7 @@
#include <util/string/builder.h>
#include <util/string/cast.h>
#include <util/string/util.h>
-#include <util/string/join.h>
+#include <util/string/join.h>
#include <util/system/env.h>
#include <unordered_map>
@@ -51,28 +51,28 @@ TMaybe<TString> MakeTypeConfig(const TString& ns, const TVector<TNodePtr>& udfAr
return Nothing();
}
-class TGroupingNode final: public TAstListNode {
-public:
+class TGroupingNode final: public TAstListNode {
+public:
TGroupingNode(TPosition pos, const TVector<TNodePtr>& args)
- : TAstListNode(pos)
- , Args(args)
- {}
-
+ : TAstListNode(pos)
+ , Args(args)
+ {}
+
bool DoInit(TContext& ctx, ISource* src) final {
- if (!src) {
- ctx.Error(Pos) << "Grouping function should have source";
- return false;
- }
+ if (!src) {
+ ctx.Error(Pos) << "Grouping function should have source";
+ return false;
+ }
TVector<TString> columns;
- columns.reserve(Args.size());
+ columns.reserve(Args.size());
const bool isJoin = src->GetJoin();
ISource* composite = src->GetCompositeSource();
- for (const auto& node: Args) {
- auto namePtr = node->GetColumnName();
- if (!namePtr || !*namePtr) {
+ for (const auto& node: Args) {
+ auto namePtr = node->GetColumnName();
+ if (!namePtr || !*namePtr) {
ctx.Error(Pos) << "GROUPING function should use columns as arguments";
- return false;
- }
+ return false;
+ }
TString column = *namePtr;
if (isJoin) {
auto sourceNamePtr = node->GetSourceName();
@@ -83,27 +83,27 @@ public:
if (!src->IsGroupByColumn(column) && !src->IsAlias(EExprSeat::GroupBy, *namePtr) && (!composite || !composite->IsGroupByColumn(column))) {
ctx.Error(node->GetPos()) << "Column '" << column << "' is not a grouping column";
- return false;
- }
- columns.emplace_back(column);
- }
- ui64 hint;
- if (!src->CalculateGroupingHint(ctx, columns, hint)) {
- return false;
- }
- Nodes.push_back(BuildAtom(Pos, "Uint64"));
- Nodes.push_back(BuildQuotedAtom(Pos, IntToString<10>(hint)));
- return TAstListNode::DoInit(ctx, src);
- }
-
+ return false;
+ }
+ columns.emplace_back(column);
+ }
+ ui64 hint;
+ if (!src->CalculateGroupingHint(ctx, columns, hint)) {
+ return false;
+ }
+ Nodes.push_back(BuildAtom(Pos, "Uint64"));
+ Nodes.push_back(BuildQuotedAtom(Pos, IntToString<10>(hint)));
+ return TAstListNode::DoInit(ctx, src);
+ }
+
TNodePtr DoClone() const final {
- return new TGroupingNode(Pos, Args);
- }
-
-private:
+ return new TGroupingNode(Pos, Args);
+ }
+
+private:
const TVector<TNodePtr> Args;
-};
-
+};
+
class TBasicAggrFunc final: public TAstListNode {
public:
TBasicAggrFunc(TPosition pos, const TString& name, TAggregationPtr aggr, const TVector<TNodePtr>& args)
@@ -111,17 +111,17 @@ public:
, Name(name)
, Aggr(aggr)
, Args(args)
- {}
+ {}
TCiString GetName() const {
return Name;
}
bool DoInit(TContext& ctx, ISource* src) final {
- if (!src) {
- ctx.Error(Pos) << "Unable to use aggregation function '" << Name << "' without data source";
- return false;
- }
+ if (!src) {
+ ctx.Error(Pos) << "Unable to use aggregation function '" << Name << "' without data source";
+ return false;
+ }
if (!DoInitAggregation(ctx, src)) {
return false;
}
@@ -159,14 +159,14 @@ public:
}
TNodePtr DoClone() const final {
- TAggregationPtr aggrClone = static_cast<IAggregation*>(Aggr->Clone().Release());
- return new TBasicAggrFunc(Pos, Name, aggrClone, CloneContainer(Args));
- }
-
- TAggregationPtr GetAggregation() const override {
- return Aggr;
- }
-
+ TAggregationPtr aggrClone = static_cast<IAggregation*>(Aggr->Clone().Release());
+ return new TBasicAggrFunc(Pos, Name, aggrClone, CloneContainer(Args));
+ }
+
+ TAggregationPtr GetAggregation() const override {
+ return Aggr;
+ }
+
private:
bool DoInitAggregation(TContext& ctx, ISource* src) {
if (PreaggregateExpr) {
@@ -185,9 +185,9 @@ private:
void DoUpdateState() const final {
State.Set(ENodeState::Const, !Args.empty() && AllOf(Args, [](const auto& arg){ return arg->IsConstant(); }));
- State.Set(ENodeState::Aggregated);
- }
-
+ State.Set(ENodeState::Aggregated);
+ }
+
TNodePtr PreaggregateExpr;
protected:
const TString Name;
@@ -257,7 +257,7 @@ protected:
TNodePtr Lambda;
};
-typedef THolder<TBasicAggrFunc> TAggrFuncPtr;
+typedef THolder<TBasicAggrFunc> TAggrFuncPtr;
class TLiteralStringAtom: public INode {
public:
@@ -268,8 +268,8 @@ public:
{
}
- bool DoInit(TContext& ctx, ISource* src) override {
- Y_UNUSED(src);
+ bool DoInit(TContext& ctx, ISource* src) override {
+ Y_UNUSED(src);
if (!Node) {
ctx.Error(Pos) << Info;
return false;
@@ -295,14 +295,14 @@ public:
return Atom ? Atom->GetLiteralValue() : "";
}
- TAstNode* Translate(TContext& ctx) const override {
+ TAstNode* Translate(TContext& ctx) const override {
return Atom->Translate(ctx);
}
- TPtr DoClone() const final {
- return {};
- }
-
+ TPtr DoClone() const final {
+ return {};
+ }
+
void DoUpdateState() const override {
YQL_ENSURE(Atom);
State.Set(ENodeState::Const, Atom->IsConstant());
@@ -655,7 +655,7 @@ public:
{}
bool DoInit(TContext& ctx, ISource* src) override {
- if (!ValidateArguments(ctx)) {
+ if (!ValidateArguments(ctx)) {
return false;
}
@@ -679,7 +679,7 @@ public:
{}
bool DoInit(TContext& ctx, ISource* src) override {
- if (!ValidateArguments(ctx)) {
+ if (!ValidateArguments(ctx)) {
return false;
}
@@ -721,7 +721,7 @@ public:
{}
bool DoInit(TContext& ctx, ISource* src) override {
- if (!ValidateArguments(ctx)) {
+ if (!ValidateArguments(ctx)) {
return false;
}
@@ -810,26 +810,26 @@ public:
}
};
-TNodePtr BuildFileNameArgument(TPosition pos, const TNodePtr& argument) {
- return new TLiteralStringAtom(pos, argument, "FilePath requires string literal as parameter");
-}
-
+TNodePtr BuildFileNameArgument(TPosition pos, const TNodePtr& argument) {
+ return new TLiteralStringAtom(pos, argument, "FilePath requires string literal as parameter");
+}
+
class TYqlAtom final: public TCallNode {
public:
TYqlAtom(TPosition pos, const TString& opName, const TVector<TNodePtr>& args)
- : TCallNode(pos, opName, 1, 1, args)
- {}
+ : TCallNode(pos, opName, 1, 1, args)
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
- if (!Args.empty()) {
- Args[0] = BuildFileNameArgument(ctx.Pos(), Args[0]);
- }
- return TCallNode::DoInit(ctx, src);
+ bool DoInit(TContext& ctx, ISource* src) override {
+ if (!Args.empty()) {
+ Args[0] = BuildFileNameArgument(ctx.Pos(), Args[0]);
+ }
+ return TCallNode::DoInit(ctx, src);
}
-
- TNodePtr DoClone() const final {
+
+ TNodePtr DoClone() const final {
return new TYqlAtom(Pos, OpName, Args);
- }
+ }
bool IsLiteral() const override {
return !Args.empty() ? Args[0]->IsLiteral() : false;
@@ -842,7 +842,7 @@ public:
TString GetLiteralValue() const override {
return !Args.empty() ? Args[0]->GetLiteralValue() : "";
}
-};
+};
class TTryMember final: public TCallNode {
public:
@@ -992,68 +992,68 @@ TString NormalizeTypeString(const TString& str) {
static const TSet<TString> AvailableDataTypes = {"Bool", "String", "Uint32", "Uint64", "Int32", "Int64", "Float", "Double", "Utf8", "Yson", "Json", "JsonDocument",
"Date", "Datetime", "Timestamp", "Interval", "Uint8", "Int8", "Uint16", "Int16", "TzDate", "TzDatetime", "TzTimestamp", "Uuid", "Decimal", "DyNumber"};
-TNodePtr GetDataTypeStringNode(TContext& ctx, TCallNode& node, unsigned argNum, TString* outTypeStrPtr = nullptr) {
- auto errMsgFunc = [&node, argNum]() {
+TNodePtr GetDataTypeStringNode(TContext& ctx, TCallNode& node, unsigned argNum, TString* outTypeStrPtr = nullptr) {
+ auto errMsgFunc = [&node, argNum]() {
static std::array<TString, 2> numToName = {{"first", "second"}};
- TStringBuilder sb;
- sb << "At " << numToName.at(argNum) << " argument of " << node.GetOpName() << " expected type string, available one of: "
- << JoinRange(", ", AvailableDataTypes.begin(), AvailableDataTypes.end()) << ";";
+ TStringBuilder sb;
+ sb << "At " << numToName.at(argNum) << " argument of " << node.GetOpName() << " expected type string, available one of: "
+ << JoinRange(", ", AvailableDataTypes.begin(), AvailableDataTypes.end()) << ";";
return TString(sb);
- };
- auto typeStringNode = node.GetArgs().at(argNum);
- auto typeStringPtr = typeStringNode->GetLiteral("String");
- TNodePtr dataTypeNode;
- if (typeStringPtr) {
+ };
+ auto typeStringNode = node.GetArgs().at(argNum);
+ auto typeStringPtr = typeStringNode->GetLiteral("String");
+ TNodePtr dataTypeNode;
+ if (typeStringPtr) {
TString typeString = NormalizeTypeString(*typeStringPtr);
if (!AvailableDataTypes.contains(typeString)) {
- ctx.Error(typeStringNode->GetPos()) << "Bad type string: '" << typeString << "'. " << errMsgFunc();
- return {};
- }
- if (outTypeStrPtr) {
- *outTypeStrPtr = typeString;
- }
- dataTypeNode = typeStringNode->Q(typeString);
- } else {
- ctx.Error(typeStringNode->GetPos()) << errMsgFunc();
- return {};
- }
- return dataTypeNode;
-}
-
-class TYqlParseFileOp final: public TCallNode {
-public:
+ ctx.Error(typeStringNode->GetPos()) << "Bad type string: '" << typeString << "'. " << errMsgFunc();
+ return {};
+ }
+ if (outTypeStrPtr) {
+ *outTypeStrPtr = typeString;
+ }
+ dataTypeNode = typeStringNode->Q(typeString);
+ } else {
+ ctx.Error(typeStringNode->GetPos()) << errMsgFunc();
+ return {};
+ }
+ return dataTypeNode;
+}
+
+class TYqlParseFileOp final: public TCallNode {
+public:
TYqlParseFileOp(TPosition pos, const TVector<TNodePtr>& args)
- : TCallNode(pos, "ParseFile", 2, 2, args)
- {}
-
- bool DoInit(TContext& ctx, ISource* src) override {
- if (!ValidateArguments(ctx)) {
- return false;
- }
-
- auto dataTypeStringNode = GetDataTypeStringNode(ctx, *this, 0);
- if (!dataTypeStringNode) {
- return false;
- }
- auto aliasNode = BuildFileNameArgument(Args[1]->GetPos(), Args[1]);
- OpName = "Apply";
+ : TCallNode(pos, "ParseFile", 2, 2, args)
+ {}
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ if (!ValidateArguments(ctx)) {
+ return false;
+ }
+
+ auto dataTypeStringNode = GetDataTypeStringNode(ctx, *this, 0);
+ if (!dataTypeStringNode) {
+ return false;
+ }
+ auto aliasNode = BuildFileNameArgument(Args[1]->GetPos(), Args[1]);
+ OpName = "Apply";
Args[0] = Y("Udf", Q("File.ByLines"), Y("Void"),
Y("TupleType",
Y("TupleType", Y("DataType", dataTypeStringNode)),
Y("StructType"),
Y("TupleType")));
- Args[1] = Y("FilePath", aliasNode);
- return TCallNode::DoInit(ctx, src);
+ Args[1] = Y("FilePath", aliasNode);
+ return TCallNode::DoInit(ctx, src);
}
-
+
TString GetOpName() const override {
- return "ParseFile";
- }
-
- TNodePtr DoClone() const final {
- return new TYqlParseFileOp(Pos, Args);
- }
+ return "ParseFile";
+ }
+
+ TNodePtr DoClone() const final {
+ return new TYqlParseFileOp(Pos, Args);
+ }
};
class TYqlDataType final : public TCallNode {
@@ -1278,22 +1278,22 @@ private:
};
template <bool IsStrict>
-class TYqlIf final: public TCallNode {
+class TYqlIf final: public TCallNode {
public:
TYqlIf(TPosition pos, const TVector<TNodePtr>& args)
: TCallNode(pos, IsStrict ? "IfStrict" : "If", 2, 3, args)
- {}
+ {}
private:
TCallNode::TPtr DoClone() const override {
- return new TYqlIf(GetPos(), CloneContainer(Args));
+ return new TYqlIf(GetPos(), CloneContainer(Args));
}
bool DoInit(TContext& ctx, ISource* src) override {
- if (!ValidateArguments(ctx)) {
- return false;
- }
-
+ if (!ValidateArguments(ctx)) {
+ return false;
+ }
+
Args[0] = Y("Coalesce", Args[0], Y("Bool", Q("false")));
if (Args.size() == 2) {
Args.push_back(Y("Null"));
@@ -1321,23 +1321,23 @@ private:
}
};
-class TYqlIn final: public TCallNode {
+class TYqlIn final: public TCallNode {
public:
TYqlIn(TPosition pos, const TVector<TNodePtr>& args)
: TCallNode(pos, "IN", 3, 3, args)
- {}
+ {}
private:
- TNodePtr DoClone() const final {
- return new TYqlIn(Pos, CloneContainer(Args));
- }
- bool DoInit(TContext& ctx, ISource* src) override {
- if (!ValidateArguments(ctx)) {
- return false;
- }
-
+ TNodePtr DoClone() const final {
+ return new TYqlIn(Pos, CloneContainer(Args));
+ }
+ bool DoInit(TContext& ctx, ISource* src) override {
+ if (!ValidateArguments(ctx)) {
+ return false;
+ }
+
auto key = Args[0];
- auto inNode = Args[1];
+ auto inNode = Args[1];
auto hints = Args[2];
const auto pos = inNode->GetPos();
@@ -1350,11 +1350,11 @@ private:
return false;
}
- if (inNode->GetLiteral("String")) {
+ if (inNode->GetLiteral("String")) {
ctx.Error(pos) << "Unable to use IN predicate with string argument, it won't search substring - "
"expecting tuple, list, dict or single column table source";
- return false;
- }
+ return false;
+ }
if (inNode->GetTupleSize() == 1) {
auto singleElement = inNode->GetTupleElement(0);
@@ -1385,39 +1385,39 @@ private:
OpName = "SqlIn";
MinArgs = MaxArgs = 3;
- Args = {
+ Args = {
inNode->GetSource() ? inNode->GetSource() : inNode,
- key,
+ key,
BuildTuple(pos, hintElements)
- };
+ };
return TCallNode::DoInit(ctx, src);
}
-
+
static TNodePtr BuildHint(TPosition pos, const TString& name) {
return BuildTuple(pos, { BuildQuotedAtom(pos, name, NYql::TNodeFlags::Default) });
}
- TString GetOpName() const override {
- return "IN predicate";
- }
+ TString GetOpName() const override {
+ return "IN predicate";
+ }
};
class TYqlUdfBase : public TCallNode {
public:
TYqlUdfBase(TPosition pos, const TString& name)
: TCallNode(pos, "Udf", 1, 1, UdfArgs(pos, name))
- {}
+ {}
TYqlUdfBase(TPosition pos, const TString& name, const TVector<TNodePtr>& args, ui32 argsCount = 2)
: TCallNode(pos, "Udf", argsCount, argsCount, UdfArgs(pos, name, &args))
- {}
+ {}
protected:
TYqlUdfBase(TPosition pos, const TString& opName, ui32 minArgs, ui32 maxArgs, const TVector<TNodePtr>& args)
: TCallNode(pos, opName, minArgs, maxArgs, args)
- {}
-
+ {}
+
private:
static TVector<TNodePtr> UdfArgs(TPosition pos, const TString& name, const TVector<TNodePtr>* args = nullptr) {
TVector<TNodePtr> res = { BuildQuotedAtom(pos, name) };
@@ -1427,12 +1427,12 @@ private:
return res;
}
- void DoUpdateState() const override {
- TCallNode::DoUpdateState();
- State.Set(ENodeState::Aggregated, false/*!RunConfig || RunConfig->IsAggregated()*/);
+ void DoUpdateState() const override {
+ TCallNode::DoUpdateState();
+ State.Set(ENodeState::Aggregated, false/*!RunConfig || RunConfig->IsAggregated()*/);
State.Set(ENodeState::Const, true /* FIXME: To avoid CheckAggregationLevel issue for non-const TypeOf. */);
- }
-
+ }
+
private:
TNodePtr RunConfig;
};
@@ -1490,23 +1490,23 @@ private:
}
};
-class TWeakFieldOp final: public TCallNode {
-public:
+class TWeakFieldOp final: public TCallNode {
+public:
TWeakFieldOp(TPosition pos, const TVector<TNodePtr>& args)
- : TCallNode(pos, "WeakField", 2, 3, args)
- {}
-
- bool DoInit(TContext& ctx, ISource* src) override {
- if (!src) {
- ctx.Error(Pos) << GetCallExplain() << " unable use without source";
- return false;
- }
-
- src->AllColumns();
-
- if (!ValidateArguments(ctx)) {
- return false;
- }
+ : TCallNode(pos, "WeakField", 2, 3, args)
+ {}
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ if (!src) {
+ ctx.Error(Pos) << GetCallExplain() << " unable use without source";
+ return false;
+ }
+
+ src->AllColumns();
+
+ if (!ValidateArguments(ctx)) {
+ return false;
+ }
bool hasError = false;
for (auto& arg: Args) {
@@ -1520,9 +1520,9 @@ public:
return false;
}
- PrecacheState();
-
- const auto memberPos = Args[0]->GetPos();
+ PrecacheState();
+
+ const auto memberPos = Args[0]->GetPos();
TVector<TNodePtr> repackArgs = {BuildAtom(memberPos, "row", NYql::TNodeFlags::Default)};
if (auto literal = Args[1]->GetLiteral("String")) {
TString targetType;
@@ -1533,59 +1533,59 @@ public:
repackArgs.push_back(Args[1]->Q(targetType));
} else {
repackArgs.push_back(Args[1]);
- }
-
+ }
+
TVector<TNodePtr> column;
- auto namePtr = Args[0]->GetColumnName();
- if (!namePtr || !*namePtr) {
+ auto namePtr = Args[0]->GetColumnName();
+ if (!namePtr || !*namePtr) {
ctx.Error(Pos) << GetCallExplain() << " expects column name as first argument";
- return false;
- }
- auto memberName = *namePtr;
- column.push_back(Args[0]->Q(*namePtr));
-
- if (src->GetJoin() && !src->IsJoinKeysInitializing()) {
- const auto sourcePtr = Args[0]->GetSourceName();
- if (!sourcePtr || !*sourcePtr) {
- ctx.Error(Pos) << GetOpName() << " required to have correlation name in case of JOIN for column at first parameter";
- return false;
- }
- column.push_back(Args[0]->Q(*sourcePtr));
- memberName = DotJoin(*sourcePtr, memberName);
- }
- if (!GetLabel()) {
- SetLabel(memberName);
- }
- repackArgs.push_back(BuildTuple(memberPos, column));
- if (Args.size() == 3) {
- repackArgs.push_back(Args[2]);
- }
- ++MinArgs;
- ++MaxArgs;
- Args.swap(repackArgs);
-
- return TCallNode::DoInit(ctx, src);
- }
-
- TNodePtr DoClone() const final {
- return new TWeakFieldOp(Pos, Args);
- }
-};
-
+ return false;
+ }
+ auto memberName = *namePtr;
+ column.push_back(Args[0]->Q(*namePtr));
+
+ if (src->GetJoin() && !src->IsJoinKeysInitializing()) {
+ const auto sourcePtr = Args[0]->GetSourceName();
+ if (!sourcePtr || !*sourcePtr) {
+ ctx.Error(Pos) << GetOpName() << " required to have correlation name in case of JOIN for column at first parameter";
+ return false;
+ }
+ column.push_back(Args[0]->Q(*sourcePtr));
+ memberName = DotJoin(*sourcePtr, memberName);
+ }
+ if (!GetLabel()) {
+ SetLabel(memberName);
+ }
+ repackArgs.push_back(BuildTuple(memberPos, column));
+ if (Args.size() == 3) {
+ repackArgs.push_back(Args[2]);
+ }
+ ++MinArgs;
+ ++MaxArgs;
+ Args.swap(repackArgs);
+
+ return TCallNode::DoInit(ctx, src);
+ }
+
+ TNodePtr DoClone() const final {
+ return new TWeakFieldOp(Pos, Args);
+ }
+};
+
template <bool Join>
class TTableRow final : public INode {
public:
TTableRow(TPosition pos, const TVector<TNodePtr>& args)
- : TTableRow(pos, args.size())
- {}
-
- TTableRow(TPosition pos, ui32 argsCount)
+ : TTableRow(pos, args.size())
+ {}
+
+ TTableRow(TPosition pos, ui32 argsCount)
: INode(pos)
- , ArgsCount(argsCount)
+ , ArgsCount(argsCount)
{}
bool DoInit(TContext& ctx, ISource* src) override {
- if (!src || src->IsFake()) {
+ if (!src || src->IsFake()) {
ctx.Error(Pos) << "TableRow requires data source";
return false;
}
@@ -1595,7 +1595,7 @@ public:
return false;
}
- src->AllColumns();
+ src->AllColumns();
const bool isJoin = src->GetJoin();
if (!Join && ctx.SimpleColumns && isJoin) {
TNodePtr block = Y();
@@ -1891,57 +1891,57 @@ private:
TNodePtr BuildUdfUserTypeArg(TPosition pos, const TVector<TNodePtr>& args, TNodePtr customUserType) {
TVector<TNodePtr> argsTypeItems;
- for (auto& arg : args) {
+ for (auto& arg : args) {
argsTypeItems.push_back(new TCallNodeImpl(pos, "TypeOf", TVector<TNodePtr>(1, arg)));
- }
-
+ }
+
TVector<TNodePtr> userTypeItems;
- userTypeItems.push_back(new TCallNodeImpl(pos, "TupleType", argsTypeItems));
- userTypeItems.push_back(new TCallNodeImpl(pos, "StructType", {}));
+ userTypeItems.push_back(new TCallNodeImpl(pos, "TupleType", argsTypeItems));
+ userTypeItems.push_back(new TCallNodeImpl(pos, "StructType", {}));
if (customUserType) {
userTypeItems.push_back(customUserType);
} else {
userTypeItems.push_back(new TCallNodeImpl(pos, "TupleType", {}));
}
-
- return new TCallNodeImpl(pos, "TupleType", userTypeItems);
-}
-
+
+ return new TCallNodeImpl(pos, "TupleType", userTypeItems);
+}
+
TNodePtr BuildUdfUserTypeArg(TPosition pos, TNodePtr positionalArgs, TNodePtr namedArgs, TNodePtr customUserType) {
TVector<TNodePtr> userTypeItems;
userTypeItems.reserve(3);
- userTypeItems.push_back(positionalArgs->Y("TypeOf", positionalArgs));
- userTypeItems.push_back(positionalArgs->Y("TypeOf", namedArgs));
+ userTypeItems.push_back(positionalArgs->Y("TypeOf", positionalArgs));
+ userTypeItems.push_back(positionalArgs->Y("TypeOf", namedArgs));
if (customUserType) {
userTypeItems.push_back(customUserType);
} else {
userTypeItems.push_back(new TCallNodeImpl(pos, "TupleType", {}));
}
-
- return new TCallNodeImpl(pos, "TupleType", userTypeItems);
-}
-
+
+ return new TCallNodeImpl(pos, "TupleType", userTypeItems);
+}
+
TVector<TNodePtr> BuildUdfArgs(const TContext& ctx, TPosition pos, const TVector<TNodePtr>& args,
TNodePtr positionalArgs, TNodePtr namedArgs, TNodePtr customUserType, TMaybe<TString> typeConfig) {
if (!ctx.Settings.EnableGenericUdfs) {
- return {};
- }
+ return {};
+ }
TVector<TNodePtr> udfArgs;
- udfArgs.push_back(new TAstListNodeImpl(pos));
- udfArgs[0]->Add(new TAstAtomNodeImpl(pos, "Void", 0));
- if (namedArgs) {
+ udfArgs.push_back(new TAstListNodeImpl(pos));
+ udfArgs[0]->Add(new TAstAtomNodeImpl(pos, "Void", 0));
+ if (namedArgs) {
udfArgs.push_back(BuildUdfUserTypeArg(pos, positionalArgs, namedArgs, customUserType));
- } else {
+ } else {
udfArgs.push_back(BuildUdfUserTypeArg(pos, args, customUserType));
- }
+ }
if (typeConfig) {
udfArgs.push_back(BuildQuotedAtom(pos, *typeConfig));
}
- return udfArgs;
-}
-
+ return udfArgs;
+}
+
TNodePtr BuildSqlCall(TContext& ctx, TPosition pos, const TString& module, const TString& name, const TVector<TNodePtr>& args,
TNodePtr positionalArgs, TNodePtr namedArgs, TNodePtr customUserType, TMaybe<TString> typeConfig)
{
@@ -1986,7 +1986,7 @@ TNodePtr BuildSqlCall(TContext& ctx, TPosition pos, const TString& module, const
return new TCallNodeImpl(pos, "SqlCall", sqlCallArgs);
}
-class TCallableNode final: public INode {
+class TCallableNode final: public INode {
public:
TCallableNode(TPosition pos, const TString& module, const TString& name, const TVector<TNodePtr>& args, bool forReduce)
: INode(pos)
@@ -1994,9 +1994,9 @@ public:
, Name(name)
, Args(args)
, ForReduce(forReduce)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
if (Module == "yql") {
Node = new TFuncNodeImpl(Pos, Name);
} else if (Module == "@yql") {
@@ -2007,7 +2007,7 @@ public:
const TString yql("(" + parsedName->Content + ")");
TAstParseResult ast = ParseAst(yql, ctx.Pool.get());
- /// TODO: do not drop warnings
+ /// TODO: do not drop warnings
if (ast.IsOk()) {
const auto rootCount = ast.Root->GetChildrenCount();
if (rootCount != 1) {
@@ -2016,13 +2016,13 @@ public:
}
Node = AstNode(ast.Root->GetChild(0));
} else {
- ctx.Error(Pos) << "Failed to parse YQL: " << ast.Issues.ToString();
+ ctx.Error(Pos) << "Failed to parse YQL: " << ast.Issues.ToString();
return false;
}
- if (src) {
- src->AllColumns();
- }
+ if (src) {
+ src->AllColumns();
+ }
} else if (ctx.Settings.ModuleMapping.contains(Module)) {
Node = Y("bind", Module + "_module", Q(Name));
if (src) {
@@ -2059,7 +2059,7 @@ public:
return Node->Init(ctx, src);
}
- TAstNode* Translate(TContext& ctx) const override {
+ TAstNode* Translate(TContext& ctx) const override {
Y_VERIFY_DEBUG(Node);
return Node->Translate(ctx);
}
@@ -2072,15 +2072,15 @@ public:
return &Module;
}
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, Node->IsConstant());
- State.Set(ENodeState::Aggregated, Node->IsAggregated());
- }
-
- TNodePtr DoClone() const override {
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, Node->IsConstant());
+ State.Set(ENodeState::Aggregated, Node->IsAggregated());
+ }
+
+ TNodePtr DoClone() const override {
return new TCallableNode(Pos, Module, Name, Args, ForReduce);
- }
-
+ }
+
void DoVisitChildren(const TVisitFunc& func, TVisitNodeSet& visited) const final {
Y_VERIFY_DEBUG(Node);
Node->VisitTree(func, visited);
@@ -2112,16 +2112,16 @@ TNodePtr BuildUdf(TContext& ctx, TPosition pos, const TString& module, const TSt
}
}
-class TScriptUdf final: public INode {
+class TScriptUdf final: public INode {
public:
TScriptUdf(TPosition pos, const TString& moduleName, const TString& funcName, const TVector<TNodePtr>& args)
- : INode(pos)
+ : INode(pos)
, ModuleName(moduleName)
, FuncName(funcName)
, Args(args)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
const bool isPython = ModuleName.find(TStringBuf("Python")) != TString::npos;
if (!isPython) {
if (Args.size() != 2) {
@@ -2166,19 +2166,19 @@ public:
return true;
}
- TAstNode* Translate(TContext& ctx) const override {
+ TAstNode* Translate(TContext& ctx) const override {
Y_UNUSED(ctx);
Y_VERIFY_DEBUG(Node);
return Node->Translate(ctx);
}
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, true);
- }
-
- TNodePtr DoClone() const final {
- return new TScriptUdf(GetPos(), ModuleName, FuncName, CloneContainer(Args));
- }
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, true);
+ }
+
+ TNodePtr DoClone() const final {
+ return new TScriptUdf(GetPos(), ModuleName, FuncName, CloneContainer(Args));
+ }
void DoVisitChildren(const TVisitFunc& func, TVisitNodeSet& visited) const final {
Y_VERIFY_DEBUG(Node);
@@ -2259,7 +2259,7 @@ private:
}
};
-class TInvalidBuiltin final: public INode {
+class TInvalidBuiltin final: public INode {
public:
TInvalidBuiltin(TPosition pos, const TString& info)
: INode(pos)
@@ -2267,23 +2267,23 @@ public:
{
}
- bool DoInit(TContext& ctx, ISource*) override {
+ bool DoInit(TContext& ctx, ISource*) override {
ctx.Error(Pos) << Info;
return false;
}
- TAstNode* Translate(TContext&) const override {
+ TAstNode* Translate(TContext&) const override {
return nullptr;
}
- TPtr DoClone() const override {
- return {};
- }
+ TPtr DoClone() const override {
+ return {};
+ }
private:
TString Info;
};
-enum EAggrFuncTypeCallback {
+enum EAggrFuncTypeCallback {
NORMAL,
KEY_PAYLOAD,
PAYLOAD_PREDICATE,
@@ -2315,7 +2315,7 @@ using TCoreFuncMap = std::unordered_map<TString, TCoreFuncInfo, THash<TString>>;
TAggrFuncFactoryCallback BuildAggrFuncFactoryCallback(
const TString& functionName,
const TString& factoryName,
- EAggrFuncTypeCallback type = NORMAL,
+ EAggrFuncTypeCallback type = NORMAL,
const TString& functionNameOverride = TString(),
const TVector<EAggregateMode>& validModes = {}) {
@@ -2335,12 +2335,12 @@ TAggrFuncFactoryCallback BuildAggrFuncFactoryCallback(
}
}
TAggregationPtr factory = nullptr;
- switch (type) {
+ switch (type) {
case NORMAL:
- factory = BuildFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
+ factory = BuildFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case KEY_PAYLOAD:
- factory = BuildKeyPayloadFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
+ factory = BuildKeyPayloadFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case PAYLOAD_PREDICATE:
factory = BuildPayloadPredicateFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
@@ -2349,16 +2349,16 @@ TAggrFuncFactoryCallback BuildAggrFuncFactoryCallback(
factory = BuildTwoArgsFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case COUNT:
- factory = BuildCountAggregation(pos, realFunctionName, factoryName, aggMode);
+ factory = BuildCountAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case HISTOGRAM:
- factory = BuildHistogramFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
+ factory = BuildHistogramFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case LINEAR_HISTOGRAM:
factory = BuildLinearHistogramFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case PERCENTILE:
- factory = BuildPercentileFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
+ factory = BuildPercentileFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case TOPFREQ:
factory = BuildTopFreqFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
@@ -2376,7 +2376,7 @@ TAggrFuncFactoryCallback BuildAggrFuncFactoryCallback(
factory = BuildListFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
case UDAF:
- factory = BuildUserDefinedFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
+ factory = BuildUserDefinedFactoryAggregation(pos, realFunctionName, factoryName, aggMode);
break;
}
if (isFactory) {
@@ -2566,7 +2566,7 @@ struct TBuiltinFuncData {
// Atom builtins
{"asatom", BuildSimpleBuiltinFactoryCallback<TYqlAsAtom>()},
{"secureparam", BuildNamedBuiltinFactoryCallback<TYqlAtom>("SecureParam")},
-
+
{"void", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("Void", 0, 0)},
{"emptylist", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("EmptyList", 0, 0)},
{"emptydict", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("EmptyDict", 0, 0)},
@@ -2697,7 +2697,7 @@ struct TBuiltinFuncData {
{"folderpath", BuildNamedBuiltinFactoryCallback<TYqlAtom>("FolderPath") },
{"files", BuildNamedBuiltinFactoryCallback<TYqlAtom>("Files")},
{"parsefile", BuildSimpleBuiltinFactoryCallback<TYqlParseFileOp>()},
-
+
// Misc builtins
{"coalesce", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("Coalesce", 1, -1)},
{"nvl", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("Coalesce", 1, -1) },
@@ -2800,9 +2800,9 @@ struct TBuiltinFuncData {
{"variance", BuildAggrFuncFactoryCallback("Variance", "variance_0_1_traits_factory")},
{"stddev", BuildAggrFuncFactoryCallback("StdDev", "variance_1_1_traits_factory")},
- {"populationvariance", BuildAggrFuncFactoryCallback("VariancePopulation", "variance_0_0_traits_factory")},
+ {"populationvariance", BuildAggrFuncFactoryCallback("VariancePopulation", "variance_0_0_traits_factory")},
{"variancepopulation", BuildAggrFuncFactoryCallback("VariancePopulation", "variance_0_0_traits_factory")},
- {"populationstddev", BuildAggrFuncFactoryCallback("StdDevPopulation", "variance_1_0_traits_factory")},
+ {"populationstddev", BuildAggrFuncFactoryCallback("StdDevPopulation", "variance_1_0_traits_factory")},
{"stddevpopulation", BuildAggrFuncFactoryCallback("StdDevPopulation", "variance_1_0_traits_factory")},
{"varpop", BuildAggrFuncFactoryCallback("VariancePopulation", "variance_0_0_traits_factory")},
{"stddevpop", BuildAggrFuncFactoryCallback("StdDevPopulation", "variance_1_0_traits_factory")},
@@ -2827,7 +2827,7 @@ struct TBuiltinFuncData {
{"covarp", BuildAggrFuncFactoryCallback("CovariancePopulation", "covariance_population_traits_factory", TWO_ARGS, "CovarP")},
{"udaf", BuildAggrFuncFactoryCallback("UDAF", "udaf_traits_factory", UDAF)},
-
+
// Window functions
{"firstvalue", BuildAggrFuncFactoryCallback("FirstValue", "first_value_traits_factory", {OverWindow})},
{"lastvalue", BuildAggrFuncFactoryCallback("LastValue", "last_value_traits_factory", {OverWindow})},
@@ -2954,15 +2954,15 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
if (ns == "yql") {
return new TCallNodeImpl(pos, name, -1, -1, args);
}
- } else if (moduleResource) {
- auto exportName = ns == "core" ? name : "$" + name;
+ } else if (moduleResource) {
+ auto exportName = ns == "core" ? name : "$" + name;
TVector<TNodePtr> applyArgs = {
new TCallNodeImpl(pos, "bind", {
- BuildAtom(pos, ns + "_module", 0), BuildQuotedAtom(pos, exportName)
+ BuildAtom(pos, ns + "_module", 0), BuildQuotedAtom(pos, exportName)
})
- };
- applyArgs.insert(applyArgs.end(), args.begin(), args.end());
- return new TCallNodeImpl(pos, "Apply", applyArgs);
+ };
+ applyArgs.insert(applyArgs.end(), args.begin(), args.end());
+ return new TCallNodeImpl(pos, "Apply", applyArgs);
} else if (ns == "hyperscan" || ns == "pcre" || ns == "pire" || ns.StartsWith("re2")) {
TString moduleName(nameSpace);
moduleName.to_title();
@@ -3153,24 +3153,24 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
if (aggrCallback != aggrFuncs.end()) {
return (*aggrCallback).second(pos, args, aggMode, false).Release();
}
- if (aggMode == EAggregateMode::Distinct) {
+ if (aggMode == EAggregateMode::Distinct) {
return new TInvalidBuiltin(pos, "DISTINCT can only be used in aggregation functions");
}
auto builtinCallback = builtinFuncs.find(normalizedName);
if (builtinCallback != builtinFuncs.end()) {
- return (*builtinCallback).second(pos, args);
+ return (*builtinCallback).second(pos, args);
} else if (normalizedName == "asstruct" || normalizedName == "structtype") {
if (args.empty()) {
return new TCallNodeImpl(pos, normalizedName == "asstruct" ? "AsStruct" : "StructType", 0, 0, args);
}
- if (mustUseNamed && *mustUseNamed) {
- *mustUseNamed = false;
- YQL_ENSURE(args.size() == 2);
- Y_VERIFY_DEBUG(dynamic_cast<TTupleNode*>(args[0].Get()));
- auto posArgs = static_cast<TTupleNode*>(args[0].Get());
- if (posArgs->IsEmpty()) {
+ if (mustUseNamed && *mustUseNamed) {
+ *mustUseNamed = false;
+ YQL_ENSURE(args.size() == 2);
+ Y_VERIFY_DEBUG(dynamic_cast<TTupleNode*>(args[0].Get()));
+ auto posArgs = static_cast<TTupleNode*>(args[0].Get());
+ if (posArgs->IsEmpty()) {
if (normalizedName == "asstruct") {
return args[1];
} else {
@@ -3178,8 +3178,8 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
auto namedArgs = static_cast<TStructNode*>(args[1].Get());
return new TStructTypeNode(pos, namedArgs->GetExprs());
}
- }
- }
+ }
+ }
return new TInvalidBuiltin(pos, TStringBuilder() <<
(normalizedName == "asstruct" ? "AsStruct" : "StructType") <<
" requires all argument to be named");
@@ -3210,15 +3210,15 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
}
}
- TNodePtr positionalArgs;
- TNodePtr namedArgs;
- if (mustUseNamed && *mustUseNamed) {
- YQL_ENSURE(args.size() == 2);
- positionalArgs = args[0];
- namedArgs = args[1];
- *mustUseNamed = false;
- }
-
+ TNodePtr positionalArgs;
+ TNodePtr namedArgs;
+ if (mustUseNamed && *mustUseNamed) {
+ YQL_ENSURE(args.size() == 2);
+ positionalArgs = args[0];
+ namedArgs = args[1];
+ *mustUseNamed = false;
+ }
+
TVector<TNodePtr> usedArgs = args;
TNodePtr customUserType = nullptr;
diff --git a/ydb/library/yql/sql/v1/context.cpp b/ydb/library/yql/sql/v1/context.cpp
index 2941670150..c08fe96cae 100644
--- a/ydb/library/yql/sql/v1/context.cpp
+++ b/ydb/library/yql/sql/v1/context.cpp
@@ -5,7 +5,7 @@
#include <ydb/library/yql/utils/yql_paths.h>
#include <util/folder/pathsplit.h>
-#include <util/string/join.h>
+#include <util/string/join.h>
#include <util/stream/null.h>
#ifdef GetMessage
@@ -72,7 +72,7 @@ TContext::TContext(const NSQLTranslation::TTranslationSettings& settings,
, ClusterPathPrefixes(settings.ClusterPathPrefixes)
, Settings(settings)
, Pool(new TMemoryPool(4096))
- , Issues(issues)
+ , Issues(issues)
, IncrementMonCounterFunction(settings.IncrementCounter)
, HasPendingErrors(false)
, DqEngineEnable(Settings.DqDefaultAuto->Allow())
@@ -124,14 +124,14 @@ const NYql::TPosition& TContext::Pos() const {
}
TString TContext::MakeName(const TString& name) {
- auto iter = GenIndexes.find(name);
- if (iter == GenIndexes.end()) {
- iter = GenIndexes.emplace(name, 0).first;
- }
- TStringBuilder str;
- str << name << iter->second;
- ++iter->second;
- return str;
+ auto iter = GenIndexes.find(name);
+ if (iter == GenIndexes.end()) {
+ iter = GenIndexes.emplace(name, 0).first;
+ }
+ TStringBuilder str;
+ str << name << iter->second;
+ ++iter->second;
+ return str;
}
IOutputStream& TContext::Error(NYql::TIssueCode code) {
@@ -143,14 +143,14 @@ IOutputStream& TContext::Error(NYql::TPosition pos, NYql::TIssueCode code) {
return MakeIssue(TSeverityIds::S_ERROR, code, pos);
}
-IOutputStream& TContext::Warning(NYql::TPosition pos, NYql::TIssueCode code) {
- return MakeIssue(TSeverityIds::S_WARNING, code, pos);
-}
-
-IOutputStream& TContext::Info(NYql::TPosition pos) {
- return MakeIssue(TSeverityIds::S_INFO, TIssuesIds::INFO, pos);
-}
-
+IOutputStream& TContext::Warning(NYql::TPosition pos, NYql::TIssueCode code) {
+ return MakeIssue(TSeverityIds::S_WARNING, code, pos);
+}
+
+IOutputStream& TContext::Info(NYql::TPosition pos) {
+ return MakeIssue(TSeverityIds::S_INFO, TIssuesIds::INFO, pos);
+}
+
void TContext::SetWarningPolicyFor(NYql::TIssueCode code, NYql::EWarningAction action) {
TString codePattern = ToString(code);
TString actionString = ToString(action);
@@ -162,7 +162,7 @@ void TContext::SetWarningPolicyFor(NYql::TIssueCode code, NYql::EWarningAction a
WarningPolicy.AddRule(rule);
}
-IOutputStream& TContext::MakeIssue(ESeverity severity, TIssueCode code, NYql::TPosition pos) {
+IOutputStream& TContext::MakeIssue(ESeverity severity, TIssueCode code, NYql::TPosition pos) {
if (severity == TSeverityIds::S_WARNING) {
auto action = WarningPolicy.GetAction(code);
if (action == EWarningAction::ERROR) {
@@ -191,13 +191,13 @@ IOutputStream& TContext::MakeIssue(ESeverity severity, TIssueCode code, NYql::TP
}
Issues.AddIssue(TIssue(pos, TString()));
- auto& curIssue = Issues.back();
- curIssue.Severity = severity;
- curIssue.IssueCode = code;
- IssueMsgHolder.Reset(new TStringOutput(Issues.back().Message));
- return *IssueMsgHolder;
-}
-
+ auto& curIssue = Issues.back();
+ curIssue.Severity = severity;
+ curIssue.IssueCode = code;
+ IssueMsgHolder.Reset(new TStringOutput(Issues.back().Message));
+ return *IssueMsgHolder;
+}
+
bool TContext::SetPathPrefix(const TString& value, TMaybe<TString> arg) {
if (arg.Defined()) {
if (*arg == YtProviderName
@@ -241,20 +241,20 @@ TNodePtr TContext::GetPrefixedPath(const TString& service, const TDeferredAtom&
}
TNodePtr TContext::UniversalAlias(const TString& baseName, TNodePtr&& node) {
- auto alias = MakeName(baseName);
- UniversalAliases.emplace(alias, node);
- return BuildAtom(node->GetPos(), alias, TNodeFlags::Default);
-}
-
+ auto alias = MakeName(baseName);
+ UniversalAliases.emplace(alias, node);
+ return BuildAtom(node->GetPos(), alias, TNodeFlags::Default);
+}
+
void TContext::DeclareVariable(const TString& varName, const TNodePtr& typeNode) {
- Variables.emplace(varName, typeNode);
-}
-
+ Variables.emplace(varName, typeNode);
+}
+
bool TContext::AddExport(TPosition pos, const TString& name) {
if (IsAnonymousName(name)) {
Error(pos) << "Can not export anonymous name " << name;
return false;
- }
+ }
if (Exports.contains(name)) {
Error(pos) << "Duplicate export symbol: " << name;
return false;
@@ -264,20 +264,20 @@ bool TContext::AddExport(TPosition pos, const TString& name) {
return false;
}
Exports.emplace(name);
- return true;
-}
-
+ return true;
+}
+
TString TContext::AddImport(const TVector<TString>& modulePath) {
- YQL_ENSURE(!modulePath.empty());
- const TString path = JoinRange("/", modulePath.cbegin(), modulePath.cend());
- auto iter = ImportModuleAliases.find(path);
- if (iter == ImportModuleAliases.end()) {
- const TString alias = MakeName(TStringBuilder() << modulePath.back() << "_module");
- iter = ImportModuleAliases.emplace(path, alias).first;
- }
- return iter->second;
-}
-
+ YQL_ENSURE(!modulePath.empty());
+ const TString path = JoinRange("/", modulePath.cbegin(), modulePath.cend());
+ auto iter = ImportModuleAliases.find(path);
+ if (iter == ImportModuleAliases.end()) {
+ const TString alias = MakeName(TStringBuilder() << modulePath.back() << "_module");
+ iter = ImportModuleAliases.emplace(path, alias).first;
+ }
+ return iter->second;
+}
+
TString TContext::AddSimpleUdf(const TString& udf) {
auto& name = SimpleUdfs[udf];
if (name.empty()) {
@@ -544,14 +544,14 @@ void TTranslation::WarnUnusedNodes() const {
}
TString GetDescription(const google::protobuf::Message& node, const google::protobuf::FieldDescriptor* d) {
- const auto& field = node.GetReflection()->GetMessage(node, d);
- return field.GetReflection()->GetString(field, d->message_type()->FindFieldByName("Descr"));
-}
-
+ const auto& field = node.GetReflection()->GetMessage(node, d);
+ return field.GetReflection()->GetString(field, d->message_type()->FindFieldByName("Descr"));
+}
+
TString TTranslation::AltDescription(const google::protobuf::Message& node, ui32 altCase, const google::protobuf::Descriptor* descr) const {
- return GetDescription(node, descr->FindFieldByNumber(altCase));
-}
-
+ return GetDescription(node, descr->FindFieldByNumber(altCase));
+}
+
void TTranslation::AltNotImplemented(const TString& ruleName, ui32 altCase, const google::protobuf::Message& node, const google::protobuf::Descriptor* descr) {
Error() << ruleName << ": alternative is not implemented yet: " << AltDescription(node, altCase, descr);
}
diff --git a/ydb/library/yql/sql/v1/context.h b/ydb/library/yql/sql/v1/context.h
index 9bbfc39725..8951757486 100644
--- a/ydb/library/yql/sql/v1/context.h
+++ b/ydb/library/yql/sql/v1/context.h
@@ -90,8 +90,8 @@ namespace NSQLTranslationV1 {
IOutputStream& Error(NYql::TIssueCode code = NYql::TIssuesIds::DEFAULT_ERROR);
IOutputStream& Error(NYql::TPosition pos, NYql::TIssueCode code = NYql::TIssuesIds::DEFAULT_ERROR);
- IOutputStream& Warning(NYql::TPosition pos, NYql::TIssueCode code);
- IOutputStream& Info(NYql::TPosition pos);
+ IOutputStream& Warning(NYql::TPosition pos, NYql::TIssueCode code);
+ IOutputStream& Info(NYql::TPosition pos);
void SetWarningPolicyFor(NYql::TIssueCode code, NYql::EWarningAction action);
@@ -147,17 +147,17 @@ namespace NSQLTranslationV1 {
TNodePtr GetPrefixedPath(const TString& service, const TDeferredAtom& cluster, const TDeferredAtom& path);
TNodePtr UniversalAlias(const TString& baseName, TNodePtr&& node);
-
- void BodyPart() {
- IntoHeading = false;
- }
-
- bool IsParseHeading() const {
- return IntoHeading;
- }
-
+
+ void BodyPart() {
+ IntoHeading = false;
+ }
+
+ bool IsParseHeading() const {
+ return IntoHeading;
+ }
+
void DeclareVariable(const TString& varName, const TNodePtr& typeNode);
-
+
bool AddExport(TPosition symbolPos, const TString& symbolName);
TString AddImport(const TVector<TString>& modulePath);
TString AddSimpleUdf(const TString& udf);
@@ -183,16 +183,16 @@ namespace NSQLTranslationV1 {
}
private:
- IOutputStream& MakeIssue(NYql::ESeverity severity, NYql::TIssueCode code, NYql::TPosition pos);
+ IOutputStream& MakeIssue(NYql::ESeverity severity, NYql::TIssueCode code, NYql::TPosition pos);
private:
NYql::TPosition Position;
- THolder<TStringOutput> IssueMsgHolder;
+ THolder<TStringOutput> IssueMsgHolder;
NSQLTranslation::TClusterMapping ClusterMapping;
TString PathPrefix;
THashMap<TString, TString> ProviderPathPrefixes;
THashMap<TString, TString> ClusterPathPrefixes;
- bool IntoHeading = true;
+ bool IntoHeading = true;
friend class TColumnRefScope;
@@ -218,11 +218,11 @@ namespace NSQLTranslationV1 {
THashMap<TString, ui32> GenIndexes;
using TWinSpecsRef = std::reference_wrapper<TWinSpecs>;
TDeque<TWinSpecsRef> WinSpecsScopes;
- bool PragmaRefSelect = false;
- bool PragmaSampleSelect = false;
- bool PragmaAllowDotInAlias = false;
+ bool PragmaRefSelect = false;
+ bool PragmaSampleSelect = false;
+ bool PragmaAllowDotInAlias = false;
bool PragmaInferSchema = false;
- bool PragmaAutoCommit = false;
+ bool PragmaAutoCommit = false;
bool SimpleColumns = true;
bool CoalesceJoinKeysOnQualifiedAll = false;
bool PragmaDirectRead = false;
@@ -250,8 +250,8 @@ namespace NSQLTranslationV1 {
bool WarnOnAnsiAliasShadowing = true;
ui32 ResultRowsLimit = 0;
ui64 ResultSizeLimit = 0;
- ui32 PragmaGroupByLimit = 1 << 5;
- ui32 PragmaGroupByCubeLimit = 5;
+ ui32 PragmaGroupByLimit = 1 << 5;
+ ui32 PragmaGroupByCubeLimit = 5;
// if FlexibleTypes=true, emit TypeOrMember callable and resolve Type/Column uncertainty on type annotation stage, otherwise always emit Type
bool FlexibleTypes = false;
THashMap<TString, TMaybe<TString>> Libraries; // alias -> optional file
@@ -311,11 +311,11 @@ namespace NSQLTranslationV1 {
template <typename TToken>
TString Identifier(const TToken& token) {
- return IdContent(Ctx, Token(token));
+ return IdContent(Ctx, Token(token));
}
TString Identifier(const TString& str) const {
- return IdContent(Ctx, str);
+ return IdContent(Ctx, str);
}
TNodePtr GetNamedNode(const TString& name);
@@ -334,7 +334,7 @@ namespace NSQLTranslationV1 {
template <typename TNode>
TString AltDescription(const TNode& node) const {
- return AltDescription(node, node.Alt_case(), TNode::descriptor());
+ return AltDescription(node, node.Alt_case(), TNode::descriptor());
}
protected:
diff --git a/ydb/library/yql/sql/v1/insert.cpp b/ydb/library/yql/sql/v1/insert.cpp
index d679260233..4f4c863018 100644
--- a/ydb/library/yql/sql/v1/insert.cpp
+++ b/ydb/library/yql/sql/v1/insert.cpp
@@ -12,22 +12,22 @@ static const TMap<ESQLWriteColumnMode, EWriteColumnMode> sqlIntoMode2WriteColumn
{ESQLWriteColumnMode::InsertOrAbortInto, EWriteColumnMode::InsertOrAbort},
{ESQLWriteColumnMode::InsertOrIgnoreInto, EWriteColumnMode::InsertOrIgnore},
{ESQLWriteColumnMode::InsertOrRevertInto, EWriteColumnMode::InsertOrRevert},
- {ESQLWriteColumnMode::UpsertInto, EWriteColumnMode::Upsert},
- {ESQLWriteColumnMode::ReplaceInto, EWriteColumnMode::Replace},
- {ESQLWriteColumnMode::InsertIntoWithTruncate, EWriteColumnMode::Renew},
- {ESQLWriteColumnMode::Update, EWriteColumnMode::Update},
- {ESQLWriteColumnMode::Delete, EWriteColumnMode::Delete},
-};
-
-class TModifySourceBase: public ISource {
+ {ESQLWriteColumnMode::UpsertInto, EWriteColumnMode::Upsert},
+ {ESQLWriteColumnMode::ReplaceInto, EWriteColumnMode::Replace},
+ {ESQLWriteColumnMode::InsertIntoWithTruncate, EWriteColumnMode::Renew},
+ {ESQLWriteColumnMode::Update, EWriteColumnMode::Update},
+ {ESQLWriteColumnMode::Delete, EWriteColumnMode::Delete},
+};
+
+class TModifySourceBase: public ISource {
public:
TModifySourceBase(TPosition pos, const TVector<TString>& columnsHint)
: ISource(pos)
- , ColumnsHint(columnsHint)
+ , ColumnsHint(columnsHint)
{
}
- bool AddFilter(TContext& ctx, TNodePtr filter) override {
+ bool AddFilter(TContext& ctx, TNodePtr filter) override {
Y_UNUSED(filter);
ctx.Error(Pos) << "Source does not allow filtering";
return false;
@@ -39,7 +39,7 @@ public:
return false;
}
- bool AddAggregation(TContext& ctx, TAggregationPtr aggr) override {
+ bool AddAggregation(TContext& ctx, TAggregationPtr aggr) override {
YQL_ENSURE(aggr);
ctx.Error(aggr->GetPos()) << "Source does not allow aggregation";
return false;
@@ -56,33 +56,33 @@ public:
return nullptr;
}
-protected:
+protected:
TVector<TString> ColumnsHint;
TString OperationHumanName;
-};
-
-class TUpdateByValues: public TModifySourceBase {
-public:
+};
+
+class TUpdateByValues: public TModifySourceBase {
+public:
TUpdateByValues(TPosition pos, const TString& operationHumanName, const TVector<TString>& columnsHint, const TVector<TNodePtr>& values)
- : TModifySourceBase(pos, columnsHint)
+ : TModifySourceBase(pos, columnsHint)
, OperationHumanName(operationHumanName)
- , Values(values)
- {}
-
- bool DoInit(TContext& ctx, ISource* src) override {
- if (ColumnsHint.size() != Values.size()) {
+ , Values(values)
+ {}
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ if (ColumnsHint.size() != Values.size()) {
ctx.Error(Pos) << "VALUES have " << Values.size() << " columns, " << OperationHumanName << " expects: " << ColumnsHint.size();
- return false;
- }
- for (auto& value: Values) {
- if (!value->Init(ctx, src)) {
+ return false;
+ }
+ for (auto& value: Values) {
+ if (!value->Init(ctx, src)) {
return false;
}
- }
- return true;
- }
-
- TNodePtr Build(TContext& ctx) override {
+ }
+ return true;
+ }
+
+ TNodePtr Build(TContext& ctx) override {
Y_UNUSED(ctx);
YQL_ENSURE(Values.size() == ColumnsHint.size());
@@ -92,33 +92,33 @@ public:
TNodePtr value = Values[i];
structObj = L(structObj, Q(Y(Q(column), value)));
- }
+ }
auto updateRow = BuildLambda(Pos, Y("row"), structObj);
return updateRow;
- }
-
- TNodePtr DoClone() const final {
- return new TUpdateByValues(Pos, OperationHumanName, ColumnsHint, CloneContainer(Values));
- }
-private:
+ }
+
+ TNodePtr DoClone() const final {
+ return new TUpdateByValues(Pos, OperationHumanName, ColumnsHint, CloneContainer(Values));
+ }
+private:
TString OperationHumanName;
-
-protected:
+
+protected:
TVector<TNodePtr> Values;
-};
-
-class TModifyByValues: public TModifySourceBase {
-public:
+};
+
+class TModifyByValues: public TModifySourceBase {
+public:
TModifyByValues(TPosition pos, const TString& operationHumanName, const TVector<TString>& columnsHint, const TVector<TVector<TNodePtr>>& values)
- : TModifySourceBase(pos, columnsHint)
+ : TModifySourceBase(pos, columnsHint)
, OperationHumanName(operationHumanName)
- , Values(values)
+ , Values(values)
{
FakeSource = BuildFakeSource(pos);
}
-
- bool DoInit(TContext& ctx, ISource* src) override {
+
+ bool DoInit(TContext& ctx, ISource* src) override {
Y_UNUSED(src);
bool hasError = false;
for (const auto& row: Values) {
@@ -142,7 +142,7 @@ public:
return !hasError;
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
Y_UNUSED(ctx);
auto tuple = Y();
for (const auto& row: Values) {
@@ -156,46 +156,46 @@ public:
}
return Y("PersistableRepr", Q(tuple));
}
-
- TNodePtr DoClone() const final {
+
+ TNodePtr DoClone() const final {
TVector<TVector<TNodePtr>> clonedValues;
- clonedValues.reserve(Values.size());
- for (auto cur: Values) {
- clonedValues.push_back(CloneContainer(cur));
- }
- return new TModifyByValues(Pos, OperationHumanName, ColumnsHint, clonedValues);
- }
-
+ clonedValues.reserve(Values.size());
+ for (auto cur: Values) {
+ clonedValues.push_back(CloneContainer(cur));
+ }
+ return new TModifyByValues(Pos, OperationHumanName, ColumnsHint, clonedValues);
+ }
+
private:
TString OperationHumanName;
TVector<TVector<TNodePtr>> Values;
TSourcePtr FakeSource;
};
-class TModifyBySource: public TModifySourceBase {
-public:
+class TModifyBySource: public TModifySourceBase {
+public:
TModifyBySource(TPosition pos, const TString& operationHumanName, const TVector<TString>& columnsHint, TSourcePtr source)
- : TModifySourceBase(pos, columnsHint)
+ : TModifySourceBase(pos, columnsHint)
, OperationHumanName(operationHumanName)
- , Source(std::move(source))
- {}
-
+ , Source(std::move(source))
+ {}
+
void GetInputTables(TTableList& tableList) const override {
- if (Source) {
+ if (Source) {
return Source->GetInputTables(tableList);
- }
- }
-
- bool DoInit(TContext& ctx, ISource* src) override {
- if (!Source->Init(ctx, src)) {
- return false;
- }
- const auto& sourceColumns = Source->GetColumns();
- const auto numColumns = !ColumnsHint.empty() && sourceColumns ? sourceColumns->List.size() : 0;
- if (ColumnsHint.size() != numColumns) {
+ }
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ if (!Source->Init(ctx, src)) {
+ return false;
+ }
+ const auto& sourceColumns = Source->GetColumns();
+ const auto numColumns = !ColumnsHint.empty() && sourceColumns ? sourceColumns->List.size() : 0;
+ if (ColumnsHint.size() != numColumns) {
ctx.Error(Pos) << "SELECT have " << numColumns << " columns, " << OperationHumanName << " expects: " << ColumnsHint.size();
- return false;
- }
+ return false;
+ }
if (numColumns) {
TStringStream str;
bool mismatchFound = false;
@@ -217,75 +217,75 @@ public:
ctx.Warning(Pos, TIssuesIds::YQL_SOURCE_SELECT_COLUMN_MISMATCH) << str.Str();
}
}
- return true;
- }
-
- TNodePtr Build(TContext& ctx) override {
- auto input = Source->Build(ctx);
- if (ColumnsHint.empty() || !Source->GetColumns()) {
- return input;
- }
- auto srcColumn = Source->GetColumns()->List.begin();
+ return true;
+ }
+
+ TNodePtr Build(TContext& ctx) override {
+ auto input = Source->Build(ctx);
+ if (ColumnsHint.empty() || !Source->GetColumns()) {
+ return input;
+ }
+ auto srcColumn = Source->GetColumns()->List.begin();
auto structObj = Y("AsStruct"); // ordered struct
- for (auto column: ColumnsHint) {
+ for (auto column: ColumnsHint) {
structObj = L(structObj, Q(Y(BuildQuotedAtom(Pos, column),
- Y("Member", "row", BuildQuotedAtom(Pos, *srcColumn))
- )));
- ++srcColumn;
- }
+ Y("Member", "row", BuildQuotedAtom(Pos, *srcColumn))
+ )));
+ ++srcColumn;
+ }
return Y("OrderedMap", input, BuildLambda(Pos, Y("row"), structObj));
- }
-
- TNodePtr DoClone() const final {
- return new TModifyBySource(Pos, OperationHumanName, ColumnsHint, Source->CloneSource());
- }
-
+ }
+
+ TNodePtr DoClone() const final {
+ return new TModifyBySource(Pos, OperationHumanName, ColumnsHint, Source->CloneSource());
+ }
+
EOrderKind GetOrderKind() const final {
return Source->GetOrderKind();
}
-private:
+private:
TString OperationHumanName;
- TSourcePtr Source;
-};
-
+ TSourcePtr Source;
+};
+
TSourcePtr BuildWriteValues(TPosition pos, const TString& operationHumanName, const TVector<TString>& columnsHint, const TVector<TVector<TNodePtr>>& values) {
return new TModifyByValues(pos, operationHumanName, columnsHint, values);
}
TSourcePtr BuildWriteValues(TPosition pos, const TString& operationHumanName, const TVector<TString>& columnsHint, TSourcePtr source) {
- return new TModifyBySource(pos, operationHumanName, columnsHint, std::move(source));
+ return new TModifyBySource(pos, operationHumanName, columnsHint, std::move(source));
}
TSourcePtr BuildUpdateValues(TPosition pos, const TVector<TString>& columnsHint, const TVector<TNodePtr>& values) {
- return new TUpdateByValues(pos, "UPDATE", columnsHint, values);
-}
-
-class TWriteColumnsNode: public TAstListNode {
+ return new TUpdateByValues(pos, "UPDATE", columnsHint, values);
+}
+
+class TWriteColumnsNode: public TAstListNode {
public:
TWriteColumnsNode(TPosition pos, TScopedStatePtr scoped,
const TTableRef& table, EWriteColumnMode mode, TSourcePtr values = nullptr, TNodePtr options = nullptr)
: TAstListNode(pos)
, Scoped(scoped)
, Table(table)
- , Mode(mode)
- , Values(std::move(values))
+ , Mode(mode)
+ , Values(std::move(values))
, Options(std::move(options))
{
FakeSource = BuildFakeSource(pos);
}
- void ResetSource(TSourcePtr source) {
- TableSource = std::move(source);
- }
-
- void ResetUpdate(TSourcePtr update) {
- Update = std::move(update);
+ void ResetSource(TSourcePtr source) {
+ TableSource = std::move(source);
+ }
+
+ void ResetUpdate(TSourcePtr update) {
+ Update = std::move(update);
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
TTableList tableList;
- TNodePtr values;
+ TNodePtr values;
auto options = Y();
if (Options) {
if (!Options->Init(ctx, src)) {
@@ -296,25 +296,25 @@ public:
ISource* underlyingSrc = src;
- if (TableSource) {
- if (!TableSource->Init(ctx, src) || !TableSource->InitFilters(ctx)) {
+ if (TableSource) {
+ if (!TableSource->Init(ctx, src) || !TableSource->InitFilters(ctx)) {
return false;
}
options = L(options, Q(Y(Q("filter"), TableSource->BuildFilterLambda())));
}
bool unordered = false;
- if (Values) {
- if (!Values->Init(ctx, TableSource.Get())) {
- return false;
- }
+ if (Values) {
+ if (!Values->Init(ctx, TableSource.Get())) {
+ return false;
+ }
Values->GetInputTables(tableList);
underlyingSrc = Values.Get();
- values = Values->Build(ctx);
- if (!values) {
- return false;
- }
+ values = Values->Build(ctx);
+ if (!values) {
+ return false;
+ }
unordered = (EOrderKind::None == Values->GetOrderKind());
}
@@ -324,24 +324,24 @@ public:
}
if (Update) {
- if (!Update->Init(ctx, TableSource.Get()) || !Update->InitFilters(ctx)) {
- return false;
- }
+ if (!Update->Init(ctx, TableSource.Get()) || !Update->InitFilters(ctx)) {
+ return false;
+ }
options = L(options, Q(Y(Q("update"), Update->Build(ctx))));
}
-
+
auto write = BuildWriteTable(Pos, "values", Table, Mode, std::move(options), Scoped);
if (!write->Init(ctx, FakeSource.Get())) {
return false;
}
- if (values) {
- node = L(node, Y("let", "values", values));
+ if (values) {
+ node = L(node, Y("let", "values", values));
if (unordered && ctx.UseUnordered(Table)) {
node = L(node, Y("let", "values", Y("Unordered", "values")));
}
} else {
node = L(node, Y("let", "values", Y("Void")));
- }
+ }
node = L(node, Y("let", "world", write));
node = L(node, Y("return", "world"));
@@ -349,44 +349,44 @@ public:
return true;
}
- TNodePtr DoClone() const final {
- return {};
- }
-
+ TNodePtr DoClone() const final {
+ return {};
+ }
+
protected:
TScopedStatePtr Scoped;
TTableRef Table;
- TSourcePtr TableSource;
- EWriteColumnMode Mode;
- TSourcePtr Values;
+ TSourcePtr TableSource;
+ EWriteColumnMode Mode;
+ TSourcePtr Values;
TSourcePtr Update;
TSourcePtr FakeSource;
TNodePtr Options;
};
-EWriteColumnMode ToWriteColumnsMode(ESQLWriteColumnMode sqlWriteColumnMode) {
- return sqlIntoMode2WriteColumn.at(sqlWriteColumnMode);
+EWriteColumnMode ToWriteColumnsMode(ESQLWriteColumnMode sqlWriteColumnMode) {
+ return sqlIntoMode2WriteColumn.at(sqlWriteColumnMode);
}
TNodePtr BuildWriteColumns(TPosition pos, TScopedStatePtr scoped, const TTableRef& table, EWriteColumnMode mode, TSourcePtr values, TNodePtr options) {
- YQL_ENSURE(values, "Invalid values node");
+ YQL_ENSURE(values, "Invalid values node");
return new TWriteColumnsNode(pos, scoped, table, mode, std::move(values), std::move(options));
-}
-
+}
+
TNodePtr BuildUpdateColumns(TPosition pos, TScopedStatePtr scoped, const TTableRef& table, TSourcePtr values, TSourcePtr source) {
- YQL_ENSURE(values, "Invalid values node");
+ YQL_ENSURE(values, "Invalid values node");
TIntrusivePtr<TWriteColumnsNode> writeNode = new TWriteColumnsNode(pos, scoped, table, EWriteColumnMode::Update);
- writeNode->ResetSource(std::move(source));
- writeNode->ResetUpdate(std::move(values));
- return writeNode;
-}
-
+ writeNode->ResetSource(std::move(source));
+ writeNode->ResetUpdate(std::move(values));
+ return writeNode;
+}
+
TNodePtr BuildDelete(TPosition pos, TScopedStatePtr scoped, const TTableRef& table, TSourcePtr source) {
TIntrusivePtr<TWriteColumnsNode> writeNode = new TWriteColumnsNode(pos, scoped, table, EWriteColumnMode::Delete);
- writeNode->ResetSource(std::move(source));
- return writeNode;
-}
-
+ writeNode->ResetSource(std::move(source));
+ return writeNode;
+}
+
class TEraseColumnsNode: public TAstListNode {
public:
diff --git a/ydb/library/yql/sql/v1/join.cpp b/ydb/library/yql/sql/v1/join.cpp
index 5a18115ca0..29f5b3ec4b 100644
--- a/ydb/library/yql/sql/v1/join.cpp
+++ b/ydb/library/yql/sql/v1/join.cpp
@@ -23,27 +23,27 @@ TString NormalizeJoinOp(const TString& joinOp) {
return JoinSeq("", joinOpsParts);
}
-struct TJoinDescr {
+struct TJoinDescr {
TString Op;
TJoinLinkSettings LinkSettings;
-
- struct TFullColumn {
- ui32 Source;
- TNodePtr Column;
- };
-
+
+ struct TFullColumn {
+ ui32 Source;
+ TNodePtr Column;
+ };
+
TVector<std::pair<TFullColumn, TFullColumn>> Keys;
-
+
explicit TJoinDescr(const TString& op)
- : Op(op)
- {}
-};
-
+ : Op(op)
+ {}
+};
+
class TJoinBase: public IJoin {
public:
TJoinBase(TPosition pos, TVector<TSourcePtr>&& sources, TVector<bool>&& anyFlags)
: IJoin(pos)
- , Sources(std::move(sources))
+ , Sources(std::move(sources))
, AnyFlags(std::move(anyFlags))
{
YQL_ENSURE(Sources.size() == AnyFlags.size());
@@ -55,86 +55,86 @@ public:
}
}
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
- ISource* srcByName = nullptr;
- if (column.IsArtificial()) {
- return true;
- }
- if (const auto sourceName = *column.GetSourceName()) {
- for (auto& source: Sources) {
- if (sourceName == source->GetLabel()) {
- srcByName = source.Get();
- break;
- }
- }
- if (!srcByName) {
- if (column.IsAsterisk()) {
- ctx.Error(column.GetPos()) << "Unknown correlation name for asterisk: " << sourceName;
- return {};
- }
- // \todo add warning, either mistake in correlation name, either it's a column
- column.ResetColumn("", sourceName);
- column.SetUseSourceAsColumn();
- column.SetAsNotReliable();
- }
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ ISource* srcByName = nullptr;
+ if (column.IsArtificial()) {
+ return true;
+ }
+ if (const auto sourceName = *column.GetSourceName()) {
+ for (auto& source: Sources) {
+ if (sourceName == source->GetLabel()) {
+ srcByName = source.Get();
+ break;
+ }
+ }
+ if (!srcByName) {
+ if (column.IsAsterisk()) {
+ ctx.Error(column.GetPos()) << "Unknown correlation name for asterisk: " << sourceName;
+ return {};
+ }
+ // \todo add warning, either mistake in correlation name, either it's a column
+ column.ResetColumn("", sourceName);
+ column.SetUseSourceAsColumn();
+ column.SetAsNotReliable();
+ }
}
if (column.IsAsterisk()) {
if (!column.GetCountHint()) {
- if (srcByName) {
- srcByName->AllColumns();
+ if (srcByName) {
+ srcByName->AllColumns();
} else {
for (auto& source: Sources) {
source->AllColumns();
}
}
}
- return true;
- }
- if (srcByName) {
- column.ResetAsReliable();
- if (!srcByName->AddColumn(ctx, column)) {
- return {};
- }
- if (!KeysInitializing && !column.IsAsterisk()) {
- column.SetUseSource();
- }
- return true;
- } else {
- unsigned acceptedColumns = 0;
- TIntrusivePtr<TColumnNode> tryColumn = static_cast<TColumnNode*>(column.Clone().Get());
- tryColumn->SetAsNotReliable();
+ return true;
+ }
+ if (srcByName) {
+ column.ResetAsReliable();
+ if (!srcByName->AddColumn(ctx, column)) {
+ return {};
+ }
+ if (!KeysInitializing && !column.IsAsterisk()) {
+ column.SetUseSource();
+ }
+ return true;
+ } else {
+ unsigned acceptedColumns = 0;
+ TIntrusivePtr<TColumnNode> tryColumn = static_cast<TColumnNode*>(column.Clone().Get());
+ tryColumn->SetAsNotReliable();
TString lastAcceptedColumnSource;
- for (auto& source: Sources) {
- if (source->AddColumn(ctx, *tryColumn)) {
- ++acceptedColumns;
- lastAcceptedColumnSource = source->GetLabel();
- }
- }
- if (!acceptedColumns) {
- TStringBuilder sb;
- const auto& fullColumnName = FullColumnName(column);
- sb << "Column " << fullColumnName << " is not fit to any source";
- for (auto& source: Sources) {
- if (const auto mistype = source->FindColumnMistype(fullColumnName)) {
- sb << ". Did you mean " << mistype.GetRef() << "?";
- break;
- }
- }
- ctx.Error(column.GetPos()) << sb;
- return {};
- } else {
- column.SetAsNotReliable();
- }
+ for (auto& source: Sources) {
+ if (source->AddColumn(ctx, *tryColumn)) {
+ ++acceptedColumns;
+ lastAcceptedColumnSource = source->GetLabel();
+ }
+ }
+ if (!acceptedColumns) {
+ TStringBuilder sb;
+ const auto& fullColumnName = FullColumnName(column);
+ sb << "Column " << fullColumnName << " is not fit to any source";
+ for (auto& source: Sources) {
+ if (const auto mistype = source->FindColumnMistype(fullColumnName)) {
+ sb << ". Did you mean " << mistype.GetRef() << "?";
+ break;
+ }
+ }
+ ctx.Error(column.GetPos()) << sb;
+ return {};
+ } else {
+ column.SetAsNotReliable();
+ }
return false;
}
}
- const TColumns* GetColumns() const override {
- YQL_ENSURE(IsColumnDone, "Unable to GetColumns while it's not finished");
- return &JoinedColumns;
- }
-
+ const TColumns* GetColumns() const override {
+ YQL_ENSURE(IsColumnDone, "Unable to GetColumns while it's not finished");
+ return &JoinedColumns;
+ }
+
void GetInputTables(TTableList& tableList) const override {
for (auto& src: Sources) {
src->GetInputTables(tableList);
@@ -147,17 +147,17 @@ public:
TString what(Sources[n]->GetLabel());
static const TSet<TString> noRightSourceJoinOps = {"LeftOnly", "LeftSemi"};
for (size_t nn = n; nn > 0 && noRightSourceJoinOps.contains(JoinOps[nn-1]); --nn) {
- what = Sources[nn-1]->GetLabel();
- }
+ what = Sources[nn-1]->GetLabel();
+ }
const TString with(Sources[n + 1]->GetLabel());
- for (auto index = n; index <= n + 1; ++index) {
- const auto& label = Sources[index]->GetLabel();
- if (label.Contains('.')) {
- ctx.Error(Sources[index]->GetPos()) << "Invalid label: " << label << ", unable to use name with dot symbol, you should use AS <simple alias name>";
- return nullptr;
- }
- }
+ for (auto index = n; index <= n + 1; ++index) {
+ const auto& label = Sources[index]->GetLabel();
+ if (label.Contains('.')) {
+ ctx.Error(Sources[index]->GetPos()) << "Invalid label: " << label << ", unable to use name with dot symbol, you should use AS <simple alias name>";
+ return nullptr;
+ }
+ }
if (what.empty() && with.empty()) {
ctx.Error() << "At least one correlation name is required in join";
return nullptr;
@@ -188,7 +188,7 @@ public:
return expr;
}
- bool DoInit(TContext& ctx, ISource* src) override;
+ bool DoInit(TContext& ctx, ISource* src) override;
void SetupJoin(const TString& opName, TNodePtr expr, const TJoinLinkSettings& linkSettings) override {
JoinOps.push_back(opName);
@@ -202,9 +202,9 @@ public:
protected:
static TString FullColumnName(const TColumnNode& column) {
- auto sourceName = *column.GetSourceName();
- auto columnName = *column.GetColumnName();
- return sourceName ? DotJoin(sourceName, columnName) : columnName;
+ auto sourceName = *column.GetSourceName();
+ auto columnName = *column.GetColumnName();
+ return sourceName ? DotJoin(sourceName, columnName) : columnName;
}
bool InitKeysOrFilters(TContext& ctx, ui32 joinIdx, TNodePtr expr) {
@@ -219,8 +219,8 @@ protected:
}
op = dynamic_cast<const TCallNode*>(expr.Get());
- YQL_ENSURE(op, "Invalid JOIN equal operation node");
- YQL_ENSURE(op->GetArgs().size() == 2, "Invalid JOIN equal operation arguments");
+ YQL_ENSURE(op, "Invalid JOIN equal operation node");
+ YQL_ENSURE(op->GetArgs().size() == 2, "Invalid JOIN equal operation arguments");
}
ui32 idx = 0;
@@ -246,54 +246,54 @@ protected:
ui32 rightSourceIdx = 0;
const TString* leftSource = nullptr;
const TString* rightSource = nullptr;
- const TString* sameColumnNamePtr = nullptr;
+ const TString* sameColumnNamePtr = nullptr;
TSet<TString> joinedSources;
if (op) {
- const TString* columnNamePtr = nullptr;
+ const TString* columnNamePtr = nullptr;
for (auto& arg : op->GetArgs()) {
- const auto sourceNamePtr = arg->GetSourceName();
- if (!sourceNamePtr) {
+ const auto sourceNamePtr = arg->GetSourceName();
+ if (!sourceNamePtr) {
ctx.Error(expr->GetPos()) << "JOIN: each equality predicate argument must depend on exactly one JOIN input";
return false;
}
- const auto sourceName = *sourceNamePtr;
- if (sourceName.empty()) {
+ const auto sourceName = *sourceNamePtr;
+ if (sourceName.empty()) {
ctx.Error(expr->GetPos()) << "JOIN: column requires correlation name";
return false;
}
- auto it = sources.find(sourceName);
+ auto it = sources.find(sourceName);
if (it != sources.end()) {
- joinedSources.insert(sourceName);
+ joinedSources.insert(sourceName);
if (it->second == joinIdx + 1) {
rightArg = pos;
- rightSource = sourceNamePtr;
+ rightSource = sourceNamePtr;
rightSourceIdx = it->second;
}
else if (it->second > joinIdx + 1) {
- ctx.Error(expr->GetPos()) << "JOIN: can not use source: " << sourceName << " in equality predicate, it is out of current join scope";
+ ctx.Error(expr->GetPos()) << "JOIN: can not use source: " << sourceName << " in equality predicate, it is out of current join scope";
return false;
}
else {
leftArg = pos;
- leftSource = sourceNamePtr;
+ leftSource = sourceNamePtr;
leftSourceIdx = it->second;
}
}
else {
- ctx.Error(expr->GetPos()) << "JOIN: unknown corellation name: " << sourceName;
+ ctx.Error(expr->GetPos()) << "JOIN: unknown corellation name: " << sourceName;
return false;
}
- if (!columnNamePtr) {
- columnNamePtr = arg->GetColumnName();
- } else {
- auto curColumnNamePtr = arg->GetColumnName();
- if (curColumnNamePtr && *curColumnNamePtr == *columnNamePtr) {
- sameColumnNamePtr = columnNamePtr;
- }
- }
+ if (!columnNamePtr) {
+ columnNamePtr = arg->GetColumnName();
+ } else {
+ auto curColumnNamePtr = arg->GetColumnName();
+ if (curColumnNamePtr && *curColumnNamePtr == *columnNamePtr) {
+ sameColumnNamePtr = columnNamePtr;
+ }
+ }
++pos;
}
- } else {
+ } else {
for (auto& x : sources) {
if (x.second == joinIdx) {
leftArg = pos;
@@ -333,10 +333,10 @@ protected:
}
Y_VERIFY_DEBUG(leftSource);
- if (sameColumnNamePtr) {
- SameKeyMap[*sameColumnNamePtr].insert(*leftSource);
- SameKeyMap[*sameColumnNamePtr].insert(*rightSource);
- }
+ if (sameColumnNamePtr) {
+ SameKeyMap[*sameColumnNamePtr].insert(*leftSource);
+ SameKeyMap[*sameColumnNamePtr].insert(*rightSource);
+ }
}
if (joinIdx == JoinDescrs.size()) {
@@ -351,10 +351,10 @@ protected:
return true;
}
- bool IsJoinKeysInitializing() const override {
- return KeysInitializing;
- }
-
+ bool IsJoinKeysInitializing() const override {
+ return KeysInitializing;
+ }
+
protected:
TVector<TString> JoinOps;
TVector<TNodePtr> JoinExprs;
@@ -363,46 +363,46 @@ protected:
THashMap<TString, THashSet<TString>> SameKeyMap;
const TVector<TSourcePtr> Sources;
const TVector<bool> AnyFlags;
- TColumns JoinedColumns;
- bool KeysInitializing = false;
- bool IsColumnDone = false;
-
- void FinishColumns() override {
- if (IsColumnDone) {
- return;
- }
- YQL_ENSURE(JoinOps.size()+1 == Sources.size());
- bool excludeNextSource = false;
- decltype(JoinOps)::const_iterator opIter = JoinOps.begin();
- for (auto& src: Sources) {
- if (excludeNextSource) {
- excludeNextSource = false;
- if (opIter != JoinOps.end()) {
- ++opIter;
- }
- continue;
- }
- if (opIter != JoinOps.end()) {
- auto joinOper = *opIter;
- ++opIter;
- if (joinOper == "LeftSemi" || joinOper == "LeftOnly") {
- excludeNextSource = true;
- }
- if (joinOper == "RightSemi" || joinOper == "RightOnly") {
- continue;
- }
- }
- auto columnsPtr = src->GetColumns();
- if (!columnsPtr) {
- continue;
- }
- TColumns upColumns;
- upColumns.Merge(*columnsPtr);
- upColumns.SetPrefix(src->GetLabel());
- JoinedColumns.Merge(upColumns);
- }
- IsColumnDone = true;
- }
+ TColumns JoinedColumns;
+ bool KeysInitializing = false;
+ bool IsColumnDone = false;
+
+ void FinishColumns() override {
+ if (IsColumnDone) {
+ return;
+ }
+ YQL_ENSURE(JoinOps.size()+1 == Sources.size());
+ bool excludeNextSource = false;
+ decltype(JoinOps)::const_iterator opIter = JoinOps.begin();
+ for (auto& src: Sources) {
+ if (excludeNextSource) {
+ excludeNextSource = false;
+ if (opIter != JoinOps.end()) {
+ ++opIter;
+ }
+ continue;
+ }
+ if (opIter != JoinOps.end()) {
+ auto joinOper = *opIter;
+ ++opIter;
+ if (joinOper == "LeftSemi" || joinOper == "LeftOnly") {
+ excludeNextSource = true;
+ }
+ if (joinOper == "RightSemi" || joinOper == "RightOnly") {
+ continue;
+ }
+ }
+ auto columnsPtr = src->GetColumns();
+ if (!columnsPtr) {
+ continue;
+ }
+ TColumns upColumns;
+ upColumns.Merge(*columnsPtr);
+ upColumns.SetPrefix(src->GetLabel());
+ JoinedColumns.Merge(upColumns);
+ }
+ IsColumnDone = true;
+ }
};
bool TJoinBase::DoInit(TContext& ctx, ISource* initSrc) {
@@ -436,22 +436,22 @@ bool TJoinBase::DoInit(TContext& ctx, ISource* initSrc) {
for (auto expr: JoinExprs) {
if (expr) {
TDeque<TNodePtr> conjQueue;
- conjQueue.push_back(expr);
- while (!conjQueue.empty()) {
- TNodePtr cur = conjQueue.front();
- conjQueue.pop_front();
- if (cur->GetOpName() == "And") {
- auto conj = dynamic_cast<const TCallNode*>(cur.Get());
- YQL_ENSURE(conj, "Invalid And operation node");
- conjQueue.insert(conjQueue.begin(), conj->GetArgs().begin(), conj->GetArgs().end());
- } else if (!InitKeysOrFilters(ctx, idx, cur)) {
+ conjQueue.push_back(expr);
+ while (!conjQueue.empty()) {
+ TNodePtr cur = conjQueue.front();
+ conjQueue.pop_front();
+ if (cur->GetOpName() == "And") {
+ auto conj = dynamic_cast<const TCallNode*>(cur.Get());
+ YQL_ENSURE(conj, "Invalid And operation node");
+ conjQueue.insert(conjQueue.begin(), conj->GetArgs().begin(), conj->GetArgs().end());
+ } else if (!InitKeysOrFilters(ctx, idx, cur)) {
return false;
}
}
- } else {
- if (!InitKeysOrFilters(ctx, idx, nullptr)) {
- return false;
- }
+ } else {
+ if (!InitKeysOrFilters(ctx, idx, nullptr)) {
+ return false;
+ }
}
++idx;
}
@@ -481,7 +481,7 @@ public:
{
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
TMap<std::pair<TString, TString>, TNodePtr> extraColumns;
TNodePtr joinTree;
for (auto& descr: JoinDescrs) {
@@ -535,9 +535,9 @@ public:
source->BuildFlattenColumns("row");
if (!flatten) {
- return nullptr;
- }
- auto block = Y(Y("let", "flatten", sourceNode));
+ return nullptr;
+ }
+ auto block = Y(Y("let", "flatten", sourceNode));
if (source->IsFlattenByExprs()) {
auto premap = source->BuildPreFlattenMap(ctx);
@@ -549,8 +549,8 @@ public:
}
block = L(block, Y("let", "flatten", Y(useOrderedForSource ? "OrderedFlatMap" : "FlatMap", "flatten", BuildLambda(Pos, Y("row"), flatten, "res"))));
- sourceNode = Y("block", Q(L(block, Y("return", "flatten"))));
- }
+ sourceNode = Y("block", Q(L(block, Y("return", "flatten"))));
+ }
TNodePtr extraMembers;
for (auto it = extraColumns.lower_bound({ source->GetLabel(), "" }); it != extraColumns.end(); ++it) {
if (it->first.first != source->GetLabel()) {
@@ -579,14 +579,14 @@ public:
}
removeMembers = L(
removeMembers,
- Y("let", "row", Y("ForceRemoveMember", "row", BuildQuotedAtom(Pos, DotJoin(it.first.first, it.first.second))))
+ Y("let", "row", Y("ForceRemoveMember", "row", BuildQuotedAtom(Pos, DotJoin(it.first.first, it.first.second))))
);
}
- auto options = Y();
+ auto options = Y();
if (StrictJoinKeyTypes) {
options = L(options, Q(Y(Q("strict_keys"))));
}
- equiJoin = L(equiJoin, joinTree, Q(options));
+ equiJoin = L(equiJoin, joinTree, Q(options));
if (removeMembers) {
equiJoin = Y(ordered ? "OrderedMap" : "Map", equiJoin, BuildLambda(Pos, Y("row"), removeMembers, "row"));
}
@@ -594,31 +594,31 @@ public:
}
const THashMap<TString, THashSet<TString>>& GetSameKeysMap() const override {
- return SameKeyMap;
- }
-
+ return SameKeyMap;
+ }
+
TVector<TString> GetJoinLabels() const override {
TVector<TString> labels;
- for (auto& source: Sources) {
- const auto label = source->GetLabel();
- YQL_ENSURE(label);
+ for (auto& source: Sources) {
+ const auto label = source->GetLabel();
+ YQL_ENSURE(label);
labels.push_back(label);
- }
- return labels;
- }
-
- TPtr DoClone() const final {
+ }
+ return labels;
+ }
+
+ TPtr DoClone() const final {
TVector<TSourcePtr> clonedSources;
- for (auto& cur: Sources) {
- clonedSources.push_back(cur->CloneSource());
- }
+ for (auto& cur: Sources) {
+ clonedSources.push_back(cur->CloneSource());
+ }
auto newSource = MakeIntrusive<TEquiJoin>(Pos, std::move(clonedSources), TVector<bool>(AnyFlags), StrictJoinKeyTypes);
- newSource->JoinOps = JoinOps;
- newSource->JoinExprs = CloneContainer(JoinExprs);
+ newSource->JoinOps = JoinOps;
+ newSource->JoinExprs = CloneContainer(JoinExprs);
newSource->JoinLinkSettings = JoinLinkSettings;
- return newSource;
- }
-
+ return newSource;
+ }
+
private:
TNodePtr GetColumnNames(
TContext& ctx,
diff --git a/ydb/library/yql/sql/v1/list_builtin.h b/ydb/library/yql/sql/v1/list_builtin.h
index 11de44214b..a8077b464a 100644
--- a/ydb/library/yql/sql/v1/list_builtin.h
+++ b/ydb/library/yql/sql/v1/list_builtin.h
@@ -22,11 +22,11 @@ public:
: TCallNode(pos, opName, args.size(), args.size(), args)
, OpName(opName)
, Args(args)
- {}
+ {}
bool DoInit(TContext& ctx, ISource* src) override = 0;
- TAstNode* Translate(TContext& ctx) const override;
+ TAstNode* Translate(TContext& ctx) const override;
protected:
const TString OpName;
@@ -36,34 +36,34 @@ protected:
inline TNodePtr GetIdentityLambda();
};
-class TListSortBuiltin final: public TListBuiltin {
+class TListSortBuiltin final: public TListBuiltin {
public:
TListSortBuiltin(TPosition pos, const TVector<TNodePtr>& args, bool asc)
: TListBuiltin(pos, "ListSort", args)
, Asc(asc)
- {}
-
- bool DoInit(TContext& ctx, ISource* src) override;
-
- TNodePtr DoClone() const final {
- return new TListSortBuiltin(Pos, CloneContainer(Args), Asc);
+ {}
+
+ bool DoInit(TContext& ctx, ISource* src) override;
+
+ TNodePtr DoClone() const final {
+ return new TListSortBuiltin(Pos, CloneContainer(Args), Asc);
}
private:
const bool Asc;
};
-class TListExtractBuiltin final: public TListBuiltin {
+class TListExtractBuiltin final: public TListBuiltin {
public:
TListExtractBuiltin(TPosition pos, const TVector<TNodePtr>& args)
: TListBuiltin(pos, "ListExtract", args)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override;
+ bool DoInit(TContext& ctx, ISource* src) override;
- TNodePtr DoClone() const final {
- return new TListExtractBuiltin(Pos, CloneContainer(Args));
- }
+ TNodePtr DoClone() const final {
+ return new TListExtractBuiltin(Pos, CloneContainer(Args));
+ }
};
class TListProcessBuiltin: public TListBuiltin {
@@ -77,37 +77,37 @@ protected:
bool CheckArgs(TContext& ctx, ISource* src);
};
-class TListMapBuiltin final: public TListProcessBuiltin {
+class TListMapBuiltin final: public TListProcessBuiltin {
public:
TListMapBuiltin(TPosition pos,
const TVector<TNodePtr>& args,
bool flat)
: TListProcessBuiltin(pos, flat ? "ListFlatMap" : "ListMap", args)
, Flat(flat)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override;
+ bool DoInit(TContext& ctx, ISource* src) override;
- TNodePtr DoClone() const final {
- return new TListMapBuiltin(Pos, CloneContainer(Args), Flat);
- }
+ TNodePtr DoClone() const final {
+ return new TListMapBuiltin(Pos, CloneContainer(Args), Flat);
+ }
private:
bool Flat;
};
-class TListFilterBuiltin final: public TListProcessBuiltin {
+class TListFilterBuiltin final: public TListProcessBuiltin {
public:
TListFilterBuiltin(TPosition pos, const TString& opName,
const TVector<TNodePtr>& args)
: TListProcessBuiltin(pos, opName, args)
- {}
+ {}
bool DoInit(TContext& ctx, ISource* src) override;
-
- TNodePtr DoClone() const final {
+
+ TNodePtr DoClone() const final {
return new TListFilterBuiltin(Pos, OpName, CloneContainer(Args));
- }
+ }
protected:
virtual TNodePtr GetFilterLambda();
};
@@ -122,7 +122,7 @@ public:
bool DoInit(TContext& ctx, ISource* src) override;
TNodePtr DoClone() const final {
- return new TListUniqBuiltin(Pos, CloneContainer(Args));
+ return new TListUniqBuiltin(Pos, CloneContainer(Args));
}
};
@@ -137,7 +137,7 @@ public:
void DoUpdateState() const override;
TNodePtr DoClone() const final {
- return new TListCreateBuiltin(Pos, CloneContainer(Args));
+ return new TListCreateBuiltin(Pos, CloneContainer(Args));
}
};
diff --git a/ydb/library/yql/sql/v1/node.cpp b/ydb/library/yql/sql/v1/node.cpp
index 9ec0a8aeb8..870bbd9cc7 100644
--- a/ydb/library/yql/sql/v1/node.cpp
+++ b/ydb/library/yql/sql/v1/node.cpp
@@ -19,15 +19,15 @@ using namespace NYql;
namespace NSQLTranslationV1 {
-TString ErrorDistinctWithoutCorrelation(const TString& column) {
- return TStringBuilder() << "DISTINCT columns for JOIN in SELECT should have table aliases (correlation name),"
- " add it if necessary to FROM section over 'AS <alias>' keyword and put it like '<alias>." << column << "'";
-}
-
-TString ErrorDistinctByGroupKey(const TString& column) {
- return TStringBuilder() << "Unable to use DISTINCT by grouping column: " << column << ". You should leave one of them.";
-}
-
+TString ErrorDistinctWithoutCorrelation(const TString& column) {
+ return TStringBuilder() << "DISTINCT columns for JOIN in SELECT should have table aliases (correlation name),"
+ " add it if necessary to FROM section over 'AS <alias>' keyword and put it like '<alias>." << column << "'";
+}
+
+TString ErrorDistinctByGroupKey(const TString& column) {
+ return TStringBuilder() << "Unable to use DISTINCT by grouping column: " << column << ". You should leave one of them.";
+}
+
TTableRef::TTableRef(const TString& refName, const TString& service, const TDeferredAtom& cluster, TNodePtr keys)
: RefName(refName)
, Service(to_lower(service))
@@ -89,34 +89,34 @@ void INode::MarkImplicitLabel(bool isImplicitLabel) {
}
void INode::SetCountHint(bool isCount) {
- State.Set(ENodeState::CountHint, isCount);
+ State.Set(ENodeState::CountHint, isCount);
}
bool INode::GetCountHint() const {
- return State.Test(ENodeState::CountHint);
+ return State.Test(ENodeState::CountHint);
}
-bool INode::IsConstant() const {
- return HasState(ENodeState::Const);
+bool INode::IsConstant() const {
+ return HasState(ENodeState::Const);
}
bool INode::MaybeConstant() const {
return HasState(ENodeState::MaybeConst);
}
-bool INode::IsAggregated() const {
- return HasState(ENodeState::Aggregated);
+bool INode::IsAggregated() const {
+ return HasState(ENodeState::Aggregated);
}
bool INode::IsAggregationKey() const {
return HasState(ENodeState::AggregationKey);
}
-bool INode::IsOverWindow() const {
- return HasState(ENodeState::OverWindow);
-}
-
-bool INode::IsNull() const {
+bool INode::IsOverWindow() const {
+ return HasState(ENodeState::OverWindow);
+}
+
+bool INode::IsNull() const {
return false;
}
@@ -132,10 +132,10 @@ TString INode::GetLiteralValue() const {
return "";
}
-bool INode::IsIntegerLiteral() const {
- return false;
-}
-
+bool INode::IsIntegerLiteral() const {
+ return false;
+}
+
INode::TPtr INode::ApplyUnaryOp(TContext& ctx, TPosition pos, const TString& opName) const {
Y_UNUSED(ctx);
if (IsNull()) {
@@ -144,12 +144,12 @@ INode::TPtr INode::ApplyUnaryOp(TContext& ctx, TPosition pos, const TString& opN
return new TCallNodeImpl(pos, opName, { Clone() });
}
-bool INode::IsAsterisk() const {
+bool INode::IsAsterisk() const {
return false;
}
-const TString* INode::SubqueryAlias() const {
- return nullptr;
+const TString* INode::SubqueryAlias() const {
+ return nullptr;
}
TString INode::GetOpName() const {
@@ -172,10 +172,10 @@ const TString* INode::GetSourceName() const {
return nullptr;
}
-const TString* INode::GetAtomContent() const {
- return nullptr;
-}
-
+const TString* INode::GetAtomContent() const {
+ return nullptr;
+}
+
bool INode::IsOptionalArg() const {
return false;
}
@@ -198,20 +198,20 @@ ISource* INode::GetSource() {
}
TVector<TNodePtr>* INode::ContentListPtr() {
- return nullptr;
-}
-
+ return nullptr;
+}
+
bool INode::Init(TContext& ctx, ISource* src) {
if (State.Test(ENodeState::Failed)) {
return false;
}
- if (!State.Test(ENodeState::Initialized)) {
- if (!DoInit(ctx, src)) {
+ if (!State.Test(ENodeState::Initialized)) {
+ if (!DoInit(ctx, src)) {
State.Set(ENodeState::Failed);
- return false;
- }
- State.Set(ENodeState::Initialized);
+ return false;
+ }
+ State.Set(ENodeState::Initialized);
}
return true;
}
@@ -223,7 +223,7 @@ bool INode::DoInit(TContext& ctx, ISource* src) {
}
TNodePtr INode::AstNode() const {
- return new TAstListNodeImpl(Pos);
+ return new TAstListNodeImpl(Pos);
}
TNodePtr INode::AstNode(TNodePtr node) const {
@@ -231,40 +231,40 @@ TNodePtr INode::AstNode(TNodePtr node) const {
}
TNodePtr INode::AstNode(const TString& str) const {
- return new TAstAtomNodeImpl(Pos, str, TNodeFlags::Default);
+ return new TAstAtomNodeImpl(Pos, str, TNodeFlags::Default);
}
TNodePtr INode::AstNode(TAstNode* node) const {
return new TAstDirectNode(node);
}
-TNodePtr INode::Clone() const {
- TNodePtr clone = DoClone();
- if (!clone) {
- clone = const_cast<INode*>(this);
- } else {
+TNodePtr INode::Clone() const {
+ TNodePtr clone = DoClone();
+ if (!clone) {
+ clone = const_cast<INode*>(this);
+ } else {
YQL_ENSURE(!State.Test(ENodeState::Initialized), "Clone should be for uninitialized or persistent node");
clone->SetLabel(Label, LabelPos);
clone->MarkImplicitLabel(ImplicitLabel);
- }
- return clone;
-}
-
-TAggregationPtr INode::GetAggregation() const {
- return {};
-}
-
+ }
+ return clone;
+}
+
+TAggregationPtr INode::GetAggregation() const {
+ return {};
+}
+
void INode::CollectPreaggregateExprs(TContext& ctx, ISource& src, TVector<INode::TPtr>& exprs) {
Y_UNUSED(ctx);
Y_UNUSED(src);
Y_UNUSED(exprs);
}
-INode::TPtr INode::WindowSpecFunc(const TPtr& type) const {
+INode::TPtr INode::WindowSpecFunc(const TPtr& type) const {
Y_UNUSED(type);
- return {};
-}
-
+ return {};
+}
+
bool INode::SetViewName(TContext& ctx, TPosition pos, const TString& view) {
Y_UNUSED(pos);
Y_UNUSED(view);
@@ -272,14 +272,14 @@ bool INode::SetViewName(TContext& ctx, TPosition pos, const TString& view) {
return false;
}
-void INode::UseAsInner() {
+void INode::UseAsInner() {
AsInner = true;
-}
-
-bool INode::UsedSubquery() const {
- return false;
-}
-
+}
+
+bool INode::UsedSubquery() const {
+ return false;
+}
+
bool INode::IsSelect() const {
return false;
}
@@ -308,24 +308,24 @@ TNodePtr INode::ShallowCopy() const {
return nullptr;
}
-void INode::DoUpdateState() const {
-}
-
-void INode::PrecacheState() const {
+void INode::DoUpdateState() const {
+}
+
+void INode::PrecacheState() const {
if (State.Test(ENodeState::Failed)) {
return;
}
- /// Not work right now! It's better use Init at first, because some kind of update depend on it
- /// \todo turn on and remove all issues
- //Y_VERIFY_DEBUG(State.Test(ENodeState::Initialized));
- if (State.Test(ENodeState::Precached)) {
- return;
- }
- DoUpdateState();
- State.Set(ENodeState::Precached);
-}
-
+ /// Not work right now! It's better use Init at first, because some kind of update depend on it
+ /// \todo turn on and remove all issues
+ //Y_VERIFY_DEBUG(State.Test(ENodeState::Initialized));
+ if (State.Test(ENodeState::Precached)) {
+ return;
+ }
+ DoUpdateState();
+ State.Set(ENodeState::Precached);
+}
+
void INode::DoVisitChildren(const TVisitFunc& func, TVisitNodeSet& visited) const {
Y_UNUSED(func);
Y_UNUSED(visited);
@@ -354,7 +354,7 @@ TAstAtomNode::~TAstAtomNode()
{
}
-void TAstAtomNode::DoUpdateState() const {
+void TAstAtomNode::DoUpdateState() const {
State.Set(ENodeState::Const);
}
@@ -362,10 +362,10 @@ TAstNode* TAstAtomNode::Translate(TContext& ctx) const {
return TAstNode::NewAtom(Pos, Content, *ctx.Pool, Flags);
}
-const TString* TAstAtomNode::GetAtomContent() const {
- return &Content;
-}
-
+const TString* TAstAtomNode::GetAtomContent() const {
+ return &Content;
+}
+
bool TAstAtomNode::IsOptionalArg() const {
return IsOptionalArg_;
}
@@ -424,39 +424,39 @@ TAstNode* TAstListNode::Translate(TContext& ctx) const {
}
void TAstListNode::UpdateStateByListNodes(const TVector<TNodePtr>& nodes) const {
- bool isConst = true;
- struct TAttributesFlags {
- bool has = false;
- bool all = true;
- };
- std::array<ENodeState, 3> checkStates = {{ENodeState::Aggregated, ENodeState::AggregationKey, ENodeState::OverWindow}};
- std::map<ENodeState, TAttributesFlags> flags;
- for (auto& node: nodes) {
- const bool isNodeConst = node->IsConstant();
+ bool isConst = true;
+ struct TAttributesFlags {
+ bool has = false;
+ bool all = true;
+ };
+ std::array<ENodeState, 3> checkStates = {{ENodeState::Aggregated, ENodeState::AggregationKey, ENodeState::OverWindow}};
+ std::map<ENodeState, TAttributesFlags> flags;
+ for (auto& node: nodes) {
+ const bool isNodeConst = node->IsConstant();
const bool isNodeMaybeConst = node->MaybeConstant();
- for (auto state: checkStates) {
- if (node->HasState(state)) {
- flags[state].has = true;
+ for (auto state: checkStates) {
+ if (node->HasState(state)) {
+ flags[state].has = true;
} else if (!isNodeConst && !isNodeMaybeConst) {
- flags[state].all = false;
- }
+ flags[state].all = false;
+ }
if (!isNodeConst) {
isConst = false;
}
- }
- }
- State.Set(ENodeState::Const, isConst);
- for (auto& flag: flags) {
- State.Set(flag.first, flag.second.has && flag.second.all);
- }
+ }
+ }
+ State.Set(ENodeState::Const, isConst);
+ for (auto& flag: flags) {
+ State.Set(flag.first, flag.second.has && flag.second.all);
+ }
State.Set(ENodeState::MaybeConst, !isConst && AllOf(nodes, [](const auto& node) { return node->IsConstant() || node->MaybeConstant(); }));
-}
-
-void TAstListNode::DoUpdateState() const {
- UpdateStateByListNodes(Nodes);
-}
-
+}
+
+void TAstListNode::DoUpdateState() const {
+ UpdateStateByListNodes(Nodes);
+}
+
void TAstListNode::DoVisitChildren(const TVisitFunc& func, TVisitNodeSet& visited) const {
for (auto& node : Nodes) {
node->VisitTree(func, visited);
@@ -468,20 +468,20 @@ TAstListNode::TAstListNode(const TAstListNode& node)
, Nodes(node.Nodes)
{
Label = node.Label;
- State = node.State;
+ State = node.State;
}
TAstListNode::TAstListNode(TPosition pos, TVector<TNodePtr>&& nodes)
- : INode(pos)
- , Nodes(std::move(nodes))
-{
+ : INode(pos)
+ , Nodes(std::move(nodes))
+{
for (const auto& node: Nodes) {
YQL_ENSURE(node, "Null ptr passed as list element");
}
-}
-
+}
+
TNodePtr TAstListNode::ShallowCopy() const {
- return new TAstListNodeImpl(Pos, Nodes);
+ return new TAstListNodeImpl(Pos, Nodes);
}
void TAstListNode::DoAdd(TNodePtr node) {
@@ -490,29 +490,29 @@ void TAstListNode::DoAdd(TNodePtr node) {
Nodes.push_back(node);
}
-TAstListNodeImpl::TAstListNodeImpl(TPosition pos)
- : TAstListNode(pos)
-{}
-
+TAstListNodeImpl::TAstListNodeImpl(TPosition pos)
+ : TAstListNode(pos)
+{}
+
TAstListNodeImpl::TAstListNodeImpl(TPosition pos, TVector<TNodePtr> nodes)
- : TAstListNode(pos)
-{
+ : TAstListNode(pos)
+{
for (const auto& node: nodes) {
YQL_ENSURE(node, "Null ptr passed as list element");
}
- Nodes.swap(nodes);
-}
-
+ Nodes.swap(nodes);
+}
+
void TAstListNodeImpl::CollectPreaggregateExprs(TContext& ctx, ISource& src, TVector<INode::TPtr>& exprs) {
for (auto& node : Nodes) {
node->CollectPreaggregateExprs(ctx, src, exprs);
}
}
-TNodePtr TAstListNodeImpl::DoClone() const {
- return new TAstListNodeImpl(Pos, CloneContainer(Nodes));
-}
-
+TNodePtr TAstListNodeImpl::DoClone() const {
+ return new TAstListNodeImpl(Pos, CloneContainer(Nodes));
+}
+
TCallNode::TCallNode(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args)
: TAstListNode(pos)
, OpName(opName)
@@ -555,51 +555,51 @@ const TVector<TNodePtr>& TCallNode::GetArgs() const {
return Args;
}
-void TCallNode::DoUpdateState() const {
- UpdateStateByListNodes(Args);
-}
-
+void TCallNode::DoUpdateState() const {
+ UpdateStateByListNodes(Args);
+}
+
TString TCallNode::GetCallExplain() const {
- auto derivedName = GetOpName();
- TStringBuilder sb;
- sb << derivedName << "()";
- if (derivedName != OpName) {
- sb << ", converted to " << OpName << "()";
- }
+ auto derivedName = GetOpName();
+ TStringBuilder sb;
+ sb << derivedName << "()";
+ if (derivedName != OpName) {
+ sb << ", converted to " << OpName << "()";
+ }
return std::move(sb);
-}
-
+}
+
void TCallNode::CollectPreaggregateExprs(TContext& ctx, ISource& src, TVector<INode::TPtr>& exprs) {
for (auto& arg : Args) {
arg->CollectPreaggregateExprs(ctx, src, exprs);
}
}
-bool TCallNode::ValidateArguments(TContext& ctx) const {
+bool TCallNode::ValidateArguments(TContext& ctx) const {
const auto argsCount = static_cast<i32>(Args.size());
if (MinArgs >= 0 && MaxArgs == MinArgs && argsCount != MinArgs) {
- ctx.Error(Pos) << GetCallExplain() << " requires exactly " << MinArgs << " arguments, given: " << Args.size();
+ ctx.Error(Pos) << GetCallExplain() << " requires exactly " << MinArgs << " arguments, given: " << Args.size();
return false;
}
if (MinArgs >= 0 && argsCount < MinArgs) {
- ctx.Error(Pos) << GetCallExplain() << " requires at least " << MinArgs << " arguments, given: " << Args.size();
+ ctx.Error(Pos) << GetCallExplain() << " requires at least " << MinArgs << " arguments, given: " << Args.size();
return false;
}
if (MaxArgs >= 0 && argsCount > MaxArgs) {
- ctx.Error(Pos) << GetCallExplain() << " requires at most " << MaxArgs << " arguments, given: " << Args.size();
+ ctx.Error(Pos) << GetCallExplain() << " requires at most " << MaxArgs << " arguments, given: " << Args.size();
+ return false;
+ }
+
+ return true;
+}
+
+bool TCallNode::DoInit(TContext& ctx, ISource* src) {
+ if (!ValidateArguments(ctx)) {
return false;
}
- return true;
-}
-
-bool TCallNode::DoInit(TContext& ctx, ISource* src) {
- if (!ValidateArguments(ctx)) {
- return false;
- }
-
bool hasError = false;
for (auto& arg: Args) {
if (!arg->Init(ctx, src)) {
@@ -607,7 +607,7 @@ bool TCallNode::DoInit(TContext& ctx, ISource* src) {
continue;
}
}
-
+
if (hasError) {
return false;
}
@@ -619,17 +619,17 @@ bool TCallNode::DoInit(TContext& ctx, ISource* src) {
}
TCallNodeImpl::TCallNodeImpl(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args)
- : TCallNode(pos, opName, minArgs, maxArgs, args)
-{}
-
+ : TCallNode(pos, opName, minArgs, maxArgs, args)
+{}
+
TCallNodeImpl::TCallNodeImpl(TPosition pos, const TString& opName, const TVector<TNodePtr>& args)
- : TCallNode(pos, opName, args.size(), args.size(), args)
-{}
-
-TCallNode::TPtr TCallNodeImpl::DoClone() const {
- return new TCallNodeImpl(GetPos(), OpName, MinArgs, MaxArgs, CloneContainer(Args));
-}
-
+ : TCallNode(pos, opName, args.size(), args.size(), args)
+{}
+
+TCallNode::TPtr TCallNodeImpl::DoClone() const {
+ return new TCallNodeImpl(GetPos(), OpName, MinArgs, MaxArgs, CloneContainer(Args));
+}
+
TFuncNodeImpl::TFuncNodeImpl(TPosition pos, const TString& opName)
: TCallNode(pos, opName, 0, 0, {})
{}
@@ -667,43 +667,43 @@ bool TCallNodeDepArgs::DoInit(TContext& ctx, ISource* src) {
return true;
}
-TCallDirectRow::TPtr TCallDirectRow::DoClone() const {
- return new TCallDirectRow(Pos, OpName, CloneContainer(Args));
-}
-
+TCallDirectRow::TPtr TCallDirectRow::DoClone() const {
+ return new TCallDirectRow(Pos, OpName, CloneContainer(Args));
+}
+
TCallDirectRow::TCallDirectRow(TPosition pos, const TString& opName, const TVector<TNodePtr>& args)
- : TCallNode(pos, opName, 0, 0, args)
-{}
-
-bool TCallDirectRow::DoInit(TContext& ctx, ISource* src) {
- if (!src) {
- ctx.Error(Pos) << "Unable to use function: " << OpName << " without source";
- return false;
- }
- if (src->IsCompositeSource() || src->GetJoin() || src->HasAggregations() || src->IsFlattenByColumns() || src->IsOverWindowSource()) {
- ctx.Error(Pos) << "Failed to use function: " << OpName << " with aggregation, join, flatten by or window functions";
- return false;
- }
+ : TCallNode(pos, opName, 0, 0, args)
+{}
+
+bool TCallDirectRow::DoInit(TContext& ctx, ISource* src) {
+ if (!src) {
+ ctx.Error(Pos) << "Unable to use function: " << OpName << " without source";
+ return false;
+ }
+ if (src->IsCompositeSource() || src->GetJoin() || src->HasAggregations() || src->IsFlattenByColumns() || src->IsOverWindowSource()) {
+ ctx.Error(Pos) << "Failed to use function: " << OpName << " with aggregation, join, flatten by or window functions";
+ return false;
+ }
if (!TCallNode::DoInit(ctx, src)) {
return false;
}
Nodes.push_back(Y("DependsOn", "row"));
return true;
-}
-
-void TCallDirectRow::DoUpdateState() const {
- State.Set(ENodeState::Const, false);
-}
-
-void TWinAggrEmulation::DoUpdateState() const {
- State.Set(ENodeState::OverWindow, true);
-}
-
-bool TWinAggrEmulation::DoInit(TContext& ctx, ISource* src) {
+}
+
+void TCallDirectRow::DoUpdateState() const {
+ State.Set(ENodeState::Const, false);
+}
+
+void TWinAggrEmulation::DoUpdateState() const {
+ State.Set(ENodeState::OverWindow, true);
+}
+
+bool TWinAggrEmulation::DoInit(TContext& ctx, ISource* src) {
if (!src) {
ctx.Error(Pos) << "Unable to use window function " << OpName << " without source";
return false;
- }
+ }
if (!src->IsOverWindowSource()) {
ctx.Error(Pos) << "Failed to use window function " << OpName << " without window specification";
@@ -716,51 +716,51 @@ bool TWinAggrEmulation::DoInit(TContext& ctx, ISource* src) {
FuncAlias = "_yql_" + src->MakeLocalName(OpName);
src->AddTmpWindowColumn(FuncAlias);
- if (!TCallNode::DoInit(ctx, src)) {
- return false;
- }
- Nodes.clear();
- Add("Member", "row", Q(FuncAlias));
- return true;
-}
-
-INode::TPtr TWinAggrEmulation::WindowSpecFunc(const TPtr& type) const {
- auto result = Y(OpName, type);
- for (const auto& arg: Args) {
- result = L(result, arg);
- }
- return Q(Y(Q(FuncAlias), result));
-}
-
+ if (!TCallNode::DoInit(ctx, src)) {
+ return false;
+ }
+ Nodes.clear();
+ Add("Member", "row", Q(FuncAlias));
+ return true;
+}
+
+INode::TPtr TWinAggrEmulation::WindowSpecFunc(const TPtr& type) const {
+ auto result = Y(OpName, type);
+ for (const auto& arg: Args) {
+ result = L(result, arg);
+ }
+ return Q(Y(Q(FuncAlias), result));
+}
+
TWinAggrEmulation::TWinAggrEmulation(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args)
- : TCallNode(pos, opName, minArgs, maxArgs, args)
- , FuncAlias(opName)
-{}
-
+ : TCallNode(pos, opName, minArgs, maxArgs, args)
+ , FuncAlias(opName)
+{}
+
TWinRowNumber::TWinRowNumber(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args)
- : TWinAggrEmulation(pos, opName, minArgs, maxArgs, args)
-{}
-
+ : TWinAggrEmulation(pos, opName, minArgs, maxArgs, args)
+{}
+
TWinLeadLag::TWinLeadLag(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args)
- : TWinAggrEmulation(pos, opName, minArgs, maxArgs, args)
-{}
-
-bool TWinLeadLag::DoInit(TContext& ctx, ISource* src) {
- if (Args.size() >= 2) {
- if (!Args[1]->IsIntegerLiteral()) {
- ctx.Error(Args[1]->GetPos()) << "Expected integer literal as second parameter of " << OpName << "( ) function";
- return false;
- }
- }
- if (!TWinAggrEmulation::DoInit(ctx, src)) {
- return false;
- }
- if (Args.size() >= 1) {
+ : TWinAggrEmulation(pos, opName, minArgs, maxArgs, args)
+{}
+
+bool TWinLeadLag::DoInit(TContext& ctx, ISource* src) {
+ if (Args.size() >= 2) {
+ if (!Args[1]->IsIntegerLiteral()) {
+ ctx.Error(Args[1]->GetPos()) << "Expected integer literal as second parameter of " << OpName << "( ) function";
+ return false;
+ }
+ }
+ if (!TWinAggrEmulation::DoInit(ctx, src)) {
+ return false;
+ }
+ if (Args.size() >= 1) {
Args[0] = BuildLambda(Pos, Y("row"), Args[0]);
- }
- return true;
-}
-
+ }
+ return true;
+}
+
TWinRank::TWinRank(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args)
: TWinAggrEmulation(pos, opName, minArgs, maxArgs, args)
{
@@ -852,15 +852,15 @@ public:
Add("quote", BuildAtom(pos, content, flags));
}
-protected:
- TQuotedAtomNode(const TQuotedAtomNode& other)
- : TAstListNode(other.Pos)
+protected:
+ TQuotedAtomNode(const TQuotedAtomNode& other)
+ : TAstListNode(other.Pos)
{
- Nodes = CloneContainer(other.Nodes);
+ Nodes = CloneContainer(other.Nodes);
+ }
+ TPtr DoClone() const final {
+ return new TQuotedAtomNode(*this);
}
- TPtr DoClone() const final {
- return new TQuotedAtomNode(*this);
- }
};
TNodePtr BuildQuotedAtom(TPosition pos, const TString& content, ui32 flags) {
@@ -872,25 +872,25 @@ bool TColumns::Add(const TString* column, bool countHint, bool isArtificial, boo
if (!countHint) {
SetAll();
}
- } else if (!All) {
+ } else if (!All) {
if (column->EndsWith('*')) {
QualifiedAll = true;
}
- bool inserted = false;
- if (isArtificial) {
+ bool inserted = false;
+ if (isArtificial) {
inserted = Artificial.insert(*column).second;
- } else {
+ } else {
inserted = Real.insert(*column).second;
- }
- if (!isReliable) {
- HasUnreliable = true;
- }
+ }
+ if (!isReliable) {
+ HasUnreliable = true;
+ }
if (std::find(List.begin(), List.end(), *column) == List.end()) {
List.push_back(*column);
NamedColumns.push_back(hasName);
- }
- return inserted;
+ }
+ return inserted;
}
return All;
}
@@ -902,66 +902,66 @@ void TColumns::Merge(const TColumns& columns) {
for (auto& c: columns.List) {
if (columns.Real.contains(c)) {
Add(&c, false, false);
- }
+ }
if (columns.Artificial.contains(c)) {
Add(&c, false, true);
- }
+ }
}
- HasUnreliable |= columns.HasUnreliable;
+ HasUnreliable |= columns.HasUnreliable;
}
}
void TColumns::SetPrefix(const TString& prefix) {
- Y_VERIFY_DEBUG(!prefix.empty());
+ Y_VERIFY_DEBUG(!prefix.empty());
auto addPrefixFunc = [&prefix](const TString& str) {
- return prefix + "." + str;
- };
+ return prefix + "." + str;
+ };
TSet<TString> newReal;
TSet<TString> newArtificial;
TVector<TString> newList;
- std::transform(Real.begin(), Real.end(), std::inserter(newReal, newReal.begin()), addPrefixFunc);
- std::transform(Artificial.begin(), Artificial.end(), std::inserter(newArtificial, newArtificial.begin()), addPrefixFunc);
- std::transform(List.begin(), List.end(), std::back_inserter(newList), addPrefixFunc);
- newReal.swap(Real);
- newArtificial.swap(Artificial);
- newList.swap(List);
-}
-
+ std::transform(Real.begin(), Real.end(), std::inserter(newReal, newReal.begin()), addPrefixFunc);
+ std::transform(Artificial.begin(), Artificial.end(), std::inserter(newArtificial, newArtificial.begin()), addPrefixFunc);
+ std::transform(List.begin(), List.end(), std::back_inserter(newList), addPrefixFunc);
+ newReal.swap(Real);
+ newArtificial.swap(Artificial);
+ newList.swap(List);
+}
+
void TColumns::SetAll() {
All = true;
- Real.clear();
+ Real.clear();
List.clear();
- Artificial.clear();
+ Artificial.clear();
}
-bool TColumns::IsColumnPossible(TContext& ctx, const TString& name) {
+bool TColumns::IsColumnPossible(TContext& ctx, const TString& name) {
if (All || Real.contains(name) || Artificial.contains(name)) {
- return true;
- }
- if (QualifiedAll) {
- if (ctx.SimpleColumns) {
- return true;
- }
+ return true;
+ }
+ if (QualifiedAll) {
+ if (ctx.SimpleColumns) {
+ return true;
+ }
for (const auto& real: Real) {
- const auto pos = real.find_first_of("*");
- if (pos == TString::npos) {
- continue;
- }
- if (name.StartsWith(real.substr(0, pos))) {
- return true;
- }
- }
- }
- return false;
-}
-
-TSortSpecificationPtr TSortSpecification::Clone() const {
- auto res = MakeIntrusive<TSortSpecification>();
- res->OrderExpr = OrderExpr->Clone();
- res->Ascending = Ascending;
- return res;
-}
-
+ const auto pos = real.find_first_of("*");
+ if (pos == TString::npos) {
+ continue;
+ }
+ if (name.StartsWith(real.substr(0, pos))) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+TSortSpecificationPtr TSortSpecification::Clone() const {
+ auto res = MakeIntrusive<TSortSpecification>();
+ res->OrderExpr = OrderExpr->Clone();
+ res->Ascending = Ascending;
+ return res;
+}
+
TFrameBoundPtr TFrameBound::Clone() const {
auto res = MakeIntrusive<TFrameBound>();
res->Pos = Pos;
@@ -981,28 +981,28 @@ TFrameSpecificationPtr TFrameSpecification::Clone() const {
return res;
}
-TWindowSpecificationPtr TWindowSpecification::Clone() const {
+TWindowSpecificationPtr TWindowSpecification::Clone() const {
YQL_ENSURE(Frame);
- auto res = MakeIntrusive<TWindowSpecification>();
- res->ExistingWindowName = ExistingWindowName;
- res->Partitions = CloneContainer(Partitions);
+ auto res = MakeIntrusive<TWindowSpecification>();
+ res->ExistingWindowName = ExistingWindowName;
+ res->Partitions = CloneContainer(Partitions);
res->IsCompact = IsCompact;
- res->OrderBy = CloneContainer(OrderBy);
+ res->OrderBy = CloneContainer(OrderBy);
res->Session = SafeClone(Session);
res->Frame = Frame->Clone();
- return res;
-}
-
-THoppingWindowSpecPtr THoppingWindowSpec::Clone() const {
- auto res = MakeIntrusive<THoppingWindowSpec>();
- res->TimeExtractor = TimeExtractor->Clone();
+ return res;
+}
+
+THoppingWindowSpecPtr THoppingWindowSpec::Clone() const {
+ auto res = MakeIntrusive<THoppingWindowSpec>();
+ res->TimeExtractor = TimeExtractor->Clone();
res->Hop = Hop->Clone();
res->Interval = Interval->Clone();
res->Delay = Delay->Clone();
res->DataWatermarks = DataWatermarks;
- return res;
-}
-
+ return res;
+}
+
TColumnNode::TColumnNode(TPosition pos, const TString& column, const TString& source, bool maybeType)
: INode(pos)
, ColumnName(column)
@@ -1026,26 +1026,26 @@ bool TColumnNode::IsAsterisk() const {
return ColumnName == "*";
}
-bool TColumnNode::IsArtificial() const {
- return Artificial;
-}
-
+bool TColumnNode::IsArtificial() const {
+ return Artificial;
+}
+
const TString* TColumnNode::GetColumnName() const {
return UseSourceAsColumn ? &Source : (ColumnExpr ? nullptr : &ColumnName);
}
const TString* TColumnNode::GetSourceName() const {
- return UseSourceAsColumn ? &Empty : &Source;
+ return UseSourceAsColumn ? &Empty : &Source;
}
bool TColumnNode::DoInit(TContext& ctx, ISource* src) {
- if (src) {
- YQL_ENSURE(!State.Test(ENodeState::Initialized)); /// should be not initialized or Aggregated already invalid
- if (src->ShouldUseSourceAsColumn(*GetSourceName())) {
- if (!IsAsterisk() && IsReliable()) {
- SetUseSourceAsColumn();
- }
- }
+ if (src) {
+ YQL_ENSURE(!State.Test(ENodeState::Initialized)); /// should be not initialized or Aggregated already invalid
+ if (src->ShouldUseSourceAsColumn(*GetSourceName())) {
+ if (!IsAsterisk() && IsReliable()) {
+ SetUseSourceAsColumn();
+ }
+ }
if (GetColumnName()) {
auto fullName = Source ? DotJoin(Source, *GetColumnName()) : *GetColumnName();
@@ -1054,18 +1054,18 @@ bool TColumnNode::DoInit(TContext& ctx, ISource* src) {
ResetColumn(alias, {});
}
Artificial = !Source && src->IsExprAlias(*GetColumnName());
- }
+ }
- if (!src->AddColumn(ctx, *this)) {
- return false;
- }
+ if (!src->AddColumn(ctx, *this)) {
+ return false;
+ }
if (GetColumnName()) {
if (src->GetJoin() && Source) {
GroupKey = src->IsGroupByColumn(DotJoin(Source, *GetColumnName()));
} else {
GroupKey = src->IsGroupByColumn(*GetColumnName()) || src->IsAlias(EExprSeat::GroupBy, *GetColumnName());
}
- }
+ }
}
if (IsAsterisk()) {
Node = AstNode("row");
@@ -1078,71 +1078,71 @@ bool TColumnNode::DoInit(TContext& ctx, ISource* src) {
callable = Reliable && !UseSource ? "Member" : "SqlColumn";
}
Node = Y(callable, "row", ColumnExpr ? Y("EvaluateAtom", ColumnExpr) : BuildQuotedAtom(Pos, *GetColumnName()));
- if (UseSource) {
- YQL_ENSURE(Source);
- Node = L(Node, BuildQuotedAtom(Pos, Source));
- }
+ if (UseSource) {
+ YQL_ENSURE(Source);
+ Node = L(Node, BuildQuotedAtom(Pos, Source));
+ }
}
return Node->Init(ctx, src);
}
-void TColumnNode::SetUseSourceAsColumn() {
- YQL_ENSURE(!State.Test(ENodeState::Initialized)); /// should be not initialized or Aggregated already invalid
- YQL_ENSURE(!IsAsterisk());
- UseSourceAsColumn = true;
-}
-
-void TColumnNode::ResetAsReliable() {
- Reliable = true;
-}
-
-void TColumnNode::SetAsNotReliable() {
- Reliable = false;
-}
-
-void TColumnNode::SetUseSource() {
- UseSource = true;
-}
-
-bool TColumnNode::IsUseSourceAsColumn() const {
- return UseSourceAsColumn;
-}
-
-bool TColumnNode::IsReliable() const {
- return Reliable;
-}
-
+void TColumnNode::SetUseSourceAsColumn() {
+ YQL_ENSURE(!State.Test(ENodeState::Initialized)); /// should be not initialized or Aggregated already invalid
+ YQL_ENSURE(!IsAsterisk());
+ UseSourceAsColumn = true;
+}
+
+void TColumnNode::ResetAsReliable() {
+ Reliable = true;
+}
+
+void TColumnNode::SetAsNotReliable() {
+ Reliable = false;
+}
+
+void TColumnNode::SetUseSource() {
+ UseSource = true;
+}
+
+bool TColumnNode::IsUseSourceAsColumn() const {
+ return UseSourceAsColumn;
+}
+
+bool TColumnNode::IsReliable() const {
+ return Reliable;
+}
+
bool TColumnNode::CanBeType() const {
return MaybeType;
}
-TNodePtr TColumnNode::DoClone() const {
- YQL_ENSURE(!Node, "TColumnNode::Clone: Node should not be initialized");
+TNodePtr TColumnNode::DoClone() const {
+ YQL_ENSURE(!Node, "TColumnNode::Clone: Node should not be initialized");
auto copy = ColumnExpr ? new TColumnNode(Pos, ColumnExpr, Source) : new TColumnNode(Pos, ColumnName, Source, MaybeType);
- copy->GroupKey = GroupKey;
- copy->Artificial = Artificial;
- copy->Reliable = Reliable;
- copy->UseSource = UseSource;
- copy->UseSourceAsColumn = UseSourceAsColumn;
- return copy;
-}
-
-void TColumnNode::DoUpdateState() const {
- State.Set(ENodeState::Const, false);
+ copy->GroupKey = GroupKey;
+ copy->Artificial = Artificial;
+ copy->Reliable = Reliable;
+ copy->UseSource = UseSource;
+ copy->UseSourceAsColumn = UseSourceAsColumn;
+ return copy;
+}
+
+void TColumnNode::DoUpdateState() const {
+ State.Set(ENodeState::Const, false);
State.Set(ENodeState::MaybeConst, MaybeType);
- State.Set(ENodeState::Aggregated, GroupKey);
- State.Set(ENodeState::AggregationKey, GroupKey);
-}
-
+ State.Set(ENodeState::Aggregated, GroupKey);
+ State.Set(ENodeState::AggregationKey, GroupKey);
+}
+
TAstNode* TColumnNode::Translate(TContext& ctx) const {
return Node->Translate(ctx);
}
void TColumnNode::ResetColumn(const TString& column, const TString& source) {
- YQL_ENSURE(!State.Test(ENodeState::Initialized)); /// should be not initialized
- Reliable = true;
- UseSource = false;
- UseSourceAsColumn = false;
+ YQL_ENSURE(!State.Test(ENodeState::Initialized)); /// should be not initialized
+ Reliable = true;
+ UseSource = false;
+ UseSourceAsColumn = false;
ColumnName = column;
ColumnExpr = nullptr;
Source = source;
@@ -1159,7 +1159,7 @@ void TColumnNode::ResetColumn(const TNodePtr& column, const TString& source) {
}
const TString TColumnNode::Empty;
-
+
TNodePtr BuildColumn(TPosition pos, const TString& column, const TString& source) {
bool maybeType = false;
return new TColumnNode(pos, column, source, maybeType);
@@ -1202,11 +1202,11 @@ bool IAggregation::IsDistinct() const {
return !DistinctKey.empty();
}
-void IAggregation::DoUpdateState() const {
- State.Set(ENodeState::Aggregated, AggMode == EAggregateMode::Normal);
- State.Set(ENodeState::OverWindow, AggMode == EAggregateMode::OverWindow);
-}
-
+void IAggregation::DoUpdateState() const {
+ State.Set(ENodeState::Aggregated, AggMode == EAggregateMode::Normal);
+ State.Set(ENodeState::OverWindow, AggMode == EAggregateMode::OverWindow);
+}
+
const TString* IAggregation::GetGenericKey() const {
return nullptr;
}
@@ -1228,7 +1228,7 @@ void IAggregation::MarkKeyColumnAsGenerated() {
}
IAggregation::IAggregation(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode)
- : INode(pos), Name(name), Func(func), AggMode(aggMode)
+ : INode(pos), Name(name), Func(func), AggMode(aggMode)
{}
TAstNode* IAggregation::Translate(TContext& ctx) const {
@@ -1237,10 +1237,10 @@ TAstNode* IAggregation::Translate(TContext& ctx) const {
return nullptr;
}
-TNodePtr IAggregation::AggregationTraits(const TNodePtr& type) const {
- const bool distinct = AggMode == EAggregateMode::Distinct;
- const auto listType = distinct ? Y("ListType", Y("StructMemberType", Y("ListItemType", type), BuildQuotedAtom(Pos, DistinctKey))) : type;
- return distinct ? Q(Y(Q(Name), GetApply(listType), BuildQuotedAtom(Pos, DistinctKey))): Q(Y(Q(Name), GetApply(listType)));
+TNodePtr IAggregation::AggregationTraits(const TNodePtr& type) const {
+ const bool distinct = AggMode == EAggregateMode::Distinct;
+ const auto listType = distinct ? Y("ListType", Y("StructMemberType", Y("ListItemType", type), BuildQuotedAtom(Pos, DistinctKey))) : type;
+ return distinct ? Q(Y(Q(Name), GetApply(listType), BuildQuotedAtom(Pos, DistinctKey))): Q(Y(Q(Name), GetApply(listType)));
}
void IAggregation::AddFactoryArguments(TNodePtr& apply) const {
@@ -1251,11 +1251,11 @@ std::vector<ui32> IAggregation::GetFactoryColumnIndices() const {
return {0u};
}
-TNodePtr IAggregation::WindowTraits(const TNodePtr& type) const {
- YQL_ENSURE(AggMode == EAggregateMode::OverWindow, "Windows traits is unavailable");
- return Q(Y(Q(Name), GetApply(type)));
-}
-
+TNodePtr IAggregation::WindowTraits(const TNodePtr& type) const {
+ YQL_ENSURE(AggMode == EAggregateMode::OverWindow, "Windows traits is unavailable");
+ return Q(Y(Q(Name), GetApply(type)));
+}
+
ISource::ISource(TPosition pos)
: INode(pos)
{
@@ -1265,20 +1265,20 @@ ISource::~ISource()
{
}
-TSourcePtr ISource::CloneSource() const {
- Y_VERIFY_DEBUG(dynamic_cast<ISource*>(Clone().Get()), "Cloned node is no source");
- TSourcePtr result = static_cast<ISource*>(Clone().Get());
- for (auto curFilter: Filters) {
- result->Filters.emplace_back(curFilter->Clone());
- }
- for (int i = 0; i < static_cast<int>(EExprSeat::Max); ++i) {
- result->NamedExprs[i] = CloneContainer(NamedExprs[i]);
- }
- result->FlattenColumns = FlattenColumns;
+TSourcePtr ISource::CloneSource() const {
+ Y_VERIFY_DEBUG(dynamic_cast<ISource*>(Clone().Get()), "Cloned node is no source");
+ TSourcePtr result = static_cast<ISource*>(Clone().Get());
+ for (auto curFilter: Filters) {
+ result->Filters.emplace_back(curFilter->Clone());
+ }
+ for (int i = 0; i < static_cast<int>(EExprSeat::Max); ++i) {
+ result->NamedExprs[i] = CloneContainer(NamedExprs[i]);
+ }
+ result->FlattenColumns = FlattenColumns;
result->FlattenMode = FlattenMode;
- return result;
-}
-
+ return result;
+}
+
bool ISource::IsFake() const {
return false;
}
@@ -1292,25 +1292,25 @@ const TColumns* ISource::GetColumns() const {
}
void ISource::GetInputTables(TTableList& tableList) const {
- for (auto srcPtr: UsedSources) {
+ for (auto srcPtr: UsedSources) {
srcPtr->GetInputTables(tableList);
- }
+ }
return;
}
-TMaybe<bool> ISource::AddColumn(TContext& ctx, TColumnNode& column) {
- if (column.IsReliable()) {
- ctx.Error(Pos) << "Source does not allow column references";
+TMaybe<bool> ISource::AddColumn(TContext& ctx, TColumnNode& column) {
+ if (column.IsReliable()) {
+ ctx.Error(Pos) << "Source does not allow column references";
ctx.Error(column.GetPos()) << "Column reference " <<
(column.GetColumnName() ? "'" + *column.GetColumnName() + "'" : "(expr)");
- }
- return {};
+ }
+ return {};
}
-void ISource::FinishColumns() {
-}
-
-
+void ISource::FinishColumns() {
+}
+
+
bool ISource::AddFilter(TContext& ctx, TNodePtr filter) {
Y_UNUSED(ctx);
Filters.push_back(filter);
@@ -1318,11 +1318,11 @@ bool ISource::AddFilter(TContext& ctx, TNodePtr filter) {
}
bool ISource::AddGroupKey(TContext& ctx, const TString& column) {
- if (!GroupKeys.insert(column).second) {
+ if (!GroupKeys.insert(column).second) {
ctx.Error() << "Duplicate grouping column: " << column;
return false;
}
- OrderedGroupKeys.push_back(column);
+ OrderedGroupKeys.push_back(column);
return true;
}
@@ -1331,50 +1331,50 @@ void ISource::SetCompactGroupBy(bool compactGroupBy) {
}
bool ISource::AddExpressions(TContext& ctx, const TVector<TNodePtr>& expressions, EExprSeat exprSeat) {
- YQL_ENSURE(exprSeat < EExprSeat::Max);
+ YQL_ENSURE(exprSeat < EExprSeat::Max);
THashSet<TString> names;
THashSet<TString> aliasSet;
// TODO: merge FlattenBy with FlattenByExpr
const bool isFlatten = (exprSeat == EExprSeat::FlattenBy || exprSeat == EExprSeat::FlattenByExpr);
THashSet<TString>& aliases = isFlatten ? FlattenByAliases : aliasSet;
- for (const auto& expr: expressions) {
- const auto& alias = expr->GetLabel();
- const auto& columnNamePtr = expr->GetColumnName();
- if (alias) {
+ for (const auto& expr: expressions) {
+ const auto& alias = expr->GetLabel();
+ const auto& columnNamePtr = expr->GetColumnName();
+ if (alias) {
ExprAliases.insert(alias);
if (!aliases.emplace(alias).second) {
- ctx.Error(expr->GetPos()) << "Duplicate alias found: " << alias << " in " << exprSeat << " section";
- return false;
- }
+ ctx.Error(expr->GetPos()) << "Duplicate alias found: " << alias << " in " << exprSeat << " section";
+ return false;
+ }
if (names.contains(alias)) {
- ctx.Error(expr->GetPos()) << "Collision between alias and column name: " << alias << " in " << exprSeat << " section";
- return false;
- }
- }
- if (columnNamePtr) {
- const auto& sourceName = *expr->GetSourceName();
- auto columnName = *columnNamePtr;
- if (sourceName) {
- columnName = DotJoin(sourceName, columnName);
- }
- if (!names.emplace(columnName).second) {
- ctx.Error(expr->GetPos()) << "Duplicate column name found: " << columnName << " in " << exprSeat << " section";
- return false;
- }
+ ctx.Error(expr->GetPos()) << "Collision between alias and column name: " << alias << " in " << exprSeat << " section";
+ return false;
+ }
+ }
+ if (columnNamePtr) {
+ const auto& sourceName = *expr->GetSourceName();
+ auto columnName = *columnNamePtr;
+ if (sourceName) {
+ columnName = DotJoin(sourceName, columnName);
+ }
+ if (!names.emplace(columnName).second) {
+ ctx.Error(expr->GetPos()) << "Duplicate column name found: " << columnName << " in " << exprSeat << " section";
+ return false;
+ }
if (!alias && aliases.contains(columnName)) {
- ctx.Error(expr->GetPos()) << "Collision between alias and column name: " << columnName << " in " << exprSeat << " section";
- return false;
- }
- if (alias && exprSeat == EExprSeat::GroupBy) {
- auto columnAlias = GroupByColumnAliases.emplace(columnName, alias);
- auto oldAlias = columnAlias.first->second;
- if (columnAlias.second && oldAlias != alias) {
- ctx.Error(expr->GetPos()) << "Alias for column not same, column: " << columnName <<
- ", exist alias: " << oldAlias << ", another alias: " << alias;
- return false;
- }
- }
- }
+ ctx.Error(expr->GetPos()) << "Collision between alias and column name: " << columnName << " in " << exprSeat << " section";
+ return false;
+ }
+ if (alias && exprSeat == EExprSeat::GroupBy) {
+ auto columnAlias = GroupByColumnAliases.emplace(columnName, alias);
+ auto oldAlias = columnAlias.first->second;
+ if (columnAlias.second && oldAlias != alias) {
+ ctx.Error(expr->GetPos()) << "Alias for column not same, column: " << columnName <<
+ ", exist alias: " << oldAlias << ", another alias: " << alias;
+ return false;
+ }
+ }
+ }
if (exprSeat == EExprSeat::GroupBy) {
if (auto sessionWindow = dynamic_cast<TSessionWindow*>(expr.Get())) {
@@ -1386,11 +1386,11 @@ bool ISource::AddExpressions(TContext& ctx, const TVector<TNodePtr>& expressions
SessionWindow = expr;
}
}
- Expressions(exprSeat).emplace_back(expr);
- }
- return true;
-}
-
+ Expressions(exprSeat).emplace_back(expr);
+ }
+ return true;
+}
+
void ISource::SetFlattenByMode(const TString& mode) {
FlattenMode = mode;
}
@@ -1425,16 +1425,16 @@ bool ISource::HasAggregations() const {
return !Aggregations.empty() || !GroupKeys.empty();
}
-void ISource::AddWindowSpecs(TWinSpecs winSpecs) {
- WinSpecs = winSpecs;
-}
-
-bool ISource::AddFuncOverWindow(TContext& ctx, TNodePtr expr) {
+void ISource::AddWindowSpecs(TWinSpecs winSpecs) {
+ WinSpecs = winSpecs;
+}
+
+bool ISource::AddFuncOverWindow(TContext& ctx, TNodePtr expr) {
Y_UNUSED(ctx);
Y_UNUSED(expr);
- return false;
-}
-
+ return false;
+}
+
void ISource::AddTmpWindowColumn(const TString& column) {
TmpWindowColumns.push_back(column);
}
@@ -1455,132 +1455,132 @@ TNodePtr ISource::GetSessionWindowSpec() const {
return SessionWindow;
}
-TWindowSpecificationPtr ISource::FindWindowSpecification(TContext& ctx, const TString& windowName) const {
- auto winIter = WinSpecs.find(windowName);
- if (winIter == WinSpecs.end()) {
+TWindowSpecificationPtr ISource::FindWindowSpecification(TContext& ctx, const TString& windowName) const {
+ auto winIter = WinSpecs.find(windowName);
+ if (winIter == WinSpecs.end()) {
ctx.Error(Pos) << "Unable to find window specification for window '" << windowName << "'";
- return {};
- }
+ return {};
+ }
YQL_ENSURE(winIter->second);
return winIter->second;
-}
-
+}
+
inline TVector<TNodePtr>& ISource::Expressions(EExprSeat exprSeat) {
- return NamedExprs[static_cast<size_t>(exprSeat)];
-}
-
+ return NamedExprs[static_cast<size_t>(exprSeat)];
+}
+
const TVector<TNodePtr>& ISource::Expressions(EExprSeat exprSeat) const {
- return NamedExprs[static_cast<size_t>(exprSeat)];
-}
-
-inline TNodePtr ISource::AliasOrColumn(const TNodePtr& node, bool withSource) {
- auto result = node->GetLabel();
- if (!result) {
- const auto columnNamePtr = node->GetColumnName();
- YQL_ENSURE(columnNamePtr);
- result = *columnNamePtr;
- if (withSource) {
- const auto sourceNamePtr = node->GetSourceName();
- if (sourceNamePtr) {
- result = DotJoin(*sourceNamePtr, result);
- }
- }
- }
+ return NamedExprs[static_cast<size_t>(exprSeat)];
+}
+
+inline TNodePtr ISource::AliasOrColumn(const TNodePtr& node, bool withSource) {
+ auto result = node->GetLabel();
+ if (!result) {
+ const auto columnNamePtr = node->GetColumnName();
+ YQL_ENSURE(columnNamePtr);
+ result = *columnNamePtr;
+ if (withSource) {
+ const auto sourceNamePtr = node->GetSourceName();
+ if (sourceNamePtr) {
+ result = DotJoin(*sourceNamePtr, result);
+ }
+ }
+ }
return BuildQuotedAtom(node->GetPos(), result);
-}
-
+}
+
bool ISource::AddAggregationOverWindow(TContext& ctx, const TString& windowName, TAggregationPtr func) {
YQL_ENSURE(func->IsOverWindow());
- if (func->IsDistinct()) {
- ctx.Error(func->GetPos()) << "Aggregation with distinct is not allowed over window: " << windowName;
- return false;
- }
- if (!FindWindowSpecification(ctx, windowName)) {
- return false;
- }
+ if (func->IsDistinct()) {
+ ctx.Error(func->GetPos()) << "Aggregation with distinct is not allowed over window: " << windowName;
+ return false;
+ }
+ if (!FindWindowSpecification(ctx, windowName)) {
+ return false;
+ }
AggregationOverWindow[windowName].emplace_back(std::move(func));
- return true;
-}
-
+ return true;
+}
+
bool ISource::AddFuncOverWindow(TContext& ctx, const TString& windowName, TNodePtr func) {
- if (!FindWindowSpecification(ctx, windowName)) {
- return false;
- }
+ if (!FindWindowSpecification(ctx, windowName)) {
+ return false;
+ }
FuncOverWindow[windowName].emplace_back(std::move(func));
- return true;
-}
-
-bool ISource::IsCompositeSource() const {
+ return true;
+}
+
+bool ISource::IsCompositeSource() const {
return false;
}
bool ISource::IsGroupByColumn(const TString& column) const {
return GroupKeys.contains(column);
-}
-
-bool ISource::IsFlattenByColumns() const {
- return !Expressions(EExprSeat::FlattenBy).empty();
-}
-
+}
+
+bool ISource::IsFlattenByColumns() const {
+ return !Expressions(EExprSeat::FlattenBy).empty();
+}
+
bool ISource::IsFlattenByExprs() const {
return !Expressions(EExprSeat::FlattenByExpr).empty();
}
bool ISource::IsAlias(EExprSeat exprSeat, const TString& column) const {
- for (const auto& exprNode: Expressions(exprSeat)) {
- const auto& labelName = exprNode->GetLabel();
- if (labelName && labelName == column) {
- return true;
- }
- }
- return false;
-}
-
+ for (const auto& exprNode: Expressions(exprSeat)) {
+ const auto& labelName = exprNode->GetLabel();
+ if (labelName && labelName == column) {
+ return true;
+ }
+ }
+ return false;
+}
+
bool ISource::IsExprAlias(const TString& column) const {
std::array<EExprSeat, 5> exprSeats = {{EExprSeat::FlattenBy, EExprSeat::FlattenByExpr, EExprSeat::GroupBy,
EExprSeat::WindowPartitionBy, EExprSeat::DistinctAggr}};
- for (auto seat: exprSeats) {
- if (IsAlias(seat, column)) {
- return true;
- }
- }
- return false;
-}
-
-bool ISource::IsExprSeat(EExprSeat exprSeat, EExprType type) const {
- auto expressions = Expressions(exprSeat);
- if (!expressions) {
- return false;
- }
- for (const auto& exprNode: expressions) {
- if (exprNode->GetLabel()) {
- return type == EExprType::WithExpression;
- }
- }
- return type == EExprType::ColumnOnly;
-}
-
-TString ISource::GetGroupByColumnAlias(const TString& column) const {
- auto iter = GroupByColumnAliases.find(column);
- if (iter == GroupByColumnAliases.end()) {
- return {};
- }
- return iter->second;
-}
-
-const TString* ISource::GetWindowName() const {
- return {};
-}
-
-bool ISource::IsCalcOverWindow() const {
+ for (auto seat: exprSeats) {
+ if (IsAlias(seat, column)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool ISource::IsExprSeat(EExprSeat exprSeat, EExprType type) const {
+ auto expressions = Expressions(exprSeat);
+ if (!expressions) {
+ return false;
+ }
+ for (const auto& exprNode: expressions) {
+ if (exprNode->GetLabel()) {
+ return type == EExprType::WithExpression;
+ }
+ }
+ return type == EExprType::ColumnOnly;
+}
+
+TString ISource::GetGroupByColumnAlias(const TString& column) const {
+ auto iter = GroupByColumnAliases.find(column);
+ if (iter == GroupByColumnAliases.end()) {
+ return {};
+ }
+ return iter->second;
+}
+
+const TString* ISource::GetWindowName() const {
+ return {};
+}
+
+bool ISource::IsCalcOverWindow() const {
return !AggregationOverWindow.empty() || !FuncOverWindow.empty() ||
AnyOf(WinSpecs, [](const auto& item) { return item.second->Session; });
-}
-
-bool ISource::IsOverWindowSource() const {
- return !WinSpecs.empty();
-}
-
+}
+
+bool ISource::IsOverWindowSource() const {
+ return !WinSpecs.empty();
+}
+
bool ISource::IsStream() const {
return false;
}
@@ -1619,42 +1619,42 @@ bool ISource::SetTableHints(TContext& ctx, TPosition pos, const TTableHints& hin
bool ISource::CalculateGroupingHint(TContext& ctx, const TVector<TString>& columns, ui64& hint) const {
Y_UNUSED(columns);
Y_UNUSED(hint);
- ctx.Error() << "Source not support grouping hint";
- return false;
-}
-
+ ctx.Error() << "Source not support grouping hint";
+ return false;
+}
+
TNodePtr ISource::BuildFilter(TContext& ctx, const TString& label) {
return Filters.empty() ? nullptr : Y(ctx.UseUnordered(*this) ? "OrderedFilter" : "Filter", label, BuildFilterLambda());
-}
-
+}
+
TNodePtr ISource::BuildFilterLambda() {
- if (Filters.empty()) {
- return BuildLambda(Pos, Y("row"), Y("Bool", Q("true")));
+ if (Filters.empty()) {
+ return BuildLambda(Pos, Y("row"), Y("Bool", Q("true")));
}
- YQL_ENSURE(Filters[0]->HasState(ENodeState::Initialized));
- TNodePtr filter(Filters[0]);
- for (ui32 i = 1; i < Filters.size(); ++i) {
- YQL_ENSURE(Filters[i]->HasState(ENodeState::Initialized));
- filter = Y("And", filter, Filters[i]);
- }
- filter = Y("Coalesce", filter, Y("Bool", Q("false")));
- return BuildLambda(Pos, Y("row"), filter);
+ YQL_ENSURE(Filters[0]->HasState(ENodeState::Initialized));
+ TNodePtr filter(Filters[0]);
+ for (ui32 i = 1; i < Filters.size(); ++i) {
+ YQL_ENSURE(Filters[i]->HasState(ENodeState::Initialized));
+ filter = Y("And", filter, Filters[i]);
+ }
+ filter = Y("Coalesce", filter, Y("Bool", Q("false")));
+ return BuildLambda(Pos, Y("row"), filter);
}
TNodePtr ISource::BuildFlattenByColumns(const TString& label) {
auto columnsList = Y("FlattenByColumns", Q(FlattenMode), label);
- for (const auto& column: Expressions(EExprSeat::FlattenBy)) {
- const auto columnNamePtr = column->GetColumnName();
- YQL_ENSURE(columnNamePtr);
- if (column->GetLabel().empty()) {
- columnsList = L(columnsList, Q(*columnNamePtr));
- } else {
- columnsList = L(columnsList, Q(Y(Q(*columnNamePtr), Q(column->GetLabel()))));
- }
- }
- return Y(Y("let", "res", columnsList));
-}
-
+ for (const auto& column: Expressions(EExprSeat::FlattenBy)) {
+ const auto columnNamePtr = column->GetColumnName();
+ YQL_ENSURE(columnNamePtr);
+ if (column->GetLabel().empty()) {
+ columnsList = L(columnsList, Q(*columnNamePtr));
+ } else {
+ columnsList = L(columnsList, Q(Y(Q(*columnNamePtr), Q(column->GetLabel()))));
+ }
+ }
+ return Y(Y("let", "res", columnsList));
+}
+
TNodePtr ISource::BuildFlattenColumns(const TString& label) {
return Y(Y("let", "res", Y("Just", Y("FlattenStructs", label))));
}
@@ -1687,7 +1687,7 @@ TNodePtr ISource::BuildPreaggregatedMap(TContext& ctx) {
if (groupByExprs) {
auto body = BuildLambdaBodyForExprAliases(Pos, groupByExprs);
res = Y("FlatMap", "core", BuildLambda(Pos, Y("row"), body));
- }
+ }
if (distinctAggrExprs) {
auto body = BuildLambdaBodyForExprAliases(Pos, distinctAggrExprs);
@@ -1695,8 +1695,8 @@ TNodePtr ISource::BuildPreaggregatedMap(TContext& ctx) {
res = res ? Y("FlatMap", res, lambda) : Y("FlatMap", "core", lambda);
}
return res;
-}
-
+}
+
TNodePtr ISource::BuildPreFlattenMap(TContext& ctx) {
Y_UNUSED(ctx);
YQL_ENSURE(IsFlattenByExprs());
@@ -1704,16 +1704,16 @@ TNodePtr ISource::BuildPreFlattenMap(TContext& ctx) {
}
TNodePtr ISource::BuildPrewindowMap(TContext& ctx) {
- auto feed = BuildAtom(Pos, "row", TNodeFlags::Default);
- for (const auto& exprNode: Expressions(EExprSeat::WindowPartitionBy)) {
- const auto name = exprNode->GetLabel();
+ auto feed = BuildAtom(Pos, "row", TNodeFlags::Default);
+ for (const auto& exprNode: Expressions(EExprSeat::WindowPartitionBy)) {
+ const auto name = exprNode->GetLabel();
if (name && !dynamic_cast<const TSessionWindow*>(exprNode.Get())) {
feed = Y("AddMember", feed, Q(name), exprNode);
- }
- }
+ }
+ }
return Y(ctx.UseUnordered(*this) ? "OrderedFlatMap" : "FlatMap", "core", BuildLambda(Pos, Y("row"), Y("AsList", feed)));
-}
-
+}
+
bool ISource::BuildSamplingLambda(TNodePtr& node) {
if (!SamplingRate) {
return true;
@@ -1737,7 +1737,7 @@ bool ISource::SetSamplingRate(TContext& ctx, TNodePtr samplingRate) {
}
TNodePtr ISource::BuildAggregation(const TString& label) {
- if (GroupKeys.empty() && Aggregations.empty() && !IsCompositeSource()) {
+ if (GroupKeys.empty() && Aggregations.empty() && !IsCompositeSource()) {
return nullptr;
}
@@ -1764,7 +1764,7 @@ TNodePtr ISource::BuildAggregation(const TString& label) {
const auto listType = Y("TypeOf", label);
auto aggrArgs = Y();
for (const auto& aggr: Aggregations) {
- if (const auto traits = aggr->AggregationTraits(listType))
+ if (const auto traits = aggr->AggregationTraits(listType))
aggrArgs = L(aggrArgs, traits);
}
@@ -1798,14 +1798,14 @@ TNodePtr ISource::BuildAggregation(const TString& label) {
}
TMaybe<TString> ISource::FindColumnMistype(const TString& name) const {
- auto result = FindMistypeIn(GroupKeys, name);
- return result ? result : FindMistypeIn(ExprAliases, name);
-}
-
-void ISource::AddDependentSource(ISource* usedSource) {
- UsedSources.push_back(usedSource);
-}
-
+ auto result = FindMistypeIn(GroupKeys, name);
+ return result ? result : FindMistypeIn(ExprAliases, name);
+}
+
+void ISource::AddDependentSource(ISource* usedSource) {
+ UsedSources.push_back(usedSource);
+}
+
class TYqlFrameBound final: public TCallNode {
public:
TYqlFrameBound(TPosition pos, TNodePtr bound)
@@ -1904,27 +1904,27 @@ private:
TNodePtr ISource::BuildCalcOverWindow(TContext& ctx, const TString& label) {
YQL_ENSURE(IsCalcOverWindow());
-
+
TSet<TString> usedWindows;
for (auto& it : AggregationOverWindow) {
usedWindows.insert(it.first);
- }
+ }
for (auto& it : FuncOverWindow) {
usedWindows.insert(it.first);
- }
+ }
for (auto& it : WinSpecs) {
if (it.second->Session) {
usedWindows.insert(it.first);
}
}
-
+
YQL_ENSURE(!usedWindows.empty());
const bool onePartition = usedWindows.size() == 1;
- const auto useLabel = onePartition ? label : "partitioning";
- const auto listType = Y("TypeOf", useLabel);
- auto framesProcess = Y();
- auto resultNode = onePartition ? Y() : Y(Y("let", "partitioning", label));
+ const auto useLabel = onePartition ? label : "partitioning";
+ const auto listType = Y("TypeOf", useLabel);
+ auto framesProcess = Y();
+ auto resultNode = onePartition ? Y() : Y(Y("let", "partitioning", label));
for (const auto& name : usedWindows) {
auto spec = FindWindowSpecification(ctx, name);
@@ -1948,12 +1948,12 @@ TNodePtr ISource::BuildCalcOverWindow(TContext& ctx, const TString& label) {
}
frames = L(frames, callOnFrame);
- auto keysTuple = Y();
+ auto keysTuple = Y();
for (const auto& key: spec->Partitions) {
if (!dynamic_cast<TSessionWindow*>(key.Get())) {
keysTuple = L(keysTuple, AliasOrColumn(key, GetJoin()));
}
- }
+ }
auto sortSpec = spec->OrderBy.empty() ? Y("Void") : BuildSortSpec(spec->OrderBy, useLabel, true, false);
if (spec->Session) {
@@ -1970,23 +1970,23 @@ TNodePtr ISource::BuildCalcOverWindow(TContext& ctx, const TString& label) {
framesProcess = Y("CalcOverWindow", useLabel, Q(keysTuple), sortSpec, Q(frames));
}
- if (!onePartition) {
- resultNode = L(resultNode, Y("let", "partitioning", framesProcess));
- }
- }
- if (onePartition) {
- return framesProcess;
- } else {
- return Y("block", Q(L(resultNode, Y("return", "partitioning"))));
- }
-}
-
+ if (!onePartition) {
+ resultNode = L(resultNode, Y("let", "partitioning", framesProcess));
+ }
+ }
+ if (onePartition) {
+ return framesProcess;
+ } else {
+ return Y("block", Q(L(resultNode, Y("return", "partitioning"))));
+ }
+}
+
TNodePtr ISource::BuildSort(TContext& ctx, const TString& label) {
Y_UNUSED(ctx);
Y_UNUSED(label);
- return nullptr;
-}
-
+ return nullptr;
+}
+
TNodePtr ISource::BuildCleanupColumns(TContext& ctx, const TString& label) {
Y_UNUSED(ctx);
Y_UNUSED(label);
@@ -1997,47 +1997,47 @@ IJoin* ISource::GetJoin() {
return nullptr;
}
-ISource* ISource::GetCompositeSource() {
- return nullptr;
-}
-
-bool ISource::IsSelect() const {
- return true;
-}
-
+ISource* ISource::GetCompositeSource() {
+ return nullptr;
+}
+
+bool ISource::IsSelect() const {
+ return true;
+}
+
bool ISource::IsTableSource() const {
return false;
}
bool ISource::ShouldUseSourceAsColumn(const TString& source) const {
- Y_UNUSED(source);
- return false;
-}
-
-bool ISource::IsJoinKeysInitializing() const {
- return false;
-}
-
+ Y_UNUSED(source);
+ return false;
+}
+
+bool ISource::IsJoinKeysInitializing() const {
+ return false;
+}
+
bool ISource::DoInit(TContext& ctx, ISource* src) {
- for (auto& column: Expressions(EExprSeat::FlattenBy)) {
- if (!column->Init(ctx, this)) {
- return false;
- }
- }
+ for (auto& column: Expressions(EExprSeat::FlattenBy)) {
+ if (!column->Init(ctx, this)) {
+ return false;
+ }
+ }
if (IsFlattenColumns() && src) {
src->AllColumns();
}
- return true;
-}
-
-bool ISource::InitFilters(TContext& ctx) {
+ return true;
+}
+
+bool ISource::InitFilters(TContext& ctx) {
for (auto& filter: Filters) {
if (!filter->Init(ctx, this)) {
return false;
}
- if (filter->IsAggregated() && !filter->IsConstant() && !filter->HasState(ENodeState::AggregationKey)) {
+ if (filter->IsAggregated() && !filter->IsConstant() && !filter->HasState(ENodeState::AggregationKey)) {
ctx.Error(filter->GetPos()) << "Can not use aggregated values in filtering";
return false;
}
@@ -2052,43 +2052,43 @@ TAstNode* ISource::Translate(TContext& ctx) const {
}
void ISource::FillSortParts(const TVector<TSortSpecificationPtr>& orderBy, TNodePtr& sortDirection, TNodePtr& sortKeySelector) {
- TNodePtr expr;
- if (orderBy.empty()) {
- YQL_ENSURE(!sortKeySelector);
- sortDirection = sortKeySelector = Y("Void");
- return;
- } else if (orderBy.size() == 1) {
- auto& sortSpec = orderBy.front();
+ TNodePtr expr;
+ if (orderBy.empty()) {
+ YQL_ENSURE(!sortKeySelector);
+ sortDirection = sortKeySelector = Y("Void");
+ return;
+ } else if (orderBy.size() == 1) {
+ auto& sortSpec = orderBy.front();
expr = Y("PersistableRepr", sortSpec->OrderExpr);
- sortDirection = Y("Bool", Q(sortSpec->Ascending ? "true" : "false"));
- } else {
- auto exprList = Y();
- sortDirection = Y();
- for (const auto& sortSpec: orderBy) {
- const auto asc = sortSpec->Ascending;
- sortDirection = L(sortDirection, Y("Bool", Q(asc ? "true" : "false")));
+ sortDirection = Y("Bool", Q(sortSpec->Ascending ? "true" : "false"));
+ } else {
+ auto exprList = Y();
+ sortDirection = Y();
+ for (const auto& sortSpec: orderBy) {
+ const auto asc = sortSpec->Ascending;
+ sortDirection = L(sortDirection, Y("Bool", Q(asc ? "true" : "false")));
exprList = L(exprList, Y("PersistableRepr", sortSpec->OrderExpr));
- }
- sortDirection = Q(sortDirection);
- expr = Q(exprList);
+ }
+ sortDirection = Q(sortDirection);
+ expr = Q(exprList);
}
- sortKeySelector = BuildLambda(Pos, Y("row"), expr);
+ sortKeySelector = BuildLambda(Pos, Y("row"), expr);
}
TNodePtr ISource::BuildSortSpec(const TVector<TSortSpecificationPtr>& orderBy, const TString& label, bool traits, bool assume) {
- YQL_ENSURE(!orderBy.empty());
- TNodePtr dirsNode;
+ YQL_ENSURE(!orderBy.empty());
+ TNodePtr dirsNode;
TNodePtr keySelectorNode;
- FillSortParts(orderBy, dirsNode, keySelectorNode);
- if (traits) {
- return Y("SortTraits", Y("TypeOf", label), dirsNode, keySelectorNode);
+ FillSortParts(orderBy, dirsNode, keySelectorNode);
+ if (traits) {
+ return Y("SortTraits", Y("TypeOf", label), dirsNode, keySelectorNode);
} else if (assume) {
return Y("AssumeSorted", label, dirsNode, keySelectorNode);
- } else {
- return Y("Sort", label, dirsNode, keySelectorNode);
- }
-}
-
+ } else {
+ return Y("Sort", label, dirsNode, keySelectorNode);
+ }
+}
+
IJoin::IJoin(TPosition pos)
: ISource(pos)
{
@@ -2228,24 +2228,24 @@ TTtlSettings::TTtlSettings(const TIdentifier& columnName, const TNodePtr& expr)
{
}
-TString IdContent(TContext& ctx, const TString& s) {
- YQL_ENSURE(!s.empty(), "Empty identifier not expected");
+TString IdContent(TContext& ctx, const TString& s) {
+ YQL_ENSURE(!s.empty(), "Empty identifier not expected");
if (!s.StartsWith('`')) {
- return s;
+ return s;
}
auto endSym = '`';
- if (s.size() < 2 || !s.EndsWith(endSym)) {
- ctx.Error() << "The identifier that starts with: '" << s[0] << "' should ends with: '" << endSym << "'";
- return {};
- }
- size_t skipSymbols = 1;
-
+ if (s.size() < 2 || !s.EndsWith(endSym)) {
+ ctx.Error() << "The identifier that starts with: '" << s[0] << "' should ends with: '" << endSym << "'";
+ return {};
+ }
+ size_t skipSymbols = 1;
+
TStringBuf atom(s.data() + skipSymbols, s.size() - 2 * skipSymbols + 1);
- TString unescapedStr;
- TStringOutput sout(unescapedStr);
- unescapedStr.reserve(s.size());
-
- size_t readBytes = 0;
+ TString unescapedStr;
+ TStringOutput sout(unescapedStr);
+ unescapedStr.reserve(s.size());
+
+ size_t readBytes = 0;
TPosition pos = ctx.Pos();
pos.Column += skipSymbols - 1;
@@ -2254,15 +2254,15 @@ TString IdContent(TContext& ctx, const TString& s) {
TTextWalker walker(pos);
walker.Advance(atom.Trunc(readBytes));
ctx.Error(pos) << "Cannot parse broken identifier: " << UnescapeResultToString(unescapeResult);
- return {};
- }
+ return {};
+ }
if (readBytes != atom.size()) {
- ctx.Error() << "The identifier not parsed completely";
- return {};
- }
-
- return unescapedStr;
+ ctx.Error() << "The identifier not parsed completely";
+ return {};
+ }
+
+ return unescapedStr;
}
TString IdContentFromString(TContext& ctx, const TString& str) {
@@ -2306,32 +2306,32 @@ public:
}
TLiteralNode::TLiteralNode(TPosition pos, bool isNull)
- : TAstListNode(pos)
+ : TAstListNode(pos)
, Null(isNull)
, Void(!isNull)
-{
+{
Add(isNull ? "Null" : "Void");
-}
+}
TLiteralNode::TLiteralNode(TPosition pos, const TString& type, const TString& value)
- : TAstListNode(pos)
- , Null(false)
+ : TAstListNode(pos)
+ , Null(false)
, Void(false)
- , Type(type)
- , Value(value)
-{
- Add(Type, BuildQuotedAtom(Pos, Value));
-}
+ , Type(type)
+ , Value(value)
+{
+ Add(Type, BuildQuotedAtom(Pos, Value));
+}
TLiteralNode::TLiteralNode(TPosition pos, const TString& value, ui32 nodeFlags)
- : TAstListNode(pos)
- , Null(false)
+ : TAstListNode(pos)
+ , Null(false)
, Void(false)
- , Type("String")
+ , Type("String")
, Value(value)
-{
+{
Add(Type, BuildQuotedAtom(pos, Value, nodeFlags));
-}
+}
TLiteralNode::TLiteralNode(TPosition pos, const TString& value, ui32 nodeFlags, const TString& type)
: TAstListNode(pos)
@@ -2343,13 +2343,13 @@ TLiteralNode::TLiteralNode(TPosition pos, const TString& value, ui32 nodeFlags,
Add(Type, BuildQuotedAtom(pos, Value, nodeFlags));
}
-bool TLiteralNode::IsNull() const {
- return Null;
-}
+bool TLiteralNode::IsNull() const {
+ return Null;
+}
const TString* TLiteralNode::GetLiteral(const TString& type) const {
- return type == Type ? &Value : nullptr;
-}
+ return type == Type ? &Value : nullptr;
+}
bool TLiteralNode::IsLiteral() const {
return true;
@@ -2363,43 +2363,43 @@ TString TLiteralNode::GetLiteralValue() const {
return Value;
}
-void TLiteralNode::DoUpdateState() const {
- State.Set(ENodeState::Const);
-}
-
-TNodePtr TLiteralNode::DoClone() const {
+void TLiteralNode::DoUpdateState() const {
+ State.Set(ENodeState::Const);
+}
+
+TNodePtr TLiteralNode::DoClone() const {
auto res = (Null || Void) ? MakeIntrusive<TLiteralNode>(Pos, Null) : MakeIntrusive<TLiteralNode>(Pos, Type, Value);
- res->Nodes = Nodes;
- return res;
-}
-
-template<typename T>
+ res->Nodes = Nodes;
+ return res;
+}
+
+template<typename T>
TLiteralNumberNode<T>::TLiteralNumberNode(TPosition pos, const TString& type, const TString& value, bool implicitType)
- : TLiteralNode(pos, type, value)
+ : TLiteralNode(pos, type, value)
, ImplicitType(implicitType)
-{}
+{}
-template<typename T>
-TNodePtr TLiteralNumberNode<T>::DoClone() const {
+template<typename T>
+TNodePtr TLiteralNumberNode<T>::DoClone() const {
return new TLiteralNumberNode<T>(Pos, Type, Value, ImplicitType);
-}
+}
-template<typename T>
-bool TLiteralNumberNode<T>::DoInit(TContext& ctx, ISource* src) {
+template<typename T>
+bool TLiteralNumberNode<T>::DoInit(TContext& ctx, ISource* src) {
Y_UNUSED(src);
- T val;
- if (!TryFromString(Value, val)) {
+ T val;
+ if (!TryFromString(Value, val)) {
ctx.Error(Pos) << "Failed to parse " << Value << " as integer literal of " << Type << " type: value out of range for " << Type;
- return false;
+ return false;
}
- return true;
-}
+ return true;
+}
+
+template<typename T>
+bool TLiteralNumberNode<T>::IsIntegerLiteral() const {
+ return std::numeric_limits<T>::is_integer;
+}
-template<typename T>
-bool TLiteralNumberNode<T>::IsIntegerLiteral() const {
- return std::numeric_limits<T>::is_integer;
-}
-
template<typename T>
TNodePtr TLiteralNumberNode<T>::ApplyUnaryOp(TContext& ctx, TPosition pos, const TString& opName) const {
YQL_ENSURE(!Value.empty());
@@ -2432,13 +2432,13 @@ TNodePtr TLiteralNumberNode<T>::ApplyUnaryOp(TContext& ctx, TPosition pos, const
}
-template class TLiteralNumberNode<i32>;
-template class TLiteralNumberNode<i64>;
-template class TLiteralNumberNode<ui32>;
-template class TLiteralNumberNode<ui64>;
-template class TLiteralNumberNode<float>;
-template class TLiteralNumberNode<double>;
-template class TLiteralNumberNode<ui8>;
+template class TLiteralNumberNode<i32>;
+template class TLiteralNumberNode<i64>;
+template class TLiteralNumberNode<ui32>;
+template class TLiteralNumberNode<ui64>;
+template class TLiteralNumberNode<float>;
+template class TLiteralNumberNode<double>;
+template class TLiteralNumberNode<ui8>;
template class TLiteralNumberNode<i8>;
template class TLiteralNumberNode<ui16>;
template class TLiteralNumberNode<i16>;
@@ -2484,8 +2484,8 @@ TMaybe<TExprOrIdent> BuildLiteralTypedSmartStringOrId(TContext& ctx, const TStri
TNodePtr BuildLiteralRawString(TPosition pos, const TString& value, bool isUtf8) {
return new TLiteralNode(pos, isUtf8 ? "Utf8" : "String", value);
-}
-
+}
+
TNodePtr BuildLiteralBool(TPosition pos, bool value) {
return new TLiteralNode(pos, "Bool", value ? "true" : "false");
}
@@ -2557,42 +2557,42 @@ bool TDeferredAtom::Empty() const {
}
TTupleNode::TTupleNode(TPosition pos, const TVector<TNodePtr>& exprs)
- : TAstListNode(pos)
- , Exprs(exprs)
-{}
-
-bool TTupleNode::IsEmpty() const {
- return Exprs.empty();
-}
-
+ : TAstListNode(pos)
+ , Exprs(exprs)
+{}
+
+bool TTupleNode::IsEmpty() const {
+ return Exprs.empty();
+}
+
const TVector<TNodePtr>& TTupleNode::Elements() const {
- return Exprs;
-}
-
-bool TTupleNode::DoInit(TContext& ctx, ISource* src) {
- auto node(Y());
- for (auto& expr: Exprs) {
+ return Exprs;
+}
+
+bool TTupleNode::DoInit(TContext& ctx, ISource* src) {
+ auto node(Y());
+ for (auto& expr: Exprs) {
if (expr->GetLabel()) {
ctx.Error(expr->GetPos()) << "Tuple does not allow named members";
return false;
}
- node = L(node, expr);
+ node = L(node, expr);
}
- Add("quote", node);
- return TAstListNode::DoInit(ctx, src);
-}
+ Add("quote", node);
+ return TAstListNode::DoInit(ctx, src);
+}
-size_t TTupleNode::GetTupleSize() const {
- return Exprs.size();
-}
+size_t TTupleNode::GetTupleSize() const {
+ return Exprs.size();
+}
-TNodePtr TTupleNode::GetTupleElement(size_t index) const {
- return Exprs[index];
-}
+TNodePtr TTupleNode::GetTupleElement(size_t index) const {
+ return Exprs[index];
+}
-TNodePtr TTupleNode::DoClone() const {
- return new TTupleNode(Pos, CloneContainer(Exprs));
-}
+TNodePtr TTupleNode::DoClone() const {
+ return new TTupleNode(Pos, CloneContainer(Exprs));
+}
void TTupleNode::CollectPreaggregateExprs(TContext& ctx, ISource& src, TVector<INode::TPtr>& exprs) {
for (auto& expr : Exprs) {
@@ -2609,18 +2609,18 @@ TNodePtr BuildTuple(TPosition pos, const TVector<TNodePtr>& exprs) {
}
TStructNode::TStructNode(TPosition pos, const TVector<TNodePtr>& exprs, const TVector<TNodePtr>& labels, bool ordered)
- : TAstListNode(pos)
- , Exprs(exprs)
+ : TAstListNode(pos)
+ , Exprs(exprs)
, Labels(labels)
, Ordered(ordered)
{
YQL_ENSURE(Labels.empty() || Labels.size() == Exprs.size());
}
-
-bool TStructNode::DoInit(TContext& ctx, ISource* src) {
+
+bool TStructNode::DoInit(TContext& ctx, ISource* src) {
Nodes.push_back(BuildAtom(Pos, (Ordered || Exprs.size() < 2) ? "AsStruct" : "AsStructUnordered", TNodeFlags::Default));
size_t i = 0;
- for (const auto& expr : Exprs) {
+ for (const auto& expr : Exprs) {
TNodePtr label;
if (Labels.empty()) {
if (!expr->GetLabel()) {
@@ -2633,12 +2633,12 @@ bool TStructNode::DoInit(TContext& ctx, ISource* src) {
}
Nodes.push_back(Q(Y(label, expr)));
}
- return TAstListNode::DoInit(ctx, src);
-}
-
-TNodePtr TStructNode::DoClone() const {
+ return TAstListNode::DoInit(ctx, src);
+}
+
+TNodePtr TStructNode::DoClone() const {
return new TStructNode(Pos, CloneContainer(Exprs), CloneContainer(Labels), Ordered);
-}
+}
void TStructNode::CollectPreaggregateExprs(TContext& ctx, ISource& src, TVector<INode::TPtr>& exprs) {
for (auto& expr : Exprs) {
@@ -2666,24 +2666,24 @@ TNodePtr BuildOrderedStructure(TPosition pos, const TVector<TNodePtr>& exprsUnla
}
TListOfNamedNodes::TListOfNamedNodes(TPosition pos, TVector<TNodePtr>&& exprs)
- : INode(pos)
- , Exprs(std::move(exprs))
-{}
-
+ : INode(pos)
+ , Exprs(std::move(exprs))
+{}
+
TVector<TNodePtr>* TListOfNamedNodes::ContentListPtr() {
- return &Exprs;
-}
-
-TAstNode* TListOfNamedNodes::Translate(TContext& ctx) const {
- YQL_ENSURE(!"Unexpected usage");
- Y_UNUSED(ctx);
- return nullptr;
-}
-
-TNodePtr TListOfNamedNodes::DoClone() const {
- return {};
-}
-
+ return &Exprs;
+}
+
+TAstNode* TListOfNamedNodes::Translate(TContext& ctx) const {
+ YQL_ENSURE(!"Unexpected usage");
+ Y_UNUSED(ctx);
+ return nullptr;
+}
+
+TNodePtr TListOfNamedNodes::DoClone() const {
+ return {};
+}
+
void TListOfNamedNodes::DoVisitChildren(const TVisitFunc& func, TVisitNodeSet& visited) const {
for (auto& expr : Exprs) {
expr->VisitTree(func, visited);
@@ -2691,9 +2691,9 @@ void TListOfNamedNodes::DoVisitChildren(const TVisitFunc& func, TVisitNodeSet& v
}
TNodePtr BuildListOfNamedNodes(TPosition pos, TVector<TNodePtr>&& exprs) {
- return new TListOfNamedNodes(pos, std::move(exprs));
-}
-
+ return new TListOfNamedNodes(pos, std::move(exprs));
+}
+
TArgPlaceholderNode::TArgPlaceholderNode(TPosition pos, const TString &name) :
INode(pos),
Name(name)
@@ -2715,10 +2715,10 @@ TString TArgPlaceholderNode::GetName() const {
return Name;
}
-TNodePtr TArgPlaceholderNode::DoClone() const {
- return {};
-}
-
+TNodePtr TArgPlaceholderNode::DoClone() const {
+ return {};
+}
+
TNodePtr BuildArgPlaceholder(TPosition pos, const TString& name) {
return new TArgPlaceholderNode(pos, name);
}
@@ -2778,16 +2778,16 @@ public:
return Ids[0].Expr->GetSourceName();
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
auto expr = Ids[0].Expr;
const TPosition pos(expr->GetPos());
if (expr->IsAsterisk()) {
ctx.Error(pos) << "Asterisk column does not allow any access";
return false;
}
- if (!expr->Init(ctx, src)) {
- return false;
- }
+ if (!expr->Init(ctx, src)) {
+ return false;
+ }
for (auto& id: Ids) {
if (id.Expr && !id.Expr->Init(ctx, src)) {
return false;
@@ -2796,8 +2796,8 @@ public:
ui32 idx = 1;
auto column = dynamic_cast<TColumnNode*>(expr.Get());
if (column) {
- const bool useSourceAsColumn = column->IsUseSourceAsColumn();
- ColumnOnly &= !useSourceAsColumn;
+ const bool useSourceAsColumn = column->IsUseSourceAsColumn();
+ ColumnOnly &= !useSourceAsColumn;
if (IsColumnRequired && !ColumnOnly) {
ctx.Error(pos) << "Please use a full form (corellation.struct.field) or an alias (struct.field as alias) to access struct's field in the GROUP BY";
return false;
@@ -2809,21 +2809,21 @@ public:
}
++idx;
}
- if (!useSourceAsColumn) {
+ if (!useSourceAsColumn) {
if (!IsLookup && !CheckColumnId(pos, ctx, Ids[idx], ColumnOnly ? "Column" : "Member", false)) {
- return false;
- }
- ++idx;
+ return false;
+ }
+ ++idx;
}
}
for (; idx < Ids.size(); ++idx) {
const auto& id = Ids[idx];
if (!id.Name.empty()) {
expr = Y("SqlAccess", Q("struct"), expr, id.Expr ? Y("EvaluateAtom", id.Expr) : BuildQuotedAtom(Pos, id.Name));
- AccessOpName = "AccessStructMember";
+ AccessOpName = "AccessStructMember";
} else if (id.Expr) {
expr = Y("SqlAccess", Q("dict"), expr, id.Expr);
- AccessOpName = "AccessDictMember";
+ AccessOpName = "AccessDictMember";
} else {
continue;
}
@@ -2846,33 +2846,33 @@ public:
return true;
}
- TAstNode* Translate(TContext& ctx) const override {
+ TAstNode* Translate(TContext& ctx) const override {
Y_VERIFY_DEBUG(Node);
return Node->Translate(ctx);
}
- TPtr DoClone() const override {
- YQL_ENSURE(!Node, "TAccessNode::Clone: Node should not be initialized");
+ TPtr DoClone() const override {
+ YQL_ENSURE(!Node, "TAccessNode::Clone: Node should not be initialized");
TVector<TIdPart> cloneIds;
- cloneIds.reserve(Ids.size());
+ cloneIds.reserve(Ids.size());
for (const auto& id: Ids) {
- cloneIds.emplace_back(id.Clone());
- }
+ cloneIds.emplace_back(id.Clone());
+ }
auto copy = new TAccessNode(Pos, cloneIds, IsLookup);
- copy->ColumnOnly = ColumnOnly;
- return copy;
- }
-
+ copy->ColumnOnly = ColumnOnly;
+ return copy;
+ }
+
protected:
- void DoUpdateState() const override {
+ void DoUpdateState() const override {
YQL_ENSURE(Node);
State.Set(ENodeState::Const, Node->IsConstant());
State.Set(ENodeState::MaybeConst, Node->MaybeConstant());
State.Set(ENodeState::Aggregated, Node->IsAggregated());
State.Set(ENodeState::AggregationKey, Node->HasState(ENodeState::AggregationKey));
State.Set(ENodeState::OverWindow, Node->IsOverWindow());
- }
-
+ }
+
void DoVisitChildren(const TVisitFunc& func, TVisitNodeSet& visited) const final {
Y_VERIFY_DEBUG(Node);
Node->VisitTree(func, visited);
@@ -2890,10 +2890,10 @@ protected:
return true;
}
- TString GetOpName() const override {
- return AccessOpName;
- }
-
+ TString GetOpName() const override {
+ return AccessOpName;
+ }
+
void CollectPreaggregateExprs(TContext& ctx, ISource& src, TVector<INode::TPtr>& exprs) override {
for (auto& id : Ids) {
if (id.Expr) {
@@ -2908,7 +2908,7 @@ private:
bool IsLookup;
bool ColumnOnly;
bool IsColumnRequired;
- TString AccessOpName;
+ TString AccessOpName;
};
TNodePtr BuildAccess(TPosition pos, const TVector<INode::TIdPart>& ids, bool isLookup) {
@@ -3054,10 +3054,10 @@ public:
{
Add("bind", AstNode(module), BuildQuotedAtom(pos, alias));
}
-
- TPtr DoClone() const final {
+
+ TPtr DoClone() const final {
return {};
- }
+ }
};
TNodePtr BuildBind(TPosition pos, const TString& module, const TString& alias) {
@@ -3076,7 +3076,7 @@ public:
}
protected:
- TPtr DoClone() const final {
+ TPtr DoClone() const final {
return {};
}
@@ -3125,8 +3125,8 @@ TString TypeByAlias(const TString& alias, bool normalize) {
} else if (typeAlias == "smallint") {
type = "Int16";
} else if (typeAlias == "int" || typeAlias == "integer") {
- type = "Int32";
- } else if (typeAlias == "bigint") {
+ type = "Int32";
+ } else if (typeAlias == "bigint") {
type = "Int64";
}
return normalize ? NormalizeTypeString(type) : type;
@@ -3139,16 +3139,16 @@ TNodePtr BuildIsNullOp(TPosition pos, TNodePtr a) {
if (a->IsNull()) {
return BuildLiteralBool(pos, true);
}
- return new TCallNodeImpl(pos, "Not", {new TCallNodeImpl(pos, "Exists", {a})});
+ return new TCallNodeImpl(pos, "Not", {new TCallNodeImpl(pos, "Exists", {a})});
}
-class TBinaryOpNode final: public TCallNode {
+class TBinaryOpNode final: public TCallNode {
public:
TBinaryOpNode(TPosition pos, const TString& opName, TNodePtr a, TNodePtr b);
- TNodePtr DoClone() const final {
- YQL_ENSURE(Args.size() == 2);
- return new TBinaryOpNode(Pos, OpName, Args[0]->Clone(), Args[1]->Clone());
+ TNodePtr DoClone() const final {
+ YQL_ENSURE(Args.size() == 2);
+ return new TBinaryOpNode(Pos, OpName, Args[0]->Clone(), Args[1]->Clone());
}
};
@@ -3175,51 +3175,51 @@ TNodePtr BuildBinaryOp(TContext& ctx, TPosition pos, const TString& opName, TNod
return new TBinaryOpNode(pos, opName, a, b);
}
-class TCalcOverWindow final: public INode {
-public:
+class TCalcOverWindow final: public INode {
+public:
TCalcOverWindow(TPosition pos, const TString& windowName, TNodePtr node)
- : INode(pos)
- , WindowName(windowName)
- , FuncNode(node)
- {}
-
- TAstNode* Translate(TContext& ctx) const override {
- return FuncNode->Translate(ctx);
- }
-
- bool DoInit(TContext& ctx, ISource* src) override {
- YQL_ENSURE(src);
- TSourcePtr overWindowSource = BuildOverWindowSource(ctx.Pos(), WindowName, src);
- if (!FuncNode->Init(ctx, overWindowSource.Get())) {
- return false;
- }
- return true;
- }
-
- TPtr DoClone() const final {
- return new TCalcOverWindow(Pos, WindowName, SafeClone(FuncNode));
- }
-
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, FuncNode->IsConstant());
+ : INode(pos)
+ , WindowName(windowName)
+ , FuncNode(node)
+ {}
+
+ TAstNode* Translate(TContext& ctx) const override {
+ return FuncNode->Translate(ctx);
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ YQL_ENSURE(src);
+ TSourcePtr overWindowSource = BuildOverWindowSource(ctx.Pos(), WindowName, src);
+ if (!FuncNode->Init(ctx, overWindowSource.Get())) {
+ return false;
+ }
+ return true;
+ }
+
+ TPtr DoClone() const final {
+ return new TCalcOverWindow(Pos, WindowName, SafeClone(FuncNode));
+ }
+
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, FuncNode->IsConstant());
State.Set(ENodeState::MaybeConst, FuncNode->MaybeConstant());
- State.Set(ENodeState::Aggregated, FuncNode->IsAggregated());
- State.Set(ENodeState::OverWindow, true);
- }
+ State.Set(ENodeState::Aggregated, FuncNode->IsAggregated());
+ State.Set(ENodeState::OverWindow, true);
+ }
void DoVisitChildren(const TVisitFunc& func, TVisitNodeSet& visited) const final {
Y_VERIFY_DEBUG(FuncNode);
FuncNode->VisitTree(func, visited);
}
-protected:
+protected:
const TString WindowName;
- TNodePtr FuncNode;
-};
-
+ TNodePtr FuncNode;
+};
+
TNodePtr BuildCalcOverWindow(TPosition pos, const TString& windowName, TNodePtr call) {
- return new TCalcOverWindow(pos, windowName, call);
-}
-
+ return new TCalcOverWindow(pos, windowName, call);
+}
+
template<bool Fast>
class TYsonOptionsNode final: public INode {
public:
@@ -3323,10 +3323,10 @@ bool Parseui32(TNodePtr from, ui32& to) {
return TryFromString(*val, to);
}
-TNodePtr GroundWithExpr(const TNodePtr& ground, const TNodePtr& expr) {
- return ground ? expr->Y("block", expr->Q(expr->L(ground, expr->Y("return", expr)))) : expr;
-}
-
+TNodePtr GroundWithExpr(const TNodePtr& ground, const TNodePtr& expr) {
+ return ground ? expr->Y("block", expr->Q(expr->L(ground, expr->Y("return", expr)))) : expr;
+}
+
TSourcePtr TryMakeSourceFromExpression(TContext& ctx, const TString& currService, const TDeferredAtom& currCluster,
TNodePtr node, const TString& view) {
if (currCluster.Empty()) {
diff --git a/ydb/library/yql/sql/v1/node.h b/ydb/library/yql/sql/v1/node.h
index 2c4341487b..de82b45a23 100644
--- a/ydb/library/yql/sql/v1/node.h
+++ b/ydb/library/yql/sql/v1/node.h
@@ -9,65 +9,65 @@
#include <util/generic/vector.h>
#include <util/generic/set.h>
#include <util/generic/map.h>
-#include <util/generic/hash.h>
-#include <util/generic/hash_set.h>
-#include <util/generic/maybe.h>
-#include <util/string/builder.h>
+#include <util/generic/hash.h>
+#include <util/generic/hash_set.h>
+#include <util/generic/maybe.h>
+#include <util/string/builder.h>
#include <library/cpp/enumbitset/enumbitset.h>
-
+
#include <array>
#include <functional>
#include <variant>
namespace NSQLTranslationV1 {
- constexpr const size_t SQL_MAX_INLINE_SCRIPT_LEN = 24;
-
+ constexpr const size_t SQL_MAX_INLINE_SCRIPT_LEN = 24;
+
using NYql::TPosition;
using NYql::TAstNode;
- enum class ENodeState {
- Begin,
- Precached = Begin,
- Initialized,
- CountHint,
- Const,
+ enum class ENodeState {
+ Begin,
+ Precached = Begin,
+ Initialized,
+ CountHint,
+ Const,
MaybeConst,
- Aggregated,
- AggregationKey,
- OverWindow,
+ Aggregated,
+ AggregationKey,
+ OverWindow,
Failed,
- End,
- };
- typedef TEnumBitSet<ENodeState, static_cast<int>(ENodeState::Begin), static_cast<int>(ENodeState::End)> TNodeState;
-
- enum class ESQLWriteColumnMode {
- InsertInto,
+ End,
+ };
+ typedef TEnumBitSet<ENodeState, static_cast<int>(ENodeState::Begin), static_cast<int>(ENodeState::End)> TNodeState;
+
+ enum class ESQLWriteColumnMode {
+ InsertInto,
InsertOrAbortInto,
InsertOrIgnoreInto,
InsertOrRevertInto,
- UpsertInto,
- ReplaceInto,
- InsertIntoWithTruncate,
- Update,
- Delete,
- };
-
- enum class EWriteColumnMode {
- Default,
+ UpsertInto,
+ ReplaceInto,
+ InsertIntoWithTruncate,
+ Update,
+ Delete,
+ };
+
+ enum class EWriteColumnMode {
+ Default,
Insert,
InsertOrAbort,
InsertOrIgnore,
InsertOrRevert,
- Upsert,
- Replace,
- Renew,
- Update,
+ Upsert,
+ Replace,
+ Renew,
+ Update,
UpdateOn,
- Delete,
+ Delete,
DeleteOn,
- };
-
+ };
+
enum class EAlterTableIntentnt {
AddColumn,
DropColumn
@@ -76,21 +76,21 @@ namespace NSQLTranslationV1 {
class TContext;
class ITableKeys;
class ISource;
- class IAggregation;
- typedef TIntrusivePtr<IAggregation> TAggregationPtr;
-
+ class IAggregation;
+ typedef TIntrusivePtr<IAggregation> TAggregationPtr;
+
struct TScopedState;
typedef TIntrusivePtr<TScopedState> TScopedStatePtr;
inline TString DotJoin(const TString& lhs, const TString& rhs) {
- TStringBuilder sb;
- sb << lhs << "." << rhs;
- return sb;
- }
-
- TString ErrorDistinctByGroupKey(const TString& column);
- TString ErrorDistinctWithoutCorrelation(const TString& column);
-
+ TStringBuilder sb;
+ sb << lhs << "." << rhs;
+ return sb;
+ }
+
+ TString ErrorDistinctByGroupKey(const TString& column);
+ TString ErrorDistinctWithoutCorrelation(const TString& column);
+
class INode: public TSimpleRefCount<INode> {
public:
typedef TIntrusivePtr<INode> TPtr;
@@ -107,11 +107,11 @@ namespace NSQLTranslationV1 {
: Expr(expr)
{
}
- TIdPart Clone() const {
- TIdPart res(Name);
- res.Expr = Expr ? Expr->Clone() : nullptr;
- return res;
- }
+ TIdPart Clone() const {
+ TIdPart res(Name);
+ res.Expr = Expr ? Expr->Clone() : nullptr;
+ return res;
+ }
};
public:
@@ -129,30 +129,30 @@ namespace NSQLTranslationV1 {
bool GetCountHint() const;
bool Init(TContext& ctx, ISource* src);
- bool IsConstant() const;
+ bool IsConstant() const;
bool MaybeConstant() const;
- bool IsAggregated() const;
+ bool IsAggregated() const;
bool IsAggregationKey() const;
- bool IsOverWindow() const;
- bool HasState(ENodeState state) const {
- PrecacheState();
- return State.Test(state);
- }
-
+ bool IsOverWindow() const;
+ bool HasState(ENodeState state) const {
+ PrecacheState();
+ return State.Test(state);
+ }
+
virtual bool IsNull() const;
virtual bool IsLiteral() const;
virtual TString GetLiteralType() const;
virtual TString GetLiteralValue() const;
- virtual bool IsIntegerLiteral() const;
+ virtual bool IsIntegerLiteral() const;
virtual TPtr ApplyUnaryOp(TContext& ctx, TPosition pos, const TString& opName) const;
virtual bool IsAsterisk() const;
- virtual const TString* SubqueryAlias() const;
+ virtual const TString* SubqueryAlias() const;
virtual TString GetOpName() const;
virtual const TString* GetLiteral(const TString& type) const;
virtual const TString* GetColumnName() const;
virtual void AssumeColumn();
virtual const TString* GetSourceName() const;
- virtual const TString* GetAtomContent() const;
+ virtual const TString* GetAtomContent() const;
virtual bool IsOptionalArg() const;
virtual size_t GetTupleSize() const;
virtual TPtr GetTupleElement(size_t index) const;
@@ -160,12 +160,12 @@ namespace NSQLTranslationV1 {
virtual ISource* GetSource();
virtual TVector<INode::TPtr>* ContentListPtr();
virtual TAstNode* Translate(TContext& ctx) const = 0;
- virtual TAggregationPtr GetAggregation() const;
+ virtual TAggregationPtr GetAggregation() const;
virtual void CollectPreaggregateExprs(TContext& ctx, ISource& src, TVector<INode::TPtr>& exprs);
- virtual TPtr WindowSpecFunc(const TPtr& type) const;
+ virtual TPtr WindowSpecFunc(const TPtr& type) const;
virtual bool SetViewName(TContext& ctx, TPosition pos, const TString& view);
void UseAsInner();
- virtual bool UsedSubquery() const;
+ virtual bool UsedSubquery() const;
virtual bool IsSelect() const;
virtual const TString* FuncName() const;
virtual const TString* ModuleName() const;
@@ -214,12 +214,12 @@ namespace NSQLTranslationV1 {
return copy;
}
- TPtr Clone() const;
+ TPtr Clone() const;
protected:
virtual TPtr ShallowCopy() const;
- virtual void DoUpdateState() const;
- virtual TPtr DoClone() const = 0;
- void PrecacheState() const;
+ virtual void DoUpdateState() const;
+ virtual TPtr DoClone() const = 0;
+ void PrecacheState() const;
virtual void DoVisitChildren(const TVisitFunc& func, TVisitNodeSet& visited) const;
private:
@@ -231,7 +231,7 @@ namespace NSQLTranslationV1 {
TString Label;
TMaybe<TPosition> LabelPos;
bool ImplicitLabel = false;
- mutable TNodeState State;
+ mutable TNodeState State;
bool AsInner = false;
};
typedef INode::TPtr TNodePtr;
@@ -239,63 +239,63 @@ namespace NSQLTranslationV1 {
using TTableHints = TMap<TString, TVector<TNodePtr>>;
void MergeHints(TTableHints& base, const TTableHints& overrides);
- template<class T>
- inline T SafeClone(const T& node) {
- return node ? node->Clone() : nullptr;
- }
-
- template<class T>
+ template<class T>
+ inline T SafeClone(const T& node) {
+ return node ? node->Clone() : nullptr;
+ }
+
+ template<class T>
inline TVector<T> CloneContainer(const TVector<T>& args) {
TVector<T> cloneArgs;
- cloneArgs.reserve(args.size());
- for (const auto& arg: args) {
- cloneArgs.emplace_back(SafeClone(arg));
- }
- return cloneArgs;
- }
-
+ cloneArgs.reserve(args.size());
+ for (const auto& arg: args) {
+ cloneArgs.emplace_back(SafeClone(arg));
+ }
+ return cloneArgs;
+ }
+
class TAstAtomNode: public INode {
public:
TAstAtomNode(TPosition pos, const TString& content, ui32 flags, bool isOptionalArg);
- ~TAstAtomNode() override;
+ ~TAstAtomNode() override;
- TAstNode* Translate(TContext& ctx) const override;
+ TAstNode* Translate(TContext& ctx) const override;
const TString& GetContent() const {
return Content;
}
- const TString* GetAtomContent() const override;
+ const TString* GetAtomContent() const override;
bool IsOptionalArg() const override;
-
+
protected:
TString Content;
ui32 Flags;
bool IsOptionalArg_;
-
- void DoUpdateState() const override;
+
+ void DoUpdateState() const override;
};
- class TAstAtomNodeImpl final: public TAstAtomNode {
+ class TAstAtomNodeImpl final: public TAstAtomNode {
public:
TAstAtomNodeImpl(TPosition pos, const TString& content, ui32 flags, bool isOptionalArg = false)
: TAstAtomNode(pos, content, flags, isOptionalArg)
- {}
-
- TNodePtr DoClone() const final {
+ {}
+
+ TNodePtr DoClone() const final {
return new TAstAtomNodeImpl(Pos, Content, Flags, IsOptionalArg_);
- }
- };
-
- class TAstDirectNode final: public INode {
- public:
+ }
+ };
+
+ class TAstDirectNode final: public INode {
+ public:
TAstDirectNode(TAstNode* node);
- TAstNode* Translate(TContext& ctx) const override;
+ TAstNode* Translate(TContext& ctx) const override;
- TPtr DoClone() const final {
+ TPtr DoClone() const final {
return new TAstDirectNode(Node);
- }
+ }
protected:
TAstNode* Node;
};
@@ -310,30 +310,30 @@ namespace NSQLTranslationV1 {
protected:
explicit TAstListNode(const TAstListNode& node);
explicit TAstListNode(TPosition pos, TVector<TNodePtr>&& nodes);
- TPtr ShallowCopy() const override;
- bool DoInit(TContext& ctx, ISource* src) override;
- void DoAdd(TNodePtr node) override;
+ TPtr ShallowCopy() const override;
+ bool DoInit(TContext& ctx, ISource* src) override;
+ void DoAdd(TNodePtr node) override;
void DoVisitChildren(const TVisitFunc& func, TVisitNodeSet& visited) const override;
- void DoUpdateState() const override;
-
+ void DoUpdateState() const override;
+
void UpdateStateByListNodes(const TVector<TNodePtr>& Nodes) const;
-
+
protected:
TVector<TNodePtr> Nodes;
- mutable TMaybe<bool> CacheGroupKey;
+ mutable TMaybe<bool> CacheGroupKey;
};
- class TAstListNodeImpl final: public TAstListNode {
- public:
- TAstListNodeImpl(TPosition pos);
+ class TAstListNodeImpl final: public TAstListNode {
+ public:
+ TAstListNodeImpl(TPosition pos);
TAstListNodeImpl(TPosition pos, TVector<TNodePtr> nodes);
void CollectPreaggregateExprs(TContext& ctx, ISource& src, TVector<INode::TPtr>& exprs) override;
-
- protected:
+
+ protected:
TNodePtr DoClone() const final;
- };
-
+ };
+
class TCallNode: public TAstListNode {
public:
TCallNode(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args);
@@ -347,8 +347,8 @@ namespace NSQLTranslationV1 {
const TVector<TNodePtr>& GetArgs() const;
protected:
- bool DoInit(TContext& ctx, ISource* src) override;
- bool ValidateArguments(TContext& ctx) const;
+ bool DoInit(TContext& ctx, ISource* src) override;
+ bool ValidateArguments(TContext& ctx) const;
TString GetCallExplain() const;
void CollectPreaggregateExprs(TContext& ctx, ISource& src, TVector<INode::TPtr>& exprs) override;
@@ -357,18 +357,18 @@ namespace NSQLTranslationV1 {
i32 MinArgs;
i32 MaxArgs;
TVector<TNodePtr> Args;
- mutable TMaybe<bool> CacheGroupKey;
-
- void DoUpdateState() const override;
+ mutable TMaybe<bool> CacheGroupKey;
+
+ void DoUpdateState() const override;
};
- class TCallNodeImpl final: public TCallNode {
- TPtr DoClone() const final;
- public:
+ class TCallNodeImpl final: public TCallNode {
+ TPtr DoClone() const final;
+ public:
TCallNodeImpl(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args);
TCallNodeImpl(TPosition pos, const TString& opName, const TVector<TNodePtr>& args);
- };
-
+ };
+
class TFuncNodeImpl final : public TCallNode {
TPtr DoClone() const final;
public:
@@ -388,30 +388,30 @@ namespace NSQLTranslationV1 {
const ui32 ReqArgsCount;
};
- class TCallDirectRow final : public TCallNode {
- TPtr DoClone() const final;
- public:
+ class TCallDirectRow final : public TCallNode {
+ TPtr DoClone() const final;
+ public:
TCallDirectRow(TPosition pos, const TString& opName, const TVector<TNodePtr>& args);
- protected:
- bool DoInit(TContext& ctx, ISource* src) override;
- void DoUpdateState() const override;
- };
-
- class TWinAggrEmulation: public TCallNode {
- protected:
- void DoUpdateState() const override;
- bool DoInit(TContext& ctx, ISource* src) override;
+ protected:
+ bool DoInit(TContext& ctx, ISource* src) override;
+ void DoUpdateState() const override;
+ };
+
+ class TWinAggrEmulation: public TCallNode {
+ protected:
+ void DoUpdateState() const override;
+ bool DoInit(TContext& ctx, ISource* src) override;
TPtr WindowSpecFunc(const TNodePtr& type) const override;
- public:
+ public:
TWinAggrEmulation(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args);
- protected:
- template<class TNodeType>
- TPtr CallNodeClone() const {
- return new TNodeType(GetPos(), OpName, MinArgs, MaxArgs, CloneContainer(Args));
- }
+ protected:
+ template<class TNodeType>
+ TPtr CallNodeClone() const {
+ return new TNodeType(GetPos(), OpName, MinArgs, MaxArgs, CloneContainer(Args));
+ }
TString FuncAlias;
- };
-
+ };
+
using TFunctionConfig = TMap<TString, TNodePtr>;
class TExternalFunctionConfig final: public TAstListNode {
@@ -429,23 +429,23 @@ namespace NSQLTranslationV1 {
TFunctionConfig Config;
};
- class TWinRowNumber final: public TWinAggrEmulation {
- TPtr DoClone() const final {
- return CallNodeClone<TWinRowNumber>();
- }
- public:
+ class TWinRowNumber final: public TWinAggrEmulation {
+ TPtr DoClone() const final {
+ return CallNodeClone<TWinRowNumber>();
+ }
+ public:
TWinRowNumber(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args);
- };
-
- class TWinLeadLag final: public TWinAggrEmulation {
- TPtr DoClone() const final {
- return CallNodeClone<TWinLeadLag>();
- }
- bool DoInit(TContext& ctx, ISource* src) override;
- public:
+ };
+
+ class TWinLeadLag final: public TWinAggrEmulation {
+ TPtr DoClone() const final {
+ return CallNodeClone<TWinLeadLag>();
+ }
+ bool DoInit(TContext& ctx, ISource* src) override;
+ public:
TWinLeadLag(TPosition pos, const TString& opName, i32 minArgs, i32 maxArgs, const TVector<TNodePtr>& args);
- };
-
+ };
+
class TWinRank final: public TWinAggrEmulation {
TPtr DoClone() const final {
return CallNodeClone<TWinRank>();
@@ -469,13 +469,13 @@ namespace NSQLTranslationV1 {
virtual TNodePtr BuildKeys(TContext& ctx, EBuildKeysMode mode) = 0;
private:
- /// all TableKeys no clonnable
- TPtr DoClone() const final {
- return {};
- }
-
- ITableKeys* GetTableKeys() override;
- TAstNode* Translate(TContext& ctx) const override;
+ /// all TableKeys no clonnable
+ TPtr DoClone() const final {
+ return {};
+ }
+
+ ITableKeys* GetTableKeys() override;
+ TAstNode* Translate(TContext& ctx) const override;
};
enum class ESampleMode {
@@ -545,35 +545,35 @@ namespace NSQLTranslationV1 {
TVector<TString> List;
TVector<bool> NamedColumns;
bool All = false;
- bool QualifiedAll = false;
- bool HasUnreliable = false;
+ bool QualifiedAll = false;
+ bool HasUnreliable = false;
bool Add(const TString* column, bool countHint, bool isArtificial = false, bool isReliable = true, bool hasName = true);
void Merge(const TColumns& columns);
void SetPrefix(const TString& prefix);
void SetAll();
- bool IsColumnPossible(TContext& ctx, const TString& column);
- };
-
- struct TSortSpecification: public TSimpleRefCount<TSortSpecification> {
- TNodePtr OrderExpr;
- bool Ascending;
- TIntrusivePtr<TSortSpecification> Clone() const;
- ~TSortSpecification() {}
- };
- typedef TIntrusivePtr<TSortSpecification> TSortSpecificationPtr;
-
- enum EFrameType {
- FrameByRows,
- FrameByRange,
+ bool IsColumnPossible(TContext& ctx, const TString& column);
+ };
+
+ struct TSortSpecification: public TSimpleRefCount<TSortSpecification> {
+ TNodePtr OrderExpr;
+ bool Ascending;
+ TIntrusivePtr<TSortSpecification> Clone() const;
+ ~TSortSpecification() {}
+ };
+ typedef TIntrusivePtr<TSortSpecification> TSortSpecificationPtr;
+
+ enum EFrameType {
+ FrameByRows,
+ FrameByRange,
FrameByGroups,
- };
- enum EFrameExclusions {
+ };
+ enum EFrameExclusions {
FrameExclNone, // same as EXCLUDE NO OTHERS
- FrameExclCurRow,
- FrameExclGroup,
- FrameExclTies,
- };
+ FrameExclCurRow,
+ FrameExclGroup,
+ FrameExclTies,
+ };
enum EFrameSettings {
// keep order
FrameUndefined,
@@ -597,22 +597,22 @@ namespace NSQLTranslationV1 {
EFrameType FrameType = FrameByRows;
TFrameBoundPtr FrameBegin;
TFrameBoundPtr FrameEnd;
- EFrameExclusions FrameExclusion = FrameExclNone;
-
+ EFrameExclusions FrameExclusion = FrameExclNone;
+
TIntrusivePtr<TFrameSpecification> Clone() const;
~TFrameSpecification() {}
- };
+ };
typedef TIntrusivePtr<TFrameSpecification> TFrameSpecificationPtr;
-
+
struct THoppingWindowSpec: public TSimpleRefCount<THoppingWindowSpec> {
TNodePtr TimeExtractor;
TNodePtr Hop;
TNodePtr Interval;
TNodePtr Delay;
bool DataWatermarks;
-
- TIntrusivePtr<THoppingWindowSpec> Clone() const;
- ~THoppingWindowSpec() {}
+
+ TIntrusivePtr<THoppingWindowSpec> Clone() const;
+ ~THoppingWindowSpec() {}
};
typedef TIntrusivePtr<THoppingWindowSpec> THoppingWindowSpecPtr;
@@ -627,9 +627,9 @@ namespace NSQLTranslationV1 {
TIntrusivePtr<TWindowSpecification> Clone() const;
~TWindowSpecification() {}
};
- typedef TIntrusivePtr<TWindowSpecification> TWindowSpecificationPtr;
+ typedef TIntrusivePtr<TWindowSpecification> TWindowSpecificationPtr;
typedef TMap<TString, TWindowSpecificationPtr> TWinSpecs;
-
+
typedef TVector<TTableRef> TTableList;
void WarnIfAliasFromSelectIsUsedInGroupBy(TContext& ctx, const TVector<TNodePtr>& selectTerms, const TVector<TNodePtr>& groupByTerms,
@@ -641,118 +641,118 @@ namespace NSQLTranslationV1 {
TDeferredAtom Label;
};
- class TColumnNode final: public INode {
+ class TColumnNode final: public INode {
public:
TColumnNode(TPosition pos, const TString& column, const TString& source, bool maybeType);
TColumnNode(TPosition pos, const TNodePtr& column, const TString& source);
-
+
virtual ~TColumnNode();
bool IsAsterisk() const override;
- virtual bool IsArtificial() const;
+ virtual bool IsArtificial() const;
const TString* GetColumnName() const override;
const TString* GetSourceName() const override;
TAstNode* Translate(TContext& ctx) const override;
void ResetColumn(const TString& column, const TString& source);
void ResetColumn(const TNodePtr& column, const TString& source);
- void SetUseSourceAsColumn();
- void SetUseSource();
- void ResetAsReliable();
- void SetAsNotReliable();
- bool IsReliable() const;
- bool IsUseSourceAsColumn() const;
+ void SetUseSourceAsColumn();
+ void SetUseSource();
+ void ResetAsReliable();
+ void SetAsNotReliable();
+ bool IsReliable() const;
+ bool IsUseSourceAsColumn() const;
bool CanBeType() const;
-
+
private:
- bool DoInit(TContext& ctx, ISource* src) override;
- TPtr DoClone() const final;
+ bool DoInit(TContext& ctx, ISource* src) override;
+ TPtr DoClone() const final;
+
+ void DoUpdateState() const override;
- void DoUpdateState() const override;
-
private:
static const TString Empty;
TNodePtr Node;
TString ColumnName;
TNodePtr ColumnExpr;
TString Source;
- bool GroupKey = false;
- bool Artificial = false;
- bool Reliable = true;
- bool UseSource = false;
- bool UseSourceAsColumn = false;
+ bool GroupKey = false;
+ bool Artificial = false;
+ bool Reliable = true;
+ bool UseSource = false;
+ bool UseSourceAsColumn = false;
bool MaybeType = false;
};
- class TArgPlaceholderNode final: public INode
+ class TArgPlaceholderNode final: public INode
{
public:
TArgPlaceholderNode(TPosition pos, const TString &name);
- TAstNode* Translate(TContext& ctx) const override;
+ TAstNode* Translate(TContext& ctx) const override;
TString GetName() const;
- TNodePtr DoClone() const final;
+ TNodePtr DoClone() const final;
protected:
- bool DoInit(TContext& ctx, ISource* src) override;
+ bool DoInit(TContext& ctx, ISource* src) override;
private:
TString Name;
};
- enum class EAggregateMode {
- Normal,
- Distinct,
- OverWindow,
- };
-
- class TTupleNode: public TAstListNode {
- public:
+ enum class EAggregateMode {
+ Normal,
+ Distinct,
+ OverWindow,
+ };
+
+ class TTupleNode: public TAstListNode {
+ public:
TTupleNode(TPosition pos, const TVector<TNodePtr>& exprs);
-
- bool IsEmpty() const;
+
+ bool IsEmpty() const;
const TVector<TNodePtr>& Elements() const;
- bool DoInit(TContext& ctx, ISource* src) override;
- size_t GetTupleSize() const override;
- TPtr GetTupleElement(size_t index) const override;
- TNodePtr DoClone() const final;
- private:
+ bool DoInit(TContext& ctx, ISource* src) override;
+ size_t GetTupleSize() const override;
+ TPtr GetTupleElement(size_t index) const override;
+ TNodePtr DoClone() const final;
+ private:
void CollectPreaggregateExprs(TContext& ctx, ISource& src, TVector<INode::TPtr>& exprs) override;
const TString* GetSourceName() const override;
const TVector<TNodePtr> Exprs;
- };
-
- class TStructNode: public TAstListNode {
- public:
+ };
+
+ class TStructNode: public TAstListNode {
+ public:
TStructNode(TPosition pos, const TVector<TNodePtr>& exprs, const TVector<TNodePtr>& labels, bool ordered);
-
- bool DoInit(TContext& ctx, ISource* src) override;
- TNodePtr DoClone() const final;
+
+ bool DoInit(TContext& ctx, ISource* src) override;
+ TNodePtr DoClone() const final;
const TVector<TNodePtr>& GetExprs() {
return Exprs;
}
- private:
+ private:
void CollectPreaggregateExprs(TContext& ctx, ISource& src, TVector<INode::TPtr>& exprs) override;
const TString* GetSourceName() const override;
const TVector<TNodePtr> Exprs;
const TVector<TNodePtr> Labels;
const bool Ordered;
- };
-
+ };
+
class IAggregation: public INode {
public:
bool IsDistinct() const;
- void DoUpdateState() const override;
-
+ void DoUpdateState() const override;
+
virtual const TString* GetGenericKey() const;
virtual bool InitAggr(TContext& ctx, bool isFactory, ISource* src, TAstListNode& node, const TVector<TNodePtr>& exprs) = 0;
- virtual TNodePtr AggregationTraits(const TNodePtr& type) const;
+ virtual TNodePtr AggregationTraits(const TNodePtr& type) const;
virtual TNodePtr AggregationTraitsFactory() const = 0;
@@ -760,8 +760,8 @@ namespace NSQLTranslationV1 {
virtual void AddFactoryArguments(TNodePtr& apply) const;
- virtual TNodePtr WindowTraits(const TNodePtr& type) const;
-
+ virtual TNodePtr WindowTraits(const TNodePtr& type) const;
+
const TString& GetName() const;
EAggregateMode GetAggregationMode() const;
@@ -778,26 +778,26 @@ namespace NSQLTranslationV1 {
TString Name;
TString Func;
- const EAggregateMode AggMode;
+ const EAggregateMode AggMode;
TString DistinctKey;
bool IsGeneratedKeyColumn = false;
};
- enum class EExprSeat: int {
- Open = 0,
+ enum class EExprSeat: int {
+ Open = 0,
FlattenByExpr,
- FlattenBy,
- GroupBy,
+ FlattenBy,
+ GroupBy,
DistinctAggr,
- WindowPartitionBy,
- Max
- };
-
- enum class EExprType: int {
- WithExpression,
- ColumnOnly,
- };
-
+ WindowPartitionBy,
+ Max
+ };
+
+ enum class EExprType: int {
+ WithExpression,
+ ColumnOnly,
+ };
+
enum class EOrderKind: int {
None,
Sort,
@@ -814,9 +814,9 @@ namespace NSQLTranslationV1 {
virtual void AllColumns();
virtual const TColumns* GetColumns() const;
virtual void GetInputTables(TTableList& tableList) const;
- /// in case of error unfilled, flag show if ensure column name
- virtual TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column);
- virtual void FinishColumns();
+ /// in case of error unfilled, flag show if ensure column name
+ virtual TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column);
+ virtual void FinishColumns();
virtual bool AddExpressions(TContext& ctx, const TVector<TNodePtr>& columns, EExprSeat exprSeat);
virtual void SetFlattenByMode(const TString& mode);
virtual void MarkFlattenColumns();
@@ -826,22 +826,22 @@ namespace NSQLTranslationV1 {
virtual void SetCompactGroupBy(bool compactGroupBy);
virtual TString MakeLocalName(const TString& name);
virtual bool AddAggregation(TContext& ctx, TAggregationPtr aggr);
- virtual bool AddFuncOverWindow(TContext& ctx, TNodePtr expr);
+ virtual bool AddFuncOverWindow(TContext& ctx, TNodePtr expr);
virtual void AddTmpWindowColumn(const TString& column);
virtual const TVector<TString>& GetTmpWindowColumns() const;
virtual bool HasAggregations() const;
- virtual void AddWindowSpecs(TWinSpecs winSpecs);
+ virtual void AddWindowSpecs(TWinSpecs winSpecs);
virtual bool AddAggregationOverWindow(TContext& ctx, const TString& windowName, TAggregationPtr func);
virtual bool AddFuncOverWindow(TContext& ctx, const TString& windowName, TNodePtr func);
virtual void SetHoppingWindowSpec(THoppingWindowSpecPtr spec);
virtual THoppingWindowSpecPtr GetHoppingWindowSpec() const;
virtual TNodePtr GetSessionWindowSpec() const;
- virtual bool IsCompositeSource() const;
+ virtual bool IsCompositeSource() const;
virtual bool IsGroupByColumn(const TString& column) const;
- virtual bool IsFlattenByColumns() const;
+ virtual bool IsFlattenByColumns() const;
virtual bool IsFlattenByExprs() const;
- virtual bool IsCalcOverWindow() const;
- virtual bool IsOverWindowSource() const;
+ virtual bool IsCalcOverWindow() const;
+ virtual bool IsOverWindowSource() const;
virtual bool IsStream() const;
virtual EOrderKind GetOrderKind() const;
virtual TWriteSettings GetWriteSettings() const;
@@ -862,39 +862,39 @@ namespace NSQLTranslationV1 {
virtual bool BuildSamplingLambda(TNodePtr& node);
virtual bool SetSamplingRate(TContext& ctx, TNodePtr samplingRate);
virtual IJoin* GetJoin();
- virtual ISource* GetCompositeSource();
- virtual bool IsSelect() const;
+ virtual ISource* GetCompositeSource();
+ virtual bool IsSelect() const;
virtual bool IsTableSource() const;
virtual bool ShouldUseSourceAsColumn(const TString& source) const;
- virtual bool IsJoinKeysInitializing() const;
- virtual const TString* GetWindowName() const;
+ virtual bool IsJoinKeysInitializing() const;
+ virtual const TString* GetWindowName() const;
virtual bool DoInit(TContext& ctx, ISource* src);
virtual TNodePtr Build(TContext& ctx) = 0;
virtual TMaybe<TString> FindColumnMistype(const TString& name) const;
-
- virtual bool InitFilters(TContext& ctx);
- void AddDependentSource(ISource* usedSource);
+
+ virtual bool InitFilters(TContext& ctx);
+ void AddDependentSource(ISource* usedSource);
bool IsAlias(EExprSeat exprSeat, const TString& label) const;
bool IsExprAlias(const TString& label) const;
- bool IsExprSeat(EExprSeat exprSeat, EExprType type = EExprType::WithExpression) const;
- TString GetGroupByColumnAlias(const TString& column) const;
+ bool IsExprSeat(EExprSeat exprSeat, EExprType type = EExprType::WithExpression) const;
+ TString GetGroupByColumnAlias(const TString& column) const;
const TVector<TNodePtr>& Expressions(EExprSeat exprSeat) const;
-
- virtual TWindowSpecificationPtr FindWindowSpecification(TContext& ctx, const TString& windowName) const;
-
- TIntrusivePtr<ISource> CloneSource() const;
-
+
+ virtual TWindowSpecificationPtr FindWindowSpecification(TContext& ctx, const TString& windowName) const;
+
+ TIntrusivePtr<ISource> CloneSource() const;
+
protected:
ISource(TPosition pos);
virtual TAstNode* Translate(TContext& ctx) const;
void FillSortParts(const TVector<TSortSpecificationPtr>& orderBy, TNodePtr& sortKeySelector, TNodePtr& sortDirection);
TNodePtr BuildSortSpec(const TVector<TSortSpecificationPtr>& orderBy, const TString& label, bool traits, bool assume);
-
+
TVector<TNodePtr>& Expressions(EExprSeat exprSeat);
- TNodePtr AliasOrColumn(const TNodePtr& node, bool withSource);
+ TNodePtr AliasOrColumn(const TNodePtr& node, bool withSource);
TNodePtr BuildWindowFrame(const TFrameSpecification& spec, bool isCompact);
@@ -909,7 +909,7 @@ namespace NSQLTranslationV1 {
TVector<TAggregationPtr> Aggregations;
TMap<TString, TVector<TAggregationPtr>> AggregationOverWindow;
TMap<TString, TVector<TNodePtr>> FuncOverWindow;
- TWinSpecs WinSpecs;
+ TWinSpecs WinSpecs;
THoppingWindowSpecPtr HoppingWindowSpec;
TNodePtr SessionWindow;
TVector<ISource*> UsedSources;
@@ -920,15 +920,15 @@ namespace NSQLTranslationV1 {
TNodePtr SamplingRate;
};
- template<>
+ template<>
inline TVector<TSourcePtr> CloneContainer<TSourcePtr>(const TVector<TSourcePtr>& args) {
TVector<TSourcePtr> cloneArgs;
- cloneArgs.reserve(args.size());
- for (const auto& arg: args) {
- cloneArgs.emplace_back(arg ? arg->CloneSource() : nullptr);
- }
- return cloneArgs;
- }
+ cloneArgs.reserve(args.size());
+ for (const auto& arg: args) {
+ cloneArgs.emplace_back(arg ? arg->CloneSource() : nullptr);
+ }
+ return cloneArgs;
+ }
struct TJoinLinkSettings {
bool ForceSortedMerge = false;
@@ -948,39 +948,39 @@ namespace NSQLTranslationV1 {
IJoin(TPosition pos);
};
- class TListOfNamedNodes final: public INode {
- public:
+ class TListOfNamedNodes final: public INode {
+ public:
TListOfNamedNodes(TPosition pos, TVector<TNodePtr>&& exprs);
-
+
TVector<TNodePtr>* ContentListPtr() override;
- TAstNode* Translate(TContext& ctx) const override;
- TPtr DoClone() const final;
+ TAstNode* Translate(TContext& ctx) const override;
+ TPtr DoClone() const final;
void DoVisitChildren(const TVisitFunc& func, TVisitNodeSet& visited) const final;
- private:
+ private:
TVector<TNodePtr> Exprs;
TString Meaning;
- };
-
- class TLiteralNode: public TAstListNode {
- public:
+ };
+
+ class TLiteralNode: public TAstListNode {
+ public:
TLiteralNode(TPosition pos, bool isNull);
TLiteralNode(TPosition pos, const TString& type, const TString& value);
TLiteralNode(TPosition pos, const TString& value, ui32 nodeFlags);
TLiteralNode(TPosition pos, const TString& value, ui32 nodeFlags, const TString& type);
- bool IsNull() const override;
+ bool IsNull() const override;
const TString* GetLiteral(const TString& type) const override;
- void DoUpdateState() const override;
- TPtr DoClone() const override;
+ void DoUpdateState() const override;
+ TPtr DoClone() const override;
bool IsLiteral() const override;
TString GetLiteralType() const override;
TString GetLiteralValue() const override;
- protected:
- bool Null;
+ protected:
+ bool Null;
bool Void;
TString Type;
TString Value;
- };
-
+ };
+
class TAsteriskNode: public INode {
public:
TAsteriskNode(TPosition pos);
@@ -989,18 +989,18 @@ namespace NSQLTranslationV1 {
TAstNode* Translate(TContext& ctx) const override;
};
- template<typename T>
- class TLiteralNumberNode: public TLiteralNode {
- public:
+ template<typename T>
+ class TLiteralNumberNode: public TLiteralNode {
+ public:
TLiteralNumberNode(TPosition pos, const TString& type, const TString& value, bool implicitType = false);
- TPtr DoClone() const override final;
- bool DoInit(TContext& ctx, ISource* src) override;
- bool IsIntegerLiteral() const override;
+ TPtr DoClone() const override final;
+ bool DoInit(TContext& ctx, ISource* src) override;
+ bool IsIntegerLiteral() const override;
TPtr ApplyUnaryOp(TContext& ctx, TPosition pos, const TString& opName) const override;
private:
const bool ImplicitType;
- };
-
+ };
+
struct TTableArg {
bool HasAt = false;
TNodePtr Expr;
@@ -1167,7 +1167,7 @@ namespace NSQLTranslationV1 {
bool IsPasswordEncrypted = false;
};
- TString IdContent(TContext& ctx, const TString& str);
+ TString IdContent(TContext& ctx, const TString& str);
TString IdContentFromString(TContext& ctx, const TString& str);
TTableHints GetContextHints(TContext& ctx);
@@ -1179,7 +1179,7 @@ namespace NSQLTranslationV1 {
TNodePtr BuildLiteralNull(TPosition pos);
TNodePtr BuildLiteralVoid(TPosition pos);
- /// String is checked as quotable, support escaping and multiline
+ /// String is checked as quotable, support escaping and multiline
TNodePtr BuildLiteralSmartString(TContext& ctx, const TString& value);
struct TExprOrIdent {
@@ -1216,10 +1216,10 @@ namespace NSQLTranslationV1 {
TNodePtr BuildCalcOverWindow(TPosition pos, const TString& windowName, TNodePtr call);
TNodePtr BuildYsonOptionsNode(TPosition pos, bool autoConvert, bool strict, bool fastYson);
-
+
TNodePtr BuildDoCall(TPosition pos, const TNodePtr& node);
TNodePtr BuildTupleResult(TNodePtr tuple, int ensureTupleSize);
-
+
// Implemented in aggregation.cpp
TAggregationPtr BuildFactoryAggregation(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode, bool multi = false);
TAggregationPtr BuildKeyPayloadFactoryAggregation(TPosition pos, const TString& name, const TString& factory, EAggregateMode aggMode);
@@ -1236,18 +1236,18 @@ namespace NSQLTranslationV1 {
TAggregationPtr BuildCountAggregation(TPosition pos, const TString& name, const TString& func, EAggregateMode aggMode);
TAggregationPtr BuildUserDefinedFactoryAggregation(TPosition pos, const TString& name, const TString& factory, EAggregateMode aggMode);
-
+
// Implemented in builtin.cpp
TNodePtr BuildCallable(TPosition pos, const TString& module, const TString& name, const TVector<TNodePtr>& args, bool forReduce = false);
TNodePtr BuildUdf(TContext& ctx, TPosition pos, const TString& module, const TString& name, const TVector<TNodePtr>& args);
TNodePtr BuildBuiltinFunc(
- TContext& ctx,
- TPosition pos,
+ TContext& ctx,
+ TPosition pos,
TString name,
const TVector<TNodePtr>& args,
const TString& nameSpace = TString(),
- EAggregateMode aggMode = EAggregateMode::Normal,
- bool* mustUseNamed = nullptr,
+ EAggregateMode aggMode = EAggregateMode::Normal,
+ bool* mustUseNamed = nullptr,
bool warnOnYqlNameSpace = true
);
@@ -1258,7 +1258,7 @@ namespace NSQLTranslationV1 {
// Implemented in select.cpp
TNodePtr BuildSubquery(TSourcePtr source, const TString& alias, bool inSubquery, int ensureTupleSize, TScopedStatePtr scoped);
TNodePtr BuildSubqueryRef(TNodePtr subquery, const TString& alias, int tupleIndex = -1);
- TNodePtr BuildSourceNode(TPosition pos, TSourcePtr source, bool checkExist = false);
+ TNodePtr BuildSourceNode(TPosition pos, TSourcePtr source, bool checkExist = false);
TSourcePtr BuildMuxSource(TPosition pos, TVector<TSourcePtr>&& sources);
TSourcePtr BuildFakeSource(TPosition pos, bool missingFrom = false);
TSourcePtr BuildNodeSource(TPosition pos, const TNodePtr& node, bool wrapToList = false);
@@ -1269,11 +1269,11 @@ namespace NSQLTranslationV1 {
TSourcePtr BuildOverWindowSource(TPosition pos, const TString& windowName, ISource* origSource);
TNodePtr BuildOrderBy(TPosition pos, const TVector<TNodePtr>& keys, const TVector<bool>& order);
- TNodePtr BuildSkipTake(TPosition pos, const TNodePtr& skip, const TNodePtr& take);
+ TNodePtr BuildSkipTake(TPosition pos, const TNodePtr& skip, const TNodePtr& take);
+
-
TSourcePtr BuildSelectCore(
- TContext& ctx,
+ TContext& ctx,
TPosition pos,
TSourcePtr source,
const TVector<TNodePtr>& groupByExpr,
@@ -1282,7 +1282,7 @@ namespace NSQLTranslationV1 {
bool assumeSorted,
const TVector<TSortSpecificationPtr>& orderBy,
TNodePtr having,
- TWinSpecs&& windowSpec,
+ TWinSpecs&& windowSpec,
THoppingWindowSpecPtr hoppingWindowSpec,
TVector<TNodePtr>&& terms,
bool distinct,
@@ -1290,27 +1290,27 @@ namespace NSQLTranslationV1 {
bool selectStream,
const TWriteSettings& settings
);
- TSourcePtr BuildSelect(TPosition pos, TSourcePtr source, TNodePtr skipTake);
+ TSourcePtr BuildSelect(TPosition pos, TSourcePtr source, TNodePtr skipTake);
+
-
- enum class ReduceMode {
- ByPartition,
- ByAll,
- };
+ enum class ReduceMode {
+ ByPartition,
+ ByAll,
+ };
TSourcePtr BuildReduce(TPosition pos, ReduceMode mode, TSourcePtr source, TVector<TSortSpecificationPtr>&& orderBy,
TVector<TNodePtr>&& keys, TVector<TNodePtr>&& args, TNodePtr udf, TNodePtr having, const TWriteSettings& settings,
const TVector<TSortSpecificationPtr>& assumeOrderBy, bool listCall);
TSourcePtr BuildProcess(TPosition pos, TSourcePtr source, TNodePtr with, bool withExtFunction, TVector<TNodePtr>&& terms, bool listCall,
bool prcessStream, const TWriteSettings& settings, const TVector<TSortSpecificationPtr>& assumeOrderBy);
-
+
TNodePtr BuildSelectResult(TPosition pos, TSourcePtr source, bool writeResult, bool inSubquery, TScopedStatePtr scoped);
// Implemented in insert.cpp
TSourcePtr BuildWriteValues(TPosition pos, const TString& opertationHumanName, const TVector<TString>& columnsHint, const TVector<TVector<TNodePtr>>& values);
TSourcePtr BuildWriteValues(TPosition pos, const TString& opertationHumanName, const TVector<TString>& columnsHint, TSourcePtr source);
TSourcePtr BuildUpdateValues(TPosition pos, const TVector<TString>& columnsHint, const TVector<TNodePtr>& values);
-
- EWriteColumnMode ToWriteColumnsMode(ESQLWriteColumnMode sqlWriteColumnMode);
+
+ EWriteColumnMode ToWriteColumnsMode(ESQLWriteColumnMode sqlWriteColumnMode);
TNodePtr BuildEraseColumns(TPosition pos, const TVector<TString>& columns);
TNodePtr BuildWriteColumns(TPosition pos, TScopedStatePtr scoped, const TTableRef& table, EWriteColumnMode mode, TSourcePtr values, TNodePtr options = nullptr);
TNodePtr BuildUpdateColumns(TPosition pos, TScopedStatePtr scoped, const TTableRef& table, TSourcePtr values, TSourcePtr source);
@@ -1342,19 +1342,19 @@ namespace NSQLTranslationV1 {
TNodePtr BuildSqlLambda(TPosition pos, TVector<TString>&& args, TVector<TNodePtr>&& exprSeq);
TNodePtr BuildWorldIfNode(TPosition pos, TNodePtr predicate, TNodePtr thenNode, TNodePtr elseNode, bool isEvaluate);
TNodePtr BuildWorldForNode(TPosition pos, TNodePtr list, TNodePtr bodyNode, TNodePtr elseNode, bool isEvaluate);
-
- template<class TContainer>
- TMaybe<TString> FindMistypeIn(const TContainer& container, const TString& name) {
- for (auto& item: container) {
+
+ template<class TContainer>
+ TMaybe<TString> FindMistypeIn(const TContainer& container, const TString& name) {
+ for (auto& item: container) {
if (NLevenshtein::Distance(name, item) < NYql::DefaultMistypeDistance) {
- return item;
- }
- }
- return {};
- }
-
+ return item;
+ }
+ }
+ return {};
+ }
+
bool Parseui32(TNodePtr from, ui32& to);
- TNodePtr GroundWithExpr(const TNodePtr& ground, const TNodePtr& expr);
+ TNodePtr GroundWithExpr(const TNodePtr& ground, const TNodePtr& expr);
TSourcePtr TryMakeSourceFromExpression(TContext& ctx, const TString& currService, const TDeferredAtom& currCluster,
TNodePtr node, const TString& view = {});
void MakeTableFromExpression(TContext& ctx, TNodePtr node, TDeferredAtom& table);
diff --git a/ydb/library/yql/sql/v1/query.cpp b/ydb/library/yql/sql/v1/query.cpp
index 75cf942a00..725356b9f5 100644
--- a/ydb/library/yql/sql/v1/query.cpp
+++ b/ydb/library/yql/sql/v1/query.cpp
@@ -458,7 +458,7 @@ TNodePtr BuildTableKeys(TPosition pos, const TString& service, const TDeferredAt
return new TPrepTableKeys(pos, service, cluster, func, args);
}
-class TInputOptions final: public TAstListNode {
+class TInputOptions final: public TAstListNode {
public:
TInputOptions(TPosition pos, const TTableHints& hints)
: TAstListNode(pos)
@@ -466,7 +466,7 @@ public:
{
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
for (auto& hint: Hints) {
TString hintName = hint.first;
TMaybe<TIssue> normalizeError = NormalizeName(Pos, hintName);
@@ -489,10 +489,10 @@ public:
return true;
}
- TPtr DoClone() const final {
- return {};
- }
-
+ TPtr DoClone() const final {
+ return {};
+ }
+
private:
TTableHints Hints;
};
@@ -505,7 +505,7 @@ TNodePtr BuildInputOptions(TPosition pos, const TTableHints& hints) {
return new TInputOptions(pos, hints);
}
-class TInputTablesNode final: public TAstListNode {
+class TInputTablesNode final: public TAstListNode {
public:
TInputTablesNode(TPosition pos, const TTableList& tables, bool inSubquery, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -515,7 +515,7 @@ public:
{
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
THashSet<TString> processedTables;
for (auto& tr: Tables) {
if (!processedTables.insert(tr.RefName).second) {
@@ -525,10 +525,10 @@ public:
Scoped->UseCluster(tr.Service, tr.Cluster);
auto tableKeys = tr.Keys->GetTableKeys();
auto keys = tableKeys->BuildKeys(ctx, ITableKeys::EBuildKeysMode::INPUT);
- if (!keys || !keys->Init(ctx, src)) {
+ if (!keys || !keys->Init(ctx, src)) {
return false;
}
- auto fields = Y("Void");
+ auto fields = Y("Void");
auto source = Y("DataSource", BuildQuotedAtom(Pos, tr.Service), Scoped->WrapCluster(tr.Cluster, ctx));
auto options = tr.Options ? Q(tr.Options) : Q(Y());
Add(Y("let", "x", keys->Y(TString(ReadName), "world", source, keys, fields, options)));
@@ -546,10 +546,10 @@ public:
return TAstListNode::DoInit(ctx, src);
}
- TPtr DoClone() const final {
- return {};
- }
-
+ TPtr DoClone() const final {
+ return {};
+ }
+
private:
TTableList Tables;
const bool InSubquery;
@@ -560,7 +560,7 @@ TNodePtr BuildInputTables(TPosition pos, const TTableList& tables, bool inSubque
return new TInputTablesNode(pos, tables, inSubquery, scoped);
}
-class TCreateTableNode final: public TAstListNode {
+class TCreateTableNode final: public TAstListNode {
public:
TCreateTableNode(TPosition pos, const TTableRef& tr, const TCreateTableParameters& params, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -571,9 +571,9 @@ public:
scoped->UseCluster(Table.Service, Table.Cluster);
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
auto keys = Table.Keys->GetTableKeys()->BuildKeys(ctx, ITableKeys::EBuildKeysMode::CREATE);
- if (!keys || !keys->Init(ctx, src)) {
+ if (!keys || !keys->Init(ctx, src)) {
return false;
}
@@ -802,9 +802,9 @@ public:
return TAstListNode::DoInit(ctx, src);
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
private:
const TTableRef Table;
const TCreateTableParameters Params;
@@ -1015,7 +1015,7 @@ TNodePtr BuildAlterTable(TPosition pos, const TTableRef& tr, const TAlterTablePa
return new TAlterTableNode(pos, tr, params, scoped);
}
-class TDropTableNode final: public TAstListNode {
+class TDropTableNode final: public TAstListNode {
public:
TDropTableNode(TPosition pos, const TTableRef& tr, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -1026,13 +1026,13 @@ public:
scoped->UseCluster(Table.Service, Table.Cluster);
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
Y_UNUSED(src);
auto keys = Table.Keys->GetTableKeys()->BuildKeys(ctx, ITableKeys::EBuildKeysMode::DROP);
if (!keys || !keys->Init(ctx, FakeSource.Get())) {
return false;
}
-
+
Add("block", Q(Y(
Y("let", "sink", Y("DataSink", BuildQuotedAtom(Pos, Table.Service), Scoped->WrapCluster(Table.Cluster, ctx))),
Y("let", "world", Y(TString(WriteName), "world", "sink", keys, Y("Void"), Q(Y(Q(Y(Q("mode"), Q("drop"))))))),
@@ -1042,9 +1042,9 @@ public:
return TAstListNode::DoInit(ctx, FakeSource.Get());
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
private:
TTableRef Table;
TScopedStatePtr Scoped;
@@ -1383,11 +1383,11 @@ TNodePtr BuildDropRoles(TPosition pos, const TString& service, const TDeferredAt
}
static const TMap<EWriteColumnMode, TString> columnModeToStrMapMR {
- {EWriteColumnMode::Default, ""},
+ {EWriteColumnMode::Default, ""},
{EWriteColumnMode::Insert, "append"},
{EWriteColumnMode::Renew, "renew"}
-};
-
+};
+
static const TMap<EWriteColumnMode, TString> columnModeToStrMapStat {
{EWriteColumnMode::Upsert, "upsert"}
};
@@ -1406,23 +1406,23 @@ static const TMap<EWriteColumnMode, TString> columnModeToStrMapKikimr {
{EWriteColumnMode::DeleteOn, "delete_on"},
};
-class TWriteTableNode final: public TAstListNode {
+class TWriteTableNode final: public TAstListNode {
public:
TWriteTableNode(TPosition pos, const TString& label, const TTableRef& table, EWriteColumnMode mode,
TNodePtr options, TScopedStatePtr scoped)
: TAstListNode(pos)
, Label(label)
, Table(table)
- , Mode(mode)
+ , Mode(mode)
, Options(options)
, Scoped(scoped)
{
scoped->UseCluster(Table.Service, Table.Cluster);
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
auto keys = Table.Keys->GetTableKeys()->BuildKeys(ctx, ITableKeys::EBuildKeysMode::WRITE);
- if (!keys || !keys->Init(ctx, src)) {
+ if (!keys || !keys->Init(ctx, src)) {
return false;
}
@@ -1460,13 +1460,13 @@ public:
return TAstListNode::DoInit(ctx, src);
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
private:
TString Label;
TTableRef Table;
- EWriteColumnMode Mode;
+ EWriteColumnMode Mode;
TNodePtr Options;
TScopedStatePtr Scoped;
};
@@ -1500,9 +1500,9 @@ protected:
return TAstListNode::DoInit(ctx, src);
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
};
class TCommitClustersNode: public TClustersSinkOperationBase {
@@ -1537,16 +1537,16 @@ TNodePtr BuildRollbackClusters(TPosition pos) {
return new TRollbackClustersNode(pos);
}
-class TWriteResultNode final: public TAstListNode {
+class TWriteResultNode final: public TAstListNode {
public:
TWriteResultNode(TPosition pos, const TString& label, TNodePtr settings)
: TAstListNode(pos)
, Label(label)
, Settings(settings)
, CommitClusters(BuildCommitClusters(Pos))
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
auto block(Y(
Y("let", "result_sink", Y("DataSink", Q(TString(ResultProviderName)))),
Y("let", "world", Y(TString(WriteName), "world", "result_sink", Y("Key"), Label, Q(Settings)))
@@ -1560,9 +1560,9 @@ public:
return TAstListNode::DoInit(ctx, src);
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
private:
TString Label;
TNodePtr Settings;
@@ -1580,9 +1580,9 @@ public:
, Blocks(blocks)
, TopLevel(topLevel)
, Scoped(scoped)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
bool hasError = false;
if (TopLevel) {
for (auto& var: ctx.Variables) {
@@ -1591,8 +1591,8 @@ public:
continue;
}
Add(Y("declare", var.first, var.second));
- }
-
+ }
+
for (const auto& lib : ctx.Libraries) {
auto node = Y("library", new TAstAtomNodeImpl(Pos, lib.first, TNodeFlags::ArbitraryContent));
if (lib.second) {
@@ -1616,7 +1616,7 @@ public:
for (const auto& moduleAlias : ctx.ImportModuleAliases) {
Add(Y("import", moduleAlias.second, BuildQuotedAtom(Pos, moduleAlias.first)));
}
-
+
for (const auto& x : ctx.SimpleUdfs) {
Add(Y("let", x.second, Y("Udf", BuildQuotedAtom(Pos, x.first))));
}
@@ -1706,14 +1706,14 @@ public:
}
for (auto& block: Blocks) {
- if (block->SubqueryAlias()) {
- continue;
- }
+ if (block->SubqueryAlias()) {
+ continue;
+ }
if (!block->Init(ctx, nullptr)) {
hasError = true;
continue;
}
- }
+ }
for (const auto& x : Scoped->Local.ExprClusters) {
auto& data = Scoped->Local.ExprClustersMap[x.Get()];
@@ -1728,15 +1728,15 @@ public:
}
for (auto& block: Blocks) {
- const auto subqueryAliasPtr = block->SubqueryAlias();
- if (subqueryAliasPtr) {
- if (block->UsedSubquery()) {
- const auto& ref = block->GetLabel();
- YQL_ENSURE(!ref.empty());
- Add(block);
- Add(Y("let", "world", Y("Nth", *subqueryAliasPtr, Q("0"))));
- Add(Y("let", ref, Y("Nth", *subqueryAliasPtr, Q("1"))));
- }
+ const auto subqueryAliasPtr = block->SubqueryAlias();
+ if (subqueryAliasPtr) {
+ if (block->UsedSubquery()) {
+ const auto& ref = block->GetLabel();
+ YQL_ENSURE(!ref.empty());
+ Add(block);
+ Add(Y("let", "world", Y("Nth", *subqueryAliasPtr, Q("0"))));
+ Add(Y("let", ref, Y("Nth", *subqueryAliasPtr, Q("1"))));
+ }
} else {
const auto& ref = block->GetLabel();
Add(Y("let", ref ? ref : "world", block));
@@ -1751,13 +1751,13 @@ public:
Add(Y("let", name, node));
}
Nodes.insert(Nodes.end(), preparedNodes.begin(), preparedNodes.end());
- }
+ }
for (const auto& symbol: ctx.Exports) {
Add(Y("export", symbol));
}
- }
-
+ }
+
if (!TopLevel || ctx.Settings.Mode != NSQLTranslation::ESqlMode::LIBRARY) {
Add(Y("return", "world"));
}
@@ -1794,7 +1794,7 @@ public:
Y_UNUSED(src);
TString serviceName;
TString cluster;
- if (std::find(Providers.cbegin(), Providers.cend(), Prefix) != Providers.cend()) {
+ if (std::find(Providers.cbegin(), Providers.cend(), Prefix) != Providers.cend()) {
cluster = "$all";
serviceName = Prefix;
} else {
@@ -1845,9 +1845,9 @@ public:
return Node->Translate(ctx);
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
private:
TString Prefix;
@@ -1862,59 +1862,59 @@ TNodePtr BuildPragma(TPosition pos, const TString& prefix, const TString& name,
return new TPragmaNode(pos, prefix, name, values, valueDefault);
}
-class TSqlLambda final: public TAstListNode {
-public:
+class TSqlLambda final: public TAstListNode {
+public:
TSqlLambda(TPosition pos, TVector<TString>&& args, TVector<TNodePtr>&& exprSeq)
- : TAstListNode(pos)
- , Args(args)
- , ExprSeq(exprSeq)
+ : TAstListNode(pos)
+ , Args(args)
+ , ExprSeq(exprSeq)
{
FakeSource = BuildFakeSource(pos);
}
-
- bool DoInit(TContext& ctx, ISource* src) override {
+
+ bool DoInit(TContext& ctx, ISource* src) override {
Y_UNUSED(src);
- for (auto& exprPtr: ExprSeq) {
+ for (auto& exprPtr: ExprSeq) {
if (!exprPtr->Init(ctx, FakeSource.Get())) {
- return {};
- }
- }
- YQL_ENSURE(!ExprSeq.empty());
- auto body = Y();
- auto end = ExprSeq.end() - 1;
- for (auto iter = ExprSeq.begin(); iter != end; ++iter) {
- auto exprPtr = *iter;
- const auto& label = exprPtr->GetLabel();
- YQL_ENSURE(label);
- body = L(body, Y("let", label, exprPtr));
- }
- body = Y("block", Q(L(body, Y("return", *end))));
- auto args = Y();
- for (const auto& arg: Args) {
+ return {};
+ }
+ }
+ YQL_ENSURE(!ExprSeq.empty());
+ auto body = Y();
+ auto end = ExprSeq.end() - 1;
+ for (auto iter = ExprSeq.begin(); iter != end; ++iter) {
+ auto exprPtr = *iter;
+ const auto& label = exprPtr->GetLabel();
+ YQL_ENSURE(label);
+ body = L(body, Y("let", label, exprPtr));
+ }
+ body = Y("block", Q(L(body, Y("return", *end))));
+ auto args = Y();
+ for (const auto& arg: Args) {
args = L(args, BuildAtom(GetPos(), arg));
- }
- Add("lambda", Q(args), body);
- return TAstListNode::DoInit(ctx, src);
- }
-
- TPtr DoClone() const final {
+ }
+ Add("lambda", Q(args), body);
+ return TAstListNode::DoInit(ctx, src);
+ }
+
+ TPtr DoClone() const final {
return {};
- }
-
+ }
+
void DoUpdateState() const override {
State.Set(ENodeState::Const);
}
-private:
+private:
TVector<TString> Args;
TVector<TNodePtr> ExprSeq;
TSourcePtr FakeSource;
-};
-
+};
+
TNodePtr BuildSqlLambda(TPosition pos, TVector<TString>&& args, TVector<TNodePtr>&& exprSeq) {
- return new TSqlLambda(pos, std::move(args), std::move(exprSeq));
-}
-
+ return new TSqlLambda(pos, std::move(args), std::move(exprSeq));
+}
+
class TWorldIf final : public TAstListNode {
public:
TWorldIf(TPosition pos, TNodePtr predicate, TNodePtr thenNode, TNodePtr elseNode, bool isEvaluate)
diff --git a/ydb/library/yql/sql/v1/select.cpp b/ydb/library/yql/sql/v1/select.cpp
index 7494529a23..2841f05a5b 100644
--- a/ydb/library/yql/sql/v1/select.cpp
+++ b/ydb/library/yql/sql/v1/select.cpp
@@ -1,6 +1,6 @@
-#include "sql.h"
+#include "sql.h"
#include "node.h"
-
+
#include "context.h"
#include <ydb/library/yql/providers/common/provider/yql_provider_names.h>
@@ -12,151 +12,151 @@ using namespace NYql;
namespace NSQLTranslationV1 {
-class TSubqueryNode: public INode {
-public:
+class TSubqueryNode: public INode {
+public:
TSubqueryNode(TSourcePtr&& source, const TString& alias, bool inSubquery, int ensureTupleSize, TScopedStatePtr scoped)
- : INode(source->GetPos())
- , Source(std::move(source))
- , Alias(alias)
+ : INode(source->GetPos())
+ , Source(std::move(source))
+ , Alias(alias)
, InSubquery(inSubquery)
, EnsureTupleSize(ensureTupleSize)
, Scoped(scoped)
- {
- YQL_ENSURE(!Alias.empty());
- }
-
- ISource* GetSource() override {
- return Source.Get();
- }
-
- bool DoInit(TContext& ctx, ISource* src) override {
- YQL_ENSURE(!src, "Source not expected for subquery node");
+ {
+ YQL_ENSURE(!Alias.empty());
+ }
+
+ ISource* GetSource() override {
+ return Source.Get();
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ YQL_ENSURE(!src, "Source not expected for subquery node");
Source->UseAsInner();
- if (!Source->Init(ctx, nullptr)) {
- return false;
- }
-
+ if (!Source->Init(ctx, nullptr)) {
+ return false;
+ }
+
TTableList tableList;
Source->GetInputTables(tableList);
-
+
auto tables = BuildInputTables(Pos, tableList, InSubquery, Scoped);
- if (!tables->Init(ctx, Source.Get())) {
- return false;
- }
-
- auto source = Source->Build(ctx);
- if (!source) {
- return false;
- }
+ if (!tables->Init(ctx, Source.Get())) {
+ return false;
+ }
+
+ auto source = Source->Build(ctx);
+ if (!source) {
+ return false;
+ }
if (EnsureTupleSize != -1) {
source = Y("EnsureTupleSize", source, Q(ToString(EnsureTupleSize)));
}
-
- Node = Y("let", Alias, Y("block", Q(L(tables, Y("return", Q(Y("world", source)))))));
- IsUsed = true;
- return true;
- }
-
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, true);
- }
-
- bool UsedSubquery() const override {
- return IsUsed;
- }
-
- TAstNode* Translate(TContext& ctx) const override {
- Y_VERIFY_DEBUG(Node);
- return Node->Translate(ctx);
- }
-
- const TString* SubqueryAlias() const override {
- return &Alias;
- }
-
- TPtr DoClone() const final {
- return {};
- }
-
-protected:
- TSourcePtr Source;
- TNodePtr Node;
- const TString Alias;
+
+ Node = Y("let", Alias, Y("block", Q(L(tables, Y("return", Q(Y("world", source)))))));
+ IsUsed = true;
+ return true;
+ }
+
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, true);
+ }
+
+ bool UsedSubquery() const override {
+ return IsUsed;
+ }
+
+ TAstNode* Translate(TContext& ctx) const override {
+ Y_VERIFY_DEBUG(Node);
+ return Node->Translate(ctx);
+ }
+
+ const TString* SubqueryAlias() const override {
+ return &Alias;
+ }
+
+ TPtr DoClone() const final {
+ return {};
+ }
+
+protected:
+ TSourcePtr Source;
+ TNodePtr Node;
+ const TString Alias;
const bool InSubquery;
const int EnsureTupleSize;
- bool IsUsed = false;
+ bool IsUsed = false;
TScopedStatePtr Scoped;
-};
-
+};
+
TNodePtr BuildSubquery(TSourcePtr source, const TString& alias, bool inSubquery, int ensureTupleSize, TScopedStatePtr scoped) {
return new TSubqueryNode(std::move(source), alias, inSubquery, ensureTupleSize, scoped);
-}
-
+}
+
class TSourceNode: public INode {
public:
- TSourceNode(TPosition pos, TSourcePtr&& source, bool checkExist)
+ TSourceNode(TPosition pos, TSourcePtr&& source, bool checkExist)
: INode(pos)
- , Source(std::move(source))
- , CheckExist(checkExist)
- {}
+ , Source(std::move(source))
+ , CheckExist(checkExist)
+ {}
- ISource* GetSource() override {
- return Source.Get();
+ ISource* GetSource() override {
+ return Source.Get();
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
if (AsInner) {
Source->UseAsInner();
}
- if (!Source->Init(ctx, src)) {
+ if (!Source->Init(ctx, src)) {
return false;
}
- Node = Source->Build(ctx);
- if (!Node) {
- return false;
- }
- if (src) {
- if (IsSubquery()) {
- /// should be not used?
- auto columnsPtr = Source->GetColumns();
+ Node = Source->Build(ctx);
+ if (!Node) {
+ return false;
+ }
+ if (src) {
+ if (IsSubquery()) {
+ /// should be not used?
+ auto columnsPtr = Source->GetColumns();
if (columnsPtr && (columnsPtr->All || columnsPtr->QualifiedAll)) {
Node = Y("SingleMember", Y("SqlAccess", Q("dict"), Y("Take", Node, Y("Uint64", Q("1"))), Y("Uint64", Q("0"))));
} else if (columnsPtr && columnsPtr->List.size() == 1) {
Node = Y("Member", Y("SqlAccess", Q("dict"), Y("Take", Node, Y("Uint64", Q("1"))), Y("Uint64", Q("0"))), Q(columnsPtr->List.front()));
} else {
- ctx.Error(Pos) << "Source used in expression should contain one concrete column";
- return false;
- }
- }
- src->AddDependentSource(Source.Get());
- }
- return true;
- }
-
- bool IsSubquery() const {
- return !AsInner && Source->IsSelect() && !CheckExist;
- }
-
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, IsSubquery());
- }
-
- TAstNode* Translate(TContext& ctx) const override {
+ ctx.Error(Pos) << "Source used in expression should contain one concrete column";
+ return false;
+ }
+ }
+ src->AddDependentSource(Source.Get());
+ }
+ return true;
+ }
+
+ bool IsSubquery() const {
+ return !AsInner && Source->IsSelect() && !CheckExist;
+ }
+
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, IsSubquery());
+ }
+
+ TAstNode* Translate(TContext& ctx) const override {
Y_VERIFY_DEBUG(Node);
return Node->Translate(ctx);
}
- TPtr DoClone() const final {
- return new TSourceNode(Pos, Source->CloneSource(), CheckExist);
- }
-protected:
- TSourcePtr Source;
+ TPtr DoClone() const final {
+ return new TSourceNode(Pos, Source->CloneSource(), CheckExist);
+ }
+protected:
+ TSourcePtr Source;
TNodePtr Node;
- bool CheckExist;
+ bool CheckExist;
};
-TNodePtr BuildSourceNode(TPosition pos, TSourcePtr source, bool checkExist) {
- return new TSourceNode(pos, std::move(source), checkExist);
+TNodePtr BuildSourceNode(TPosition pos, TSourcePtr source, bool checkExist) {
+ return new TSourceNode(pos, std::move(source), checkExist);
}
class TFakeSource: public ISource {
@@ -164,12 +164,12 @@ public:
TFakeSource(TPosition pos, bool missingFrom)
: ISource(pos)
, MissingFrom(missingFrom)
- {}
+ {}
bool IsFake() const override {
return true;
}
-
+
TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
// TODO: fix column reference scope - with proper scopes error below should happen earlier
if (column.CanBeType()) {
@@ -181,14 +181,14 @@ public:
return {};
}
- bool AddFilter(TContext& ctx, TNodePtr filter) override {
+ bool AddFilter(TContext& ctx, TNodePtr filter) override {
Y_UNUSED(filter);
auto pos = filter ? filter->GetPos() : Pos;
ctx.Error(pos) << (MissingFrom ? "Filtering is not allowed without FROM" : "Source does not allow filtering");
return false;
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
Y_UNUSED(ctx);
return Y("AsList", Y("AsStruct"));
}
@@ -199,7 +199,7 @@ public:
return false;
}
- bool AddAggregation(TContext& ctx, TAggregationPtr aggr) override {
+ bool AddAggregation(TContext& ctx, TAggregationPtr aggr) override {
YQL_ENSURE(aggr);
ctx.Error(aggr->GetPos()) << "Aggregation is not allowed " << (MissingFrom ? "without FROM" : "in this context");
return false;
@@ -240,10 +240,10 @@ public:
Y_UNUSED(label);
return nullptr;
}
-
- TPtr DoClone() const final {
+
+ TPtr DoClone() const final {
return new TFakeSource(Pos, MissingFrom);
- }
+ }
private:
const bool MissingFrom;
};
@@ -336,14 +336,14 @@ protected:
IProxySource(TPosition pos, ISource* src)
: ISource(pos)
, Source(src)
- {}
+ {}
- void AllColumns() override {
+ void AllColumns() override {
Y_VERIFY_DEBUG(Source);
return Source->AllColumns();
}
- const TColumns* GetColumns() const override {
+ const TColumns* GetColumns() const override {
Y_VERIFY_DEBUG(Source);
return Source->GetColumns();
}
@@ -353,19 +353,19 @@ protected:
ISource::GetInputTables(tableList);
}
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
Y_VERIFY_DEBUG(Source);
const TString label(Source->GetLabel());
Source->SetLabel(Label);
- const auto ret = Source->AddColumn(ctx, column);
+ const auto ret = Source->AddColumn(ctx, column);
Source->SetLabel(label);
return ret;
}
bool ShouldUseSourceAsColumn(const TString& source) const override {
- return Source->ShouldUseSourceAsColumn(source);
- }
-
+ return Source->ShouldUseSourceAsColumn(source);
+ }
+
bool IsStream() const override {
Y_VERIFY_DEBUG(Source);
return Source->IsStream();
@@ -396,48 +396,48 @@ protected:
{
}
- void AllColumns() override {
+ void AllColumns() override {
Columns.SetAll();
}
- const TColumns* GetColumns() const override {
+ const TColumns* GetColumns() const override {
return &Columns;
}
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
auto& label = *column.GetSourceName();
if (!label.empty() && label != GetLabel()) {
- if (column.IsReliable()) {
- ctx.Error(column.GetPos()) << "Unknown correlation name: " << label;
- }
- return {};
+ if (column.IsReliable()) {
+ ctx.Error(column.GetPos()) << "Unknown correlation name: " << label;
+ }
+ return {};
}
if (column.IsAsterisk()) {
return true;
}
const auto* name = column.GetColumnName();
if (name && !column.CanBeType() && !Columns.IsColumnPossible(ctx, *name) && !IsAlias(EExprSeat::GroupBy, *name) && !IsAlias(EExprSeat::DistinctAggr, *name)) {
- if (column.IsReliable()) {
- TStringBuilder sb;
+ if (column.IsReliable()) {
+ TStringBuilder sb;
sb << "Column " << *name << " is not in source column set";
if (const auto mistype = FindColumnMistype(*name)) {
- sb << ". Did you mean " << mistype.GetRef() << "?";
- }
- ctx.Error(column.GetPos()) << sb;
- }
- return {};
+ sb << ". Did you mean " << mistype.GetRef() << "?";
+ }
+ ctx.Error(column.GetPos()) << sb;
+ }
+ return {};
}
return true;
}
TMaybe<TString> FindColumnMistype(const TString& name) const override {
- auto result = FindMistypeIn(Columns.Real, name);
- if (!result) {
- auto result = FindMistypeIn(Columns.Artificial, name);
- }
- return result ? result : ISource::FindColumnMistype(name);
- }
-
+ auto result = FindMistypeIn(Columns.Real, name);
+ if (!result) {
+ auto result = FindMistypeIn(Columns.Artificial, name);
+ }
+ return result ? result : ISource::FindColumnMistype(name);
+ }
+
protected:
TColumns Columns;
};
@@ -543,60 +543,60 @@ TSourcePtr BuildMuxSource(TPosition pos, TVector<TSourcePtr>&& sources) {
return new TMuxSource(pos, std::move(sources));
}
-class TSubqueryRefNode: public IRealSource {
-public:
+class TSubqueryRefNode: public IRealSource {
+public:
TSubqueryRefNode(const TNodePtr& subquery, const TString& alias, int tupleIndex)
- : IRealSource(subquery->GetPos())
- , Subquery(subquery)
- , Alias(alias)
+ : IRealSource(subquery->GetPos())
+ , Subquery(subquery)
+ , Alias(alias)
, TupleIndex(tupleIndex)
- {
- YQL_ENSURE(subquery->GetSource());
- }
-
- ISource* GetSource() override {
- return this;
- }
-
- bool DoInit(TContext& ctx, ISource* src) override {
- // independent subquery should not connect source
+ {
+ YQL_ENSURE(subquery->GetSource());
+ }
+
+ ISource* GetSource() override {
+ return this;
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ // independent subquery should not connect source
Subquery->UseAsInner();
- if (!Subquery->Init(ctx, nullptr)) {
- return false;
- }
- Columns = *Subquery->GetSource()->GetColumns();
- Node = BuildAtom(Pos, Alias, TNodeFlags::Default);
+ if (!Subquery->Init(ctx, nullptr)) {
+ return false;
+ }
+ Columns = *Subquery->GetSource()->GetColumns();
+ Node = BuildAtom(Pos, Alias, TNodeFlags::Default);
if (TupleIndex != -1) {
Node = Y("Nth", Node, Q(ToString(TupleIndex)));
}
- if (!Node->Init(ctx, src)) {
- return false;
- }
+ if (!Node->Init(ctx, src)) {
+ return false;
+ }
if (src && Subquery->GetSource()->IsSelect()) {
- auto columnsPtr = &Columns;
+ auto columnsPtr = &Columns;
if (columnsPtr && (columnsPtr->All || columnsPtr->QualifiedAll)) {
Node = Y("SingleMember", Y("SqlAccess", Q("dict"), Y("Take", Node, Y("Uint64", Q("1"))), Y("Uint64", Q("0"))));
} else if (columnsPtr && columnsPtr->List.size() == 1) {
Node = Y("Member", Y("SqlAccess", Q("dict"), Y("Take", Node, Y("Uint64", Q("1"))), Y("Uint64", Q("0"))), Q(columnsPtr->List.front()));
} else {
ctx.Error(Pos) << "Source used in expression should contain one concrete column";
- return false;
- }
- }
+ return false;
+ }
+ }
TNodePtr sample;
if (!BuildSamplingLambda(sample)) {
return false;
} else if (sample) {
Node = Y("block", Q(Y(Y("let", Node, Y("OrderedFlatMap", Node, sample)), Y("return", Node))));
}
- return true;
- }
-
- TNodePtr Build(TContext& ctx) override {
- Y_UNUSED(ctx);
- return Node;
- }
-
+ return true;
+ }
+
+ TNodePtr Build(TContext& ctx) override {
+ Y_UNUSED(ctx);
+ return Node;
+ }
+
bool SetSamplingOptions(
TContext& ctx,
TPosition pos,
@@ -617,31 +617,31 @@ public:
bool IsStream() const override {
return Subquery->GetSource()->IsStream();
}
-
- void DoUpdateState() const override {
- State.Set(ENodeState::Const, true);
- }
-
- TAstNode* Translate(TContext& ctx) const override {
- Y_VERIFY_DEBUG(Node);
- return Node->Translate(ctx);
- }
-
- TPtr DoClone() const final {
+
+ void DoUpdateState() const override {
+ State.Set(ENodeState::Const, true);
+ }
+
+ TAstNode* Translate(TContext& ctx) const override {
+ Y_VERIFY_DEBUG(Node);
+ return Node->Translate(ctx);
+ }
+
+ TPtr DoClone() const final {
return new TSubqueryRefNode(Subquery, Alias, TupleIndex);
- }
-
-protected:
- TNodePtr Subquery;
- const TString Alias;
+ }
+
+protected:
+ TNodePtr Subquery;
+ const TString Alias;
const int TupleIndex;
- TNodePtr Node;
-};
-
+ TNodePtr Node;
+};
+
TNodePtr BuildSubqueryRef(TNodePtr subquery, const TString& alias, int tupleIndex) {
return new TSubqueryRefNode(std::move(subquery), alias, tupleIndex);
-}
-
+}
+
class TTableSource: public IRealSource {
public:
TTableSource(TPosition pos, const TTableRef& table, const TString& label)
@@ -658,15 +658,15 @@ public:
}
bool ShouldUseSourceAsColumn(const TString& source) const override {
- return source && source != GetLabel();
- }
-
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ return source && source != GetLabel();
+ }
+
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
Columns.Add(column.GetColumnName(), column.GetCountHint(), column.IsArtificial(), column.IsReliable());
- if (!IRealSource::AddColumn(ctx, column)) {
- return {};
- }
- return false;
+ if (!IRealSource::AddColumn(ctx, column)) {
+ return {};
+ }
+ return false;
}
bool SetSamplingOptions(
@@ -732,7 +732,7 @@ public:
return Table.Keys->SetViewName(ctx, pos, view);
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
if (!Table.Keys->Init(ctx, nullptr)) {
return nullptr;
}
@@ -743,9 +743,9 @@ public:
return IsStreamingService(Table.Service);
}
- TPtr DoClone() const final {
+ TPtr DoClone() const final {
return new TTableSource(Pos, Table, GetLabel());
- }
+ }
bool IsTableSource() const override {
return true;
@@ -796,15 +796,15 @@ public:
}
bool ShouldUseSourceAsColumn(const TString& source) const override {
- return source && source != GetLabel();
- }
-
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ return source && source != GetLabel();
+ }
+
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
if (const TString* columnName = column.GetColumnName()) {
if (columnName && IsExprAlias(*columnName)) {
- return true;
- }
- }
+ return true;
+ }
+ }
return IProxySource::AddColumn(ctx, column);
}
@@ -855,7 +855,7 @@ public:
return ISource::DoInit(ctx, source);
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
Y_UNUSED(ctx);
return NewSource ? NewSource->Build(ctx) : Node;
}
@@ -871,11 +871,11 @@ public:
return IsStreamingService(Service);
}
- TPtr DoClone() const final {
+ TPtr DoClone() const final {
return new TInnerSource(Pos, SafeClone(Node), Service, Cluster, GetLabel());
- }
-protected:
- TNodePtr Node;
+ }
+protected:
+ TNodePtr Node;
TString Service;
TDeferredAtom Cluster;
TSourcePtr NewSource;
@@ -922,9 +922,9 @@ static bool IsComparableExpression(TContext& ctx, const TNodePtr& expr, bool ass
return true;
}
-/// \todo move to reduce.cpp? or mapreduce.cpp?
-class TReduceSource: public IRealSource {
-public:
+/// \todo move to reduce.cpp? or mapreduce.cpp?
+class TReduceSource: public IRealSource {
+public:
TReduceSource(TPosition pos,
ReduceMode mode,
TSourcePtr source,
@@ -936,78 +936,78 @@ public:
const TWriteSettings& settings,
const TVector<TSortSpecificationPtr>& assumeOrderBy,
bool listCall)
- : IRealSource(pos)
- , Mode(mode)
- , Source(std::move(source))
- , OrderBy(std::move(orderBy))
- , Keys(std::move(keys))
- , Args(std::move(args))
- , Udf(udf)
- , Having(having)
+ : IRealSource(pos)
+ , Mode(mode)
+ , Source(std::move(source))
+ , OrderBy(std::move(orderBy))
+ , Keys(std::move(keys))
+ , Args(std::move(args))
+ , Udf(udf)
+ , Having(having)
, Settings(settings)
, AssumeOrderBy(assumeOrderBy)
, ListCall(listCall)
- {
- YQL_ENSURE(!Keys.empty());
- YQL_ENSURE(Source);
- }
-
+ {
+ YQL_ENSURE(!Keys.empty());
+ YQL_ENSURE(Source);
+ }
+
void GetInputTables(TTableList& tableList) const override {
Source->GetInputTables(tableList);
ISource::GetInputTables(tableList);
- }
-
- bool DoInit(TContext& ctx, ISource* src) final {
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) final {
if (AsInner) {
Source->UseAsInner();
}
- YQL_ENSURE(!src);
- if (!Source->Init(ctx, src)) {
- return false;
- }
- if (!Source->InitFilters(ctx)) {
- return false;
- }
- src = Source.Get();
- for (auto& key: Keys) {
- if (!key->Init(ctx, src)) {
- return false;
- }
- auto keyNamePtr = key->GetColumnName();
- YQL_ENSURE(keyNamePtr);
- if (!src->AddGroupKey(ctx, *keyNamePtr)) {
- return false;
- }
- }
- if (Having && !Having->Init(ctx, nullptr)) {
- return false;
- }
-
- /// SIN: verify reduce one argument
- if (Args.size() != 1) {
- ctx.Error(Pos) << "REDUCE requires exactly one UDF argument";
- return false;
- }
- if (!Args[0]->Init(ctx, src)) {
- return false;
- }
-
- for (auto orderSpec: OrderBy) {
- if (!orderSpec->OrderExpr->Init(ctx, src)) {
- return false;
- }
- }
-
+ YQL_ENSURE(!src);
+ if (!Source->Init(ctx, src)) {
+ return false;
+ }
+ if (!Source->InitFilters(ctx)) {
+ return false;
+ }
+ src = Source.Get();
+ for (auto& key: Keys) {
+ if (!key->Init(ctx, src)) {
+ return false;
+ }
+ auto keyNamePtr = key->GetColumnName();
+ YQL_ENSURE(keyNamePtr);
+ if (!src->AddGroupKey(ctx, *keyNamePtr)) {
+ return false;
+ }
+ }
+ if (Having && !Having->Init(ctx, nullptr)) {
+ return false;
+ }
+
+ /// SIN: verify reduce one argument
+ if (Args.size() != 1) {
+ ctx.Error(Pos) << "REDUCE requires exactly one UDF argument";
+ return false;
+ }
+ if (!Args[0]->Init(ctx, src)) {
+ return false;
+ }
+
+ for (auto orderSpec: OrderBy) {
+ if (!orderSpec->OrderExpr->Init(ctx, src)) {
+ return false;
+ }
+ }
+
if (!Udf->Init(ctx, src)) {
return false;
}
- if (Udf->GetLabel().empty()) {
- Columns.SetAll();
- } else {
+ if (Udf->GetLabel().empty()) {
+ Columns.SetAll();
+ } else {
Columns.Add(&Udf->GetLabel(), false);
- }
+ }
const auto label = GetLabel();
for (const auto& sortSpec: AssumeOrderBy) {
@@ -1022,29 +1022,29 @@ public:
}
SetLabel(label);
- return true;
- }
-
- TNodePtr Build(TContext& ctx) final {
- auto input = Source->Build(ctx);
- if (!input) {
- return nullptr;
- }
-
+ return true;
+ }
+
+ TNodePtr Build(TContext& ctx) final {
+ auto input = Source->Build(ctx);
+ if (!input) {
+ return nullptr;
+ }
+
auto keysTuple = Y();
if (Keys.size() == 1) {
keysTuple = Y("Member", "row", BuildQuotedAtom(Pos, *Keys.back()->GetColumnName()));
}
else {
- for (const auto& key: Keys) {
- keysTuple = L(keysTuple, Y("Member", "row", BuildQuotedAtom(Pos, *key->GetColumnName())));
- }
- keysTuple = Q(keysTuple);
- }
+ for (const auto& key: Keys) {
+ keysTuple = L(keysTuple, Y("Member", "row", BuildQuotedAtom(Pos, *key->GetColumnName())));
+ }
+ keysTuple = Q(keysTuple);
+ }
auto extractKey = Y("SqlExtractKey", "row", BuildLambda(Pos, Y("row"), keysTuple));
auto extractKeyLambda = BuildLambda(Pos, Y("row"), extractKey);
-
- TNodePtr processPartitions;
+
+ TNodePtr processPartitions;
if (ListCall) {
if (Mode != ReduceMode::ByAll) {
ctx.Error(Pos) << "TableRows() must be used only with USING ALL";
@@ -1065,7 +1065,7 @@ public:
}
processPartitions = Y("SqlReduce", "partitionStream", BuildQuotedAtom(Pos, "byAll", TNodeFlags::Default), Udf, expr);
break;
- }
+ }
case ReduceMode::ByPartition: {
processPartitions = Y("SqlReduce", "partitionStream", extractKeyLambda, Udf,
BuildLambda(Pos, Y("row"), Args[0]));
@@ -1073,25 +1073,25 @@ public:
}
default:
YQL_ENSURE(false, "Unexpected REDUCE mode");
- }
- }
-
- TNodePtr sortDirection;
+ }
+ }
+
+ TNodePtr sortDirection;
TNodePtr sortKeySelector;
- FillSortParts(OrderBy, sortDirection, sortKeySelector);
+ FillSortParts(OrderBy, sortDirection, sortKeySelector);
if (!OrderBy.empty()) {
sortKeySelector = BuildLambda(Pos, Y("row"), Y("SqlExtractKey", "row", sortKeySelector));
}
-
+
auto partitionByKey = Y(!ListCall && Mode == ReduceMode::ByAll ? "PartitionByKey" : "PartitionsByKeys", "core", extractKeyLambda,
- sortDirection, sortKeySelector, BuildLambda(Pos, Y("partitionStream"), processPartitions));
-
+ sortDirection, sortKeySelector, BuildLambda(Pos, Y("partitionStream"), processPartitions));
+
auto inputLabel = ListCall ? "inputRowsList" : "core";
auto block(Y(Y("let", inputLabel, input)));
auto filter = Source->BuildFilter(ctx, inputLabel);
- if (filter) {
+ if (filter) {
block = L(block, Y("let", inputLabel, filter));
- }
+ }
if (ListCall) {
block = L(block, Y("let", "core", "inputRowsList"));
}
@@ -1100,14 +1100,14 @@ public:
block = L(block, Y("let", "core", Y("RemoveSystemMembers", "core")));
}
block = L(block, Y("let", "core", Y("AutoDemuxList", partitionByKey)));
- if (Having) {
- block = L(block, Y("let", "core",
+ if (Having) {
+ block = L(block, Y("let", "core",
Y("Filter", "core", BuildLambda(Pos, Y("row"), Y("Coalesce", Having, Y("Bool", Q("false")))))
- ));
- }
- return Y("block", Q(L(block, Y("return", "core"))));
- }
-
+ ));
+ }
+ return Y("block", Q(L(block, Y("return", "core"))));
+ }
+
TNodePtr BuildSort(TContext& ctx, const TString& label) override {
Y_UNUSED(ctx);
if (AssumeOrderBy.empty()) {
@@ -1125,24 +1125,24 @@ public:
return Settings;
}
- TPtr DoClone() const final {
- return new TReduceSource(Pos, Mode, Source->CloneSource(), CloneContainer(OrderBy),
+ TPtr DoClone() const final {
+ return new TReduceSource(Pos, Mode, Source->CloneSource(), CloneContainer(OrderBy),
CloneContainer(Keys), CloneContainer(Args), SafeClone(Udf), SafeClone(Having), Settings,
CloneContainer(AssumeOrderBy), ListCall);
- }
-private:
- ReduceMode Mode;
- TSourcePtr Source;
+ }
+private:
+ ReduceMode Mode;
+ TSourcePtr Source;
TVector<TSortSpecificationPtr> OrderBy;
TVector<TNodePtr> Keys;
TVector<TNodePtr> Args;
- TNodePtr Udf;
- TNodePtr Having;
+ TNodePtr Udf;
+ TNodePtr Having;
const TWriteSettings Settings;
TVector<TSortSpecificationPtr> AssumeOrderBy;
const bool ListCall;
-};
-
+};
+
TSourcePtr BuildReduce(TPosition pos,
ReduceMode mode,
TSourcePtr source,
@@ -1156,8 +1156,8 @@ TSourcePtr BuildReduce(TPosition pos,
bool listCall) {
return new TReduceSource(pos, mode, std::move(source), std::move(orderBy), std::move(keys),
std::move(args), udf, having, settings, assumeOrderBy, listCall);
-}
-
+}
+
namespace {
bool InitAndGetGroupKey(TContext& ctx, const TNodePtr& expr, ISource* src, TStringBuf where, TString& keyColumn) {
@@ -1192,45 +1192,45 @@ bool InitAndGetGroupKey(TContext& ctx, const TNodePtr& expr, ISource* src, TStri
}
-class TCompositeSelect: public IRealSource {
-public:
+class TCompositeSelect: public IRealSource {
+public:
TCompositeSelect(TPosition pos, TSourcePtr source, TSourcePtr originalSource, const TWriteSettings& settings)
- : IRealSource(pos)
- , Source(std::move(source))
+ : IRealSource(pos)
+ , Source(std::move(source))
, OriginalSource(std::move(originalSource))
, Settings(settings)
- {
- YQL_ENSURE(Source);
- }
-
+ {
+ YQL_ENSURE(Source);
+ }
+
void SetSubselects(TVector<TSourcePtr>&& subselects, TVector<TNodePtr>&& grouping, TVector<TNodePtr>&& groupByExpr) {
- Subselects = std::move(subselects);
+ Subselects = std::move(subselects);
Grouping = std::move(grouping);
GroupByExpr = std::move(groupByExpr);
- Y_VERIFY_DEBUG(Subselects.size() > 1);
- }
-
+ Y_VERIFY_DEBUG(Subselects.size() > 1);
+ }
+
void GetInputTables(TTableList& tableList) const override {
- for (const auto& select: Subselects) {
+ for (const auto& select: Subselects) {
select->GetInputTables(tableList);
- }
+ }
ISource::GetInputTables(tableList);
- }
-
- bool DoInit(TContext& ctx, ISource* src) override {
+ }
+
+ bool DoInit(TContext& ctx, ISource* src) override {
if (AsInner) {
Source->UseAsInner();
}
- if (src) {
- src->AddDependentSource(Source.Get());
- }
- if (!Source->Init(ctx, src)) {
- return false;
- }
- if (!Source->InitFilters(ctx)) {
- return false;
- }
+ if (src) {
+ src->AddDependentSource(Source.Get());
+ }
+ if (!Source->Init(ctx, src)) {
+ return false;
+ }
+ if (!Source->InitFilters(ctx)) {
+ return false;
+ }
if (!CalculateGroupingCols(ctx, src)) {
return false;
@@ -1262,31 +1262,31 @@ public:
}
}
- for (const auto& select: Subselects) {
- select->SetLabel(Label);
+ for (const auto& select: Subselects) {
+ select->SetLabel(Label);
if (AsInner) {
select->UseAsInner();
}
- if (!select->Init(ctx, Source.Get())) {
- return false;
- }
- }
- return true;
- }
-
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
- for (const auto& select: Subselects) {
- if (!select->AddColumn(ctx, column)) {
- return {};
- }
- }
- return true;
- }
-
- TNodePtr Build(TContext& ctx) override {
- auto input = Source->Build(ctx);
- auto block(Y(Y("let", "composite", input)));
+ if (!select->Init(ctx, Source.Get())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ for (const auto& select: Subselects) {
+ if (!select->AddColumn(ctx, column)) {
+ return {};
+ }
+ }
+ return true;
+ }
+
+ TNodePtr Build(TContext& ctx) override {
+ auto input = Source->Build(ctx);
+ auto block(Y(Y("let", "composite", input)));
bool ordered = ctx.UseUnordered(*this);
if (PreFlattenMap) {
@@ -1296,57 +1296,57 @@ public:
block = L(block, Y("let", "composite", Y(ordered ? "OrderedFlatMap" : "FlatMap", "composite", BuildLambda(Pos, Y("row"), Flatten, "res"))));
}
auto filter = Source->BuildFilter(ctx, "composite");
- if (filter) {
- block = L(block, Y("let", "composite", filter));
- }
-
- TNodePtr compositeNode = Y("UnionAll");
- for (const auto& select: Subselects) {
- auto addNode = select->Build(ctx);
- if (!addNode) {
- return nullptr;
- }
- compositeNode->Add(addNode);
- }
-
- return GroundWithExpr(block, compositeNode);
- }
-
- bool IsGroupByColumn(const TString& column) const override {
+ if (filter) {
+ block = L(block, Y("let", "composite", filter));
+ }
+
+ TNodePtr compositeNode = Y("UnionAll");
+ for (const auto& select: Subselects) {
+ auto addNode = select->Build(ctx);
+ if (!addNode) {
+ return nullptr;
+ }
+ compositeNode->Add(addNode);
+ }
+
+ return GroundWithExpr(block, compositeNode);
+ }
+
+ bool IsGroupByColumn(const TString& column) const override {
YQL_ENSURE(!GroupingCols.empty());
return GroupingCols.contains(column);
- }
-
+ }
+
const TSet<TString>& GetGroupingCols() const {
return GroupingCols;
}
- TNodePtr BuildSort(TContext& ctx, const TString& label) override {
- return Subselects.front()->BuildSort(ctx, label);
- }
-
+ TNodePtr BuildSort(TContext& ctx, const TString& label) override {
+ return Subselects.front()->BuildSort(ctx, label);
+ }
+
EOrderKind GetOrderKind() const override {
return Subselects.front()->GetOrderKind();
}
- const TColumns* GetColumns() const override{
- return Subselects.front()->GetColumns();
- }
-
- ISource* RealSource() const {
- return Source.Get();
- }
-
+ const TColumns* GetColumns() const override{
+ return Subselects.front()->GetColumns();
+ }
+
+ ISource* RealSource() const {
+ return Source.Get();
+ }
+
TWriteSettings GetWriteSettings() const override {
return Settings;
}
- TNodePtr DoClone() const final {
+ TNodePtr DoClone() const final {
auto newSource = MakeIntrusive<TCompositeSelect>(Pos, Source->CloneSource(), OriginalSource->CloneSource(), Settings);
newSource->SetSubselects(CloneContainer(Subselects), CloneContainer(Grouping), CloneContainer(GroupByExpr));
- return newSource;
- }
-private:
+ return newSource;
+ }
+private:
bool CalculateGroupingCols(TContext& ctx, ISource* initSrc) {
auto origSrc = OriginalSource->CloneSource();
if (!origSrc->Init(ctx, initSrc)) {
@@ -1376,7 +1376,7 @@ private:
return !hasError;
}
- TSourcePtr Source;
+ TSourcePtr Source;
TSourcePtr OriginalSource;
TNodePtr Flatten;
TNodePtr PreFlattenMap;
@@ -1385,9 +1385,9 @@ private:
TVector<TNodePtr> Grouping;
TVector<TNodePtr> GroupByExpr;
TSet<TString> GroupingCols;
-};
-
-/// \todo simplify class
+};
+
+/// \todo simplify class
class TSelectCore: public IRealSource {
public:
TSelectCore(
@@ -1399,7 +1399,7 @@ public:
bool assumeSorted,
const TVector<TSortSpecificationPtr>& orderBy,
TNodePtr having,
- TWinSpecs& winSpecs,
+ TWinSpecs& winSpecs,
THoppingWindowSpecPtr hoppingWindowSpec,
const TVector<TNodePtr>& terms,
bool distinct,
@@ -1408,16 +1408,16 @@ public:
const TWriteSettings& settings
)
: IRealSource(pos)
- , Source(std::move(source))
- , GroupByExpr(groupByExpr)
+ , Source(std::move(source))
+ , GroupByExpr(groupByExpr)
, GroupBy(groupBy)
, AssumeSorted(assumeSorted)
, CompactGroupBy(compactGroupBy)
- , OrderBy(orderBy)
+ , OrderBy(orderBy)
, Having(having)
- , WinSpecs(winSpecs)
+ , WinSpecs(winSpecs)
, Terms(terms)
- , Without(without)
+ , Without(without)
, Distinct(distinct)
, HoppingWindowSpec(hoppingWindowSpec)
, SelectStream(selectStream)
@@ -1436,12 +1436,12 @@ public:
ISource::GetInputTables(tableList);
}
- bool DoInit(TContext& ctx, ISource* initSrc) override {
+ bool DoInit(TContext& ctx, ISource* initSrc) override {
if (AsInner) {
Source->UseAsInner();
}
- if (!Source->Init(ctx, initSrc)) {
+ if (!Source->Init(ctx, initSrc)) {
return false;
}
if (SelectStream && !Source->IsStream()) {
@@ -1449,7 +1449,7 @@ public:
return false;
}
- auto src = Source.Get();
+ auto src = Source.Get();
bool hasError = false;
if (src->IsFlattenByExprs()) {
@@ -1475,7 +1475,7 @@ public:
Having->CollectPreaggregateExprs(ctx, *src, DistinctAggrExpr);
}
- for (auto& expr: GroupByExpr) {
+ for (auto& expr: GroupByExpr) {
if (auto sessionWindow = dynamic_cast<TSessionWindow*>(expr.Get())) {
if (Source->IsStream()) {
ctx.Error(Pos) << "SessionWindow is unsupported for streaming sources";
@@ -1496,11 +1496,11 @@ public:
if (!expr->Init(ctx, src) || !IsComparableExpression(ctx, expr, false, "GROUP BY")) {
hasError = true;
- }
- }
+ }
+ }
if (hasError || !src->AddExpressions(ctx, GroupByExpr, EExprSeat::GroupBy)) {
return false;
- }
+ }
for (auto& expr: DistinctAggrExpr) {
if (!expr->Init(ctx, src)) {
@@ -1511,19 +1511,19 @@ public:
return false;
}
- /// grouped expressions are available in filters
- if (!Source->InitFilters(ctx)) {
+ /// grouped expressions are available in filters
+ if (!Source->InitFilters(ctx)) {
return false;
- }
+ }
- for (auto& expr: GroupBy) {
+ for (auto& expr: GroupBy) {
TString usedColumn;
if (!InitAndGetGroupKey(ctx, expr, src, "GROUP BY", usedColumn)) {
hasError = true;
} else if (usedColumn) {
- if (!src->AddGroupKey(ctx, usedColumn)) {
+ if (!src->AddGroupKey(ctx, usedColumn)) {
hasError = true;
- }
+ }
}
}
@@ -1534,23 +1534,23 @@ public:
if (Having && !Having->Init(ctx, src)) {
return false;
}
- src->AddWindowSpecs(WinSpecs);
+ src->AddWindowSpecs(WinSpecs);
const bool isJoin = Source->GetJoin();
if (!InitSelect(ctx, src, isJoin, hasError)) {
return false;
}
- src->FinishColumns();
+ src->FinishColumns();
Aggregate = src->BuildAggregation("core");
if (src->IsFlattenByColumns() || src->IsFlattenColumns()) {
Flatten = src->IsFlattenByColumns() ?
src->BuildFlattenByColumns("row") :
src->BuildFlattenColumns("row");
- if (!Flatten || !Flatten->Init(ctx, src)) {
+ if (!Flatten || !Flatten->Init(ctx, src)) {
return false;
- }
- }
+ }
+ }
if (src->IsFlattenByExprs()) {
PreFlattenMap = src->BuildPreFlattenMap(ctx);
@@ -1563,8 +1563,8 @@ public:
PreaggregatedMap = src->BuildPreaggregatedMap(ctx);
if (!PreaggregatedMap) {
return false;
- }
- }
+ }
+ }
if (Aggregate) {
if (!Aggregate->Init(ctx, src)) {
return false;
@@ -1576,7 +1576,7 @@ public:
BuildLambda(Pos, Y("row"), Y("Coalesce", Having, Y("Bool", Q("false"))))
);
}
- } else if (Having) {
+ } else if (Having) {
if (Distinct) {
Aggregate = Y(
"Filter",
@@ -1593,27 +1593,27 @@ public:
ctx.Error(Pos) << "No aggregations were specified";
return false;
}
- if (hasError) {
- return false;
- }
-
- if (src->IsCalcOverWindow()) {
- if (src->IsExprSeat(EExprSeat::WindowPartitionBy, EExprType::WithExpression)) {
+ if (hasError) {
+ return false;
+ }
+
+ if (src->IsCalcOverWindow()) {
+ if (src->IsExprSeat(EExprSeat::WindowPartitionBy, EExprType::WithExpression)) {
PrewindowMap = src->BuildPrewindowMap(ctx);
- if (!PrewindowMap) {
+ if (!PrewindowMap) {
return false;
- }
- }
+ }
+ }
CalcOverWindow = src->BuildCalcOverWindow(ctx, "core");
if (!CalcOverWindow || !CalcOverWindow->Init(ctx, src)) {
return false;
- }
- }
+ }
+ }
return true;
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
auto input = Source->Build(ctx);
if (!input) {
return nullptr;
@@ -1912,11 +1912,11 @@ private:
const bool isJoin = Source->GetJoin();
const bool needCoalesce = isJoin && ctx.SimpleColumns &&
(Columns.All || multipleQualifiedAll || ctx.CoalesceJoinKeysOnQualifiedAll);
-
+
if (!needCoalesce) {
return base;
}
-
+
auto terms = base;
const auto& sameKeyMap = Source->GetJoin()->GetSameKeysMap();
if (sameKeyMap) {
@@ -1926,10 +1926,10 @@ private:
for (const auto& label : coalesceLabels) {
if (sources.contains(label)) {
coalesceKeys = L(coalesceKeys, Q(DotJoin(label, key)));
- }
- }
+ }
+ }
terms = L(terms, Y("let", "flatSameKeys", Y("CoalesceMembers", "flatSameKeys", Q(coalesceKeys))));
- }
+ }
terms = L(terms, Y("let", "row", "flatSameKeys"));
}
@@ -1990,9 +1990,9 @@ private:
YQL_ENSURE(*sourceName && !sourceName->empty());
YQL_ENSURE(Columns.QualifiedAll);
starTerms.insert(*sourceName);
- }
+ }
}
-
+
TVector<TString> matched;
TVector<TString> unmatched;
for (auto& label : Source->GetJoin()->GetJoinLabels()) {
@@ -2000,7 +2000,7 @@ private:
matched.push_back(label);
} else {
unmatched.push_back(label);
- }
+ }
}
coalesceLabels.insert(coalesceLabels.end(), matched.begin(), matched.end());
@@ -2054,11 +2054,11 @@ private:
}
terms = L(terms, Y("let", "res", members));
- }
+ }
sqlProjectArgs = L(sqlProjectArgs, Y("SqlProjectStarItem", "projectCoreType", BuildQuotedAtom(Pos, *sourceName), BuildLambda(Pos, Y("row"), terms, "res"), Q(options)));
- }
+ }
++column;
- }
+ }
}
auto block(Y(Y("let", "projectCoreType", Y("TypeOf", "core"))));
@@ -2068,8 +2068,8 @@ private:
block = L(block, Y("let", "core", Y(ordered ? "OrderedSqlProject" : "SqlProject", "core", Q(sqlProjectArgs))));
return Y("block", Q(L(block, Y("return", "core"))));
- }
-
+ }
+
private:
TSourcePtr Source;
TVector<TNodePtr> GroupByExpr;
@@ -2079,18 +2079,18 @@ private:
bool CompactGroupBy = false;
TVector<TSortSpecificationPtr> OrderBy;
TNodePtr Having;
- TWinSpecs WinSpecs;
+ TWinSpecs WinSpecs;
TNodePtr Flatten;
TNodePtr PreFlattenMap;
- TNodePtr PreaggregatedMap;
- TNodePtr PrewindowMap;
+ TNodePtr PreaggregatedMap;
+ TNodePtr PrewindowMap;
TNodePtr Aggregate;
- TNodePtr CalcOverWindow;
+ TNodePtr CalcOverWindow;
TNodePtr CompositeTerms;
TVector<TNodePtr> Terms;
TVector<TNodePtr> Without;
- const bool Distinct;
- bool OrderByInit = false;
+ const bool Distinct;
+ bool OrderByInit = false;
THoppingWindowSpecPtr HoppingWindowSpec;
const bool SelectStream;
const TWriteSettings Settings;
@@ -2360,97 +2360,97 @@ TSourcePtr BuildProcess(
return new TProcessSource(pos, std::move(source), with, withExtFunction, std::move(terms), listCall, processStream, settings, assumeOrderBy);
}
-class TNestedProxySource: public IProxySource {
-public:
+class TNestedProxySource: public IProxySource {
+public:
TNestedProxySource(TPosition pos, const TVector<TNodePtr>& groupBy, TSourcePtr source)
- : IProxySource(pos, source.Get())
- , CompositeSelect(nullptr)
- , Holder(std::move(source))
- , GroupBy(groupBy)
- {}
-
+ : IProxySource(pos, source.Get())
+ , CompositeSelect(nullptr)
+ , Holder(std::move(source))
+ , GroupBy(groupBy)
+ {}
+
TNestedProxySource(TCompositeSelect* compositeSelect, const TVector<TNodePtr>& groupBy)
- : IProxySource(compositeSelect->GetPos(), compositeSelect->RealSource())
- , CompositeSelect(compositeSelect)
- , GroupBy(groupBy)
- {}
-
- bool DoInit(TContext& ctx, ISource* src) override {
- return Source->Init(ctx, src);
- }
-
- TNodePtr Build(TContext& ctx) override {
- return CompositeSelect ? BuildAtom(Pos, "composite", TNodeFlags::Default) : Source->Build(ctx);
- }
-
- bool InitFilters(TContext& ctx) override {
- return CompositeSelect ? true : Source->InitFilters(ctx);
- }
-
+ : IProxySource(compositeSelect->GetPos(), compositeSelect->RealSource())
+ , CompositeSelect(compositeSelect)
+ , GroupBy(groupBy)
+ {}
+
+ bool DoInit(TContext& ctx, ISource* src) override {
+ return Source->Init(ctx, src);
+ }
+
+ TNodePtr Build(TContext& ctx) override {
+ return CompositeSelect ? BuildAtom(Pos, "composite", TNodeFlags::Default) : Source->Build(ctx);
+ }
+
+ bool InitFilters(TContext& ctx) override {
+ return CompositeSelect ? true : Source->InitFilters(ctx);
+ }
+
TNodePtr BuildFilter(TContext& ctx, const TString& label) override {
return CompositeSelect ? nullptr : Source->BuildFilter(ctx, label);
- }
-
+ }
+
IJoin* GetJoin() override {
return Source->GetJoin();
}
- bool IsCompositeSource() const override {
- return true;
- }
-
- ISource* GetCompositeSource() override {
- return CompositeSelect;
- }
-
+ bool IsCompositeSource() const override {
+ return true;
+ }
+
+ ISource* GetCompositeSource() override {
+ return CompositeSelect;
+ }
+
bool CalculateGroupingHint(TContext& ctx, const TVector<TString>& columns, ui64& hint) const override {
Y_UNUSED(ctx);
- hint = 0;
- if (GroupByColumns.empty()) {
+ hint = 0;
+ if (GroupByColumns.empty()) {
for (const auto& groupByNode: GroupBy) {
- auto namePtr = groupByNode->GetColumnName();
- YQL_ENSURE(namePtr);
- GroupByColumns.insert(*namePtr);
- }
- }
- for (const auto& column: columns) {
- hint <<= 1;
+ auto namePtr = groupByNode->GetColumnName();
+ YQL_ENSURE(namePtr);
+ GroupByColumns.insert(*namePtr);
+ }
+ }
+ for (const auto& column: columns) {
+ hint <<= 1;
if (!GroupByColumns.contains(column)) {
- hint += 1;
- }
- }
- return true;
- }
-
- void FinishColumns() override {
- Source->FinishColumns();
- }
-
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ hint += 1;
+ }
+ }
+ return true;
+ }
+
+ void FinishColumns() override {
+ Source->FinishColumns();
+ }
+
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
if (const TString* columnName = column.GetColumnName()) {
if (columnName && IsExprAlias(*columnName)) {
return true;
}
}
- return Source->AddColumn(ctx, column);
- }
-
- TPtr DoClone() const final {
- return Holder.Get() ? new TNestedProxySource(Pos, CloneContainer(GroupBy), Holder->CloneSource()) :
- new TNestedProxySource(CompositeSelect, CloneContainer(GroupBy));
- }
-
-private:
- TCompositeSelect* CompositeSelect;
- TSourcePtr Holder;
+ return Source->AddColumn(ctx, column);
+ }
+
+ TPtr DoClone() const final {
+ return Holder.Get() ? new TNestedProxySource(Pos, CloneContainer(GroupBy), Holder->CloneSource()) :
+ new TNestedProxySource(CompositeSelect, CloneContainer(GroupBy));
+ }
+
+private:
+ TCompositeSelect* CompositeSelect;
+ TSourcePtr Holder;
TVector<TNodePtr> GroupBy;
mutable TSet<TString> GroupByColumns;
-};
-
+};
+
namespace {
TSourcePtr DoBuildSelectCore(
- TContext& ctx,
+ TContext& ctx,
TPosition pos,
TSourcePtr originalSource,
TSourcePtr source,
@@ -2460,7 +2460,7 @@ TSourcePtr DoBuildSelectCore(
bool assumeSorted,
const TVector<TSortSpecificationPtr>& orderBy,
TNodePtr having,
- TWinSpecs&& winSpecs,
+ TWinSpecs&& winSpecs,
THoppingWindowSpecPtr hoppingWindowSpec,
TVector<TNodePtr>&& terms,
bool distinct,
@@ -2468,52 +2468,52 @@ TSourcePtr DoBuildSelectCore(
bool selectStream,
const TWriteSettings& settings
) {
- if (groupBy.empty() || !groupBy.front()->ContentListPtr()) {
+ if (groupBy.empty() || !groupBy.front()->ContentListPtr()) {
return new TSelectCore(pos, std::move(source), groupByExpr, groupBy, compactGroupBy, assumeSorted,
orderBy, having, winSpecs, hoppingWindowSpec, terms, distinct, without, selectStream, settings);
- }
- if (groupBy.size() == 1) {
- /// actualy no big idea to use grouping function in this case (result allways 0)
- auto contentPtr = groupBy.front()->ContentListPtr();
+ }
+ if (groupBy.size() == 1) {
+ /// actualy no big idea to use grouping function in this case (result allways 0)
+ auto contentPtr = groupBy.front()->ContentListPtr();
source = new TNestedProxySource(pos, *contentPtr, source);
return DoBuildSelectCore(ctx, pos, originalSource, source, groupByExpr, *contentPtr, compactGroupBy,
assumeSorted, orderBy, having, std::move(winSpecs),
hoppingWindowSpec, std::move(terms), distinct, std::move(without), selectStream, settings);
- }
- /// \todo some smart merge logic, generalize common part of grouping (expr, flatten, etc)?
+ }
+ /// \todo some smart merge logic, generalize common part of grouping (expr, flatten, etc)?
TIntrusivePtr<TCompositeSelect> compositeSelect = new TCompositeSelect(pos, std::move(source), originalSource->CloneSource(), settings);
- size_t totalGroups = 0;
+ size_t totalGroups = 0;
TVector<TSourcePtr> subselects;
TVector<TNodePtr> groupingCols;
- for (auto& grouping: groupBy) {
- auto contentPtr = grouping->ContentListPtr();
+ for (auto& grouping: groupBy) {
+ auto contentPtr = grouping->ContentListPtr();
TVector<TNodePtr> cache(1, nullptr);
- if (!contentPtr) {
- cache[0] = grouping;
- contentPtr = &cache;
- }
+ if (!contentPtr) {
+ cache[0] = grouping;
+ contentPtr = &cache;
+ }
groupingCols.insert(groupingCols.end(), contentPtr->cbegin(), contentPtr->cend());
TSourcePtr proxySource = new TNestedProxySource(compositeSelect.Get(), CloneContainer(*contentPtr));
- if (!subselects.empty()) {
- /// clone terms for others usage
+ if (!subselects.empty()) {
+ /// clone terms for others usage
TVector<TNodePtr> termsCopy;
- for (const auto& term: terms) {
- termsCopy.emplace_back(term->Clone());
- }
- std::swap(terms, termsCopy);
- }
- totalGroups += contentPtr->size();
+ for (const auto& term: terms) {
+ termsCopy.emplace_back(term->Clone());
+ }
+ std::swap(terms, termsCopy);
+ }
+ totalGroups += contentPtr->size();
TSelectCore* selectCore = new TSelectCore(pos, std::move(proxySource), CloneContainer(groupByExpr),
CloneContainer(*contentPtr), compactGroupBy, assumeSorted, orderBy, SafeClone(having), winSpecs,
hoppingWindowSpec, terms, distinct, without, selectStream, settings);
- subselects.emplace_back(selectCore);
- }
- if (totalGroups > ctx.PragmaGroupByLimit) {
- ctx.Error(pos) << "Unable to GROUP BY more than " << ctx.PragmaGroupByLimit << " groups, you try use " << totalGroups << " groups";
- return nullptr;
- }
+ subselects.emplace_back(selectCore);
+ }
+ if (totalGroups > ctx.PragmaGroupByLimit) {
+ ctx.Error(pos) << "Unable to GROUP BY more than " << ctx.PragmaGroupByLimit << " groups, you try use " << totalGroups << " groups";
+ return nullptr;
+ }
compositeSelect->SetSubselects(std::move(subselects), std::move(groupingCols), CloneContainer(groupByExpr));
- return compositeSelect;
+ return compositeSelect;
}
}
@@ -2546,10 +2546,10 @@ public:
: IRealSource(pos)
, Sources(std::move(sources))
, Settings(settings)
- {
- }
+ {
+ }
- const TColumns* GetColumns() const override {
+ const TColumns* GetColumns() const override {
return IRealSource::GetColumns();
}
@@ -2561,7 +2561,7 @@ public:
ISource::GetInputTables(tableList);
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
bool first = true;
for (auto& s: Sources) {
s->UseAsInner();
@@ -2578,7 +2578,7 @@ public:
return true;
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
auto res = ctx.PositionalUnionAll ? Y("UnionAllPositional") : Y("UnionAll");
for (auto& s: Sources) {
auto input = s->Build(ctx);
@@ -2590,20 +2590,20 @@ public:
return res;
}
-
- bool IsStream() const override {
- for (auto& s: Sources) {
- if (!s->IsStream()) {
- return false;
- }
- }
- return true;
- }
-
- TNodePtr DoClone() const final {
+
+ bool IsStream() const override {
+ for (auto& s: Sources) {
+ if (!s->IsStream()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ TNodePtr DoClone() const final {
return MakeIntrusive<TUnionAll>(Pos, CloneContainer(Sources), Settings);
- }
-
+ }
+
bool IsSelect() const override {
return true;
}
@@ -2621,15 +2621,15 @@ TSourcePtr BuildUnionAll(TPosition pos, TVector<TSourcePtr>&& sources, const TWr
return new TUnionAll(pos, std::move(sources), settings);
}
-class TOverWindowSource: public IProxySource {
-public:
+class TOverWindowSource: public IProxySource {
+public:
TOverWindowSource(TPosition pos, const TString& windowName, ISource* origSource)
- : IProxySource(pos, origSource)
- , WindowName(windowName)
- {
- Source->SetLabel(origSource->GetLabel());
- }
-
+ : IProxySource(pos, origSource)
+ , WindowName(windowName)
+ {
+ Source->SetLabel(origSource->GetLabel());
+ }
+
TString MakeLocalName(const TString& name) override {
return Source->MakeLocalName(name);
}
@@ -2638,84 +2638,84 @@ public:
return Source->AddTmpWindowColumn(column);
}
- bool AddAggregation(TContext& ctx, TAggregationPtr aggr) override {
- if (aggr->IsOverWindow()) {
- return Source->AddAggregationOverWindow(ctx, WindowName, aggr);
- }
- return Source->AddAggregation(ctx, aggr);
- }
-
- bool AddFuncOverWindow(TContext& ctx, TNodePtr expr) override {
- return Source->AddFuncOverWindow(ctx, WindowName, expr);
- }
-
- bool IsOverWindowSource() const override {
- return true;
- }
-
- TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
- return Source->AddColumn(ctx, column);
- }
-
- TNodePtr Build(TContext& ctx) override {
+ bool AddAggregation(TContext& ctx, TAggregationPtr aggr) override {
+ if (aggr->IsOverWindow()) {
+ return Source->AddAggregationOverWindow(ctx, WindowName, aggr);
+ }
+ return Source->AddAggregation(ctx, aggr);
+ }
+
+ bool AddFuncOverWindow(TContext& ctx, TNodePtr expr) override {
+ return Source->AddFuncOverWindow(ctx, WindowName, expr);
+ }
+
+ bool IsOverWindowSource() const override {
+ return true;
+ }
+
+ TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
+ return Source->AddColumn(ctx, column);
+ }
+
+ TNodePtr Build(TContext& ctx) override {
Y_UNUSED(ctx);
- Y_FAIL("Unexpected call");
- }
-
- const TString* GetWindowName() const override {
- return &WindowName;
- }
-
- TWindowSpecificationPtr FindWindowSpecification(TContext& ctx, const TString& windowName) const override {
- return Source->FindWindowSpecification(ctx, windowName);
- }
-
+ Y_FAIL("Unexpected call");
+ }
+
+ const TString* GetWindowName() const override {
+ return &WindowName;
+ }
+
+ TWindowSpecificationPtr FindWindowSpecification(TContext& ctx, const TString& windowName) const override {
+ return Source->FindWindowSpecification(ctx, windowName);
+ }
+
TNodePtr GetSessionWindowSpec() const override {
return Source->GetSessionWindowSpec();
}
- TNodePtr DoClone() const final {
- return {};
- }
-
-private:
+ TNodePtr DoClone() const final {
+ return {};
+ }
+
+private:
const TString WindowName;
-};
-
+};
+
TSourcePtr BuildOverWindowSource(TPosition pos, const TString& windowName, ISource* origSource) {
- return new TOverWindowSource(pos, windowName, origSource);
-}
-
-class TSkipTakeNode final: public TAstListNode {
+ return new TOverWindowSource(pos, windowName, origSource);
+}
+
+class TSkipTakeNode final: public TAstListNode {
public:
- TSkipTakeNode(TPosition pos, const TNodePtr& skip, const TNodePtr& take)
+ TSkipTakeNode(TPosition pos, const TNodePtr& skip, const TNodePtr& take)
: TAstListNode(pos)
{
TNodePtr select(AstNode("select"));
- if (skip) {
- select = Y("Skip", select, skip);
+ if (skip) {
+ select = Y("Skip", select, skip);
}
- Add("let", "select", Y("Take", select, take));
+ Add("let", "select", Y("Take", select, take));
}
- TPtr DoClone() const final {
- return {};
+ TPtr DoClone() const final {
+ return {};
}
};
-TNodePtr BuildSkipTake(TPosition pos, const TNodePtr& skip, const TNodePtr& take) {
+TNodePtr BuildSkipTake(TPosition pos, const TNodePtr& skip, const TNodePtr& take) {
return new TSkipTakeNode(pos, skip, take);
}
class TSelect: public IProxySource {
public:
- TSelect(TPosition pos, TSourcePtr source, TNodePtr skipTake)
+ TSelect(TPosition pos, TSourcePtr source, TNodePtr skipTake)
: IProxySource(pos, source.Get())
- , Source(std::move(source))
+ , Source(std::move(source))
, SkipTake(skipTake)
- {}
+ {}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
Source->SetLabel(Label);
if (AsInner) {
Source->UseAsInner();
@@ -2739,15 +2739,15 @@ public:
return true;
}
- TNodePtr Build(TContext& ctx) override {
+ TNodePtr Build(TContext& ctx) override {
auto input = Source->Build(ctx);
if (!input) {
return nullptr;
}
- const auto label = "select";
- auto block(Y(Y("let", label, input)));
+ const auto label = "select";
+ auto block(Y(Y("let", label, input)));
- auto sortNode = Source->BuildSort(ctx, label);
+ auto sortNode = Source->BuildSort(ctx, label);
if (sortNode && !IgnoreSort()) {
block = L(block, sortNode);
}
@@ -2767,7 +2767,7 @@ public:
block = L(block, removeNode);
}
- block = L(block, Y("return", label));
+ block = L(block, Y("return", label));
return Y("block", Q(block));
}
@@ -2788,13 +2788,13 @@ public:
return SetSamplingRate(ctx, samplingRate);
}
- bool IsSelect() const override {
- return Source->IsSelect();
- }
-
- TPtr DoClone() const final {
- return MakeIntrusive<TSelect>(Pos, Source->CloneSource(), SafeClone(SkipTake));
- }
+ bool IsSelect() const override {
+ return Source->IsSelect();
+ }
+
+ TPtr DoClone() const final {
+ return MakeIntrusive<TSelect>(Pos, Source->CloneSource(), SafeClone(SkipTake));
+ }
protected:
bool IgnoreSort() const {
return AsInner && !SkipTake && EOrderKind::Sort == Source->GetOrderKind();
@@ -2805,16 +2805,16 @@ protected:
TSourcePtr FakeSource;
};
-TSourcePtr BuildSelect(TPosition pos, TSourcePtr source, TNodePtr skipTake) {
- return new TSelect(pos, std::move(source), skipTake);
+TSourcePtr BuildSelect(TPosition pos, TSourcePtr source, TNodePtr skipTake) {
+ return new TSelect(pos, std::move(source), skipTake);
}
-class TSelectResultNode final: public TAstListNode {
+class TSelectResultNode final: public TAstListNode {
public:
TSelectResultNode(TPosition pos, TSourcePtr source, bool writeResult, bool inSubquery,
TScopedStatePtr scoped)
: TAstListNode(pos)
- , Source(std::move(source))
+ , Source(std::move(source))
, WriteResult(writeResult)
, InSubquery(inSubquery)
, Scoped(scoped)
@@ -2827,12 +2827,12 @@ public:
return true;
}
- bool DoInit(TContext& ctx, ISource* src) override {
+ bool DoInit(TContext& ctx, ISource* src) override {
if (!Source->Init(ctx, src)) {
return false;
}
- src = Source.Get();
+ src = Source.Get();
TTableList tableList;
Source->GetInputTables(tableList);
@@ -2874,7 +2874,7 @@ public:
}
auto columns = Source->GetColumns();
- if (columns && !columns->All && !(columns->QualifiedAll && ctx.SimpleColumns)) {
+ if (columns && !columns->All && !(columns->QualifiedAll && ctx.SimpleColumns)) {
auto list = Y();
for (auto& c: columns->List) {
if (c.EndsWith('*')) {
@@ -2913,12 +2913,12 @@ public:
return true;
}
- TPtr DoClone() const final {
- return {};
- }
+ TPtr DoClone() const final {
+ return {};
+ }
protected:
- TSourcePtr Source;
-
+ TSourcePtr Source;
+
const bool WriteResult;
const bool InSubquery;
TScopedStatePtr Scoped;
diff --git a/ydb/library/yql/sql/v1/sql.cpp b/ydb/library/yql/sql/v1/sql.cpp
index f6e71f6b26..ab5a864788 100644
--- a/ydb/library/yql/sql/v1/sql.cpp
+++ b/ydb/library/yql/sql/v1/sql.cpp
@@ -30,9 +30,9 @@
#include <util/string/ascii.h>
#include <util/string/cast.h>
#include <util/string/reverse.h>
-#include <util/string/split.h>
+#include <util/string/split.h>
#include <util/string/hex.h>
-#include <util/string/join.h>
+#include <util/string/join.h>
#if defined(_tsan_enabled_)
#include <util/system/mutex.h>
@@ -54,13 +54,13 @@ static TPosition GetPos(const TToken& token) {
return TPosition(token.GetColumn(), token.GetLine());
}
-template <typename TToken>
-TIdentifier GetIdentifier(TTranslation& ctx, const TToken& node) {
- auto token = node.GetToken1();
- return TIdentifier(TPosition(token.GetColumn(), token.GetLine()), ctx.Identifier(token));
-}
-
-inline TIdentifier GetKeywordId(TTranslation& ctx, const TRule_keyword& node) {
+template <typename TToken>
+TIdentifier GetIdentifier(TTranslation& ctx, const TToken& node) {
+ auto token = node.GetToken1();
+ return TIdentifier(TPosition(token.GetColumn(), token.GetLine()), ctx.Identifier(token));
+}
+
+inline TIdentifier GetKeywordId(TTranslation& ctx, const TRule_keyword& node) {
// keyword:
// keyword_compat
// | keyword_expr_uncompat
@@ -73,9 +73,9 @@ inline TIdentifier GetKeywordId(TTranslation& ctx, const TRule_keyword& node) {
// | keyword_schema_uncompat
//;
switch (node.Alt_case()) {
- case TRule_keyword::kAltKeyword1:
+ case TRule_keyword::kAltKeyword1:
return GetIdentifier(ctx, node.GetAlt_keyword1().GetRule_keyword_compat1());
- case TRule_keyword::kAltKeyword2:
+ case TRule_keyword::kAltKeyword2:
return GetIdentifier(ctx, node.GetAlt_keyword2().GetRule_keyword_expr_uncompat1());
case TRule_keyword::kAltKeyword3:
return GetIdentifier(ctx, node.GetAlt_keyword3().GetRule_keyword_table_uncompat1());
@@ -96,10 +96,10 @@ inline TIdentifier GetKeywordId(TTranslation& ctx, const TRule_keyword& node) {
}
}
-inline TString GetKeyword(TTranslation& ctx, const TRule_keyword& node) {
- return GetKeywordId(ctx, node).Name;
-}
-
+inline TString GetKeyword(TTranslation& ctx, const TRule_keyword& node) {
+ return GetKeywordId(ctx, node).Name;
+}
+
template <typename TRule>
inline TString GetKeyword(TTranslation& ctx, const TRule& node) {
return GetIdentifier(ctx, node).Name;
@@ -113,15 +113,15 @@ static TString Id(const TRule_identifier& node, TTranslation& ctx) {
static TString Id(const TRule_id& node, TTranslation& ctx) {
// id: identifier | keyword;
switch (node.Alt_case()) {
- case TRule_id::kAltId1:
+ case TRule_id::kAltId1:
return Id(node.GetAlt_id1().GetRule_identifier1(), ctx);
- case TRule_id::kAltId2:
- return GetKeyword(ctx, node.GetAlt_id2().GetRule_keyword1());
- default:
+ case TRule_id::kAltId2:
+ return GetKeyword(ctx, node.GetAlt_id2().GetRule_keyword1());
+ default:
Y_FAIL("You should change implementation according to grammar changes");
- }
-}
-
+ }
+}
+
static TString Id(const TRule_id_or_type& node, TTranslation& ctx) {
switch (node.Alt_case()) {
case TRule_id_or_type::kAltIdOrType1:
@@ -133,7 +133,7 @@ static TString Id(const TRule_id_or_type& node, TTranslation& ctx) {
}
}
-static TString Id(const TRule_id_schema& node, TTranslation& ctx) {
+static TString Id(const TRule_id_schema& node, TTranslation& ctx) {
//id_schema:
// identifier
// | keyword_compat
@@ -147,9 +147,9 @@ static TString Id(const TRule_id_schema& node, TTranslation& ctx) {
// // | keyword_schema_uncompat
//;
switch (node.Alt_case()) {
- case TRule_id_schema::kAltIdSchema1:
+ case TRule_id_schema::kAltIdSchema1:
return Id(node.GetAlt_id_schema1().GetRule_identifier1(), ctx);
- case TRule_id_schema::kAltIdSchema2:
+ case TRule_id_schema::kAltIdSchema2:
return GetKeyword(ctx, node.GetAlt_id_schema2().GetRule_keyword_compat1());
case TRule_id_schema::kAltIdSchema3:
return GetKeyword(ctx, node.GetAlt_id_schema3().GetRule_keyword_expr_uncompat1());
@@ -241,7 +241,7 @@ static TString Id(const TRule_id_table_or_type& node, TTranslation& ctx) {
}
}
-static TString Id(const TRule_id_expr& node, TTranslation& ctx) {
+static TString Id(const TRule_id_expr& node, TTranslation& ctx) {
//id_expr:
// identifier
// | keyword_compat
@@ -254,12 +254,12 @@ static TString Id(const TRule_id_expr& node, TTranslation& ctx) {
// | keyword_hint_uncompat
// | keyword_schema_uncompat
//;
- switch (node.Alt_case()) {
- case TRule_id_expr::kAltIdExpr1:
+ switch (node.Alt_case()) {
+ case TRule_id_expr::kAltIdExpr1:
return Id(node.GetAlt_id_expr1().GetRule_identifier1(), ctx);
- case TRule_id_expr::kAltIdExpr2:
+ case TRule_id_expr::kAltIdExpr2:
return GetKeyword(ctx, node.GetAlt_id_expr2().GetRule_keyword_compat1());
- case TRule_id_expr::kAltIdExpr3:
+ case TRule_id_expr::kAltIdExpr3:
return GetKeyword(ctx, node.GetAlt_id_expr3().GetRule_keyword_alter_uncompat1());
case TRule_id_expr::kAltIdExpr4:
return GetKeyword(ctx, node.GetAlt_id_expr4().GetRule_keyword_in_uncompat1());
@@ -269,11 +269,11 @@ static TString Id(const TRule_id_expr& node, TTranslation& ctx) {
return GetKeyword(ctx, node.GetAlt_id_expr6().GetRule_keyword_hint_uncompat1());
case TRule_id_expr::kAltIdExpr7:
return GetKeyword(ctx, node.GetAlt_id_expr7().GetRule_keyword_schema_uncompat1());
- default:
+ default:
Y_FAIL("You should change implementation according to grammar changes");
- }
-}
-
+ }
+}
+
static bool IsQuotedId(const TRule_id_expr& node, TTranslation& ctx) {
if (node.Alt_case() != TRule_id_expr::kAltIdExpr1) {
return false;
@@ -515,12 +515,12 @@ static TIdentifier IdEx(const TRule& node, TTranslation& ctx) {
}
static TString OptIdPrefixAsStr(const TRule_opt_id_prefix& node, TTranslation& ctx, const TString& defaultStr = {}) {
- if (!node.HasBlock1()) {
- return defaultStr;
- }
+ if (!node.HasBlock1()) {
+ return defaultStr;
+ }
return Id(node.GetBlock1().GetRule_an_id1(), ctx);
-}
-
+}
+
static TString OptIdPrefixAsStr(const TRule_opt_id_prefix_or_type& node, TTranslation& ctx, const TString& defaultStr = {}) {
if (!node.HasBlock1()) {
return defaultStr;
@@ -530,11 +530,11 @@ static TString OptIdPrefixAsStr(const TRule_opt_id_prefix_or_type& node, TTransl
static void PureColumnListStr(const TRule_pure_column_list& node, TTranslation& ctx, TVector<TString>& outList) {
outList.push_back(Id(node.GetRule_an_id2(), ctx));
- for (auto& block: node.GetBlock3()) {
+ for (auto& block: node.GetBlock3()) {
outList.push_back(Id(block.GetRule_an_id2(), ctx));
- }
-}
-
+ }
+}
+
static bool NamedNodeImpl(const TRule_bind_parameter& node, TString& name, TTranslation& ctx) {
// bind_parameter: DOLLAR an_id_or_type;
auto id = Id(node.GetRule_an_id_or_type2(), ctx);
@@ -720,25 +720,25 @@ static std::pair<TString, TString> TableKeyImpl(const TRule_table_key& node, TTr
return TableKeyImpl(std::make_pair(hasAt, name), view, ctx);
}
-/// \return optional prefix
+/// \return optional prefix
static TString ColumnNameAsStr(TTranslation& ctx, const TRule_column_name& node, TString& id) {
id = Id(node.GetRule_an_id2(), ctx);
- return OptIdPrefixAsStr(node.GetRule_opt_id_prefix1(), ctx);
-}
-
+ return OptIdPrefixAsStr(node.GetRule_opt_id_prefix1(), ctx);
+}
+
static TString ColumnNameAsSingleStr(TTranslation& ctx, const TRule_column_name& node) {
TString body;
const TString prefix = ColumnNameAsStr(ctx, node, body);
- return prefix ? prefix + '.' + body : body;
-}
-
+ return prefix ? prefix + '.' + body : body;
+}
+
static void FillTargetList(TTranslation& ctx, const TRule_set_target_list& node, TVector<TString>& targetList) {
- targetList.push_back(ColumnNameAsSingleStr(ctx, node.GetRule_set_target2().GetRule_column_name1()));
- for (auto& block: node.GetBlock3()) {
- targetList.push_back(ColumnNameAsSingleStr(ctx, block.GetRule_set_target2().GetRule_column_name1()));
- }
-}
-
+ targetList.push_back(ColumnNameAsSingleStr(ctx, node.GetRule_set_target2().GetRule_column_name1()));
+ for (auto& block: node.GetBlock3()) {
+ targetList.push_back(ColumnNameAsSingleStr(ctx, block.GetRule_set_target2().GetRule_column_name1()));
+ }
+}
+
TTableHints GetContextHints(TContext& ctx) {
TTableHints hints;
if (ctx.PragmaInferSchema) {
@@ -774,14 +774,14 @@ static bool ValidateForCounters(const TString& input) {
}
static bool IsColumnsOnly(const TVector<TSortSpecificationPtr>& container) {
- for (const auto& elem: container) {
- if (!elem->OrderExpr->GetColumnName()) {
- return false;
- }
- }
- return true;
-}
-
+ for (const auto& elem: container) {
+ if (!elem->OrderExpr->GetColumnName()) {
+ return false;
+ }
+ }
+ return true;
+}
+
static bool PackageVersionFromString(const TString& s, ui32& version) {
if (s == "release") {
version = 0;
@@ -808,15 +808,15 @@ protected:
, Mode(mode)
{
/// \todo remove NSQLTranslation::ESqlMode params
- YQL_ENSURE(ctx.Settings.Mode == mode);
+ YQL_ENSURE(ctx.Settings.Mode == mode);
}
protected:
- enum class EExpr {
- Regular,
- GroupBy,
- SqlLambdaParams,
- };
+ enum class EExpr {
+ Regular,
+ GroupBy,
+ SqlLambdaParams,
+ };
TNodePtr NamedExpr(const TRule_named_expr& node, EExpr exprMode = EExpr::Regular);
bool NamedExprList(const TRule_named_expr_list& node, TVector<TNodePtr>& exprs, EExpr exprMode = EExpr::Regular);
bool BindList(const TRule_bind_parameter_list& node, TVector<TSymbolNameWithPos>& bindNames);
@@ -826,7 +826,7 @@ protected:
TVector<TSymbolNameWithPos>& aliases);
bool NamedBindParam(const TRule_named_bind_parameter& node, TSymbolNameWithPos& name, TSymbolNameWithPos& alias);
TNodePtr NamedNode(const TRule_named_nodes_stmt& rule, TVector<TSymbolNameWithPos>& names);
-
+
bool ImportStatement(const TRule_import_stmt& stmt, TVector<TString>* namesPtr = nullptr);
TNodePtr DoStatement(const TRule_do_stmt& stmt, bool makeLambda, const TVector<TString>& args = {});
bool DefineActionOrSubqueryStatement(const TRule_define_action_or_subquery_stmt& stmt);
@@ -838,7 +838,7 @@ protected:
TMaybe<TSourcePtr> AsTableImpl(const TRule_table_ref& node);
bool ClusterExpr(const TRule_cluster_expr& node, bool allowWildcard, TString& service, TDeferredAtom& cluster);
bool ClusterExprOrBinding(const TRule_cluster_expr& node, TString& service, TDeferredAtom& cluster, bool& isBinding);
-
+
TMaybe<TColumnSchema> ColumnSchemaImpl(const TRule_column_schema& node);
bool CreateTableEntry(const TRule_create_table_entry& node, TCreateTableParameters& params);
@@ -895,13 +895,13 @@ protected:
class TSqlExpression: public TSqlTranslation {
public:
- enum class ESmartParenthesis {
- Default,
- GroupBy,
- InStatement,
- SqlLambdaParams,
- };
-
+ enum class ESmartParenthesis {
+ Default,
+ GroupBy,
+ InStatement,
+ SqlLambdaParams,
+ };
+
TSqlExpression(TContext& ctx, NSQLTranslation::ESqlMode mode)
: TSqlTranslation(ctx, mode)
{
@@ -925,10 +925,10 @@ public:
}
}
- void SetSmartParenthesisMode(ESmartParenthesis mode) {
- SmartParenthesisMode = mode;
- }
-
+ void SetSmartParenthesisMode(ESmartParenthesis mode) {
+ SmartParenthesisMode = mode;
+ }
+
TMaybe<TExprOrIdent> LiteralExpr(const TRule_literal_value& node);
private:
struct TTrailingQuestions {
@@ -972,7 +972,7 @@ private:
bool SqlLambdaParams(const TNodePtr& node, TVector<TSymbolNameWithPos>& args, ui32& optionalArgumentsCount);
bool SqlLambdaExprBody(TContext& ctx, const TRule_lambda_body& node, TVector<TNodePtr>& exprSeq);
bool SqlLambdaExprBody(TContext& ctx, const TRule_expr& node, TVector<TNodePtr>& exprSeq);
-
+
TNodePtr KeyExpr(const TRule_key_expr& node) {
TSqlExpression expr(Ctx, Mode);
return expr.Build(node.GetRule_expr2());
@@ -1014,10 +1014,10 @@ private:
auto getNode = [](const TRule_neq_subexpr::TBlock2& b) -> const TRule_bit_subexpr& { return b.GetRule_bit_subexpr2(); };
auto result = BinOpList(node.GetRule_bit_subexpr1(), getNode, node.GetBlock2().begin(), node.GetBlock2().end(), tail);
- if (!result) {
+ if (!result) {
return {};
- }
- if (node.HasBlock3()) {
+ }
+ if (node.HasBlock3()) {
auto& block = node.GetBlock3();
if (block.Alt_case() == TRule_neq_subexpr::TBlock3::kAlt1) {
TSqlExpression altExpr(Ctx, Mode);
@@ -1028,9 +1028,9 @@ private:
const TVector<TNodePtr> args({result, altResult});
Token(block.GetAlt1().GetRule_double_question1().GetToken1());
result = BuildBuiltinFunc(Ctx, Ctx.Pos(), "Coalesce", args);
- }
- }
- return result;
+ }
+ }
+ return result;
}
TNodePtr SubExpr(const TRule_eq_subexpr& node, const TTrailingQuestions& tail) {
@@ -1053,7 +1053,7 @@ private:
template <typename TNode, typename TGetNode, typename TIter>
TNodePtr BinOpList(const TNode& node, TGetNode getNode, TIter begin, TIter end, const TTrailingQuestions& tail);
-
+
template <typename TGetNode, typename TIter>
TNodePtr BinOpList(const TRule_bit_subexpr& node, TGetNode getNode, TIter begin, TIter end, const TTrailingQuestions& tail);
@@ -1061,16 +1061,16 @@ private:
TNodePtr BinOpList(const TRule_eq_subexpr& node, TGetNode getNode, TIter begin, TIter end, const TTrailingQuestions& tail);
TNodePtr BinOperList(const TString& opName, TVector<TNodePtr>::const_iterator begin, TVector<TNodePtr>::const_iterator end) const;
-
+
struct TCaseBranch {
TNodePtr Pred;
TNodePtr Value;
};
TCaseBranch ReduceCaseBranches(TVector<TCaseBranch>::const_iterator begin, TVector<TCaseBranch>::const_iterator end) const;
- template <typename TNode, typename TGetNode, typename TIter>
+ template <typename TNode, typename TGetNode, typename TIter>
TNodePtr BinOper(const TString& operName, const TNode& node, TGetNode getNode, TIter begin, TIter end, const TTrailingQuestions& tail);
-
+
TNodePtr SqlInExpr(const TRule_in_expr& node, const TTrailingQuestions& tail);
void UnexpectedQuestionToken(const TTrailingQuestions& tail) {
@@ -1078,35 +1078,35 @@ private:
Ctx.Error(tail.Pos) << "Unexpected token '?' at the end of expression";
}
- TNodePtr SmartParenthesis(const TRule_smart_parenthesis& node);
-
- ESmartParenthesis SmartParenthesisMode = ESmartParenthesis::Default;
-
+ TNodePtr SmartParenthesis(const TRule_smart_parenthesis& node);
+
+ ESmartParenthesis SmartParenthesisMode = ESmartParenthesis::Default;
+
THashMap<TString, TNodePtr> ExprShortcuts;
};
-class TSqlCallExpr: public TSqlTranslation {
-public:
+class TSqlCallExpr: public TSqlTranslation {
+public:
TSqlCallExpr(TContext& ctx, NSQLTranslation::ESqlMode mode)
- : TSqlTranslation(ctx, mode)
- {
- }
-
+ : TSqlTranslation(ctx, mode)
+ {
+ }
+
TSqlCallExpr(const TSqlCallExpr& call, const TVector<TNodePtr>& args)
- : TSqlTranslation(call.Ctx, call.Mode)
- , Pos(call.Pos)
- , Func(call.Func)
- , Module(call.Module)
- , Node(call.Node)
- , Args(args)
- , AggMode(call.AggMode)
+ : TSqlTranslation(call.Ctx, call.Mode)
+ , Pos(call.Pos)
+ , Func(call.Func)
+ , Module(call.Module)
+ , Node(call.Node)
+ , Args(args)
+ , AggMode(call.AggMode)
, DistinctAllowed(call.DistinctAllowed)
, UsingCallExpr(call.UsingCallExpr)
, IsExternalCall(call.IsExternalCall)
, CallConfig(call.CallConfig)
- {
- }
-
+ {
+ }
+
void AllowDistinct() {
DistinctAllowed = true;
}
@@ -1118,37 +1118,37 @@ public:
bool Init(const TRule_value_constructor& node);
bool Init(const TRule_invoke_expr& node);
bool ConfigureExternalCall(const TRule_external_call_settings& node);
- void IncCounters();
-
+ void IncCounters();
+
TNodePtr BuildUdf(bool forReduce) {
auto result = Node ? Node : BuildCallable(Pos, Module, Func, Args, forReduce);
if (to_lower(Module) == "tensorflow" && Func == "RunBatch") {
Args.erase(Args.begin() + 2);
}
return result;
- }
-
- TNodePtr BuildCall() {
+ }
+
+ TNodePtr BuildCall() {
TVector<TNodePtr> args;
bool warnOnYqlNameSpace = true;
if (Node && !Node->FuncName()) {
- Module = "YQL";
- Func = NamedArgs.empty() ? "Apply" : "NamedApply";
+ Module = "YQL";
+ Func = NamedArgs.empty() ? "Apply" : "NamedApply";
warnOnYqlNameSpace = false;
- args.push_back(Node);
- }
+ args.push_back(Node);
+ }
if (Node && Node->FuncName()) {
Module = Node->ModuleName() ? *Node->ModuleName() : "YQL";
Func = *Node->FuncName();
}
- bool mustUseNamed = !NamedArgs.empty();
- if (mustUseNamed) {
+ bool mustUseNamed = !NamedArgs.empty();
+ if (mustUseNamed) {
if (Node && !Node->FuncName()) {
- mustUseNamed = false;
- }
- args.emplace_back(BuildTuple(Pos, PositionalArgs));
- args.emplace_back(BuildStructure(Pos, NamedArgs));
+ mustUseNamed = false;
+ }
+ args.emplace_back(BuildTuple(Pos, PositionalArgs));
+ args.emplace_back(BuildStructure(Pos, NamedArgs));
} else if (IsExternalCall) {
Func = "SqlExternalFunction";
if (Args.size() < 2 || Args.size() > 3) {
@@ -1166,98 +1166,98 @@ public:
auto configNode = new TExternalFunctionConfig(Pos, CallConfig);
auto configList = new TAstListNodeImpl(Pos, { new TAstAtomNodeImpl(Pos, "quote", 0), configNode });
args.push_back(configList);
- } else {
- args.insert(args.end(), Args.begin(), Args.end());
- }
+ } else {
+ args.insert(args.end(), Args.begin(), Args.end());
+ }
auto result = BuildBuiltinFunc(Ctx, Pos, Func, args, Module, AggMode, &mustUseNamed, warnOnYqlNameSpace);
- if (mustUseNamed) {
- Error() << "Named args are used for call, but unsupported by function: " << Func;
- return nullptr;
- }
+ if (mustUseNamed) {
+ Error() << "Named args are used for call, but unsupported by function: " << Func;
+ return nullptr;
+ }
if (WindowName) {
result = BuildCalcOverWindow(Pos, WindowName, result);
}
- return result;
- }
-
- TPosition GetPos() const {
- return Pos;
- }
-
+ return result;
+ }
+
+ TPosition GetPos() const {
+ return Pos;
+ }
+
const TVector<TNodePtr>& GetArgs() const {
- return Args;
- }
-
- void SetOverWindow() {
- YQL_ENSURE(AggMode == EAggregateMode::Normal);
- AggMode = EAggregateMode::OverWindow;
- }
-
- void SetIgnoreNulls() {
- Func += "_IgnoreNulls";
- }
-
+ return Args;
+ }
+
+ void SetOverWindow() {
+ YQL_ENSURE(AggMode == EAggregateMode::Normal);
+ AggMode = EAggregateMode::OverWindow;
+ }
+
+ void SetIgnoreNulls() {
+ Func += "_IgnoreNulls";
+ }
+
bool IsExternal() {
return IsExternalCall;
}
-private:
+private:
bool ExtractCallParam(const TRule_external_call_param& node);
bool FillArg(const TString& module, const TString& func, size_t& idx, const TRule_named_expr& node);
bool FillArgs(const TRule_named_expr_list& node);
private:
- TPosition Pos;
- TString Func;
- TString Module;
- TNodePtr Node;
+ TPosition Pos;
+ TString Func;
+ TString Module;
+ TNodePtr Node;
TVector<TNodePtr> Args;
TVector<TNodePtr> PositionalArgs;
TVector<TNodePtr> NamedArgs;
- EAggregateMode AggMode = EAggregateMode::Normal;
+ EAggregateMode AggMode = EAggregateMode::Normal;
TString WindowName;
bool DistinctAllowed = false;
bool UsingCallExpr = false;
bool IsExternalCall = false;
TFunctionConfig CallConfig;
-};
-
+};
+
TNodePtr TSqlTranslation::NamedExpr(const TRule_named_expr& node, EExpr exprMode) {
TSqlExpression expr(Ctx, Mode);
- if (exprMode == EExpr::GroupBy) {
- expr.SetSmartParenthesisMode(TSqlExpression::ESmartParenthesis::GroupBy);
- } else if (exprMode == EExpr::SqlLambdaParams) {
- expr.SetSmartParenthesisMode(TSqlExpression::ESmartParenthesis::SqlLambdaParams);
- }
+ if (exprMode == EExpr::GroupBy) {
+ expr.SetSmartParenthesisMode(TSqlExpression::ESmartParenthesis::GroupBy);
+ } else if (exprMode == EExpr::SqlLambdaParams) {
+ expr.SetSmartParenthesisMode(TSqlExpression::ESmartParenthesis::SqlLambdaParams);
+ }
TNodePtr exprNode(expr.Build(node.GetRule_expr1()));
- if (!exprNode) {
- Ctx.IncrementMonCounter("sql_errors", "NamedExprInvalid");
- return nullptr;
- }
- if (node.HasBlock2()) {
+ if (!exprNode) {
+ Ctx.IncrementMonCounter("sql_errors", "NamedExprInvalid");
+ return nullptr;
+ }
+ if (node.HasBlock2()) {
exprNode = SafeClone(exprNode);
exprNode->SetLabel(Id(node.GetBlock2().GetRule_an_id_or_type2(), *this));
- }
- return exprNode;
-}
-
+ }
+ return exprNode;
+}
+
bool TSqlTranslation::NamedExprList(const TRule_named_expr_list& node, TVector<TNodePtr>& exprs, EExpr exprMode) {
exprs.emplace_back(NamedExpr(node.GetRule_named_expr1(), exprMode));
- if (!exprs.back()) {
- return false;
- }
- for (auto& b: node.GetBlock2()) {
+ if (!exprs.back()) {
+ return false;
+ }
+ for (auto& b: node.GetBlock2()) {
exprs.emplace_back(NamedExpr(b.GetRule_named_expr2(), exprMode));
- if (!exprs.back()) {
- return false;
- }
- }
- return true;
-}
-
+ if (!exprs.back()) {
+ return false;
+ }
+ }
+ return true;
+}
+
bool TSqlTranslation::BindList(const TRule_bind_parameter_list& node, TVector<TSymbolNameWithPos>& bindNames) {
bindNames.clear();
@@ -1292,7 +1292,7 @@ bool TSqlTranslation::ActionOrSubqueryArgs(const TRule_action_or_subquery_args&
}
bindNames.emplace_back(TSymbolNameWithPos{name, Ctx.Pos()});
- for (auto& b: node.GetBlock2()) {
+ for (auto& b: node.GetBlock2()) {
if (!NamedNodeImpl(b.GetRule_opt_bind_parameter2(), name, isOptional, *this)) {
return false;
}
@@ -1304,21 +1304,21 @@ bool TSqlTranslation::ActionOrSubqueryArgs(const TRule_action_or_subquery_args&
return false;
}
bindNames.emplace_back(TSymbolNameWithPos{name, Ctx.Pos()});
- }
- return true;
-}
-
+ }
+ return true;
+}
+
bool TSqlTranslation::ModulePath(const TRule_module_path& node, TVector<TString>& path) {
- if (node.HasBlock1()) {
- path.emplace_back(TString());
- }
+ if (node.HasBlock1()) {
+ path.emplace_back(TString());
+ }
path.emplace_back(Id(node.GetRule_an_id2(), *this));
- for (auto& b: node.GetBlock3()) {
+ for (auto& b: node.GetBlock3()) {
path.emplace_back(Id(b.GetRule_an_id2(), *this));
- }
- return true;
-}
-
+ }
+ return true;
+}
+
bool TSqlTranslation::NamedBindList(const TRule_named_bind_parameter_list& node, TVector<TSymbolNameWithPos>& names,
TVector<TSymbolNameWithPos>& aliases)
{
@@ -1333,31 +1333,31 @@ bool TSqlTranslation::NamedBindList(const TRule_named_bind_parameter_list& node,
names.push_back(name);
aliases.push_back(alias);
- for (auto& b: node.GetBlock2()) {
+ for (auto& b: node.GetBlock2()) {
if (!NamedBindParam(b.GetRule_named_bind_parameter2(), name, alias)) {
return false;
}
names.push_back(name);
aliases.push_back(alias);
- }
+ }
return true;
-}
-
+}
+
bool TSqlTranslation::NamedBindParam(const TRule_named_bind_parameter& node, TSymbolNameWithPos& name, TSymbolNameWithPos& alias) {
name = alias = {};
if (!NamedNodeImpl(node.GetRule_bind_parameter1(), name.Name, *this)) {
return false;
}
name.Pos = Ctx.Pos();
- if (node.HasBlock2()) {
+ if (node.HasBlock2()) {
if (!NamedNodeImpl(node.GetBlock2().GetRule_bind_parameter2(), alias.Name, *this)) {
return false;
}
alias.Pos = Ctx.Pos();
- }
+ }
return true;
-}
-
+}
+
TMaybe<TTableArg> TSqlTranslation::TableArgImpl(const TRule_table_arg& node) {
TTableArg ret;
ret.HasAt = node.HasBlock1();
@@ -2814,27 +2814,27 @@ TNodePtr TSqlTranslation::TypeNode(const TRule_type_name_composite& node) {
}
bool Expr(TSqlExpression& sqlExpr, TVector<TNodePtr>& exprNodes, const TRule_expr& node) {
- TNodePtr exprNode = sqlExpr.Build(node);
- if (!exprNode) {
- return false;
- }
- exprNodes.push_back(exprNode);
- return true;
-}
-
+ TNodePtr exprNode = sqlExpr.Build(node);
+ if (!exprNode) {
+ return false;
+ }
+ exprNodes.push_back(exprNode);
+ return true;
+}
+
bool ExprList(TSqlExpression& sqlExpr, TVector<TNodePtr>& exprNodes, const TRule_expr_list& node) {
- if (!Expr(sqlExpr, exprNodes, node.GetRule_expr1())) {
- return false;
- }
- for (auto b: node.GetBlock2()) {
- sqlExpr.Token(b.GetToken1());
- if (!Expr(sqlExpr, exprNodes, b.GetRule_expr2())) {
- return false;
- }
- }
- return true;
-}
-
+ if (!Expr(sqlExpr, exprNodes, node.GetRule_expr1())) {
+ return false;
+ }
+ for (auto b: node.GetBlock2()) {
+ sqlExpr.Token(b.GetToken1());
+ if (!Expr(sqlExpr, exprNodes, b.GetRule_expr2())) {
+ return false;
+ }
+ }
+ return true;
+}
+
TNodePtr TSqlTranslation::ValueConstructorLiteral(const TRule_value_constructor_literal& node) {
return BuildLiteralSmartString(Ctx, Token(node.GetToken1()));
}
@@ -3239,14 +3239,14 @@ bool TSqlCallExpr::Init(const TRule_using_call_expr& node) {
const auto& block = node.GetBlock1();
switch (block.Alt_case()) {
case TRule_using_call_expr::TBlock1::kAlt1: {
- auto& subblock = block.GetAlt1().GetBlock1();
+ auto& subblock = block.GetAlt1().GetBlock1();
Module = Id(subblock.GetRule_an_id_or_type1(), *this);
Func = Id(subblock.GetRule_an_id_or_type3(), *this);
break;
}
case TRule_using_call_expr::TBlock1::kAlt2: {
Func = Id(block.GetAlt2().GetRule_an_id_expr1(), *this);
- break;
+ break;
}
case TRule_using_call_expr::TBlock1::kAlt3: {
TString bindName;
@@ -3494,7 +3494,7 @@ private:
TSourcePtr SingleSource(const TRule_single_source& node, const TVector<TString>& derivedColumns, TPosition derivedColumnsPos, bool unorderedSubquery);
TSourcePtr NamedSingleSource(const TRule_named_single_source& node, bool unorderedSubquery);
bool FlattenByArg(const TString& sourceLabel, TVector<TNodePtr>& flattenByColumns, TVector<TNodePtr>& flattenByExprs, const TRule_flatten_by_arg& node);
- TSourcePtr FlattenSource(const TRule_flatten_source& node);
+ TSourcePtr FlattenSource(const TRule_flatten_source& node);
TSourcePtr JoinSource(const TRule_join_source& node);
bool JoinOp(ISource* join, const TRule_join_source::TBlock3& block, TMaybe<TPosition> anyPos);
TNodePtr JoinExpr(ISource*, const TRule_join_constraint& node);
@@ -3510,7 +3510,7 @@ private:
TMaybe<TSelectKindPlacement> placement, TVector<TSortSpecificationPtr>& selectOpOrederBy, bool& selectOpAssumeOrderBy);
bool WindowDefinition(const TRule_window_definition& node, TWinSpecs& winSpecs);
- bool WindowClause(const TRule_window_clause& node, TWinSpecs& winSpecs);
+ bool WindowClause(const TRule_window_clause& node, TWinSpecs& winSpecs);
struct TSelectKindResult {
TSourcePtr Source;
@@ -3552,45 +3552,45 @@ private:
bool BuildRow(const TRule_values_source_row& inRow, TVector<TNodePtr>& outRow);
};
-class TGroupByClause: public TSqlTranslation {
- enum class EGroupByFeatures {
- Begin,
- Ordinary = Begin,
- Expression,
- Rollup,
- Cube,
- GroupingSet,
- Empty,
- End,
- };
- typedef TEnumBitSet<EGroupByFeatures, static_cast<int>(EGroupByFeatures::Begin), static_cast<int>(EGroupByFeatures::End)> TGroupingSetFeatures;
-
- class TGroupByClauseCtx: public TSimpleRefCount<TGroupByClauseCtx> {
- public:
- typedef TIntrusivePtr<TGroupByClauseCtx> TPtr;
-
- TGroupingSetFeatures GroupFeatures;
+class TGroupByClause: public TSqlTranslation {
+ enum class EGroupByFeatures {
+ Begin,
+ Ordinary = Begin,
+ Expression,
+ Rollup,
+ Cube,
+ GroupingSet,
+ Empty,
+ End,
+ };
+ typedef TEnumBitSet<EGroupByFeatures, static_cast<int>(EGroupByFeatures::Begin), static_cast<int>(EGroupByFeatures::End)> TGroupingSetFeatures;
+
+ class TGroupByClauseCtx: public TSimpleRefCount<TGroupByClauseCtx> {
+ public:
+ typedef TIntrusivePtr<TGroupByClauseCtx> TPtr;
+
+ TGroupingSetFeatures GroupFeatures;
TMap<TString, TNodePtr> NodeAliases;
- size_t UnnamedCount = 0;
- };
-
-public:
+ size_t UnnamedCount = 0;
+ };
+
+public:
TGroupByClause(TContext& ctx, NSQLTranslation::ESqlMode mode, TGroupByClauseCtx::TPtr groupSetContext = {})
- : TSqlTranslation(ctx, mode)
- , GroupSetContext(groupSetContext ? groupSetContext : TGroupByClauseCtx::TPtr(new TGroupByClauseCtx()))
+ : TSqlTranslation(ctx, mode)
+ , GroupSetContext(groupSetContext ? groupSetContext : TGroupByClauseCtx::TPtr(new TGroupByClauseCtx()))
, CompactGroupBy(false)
- {}
-
+ {}
+
bool Build(const TRule_group_by_clause& node, bool stream);
bool ParseList(const TRule_grouping_element_list& groupingListNode, EGroupByFeatures featureContext);
-
+
void SetFeatures(const TString& field) const;
TVector<TNodePtr>& Content();
TMap<TString, TNodePtr>& Aliases();
THoppingWindowSpecPtr GetHoppingWindow() const;
bool IsCompactGroupBy() const;
-private:
+private:
TMaybe<TVector<TNodePtr>> MultiplyGroupingSets(const TVector<TNodePtr>& lhs, const TVector<TNodePtr>& rhs) const;
bool ResolveGroupByAndGrouping();
bool GroupingElement(const TRule_grouping_element& node, EGroupByFeatures featureContext);
@@ -3598,60 +3598,60 @@ private:
bool OrdinaryGroupingSet(const TRule_ordinary_grouping_set& node, EGroupByFeatures featureContext);
bool OrdinaryGroupingSetList(const TRule_ordinary_grouping_set_list& node, EGroupByFeatures featureContext);
bool HoppingWindow(const TRule_hopping_window_specification& node);
-
+
bool AllowUnnamed(TPosition pos, EGroupByFeatures featureContext);
-
- TGroupingSetFeatures& Features();
- const TGroupingSetFeatures& Features() const;
+
+ TGroupingSetFeatures& Features();
+ const TGroupingSetFeatures& Features() const;
bool AddAlias(const TString& label, const TNodePtr& node);
TString GenerateGroupByExprName();
bool IsAutogenerated(const TString* name) const;
-
+
TVector<TNodePtr> GroupBySet;
- TGroupByClauseCtx::TPtr GroupSetContext;
+ TGroupByClauseCtx::TPtr GroupSetContext;
THoppingWindowSpecPtr HoppingWindowSpec; // stream queries
static const TString AutogenerateNamePrefix;
bool CompactGroupBy;
-};
-
+};
+
const TString TGroupByClause::AutogenerateNamePrefix = "group";
-
+
bool ParseNumbers(TContext& ctx, const TString& strOrig, ui64& value, TString& suffix) {
- const auto str = to_lower(strOrig);
+ const auto str = to_lower(strOrig);
const auto strLen = str.size();
- ui64 base = 10;
- if (strLen > 2 && str[0] == '0') {
- const auto formatChar = str[1];
- if (formatChar == 'x') {
- base = 16;
- } else if (formatChar == 'o') {
- base = 8;
- } else if (formatChar == 'b') {
- base = 2;
- }
- }
- if (strLen > 1) {
- auto iter = str.cend() - 1;
+ ui64 base = 10;
+ if (strLen > 2 && str[0] == '0') {
+ const auto formatChar = str[1];
+ if (formatChar == 'x') {
+ base = 16;
+ } else if (formatChar == 'o') {
+ base = 8;
+ } else if (formatChar == 'b') {
+ base = 2;
+ }
+ }
+ if (strLen > 1) {
+ auto iter = str.cend() - 1;
if (*iter == 'l' || *iter == 's' || *iter == 't' || /* deprecated */ *iter == 'b') {
- --iter;
- }
+ --iter;
+ }
if (*iter == 'u') {
- --iter;
- }
+ --iter;
+ }
suffix = TString(++iter, str.cend());
- }
- value = 0;
+ }
+ value = 0;
const TString digString(str.begin() + (base == 10 ? 0 : 2), str.end() - suffix.size());
- for (const char& cur: digString) {
+ for (const char& cur: digString) {
const ui64 curDigit = Char2DigitTable[static_cast<int>(cur)];
if (curDigit >= base) {
- ctx.Error(ctx.Pos()) << "Failed to parse number from string: " << strOrig << ", char: '" << cur <<
- "' is out of base: " << base;
- return false;
- }
+ ctx.Error(ctx.Pos()) << "Failed to parse number from string: " << strOrig << ", char: '" << cur <<
+ "' is out of base: " << base;
+ return false;
+ }
ui64 curValue = value;
- value *= base;
+ value *= base;
bool overflow = ((value / base) != curValue);
if (!overflow) {
curValue = value;
@@ -3660,62 +3660,62 @@ bool ParseNumbers(TContext& ctx, const TString& strOrig, ui64& value, TString& s
}
if (overflow) {
- ctx.Error(ctx.Pos()) << "Failed to parse number from string: " << strOrig << ", number limit overflow";
- return false;
- }
- }
- return true;
-}
-
-TNodePtr LiteralNumber(TContext& ctx, const TRule_integer& node) {
+ ctx.Error(ctx.Pos()) << "Failed to parse number from string: " << strOrig << ", number limit overflow";
+ return false;
+ }
+ }
+ return true;
+}
+
+TNodePtr LiteralNumber(TContext& ctx, const TRule_integer& node) {
const TString intergerString = ctx.Token(node.GetToken1());
- ui64 value;
+ ui64 value;
TString suffix;
- if (!ParseNumbers(ctx, intergerString, value, suffix)) {
- return {};
- }
+ if (!ParseNumbers(ctx, intergerString, value, suffix)) {
+ return {};
+ }
- const bool noSpaceForInt32 = value >> 31;
- const bool noSpaceForInt64 = value >> 63;
- if (suffix == "") {
+ const bool noSpaceForInt32 = value >> 31;
+ const bool noSpaceForInt64 = value >> 63;
+ if (suffix == "") {
bool implicitType = true;
- if (noSpaceForInt64) {
+ if (noSpaceForInt64) {
return new TLiteralNumberNode<ui64>(ctx.Pos(), "Uint64", ToString(value), implicitType);
- } else if (noSpaceForInt32) {
+ } else if (noSpaceForInt32) {
return new TLiteralNumberNode<i64>(ctx.Pos(), "Int64", ToString(value), implicitType);
- }
+ }
return new TLiteralNumberNode<i32>(ctx.Pos(), "Int32", ToString(value), implicitType);
- } else if (suffix == "u") {
- return new TLiteralNumberNode<ui32>(ctx.Pos(), "Uint32", ToString(value));
- } else if (suffix == "ul") {
- return new TLiteralNumberNode<ui64>(ctx.Pos(), "Uint64", ToString(value));
+ } else if (suffix == "u") {
+ return new TLiteralNumberNode<ui32>(ctx.Pos(), "Uint32", ToString(value));
+ } else if (suffix == "ul") {
+ return new TLiteralNumberNode<ui64>(ctx.Pos(), "Uint64", ToString(value));
} else if (suffix == "ut") {
return new TLiteralNumberNode<ui8>(ctx.Pos(), "Uint8", ToString(value));
} else if (suffix == "t") {
return new TLiteralNumberNode<i8>(ctx.Pos(), "Int8", ToString(value));
- } else if (suffix == "l") {
- return new TLiteralNumberNode<i64>(ctx.Pos(), "Int64", ToString(value));
+ } else if (suffix == "l") {
+ return new TLiteralNumberNode<i64>(ctx.Pos(), "Int64", ToString(value));
} else if (suffix == "us") {
return new TLiteralNumberNode<ui16>(ctx.Pos(), "Uint16", ToString(value));
} else if (suffix == "s") {
return new TLiteralNumberNode<i16>(ctx.Pos(), "Int16", ToString(value));
- } else {
- ctx.Error(ctx.Pos()) << "Failed to parse number from string: " << intergerString << ", invalid suffix: " << suffix;
- return {};
- }
-}
-
-TNodePtr LiteralReal(TContext& ctx, const TRule_real& node) {
+ } else {
+ ctx.Error(ctx.Pos()) << "Failed to parse number from string: " << intergerString << ", invalid suffix: " << suffix;
+ return {};
+ }
+}
+
+TNodePtr LiteralReal(TContext& ctx, const TRule_real& node) {
const TString value(ctx.Token(node.GetToken1()));
- YQL_ENSURE(!value.empty());
+ YQL_ENSURE(!value.empty());
const auto lastValue = value[value.size() - 1];
- if (lastValue == 'f' || lastValue == 'F') {
+ if (lastValue == 'f' || lastValue == 'F') {
return new TLiteralNumberNode<float>(ctx.Pos(), "Float", value.substr(0, value.size()-1));
- } else {
- return new TLiteralNumberNode<double>(ctx.Pos(), "Double", value);
- }
-}
-
+ } else {
+ return new TLiteralNumberNode<double>(ctx.Pos(), "Double", value);
+ }
+}
+
TMaybe<TExprOrIdent> TSqlExpression::LiteralExpr(const TRule_literal_value& node) {
TExprOrIdent result;
switch (node.Alt_case()) {
@@ -4607,7 +4607,7 @@ TMaybe<TExprOrIdent> TSqlExpression::AtomExpr(const TRule_atom_expr& node, const
case TRule_atom_expr::kAltAtomExpr2:
result.Expr = BindParameterRule(node.GetAlt_atom_expr2().GetRule_bind_parameter1(), tail);
break;
- case TRule_atom_expr::kAltAtomExpr3:
+ case TRule_atom_expr::kAltAtomExpr3:
result.Expr = LambdaRule(node.GetAlt_atom_expr3().GetRule_lambda1());
break;
case TRule_atom_expr::kAltAtomExpr4:
@@ -4774,18 +4774,18 @@ bool TSqlExpression::SqlLambdaParams(const TNodePtr& node, TVector<TSymbolNameWi
args.clear();
optionalArgumentsCount = 0;
auto errMsg = TStringBuf("Invalid lambda arguments syntax. Lambda arguments should start with '$' as named value.");
- auto tupleNodePtr = dynamic_cast<TTupleNode*>(node.Get());
- if (!tupleNodePtr) {
- Ctx.Error(node->GetPos()) << errMsg;
- return false;
- }
+ auto tupleNodePtr = dynamic_cast<TTupleNode*>(node.Get());
+ if (!tupleNodePtr) {
+ Ctx.Error(node->GetPos()) << errMsg;
+ return false;
+ }
THashSet<TString> dupArgsChecker;
- for (const auto& argPtr: tupleNodePtr->Elements()) {
- auto contentPtr = argPtr->GetAtomContent();
- if (!contentPtr || !contentPtr->StartsWith("$")) {
- Ctx.Error(argPtr->GetPos()) << errMsg;
- return false;
- }
+ for (const auto& argPtr: tupleNodePtr->Elements()) {
+ auto contentPtr = argPtr->GetAtomContent();
+ if (!contentPtr || !contentPtr->StartsWith("$")) {
+ Ctx.Error(argPtr->GetPos()) << errMsg;
+ return false;
+ }
if (argPtr->IsOptionalArg()) {
++optionalArgumentsCount;
} else if (optionalArgumentsCount > 0) {
@@ -4794,14 +4794,14 @@ bool TSqlExpression::SqlLambdaParams(const TNodePtr& node, TVector<TSymbolNameWi
}
if (!IsAnonymousName(*contentPtr) && !dupArgsChecker.insert(*contentPtr).second) {
- Ctx.Error(argPtr->GetPos()) << "Duplicate lambda argument parametr: '" << *contentPtr << "'.";
- return false;
- }
+ Ctx.Error(argPtr->GetPos()) << "Duplicate lambda argument parametr: '" << *contentPtr << "'.";
+ return false;
+ }
args.push_back(TSymbolNameWithPos{*contentPtr, argPtr->GetPos()});
- }
- return true;
-}
-
+ }
+ return true;
+}
+
bool TSqlExpression::SqlLambdaExprBody(TContext& ctx, const TRule_expr& node, TVector<TNodePtr>& exprSeq) {
TSqlExpression expr(ctx, ctx.Settings.Mode);
TNodePtr nodeExpr = expr.Build(node);
@@ -4817,19 +4817,19 @@ bool TSqlExpression::SqlLambdaExprBody(TContext& ctx, const TRule_lambda_body& n
TVector<TString> localNames;
bool hasError = false;
for (auto& block: node.GetBlock2()) {
- const auto& rule = block.GetRule_lambda_stmt1();
- switch (rule.Alt_case()) {
- case TRule_lambda_stmt::kAltLambdaStmt1: {
+ const auto& rule = block.GetRule_lambda_stmt1();
+ switch (rule.Alt_case()) {
+ case TRule_lambda_stmt::kAltLambdaStmt1: {
TVector<TSymbolNameWithPos> names;
auto nodeExpr = NamedNode(rule.GetAlt_lambda_stmt1().GetRule_named_nodes_stmt1(), names);
- if (!nodeExpr) {
+ if (!nodeExpr) {
hasError = true;
continue;
- } else if (nodeExpr->GetSource()) {
- ctx.Error() << "SELECT is not supported inside lambda body";
+ } else if (nodeExpr->GetSource()) {
+ ctx.Error() << "SELECT is not supported inside lambda body";
hasError = true;
continue;
- }
+ }
if (names.size() > 1) {
auto ref = ctx.MakeName("tie");
exprSeq.push_back(nodeExpr->Y("EnsureTupleSize", nodeExpr, nodeExpr->Q(ToString(names.size()))));
@@ -4848,18 +4848,18 @@ bool TSqlExpression::SqlLambdaExprBody(TContext& ctx, const TRule_lambda_body& n
localNames.push_back(symbol.Name);
exprSeq.push_back(nodeExpr);
}
- break;
- }
- case TRule_lambda_stmt::kAltLambdaStmt2: {
+ break;
+ }
+ case TRule_lambda_stmt::kAltLambdaStmt2: {
if (!ImportStatement(rule.GetAlt_lambda_stmt2().GetRule_import_stmt1(), &localNames)) {
hasError = true;
- }
- break;
- }
- default:
+ }
+ break;
+ }
+ default:
Y_FAIL("SampleClause: does not correspond to grammar changes");
- }
- }
+ }
+ }
TNodePtr nodeExpr;
if (!hasError) {
@@ -4870,13 +4870,13 @@ bool TSqlExpression::SqlLambdaExprBody(TContext& ctx, const TRule_lambda_body& n
PopNamedNode(name);
}
- if (!nodeExpr) {
- return false;
- }
- exprSeq.push_back(nodeExpr);
- return true;
-}
-
+ if (!nodeExpr) {
+ return false;
+ }
+ exprSeq.push_back(nodeExpr);
+ return true;
+}
+
TNodePtr TSqlExpression::SubExpr(const TRule_con_subexpr& node, const TTrailingQuestions& tail) {
// con_subexpr: unary_subexpr | unary_op unary_subexpr;
switch (node.Alt_case()) {
@@ -4911,9 +4911,9 @@ TNodePtr TSqlExpression::SubExpr(const TRule_con_subexpr& node, const TTrailingQ
TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node, const TTrailingQuestions& tail) {
// xor_subexpr: eq_subexpr cond_expr?;
TNodePtr res(SubExpr(node.GetRule_eq_subexpr1(), node.HasBlock2() ? TTrailingQuestions{} : tail));
- if (!res) {
- return {};
- }
+ if (!res) {
+ return {};
+ }
TPosition pos(Ctx.Pos());
if (node.HasBlock2()) {
auto cond = node.GetBlock2().GetRule_cond_expr1();
@@ -4923,9 +4923,9 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node, const TTrailingQ
const bool notMatch = matchOp.HasBlock1();
const TCiString& opName = Token(matchOp.GetRule_match_op2().GetToken1());
const auto& pattern = SubExpr(cond.GetAlt_cond_expr1().GetRule_eq_subexpr3(), matchOp.HasBlock4() ? TTrailingQuestions{} : tail);
- if (!pattern) {
- return {};
- }
+ if (!pattern) {
+ return {};
+ }
TNodePtr isMatch;
if (opName == "like" || opName == "ilike") {
const TString* escapeLiteral = nullptr;
@@ -4936,9 +4936,9 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node, const TTrailingQ
if (matchOp.HasBlock4()) {
const auto& escapeBlock = matchOp.GetBlock4();
TNodePtr escapeExpr = SubExpr(escapeBlock.GetRule_eq_subexpr2(), tail);
- if (!escapeExpr) {
- return {};
- }
+ if (!escapeExpr) {
+ return {};
+ }
escapeLiteral = escapeExpr->GetLiteral("String");
escapeNode = escapeExpr;
if (escapeLiteral) {
@@ -4960,7 +4960,7 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node, const TTrailingQ
Error() << "please choose ASCII character";
return nullptr;
}
- escaperArgs.push_back(BuildLiteralRawString(pos, *escapeLiteral));
+ escaperArgs.push_back(BuildLiteralRawString(pos, *escapeLiteral));
} else {
Ctx.IncrementMonCounter("sql_errors", "LikeNotLiteralEscape");
Error() << "ESCAPE clause requires String literal argument";
@@ -4977,12 +4977,12 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node, const TTrailingQ
auto csOption = BuildStructure(pos, { csModeLiteral });
auto optionsApply = new TCallNodeImpl(pos, "NamedApply", { re2options, BuildTuple(pos, {}), csOption });
- const TNodePtr escapedPattern = new TCallNodeImpl(pos, "Apply", { escaperArgs });
+ const TNodePtr escapedPattern = new TCallNodeImpl(pos, "Apply", { escaperArgs });
auto list = new TAstListNodeImpl(pos, { escapedPattern, optionsApply });
auto runConfig = new TAstListNodeImpl(pos, { new TAstAtomNodeImpl(pos, "quote", 0), list });
const auto& matcher = BuildUdf(Ctx, pos, "Re2", "Match", { runConfig });
- isMatch = new TCallNodeImpl(pos, "Apply", { matcher, res });
+ isMatch = new TCallNodeImpl(pos, "Apply", { matcher, res });
bool isUtf8 = false;
const TString* literalPattern = pattern->GetLiteral("String");
@@ -5051,7 +5051,7 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node, const TTrailingQ
const auto& matcher = Ctx.PragmaRegexUseRe2 ?
BuildUdf(Ctx, pos, "Re2", opName == "match" ? "Match" : "Grep", {BuildTuple(pos, {pattern, BuildLiteralNull(pos)})}):
BuildUdf(Ctx, pos, "Pcre", opName == "match" ? "BacktrackingMatch" : "BacktrackingGrep", { pattern });
- isMatch = new TCallNodeImpl(pos, "Apply", { matcher, res });
+ isMatch = new TCallNodeImpl(pos, "Apply", { matcher, res });
if (opName != "match") {
Ctx.IncrementMonCounter("sql_features", notMatch ? "NotRegexp" : "Regexp");
} else {
@@ -5065,15 +5065,15 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node, const TTrailingQ
return (notMatch && isMatch) ? isMatch->ApplyUnaryOp(Ctx, pos, "Not") : isMatch;
}
case TRule_cond_expr::kAltCondExpr2: {
- auto altInExpr = cond.GetAlt_cond_expr2();
- const bool notIn = altInExpr.HasBlock1();
+ auto altInExpr = cond.GetAlt_cond_expr2();
+ const bool notIn = altInExpr.HasBlock1();
auto hints = BuildTuple(pos, {});
if (altInExpr.HasBlock3()) {
Ctx.IncrementMonCounter("sql_features", "IsCompactHint");
auto sizeHint = BuildTuple(pos, { BuildQuotedAtom(pos, "isCompact", NYql::TNodeFlags::Default) });
hints = BuildTuple(pos, { sizeHint });
}
- TSqlExpression inSubexpr(Ctx, Mode);
+ TSqlExpression inSubexpr(Ctx, Mode);
auto inRight = inSubexpr.SqlInExpr(altInExpr.GetRule_in_expr4(), tail);
auto isIn = BuildBuiltinFunc(Ctx, pos, "In", {res, inRight, hints});
Ctx.IncrementMonCounter("sql_features", notIn ? "NotIn" : "In");
@@ -5137,19 +5137,19 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node, const TTrailingQ
}
TNodePtr TSqlExpression::BinOperList(const TString& opName, TVector<TNodePtr>::const_iterator begin, TVector<TNodePtr>::const_iterator end) const {
- TPosition pos(Ctx.Pos());
- const size_t opCount = end - begin;
- Y_VERIFY_DEBUG(opCount >= 2);
- if (opCount == 2) {
+ TPosition pos(Ctx.Pos());
+ const size_t opCount = end - begin;
+ Y_VERIFY_DEBUG(opCount >= 2);
+ if (opCount == 2) {
return BuildBinaryOp(Ctx, pos, opName, *begin, *(begin+1));
- } if (opCount == 3) {
+ } if (opCount == 3) {
return BuildBinaryOp(Ctx, pos, opName, BuildBinaryOp(Ctx, pos, opName, *begin, *(begin+1)), *(begin+2));
- } else {
- auto mid = begin + opCount / 2;
+ } else {
+ auto mid = begin + opCount / 2;
return BuildBinaryOp(Ctx, pos, opName, BinOperList(opName, begin, mid), BinOperList(opName, mid, end));
- }
-}
-
+ }
+}
+
TSqlExpression::TCaseBranch TSqlExpression::ReduceCaseBranches(TVector<TCaseBranch>::const_iterator begin, TVector<TCaseBranch>::const_iterator end) const {
YQL_ENSURE(begin < end);
const size_t branchCount = end - begin;
@@ -5175,21 +5175,21 @@ TSqlExpression::TCaseBranch TSqlExpression::ReduceCaseBranches(TVector<TCaseBran
template <typename TNode, typename TGetNode, typename TIter>
TNodePtr TSqlExpression::BinOper(const TString& opName, const TNode& node, TGetNode getNode, TIter begin, TIter end, const TTrailingQuestions& tail) {
- if (begin == end) {
+ if (begin == end) {
return SubExpr(node, tail);
- }
- Ctx.IncrementMonCounter("sql_binary_operations", opName);
- const size_t listSize = end - begin;
+ }
+ Ctx.IncrementMonCounter("sql_binary_operations", opName);
+ const size_t listSize = end - begin;
TVector<TNodePtr> nodes;
- nodes.reserve(1 + listSize);
+ nodes.reserve(1 + listSize);
nodes.push_back(SubExpr(node, {}));
- for (; begin != end; ++begin) {
+ for (; begin != end; ++begin) {
nodes.push_back(SubExpr(getNode(*begin), (begin + 1 == end) ? tail : TTrailingQuestions{}));
- }
- return BinOperList(opName, nodes.begin(), nodes.end());
-}
-
-template <typename TNode, typename TGetNode, typename TIter>
+ }
+ return BinOperList(opName, nodes.begin(), nodes.end());
+}
+
+template <typename TNode, typename TGetNode, typename TIter>
TNodePtr TSqlExpression::BinOpList(const TNode& node, TGetNode getNode, TIter begin, TIter end, const TTrailingQuestions& tail) {
TNodePtr partialResult = SubExpr(node, (begin == end) ? tail : TTrailingQuestions{});
while (begin != end) {
@@ -5403,58 +5403,58 @@ TNodePtr TSqlExpression::BinOpList(const TRule_eq_subexpr& node, TGetNode getNod
}
TNodePtr TSqlExpression::SqlInExpr(const TRule_in_expr& node, const TTrailingQuestions& tail) {
- TSqlExpression expr(Ctx, Mode);
- expr.SetSmartParenthesisMode(TSqlExpression::ESmartParenthesis::InStatement);
+ TSqlExpression expr(Ctx, Mode);
+ expr.SetSmartParenthesisMode(TSqlExpression::ESmartParenthesis::InStatement);
auto result = expr.UnaryExpr(node.GetRule_in_unary_subexpr1(), tail);
- return result;
-}
-
-TNodePtr TSqlExpression::SmartParenthesis(const TRule_smart_parenthesis& node) {
+ return result;
+}
+
+TNodePtr TSqlExpression::SmartParenthesis(const TRule_smart_parenthesis& node) {
TVector<TNodePtr> exprs;
- Token(node.GetToken1());
- const TPosition pos(Ctx.Pos());
- const bool isTuple = node.HasBlock3();
- bool expectTuple = SmartParenthesisMode == ESmartParenthesis::InStatement;
- EExpr mode = EExpr::Regular;
+ Token(node.GetToken1());
+ const TPosition pos(Ctx.Pos());
+ const bool isTuple = node.HasBlock3();
+ bool expectTuple = SmartParenthesisMode == ESmartParenthesis::InStatement;
+ EExpr mode = EExpr::Regular;
if (SmartParenthesisMode == ESmartParenthesis::SqlLambdaParams) {
- mode = EExpr::SqlLambdaParams;
- expectTuple = true;
- }
+ mode = EExpr::SqlLambdaParams;
+ expectTuple = true;
+ }
if (node.HasBlock2() && !NamedExprList(node.GetBlock2().GetRule_named_expr_list1(), exprs, mode)) {
- return {};
- }
-
- bool hasAliases = false;
- bool hasUnnamed = false;
+ return {};
+ }
+
+ bool hasAliases = false;
+ bool hasUnnamed = false;
for (const auto& expr: exprs) {
- if (expr->GetLabel()) {
- hasAliases = true;
- } else {
- hasUnnamed = true;
- }
- if (hasAliases && hasUnnamed && SmartParenthesisMode != ESmartParenthesis::GroupBy) {
- Ctx.IncrementMonCounter("sql_errors", "AnonymousStructMembers");
- Ctx.Error(pos) << "Structure does not allow anonymous members";
- return nullptr;
- }
- }
- if (exprs.size() == 1 && hasUnnamed && !isTuple && !expectTuple) {
- return exprs.back();
- }
- if (SmartParenthesisMode == ESmartParenthesis::GroupBy) {
- /// \todo support nested tuple\struct
- if (isTuple) {
- Ctx.IncrementMonCounter("sql_errors", "SimpleTupleInGroupBy");
- Ctx.Error(pos) << "Unable to use tuple in group by clause";
- return nullptr;
- }
- Ctx.IncrementMonCounter("sql_features", "ListOfNamedNode");
- return BuildListOfNamedNodes(pos, std::move(exprs));
- }
- Ctx.IncrementMonCounter("sql_features", hasUnnamed ? "SimpleTuple" : "SimpleStruct");
+ if (expr->GetLabel()) {
+ hasAliases = true;
+ } else {
+ hasUnnamed = true;
+ }
+ if (hasAliases && hasUnnamed && SmartParenthesisMode != ESmartParenthesis::GroupBy) {
+ Ctx.IncrementMonCounter("sql_errors", "AnonymousStructMembers");
+ Ctx.Error(pos) << "Structure does not allow anonymous members";
+ return nullptr;
+ }
+ }
+ if (exprs.size() == 1 && hasUnnamed && !isTuple && !expectTuple) {
+ return exprs.back();
+ }
+ if (SmartParenthesisMode == ESmartParenthesis::GroupBy) {
+ /// \todo support nested tuple\struct
+ if (isTuple) {
+ Ctx.IncrementMonCounter("sql_errors", "SimpleTupleInGroupBy");
+ Ctx.Error(pos) << "Unable to use tuple in group by clause";
+ return nullptr;
+ }
+ Ctx.IncrementMonCounter("sql_features", "ListOfNamedNode");
+ return BuildListOfNamedNodes(pos, std::move(exprs));
+ }
+ Ctx.IncrementMonCounter("sql_features", hasUnnamed ? "SimpleTuple" : "SimpleStruct");
return (hasUnnamed || expectTuple || exprs.size() == 0) ? BuildTuple(pos, exprs) : BuildStructure(pos, exprs);
-}
-
+}
+
TNodePtr TSqlTranslation::NamedNode(const TRule_named_nodes_stmt& rule, TVector<TSymbolNameWithPos>& names) {
// named_nodes_stmt: bind_parameter_list EQUALS (expr | subselect_stmt);
// subselect_stmt: (LPAREN select_stmt RPAREN | select_unparenthesized_stmt);
@@ -5462,7 +5462,7 @@ TNodePtr TSqlTranslation::NamedNode(const TRule_named_nodes_stmt& rule, TVector<
return {};
}
- TNodePtr nodeExpr = nullptr;
+ TNodePtr nodeExpr = nullptr;
switch (rule.GetBlock3().Alt_case()) {
case TRule_named_nodes_stmt::TBlock3::kAlt1: {
TSqlExpression expr(Ctx, Mode);
@@ -5473,7 +5473,7 @@ TNodePtr TSqlTranslation::NamedNode(const TRule_named_nodes_stmt& rule, TVector<
case TRule_named_nodes_stmt::TBlock3::kAlt2:{
const auto& subselect_rule = rule.GetBlock3().GetAlt2().GetRule_subselect_stmt1();
- TSqlSelect expr(Ctx, Mode);
+ TSqlSelect expr(Ctx, Mode);
TPosition pos;
TSourcePtr source = nullptr;
switch (subselect_rule.GetBlock1().Alt_case()) {
@@ -5491,35 +5491,35 @@ TNodePtr TSqlTranslation::NamedNode(const TRule_named_nodes_stmt& rule, TVector<
return nullptr;
}
- if (!source) {
- return {};
- }
+ if (!source) {
+ return {};
+ }
return BuildSourceNode(pos, std::move(source));
- }
+ }
default:
AltNotImplemented("named_node", rule.GetBlock3());
Ctx.IncrementMonCounter("sql_errors", "UnknownNamedNode");
return nullptr;
}
-}
-
+}
+
bool TSqlTranslation::ImportStatement(const TRule_import_stmt& stmt, TVector<TString>* namesPtr) {
TVector<TString> modulePath;
- if (!ModulePath(stmt.GetRule_module_path2(), modulePath)) {
- return false;
- }
+ if (!ModulePath(stmt.GetRule_module_path2(), modulePath)) {
+ return false;
+ }
TVector<TSymbolNameWithPos> names;
TVector<TSymbolNameWithPos> aliases;
if (!NamedBindList(stmt.GetRule_named_bind_parameter_list4(), names, aliases)) {
- return false;
- }
+ return false;
+ }
YQL_ENSURE(names.size() == aliases.size());
- const TString moduleAlias = Ctx.AddImport(std::move(modulePath));
- if (!moduleAlias) {
- return false;
- }
+ const TString moduleAlias = Ctx.AddImport(std::move(modulePath));
+ if (!moduleAlias) {
+ return false;
+ }
for (size_t i = 0; i < names.size(); ++i) {
auto& name = names[i];
@@ -5538,13 +5538,13 @@ bool TSqlTranslation::ImportStatement(const TRule_import_stmt& stmt, TVector<TSt
};
var.Name = PushNamedNode(var.Pos, var.Name, builder);
- if (namesPtr) {
+ if (namesPtr) {
namesPtr->push_back(var.Name);
- }
- }
- return true;
-}
-
+ }
+ }
+ return true;
+}
+
bool TSqlSelect::JoinOp(ISource* join, const TRule_join_source::TBlock3& block, TMaybe<TPosition> anyPos) {
// block: (join_op (ANY)? flatten_source join_constraint?)
// join_op:
@@ -5710,12 +5710,12 @@ bool TSqlSelect::FlattenByArg(const TString& sourceLabel, TVector<TNodePtr>& fla
flattenByExprs.clear();
TVector<TNodePtr> namedExprs;
- switch (node.Alt_case()) {
+ switch (node.Alt_case()) {
case TRule_flatten_by_arg::kAltFlattenByArg1: {
TVector<TNodePtr> columns;
if (!NamedColumn(columns, node.GetAlt_flatten_by_arg1().GetRule_named_column1())) {
return false;
- }
+ }
YQL_ENSURE(columns.size() == 1);
auto& column = columns.back();
auto columnNamePtr = column->GetColumnName();
@@ -5745,13 +5745,13 @@ bool TSqlSelect::FlattenByArg(const TString& sourceLabel, TVector<TNodePtr>& fla
flattenByExprs.emplace_back(std::move(node));
}
- break;
+ break;
}
case TRule_flatten_by_arg::kAltFlattenByArg2: {
TColumnRefScope scope(Ctx, EColumnRefState::Allow);
if (!NamedExprList(node.GetAlt_flatten_by_arg2().GetRule_named_expr_list2(), namedExprs) || Ctx.HasPendingErrors) {
return false;
- }
+ }
for (auto& namedExprNode : namedExprs) {
YQL_ENSURE(!namedExprNode->ContentListPtr());
@@ -5771,23 +5771,23 @@ bool TSqlSelect::FlattenByArg(const TString& sourceLabel, TVector<TNodePtr>& fla
flattenByExprs.emplace_back(std::move(namedExprNode));
}
}
- break;
+ break;
}
- default:
+ default:
Ctx.IncrementMonCounter("sql_errors", "UnknownFlattenByArg");
AltNotImplemented("flatten_by_arg", node);
return false;
- }
+ }
return true;
-}
-
-TSourcePtr TSqlSelect::FlattenSource(const TRule_flatten_source& node) {
+}
+
+TSourcePtr TSqlSelect::FlattenSource(const TRule_flatten_source& node) {
auto source = NamedSingleSource(node.GetRule_named_single_source1(), true);
- if (!source) {
- return nullptr;
- }
- if (node.HasBlock2()) {
- auto flatten = node.GetBlock2();
+ if (!source) {
+ return nullptr;
+ }
+ if (node.HasBlock2()) {
+ auto flatten = node.GetBlock2();
auto flatten2 = flatten.GetBlock2();
switch (flatten2.Alt_case()) {
case TRule_flatten_source::TBlock2::TBlock2::kAlt1: {
@@ -5813,21 +5813,21 @@ TSourcePtr TSqlSelect::FlattenSource(const TRule_flatten_source& node) {
source->SetFlattenByMode(mode);
break;
- }
+ }
case TRule_flatten_source::TBlock2::TBlock2::kAlt2: {
Ctx.IncrementMonCounter("sql_features", "FlattenColumns");
source->MarkFlattenColumns();
break;
- }
+ }
default:
Ctx.IncrementMonCounter("sql_errors", "UnknownOrdinaryNamedColumn");
AltNotImplemented("flatten_source", flatten2);
}
- }
- return source;
-}
-
+ }
+ return source;
+}
+
TSourcePtr TSqlSelect::JoinSource(const TRule_join_source& node) {
// join_source: (ANY)? flatten_source (join_op (ANY)? flatten_source join_constraint?)*;
if (node.HasBlock1() && !node.Block3Size()) {
@@ -5846,7 +5846,7 @@ TSourcePtr TSqlSelect::JoinSource(const TRule_join_source& node) {
TVector<TMaybe<TPosition>> anyPositions;
TVector<bool> anyFlags;
- sources.emplace_back(std::move(source));
+ sources.emplace_back(std::move(source));
anyPositions.emplace_back(node.HasBlock1() ? Ctx.TokenPosition(node.GetBlock1().GetToken1()) : TMaybe<TPosition>());
anyFlags.push_back(bool(anyPositions.back()));
@@ -5885,15 +5885,15 @@ bool TSqlSelect::SelectTerm(TVector<TNodePtr>& terms, const TRule_result_column&
// | expr ((AS an_id) | an_id_pure)?
// ;
switch (node.Alt_case()) {
- case TRule_result_column::kAltResultColumn1: {
- auto alt = node.GetAlt_result_column1();
-
- Token(alt.GetToken2());
- auto idAsteriskQualify = OptIdPrefixAsStr(alt.GetRule_opt_id_prefix1(), *this);
- Ctx.IncrementMonCounter("sql_features", idAsteriskQualify ? "QualifyAsterisk" : "Asterisk");
- terms.push_back(BuildColumn(Ctx.Pos(), "*", idAsteriskQualify));
- break;
- }
+ case TRule_result_column::kAltResultColumn1: {
+ auto alt = node.GetAlt_result_column1();
+
+ Token(alt.GetToken2());
+ auto idAsteriskQualify = OptIdPrefixAsStr(alt.GetRule_opt_id_prefix1(), *this);
+ Ctx.IncrementMonCounter("sql_features", idAsteriskQualify ? "QualifyAsterisk" : "Asterisk");
+ terms.push_back(BuildColumn(Ctx.Pos(), "*", idAsteriskQualify));
+ break;
+ }
case TRule_result_column::kAltResultColumn2: {
auto alt = node.GetAlt_result_column2();
TColumnRefScope scope(Ctx, EColumnRefState::Allow);
@@ -5939,42 +5939,42 @@ bool TSqlSelect::SelectTerm(TVector<TNodePtr>& terms, const TRule_result_column&
bool TSqlSelect::ValidateSelectColumns(const TVector<TNodePtr>& terms) {
TSet<TString> labels;
TSet<TString> asteriskSources;
- for (const auto& term: terms) {
- const auto& label = term->GetLabel();
+ for (const auto& term: terms) {
+ const auto& label = term->GetLabel();
if (!Ctx.PragmaAllowDotInAlias && label.find('.') != TString::npos) {
- Ctx.Error(term->GetPos()) << "Unable to use '.' in column name. Invalid column name: " << label;
- return false;
- }
- if (!label.empty()) {
- if (!labels.insert(label).second) {
- Ctx.Error(term->GetPos()) << "Unable to use duplicate column names. Collision in name: " << label;
- return false;
- }
- }
- if (term->IsAsterisk()) {
- const auto& source = *term->GetSourceName();
- if (source.empty() && terms.ysize() > 1) {
+ Ctx.Error(term->GetPos()) << "Unable to use '.' in column name. Invalid column name: " << label;
+ return false;
+ }
+ if (!label.empty()) {
+ if (!labels.insert(label).second) {
+ Ctx.Error(term->GetPos()) << "Unable to use duplicate column names. Collision in name: " << label;
+ return false;
+ }
+ }
+ if (term->IsAsterisk()) {
+ const auto& source = *term->GetSourceName();
+ if (source.empty() && terms.ysize() > 1) {
Ctx.Error(term->GetPos()) << "Unable to use plain '*' with other projection items. Please use qualified asterisk instead: '<table>.*' (<table> can be either table name or table alias).";
- return false;
- } else if (!asteriskSources.insert(source).second) {
- Ctx.Error(term->GetPos()) << "Unable to use twice same quialified asterisk. Invalid source: " << source;
- return false;
- }
- } else if (label.empty()) {
- const auto* column = term->GetColumnName();
- if (column && !column->empty()) {
- const auto& source = *term->GetSourceName();
- const auto usedName = source.empty() ? *column : source + '.' + *column;
- if (!labels.insert(usedName).second) {
- Ctx.Error(term->GetPos()) << "Unable to use duplicate column names. Collision in name: " << usedName;
- return false;
- }
- }
- }
- }
- return true;
-}
-
+ return false;
+ } else if (!asteriskSources.insert(source).second) {
+ Ctx.Error(term->GetPos()) << "Unable to use twice same quialified asterisk. Invalid source: " << source;
+ return false;
+ }
+ } else if (label.empty()) {
+ const auto* column = term->GetColumnName();
+ if (column && !column->empty()) {
+ const auto& source = *term->GetSourceName();
+ const auto usedName = source.empty() ? *column : source + '.' + *column;
+ if (!labels.insert(usedName).second) {
+ Ctx.Error(term->GetPos()) << "Unable to use duplicate column names. Collision in name: " << usedName;
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+}
+
TSourcePtr TSqlSelect::SingleSource(const TRule_single_source& node, const TVector<TString>& derivedColumns, TPosition derivedColumnsPos, bool unorderedSubquery) {
switch (node.Alt_case()) {
case TRule_single_source::kAltSingleSource1: {
@@ -6014,8 +6014,8 @@ TSourcePtr TSqlSelect::SingleSource(const TRule_single_source& node, const TVect
}
return BuildInnerSource(pos, BuildSourceNode(pos, std::move(source)), Ctx.Scoped->CurrService, Ctx.Scoped->CurrCluster);
}
- case TRule_single_source::kAltSingleSource3: {
- const auto& alt = node.GetAlt_single_source3();
+ case TRule_single_source::kAltSingleSource3: {
+ const auto& alt = node.GetAlt_single_source3();
TPosition pos;
return TSqlValues(Ctx, Mode).Build(alt.GetRule_values_stmt2(), pos, derivedColumns, derivedColumnsPos);
}
@@ -6044,9 +6044,9 @@ TSourcePtr TSqlSelect::NamedSingleSource(const TRule_named_single_source& node,
}
auto singleSource = SingleSource(node.GetRule_single_source1(), derivedColumns, derivedColumnsPos, unorderedSubquery);
- if (!singleSource) {
- return nullptr;
- }
+ if (!singleSource) {
+ return nullptr;
+ }
if (node.HasBlock2()) {
TString label;
switch (node.GetBlock2().GetBlock1().Alt_case()) {
@@ -6064,8 +6064,8 @@ TSourcePtr TSqlSelect::NamedSingleSource(const TRule_named_single_source& node,
default:
Y_FAIL("You should change implementation according to grammar changes");
}
- singleSource->SetLabel(label);
- }
+ singleSource->SetLabel(label);
+ }
if (node.HasBlock3()) {
ESampleMode mode = ESampleMode::Auto;
TSqlExpression expr(Ctx, Mode);
@@ -6123,11 +6123,11 @@ TSourcePtr TSqlSelect::NamedSingleSource(const TRule_named_single_source& node,
return nullptr;
}
}
- return singleSource;
-}
-
+ return singleSource;
+}
+
bool TSqlSelect::ColumnName(TVector<TNodePtr>& keys, const TRule_column_name& node) {
- const auto sourceName = OptIdPrefixAsStr(node.GetRule_opt_id_prefix1(), *this);
+ const auto sourceName = OptIdPrefixAsStr(node.GetRule_opt_id_prefix1(), *this);
const auto columnName = Id(node.GetRule_an_id2(), *this);
if (columnName.empty()) {
// TDOD: Id() should return TMaybe<TString>
@@ -6163,9 +6163,9 @@ bool TSqlSelect::ColumnName(TVector<TNodePtr>& keys, const TRule_without_column_
}
return false;
}
- keys.push_back(BuildColumn(Ctx.Pos(), columnName, sourceName));
- return true;
-}
+ keys.push_back(BuildColumn(Ctx.Pos(), columnName, sourceName));
+ return true;
+}
template<typename TRule>
bool TSqlSelect::ColumnList(TVector<TNodePtr>& keys, const TRule& node) {
@@ -6177,81 +6177,81 @@ bool TSqlSelect::ColumnList(TVector<TNodePtr>& keys, const TRule& node) {
}
if (!result) {
- return false;
- }
+ return false;
+ }
- for (auto b: node.GetBlock2()) {
- Token(b.GetToken1());
+ for (auto b: node.GetBlock2()) {
+ Token(b.GetToken1());
if constexpr (std::is_same_v<TRule, TRule_column_list>) {
result = ColumnName(keys, b.GetRule_column_name2());
} else {
result = ColumnName(keys, b.GetRule_without_column_name2());
}
if (!result) {
- return false;
- }
+ return false;
+ }
}
- return true;
+ return true;
}
bool TSqlSelect::NamedColumn(TVector<TNodePtr>& columnList, const TRule_named_column& node) {
- if (!ColumnName(columnList, node.GetRule_column_name1())) {
- return false;
- }
- if (node.HasBlock2()) {
+ if (!ColumnName(columnList, node.GetRule_column_name1())) {
+ return false;
+ }
+ if (node.HasBlock2()) {
const auto label = Id(node.GetBlock2().GetRule_an_id2(), *this);
- columnList.back()->SetLabel(label);
- }
- return true;
-}
-
+ columnList.back()->SetLabel(label);
+ }
+ return true;
+}
+
bool TSqlTranslation::SortSpecification(const TRule_sort_specification& node, TVector<TSortSpecificationPtr>& sortSpecs) {
- bool asc = true;
- TSqlExpression expr(Ctx, Mode);
+ bool asc = true;
+ TSqlExpression expr(Ctx, Mode);
TColumnRefScope scope(Ctx, EColumnRefState::Allow);
- TNodePtr exprNode = expr.Build(node.GetRule_expr1());
- if (!exprNode) {
- return false;
- }
- if (node.HasBlock2()) {
- const auto& token = node.GetBlock2().GetToken1();
- Token(token);
- switch (token.GetId()) {
+ TNodePtr exprNode = expr.Build(node.GetRule_expr1());
+ if (!exprNode) {
+ return false;
+ }
+ if (node.HasBlock2()) {
+ const auto& token = node.GetBlock2().GetToken1();
+ Token(token);
+ switch (token.GetId()) {
case SQLv1LexerTokens::TOKEN_ASC:
- Ctx.IncrementMonCounter("sql_features", "OrderByAsc");
- break;
+ Ctx.IncrementMonCounter("sql_features", "OrderByAsc");
+ break;
case SQLv1LexerTokens::TOKEN_DESC:
- asc = false;
- Ctx.IncrementMonCounter("sql_features", "OrderByDesc");
- break;
- default:
- Ctx.IncrementMonCounter("sql_errors", "UnknownOrderBy");
- Error() << "Unsupported direction token: " << token.GetId();
- return false;
- }
- } else {
- Ctx.IncrementMonCounter("sql_features", "OrderByDefault");
- }
- auto sortSpecPtr = MakeIntrusive<TSortSpecification>();
- sortSpecPtr->OrderExpr = exprNode;
- sortSpecPtr->Ascending = asc;
- sortSpecs.emplace_back(sortSpecPtr);
- return true;
-}
-
+ asc = false;
+ Ctx.IncrementMonCounter("sql_features", "OrderByDesc");
+ break;
+ default:
+ Ctx.IncrementMonCounter("sql_errors", "UnknownOrderBy");
+ Error() << "Unsupported direction token: " << token.GetId();
+ return false;
+ }
+ } else {
+ Ctx.IncrementMonCounter("sql_features", "OrderByDefault");
+ }
+ auto sortSpecPtr = MakeIntrusive<TSortSpecification>();
+ sortSpecPtr->OrderExpr = exprNode;
+ sortSpecPtr->Ascending = asc;
+ sortSpecs.emplace_back(sortSpecPtr);
+ return true;
+}
+
bool TSqlTranslation::SortSpecificationList(const TRule_sort_specification_list& node, TVector<TSortSpecificationPtr>& sortSpecs) {
- if (!SortSpecification(node.GetRule_sort_specification1(), sortSpecs)) {
- return false;
- }
- for (auto sortSpec: node.GetBlock2()) {
- Token(sortSpec.GetToken1());
- if (!SortSpecification(sortSpec.GetRule_sort_specification2(), sortSpecs)) {
- return false;
- }
- }
- return true;
-}
-
+ if (!SortSpecification(node.GetRule_sort_specification1(), sortSpecs)) {
+ return false;
+ }
+ for (auto sortSpec: node.GetBlock2()) {
+ Token(sortSpec.GetToken1());
+ if (!SortSpecification(sortSpec.GetRule_sort_specification2(), sortSpecs)) {
+ return false;
+ }
+ }
+ return true;
+}
+
bool TSqlTranslation::IsDistinctOptSet(const TRule_opt_set_quantifier& node) const {
TPosition pos;
return node.HasBlock1() && node.GetBlock1().GetToken1().GetId() == SQLv1LexerTokens::TOKEN_DISTINCT;
@@ -6334,9 +6334,9 @@ TSourcePtr TSqlSelect::ProcessCore(const TRule_process_core& node, const TWriteS
const bool hasUsing = node.HasBlock5();
const bool unorderedSubquery = hasUsing;
TSourcePtr source(NamedSingleSource(node.GetRule_named_single_source3(), unorderedSubquery));
- if (!source) {
- return nullptr;
- }
+ if (!source) {
+ return nullptr;
+ }
if (node.GetBlock4().size()) {
TVector<TSourcePtr> sources(1, source);
for (auto& s: node.GetBlock4()) {
@@ -6363,13 +6363,13 @@ TSourcePtr TSqlSelect::ProcessCore(const TRule_process_core& node, const TWriteS
if (!where || !source->AddFilter(Ctx, where)) {
return nullptr;
}
- Ctx.IncrementMonCounter("sql_features", "ProcessWhere");
- } else {
+ Ctx.IncrementMonCounter("sql_features", "ProcessWhere");
+ } else {
Ctx.IncrementMonCounter("sql_features", processStream ? "ProcessStream" : "Process");
}
if (block5.HasBlock6()) {
- Ctx.Error() << "PROCESS does not allow HAVING yet! You may request it on yql@ maillist.";
+ Ctx.Error() << "PROCESS does not allow HAVING yet! You may request it on yql@ maillist.";
return nullptr;
}
@@ -6385,7 +6385,7 @@ TSourcePtr TSqlSelect::ProcessCore(const TRule_process_core& node, const TWriteS
}
auto args = call.GetArgs();
- for (auto& arg: args) {
+ for (auto& arg: args) {
if (auto placeholder = dynamic_cast<TTableRows*>(arg.Get())) {
if (listCall) {
Ctx.Error() << "Only one TableRows() argument is allowed.";
@@ -6410,16 +6410,16 @@ TSourcePtr TSqlSelect::ProcessCore(const TRule_process_core& node, const TWriteS
TSqlCallExpr finalCall(call, args);
TNodePtr with(finalCall.IsExternal() ? finalCall.BuildCall() : finalCall.BuildUdf(/* forReduce = */ false));
if (!with) {
- return {};
- }
+ return {};
+ }
args = finalCall.GetArgs();
if (call.IsExternal())
listCall = true;
-
+
if (block5.HasBlock3()) {
with->SetLabel(Id(block5.GetBlock3().GetRule_an_id2(), *this));
- }
-
+ }
+
if (call.IsExternal() && block5.HasBlock7()) {
Ctx.Error() << "PROCESS with USING EXTERNAL FUNCTION doesn't allow ASSUME block";
return nullptr;
@@ -6434,22 +6434,22 @@ TSourcePtr TSqlSelect::ProcessCore(const TRule_process_core& node, const TWriteS
}
return BuildProcess(startPos, std::move(source), with, finalCall.IsExternal(), std::move(args), listCall, processStream, settings, assumeOrderBy);
-}
-
+}
+
TSourcePtr TSqlSelect::ReduceCore(const TRule_reduce_core& node, const TWriteSettings& settings, TPosition& selectPos) {
// REDUCE named_single_source (COMMA named_single_source)* (PRESORT sort_specification_list)?
// ON column_list USING ALL? using_call_expr (AS an_id)?
// (WHERE expr)? (HAVING expr)? (ASSUME order_by_clause)?
Token(node.GetToken1());
- TPosition startPos(Ctx.Pos());
+ TPosition startPos(Ctx.Pos());
if (!selectPos) {
selectPos = startPos;
}
-
+
TSourcePtr source(NamedSingleSource(node.GetRule_named_single_source2(), true));
- if (!source) {
- return {};
- }
+ if (!source) {
+ return {};
+ }
if (node.GetBlock3().size()) {
TVector<TSourcePtr> sources(1, source);
for (auto& s: node.GetBlock3()) {
@@ -6461,43 +6461,43 @@ TSourcePtr TSqlSelect::ReduceCore(const TRule_reduce_core& node, const TWriteSet
auto pos = source->GetPos();
source = BuildMuxSource(pos, std::move(sources));
}
-
+
TVector<TSortSpecificationPtr> orderBy;
if (node.HasBlock4()) {
if (!SortSpecificationList(node.GetBlock4().GetRule_sort_specification_list2(), orderBy)) {
- return {};
- }
- }
-
+ return {};
+ }
+ }
+
TVector<TNodePtr> keys;
if (!ColumnList(keys, node.GetRule_column_list6())) {
return nullptr;
}
-
+
if (node.HasBlock11()) {
TColumnRefScope scope(Ctx, EColumnRefState::Allow);
- TSqlExpression expr(Ctx, Mode);
+ TSqlExpression expr(Ctx, Mode);
TNodePtr where = expr.Build(node.GetBlock11().GetRule_expr2());
- if (!where || !source->AddFilter(Ctx, where)) {
- return nullptr;
- }
- Ctx.IncrementMonCounter("sql_features", "ReduceWhere");
- } else {
- Ctx.IncrementMonCounter("sql_features", "Reduce");
- }
-
- TNodePtr having;
+ if (!where || !source->AddFilter(Ctx, where)) {
+ return nullptr;
+ }
+ Ctx.IncrementMonCounter("sql_features", "ReduceWhere");
+ } else {
+ Ctx.IncrementMonCounter("sql_features", "Reduce");
+ }
+
+ TNodePtr having;
if (node.HasBlock12()) {
TColumnRefScope scope(Ctx, EColumnRefState::Allow);
- TSqlExpression expr(Ctx, Mode);
+ TSqlExpression expr(Ctx, Mode);
having = expr.Build(node.GetBlock12().GetRule_expr2());
- if (!having) {
- return nullptr;
- }
- }
-
+ if (!having) {
+ return nullptr;
+ }
+ }
+
bool listCall = false;
- TSqlCallExpr call(Ctx, Mode);
+ TSqlCallExpr call(Ctx, Mode);
bool initRet = call.Init(node.GetRule_using_call_expr9());
if (initRet) {
call.IncCounters();
@@ -6506,8 +6506,8 @@ TSourcePtr TSqlSelect::ReduceCore(const TRule_reduce_core& node, const TWriteSet
if (!initRet) {
return nullptr;
}
-
- auto args = call.GetArgs();
+
+ auto args = call.GetArgs();
for (auto& arg: args) {
if (auto placeholder = dynamic_cast<TTableRows*>(arg.Get())) {
if (listCall) {
@@ -6517,18 +6517,18 @@ TSourcePtr TSqlSelect::ReduceCore(const TRule_reduce_core& node, const TWriteSet
listCall = true;
}
}
-
- TSqlCallExpr finalCall(call, args);
-
+
+ TSqlCallExpr finalCall(call, args);
+
TNodePtr udf(finalCall.BuildUdf(/* forReduce = */ true));
if (!udf) {
- return {};
- }
-
+ return {};
+ }
+
if (node.HasBlock10()) {
udf->SetLabel(Id(node.GetBlock10().GetRule_an_id2(), *this));
- }
-
+ }
+
const auto reduceMode = node.HasBlock8() ? ReduceMode::ByAll : ReduceMode::ByPartition;
TVector<TSortSpecificationPtr> assumeOrderBy;
@@ -6562,8 +6562,8 @@ TSourcePtr TSqlSelect::SelectCore(const TRule_select_core& node, const TWriteSet
}
const bool distinct = IsDistinctOptSet(node.GetRule_opt_set_quantifier4());
- if (distinct) {
- Ctx.IncrementMonCounter("sql_features", "DistinctInSelect");
+ if (distinct) {
+ Ctx.IncrementMonCounter("sql_features", "DistinctInSelect");
}
TSourcePtr source(BuildFakeSource(selectPos, /* missingFrom = */ true));
@@ -6579,17 +6579,17 @@ TSourcePtr TSqlSelect::SelectCore(const TRule_select_core& node, const TWriteSet
} else if (node.HasBlock9()) {
source = JoinSource(node.GetBlock9().GetRule_join_source2());
}
- if (!source) {
- return nullptr;
- }
+ if (!source) {
+ return nullptr;
+ }
const bool selectStream = node.HasBlock3();
TVector<TNodePtr> without;
if (node.HasBlock8()) {
if (!ColumnList(without, node.GetBlock8().GetRule_without_column_list2())) {
- return nullptr;
- }
- }
+ return nullptr;
+ }
+ }
if (node.HasBlock10()) {
auto block = node.GetBlock10();
Token(block.GetToken1());
@@ -6600,59 +6600,59 @@ TSourcePtr TSqlSelect::SelectCore(const TRule_select_core& node, const TWriteSet
TSqlExpression expr(Ctx, Mode);
where = expr.Build(block.GetRule_expr2());
}
- if (!where) {
- Ctx.IncrementMonCounter("sql_errors", "WhereInvalid");
+ if (!where) {
+ Ctx.IncrementMonCounter("sql_errors", "WhereInvalid");
+ return nullptr;
+ }
+ if (!source->AddFilter(Ctx, where)) {
+ Ctx.IncrementMonCounter("sql_errors", "WhereNotSupportedBySource");
return nullptr;
}
- if (!source->AddFilter(Ctx, where)) {
- Ctx.IncrementMonCounter("sql_errors", "WhereNotSupportedBySource");
- return nullptr;
- }
Ctx.IncrementMonCounter("sql_features", "Where");
}
- /// \todo merge gtoupByExpr and groupBy in one
+ /// \todo merge gtoupByExpr and groupBy in one
TVector<TNodePtr> groupByExpr, groupBy;
THoppingWindowSpecPtr hoppingWindowSpec;
bool compactGroupBy = false;
if (node.HasBlock11()) {
- TGroupByClause clause(Ctx, Mode);
+ TGroupByClause clause(Ctx, Mode);
if (!clause.Build(node.GetBlock11().GetRule_group_by_clause1(), source->IsStream())) {
return nullptr;
}
for (const auto& exprAlias: clause.Aliases()) {
- YQL_ENSURE(exprAlias.first == exprAlias.second->GetLabel());
- groupByExpr.emplace_back(exprAlias.second);
+ YQL_ENSURE(exprAlias.first == exprAlias.second->GetLabel());
+ groupByExpr.emplace_back(exprAlias.second);
}
- groupBy = std::move(clause.Content());
- clause.SetFeatures("sql_features");
+ groupBy = std::move(clause.Content());
+ clause.SetFeatures("sql_features");
hoppingWindowSpec = clause.GetHoppingWindow();
compactGroupBy = clause.IsCompactGroupBy();
}
-
- TNodePtr having;
+
+ TNodePtr having;
if (node.HasBlock12()) {
- TSqlExpression expr(Ctx, Mode);
+ TSqlExpression expr(Ctx, Mode);
TColumnRefScope scope(Ctx, EColumnRefState::Allow);
having = expr.Build(node.GetBlock12().GetRule_expr2());
- if (!having) {
- return nullptr;
- }
- Ctx.IncrementMonCounter("sql_features", "Having");
- }
-
- TWinSpecs windowSpec;
+ if (!having) {
+ return nullptr;
+ }
+ Ctx.IncrementMonCounter("sql_features", "Having");
+ }
+
+ TWinSpecs windowSpec;
if (node.HasBlock13()) {
if (source->IsStream()) {
Ctx.Error() << "WINDOW is not allowed in streaming queries";
- return nullptr;
- }
+ return nullptr;
+ }
if (!WindowClause(node.GetBlock13().GetRule_window_clause1(), windowSpec)) {
return nullptr;
}
- Ctx.IncrementMonCounter("sql_features", "WindowClause");
- }
-
+ Ctx.IncrementMonCounter("sql_features", "WindowClause");
+ }
+
bool assumeSorted = false;
TVector<TSortSpecificationPtr> orderBy;
if (node.HasBlock14()) {
@@ -6663,8 +6663,8 @@ TSourcePtr TSqlSelect::SelectCore(const TRule_select_core& node, const TWriteSet
if (source->IsStream()) {
Ctx.Error() << "ORDER BY is not allowed in streaming queries";
- return nullptr;
- }
+ return nullptr;
+ }
if (!ValidateLimitOrderByWithSelectOp(placement, "ORDER BY")) {
return nullptr;
@@ -6682,7 +6682,7 @@ TSourcePtr TSqlSelect::SelectCore(const TRule_select_core& node, const TWriteSet
selectOpOrederBy.swap(orderBy);
std::swap(selectOpAssumeOrderBy, assumeSorted);
}
- }
+ }
TVector<TNodePtr> terms;
{
@@ -6712,9 +6712,9 @@ TSourcePtr TSqlSelect::SelectCore(const TRule_select_core& node, const TWriteSet
}
}
- if (!ValidateSelectColumns(terms)) {
- return nullptr;
- }
+ if (!ValidateSelectColumns(terms)) {
+ return nullptr;
+ }
return BuildSelectCore(Ctx, startPos, std::move(source), groupByExpr, groupBy, compactGroupBy, assumeSorted, orderBy, having,
std::move(windowSpec), hoppingWindowSpec, std::move(terms), distinct, std::move(without), selectStream, settings);
}
@@ -6729,13 +6729,13 @@ TString TSqlTranslation::FrameSettingsToString(EFrameSettings settings, bool isU
result = "CURRENT ROW"; break;
case FrameFollowing:
result = "FOLLOWING"; break;
- default:
+ default:
Y_FAIL("Unexpected frame settings");
- }
+ }
return (isUnbounded ? "UNBOUNDED " : "") + result;
-}
-
+}
+
bool CheckFrameBoundLiteral(TContext& ctx, const TFrameBound& bound, TMaybe<i32>& boundValue) {
boundValue = {};
auto node = bound.Bound;
@@ -6812,8 +6812,8 @@ bool TSqlTranslation::FrameBound(const TRule_window_frame_bound& rule, TFrameBou
// | (expr | UNBOUNDED) (PRECEDING | FOLLOWING)
// ;
bound = new TFrameBound;
- switch (rule.Alt_case()) {
- case TRule_window_frame_bound::kAltWindowFrameBound1:
+ switch (rule.Alt_case()) {
+ case TRule_window_frame_bound::kAltWindowFrameBound1:
bound->Pos = GetPos(rule.GetAlt_window_frame_bound1().GetToken1());
bound->Settings = FrameCurrentRow;
break;
@@ -6834,7 +6834,7 @@ bool TSqlTranslation::FrameBound(const TRule_window_frame_bound& rule, TFrameBou
break;
default:
Y_FAIL("You should change implementation according to grammar changes");
- }
+ }
const TString settingToken = to_lower(Token(rule.GetAlt_window_frame_bound2().GetToken2()));
if (settingToken == "preceding") {
@@ -6843,59 +6843,59 @@ bool TSqlTranslation::FrameBound(const TRule_window_frame_bound& rule, TFrameBou
bound->Settings = FrameFollowing;
} else {
Y_FAIL("You should change implementation according to grammar changes");
- }
+ }
break;
}
- default:
- Y_FAIL("FrameClause: frame bound not corresond to grammar changes");
- }
+ default:
+ Y_FAIL("FrameClause: frame bound not corresond to grammar changes");
+ }
return true;
-}
-
+}
+
bool TSqlTranslation::FrameClause(const TRule_window_frame_clause& rule, TFrameSpecificationPtr& frameSpec) {
frameSpec = new TFrameSpecification;
const TString frameUnitStr = to_lower(Token(rule.GetRule_window_frame_units1().GetToken1()));
- if (frameUnitStr == "rows") {
+ if (frameUnitStr == "rows") {
frameSpec->FrameType = EFrameType::FrameByRows;
- } else if (frameUnitStr == "range") {
+ } else if (frameUnitStr == "range") {
frameSpec->FrameType = EFrameType::FrameByRange;
} else if (frameUnitStr == "groups") {
frameSpec->FrameType = EFrameType::FrameByGroups;
- } else {
- Ctx.Error() << "Unknown frame type in window specification: " << frameUnitStr;
- return false;
- }
+ } else {
+ Ctx.Error() << "Unknown frame type in window specification: " << frameUnitStr;
+ return false;
+ }
if (frameSpec->FrameType != EFrameType::FrameByRows) {
Ctx.Error() << "Only ROWS is supported as window frame unit";
return false;
}
- auto frameExtent = rule.GetRule_window_frame_extent2();
- switch (frameExtent.Alt_case()) {
+ auto frameExtent = rule.GetRule_window_frame_extent2();
+ switch (frameExtent.Alt_case()) {
case TRule_window_frame_extent::kAltWindowFrameExtent1: {
auto start = frameExtent.GetAlt_window_frame_extent1().GetRule_window_frame_bound1();
if (!FrameBound(start, frameSpec->FrameBegin)) {
- return false;
- }
+ return false;
+ }
frameSpec->FrameEnd = new TFrameBound;
frameSpec->FrameEnd->Pos = frameSpec->FrameBegin->Pos;
frameSpec->FrameEnd->Settings = FrameCurrentRow;
- break;
+ break;
}
- case TRule_window_frame_extent::kAltWindowFrameExtent2: {
- auto between = frameExtent.GetAlt_window_frame_extent2().GetRule_window_frame_between1();
+ case TRule_window_frame_extent::kAltWindowFrameExtent2: {
+ auto between = frameExtent.GetAlt_window_frame_extent2().GetRule_window_frame_between1();
if (!FrameBound(between.GetRule_window_frame_bound2(), frameSpec->FrameBegin)) {
- return false;
- }
+ return false;
+ }
if (!FrameBound(between.GetRule_window_frame_bound4(), frameSpec->FrameEnd)) {
- return false;
- }
- break;
- }
- default:
+ return false;
+ }
+ break;
+ }
+ default:
Y_FAIL("FrameClause: frame extent not correspond to grammar changes");
- }
+ }
YQL_ENSURE(frameSpec->FrameBegin);
YQL_ENSURE(frameSpec->FrameEnd);
// check for literal
@@ -6904,33 +6904,33 @@ bool TSqlTranslation::FrameClause(const TRule_window_frame_clause& rule, TFrameS
return false;
}
- if (rule.HasBlock3()) {
- switch (rule.GetBlock3().GetRule_window_frame_exclusion1().Alt_case()) {
- case TRule_window_frame_exclusion::kAltWindowFrameExclusion1:
+ if (rule.HasBlock3()) {
+ switch (rule.GetBlock3().GetRule_window_frame_exclusion1().Alt_case()) {
+ case TRule_window_frame_exclusion::kAltWindowFrameExclusion1:
frameSpec->FrameExclusion = FrameExclCurRow;
- break;
- case TRule_window_frame_exclusion::kAltWindowFrameExclusion2:
+ break;
+ case TRule_window_frame_exclusion::kAltWindowFrameExclusion2:
frameSpec->FrameExclusion = FrameExclGroup;
- break;
- case TRule_window_frame_exclusion::kAltWindowFrameExclusion3:
+ break;
+ case TRule_window_frame_exclusion::kAltWindowFrameExclusion3:
frameSpec->FrameExclusion = FrameExclTies;
- break;
- case TRule_window_frame_exclusion::kAltWindowFrameExclusion4:
+ break;
+ case TRule_window_frame_exclusion::kAltWindowFrameExclusion4:
frameSpec->FrameExclusion = FrameExclNone;
- break;
- default:
+ break;
+ default:
Y_FAIL("FrameClause: frame exclusion not correspond to grammar changes");
- }
- }
+ }
+ }
if (frameSpec->FrameExclusion != FrameExclNone) {
Ctx.Error() << "Frame exclusion is not supported yet";
return false;
}
- return true;
-}
-
+ return true;
+}
+
TWindowSpecificationPtr TSqlTranslation::WindowSpecification(const TRule_window_specification_details& rule) {
/*
window_specification_details:
@@ -6939,12 +6939,12 @@ TWindowSpecificationPtr TSqlTranslation::WindowSpecification(const TRule_window_
window_order_clause?
window_frame_clause?
*/
- TWindowSpecificationPtr winSpecPtr = new TWindowSpecification;
- if (rule.HasBlock1()) {
- Ctx.Error() << "Existing window name is not supported in window specification yet!";
- return {};
- }
- if (rule.HasBlock2()) {
+ TWindowSpecificationPtr winSpecPtr = new TWindowSpecification;
+ if (rule.HasBlock1()) {
+ Ctx.Error() << "Existing window name is not supported in window specification yet!";
+ return {};
+ }
+ if (rule.HasBlock2()) {
/*
window_partition_clause: PARTITION COMPACT? BY named_expr_list;
*/
@@ -6952,8 +6952,8 @@ TWindowSpecificationPtr TSqlTranslation::WindowSpecification(const TRule_window_
winSpecPtr->IsCompact = partitionClause.HasBlock2();
TColumnRefScope scope(Ctx, EColumnRefState::Allow);
if (!NamedExprList(partitionClause.GetRule_named_expr_list4(), winSpecPtr->Partitions)) {
- return {};
- }
+ return {};
+ }
// ignore empty unnamed tuples:
// "PARTITION BY (), foo(x) as y, (), (z)" is allowed and will work exactly the same as
// "PARTITION BY foo(x) as y, z"
@@ -6965,13 +6965,13 @@ TWindowSpecificationPtr TSqlTranslation::WindowSpecification(const TRule_window_
});
winSpecPtr->Partitions.erase(removed, winSpecPtr->Partitions.end());
- }
- if (rule.HasBlock3()) {
- if (!OrderByClause(rule.GetBlock3().GetRule_window_order_clause1().GetRule_order_by_clause1(), winSpecPtr->OrderBy)) {
- return {};
- }
- }
- if (rule.HasBlock4()) {
+ }
+ if (rule.HasBlock3()) {
+ if (!OrderByClause(rule.GetBlock3().GetRule_window_order_clause1().GetRule_order_by_clause1(), winSpecPtr->OrderBy)) {
+ return {};
+ }
+ }
+ if (rule.HasBlock4()) {
if (!FrameClause(rule.GetBlock4().GetRule_window_frame_clause1(), winSpecPtr->Frame)) {
return {};
}
@@ -6995,52 +6995,52 @@ TWindowSpecificationPtr TSqlTranslation::WindowSpecification(const TRule_window_
// TODO: According to standard this should be RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW with order by clause
// TODO: and RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING without order by
- }
- return winSpecPtr;
-}
-
+ }
+ return winSpecPtr;
+}
+
bool TSqlSelect::WindowDefinition(const TRule_window_definition& rule, TWinSpecs& winSpecs) {
const TString windowName = Id(rule.GetRule_new_window_name1().GetRule_window_name1().GetRule_an_id_window1(), *this);
if (winSpecs.contains(windowName)) {
- Ctx.Error() << "Unable to declare window with same name: " << windowName;
- return false;
- }
- auto windowSpec = WindowSpecification(rule.GetRule_window_specification3().GetRule_window_specification_details2());
- if (!windowSpec) {
- return false;
- }
- winSpecs.emplace(windowName, std::move(windowSpec));
- return true;
-}
-
-bool TSqlSelect::WindowClause(const TRule_window_clause& rule, TWinSpecs& winSpecs) {
- auto windowList = rule.GetRule_window_definition_list2();
+ Ctx.Error() << "Unable to declare window with same name: " << windowName;
+ return false;
+ }
+ auto windowSpec = WindowSpecification(rule.GetRule_window_specification3().GetRule_window_specification_details2());
+ if (!windowSpec) {
+ return false;
+ }
+ winSpecs.emplace(windowName, std::move(windowSpec));
+ return true;
+}
+
+bool TSqlSelect::WindowClause(const TRule_window_clause& rule, TWinSpecs& winSpecs) {
+ auto windowList = rule.GetRule_window_definition_list2();
if (!WindowDefinition(windowList.GetRule_window_definition1(), winSpecs)) {
- return false;
- }
- for (auto& block: windowList.GetBlock2()) {
+ return false;
+ }
+ for (auto& block: windowList.GetBlock2()) {
if (!WindowDefinition(block.GetRule_window_definition2(), winSpecs)) {
- return false;
- }
- }
- return true;
-}
-
+ return false;
+ }
+ }
+ return true;
+}
+
bool TSqlTranslation::OrderByClause(const TRule_order_by_clause& node, TVector<TSortSpecificationPtr>& orderBy) {
- return SortSpecificationList(node.GetRule_sort_specification_list3(), orderBy);
-}
-
+ return SortSpecificationList(node.GetRule_sort_specification_list3(), orderBy);
+}
+
bool TGroupByClause::Build(const TRule_group_by_clause& node, bool stream) {
CompactGroupBy = node.HasBlock2();
TPosition distinctPos;
if (IsDistinctOptSet(node.GetRule_opt_set_quantifier4(), distinctPos)) {
Ctx.Error(distinctPos) << "DISTINCT is not supported in GROUP BY clause yet!";
- Ctx.IncrementMonCounter("sql_errors", "DistinctInGroupByNotSupported");
- return false;
- }
+ Ctx.IncrementMonCounter("sql_errors", "DistinctInGroupByNotSupported");
+ return false;
+ }
if (!ParseList(node.GetRule_grouping_element_list5(), EGroupByFeatures::Ordinary)) {
- return false;
- }
+ return false;
+ }
if (!ResolveGroupByAndGrouping()) {
return false;
}
@@ -7050,52 +7050,52 @@ bool TGroupByClause::Build(const TRule_group_by_clause& node, bool stream) {
return false;
}
}
- return true;
-}
-
+ return true;
+}
+
bool TGroupByClause::ParseList(const TRule_grouping_element_list& groupingListNode, EGroupByFeatures featureContext) {
if (!GroupingElement(groupingListNode.GetRule_grouping_element1(), featureContext)) {
- return false;
- }
- for (auto b: groupingListNode.GetBlock2()) {
+ return false;
+ }
+ for (auto b: groupingListNode.GetBlock2()) {
if (!GroupingElement(b.GetRule_grouping_element2(), featureContext)) {
- return false;
- }
- }
- return true;
-}
-
+ return false;
+ }
+ }
+ return true;
+}
+
void TGroupByClause::SetFeatures(const TString& field) const {
- Ctx.IncrementMonCounter(field, "GroupBy");
- const auto& features = Features();
- if (features.Test(EGroupByFeatures::Ordinary)) {
- Ctx.IncrementMonCounter(field, "GroupByOrdinary");
- }
- if (features.Test(EGroupByFeatures::Expression)) {
- Ctx.IncrementMonCounter(field, "GroupByExpression");
- }
- if (features.Test(EGroupByFeatures::Rollup)) {
- Ctx.IncrementMonCounter(field, "GroupByRollup");
- }
- if (features.Test(EGroupByFeatures::Cube)) {
- Ctx.IncrementMonCounter(field, "GroupByCube");
- }
- if (features.Test(EGroupByFeatures::GroupingSet)) {
- Ctx.IncrementMonCounter(field, "GroupByGroupingSet");
- }
- if (features.Test(EGroupByFeatures::Empty)) {
- Ctx.IncrementMonCounter(field, "GroupByEmpty");
- }
-}
-
+ Ctx.IncrementMonCounter(field, "GroupBy");
+ const auto& features = Features();
+ if (features.Test(EGroupByFeatures::Ordinary)) {
+ Ctx.IncrementMonCounter(field, "GroupByOrdinary");
+ }
+ if (features.Test(EGroupByFeatures::Expression)) {
+ Ctx.IncrementMonCounter(field, "GroupByExpression");
+ }
+ if (features.Test(EGroupByFeatures::Rollup)) {
+ Ctx.IncrementMonCounter(field, "GroupByRollup");
+ }
+ if (features.Test(EGroupByFeatures::Cube)) {
+ Ctx.IncrementMonCounter(field, "GroupByCube");
+ }
+ if (features.Test(EGroupByFeatures::GroupingSet)) {
+ Ctx.IncrementMonCounter(field, "GroupByGroupingSet");
+ }
+ if (features.Test(EGroupByFeatures::Empty)) {
+ Ctx.IncrementMonCounter(field, "GroupByEmpty");
+ }
+}
+
TVector<TNodePtr>& TGroupByClause::Content() {
- return GroupBySet;
-}
-
+ return GroupBySet;
+}
+
TMap<TString, TNodePtr>& TGroupByClause::Aliases() {
- return GroupSetContext->NodeAliases;
-}
-
+ return GroupSetContext->NodeAliases;
+}
+
THoppingWindowSpecPtr TGroupByClause::GetHoppingWindow() const {
return HoppingWindowSpec;
}
@@ -7107,7 +7107,7 @@ bool TGroupByClause::IsCompactGroupBy() const {
TMaybe<TVector<TNodePtr>> TGroupByClause::MultiplyGroupingSets(const TVector<TNodePtr>& lhs, const TVector<TNodePtr>& rhs) const {
TVector<TNodePtr> content;
for (const auto& leftNode: lhs) {
- auto leftPtr = leftNode->ContentListPtr();
+ auto leftPtr = leftNode->ContentListPtr();
if (!leftPtr) {
// TODO: shouldn't happen
Ctx.Error() << "Unable to multiply grouping sets";
@@ -7115,28 +7115,28 @@ TMaybe<TVector<TNodePtr>> TGroupByClause::MultiplyGroupingSets(const TVector<TNo
}
for (const auto& rightNode: rhs) {
TVector<TNodePtr> mulItem(leftPtr->begin(), leftPtr->end());
- auto rightPtr = rightNode->ContentListPtr();
+ auto rightPtr = rightNode->ContentListPtr();
if (!rightPtr) {
// TODO: shouldn't happen
Ctx.Error() << "Unable to multiply grouping sets";
return {};
}
- mulItem.insert(mulItem.end(), rightPtr->begin(), rightPtr->end());
- content.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(mulItem)));
- }
- }
- return content;
-}
-
+ mulItem.insert(mulItem.end(), rightPtr->begin(), rightPtr->end());
+ content.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(mulItem)));
+ }
+ }
+ return content;
+}
+
bool TGroupByClause::ResolveGroupByAndGrouping() {
- auto listPos = std::find_if(GroupBySet.begin(), GroupBySet.end(), [](const TNodePtr& node) {
- return node->ContentListPtr();
- });
- if (listPos == GroupBySet.end()) {
+ auto listPos = std::find_if(GroupBySet.begin(), GroupBySet.end(), [](const TNodePtr& node) {
+ return node->ContentListPtr();
+ });
+ if (listPos == GroupBySet.end()) {
return true;
- }
- auto curContent = *(*listPos)->ContentListPtr();
- if (listPos != GroupBySet.begin()) {
+ }
+ auto curContent = *(*listPos)->ContentListPtr();
+ if (listPos != GroupBySet.begin()) {
TVector<TNodePtr> emulate(GroupBySet.begin(), listPos);
TVector<TNodePtr> emulateContent(1, BuildListOfNamedNodes(Ctx.Pos(), std::move(emulate)));
auto mult = MultiplyGroupingSets(emulateContent, curContent);
@@ -7144,16 +7144,16 @@ bool TGroupByClause::ResolveGroupByAndGrouping() {
return false;
}
curContent = *mult;
- }
- for (++listPos; listPos != GroupBySet.end(); ++listPos) {
- auto newElem = (*listPos)->ContentListPtr();
- if (newElem) {
+ }
+ for (++listPos; listPos != GroupBySet.end(); ++listPos) {
+ auto newElem = (*listPos)->ContentListPtr();
+ if (newElem) {
auto mult = MultiplyGroupingSets(curContent, *newElem);
if (!mult) {
return false;
}
curContent = *mult;
- } else {
+ } else {
TVector<TNodePtr> emulate(1, *listPos);
TVector<TNodePtr> emulateContent(1, BuildListOfNamedNodes(Ctx.Pos(), std::move(emulate)));
auto mult = MultiplyGroupingSets(curContent, emulateContent);
@@ -7161,98 +7161,98 @@ bool TGroupByClause::ResolveGroupByAndGrouping() {
return false;
}
curContent = *mult;
- }
- }
+ }
+ }
TVector<TNodePtr> result(1, BuildListOfNamedNodes(Ctx.Pos(), std::move(curContent)));
- std::swap(result, GroupBySet);
+ std::swap(result, GroupBySet);
return true;
-}
-
+}
+
bool TGroupByClause::GroupingElement(const TRule_grouping_element& node, EGroupByFeatures featureContext) {
- TSourcePtr res;
+ TSourcePtr res;
TVector<TNodePtr> emptyContent;
- switch (node.Alt_case()) {
- case TRule_grouping_element::kAltGroupingElement1:
+ switch (node.Alt_case()) {
+ case TRule_grouping_element::kAltGroupingElement1:
if (!OrdinaryGroupingSet(node.GetAlt_grouping_element1().GetRule_ordinary_grouping_set1(), featureContext)) {
- return false;
- }
- Features().Set(EGroupByFeatures::Ordinary);
- break;
- case TRule_grouping_element::kAltGroupingElement2: {
- TGroupByClause subClause(Ctx, Mode, GroupSetContext);
+ return false;
+ }
+ Features().Set(EGroupByFeatures::Ordinary);
+ break;
+ case TRule_grouping_element::kAltGroupingElement2: {
+ TGroupByClause subClause(Ctx, Mode, GroupSetContext);
if (!subClause.OrdinaryGroupingSetList(node.GetAlt_grouping_element2().GetRule_rollup_list1().GetRule_ordinary_grouping_set_list3(),
EGroupByFeatures::Rollup))
{
- return false;
- }
- auto& content = subClause.Content();
+ return false;
+ }
+ auto& content = subClause.Content();
TVector<TNodePtr> collection;
- for (auto limit = content.end(), begin = content.begin(); limit != begin; --limit) {
+ for (auto limit = content.end(), begin = content.begin(); limit != begin; --limit) {
TVector<TNodePtr> grouping(begin, limit);
- collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(grouping)));
- }
- collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(emptyContent)));
- GroupBySet.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(collection)));
- Ctx.IncrementMonCounter("sql_features", TStringBuilder() << "GroupByRollup" << content.size());
- Features().Set(EGroupByFeatures::Rollup);
- break;
- }
- case TRule_grouping_element::kAltGroupingElement3: {
- TGroupByClause subClause(Ctx, Mode, GroupSetContext);
+ collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(grouping)));
+ }
+ collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(emptyContent)));
+ GroupBySet.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(collection)));
+ Ctx.IncrementMonCounter("sql_features", TStringBuilder() << "GroupByRollup" << content.size());
+ Features().Set(EGroupByFeatures::Rollup);
+ break;
+ }
+ case TRule_grouping_element::kAltGroupingElement3: {
+ TGroupByClause subClause(Ctx, Mode, GroupSetContext);
if (!subClause.OrdinaryGroupingSetList(node.GetAlt_grouping_element3().GetRule_cube_list1().GetRule_ordinary_grouping_set_list3(),
EGroupByFeatures::Cube))
{
- return false;
- }
- auto& content = subClause.Content();
- if (content.size() > Ctx.PragmaGroupByCubeLimit) {
- Ctx.Error() << "GROUP BY CUBE is allowed only for " << Ctx.PragmaGroupByCubeLimit << " columns, but you use " << content.size();
- return false;
- }
+ return false;
+ }
+ auto& content = subClause.Content();
+ if (content.size() > Ctx.PragmaGroupByCubeLimit) {
+ Ctx.Error() << "GROUP BY CUBE is allowed only for " << Ctx.PragmaGroupByCubeLimit << " columns, but you use " << content.size();
+ return false;
+ }
TVector<TNodePtr> collection;
- for (unsigned mask = (1 << content.size()) - 1; mask > 0; --mask) {
+ for (unsigned mask = (1 << content.size()) - 1; mask > 0; --mask) {
TVector<TNodePtr> grouping;
- for (unsigned index = 0; index < content.size(); ++index) {
- if (mask & (1 << index)) {
- grouping.push_back(content[content.size() - index - 1]);
- }
- }
- collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(grouping)));
- }
- collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(emptyContent)));
- GroupBySet.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(collection)));
- Ctx.IncrementMonCounter("sql_features", TStringBuilder() << "GroupByCube" << content.size());
- Features().Set(EGroupByFeatures::Cube);
- break;
- }
- case TRule_grouping_element::kAltGroupingElement4: {
- auto listNode = node.GetAlt_grouping_element4().GetRule_grouping_sets_specification1().GetRule_grouping_element_list4();
- TGroupByClause subClause(Ctx, Mode, GroupSetContext);
+ for (unsigned index = 0; index < content.size(); ++index) {
+ if (mask & (1 << index)) {
+ grouping.push_back(content[content.size() - index - 1]);
+ }
+ }
+ collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(grouping)));
+ }
+ collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(emptyContent)));
+ GroupBySet.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(collection)));
+ Ctx.IncrementMonCounter("sql_features", TStringBuilder() << "GroupByCube" << content.size());
+ Features().Set(EGroupByFeatures::Cube);
+ break;
+ }
+ case TRule_grouping_element::kAltGroupingElement4: {
+ auto listNode = node.GetAlt_grouping_element4().GetRule_grouping_sets_specification1().GetRule_grouping_element_list4();
+ TGroupByClause subClause(Ctx, Mode, GroupSetContext);
if (!subClause.ParseList(listNode, EGroupByFeatures::GroupingSet)) {
- return false;
- }
- auto& content = subClause.Content();
+ return false;
+ }
+ auto& content = subClause.Content();
TVector<TNodePtr> collection;
- bool hasEmpty = false;
- for (auto& elem: content) {
- auto elemContent = elem->ContentListPtr();
- if (elemContent) {
- if (!elemContent->empty() && elemContent->front()->ContentListPtr()) {
- for (auto& sub: *elemContent) {
- FeedCollection(sub, collection, hasEmpty);
- }
- } else {
- FeedCollection(elem, collection, hasEmpty);
- }
- } else {
+ bool hasEmpty = false;
+ for (auto& elem: content) {
+ auto elemContent = elem->ContentListPtr();
+ if (elemContent) {
+ if (!elemContent->empty() && elemContent->front()->ContentListPtr()) {
+ for (auto& sub: *elemContent) {
+ FeedCollection(sub, collection, hasEmpty);
+ }
+ } else {
+ FeedCollection(elem, collection, hasEmpty);
+ }
+ } else {
TVector<TNodePtr> elemList(1, std::move(elem));
- collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(elemList)));
- }
- }
- GroupBySet.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(collection)));
- Features().Set(EGroupByFeatures::GroupingSet);
- break;
- }
+ collection.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(elemList)));
+ }
+ }
+ GroupBySet.push_back(BuildListOfNamedNodes(Ctx.Pos(), std::move(collection)));
+ Features().Set(EGroupByFeatures::GroupingSet);
+ break;
+ }
case TRule_grouping_element::kAltGroupingElement5: {
if (!HoppingWindow(node.GetAlt_grouping_element5().GetRule_hopping_window_specification1())) {
return false;
@@ -7261,41 +7261,41 @@ bool TGroupByClause::GroupingElement(const TRule_grouping_element& node, EGroupB
}
default:
Y_FAIL("You should change implementation according to grammar changes");
- }
- return true;
-}
-
+ }
+ return true;
+}
+
void TGroupByClause::FeedCollection(const TNodePtr& elem, TVector<TNodePtr>& collection, bool& hasEmpty) const {
- auto elemContentPtr = elem->ContentListPtr();
- if (elemContentPtr && elemContentPtr->empty()) {
- if (hasEmpty) {
- return;
- }
- hasEmpty = true;
- }
- collection.push_back(elem);
-}
-
+ auto elemContentPtr = elem->ContentListPtr();
+ if (elemContentPtr && elemContentPtr->empty()) {
+ if (hasEmpty) {
+ return;
+ }
+ hasEmpty = true;
+ }
+ collection.push_back(elem);
+}
+
bool TGroupByClause::OrdinaryGroupingSet(const TRule_ordinary_grouping_set& node, EGroupByFeatures featureContext) {
TNodePtr namedExprNode;
{
TColumnRefScope scope(Ctx, EColumnRefState::Allow);
namedExprNode = NamedExpr(node.GetRule_named_expr1(), EExpr::GroupBy);
}
- if (!namedExprNode) {
- return false;
- }
- auto nodeLabel = namedExprNode->GetLabel();
- auto contentPtr = namedExprNode->ContentListPtr();
- if (contentPtr) {
- if (nodeLabel && (contentPtr->size() != 1 || contentPtr->front()->GetLabel())) {
- Ctx.Error() << "Unable to use aliases for list of named expressions";
- Ctx.IncrementMonCounter("sql_errors", "GroupByAliasForListOfExpressions");
- return false;
- }
- for (auto& content: *contentPtr) {
- auto label = content->GetLabel();
- if (!label) {
+ if (!namedExprNode) {
+ return false;
+ }
+ auto nodeLabel = namedExprNode->GetLabel();
+ auto contentPtr = namedExprNode->ContentListPtr();
+ if (contentPtr) {
+ if (nodeLabel && (contentPtr->size() != 1 || contentPtr->front()->GetLabel())) {
+ Ctx.Error() << "Unable to use aliases for list of named expressions";
+ Ctx.IncrementMonCounter("sql_errors", "GroupByAliasForListOfExpressions");
+ return false;
+ }
+ for (auto& content: *contentPtr) {
+ auto label = content->GetLabel();
+ if (!label) {
if (content->GetColumnName()) {
namedExprNode->AssumeColumn();
continue;
@@ -7305,14 +7305,14 @@ bool TGroupByClause::OrdinaryGroupingSet(const TRule_ordinary_grouping_set& node
return false;
}
- content->SetLabel(label = GenerateGroupByExprName());
- }
- if (!AddAlias(label, content)) {
- return false;
- }
- content = BuildColumn(content->GetPos(), label);
- }
- } else {
+ content->SetLabel(label = GenerateGroupByExprName());
+ }
+ if (!AddAlias(label, content)) {
+ return false;
+ }
+ content = BuildColumn(content->GetPos(), label);
+ }
+ } else {
if (!nodeLabel && namedExprNode->GetColumnName()) {
namedExprNode->AssumeColumn();
}
@@ -7321,31 +7321,31 @@ bool TGroupByClause::OrdinaryGroupingSet(const TRule_ordinary_grouping_set& node
if (!AllowUnnamed(namedExprNode->GetPos(), featureContext)) {
return false;
}
- namedExprNode->SetLabel(nodeLabel = GenerateGroupByExprName());
- }
- if (nodeLabel) {
- if (!AddAlias(nodeLabel, namedExprNode)) {
- return false;
- }
- namedExprNode = BuildColumn(namedExprNode->GetPos(), nodeLabel);
- }
- }
- GroupBySet.emplace_back(std::move(namedExprNode));
- return true;
-}
-
+ namedExprNode->SetLabel(nodeLabel = GenerateGroupByExprName());
+ }
+ if (nodeLabel) {
+ if (!AddAlias(nodeLabel, namedExprNode)) {
+ return false;
+ }
+ namedExprNode = BuildColumn(namedExprNode->GetPos(), nodeLabel);
+ }
+ }
+ GroupBySet.emplace_back(std::move(namedExprNode));
+ return true;
+}
+
bool TGroupByClause::OrdinaryGroupingSetList(const TRule_ordinary_grouping_set_list& node, EGroupByFeatures featureContext) {
if (!OrdinaryGroupingSet(node.GetRule_ordinary_grouping_set1(), featureContext)) {
- return false;
- }
- for (auto& block: node.GetBlock2()) {
+ return false;
+ }
+ for (auto& block: node.GetBlock2()) {
if (!OrdinaryGroupingSet(block.GetRule_ordinary_grouping_set2(), featureContext)) {
- return false;
- }
- }
- return true;
-}
-
+ return false;
+ }
+ }
+ return true;
+}
+
bool TGroupByClause::HoppingWindow(const TRule_hopping_window_specification& node) {
if (HoppingWindowSpec) {
Ctx.Error() << "Duplicate hopping window specification.";
@@ -7428,35 +7428,35 @@ bool TGroupByClause::AllowUnnamed(TPosition pos, EGroupByFeatures featureContext
break;
default:
YQL_ENSURE(false, "Unknown feature");
- }
+ }
Ctx.Error(pos) << "Unnamed expressions are not supported in " << feature << ". Please use '<expr> AS <name>'.";
Ctx.IncrementMonCounter("sql_errors", "GroupBySetNoAliasOrColumn");
return false;
-}
-
-TGroupByClause::TGroupingSetFeatures& TGroupByClause::Features() {
- return GroupSetContext->GroupFeatures;
-}
-
-const TGroupByClause::TGroupingSetFeatures& TGroupByClause::Features() const {
- return GroupSetContext->GroupFeatures;
-}
-
+}
+
+TGroupByClause::TGroupingSetFeatures& TGroupByClause::Features() {
+ return GroupSetContext->GroupFeatures;
+}
+
+const TGroupByClause::TGroupingSetFeatures& TGroupByClause::Features() const {
+ return GroupSetContext->GroupFeatures;
+}
+
bool TGroupByClause::AddAlias(const TString& label, const TNodePtr& node) {
if (Aliases().contains(label)) {
- Ctx.Error() << "Duplicated aliases not allowed";
- Ctx.IncrementMonCounter("sql_errors", "GroupByDuplicateAliases");
- return false;
- }
- Aliases().emplace(label, node);
- return true;
-}
-
+ Ctx.Error() << "Duplicated aliases not allowed";
+ Ctx.IncrementMonCounter("sql_errors", "GroupByDuplicateAliases");
+ return false;
+ }
+ Aliases().emplace(label, node);
+ return true;
+}
+
TString TGroupByClause::GenerateGroupByExprName() {
- return TStringBuilder() << AutogenerateNamePrefix << GroupSetContext->UnnamedCount++;
-}
-
+ return TStringBuilder() << AutogenerateNamePrefix << GroupSetContext->UnnamedCount++;
+}
+
bool TSqlSelect::ValidateLimitOrderByWithSelectOp(TMaybe<TSelectKindPlacement> placement, TStringBuf what) {
if (!placement.Defined()) {
// not in select_op chain
@@ -7494,42 +7494,42 @@ TSqlSelect::TSelectKindResult TSqlSelect::SelectKind(const TRule_select_kind_par
{
auto res = SelectKind(node.GetRule_select_kind1(), selectPos, placement);
if (!res) {
- return {};
- }
- TPosition startPos(Ctx.Pos());
- /// LIMIT INTEGER block
- TNodePtr skipTake;
- if (node.HasBlock2()) {
- auto block = node.GetBlock2();
-
- Token(block.GetToken1());
- TPosition pos(Ctx.Pos());
-
+ return {};
+ }
+ TPosition startPos(Ctx.Pos());
+ /// LIMIT INTEGER block
+ TNodePtr skipTake;
+ if (node.HasBlock2()) {
+ auto block = node.GetBlock2();
+
+ Token(block.GetToken1());
+ TPosition pos(Ctx.Pos());
+
if (!ValidateLimitOrderByWithSelectOp(placement, "LIMIT")) {
return {};
}
TSqlExpression takeExpr(Ctx, Mode);
auto take = takeExpr.Build(block.GetRule_expr2());
- if (!take) {
+ if (!take) {
return{};
- }
+ }
- TNodePtr skip;
- if (block.HasBlock3()) {
+ TNodePtr skip;
+ if (block.HasBlock3()) {
TSqlExpression skipExpr(Ctx, Mode);
skip = skipExpr.Build(block.GetBlock3().GetRule_expr2());
- if (!skip) {
- return {};
- }
- if (Token(block.GetBlock3().GetToken1()) == ",") {
- // LIMIT skip, take
- skip.Swap(take);
- Ctx.IncrementMonCounter("sql_features", "LimitSkipTake");
- } else {
- Ctx.IncrementMonCounter("sql_features", "LimitOffset");
- }
- }
+ if (!skip) {
+ return {};
+ }
+ if (Token(block.GetBlock3().GetToken1()) == ",") {
+ // LIMIT skip, take
+ skip.Swap(take);
+ Ctx.IncrementMonCounter("sql_features", "LimitSkipTake");
+ } else {
+ Ctx.IncrementMonCounter("sql_features", "LimitOffset");
+ }
+ }
auto st = BuildSkipTake(pos, skip, take);
if (NeedPassLimitOrderByToUnderlyingSelect(placement)) {
@@ -7538,13 +7538,13 @@ TSqlSelect::TSelectKindResult TSqlSelect::SelectKind(const TRule_select_kind_par
res.SelectOpSkipTake = st;
}
- Ctx.IncrementMonCounter("sql_features", "Limit");
- }
+ Ctx.IncrementMonCounter("sql_features", "Limit");
+ }
res.Source = BuildSelect(startPos, std::move(res.Source), skipTake);
return res;
-}
-
+}
+
TSqlSelect::TSelectKindResult TSqlSelect::SelectKind(const TRule_select_kind& node, TPosition& selectPos,
TMaybe<TSelectKindPlacement> placement)
{
@@ -7609,7 +7609,7 @@ TSqlSelect::TSelectKindResult TSqlSelect::SelectKind(const TRule_select_kind& no
case TRule_select_kind_TBlock2::kAlt3: {
res.Source = SelectCore(node.GetBlock2().GetAlt3().GetRule_select_core1(), settings, selectPos,
placement, res.SelectOpOrderBy, res.SelectOpAssumeOrderBy);
- break;
+ break;
}
default:
Y_FAIL("You should change implementation according to grammar changes");
@@ -7621,13 +7621,13 @@ TSqlSelect::TSelectKindResult TSqlSelect::SelectKind(const TRule_select_kind& no
TSqlSelect::TSelectKindResult TSqlSelect::SelectKind(const TRule_select_kind_parenthesis& node, TPosition& selectPos,
TMaybe<TSelectKindPlacement> placement)
{
- if (node.Alt_case() == TRule_select_kind_parenthesis::kAltSelectKindParenthesis1) {
+ if (node.Alt_case() == TRule_select_kind_parenthesis::kAltSelectKindParenthesis1) {
return SelectKind(node.GetAlt_select_kind_parenthesis1().GetRule_select_kind_partial1(), selectPos, placement);
- } else {
+ } else {
return SelectKind(node.GetAlt_select_kind_parenthesis2().GetRule_select_kind_partial2(), selectPos, {});
- }
-}
-
+ }
+}
+
template<typename TRule>
TSourcePtr TSqlSelect::Build(const TRule& node, TPosition pos, TSelectKindResult&& first) {
TPosition unionPos = pos; // Position of first select
@@ -7659,17 +7659,17 @@ TSourcePtr TSqlSelect::Build(const TRule& node, TPosition pos, TSelectKindResult
}
switch (b.GetRule_select_op1().Alt_case()) {
- case TRule_select_op::kAltSelectOp1: {
+ case TRule_select_op::kAltSelectOp1: {
const bool isUnionAll = b.GetRule_select_op1().GetAlt_select_op1().HasBlock2();
- if (!isUnionAll) {
- Token(b.GetRule_select_op1().GetAlt_select_op1().GetToken1());
- Ctx.Error() << "UNION without quantifier ALL is not supported yet. Did you mean UNION ALL?";
- return nullptr;
- } else {
+ if (!isUnionAll) {
+ Token(b.GetRule_select_op1().GetAlt_select_op1().GetToken1());
+ Ctx.Error() << "UNION without quantifier ALL is not supported yet. Did you mean UNION ALL?";
+ return nullptr;
+ } else {
sources.emplace_back(std::move(next.Source));
- }
+ }
break;
- }
+ }
default:
Ctx.Error() << "INTERSECT and EXCEPT are not implemented yet";
return nullptr;
@@ -7849,30 +7849,30 @@ TSourcePtr TSqlIntoValues::Build(const TRule_into_values_source& node, const TSt
TSourcePtr TSqlIntoValues::ValuesSource(const TRule_values_source& node, TVector<TString>& columnsHint,
const TString& operationName)
{
- Ctx.IncrementMonCounter("sql_features", "ValuesSource");
+ Ctx.IncrementMonCounter("sql_features", "ValuesSource");
TPosition pos(Ctx.Pos());
- switch (node.Alt_case()) {
- case TRule_values_source::kAltValuesSource1: {
+ switch (node.Alt_case()) {
+ case TRule_values_source::kAltValuesSource1: {
TVector<TVector<TNodePtr>> rows {{}};
const auto& rowList = node.GetAlt_values_source1().GetRule_values_stmt1().GetRule_values_source_row_list2();
if (!BuildRows(rowList, rows)) {
- return nullptr;
+ return nullptr;
}
return BuildWriteValues(pos, operationName, columnsHint, rows);
}
- case TRule_values_source::kAltValuesSource2: {
+ case TRule_values_source::kAltValuesSource2: {
TSqlSelect select(Ctx, Mode);
TPosition selectPos;
auto source = select.Build(node.GetAlt_values_source2().GetRule_select_stmt1(), selectPos);
if (!source) {
return nullptr;
}
- return BuildWriteValues(pos, "UPDATE", columnsHint, std::move(source));
+ return BuildWriteValues(pos, "UPDATE", columnsHint, std::move(source));
}
- default:
- Ctx.IncrementMonCounter("sql_errors", "UnknownValuesSource");
- AltNotImplemented("values_source", node);
- return nullptr;
+ default:
+ Ctx.IncrementMonCounter("sql_errors", "UnknownValuesSource");
+ AltNotImplemented("values_source", node);
+ return nullptr;
}
}
@@ -7896,16 +7896,16 @@ private:
TString SqlIntoUserModeStr;
};
-TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) {
+TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) {
static const TMap<TString, ESQLWriteColumnMode> str2Mode = {
- {"InsertInto", ESQLWriteColumnMode::InsertInto},
+ {"InsertInto", ESQLWriteColumnMode::InsertInto},
{"InsertOrAbortInto", ESQLWriteColumnMode::InsertOrAbortInto},
{"InsertOrIgnoreInto", ESQLWriteColumnMode::InsertOrIgnoreInto},
{"InsertOrRevertInto", ESQLWriteColumnMode::InsertOrRevertInto},
- {"UpsertInto", ESQLWriteColumnMode::UpsertInto},
- {"ReplaceInto", ESQLWriteColumnMode::ReplaceInto},
+ {"UpsertInto", ESQLWriteColumnMode::UpsertInto},
+ {"ReplaceInto", ESQLWriteColumnMode::ReplaceInto},
{"InsertIntoWithTruncate", ESQLWriteColumnMode::InsertIntoWithTruncate}
- };
+ };
auto& modeBlock = node.GetBlock1();
@@ -8049,18 +8049,18 @@ TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) {
);
}
- if (withTruncate) {
- if (SqlIntoModeStr != "InsertInto") {
- Error() << "Unable " << SqlIntoUserModeStr << " with truncate mode";
- return nullptr;
- }
- SqlIntoModeStr += "WithTruncate";
- SqlIntoUserModeStr += " ... WITH TRUNCATE";
- }
- const auto iterMode = str2Mode.find(SqlIntoModeStr);
- YQL_ENSURE(iterMode != str2Mode.end(), "Invalid sql write mode string: " << SqlIntoModeStr);
+ if (withTruncate) {
+ if (SqlIntoModeStr != "InsertInto") {
+ Error() << "Unable " << SqlIntoUserModeStr << " with truncate mode";
+ return nullptr;
+ }
+ SqlIntoModeStr += "WithTruncate";
+ SqlIntoUserModeStr += " ... WITH TRUNCATE";
+ }
+ const auto iterMode = str2Mode.find(SqlIntoModeStr);
+ YQL_ENSURE(iterMode != str2Mode.end(), "Invalid sql write mode string: " << SqlIntoModeStr);
const auto SqlIntoMode = iterMode->second;
-
+
TPosition pos(Ctx.Pos());
TNodePtr tableKey = BuildTableKey(pos, service, cluster, nameOrAt.second, nameOrAt.first ? "@" : "");
@@ -8068,13 +8068,13 @@ TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) {
Ctx.IncrementMonCounter("sql_insert_clusters", table.Cluster.GetLiteral() ? *table.Cluster.GetLiteral() : "unknown");
auto values = TSqlIntoValues(Ctx, Mode).Build(node.GetRule_into_values_source4(), SqlIntoUserModeStr);
- if (!values) {
- return nullptr;
- }
+ if (!values) {
+ return nullptr;
+ }
if (!ValidateServiceName(node, table, SqlIntoMode, GetPos(modeTokens[0]))) {
- return nullptr;
- }
- Ctx.IncrementMonCounter("sql_features", SqlIntoModeStr);
+ return nullptr;
+ }
+ Ctx.IncrementMonCounter("sql_features", SqlIntoModeStr);
TNodePtr options;
if (eraseColumns) {
@@ -8082,8 +8082,8 @@ TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) {
}
return BuildWriteColumns(pos, Ctx.Scoped, table, ToWriteColumnsMode(SqlIntoMode), std::move(values), std::move(options));
-}
-
+}
+
bool TSqlIntoTable::ValidateServiceName(const TRule_into_table_stmt& node, const TTableRef& table,
ESQLWriteColumnMode mode, const TPosition& pos) {
Y_UNUSED(node);
@@ -8105,18 +8105,18 @@ bool TSqlIntoTable::ValidateServiceName(const TRule_into_table_stmt& node, const
}
}
- if (isMapReduce) {
- if (mode == ESQLWriteColumnMode::ReplaceInto) {
+ if (isMapReduce) {
+ if (mode == ESQLWriteColumnMode::ReplaceInto) {
Ctx.Error(pos) << "Meaning of REPLACE INTO has been changed, now you should use INSERT INTO <table> WITH TRUNCATE ... for " << serviceName;
- Ctx.IncrementMonCounter("sql_errors", "ReplaceIntoConflictUsage");
+ Ctx.IncrementMonCounter("sql_errors", "ReplaceIntoConflictUsage");
return false;
- }
- } else if (isKikimr) {
+ }
+ } else if (isKikimr) {
if (mode == ESQLWriteColumnMode::InsertIntoWithTruncate) {
Ctx.Error(pos) << "INSERT INTO WITH TRUNCATE is not supported for " << serviceName << " tables";
- Ctx.IncrementMonCounter("sql_errors", TStringBuilder() << SqlIntoUserModeStr << "UnsupportedFor" << serviceName);
- return false;
- }
+ Ctx.IncrementMonCounter("sql_errors", TStringBuilder() << SqlIntoUserModeStr << "UnsupportedFor" << serviceName);
+ return false;
+ }
} else if (isRtmr) {
if (mode != ESQLWriteColumnMode::InsertInto) {
Ctx.Error(pos) << SqlIntoUserModeStr << " is unsupported for " << serviceName;
@@ -8129,11 +8129,11 @@ bool TSqlIntoTable::ValidateServiceName(const TRule_into_table_stmt& node, const
Ctx.IncrementMonCounter("sql_errors", TStringBuilder() << SqlIntoUserModeStr << "UnsupportedFor" << serviceName);
return false;
}
- }
+ }
+
+ return true;
+}
- return true;
-}
-
class TSqlQuery: public TSqlTranslation {
public:
TSqlQuery(TContext& ctx, NSQLTranslation::ESqlMode mode, bool topLevel)
@@ -8146,8 +8146,8 @@ public:
bool Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& core);
private:
- bool DeclareStatement(const TRule_declare_stmt& stmt);
- bool ExportStatement(const TRule_export_stmt& stmt);
+ bool DeclareStatement(const TRule_declare_stmt& stmt);
+ bool ExportStatement(const TRule_export_stmt& stmt);
bool AlterTableAction(const TRule_alter_table_action& node, TAlterTableParameters& params);
bool AlterTableAddColumn(const TRule_alter_table_add_column& node, TAlterTableParameters& params);
bool AlterTableDropColumn(const TRule_alter_table_drop_column& node, TAlterTableParameters& params);
@@ -8166,34 +8166,34 @@ private:
TNodePtr PragmaStatement(const TRule_pragma_stmt& stmt, bool& success);
void AddStatementToBlocks(TVector<TNodePtr>& blocks, TNodePtr node);
- TNodePtr Build(const TRule_delete_stmt& stmt);
-
- TNodePtr Build(const TRule_update_stmt& stmt);
- TSourcePtr Build(const TRule_set_clause_choice& stmt);
+ TNodePtr Build(const TRule_delete_stmt& stmt);
+
+ TNodePtr Build(const TRule_update_stmt& stmt);
+ TSourcePtr Build(const TRule_set_clause_choice& stmt);
bool FillSetClause(const TRule_set_clause& node, TVector<TString>& targetList, TVector<TNodePtr>& values);
- TSourcePtr Build(const TRule_set_clause_list& stmt);
- TSourcePtr Build(const TRule_multiple_column_assignment& stmt);
-
- template<class TNode>
+ TSourcePtr Build(const TRule_set_clause_list& stmt);
+ TSourcePtr Build(const TRule_multiple_column_assignment& stmt);
+
+ template<class TNode>
void ParseStatementName(const TNode& node, TString& internalStatementName, TString& humanStatementName) {
internalStatementName.clear();
humanStatementName.clear();
- const auto& descr = AltDescription(node);
+ const auto& descr = AltDescription(node);
TVector<TString> parts;
- const auto pos = descr.find(": ");
+ const auto pos = descr.find(": ");
Y_VERIFY_DEBUG(pos != TString::npos);
Split(TString(descr.begin() + pos + 2, descr.end()), "_", parts);
- Y_VERIFY_DEBUG(parts.size() > 1);
- parts.pop_back();
- for (auto& part: parts) {
- part.to_upper(0, 1);
+ Y_VERIFY_DEBUG(parts.size() > 1);
+ parts.pop_back();
+ for (auto& part: parts) {
+ part.to_upper(0, 1);
internalStatementName += part;
if (!humanStatementName.empty()) {
humanStatementName += ' ';
- }
+ }
humanStatementName += to_upper(part);
- }
- }
+ }
+ }
const bool TopLevel;
};
@@ -8299,12 +8299,12 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
TString internalStatementName;
TString humanStatementName;
ParseStatementName(core, internalStatementName, humanStatementName);
- const auto& altCase = core.Alt_case();
+ const auto& altCase = core.Alt_case();
if (Mode == NSQLTranslation::ESqlMode::LIMITED_VIEW && (altCase >= TRule_sql_stmt_core::kAltSqlStmtCore4 &&
altCase != TRule_sql_stmt_core::kAltSqlStmtCore13)) {
Error() << humanStatementName << " statement is not supported in limited views";
- return false;
- }
+ return false;
+ }
if (Mode == NSQLTranslation::ESqlMode::SUBQUERY && (altCase >= TRule_sql_stmt_core::kAltSqlStmtCore4 &&
altCase != TRule_sql_stmt_core::kAltSqlStmtCore13 && altCase != TRule_sql_stmt_core::kAltSqlStmtCore6 &&
@@ -8313,12 +8313,12 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
return false;
}
- switch (altCase) {
+ switch (altCase) {
case TRule_sql_stmt_core::kAltSqlStmtCore1: {
bool success = false;
TNodePtr nodeExpr = PragmaStatement(core.GetAlt_sql_stmt_core1().GetRule_pragma_stmt1(), success);
if (!success) {
- return false;
+ return false;
}
if (nodeExpr) {
AddStatementToBlocks(blocks, nodeExpr);
@@ -8326,7 +8326,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
break;
}
case TRule_sql_stmt_core::kAltSqlStmtCore2: {
- Ctx.BodyPart();
+ Ctx.BodyPart();
TSqlSelect select(Ctx, Mode);
TPosition pos;
auto source = select.Build(core.GetAlt_sql_stmt_core2().GetRule_select_stmt1(), pos);
@@ -8339,20 +8339,20 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
break;
}
case TRule_sql_stmt_core::kAltSqlStmtCore3: {
- Ctx.BodyPart();
+ Ctx.BodyPart();
TVector<TSymbolNameWithPos> names;
auto nodeExpr = NamedNode(core.GetAlt_sql_stmt_core3().GetRule_named_nodes_stmt1(), names);
- if (!nodeExpr) {
+ if (!nodeExpr) {
return false;
}
TVector<TNodePtr> nodes;
- auto subquery = nodeExpr->GetSource();
- if (subquery) {
- const auto alias = Ctx.MakeName("subquerynode");
- const auto ref = Ctx.MakeName("subquery");
+ auto subquery = nodeExpr->GetSource();
+ if (subquery) {
+ const auto alias = Ctx.MakeName("subquerynode");
+ const auto ref = Ctx.MakeName("subquery");
blocks.push_back(BuildSubquery(subquery, alias,
Mode == NSQLTranslation::ESqlMode::SUBQUERY, names.size() == 1 ? -1 : names.size(), Ctx.Scoped));
- blocks.back()->SetLabel(ref);
+ blocks.back()->SetLabel(ref);
for (size_t i = 0; i < names.size(); ++i) {
nodes.push_back(BuildSubqueryRef(blocks.back(), ref, names.size() == 1 ? -1 : i));
@@ -8366,7 +8366,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
} else {
nodes.push_back(std::move(nodeExpr));
}
- }
+ }
for (size_t i = 0; i < names.size(); ++i) {
PushNamedNode(names[i].Pos, names[i].Name, nodes[i]);
@@ -8374,7 +8374,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
break;
}
case TRule_sql_stmt_core::kAltSqlStmtCore4: {
- Ctx.BodyPart();
+ Ctx.BodyPart();
const auto& rule = core.GetAlt_sql_stmt_core4().GetRule_create_table_stmt1();
TTableRef tr;
if (!SimpleTableRefImpl(rule.GetRule_simple_table_ref3(), tr)) {
@@ -8384,12 +8384,12 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
TCreateTableParameters params;
if (!CreateTableEntry(rule.GetRule_create_table_entry5(), params)) {
- return false;
- }
+ return false;
+ }
for (auto& block: rule.GetBlock6()) {
if (!CreateTableEntry(block.GetRule_create_table_entry2(), params)) {
- return false;
- }
+ return false;
+ }
}
if (rule.HasBlock8()) {
@@ -8402,7 +8402,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
break;
}
case TRule_sql_stmt_core::kAltSqlStmtCore5: {
- Ctx.BodyPart();
+ Ctx.BodyPart();
const auto& rule = core.GetAlt_sql_stmt_core5().GetRule_drop_table_stmt1();
if (rule.HasBlock3()) {
Context().Error(GetPos(rule.GetToken1())) << "IF EXISTS in " << humanStatementName
@@ -8417,72 +8417,72 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
AddStatementToBlocks(blocks, BuildDropTable(Ctx.Pos(), tr, Ctx.Scoped));
break;
}
- case TRule_sql_stmt_core::kAltSqlStmtCore6: {
- const auto& rule = core.GetAlt_sql_stmt_core6().GetRule_use_stmt1();
- Token(rule.GetToken1());
+ case TRule_sql_stmt_core::kAltSqlStmtCore6: {
+ const auto& rule = core.GetAlt_sql_stmt_core6().GetRule_use_stmt1();
+ Token(rule.GetToken1());
if (!ClusterExpr(rule.GetRule_cluster_expr2(), true, Ctx.Scoped->CurrService, Ctx.Scoped->CurrCluster)) {
return false;
}
- break;
- }
- case TRule_sql_stmt_core::kAltSqlStmtCore7: {
- Ctx.BodyPart();
- TSqlIntoTable intoTable(Ctx, Mode);
- TNodePtr block(intoTable.Build(core.GetAlt_sql_stmt_core7().GetRule_into_table_stmt1()));
- if (!block) {
+ break;
+ }
+ case TRule_sql_stmt_core::kAltSqlStmtCore7: {
+ Ctx.BodyPart();
+ TSqlIntoTable intoTable(Ctx, Mode);
+ TNodePtr block(intoTable.Build(core.GetAlt_sql_stmt_core7().GetRule_into_table_stmt1()));
+ if (!block) {
return false;
}
- blocks.emplace_back(block);
- break;
- }
- case TRule_sql_stmt_core::kAltSqlStmtCore8: {
- Ctx.BodyPart();
+ blocks.emplace_back(block);
+ break;
+ }
+ case TRule_sql_stmt_core::kAltSqlStmtCore8: {
+ Ctx.BodyPart();
const auto& rule = core.GetAlt_sql_stmt_core8().GetRule_commit_stmt1();
Token(rule.GetToken1());
- blocks.emplace_back(BuildCommitClusters(Ctx.Pos()));
+ blocks.emplace_back(BuildCommitClusters(Ctx.Pos()));
break;
}
- case TRule_sql_stmt_core::kAltSqlStmtCore9: {
- Ctx.BodyPart();
- auto updateNode = Build(core.GetAlt_sql_stmt_core9().GetRule_update_stmt1());
- if (!updateNode) {
- return false;
- }
+ case TRule_sql_stmt_core::kAltSqlStmtCore9: {
+ Ctx.BodyPart();
+ auto updateNode = Build(core.GetAlt_sql_stmt_core9().GetRule_update_stmt1());
+ if (!updateNode) {
+ return false;
+ }
AddStatementToBlocks(blocks, updateNode);
- break;
- }
- case TRule_sql_stmt_core::kAltSqlStmtCore10: {
- Ctx.BodyPart();
- auto deleteNode = Build(core.GetAlt_sql_stmt_core10().GetRule_delete_stmt1());
- if (!deleteNode) {
- return false;
- }
- blocks.emplace_back(deleteNode);
- break;
- }
+ break;
+ }
+ case TRule_sql_stmt_core::kAltSqlStmtCore10: {
+ Ctx.BodyPart();
+ auto deleteNode = Build(core.GetAlt_sql_stmt_core10().GetRule_delete_stmt1());
+ if (!deleteNode) {
+ return false;
+ }
+ blocks.emplace_back(deleteNode);
+ break;
+ }
case TRule_sql_stmt_core::kAltSqlStmtCore11: {
- Ctx.BodyPart();
+ Ctx.BodyPart();
const auto& rule = core.GetAlt_sql_stmt_core11().GetRule_rollback_stmt1();
Token(rule.GetToken1());
- blocks.emplace_back(BuildRollbackClusters(Ctx.Pos()));
+ blocks.emplace_back(BuildRollbackClusters(Ctx.Pos()));
break;
}
- case TRule_sql_stmt_core::kAltSqlStmtCore12:
- if (!DeclareStatement(core.GetAlt_sql_stmt_core12().GetRule_declare_stmt1())) {
- return false;
- }
- break;
- case TRule_sql_stmt_core::kAltSqlStmtCore13:
+ case TRule_sql_stmt_core::kAltSqlStmtCore12:
+ if (!DeclareStatement(core.GetAlt_sql_stmt_core12().GetRule_declare_stmt1())) {
+ return false;
+ }
+ break;
+ case TRule_sql_stmt_core::kAltSqlStmtCore13:
if (!ImportStatement(core.GetAlt_sql_stmt_core13().GetRule_import_stmt1())) {
- return false;
- }
- break;
- case TRule_sql_stmt_core::kAltSqlStmtCore14:
- if (!ExportStatement(core.GetAlt_sql_stmt_core14().GetRule_export_stmt1())) {
- return false;
- }
- break;
+ return false;
+ }
+ break;
+ case TRule_sql_stmt_core::kAltSqlStmtCore14:
+ if (!ExportStatement(core.GetAlt_sql_stmt_core14().GetRule_export_stmt1())) {
+ return false;
+ }
+ break;
case TRule_sql_stmt_core::kAltSqlStmtCore15: {
Ctx.BodyPart();
const auto& rule = core.GetAlt_sql_stmt_core15().GetRule_alter_table_stmt1();
@@ -8767,57 +8767,57 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
return !Ctx.HasPendingErrors;
}
-bool TSqlQuery::DeclareStatement(const TRule_declare_stmt& stmt) {
- TNodePtr defaultValue;
- if (stmt.HasBlock5()) {
- TSqlExpression sqlExpr(Ctx, Mode);
+bool TSqlQuery::DeclareStatement(const TRule_declare_stmt& stmt) {
+ TNodePtr defaultValue;
+ if (stmt.HasBlock5()) {
+ TSqlExpression sqlExpr(Ctx, Mode);
auto exprOrId = sqlExpr.LiteralExpr(stmt.GetBlock5().GetRule_literal_value2());
if (!exprOrId) {
- return false;
- }
+ return false;
+ }
if (!exprOrId->Expr) {
Ctx.Error() << "Identifier is not expected here";
return false;
}
defaultValue = exprOrId->Expr;
- }
- if (defaultValue) {
- Error() << "DEFAULT value not supported yet";
- return false;
- }
- if (!Ctx.IsParseHeading()) {
- Error() << "DECLARE statement should be in beginning of query, but it's possible to use PRAGMA or USE before it";
- return false;
- }
+ }
+ if (defaultValue) {
+ Error() << "DEFAULT value not supported yet";
+ return false;
+ }
+ if (!Ctx.IsParseHeading()) {
+ Error() << "DECLARE statement should be in beginning of query, but it's possible to use PRAGMA or USE before it";
+ return false;
+ }
TString varName;
if (!NamedNodeImpl(stmt.GetRule_bind_parameter2(), varName, *this)) {
return false;
}
- const auto varPos = Ctx.Pos();
+ const auto varPos = Ctx.Pos();
const auto typeNode = TypeNode(stmt.GetRule_type_name4());
- if (!typeNode) {
- return false;
- }
+ if (!typeNode) {
+ return false;
+ }
if (IsAnonymousName(varName)) {
Ctx.Error(varPos) << "Can not use anonymous name '" << varName << "' in DECLARE statement";
return false;
}
varName = PushNamedAtom(varPos, varName);
Ctx.DeclareVariable(varName, typeNode);
- return true;
-}
-
-bool TSqlQuery::ExportStatement(const TRule_export_stmt& stmt) {
+ return true;
+}
+
+bool TSqlQuery::ExportStatement(const TRule_export_stmt& stmt) {
if (Mode != NSQLTranslation::ESqlMode::LIBRARY || !TopLevel) {
Error() << "EXPORT statement should be used only in a library on the top level";
return false;
}
TVector<TSymbolNameWithPos> bindNames;
- if (!BindList(stmt.GetRule_bind_parameter_list2(), bindNames)) {
- return false;
- }
+ if (!BindList(stmt.GetRule_bind_parameter_list2(), bindNames)) {
+ return false;
+ }
for (auto& bindName : bindNames) {
if (!Ctx.AddExport(bindName.Pos, bindName.Name)) {
@@ -8825,8 +8825,8 @@ bool TSqlQuery::ExportStatement(const TRule_export_stmt& stmt) {
}
}
return true;
-}
-
+}
+
bool TSqlQuery::AlterTableAction(const TRule_alter_table_action& node, TAlterTableParameters& params) {
if (params.RenameTo) {
// rename action is followed by some other actions
@@ -9132,7 +9132,7 @@ void TSqlQuery::AlterTableDropChangefeed(const TRule_alter_table_drop_changefeed
}
TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success) {
- success = false;
+ success = false;
const TString& prefix = OptIdPrefixAsStr(stmt.GetRule_opt_id_prefix_or_type2(), *this);
const TString& lowerPrefix = to_lower(prefix);
const TString pragma(Id(stmt.GetRule_an_id3(), *this));
@@ -9143,25 +9143,25 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
Ctx.IncrementMonCounter("sql_errors", "NormalizePragmaError");
return {};
}
-
+
TVector<TDeferredAtom> values;
TVector<const TRule_pragma_value*> pragmaValues;
bool pragmaValueDefault = false;
- if (stmt.GetBlock4().HasAlt1()) {
- pragmaValues.push_back(&stmt.GetBlock4().GetAlt1().GetRule_pragma_value2());
- }
- else if (stmt.GetBlock4().HasAlt2()) {
- pragmaValues.push_back(&stmt.GetBlock4().GetAlt2().GetRule_pragma_value2());
- for (auto& additionalValue : stmt.GetBlock4().GetAlt2().GetBlock3()) {
- pragmaValues.push_back(&additionalValue.GetRule_pragma_value2());
- }
- }
-
+ if (stmt.GetBlock4().HasAlt1()) {
+ pragmaValues.push_back(&stmt.GetBlock4().GetAlt1().GetRule_pragma_value2());
+ }
+ else if (stmt.GetBlock4().HasAlt2()) {
+ pragmaValues.push_back(&stmt.GetBlock4().GetAlt2().GetRule_pragma_value2());
+ for (auto& additionalValue : stmt.GetBlock4().GetAlt2().GetBlock3()) {
+ pragmaValues.push_back(&additionalValue.GetRule_pragma_value2());
+ }
+ }
+
const bool withConfigure = prefix || normalizedPragma == "file" || normalizedPragma == "folder" || normalizedPragma == "udf";
static const THashSet<TStringBuf> lexicalScopePragmas = {"classicdivision", "strictjoinkeytypes", "disablestrictjoinkeytypes"};
const bool hasLexicalScope = withConfigure || lexicalScopePragmas.contains(normalizedPragma);
- for (auto pragmaValue : pragmaValues) {
- if (pragmaValue->HasAlt_pragma_value3()) {
+ for (auto pragmaValue : pragmaValues) {
+ if (pragmaValue->HasAlt_pragma_value3()) {
auto value = Token(pragmaValue->GetAlt_pragma_value3().GetToken1());
auto parsed = StringContentOrIdContent(Ctx, Ctx.Pos(), value);
if (!parsed) {
@@ -9172,7 +9172,7 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
}
else if (pragmaValue->HasAlt_pragma_value2()
&& pragmaValue->GetAlt_pragma_value2().GetRule_id1().HasAlt_id2()
- && "default" == Id(pragmaValue->GetAlt_pragma_value2().GetRule_id1(), *this))
+ && "default" == Id(pragmaValue->GetAlt_pragma_value2().GetRule_id1(), *this))
{
pragmaValueDefault = true;
}
@@ -9191,11 +9191,11 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
values.push_back(atom);
} else {
Error() << "Expected string" << (withConfigure ? ", named parameter" : "") << " or 'default' keyword as pragma value for pragma: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
- }
-
+ }
+ }
+
if (prefix.empty()) {
if (!TopLevel && !hasLexicalScope) {
Error() << "This pragma '" << pragma << "' is not allowed to be used in actions or subqueries";
@@ -9204,22 +9204,22 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
}
if (normalizedPragma == "refselect") {
- Ctx.PragmaRefSelect = true;
- Ctx.IncrementMonCounter("sql_pragma", "RefSelect");
- } else if (normalizedPragma == "sampleselect") {
- Ctx.PragmaSampleSelect = true;
- Ctx.IncrementMonCounter("sql_pragma", "SampleSelect");
- } else if (normalizedPragma == "allowdotinalias") {
- Ctx.PragmaAllowDotInAlias = true;
- Ctx.IncrementMonCounter("sql_pragma", "AllowDotInAlias");
- } else if (normalizedPragma == "udf") {
+ Ctx.PragmaRefSelect = true;
+ Ctx.IncrementMonCounter("sql_pragma", "RefSelect");
+ } else if (normalizedPragma == "sampleselect") {
+ Ctx.PragmaSampleSelect = true;
+ Ctx.IncrementMonCounter("sql_pragma", "SampleSelect");
+ } else if (normalizedPragma == "allowdotinalias") {
+ Ctx.PragmaAllowDotInAlias = true;
+ Ctx.IncrementMonCounter("sql_pragma", "AllowDotInAlias");
+ } else if (normalizedPragma == "udf") {
if (values.size() != 1 || pragmaValueDefault) {
Error() << "Expected file alias as pragma value";
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
-
- Ctx.IncrementMonCounter("sql_pragma", "udf");
+ }
+
+ Ctx.IncrementMonCounter("sql_pragma", "udf");
success = true;
return BuildPragma(Ctx.Pos(), TString(ConfigProviderName), "ImportUdfs", values, false);
} else if (normalizedPragma == "packageversion") {
@@ -9247,7 +9247,7 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
Ctx.IncrementMonCounter("sql_pragma", "PackageVersion");
success = true;
return BuildPragma(Ctx.Pos(), TString(ConfigProviderName), "SetPackageVersion", TVector<TDeferredAtom>{ values[0], TDeferredAtom(values[1].Build()->GetPos(), ToString(version)) }, false);
- } else if (normalizedPragma == "file") {
+ } else if (normalizedPragma == "file") {
if (values.size() != 2U || pragmaValueDefault) {
Error() << "Expected file alias and url as pragma values";
Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
@@ -9293,12 +9293,12 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
} else if (normalizedPragma == "directread") {
Ctx.PragmaDirectRead = true;
Ctx.IncrementMonCounter("sql_pragma", "DirectRead");
- } else if (normalizedPragma == "equijoin") {
- Ctx.IncrementMonCounter("sql_pragma", "EquiJoin");
- } else if (normalizedPragma == "autocommit") {
- Ctx.PragmaAutoCommit = true;
- Ctx.IncrementMonCounter("sql_pragma", "AutoCommit");
- } else if (normalizedPragma == "tablepathprefix") {
+ } else if (normalizedPragma == "equijoin") {
+ Ctx.IncrementMonCounter("sql_pragma", "EquiJoin");
+ } else if (normalizedPragma == "autocommit") {
+ Ctx.PragmaAutoCommit = true;
+ Ctx.IncrementMonCounter("sql_pragma", "AutoCommit");
+ } else if (normalizedPragma == "tablepathprefix") {
TString value;
TMaybe<TString> arg;
@@ -9306,7 +9306,7 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
if (!values.front().GetLiteral(value, Ctx)) {
Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
+ }
if (values.size() == 2) {
arg = value;
@@ -9318,29 +9318,29 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
if (!Ctx.SetPathPrefix(value, arg)) {
return {};
- }
- } else {
- Error() << "Expected path prefix or tuple of (Provider, PathPrefix) or"
- << " (Cluster, PathPrefix) as pragma value";
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ }
+ } else {
+ Error() << "Expected path prefix or tuple of (Provider, PathPrefix) or"
+ << " (Cluster, PathPrefix) as pragma value";
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
-
- Ctx.IncrementMonCounter("sql_pragma", "PathPrefix");
- } else if (normalizedPragma == "groupbylimit") {
+ }
+
+ Ctx.IncrementMonCounter("sql_pragma", "PathPrefix");
+ } else if (normalizedPragma == "groupbylimit") {
if (values.size() != 1 || !values[0].GetLiteral() || !TryFromString(*values[0].GetLiteral(), Ctx.PragmaGroupByLimit)) {
Error() << "Expected unsigned integer literal as a single argument for: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
- Ctx.IncrementMonCounter("sql_pragma", "GroupByLimit");
- } else if (normalizedPragma == "groupbycubelimit") {
+ }
+ Ctx.IncrementMonCounter("sql_pragma", "GroupByLimit");
+ } else if (normalizedPragma == "groupbycubelimit") {
if (values.size() != 1 || !values[0].GetLiteral() || !TryFromString(*values[0].GetLiteral(), Ctx.PragmaGroupByCubeLimit)) {
Error() << "Expected unsigned integer literal as a single argument for: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
- Ctx.IncrementMonCounter("sql_pragma", "GroupByCubeLimit");
+ }
+ Ctx.IncrementMonCounter("sql_pragma", "GroupByCubeLimit");
} else if (normalizedPragma == "simplecolumns") {
Ctx.SimpleColumns = true;
Ctx.IncrementMonCounter("sql_pragma", "SimpleColumns");
@@ -9395,7 +9395,7 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
return {};
default:
Y_ENSURE(false, "Unknown parse result");
- }
+ }
Ctx.WarningPolicy.AddRule(rule);
if (rule.GetPattern() == "*" && rule.GetAction() == EWarningAction::ERROR) {
@@ -9404,16 +9404,16 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
}
Ctx.IncrementMonCounter("sql_pragma", "warning");
- } else if (normalizedPragma == "greetings") {
- if (values.size() > 1) {
+ } else if (normalizedPragma == "greetings") {
+ if (values.size() > 1) {
Error() << "Multiple arguments are not expected for " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
- return {};
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ return {};
}
if (values.empty()) {
values.emplace_back(TDeferredAtom(Ctx.Pos(), "Hello, world! And best wishes from the YQL Team!"));
- }
+ }
TString arg;
if (!values.front().GetLiteral(arg, Ctx)) {
@@ -9421,19 +9421,19 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
return {};
}
Ctx.Info(Ctx.Pos()) << arg;
- } else if (normalizedPragma == "warningmsg") {
+ } else if (normalizedPragma == "warningmsg") {
if (values.size() != 1 || !values[0].GetLiteral()) {
Error() << "Expected string literal as a single argument for: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
- return {};
- }
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ return {};
+ }
Ctx.Warning(Ctx.Pos(), TIssuesIds::YQL_PRAGMA_WARNING_MSG) << *values[0].GetLiteral();
- } else if (normalizedPragma == "errormsg") {
+ } else if (normalizedPragma == "errormsg") {
if (values.size() != 1 || !values[0].GetLiteral()) {
Error() << "Expected string literal as a single argument for: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
- return {};
- }
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ return {};
+ }
Ctx.Error(Ctx.Pos()) << *values[0].GetLiteral();
} else if (normalizedPragma == "classicdivision") {
if (values.size() != 1 || !values[0].GetLiteral() || !TryFromString(*values[0].GetLiteral(), Ctx.Scoped->PragmaClassicDivision)) {
@@ -9596,12 +9596,12 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
} else if (normalizedPragma == "disableflexibletypes") {
Ctx.FlexibleTypes = false;
Ctx.IncrementMonCounter("sql_pragma", "DisableFlexibleTypes");
- } else {
- Error() << "Unknown pragma: " << pragma;
- Ctx.IncrementMonCounter("sql_errors", "UnknownPragma");
+ } else {
+ Error() << "Unknown pragma: " << pragma;
+ Ctx.IncrementMonCounter("sql_errors", "UnknownPragma");
return {};
- }
- } else {
+ }
+ } else {
if (lowerPrefix == "yson") {
if (!TopLevel) {
Error() << "This pragma '" << pragma << "' is not allowed to be used in actions";
@@ -9651,36 +9651,36 @@ TNodePtr TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt, bool& success
} else if (std::find(Providers.cbegin(), Providers.cend(), lowerPrefix) == Providers.cend()) {
if (!Ctx.HasCluster(prefix)) {
- Error() << "Unknown pragma prefix: " << prefix << ", please use cluster name or one of provider " <<
- JoinRange(", ", Providers.cbegin(), Providers.cend());
- Ctx.IncrementMonCounter("sql_errors", "UnknownPragma");
+ Error() << "Unknown pragma prefix: " << prefix << ", please use cluster name or one of provider " <<
+ JoinRange(", ", Providers.cbegin(), Providers.cend());
+ Ctx.IncrementMonCounter("sql_errors", "UnknownPragma");
return {};
- }
- }
-
+ }
+ }
+
if (normalizedPragma != "flags" && normalizedPragma != "packageversion") {
- if (values.size() > 1) {
- Error() << "Expected at most one value in the pragma";
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ if (values.size() > 1) {
+ Error() << "Expected at most one value in the pragma";
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
- } else {
+ }
+ } else {
if (pragmaValueDefault || values.size() < 1) {
- Error() << "Expected at least one value in the pragma";
- Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
+ Error() << "Expected at least one value in the pragma";
+ Ctx.IncrementMonCounter("sql_errors", "BadPragmaValue");
return {};
- }
- }
-
- success = true;
- Ctx.IncrementMonCounter("sql_pragma", pragma);
+ }
+ }
+
+ success = true;
+ Ctx.IncrementMonCounter("sql_pragma", pragma);
return BuildPragma(Ctx.Pos(), lowerPrefix, normalizedPragma, values, pragmaValueDefault);
- }
- success = true;
+ }
+ success = true;
return {};
-}
-
-TNodePtr TSqlQuery::Build(const TRule_delete_stmt& stmt) {
+}
+
+TNodePtr TSqlQuery::Build(const TRule_delete_stmt& stmt) {
TTableRef table;
if (!SimpleTableRefImpl(stmt.GetRule_simple_table_ref3(), table)) {
return nullptr;
@@ -9694,7 +9694,7 @@ TNodePtr TSqlQuery::Build(const TRule_delete_stmt& stmt) {
TSourcePtr source = BuildTableSource(Ctx.Pos(), table);
- if (stmt.HasBlock4()) {
+ if (stmt.HasBlock4()) {
switch (stmt.GetBlock4().Alt_case()) {
case TRule_delete_stmt_TBlock4::kAlt1: {
const auto& alt = stmt.GetBlock4().GetAlt1();
@@ -9722,13 +9722,13 @@ TNodePtr TSqlQuery::Build(const TRule_delete_stmt& stmt) {
default:
return nullptr;
- }
- }
+ }
+ }
return BuildDelete(Ctx.Pos(), Ctx.Scoped, table, std::move(source));
-}
-
-TNodePtr TSqlQuery::Build(const TRule_update_stmt& stmt) {
+}
+
+TNodePtr TSqlQuery::Build(const TRule_update_stmt& stmt) {
TTableRef table;
if (!SimpleTableRefImpl(stmt.GetRule_simple_table_ref2(), table)) {
return nullptr;
@@ -9772,78 +9772,78 @@ TNodePtr TSqlQuery::Build(const TRule_update_stmt& stmt) {
}
default:
- return nullptr;
- }
-}
-
-TSourcePtr TSqlQuery::Build(const TRule_set_clause_choice& stmt) {
- switch (stmt.Alt_case()) {
- case TRule_set_clause_choice::kAltSetClauseChoice1:
- return Build(stmt.GetAlt_set_clause_choice1().GetRule_set_clause_list1());
- case TRule_set_clause_choice::kAltSetClauseChoice2:
- return Build(stmt.GetAlt_set_clause_choice2().GetRule_multiple_column_assignment1());
- default:
- AltNotImplemented("set_clause_choice", stmt);
- return nullptr;
- }
-}
-
+ return nullptr;
+ }
+}
+
+TSourcePtr TSqlQuery::Build(const TRule_set_clause_choice& stmt) {
+ switch (stmt.Alt_case()) {
+ case TRule_set_clause_choice::kAltSetClauseChoice1:
+ return Build(stmt.GetAlt_set_clause_choice1().GetRule_set_clause_list1());
+ case TRule_set_clause_choice::kAltSetClauseChoice2:
+ return Build(stmt.GetAlt_set_clause_choice2().GetRule_multiple_column_assignment1());
+ default:
+ AltNotImplemented("set_clause_choice", stmt);
+ return nullptr;
+ }
+}
+
bool TSqlQuery::FillSetClause(const TRule_set_clause& node, TVector<TString>& targetList, TVector<TNodePtr>& values) {
- targetList.push_back(ColumnNameAsSingleStr(*this, node.GetRule_set_target1().GetRule_column_name1()));
+ targetList.push_back(ColumnNameAsSingleStr(*this, node.GetRule_set_target1().GetRule_column_name1()));
TColumnRefScope scope(Ctx, EColumnRefState::Allow);
- TSqlExpression sqlExpr(Ctx, Mode);
- if (!Expr(sqlExpr, values, node.GetRule_expr3())) {
- return false;
- }
- return true;
-}
-
-TSourcePtr TSqlQuery::Build(const TRule_set_clause_list& stmt) {
+ TSqlExpression sqlExpr(Ctx, Mode);
+ if (!Expr(sqlExpr, values, node.GetRule_expr3())) {
+ return false;
+ }
+ return true;
+}
+
+TSourcePtr TSqlQuery::Build(const TRule_set_clause_list& stmt) {
TVector<TString> targetList;
TVector<TNodePtr> values;
- const TPosition pos(Ctx.Pos());
- if (!FillSetClause(stmt.GetRule_set_clause1(), targetList, values)) {
- return nullptr;
- }
- for (auto& block: stmt.GetBlock2()) {
- if (!FillSetClause(block.GetRule_set_clause2(), targetList, values)) {
- return nullptr;
- }
- }
- Y_VERIFY_DEBUG(targetList.size() == values.size());
- return BuildUpdateValues(pos, targetList, values);
-}
-
-TSourcePtr TSqlQuery::Build(const TRule_multiple_column_assignment& stmt) {
+ const TPosition pos(Ctx.Pos());
+ if (!FillSetClause(stmt.GetRule_set_clause1(), targetList, values)) {
+ return nullptr;
+ }
+ for (auto& block: stmt.GetBlock2()) {
+ if (!FillSetClause(block.GetRule_set_clause2(), targetList, values)) {
+ return nullptr;
+ }
+ }
+ Y_VERIFY_DEBUG(targetList.size() == values.size());
+ return BuildUpdateValues(pos, targetList, values);
+}
+
+TSourcePtr TSqlQuery::Build(const TRule_multiple_column_assignment& stmt) {
TVector<TString> targetList;
- FillTargetList(*this, stmt.GetRule_set_target_list1(), targetList);
- auto simpleValuesNode = stmt.GetRule_simple_values_source4();
- const TPosition pos(Ctx.Pos());
- switch (simpleValuesNode.Alt_case()) {
- case TRule_simple_values_source::kAltSimpleValuesSource1: {
+ FillTargetList(*this, stmt.GetRule_set_target_list1(), targetList);
+ auto simpleValuesNode = stmt.GetRule_simple_values_source4();
+ const TPosition pos(Ctx.Pos());
+ switch (simpleValuesNode.Alt_case()) {
+ case TRule_simple_values_source::kAltSimpleValuesSource1: {
TVector<TNodePtr> values;
- TSqlExpression sqlExpr(Ctx, Mode);
- if (!ExprList(sqlExpr, values, simpleValuesNode.GetAlt_simple_values_source1().GetRule_expr_list1())) {
- return nullptr;
- }
- return BuildUpdateValues(pos, targetList, values);
- }
- case TRule_simple_values_source::kAltSimpleValuesSource2: {
- TSqlSelect select(Ctx, Mode);
+ TSqlExpression sqlExpr(Ctx, Mode);
+ if (!ExprList(sqlExpr, values, simpleValuesNode.GetAlt_simple_values_source1().GetRule_expr_list1())) {
+ return nullptr;
+ }
+ return BuildUpdateValues(pos, targetList, values);
+ }
+ case TRule_simple_values_source::kAltSimpleValuesSource2: {
+ TSqlSelect select(Ctx, Mode);
TPosition selectPos;
auto source = select.Build(simpleValuesNode.GetAlt_simple_values_source2().GetRule_select_stmt1(), selectPos);
- if (!source) {
- return nullptr;
- }
- return BuildWriteValues(pos, "UPDATE", targetList, std::move(source));
- }
- default:
- Ctx.IncrementMonCounter("sql_errors", "UnknownSimpleValuesSourceAlt");
- AltNotImplemented("simple_values_source", simpleValuesNode);
- return nullptr;
- }
-}
-
+ if (!source) {
+ return nullptr;
+ }
+ return BuildWriteValues(pos, "UPDATE", targetList, std::move(source));
+ }
+ default:
+ Ctx.IncrementMonCounter("sql_errors", "UnknownSimpleValuesSourceAlt");
+ AltNotImplemented("simple_values_source", simpleValuesNode);
+ return nullptr;
+ }
+}
+
TNodePtr TSqlQuery::Build(const TSQLv1ParserAST& ast) {
const auto& query = ast.GetRule_sql_query();
TVector<TNodePtr> blocks;
@@ -10090,48 +10090,48 @@ TAstNode* SqlASTToYql(const google::protobuf::Message& protoAst, TContext& ctx)
return nullptr;
}
-void SqlASTToYqlImpl(NYql::TAstParseResult& res, const google::protobuf::Message& protoAst,
- TContext& ctx) {
+void SqlASTToYqlImpl(NYql::TAstParseResult& res, const google::protobuf::Message& protoAst,
+ TContext& ctx) {
YQL_ENSURE(!ctx.Issues.Size());
- res.Root = SqlASTToYql(protoAst, ctx);
+ res.Root = SqlASTToYql(protoAst, ctx);
res.Pool = std::move(ctx.Pool);
- if (!res.Root) {
+ if (!res.Root) {
if (ctx.Issues.Size()) {
- ctx.IncrementMonCounter("sql_errors", "AstToYqlError");
- } else {
- ctx.IncrementMonCounter("sql_errors", "AstToYqlSilentError");
+ ctx.IncrementMonCounter("sql_errors", "AstToYqlError");
+ } else {
+ ctx.IncrementMonCounter("sql_errors", "AstToYqlSilentError");
ctx.Error() << "Error occurred on parse SQL query, but no error is collected" <<
- ", please send this request over bug report into YQL interface or write on yql@ maillist";
- }
- }
-}
-
-NYql::TAstParseResult SqlASTToYql(const google::protobuf::Message& protoAst,
+ ", please send this request over bug report into YQL interface or write on yql@ maillist";
+ }
+ }
+}
+
+NYql::TAstParseResult SqlASTToYql(const google::protobuf::Message& protoAst,
const NSQLTranslation::TTranslationSettings& settings)
{
YQL_ENSURE(IsQueryMode(settings.Mode));
TAstParseResult res;
- TContext ctx(settings, res.Issues);
- SqlASTToYqlImpl(res, protoAst, ctx);
+ TContext ctx(settings, res.Issues);
+ SqlASTToYqlImpl(res, protoAst, ctx);
return res;
}
NYql::TAstParseResult SqlToYql(const TString& query, const NSQLTranslation::TTranslationSettings& settings, NYql::TWarningRules* warningRules)
{
TAstParseResult res;
- TContext ctx(settings, res.Issues);
+ TContext ctx(settings, res.Issues);
NSQLTranslation::TErrorCollectorOverIssues collector(res.Issues, settings.MaxErrors, settings.File);
google::protobuf::Message* ast(SqlAST(query, "query", collector, settings.AnsiLexer, settings.Arena));
if (ast) {
- SqlASTToYqlImpl(res, *ast, ctx);
+ SqlASTToYqlImpl(res, *ast, ctx);
} else {
ctx.IncrementMonCounter("sql_errors", "AstError");
}
if (warningRules) {
*warningRules = ctx.WarningPolicy.GetRules();
ctx.WarningPolicy.Clear();
- }
+ }
return res;
}
diff --git a/ydb/library/yql/sql/v1/sql.h b/ydb/library/yql/sql/v1/sql.h
index 1e657d1c35..9c7dc676c6 100644
--- a/ydb/library/yql/sql/v1/sql.h
+++ b/ydb/library/yql/sql/v1/sql.h
@@ -11,7 +11,7 @@
namespace NSQLTranslation {
struct TTranslationSettings;
}
-
+
namespace NSQLTranslationV1 {
NYql::TAstParseResult SqlToYql(const TString& query, const NSQLTranslation::TTranslationSettings& settings, NYql::TWarningRules* warningRules = nullptr);
diff --git a/ydb/library/yql/sql/v1/sql_ut.cpp b/ydb/library/yql/sql/v1/sql_ut.cpp
index 53eb4d845c..85b6e0dfcd 100644
--- a/ydb/library/yql/sql/v1/sql_ut.cpp
+++ b/ydb/library/yql/sql/v1/sql_ut.cpp
@@ -5,25 +5,25 @@
#include <library/cpp/testing/unittest/registar.h>
-#include <util/string/split.h>
+#include <util/string/split.h>
using namespace NSQLTranslation;
-enum class EDebugOutput {
- None,
- ToCerr,
-};
+enum class EDebugOutput {
+ None,
+ ToCerr,
+};
TString Err2Str(NYql::TAstParseResult& res, EDebugOutput debug = EDebugOutput::None) {
- TStringStream s;
- res.Issues.PrintTo(s);
-
- if (debug == EDebugOutput::ToCerr) {
- Cerr << s.Str() << Endl;
- }
- return s.Str();
-}
-
+ TStringStream s;
+ res.Issues.PrintTo(s);
+
+ if (debug == EDebugOutput::ToCerr) {
+ Cerr << s.Str() << Endl;
+ }
+ return s.Str();
+}
+
NYql::TAstParseResult SqlToYqlWithMode(const TString& query, NSQLTranslation::ESqlMode mode = NSQLTranslation::ESqlMode::QUERY, size_t maxErrors = 10, const TString& provider = {},
EDebugOutput debug = EDebugOutput::None, bool ansiLexer = false, NSQLTranslation::TTranslationSettings settings = {})
{
@@ -38,12 +38,12 @@ NYql::TAstParseResult SqlToYqlWithMode(const TString& query, NSQLTranslation::ES
settings.AnsiLexer = ansiLexer;
settings.SyntaxVersion = 1;
auto res = SqlToYql(query, settings);
- if (debug == EDebugOutput::ToCerr) {
- Err2Str(res, debug);
- }
- return res;
-}
-
+ if (debug == EDebugOutput::ToCerr) {
+ Err2Str(res, debug);
+ }
+ return res;
+}
+
NYql::TAstParseResult SqlToYql(const TString& query, size_t maxErrors = 10, const TString& provider = {}, EDebugOutput debug = EDebugOutput::None) {
return SqlToYqlWithMode(query, NSQLTranslation::ESqlMode::QUERY, maxErrors, provider, debug);
}
@@ -72,15 +72,15 @@ void ExpectFailWithErrorForAnsiLexer(const TString& query, const TString& error)
}
TString GetPrettyPrint(const NYql::TAstParseResult& res) {
- TStringStream yqlProgram;
- res.Root->PrettyPrintTo(yqlProgram, NYql::TAstPrintFlags::PerLine | NYql::TAstPrintFlags::ShortQuote);
- return yqlProgram.Str();
-}
-
+ TStringStream yqlProgram;
+ res.Root->PrettyPrintTo(yqlProgram, NYql::TAstPrintFlags::PerLine | NYql::TAstPrintFlags::ShortQuote);
+ return yqlProgram.Str();
+}
+
TString Quote(const char* str) {
- return TStringBuilder() << "'\"" << str << "\"";
-}
-
+ return TStringBuilder() << "'\"" << str << "\"";
+}
+
class TWordCountHive: public TMap<TString, unsigned> {
public:
TWordCountHive(std::initializer_list<TString> strings) {
@@ -96,27 +96,27 @@ public:
};
typedef std::function<void (const TString& word, const TString& line)> TVerifyLineFunc;
-
+
TString VerifyProgram(const NYql::TAstParseResult& res, TWordCountHive& wordCounter, TVerifyLineFunc verifyLine = TVerifyLineFunc()) {
- const auto programm = GetPrettyPrint(res);
+ const auto programm = GetPrettyPrint(res);
TVector<TString> yqlProgram;
- Split(programm, "\n", yqlProgram);
- for (const auto& line: yqlProgram) {
- for (auto& counterIter: wordCounter) {
- const auto& word = counterIter.first;
+ Split(programm, "\n", yqlProgram);
+ for (const auto& line: yqlProgram) {
+ for (auto& counterIter: wordCounter) {
+ const auto& word = counterIter.first;
auto pos = line.find(word);
while (pos != TString::npos) {
- ++counterIter.second;
- if (verifyLine) {
- verifyLine(word, line);
- }
+ ++counterIter.second;
+ if (verifyLine) {
+ verifyLine(word, line);
+ }
pos = line.find(word, pos + word.length());
- }
- }
- }
- return programm;
-}
-
+ }
+ }
+ }
+ return programm;
+}
+
void VerifySqlInHints(const TString& query, const THashSet<TString>& expectedHints, TMaybe<bool> ansi) {
TString pragma;
if (ansi.Defined()) {
@@ -220,93 +220,93 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
Y_UNIT_TEST(Jubilee) {
NYql::TAstParseResult res = SqlToYql("USE plato; INSERT INTO Arcadia (r2000000) VALUES (\"2M GET!!!\");");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(QualifiedAsteriskBefore) {
NYql::TAstParseResult res = SqlToYql(
"PRAGMA DisableSimpleColumns;"
"select interested_table.*, LENGTH(value) AS megahelpful_len from plato.Input as interested_table;"
);
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
static bool seenStar = false;
- if (word == "FlattenMembers") {
+ if (word == "FlattenMembers") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("interested_table."));
} else if (word == "SqlProjectItem") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("megahelpful_len")));
UNIT_ASSERT_VALUES_EQUAL(seenStar, true);
} else if (word == "SqlProjectStarItem") {
seenStar = true;
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("FlattenMembers"), 0}, {TString("SqlProjectItem"), 0}, {TString("SqlProjectStarItem"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
+ VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["FlattenMembers"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SqlProjectItem"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SqlProjectStarItem"]);
- }
-
+ }
+
Y_UNIT_TEST(QualifiedAsteriskAfter) {
NYql::TAstParseResult res = SqlToYql(
"PRAGMA DisableSimpleColumns;"
"select LENGTH(value) AS megahelpful_len, interested_table.* from plato.Input as interested_table;"
);
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
static bool seenStar = false;
- if (word == "FlattenMembers") {
+ if (word == "FlattenMembers") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("interested_table."));
} else if (word == "SqlProjectItem") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("megahelpful_len")));
UNIT_ASSERT_VALUES_EQUAL(seenStar, false);
} else if (word == "SqlProjectStarItem") {
seenStar = true;
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("FlattenMembers"), 0}, {TString("SqlProjectItem"), 0}, {TString("SqlProjectStarItem"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
+ VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["FlattenMembers"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SqlProjectItem"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SqlProjectStarItem"]);
- }
-
+ }
+
Y_UNIT_TEST(QualifiedMembers) {
NYql::TAstParseResult res = SqlToYql("select interested_table.key, interested_table.value from plato.Input as interested_table;");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
const bool fieldKey = TString::npos != line.find(Quote("key"));
const bool fieldValue = TString::npos != line.find(Quote("value"));
const bool refOnTable = TString::npos != line.find("interested_table.");
if (word == "SqlProjectItem") {
- UNIT_ASSERT(fieldKey || fieldValue);
- UNIT_ASSERT(!refOnTable);
- } else if (word == "Write!") {
- UNIT_ASSERT(fieldKey && fieldValue && !refOnTable);
- }
- };
+ UNIT_ASSERT(fieldKey || fieldValue);
+ UNIT_ASSERT(!refOnTable);
+ } else if (word == "Write!") {
+ UNIT_ASSERT(fieldKey && fieldValue && !refOnTable);
+ }
+ };
TWordCountHive elementStat = {{TString("SqlProjectStarItem"), 0}, {TString("SqlProjectItem"), 0}, {TString("Write!"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
+ VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT_VALUES_EQUAL(0, elementStat["SqlProjectStarItem"]);
UNIT_ASSERT_VALUES_EQUAL(2, elementStat["SqlProjectItem"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
+ }
+
Y_UNIT_TEST(JoinParseCorrect) {
NYql::TAstParseResult res = SqlToYql(
"PRAGMA DisableSimpleColumns;"
- " SELECT table_bb.*, table_aa.key as megakey"
+ " SELECT table_bb.*, table_aa.key as megakey"
" FROM plato.Input AS table_aa"
" JOIN plato.Input AS table_bb"
- " ON table_aa.value == table_bb.value;"
+ " ON table_aa.value == table_bb.value;"
);
UNIT_ASSERT(res.Root);
-
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "SelectMembers") {
+ if (word == "SelectMembers") {
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("table_aa."));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("table_bb."));
} else if (word == "SqlProjectItem") {
@@ -314,130 +314,130 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
} else if (word == "SqlColumn") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("table_aa")));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("key")));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("SqlProjectItem"), 0}, {TString("SqlProjectStarItem"), 0}, {TString("SelectMembers"), 0}, {TString("SqlColumn"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
+ VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SqlProjectItem"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SqlProjectStarItem"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SelectMembers"]);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SelectMembers"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SqlColumn"]);
}
Y_UNIT_TEST(Join3Table) {
NYql::TAstParseResult res = SqlToYql(
" PRAGMA DisableSimpleColumns;"
- " SELECT table_bb.*, table_aa.key as gigakey, table_cc.* "
+ " SELECT table_bb.*, table_aa.key as gigakey, table_cc.* "
" FROM plato.Input AS table_aa"
" JOIN plato.Input AS table_bb ON table_aa.key == table_bb.key"
" JOIN plato.Input AS table_cc ON table_aa.subkey == table_cc.subkey;"
);
- Err2Str(res);
+ Err2Str(res);
UNIT_ASSERT(res.Root);
-
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "SelectMembers") {
+ if (word == "SelectMembers") {
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("table_aa."));
UNIT_ASSERT(line.find("table_bb.") != TString::npos || line.find("table_cc.") != TString::npos);
} else if (word == "SqlProjectItem") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("gigakey")));
} else if (word == "SqlColumn") {
- const auto posTableAA = line.find(Quote("table_aa"));
+ const auto posTableAA = line.find(Quote("table_aa"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, posTableAA);
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("key")));
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("table_aa", posTableAA + 3));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("SqlProjectItem"), 0}, {TString("SqlProjectStarItem"), 0}, {TString("SelectMembers"), 0}, {TString("SqlColumn"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
+ VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SqlProjectItem"]);
UNIT_ASSERT_VALUES_EQUAL(2, elementStat["SqlProjectStarItem"]);
UNIT_ASSERT_VALUES_EQUAL(2, elementStat["SelectMembers"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SqlColumn"]);
}
-
+
Y_UNIT_TEST(JoinWithoutConcreteColumns) {
- NYql::TAstParseResult res = SqlToYql(
+ NYql::TAstParseResult res = SqlToYql(
" use plato;"
- " SELECT a.v, b.value"
+ " SELECT a.v, b.value"
" FROM `Input1` VIEW `ksv` AS a"
" JOIN `Input2` AS b"
- " ON a.k == b.key;"
- );
- UNIT_ASSERT(res.Root);
-
+ " ON a.k == b.key;"
+ );
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
if (word == "SqlProjectItem") {
UNIT_ASSERT(line.find(Quote("a.v")) != TString::npos || line.find(Quote("b.value")) != TString::npos);
} else if (word == "SqlColumn") {
- const auto posTableA = line.find(Quote("a"));
- const auto posTableB = line.find(Quote("b"));
+ const auto posTableA = line.find(Quote("a"));
+ const auto posTableB = line.find(Quote("b"));
if (posTableA != TString::npos) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("v")));
} else {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, posTableB);
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("value")));
}
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("SqlProjectStarItem"), 0}, {TString("SqlProjectItem"), 0}, {TString("SqlColumn"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
+ VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT_VALUES_EQUAL(0, elementStat["SqlProjectStarItem"]);
UNIT_ASSERT_VALUES_EQUAL(2, elementStat["SqlProjectItem"]);
UNIT_ASSERT_VALUES_EQUAL(2, elementStat["SqlColumn"]);
- }
-
+ }
+
Y_UNIT_TEST(JoinWithSameValues) {
NYql::TAstParseResult res = SqlToYql("SELECT a.value, b.value FROM plato.Input AS a JOIN plato.Input as b ON a.key == b.key;");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
if (word == "SqlProjectItem") {
const bool isValueFromA = TString::npos != line.find(Quote("a.value"));
const bool isValueFromB = TString::npos != line.find(Quote("b.value"));
- UNIT_ASSERT(isValueFromA || isValueFromB);
- } if (word == "Write!") {
+ UNIT_ASSERT(isValueFromA || isValueFromB);
+ } if (word == "Write!") {
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("a.a."));
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("b.b."));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("SqlProjectStarItem"), 0}, {TString("SqlProjectItem"), 0}, {"Write!", 0}};
- VerifyProgram(res, elementStat, verifyLine);
+ VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT_VALUES_EQUAL(0, elementStat["SqlProjectStarItem"]);
UNIT_ASSERT_VALUES_EQUAL(2, elementStat["SqlProjectItem"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
+ }
+
Y_UNIT_TEST(SameColumnsForDifferentTables) {
NYql::TAstParseResult res = SqlToYql("SELECT a.key, b.key FROM plato.Input as a JOIN plato.Input as b on a.key==b.key;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(SameColumnsForDifferentTablesFullJoin) {
NYql::TAstParseResult res = SqlToYql("SELECT a.key, b.key, a.value, b.value FROM plato.Input AS a FULL JOIN plato.Input AS b USING(key);");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(ReverseLabels) {
NYql::TAstParseResult res = SqlToYql("select in.key as subkey, subkey as key from plato.Input as in;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(AutogenerationAliasWithoutCollisionConflict1) {
NYql::TAstParseResult res = SqlToYql("select LENGTH(Value), key as column1 from plato.Input;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(AutogenerationAliasWithoutCollision2Conflict2) {
NYql::TAstParseResult res = SqlToYql("select key as column0, LENGTH(Value) from plato.Input;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(InputAliasForQualifiedAsterisk) {
NYql::TAstParseResult res = SqlToYql("use plato; select zyuzya.*, key from plato.Input as zyuzya;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(SelectSupportsResultColumnsWithTrailingComma) {
NYql::TAstParseResult res = SqlToYql("select a, b, c, from plato.Input;");
UNIT_ASSERT(res.Root);
@@ -445,124 +445,124 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
Y_UNIT_TEST(SelectOrderByLabeledColumn) {
NYql::TAstParseResult res = SqlToYql("pragma DisableOrderedColumns; select key as goal from plato.Input order by goal");
- UNIT_ASSERT(res.Root);
+ UNIT_ASSERT(res.Root);
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "DataSource") {
+ if (word == "DataSource") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("plato"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("Input"));
-
+
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("goal"));
- } else if (word == "Sort") {
+ } else if (word == "Sort") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("goal"));
-
+
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("key"));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("DataSource"), 0}, {TString("Sort"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["DataSource"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["DataSource"]);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
+ }
+
Y_UNIT_TEST(SelectOrderBySimpleExpr) {
NYql::TAstParseResult res = SqlToYql("select a from plato.Input order by a + a");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(SelectOrderByDuplicateLabels) {
NYql::TAstParseResult res = SqlToYql("select a from plato.Input order by a, a");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(SelectOrderByExpression) {
NYql::TAstParseResult res = SqlToYql("select * from plato.Input as i order by cast(key as uint32) + cast(subkey as uint32)");
- UNIT_ASSERT(res.Root);
+ UNIT_ASSERT(res.Root);
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Sort") {
+ if (word == "Sort") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"+\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("key"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("subkey"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("(Bool 'true)"));
-
+
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("i.key"));
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("i.subkey"));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("Sort"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
+ }
+
Y_UNIT_TEST(SelectOrderByExpressionDesc) {
NYql::TAstParseResult res = SqlToYql("pragma disablesimplecolumns; select i.*, key, subkey from plato.Input as i order by cast(i.key as uint32) - cast(i.subkey as uint32) desc");
- UNIT_ASSERT(res.Root);
+ UNIT_ASSERT(res.Root);
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Sort") {
+ if (word == "Sort") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"-\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"key\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"subkey\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("(Bool 'false)"));
- } else if (word == "Write!") {
+ } else if (word == "Write!") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("'columns"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"key\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"subkey\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("prefix"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"i.\""));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("Sort"), 0}, {TString("Write!"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
+ }
+
Y_UNIT_TEST(SelectOrderByExpressionAsc) {
NYql::TAstParseResult res = SqlToYql("select i.key, i.subkey from plato.Input as i order by cast(key as uint32) % cast(i.subkey as uint32) asc");
- UNIT_ASSERT(res.Root);
+ UNIT_ASSERT(res.Root);
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Sort") {
+ if (word == "Sort") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"%\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"key\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"subkey\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("(Bool 'true)"));
- } else if (word == "Write!") {
+ } else if (word == "Write!") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("'columns"));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"key\""));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("\"subkey\""));
UNIT_ASSERT_VALUES_EQUAL(TString::npos, line.find("i."));
- }
- };
+ }
+ };
TWordCountHive elementStat = {{TString("Sort"), 0}, {TString("Write!"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Sort"]);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write!"]);
+ }
+
Y_UNIT_TEST(ReferenceToKeyInSubselect) {
NYql::TAstParseResult res = SqlToYql("select b.key from (select a.key from plato.Input as a) as b;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(OrderByCastValue) {
NYql::TAstParseResult res = SqlToYql("select i.key, i.subkey from plato.Input as i order by cast(key as uint32) desc;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(GroupByCastValue) {
NYql::TAstParseResult res = SqlToYql("select count(1) from plato.Input as i group by cast(key as uint8);");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(KeywordInSelectColumns) {
- NYql::TAstParseResult res = SqlToYql("select in, s.check from (select 1 as in, \"test\" as check) as s;");
- UNIT_ASSERT(res.Root);
- }
+ NYql::TAstParseResult res = SqlToYql("select in, s.check from (select 1 as in, \"test\" as check) as s;");
+ UNIT_ASSERT(res.Root);
+ }
Y_UNIT_TEST(SelectAllGroupBy) {
NYql::TAstParseResult res = SqlToYql("select * from plato.Input group by subkey;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(PrimaryKeyParseCorrect) {
NYql::TAstParseResult res = SqlToYql("USE plato; CREATE TABLE tableName (Key Uint32, Subkey Int64, Value String, PRIMARY KEY (Key, Subkey));");
UNIT_ASSERT(res.Root);
@@ -580,39 +580,39 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["primarykey"]);
}
-
+
Y_UNIT_TEST(DeleteFromTableByKey) {
NYql::TAstParseResult res = SqlToYql("delete from plato.Input where key = 200;", 10, "kikimr");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Write") {
+ if (word == "Write") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("('mode 'delete)"));
- }
- };
-
+ }
+ };
+
TWordCountHive elementStat = {{TString("Write"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
-
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
+ }
+
Y_UNIT_TEST(DeleteFromTable) {
NYql::TAstParseResult res = SqlToYql("delete from plato.Input;", 10, "kikimr");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Write") {
+ if (word == "Write") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("('mode 'delete)"));
- }
- };
-
+ }
+ };
+
TWordCountHive elementStat = {{TString("Write"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
-
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
+ }
+
Y_UNIT_TEST(DeleteFromTableOnValues) {
NYql::TAstParseResult res = SqlToYql("delete from plato.Input on (key) values (1);",
10, "kikimr");
@@ -649,107 +649,107 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
Y_UNIT_TEST(UpdateByValues) {
NYql::TAstParseResult res = SqlToYql("update plato.Input set key = 777, value = 'cool' where key = 200;", 10, "kikimr");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Write") {
+ if (word == "Write") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("('mode 'update)"));
} else if (word == "AsStruct") {
const bool isKey = line.find("key") != TString::npos;
const bool isValue = line.find("value") != TString::npos;
- UNIT_ASSERT(isKey || isValue);
- if (isKey) {
+ UNIT_ASSERT(isKey || isValue);
+ if (isKey) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("777")));
- } else if (isValue) {
+ } else if (isValue) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("cool")));
- }
- }
- };
-
+ }
+ }
+ };
+
TWordCountHive elementStat = {{TString("Write"), 0}, {TString("AsStruct"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
-
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
+ VerifyProgram(res, elementStat, verifyLine);
+
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
- }
-
+ }
+
Y_UNIT_TEST(UpdateByMultiValues) {
NYql::TAstParseResult res = SqlToYql("update plato.Input set (key, value, subkey) = ('2','ddd',':') where key = 200;", 10, "kikimr");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Write") {
+ if (word == "Write") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("('mode 'update)"));
} else if (word == "AsStruct") {
const bool isKey = line.find("key") != TString::npos;
const bool isSubkey = line.find("subkey") != TString::npos;
const bool isValue = line.find("value") != TString::npos;
- UNIT_ASSERT(isKey || isSubkey || isValue);
+ UNIT_ASSERT(isKey || isSubkey || isValue);
if (isKey && !isSubkey) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("2")));
- } else if (isSubkey) {
+ } else if (isSubkey) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote(":")));
- } else if (isValue) {
+ } else if (isValue) {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("ddd")));
- }
- }
- };
-
+ }
+ }
+ };
+
TWordCountHive elementStat = {{TString("Write"), 0}, {TString("AsStruct"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
-
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
+ VerifyProgram(res, elementStat, verifyLine);
+
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
- }
-
+ }
+
Y_UNIT_TEST(UpdateBySelect) {
NYql::TAstParseResult res = SqlToYql("update plato.Input set (key, value, subkey) = (select key, value, subkey from plato.Input where key = 911) where key = 200;", 10, "kikimr");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
int lineIndex = 0;
int writeLineIndex = -1;
bool found = false;
TVerifyLineFunc verifyLine = [&lineIndex, &writeLineIndex, &found](const TString& word, const TString& line) {
- if (word == "Write") {
+ if (word == "Write") {
writeLineIndex = lineIndex;
found = line.find("('mode 'update)") != TString::npos;
} else if (word == "mode") {
found |= lineIndex == writeLineIndex + 1 && line.find("('mode 'update)") != TString::npos;
UNIT_ASSERT(found);
- }
+ }
++lineIndex;
- };
-
+ };
+
TWordCountHive elementStat = {{TString("Write"), 0}, {TString("mode"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
-
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
- }
-
+ VerifyProgram(res, elementStat, verifyLine);
+
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
+ }
+
Y_UNIT_TEST(UpdateSelfModifyAll) {
NYql::TAstParseResult res = SqlToYql("update plato.Input set subkey = subkey + 's';", 10, "kikimr");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Write") {
+ if (word == "Write") {
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("('mode 'update)"));
} else if (word == "AsStruct") {
const bool isSubkey = line.find("subkey") != TString::npos;
- UNIT_ASSERT(isSubkey);
+ UNIT_ASSERT(isSubkey);
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("subkey")));
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(Quote("s")));
- }
- };
-
+ }
+ };
+
TWordCountHive elementStat = {{TString("Write"), 0}, {TString("AsStruct"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
-
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
+ VerifyProgram(res, elementStat, verifyLine);
+
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["AsStruct"]);
- }
-
+ }
+
Y_UNIT_TEST(UpdateOnValues) {
NYql::TAstParseResult res = SqlToYql("update plato.Input on (key, value) values (5, 'cool')", 10, "kikimr");
UNIT_ASSERT(res.Root);
@@ -785,13 +785,13 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
Y_UNIT_TEST(UnionAllTest) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input UNION ALL select subkey FROM plato.Input;");
- UNIT_ASSERT(res.Root);
-
+ UNIT_ASSERT(res.Root);
+
TWordCountHive elementStat = {{TString("UnionAll"), 0}};
- VerifyProgram(res, elementStat, {});
- UNIT_ASSERT_VALUES_EQUAL(1, elementStat["UnionAll"]);
- }
-
+ VerifyProgram(res, elementStat, {});
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["UnionAll"]);
+ }
+
Y_UNIT_TEST(DeclareDecimalParameter) {
NYql::TAstParseResult res = SqlToYql("declare $value as Decimal(22,9); select $value as cnt;");
UNIT_ASSERT(res.Root);
@@ -799,15 +799,15 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
Y_UNIT_TEST(SimpleGroupBy) {
NYql::TAstParseResult res = SqlToYql("select count(1),z from plato.Input group by key as z order by z;");
- UNIT_ASSERT(res.Root);
- }
-
+ UNIT_ASSERT(res.Root);
+ }
+
Y_UNIT_TEST(EmptyColumnName0) {
/// Now it's parsed well and error occur on validate step like "4:31:Empty struct member name is not allowed" in "4:31:Function: AddMember"
NYql::TAstParseResult res = SqlToYql("insert into plato.Output (``, list1) values (0, AsList(0, 1, 2));");
- /// Verify that parsed well without crash
- UNIT_ASSERT(res.Root);
- }
+ /// Verify that parsed well without crash
+ UNIT_ASSERT(res.Root);
+ }
Y_UNIT_TEST(KikimrRollback) {
NYql::TAstParseResult res = SqlToYql("use plato; select * from Input; rollback;", 10, "kikimr");
@@ -826,11 +826,11 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
VerifyProgram(res, elementStat);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat.cbegin()->second);
}
-
+
Y_UNIT_TEST(DoNotCrashOnNamedInFilter) {
NYql::TAstParseResult res = SqlToYql("USE plato; $all = ($table_name) -> { return true; }; SELECT * FROM FILTER(Input, $all)");
- UNIT_ASSERT(res.Root);
- }
+ UNIT_ASSERT(res.Root);
+ }
Y_UNIT_TEST(PragmasFileAndUdfOrder) {
NYql::TAstParseResult res = SqlToYql(R"(
@@ -844,22 +844,22 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
const auto udfs = programm.find("ImportUdfs");
UNIT_ASSERT(file < udfs);
}
-
+
Y_UNIT_TEST(ProcessUserType) {
NYql::TAstParseResult res = SqlToYql("process plato.Input using Kikimr::PushData(TableRows());", 1, TString(NYql::KikimrProviderName));
- UNIT_ASSERT(res.Root);
-
- TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
- if (word == "Kikimr.PushData") {
- UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("TupleType"));
- UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("TypeOf"));
- }
- };
-
- TWordCountHive elementStat = {{TString("Kikimr.PushData"), 0}};
- VerifyProgram(res, elementStat, verifyLine);
+ UNIT_ASSERT(res.Root);
+
+ TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
+ if (word == "Kikimr.PushData") {
+ UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("TupleType"));
+ UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("TypeOf"));
+ }
+ };
+
+ TWordCountHive elementStat = {{TString("Kikimr.PushData"), 0}};
+ VerifyProgram(res, elementStat, verifyLine);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Kikimr.PushData"]);
- }
+ }
Y_UNIT_TEST(ProcessUserTypeAuth) {
NYql::TAstParseResult res = SqlToYql("process plato.Input using YDB::PushData(TableRows(), AsTuple('oauth', SecureParam('api:oauth')));", 1, TString(NYql::KikimrProviderName));
@@ -1606,7 +1606,7 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
Y_UNIT_TEST_SUITE(ExternalFunction) {
Y_UNIT_TEST(ValidUseFunctions) {
-
+
UNIT_ASSERT(SqlToYql(
"PROCESS plato.Input"
" USING EXTERNAL FUNCTION('YANDEX-CLOUD', 'foo', <|a: 123, b: a + 641|>)"
@@ -1713,7 +1713,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(InvalidDoubleAtString) {
- NYql::TAstParseResult res = SqlToYql("select @@@@@@");
+ NYql::TAstParseResult res = SqlToYql("select @@@@@@");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:13: Error: Unexpected character : syntax error...\n\n"
"<main>:1:0: Error: Unexpected token absence : cannot match to any predicted input...\n\n");
@@ -1739,13 +1739,13 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(SelectInvalidSyntax) {
- NYql::TAstParseResult res = SqlToYql("select 1 form Wat");
+ NYql::TAstParseResult res = SqlToYql("select 1 form Wat");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:14: Error: Unexpected token 'Wat' : cannot match to any predicted input...\n\n");
}
Y_UNIT_TEST(SelectNoCluster) {
- NYql::TAstParseResult res = SqlToYql("select foo from bar");
+ NYql::TAstParseResult res = SqlToYql("select foo from bar");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: No cluster name given and no default cluster is selected\n");
}
@@ -1763,9 +1763,9 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(SelectCaseWithoutThen) {
- NYql::TAstParseResult res = SqlToYql("select case when true 1;");
+ NYql::TAstParseResult res = SqlToYql("select case when true 1;");
UNIT_ASSERT(!res.Root);
- UNIT_ASSERT_NO_DIFF(Err2Str(res),
+ UNIT_ASSERT_NO_DIFF(Err2Str(res),
"<main>:1:22: Error: Unexpected token absence : Missing THEN \n\n"
"<main>:1:23: Error: Unexpected token absence : Missing END \n\n"
);
@@ -1787,7 +1787,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(SelectWithBadAggregationNoInput) {
- NYql::TAstParseResult res = SqlToYql("select a, Min(b), c");
+ NYql::TAstParseResult res = SqlToYql("select a, Min(b), c");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res),
"<main>:1:1: Error: Column references are not allowed without FROM\n"
@@ -1935,7 +1935,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(SelectWithBadAggregationInGrouping) {
- NYql::TAstParseResult res = SqlToYql("select a, Min(b), c group by c");
+ NYql::TAstParseResult res = SqlToYql("select a, Min(b), c group by c");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Column references are not allowed without FROM\n"
"<main>:1:30: Error: Column reference 'c'\n");
@@ -1972,10 +1972,10 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
Y_UNIT_TEST(ErrorInOrderByExpresison) {
NYql::TAstParseResult res = SqlToYql("select key, value from plato.Input order by (key as zey)");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:45: Error: You should use in ORDER BY column name, qualified field, callable function or expression\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectAggregatedWhere) {
NYql::TAstParseResult res = SqlToYql("select * from plato.Input where count(key)");
UNIT_ASSERT(!res.Root);
@@ -2018,7 +2018,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
NYql::TAstParseResult res = SqlToYql(
"$left = (SELECT * FROM plato.Input1 LIMIT 2);\n"
"$right = (SELECT * FROM plato.Input2 LIMIT 2);\n"
- "SELECT * FROM $left FULL JOIN $right USING (key);\n"
+ "SELECT * FROM $left FULL JOIN $right USING (key);\n"
);
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:3:45: Error: At least one correlation name is required in join\n");
@@ -2107,7 +2107,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(BuiltinFileOpNoArgs) {
- NYql::TAstParseResult res = SqlToYql("select FilePath()");
+ NYql::TAstParseResult res = SqlToYql("select FilePath()");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: FilePath() requires exactly 1 arguments, given: 0\n");
}
@@ -2138,118 +2138,118 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
Y_UNIT_TEST(AsteriskWithSomethingAfter) {
NYql::TAstParseResult res = SqlToYql("select *, LENGTH(value) from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Unable to use plain '*' with other projection items. Please use qualified asterisk instead: '<table>.*' (<table> can be either table name or table alias).\n");
- }
+ }
Y_UNIT_TEST(AsteriskWithSomethingBefore) {
NYql::TAstParseResult res = SqlToYql("select LENGTH(value), * from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:23: Error: Unable to use plain '*' with other projection items. Please use qualified asterisk instead: '<table>.*' (<table> can be either table name or table alias).\n");
}
-
+
Y_UNIT_TEST(DuplicatedQualifiedAsterisk) {
NYql::TAstParseResult res = SqlToYql("select in.*, key, in.* from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:19: Error: Unable to use twice same quialified asterisk. Invalid source: in\n");
- }
-
+ }
+
Y_UNIT_TEST(BrokenLabel) {
NYql::TAstParseResult res = SqlToYql("select in.*, key as `funny.label` from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:14: Error: Unable to use '.' in column name. Invalid column name: funny.label\n");
- }
-
+ }
+
Y_UNIT_TEST(KeyConflictDetect0) {
NYql::TAstParseResult res = SqlToYql("select key, in.key as key from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:13: Error: Unable to use duplicate column names. Collision in name: key\n");
- }
-
+ }
+
Y_UNIT_TEST(KeyConflictDetect1) {
NYql::TAstParseResult res = SqlToYql("select length(key) as key, key from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:28: Error: Unable to use duplicate column names. Collision in name: key\n");
- }
-
+ }
+
Y_UNIT_TEST(KeyConflictDetect2) {
NYql::TAstParseResult res = SqlToYql("select key, in.key from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: key\n");
- }
-
+ }
+
Y_UNIT_TEST(AutogenerationAliasWithCollisionConflict1) {
NYql::TAstParseResult res = SqlToYql("select LENGTH(Value), key as column0 from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: column0\n");
- }
-
+ }
+
Y_UNIT_TEST(AutogenerationAliasWithCollisionConflict2) {
NYql::TAstParseResult res = SqlToYql("select key as column1, LENGTH(Value) from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: column1\n");
- }
-
+ }
+
Y_UNIT_TEST(MissedSourceTableForQualifiedAsteriskOnSimpleSelect) {
NYql::TAstParseResult res = SqlToYql("use plato; select Intop.*, Input.key from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:19: Error: Unknown correlation name: Intop\n");
- }
-
+ }
+
Y_UNIT_TEST(MissedSourceTableForQualifiedAsteriskOnJoin) {
NYql::TAstParseResult res = SqlToYql("use plato; select tmissed.*, t2.*, t1.key from plato.Input as t1 join plato.Input as t2 on t1.key==t2.key;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:19: Error: Unknown correlation name for asterisk: tmissed\n");
- }
-
+ }
+
Y_UNIT_TEST(UnableToReferenceOnNotExistSubcolumn) {
NYql::TAstParseResult res = SqlToYql("select b.subkey from (select key from plato.Input as a) as b;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Column subkey is not in source column set\n");
- }
-
+ }
+
Y_UNIT_TEST(ConflictOnSameNameWithQualify0) {
NYql::TAstParseResult res = SqlToYql("select in.key, in.key as key from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: key\n");
- }
-
+ }
+
Y_UNIT_TEST(ConflictOnSameNameWithQualify1) {
NYql::TAstParseResult res = SqlToYql("select in.key, length(key) as key from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: key\n");
- }
-
+ }
+
Y_UNIT_TEST(ConflictOnSameNameWithQualify2) {
NYql::TAstParseResult res = SqlToYql("select key, in.key from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: key\n");
- }
-
+ }
+
Y_UNIT_TEST(ConflictOnSameNameWithQualify3) {
NYql::TAstParseResult res = SqlToYql("select in.key, subkey as key from plato.Input as in;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Duplicate column: key\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectOrderByUnknownLabel) {
NYql::TAstParseResult res = SqlToYql("select a from plato.Input order by b");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:36: Error: Column b is not in source column set. Did you mean a?\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectFlattenBySameColumns) {
NYql::TAstParseResult res = SqlToYql("select key from plato.Input flatten by (key, key as kk)");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:46: Error: Duplicate column name found: key in FlattenBy section\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectFlattenBySameAliases) {
NYql::TAstParseResult res = SqlToYql("select key from plato.Input flatten by (key as kk, subkey as kk);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:52: Error: Duplicate alias found: kk in FlattenBy section\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectFlattenByExprSameAliases) {
NYql::TAstParseResult res = SqlToYql("select key from plato.Input flatten by (key as kk, ListSkip(subkey,1) as kk);");
UNIT_ASSERT(!res.Root);
@@ -2258,16 +2258,16 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
Y_UNIT_TEST(SelectFlattenByConflictNameAndAlias0) {
NYql::TAstParseResult res = SqlToYql("select key from plato.Input flatten by (key, subkey as key);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:46: Error: Collision between alias and column name: key in FlattenBy section\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectFlattenByConflictNameAndAlias1) {
NYql::TAstParseResult res = SqlToYql("select key from plato.Input flatten by (key as kk, subkey as key);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:52: Error: Collision between alias and column name: key in FlattenBy section\n");
- }
-
+ }
+
Y_UNIT_TEST(SelectFlattenByExprConflictNameAndAlias1) {
NYql::TAstParseResult res = SqlToYql("select key from plato.Input flatten by (key as kk, ListSkip(subkey,1) as key);");
UNIT_ASSERT(!res.Root);
@@ -2286,7 +2286,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:42: Error: Unable to use IN predicate with string argument, it won't search substring - "
"expecting tuple, list, dict or single column table source\n");
}
-
+
Y_UNIT_TEST(UseSubqueryInScalarContextInsideIn) {
NYql::TAstParseResult res = SqlToYql("$q = (select key from plato.Input); select * from plato.Input where subkey in ($q);");
UNIT_ASSERT(res.Root);
@@ -2302,17 +2302,17 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(ErrorColumnPosition) {
- NYql::TAstParseResult res = SqlToYql(
+ NYql::TAstParseResult res = SqlToYql(
"USE plato;\n"
- "SELECT \n"
- "value FROM (\n"
- "select key from Input\n"
- ");\n"
- );
- UNIT_ASSERT(!res.Root);
+ "SELECT \n"
+ "value FROM (\n"
+ "select key from Input\n"
+ ");\n"
+ );
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:3:1: Error: Column value is not in source column set\n");
- }
-
+ }
+
Y_UNIT_TEST(InsertAbortMapReduce) {
NYql::TAstParseResult res = SqlToYql("INSERT OR ABORT INTO plato.Output SELECT key FROM plato.Input");
UNIT_ASSERT(!res.Root);
@@ -2323,14 +2323,14 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
NYql::TAstParseResult res = SqlToYql("REPLACE INTO plato.Output SELECT key FROM plato.Input");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:0: Error: Meaning of REPLACE INTO has been changed, now you should use INSERT INTO <table> WITH TRUNCATE ... for yt\n");
- }
-
+ }
+
Y_UNIT_TEST(UpsertIntoMapReduce) {
NYql::TAstParseResult res = SqlToYql("UPSERT INTO plato.Output SELECT key FROM plato.Input");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:0: Error: UPSERT INTO is not supported for yt tables\n");
- }
-
+ }
+
Y_UNIT_TEST(UpdateMapReduce) {
NYql::TAstParseResult res = SqlToYql("UPDATE plato.Output SET value = value + 1 WHERE key < 1");
UNIT_ASSERT(!res.Root);
@@ -2345,46 +2345,46 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
Y_UNIT_TEST(ReplaceIntoWithTruncate) {
NYql::TAstParseResult res = SqlToYql("REPLACE INTO plato.Output WITH TRUNCATE SELECT key FROM plato.Input");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:32: Error: Unable REPLACE INTO with truncate mode\n");
- }
-
+ }
+
Y_UNIT_TEST(UpsertIntoWithTruncate) {
NYql::TAstParseResult res = SqlToYql("UPSERT INTO plato.Output WITH TRUNCATE SELECT key FROM plato.Input");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:31: Error: Unable UPSERT INTO with truncate mode\n");
- }
-
+ }
+
Y_UNIT_TEST(InsertIntoWithTruncateKikimr) {
NYql::TAstParseResult res = SqlToYql("INSERT INTO plato.Output WITH TRUNCATE SELECT key FROM plato.Input", 10, TString(NYql::KikimrProviderName));
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:0: Error: INSERT INTO WITH TRUNCATE is not supported for kikimr tables\n");
- }
-
+ }
+
Y_UNIT_TEST(InsertIntoWithWrongArgumentCount) {
NYql::TAstParseResult res = SqlToYql("insert into plato.Output with truncate (key, value, subkey) values (5, '1', '2', '3');");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:53: Error: VALUES have 4 columns, INSERT INTO ... WITH TRUNCATE expects: 3\n");
- }
-
+ }
+
Y_UNIT_TEST(UpsertWithWrongArgumentCount) {
NYql::TAstParseResult res = SqlToYql("upsert into plato.Output (key, value, subkey) values (2, '3');", 10, TString(NYql::KikimrProviderName));
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:39: Error: VALUES have 2 columns, UPSERT INTO expects: 3\n");
- }
-
+ }
+
Y_UNIT_TEST(UnionNotSupported) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input UNION select subkey FROM plato.Input;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:29: Error: UNION without quantifier ALL is not supported yet. Did you mean UNION ALL?\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupingSetByExprWithoutAlias) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY GROUPING SETS (cast(key as uint32), subkey);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:53: Error: Unnamed expressions are not supported in GROUPING SETS. Please use '<expr> AS <name>'.\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupingSetByExprWithoutAlias2) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY subkey || subkey, GROUPING SETS (\n"
"cast(key as uint32), subkey);");
@@ -2394,106 +2394,106 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
Y_UNIT_TEST(CubeByExprWithoutAlias) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY CUBE (key, subkey / key);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:56: Error: Unnamed expressions are not supported in CUBE. Please use '<expr> AS <name>'.\n");
- }
-
+ }
+
Y_UNIT_TEST(RollupByExprWithoutAlias) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY ROLLUP (subkey / key);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:53: Error: Unnamed expressions are not supported in ROLLUP. Please use '<expr> AS <name>'.\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupByHugeCubeDeniedNoPragma) {
- NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY CUBE (key, subkey, value, key + subkey as sum, key - subkey as sub, key + val as keyval);");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY CUBE (key, subkey, value, key + subkey as sum, key - subkey as sub, key + val as keyval);");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:119: Error: GROUP BY CUBE is allowed only for 5 columns, but you use 6\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupByInvalidPragma) {
- NYql::TAstParseResult res = SqlToYql("PRAGMA GroupByCubeLimit = '-4';");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("PRAGMA GroupByCubeLimit = '-4';");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:27: Error: Expected unsigned integer literal as a single argument for: GroupByCubeLimit\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupByHugeCubeDeniedPragme) {
- NYql::TAstParseResult res = SqlToYql("PRAGMA GroupByCubeLimit = '4'; SELECT key FROM plato.Input GROUP BY CUBE (key, subkey, value, key + subkey as sum, key - subkey as sub);");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("PRAGMA GroupByCubeLimit = '4'; SELECT key FROM plato.Input GROUP BY CUBE (key, subkey, value, key + subkey as sum, key - subkey as sub);");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:132: Error: GROUP BY CUBE is allowed only for 4 columns, but you use 5\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupByFewBigCubes) {
NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY CUBE(key, subkey, key + subkey as sum), CUBE(value, value + key + subkey as total);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:1: Error: Unable to GROUP BY more than 32 groups, you try use 80 groups\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupByFewBigCubesWithPragmaLimit) {
- NYql::TAstParseResult res = SqlToYql("PRAGMA GroupByLimit = '16'; SELECT key FROM plato.Input GROUP BY GROUPING SETS(key, subkey, key + subkey as sum), ROLLUP(value, value + key + subkey as total);");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("PRAGMA GroupByLimit = '16'; SELECT key FROM plato.Input GROUP BY GROUPING SETS(key, subkey, key + subkey as sum), ROLLUP(value, value + key + subkey as total);");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:29: Error: Unable to GROUP BY more than 16 groups, you try use 18 groups\n");
- }
-
+ }
+
Y_UNIT_TEST(NoGroupingColumn0) {
- NYql::TAstParseResult res = SqlToYql(
- "select count(1), key_first, val_first, grouping(key_first, val_first, nomind) as group\n"
+ NYql::TAstParseResult res = SqlToYql(
+ "select count(1), key_first, val_first, grouping(key_first, val_first, nomind) as group\n"
"from plato.Input group by grouping sets (cast(key as uint32) /100 as key_first, Substring(value, 1, 1) as val_first);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:71: Error: Column 'nomind' is not a grouping column\n");
- }
-
+ }
+
Y_UNIT_TEST(NoGroupingColumn1) {
NYql::TAstParseResult res = SqlToYql("select count(1), grouping(key, value) as group_duo from plato.Input group by cube (key, subkey);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:32: Error: Column 'value' is not a grouping column\n");
- }
-
+ }
+
Y_UNIT_TEST(EmptyAccess0) {
NYql::TAstParseResult res = SqlToYql("insert into plato.Output (list0, list1) values (AsList(0, 1, 2), AsList(``));");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:73: Error: Column reference \"\" is not allowed in current scope\n");
- }
-
+ }
+
Y_UNIT_TEST(EmptyAccess1) {
NYql::TAstParseResult res = SqlToYql("insert into plato.Output (list0, list1) values (AsList(0, 1, 2), ``);");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:66: Error: Column reference \"\" is not allowed in current scope\n");
- }
-
+ }
+
Y_UNIT_TEST(UseUnknownColumnInInsert) {
NYql::TAstParseResult res = SqlToYql("insert into plato.Output (list0, list1) values (AsList(0, 1, 2), AsList(`test`));");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:73: Error: Column reference \"test\" is not allowed in current scope\n");
- }
-
+ }
+
Y_UNIT_TEST(GroupByEmptyColumn) {
NYql::TAstParseResult res = SqlToYql("select count(1) from plato.Input group by ``;");
- UNIT_ASSERT(!res.Root);
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:43: Error: Column name can not be empty\n");
- }
+ }
Y_UNIT_TEST(ConvertNumberOutOfBase) {
- NYql::TAstParseResult res = SqlToYql("select 0o80l;");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("select 0o80l;");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Failed to parse number from string: 0o80l, char: '8' is out of base: 8\n");
- }
-
+ }
+
Y_UNIT_TEST(ConvertNumberOutOfRangeForInt64ButFitsInUint64) {
- NYql::TAstParseResult res = SqlToYql("select 0xc000000000000000l;");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("select 0xc000000000000000l;");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Failed to parse 13835058055282163712 as integer literal of Int64 type: value out of range for Int64\n");
- }
-
+ }
+
Y_UNIT_TEST(ConvertNumberOutOfRangeUint64) {
- NYql::TAstParseResult res = SqlToYql("select 0xc0000000000000000l;");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("select 0xc0000000000000000l;");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Failed to parse number from string: 0xc0000000000000000l, number limit overflow\n");
res = SqlToYql("select 1234234543563435151456;\n");
UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Failed to parse number from string: 1234234543563435151456, number limit overflow\n");
- }
-
+ }
+
Y_UNIT_TEST(ConvertNumberNegativeOutOfRange) {
NYql::TAstParseResult res = SqlToYql("select -9223372036854775808;\n"
"select -9223372036854775809;");
@@ -2502,22 +2502,22 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) {
}
Y_UNIT_TEST(InvaildUsageReal0) {
- NYql::TAstParseResult res = SqlToYql("select .0;");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("select .0;");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:7: Error: Unexpected token '.' : cannot match to any predicted input...\n\n");
- }
-
+ }
+
Y_UNIT_TEST(InvaildUsageReal1) {
- NYql::TAstParseResult res = SqlToYql("select .0f;");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("select .0f;");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:7: Error: Unexpected token '.' : cannot match to any predicted input...\n\n");
- }
-
+ }
+
Y_UNIT_TEST(InvaildUsageWinFunctionWithoutWindow) {
- NYql::TAstParseResult res = SqlToYql("select lead(key, 2) from plato.Input;");
- UNIT_ASSERT(!res.Root);
+ NYql::TAstParseResult res = SqlToYql("select lead(key, 2) from plato.Input;");
+ UNIT_ASSERT(!res.Root);
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:8: Error: Failed to use window function Lead without window specification\n");
- }
+ }
Y_UNIT_TEST(DropTableWithIfExists) {
NYql::TAstParseResult res = SqlToYql("DROP TABLE IF EXISTS plato.foo;");
diff --git a/ydb/library/yql/sql/v1/ya.make b/ydb/library/yql/sql/v1/ya.make
index 24ab1ef04a..432fdefbf7 100644
--- a/ydb/library/yql/sql/v1/ya.make
+++ b/ydb/library/yql/sql/v1/ya.make
@@ -41,7 +41,7 @@ YQL_LAST_ABI_VERSION()
GENERATE_ENUM_SERIALIZATION(node.h)
GENERATE_ENUM_SERIALIZATION(sql_call_param.h)
-
+
END()
RECURSE_FOR_TESTS(
diff --git a/ydb/library/yql/udfs/common/digest/digest_udf.cpp b/ydb/library/yql/udfs/common/digest/digest_udf.cpp
index f507e0e824..7487a078dd 100644
--- a/ydb/library/yql/udfs/common/digest/digest_udf.cpp
+++ b/ydb/library/yql/udfs/common/digest/digest_udf.cpp
@@ -85,7 +85,7 @@ namespace {
static bool DeclareSignature(
const TStringRef& name,
- TType* userType,
+ TType* userType,
IFunctionTypeInfoBuilder& builder,
bool typesOnly) {
Y_UNUSED(userType);
diff --git a/ydb/library/yql/udfs/common/histogram/histogram_udf.cpp b/ydb/library/yql/udfs/common/histogram/histogram_udf.cpp
index 915caee9b7..3cbf685cc1 100644
--- a/ydb/library/yql/udfs/common/histogram/histogram_udf.cpp
+++ b/ydb/library/yql/udfs/common/histogram/histogram_udf.cpp
@@ -143,7 +143,7 @@ namespace {
public:
static bool DeclareSignature(
const TStringRef& name,
- TType* userType,
+ TType* userType,
IFunctionTypeInfoBuilder& builder,
bool typesOnly) {
Y_UNUSED(userType);
@@ -194,7 +194,7 @@ namespace {
public:
static bool DeclareSignature(
const TStringRef& name,
- TType* userType,
+ TType* userType,
IFunctionTypeInfoBuilder& builder,
bool typesOnly) {
Y_UNUSED(userType);
@@ -246,7 +246,7 @@ namespace {
public:
static bool DeclareSignature(
const TStringRef& name,
- TType* userType,
+ TType* userType,
IFunctionTypeInfoBuilder& builder,
bool typesOnly) {
Y_UNUSED(userType);
@@ -299,7 +299,7 @@ namespace {
public:
static bool DeclareSignature(
const TStringRef& name,
- TType* userType,
+ TType* userType,
IFunctionTypeInfoBuilder& builder,
bool typesOnly) {
Y_UNUSED(userType);
@@ -351,7 +351,7 @@ namespace {
public:
static bool DeclareSignature(
const TStringRef& name,
- TType* userType,
+ TType* userType,
IFunctionTypeInfoBuilder& builder,
bool typesOnly) {
Y_UNUSED(userType);
diff --git a/ydb/library/yql/udfs/common/re2/re2_udf.cpp b/ydb/library/yql/udfs/common/re2/re2_udf.cpp
index d67bf9fcd5..b478675fb6 100644
--- a/ydb/library/yql/udfs/common/re2/re2_udf.cpp
+++ b/ydb/library/yql/udfs/common/re2/re2_udf.cpp
@@ -251,7 +251,7 @@ namespace {
TSourcePosition Pos_;
TUnboxedValue BuildEmptyStruct(const IValueBuilder* valueBuilder) const {
- TUnboxedValue* items = nullptr;
+ TUnboxedValue* items = nullptr;
return valueBuilder->NewArray(RegexpGroups.Names.size(), items);
}
};