예제 #1
0
        public static QsiTableNode VisitSetOperandList(Set_operand_listContext context)
        {
            QsiTableNode[] sources = context._sets
                                     .Select(VisitSetOperand)
                                     .ToArray();

            var orderByClause         = context.opt_order_by_clause();
            var limitOffsetClauseExpr = ExpressionVisitor.VisitLimitOffsetClause(context.opt_limit_offset_clause());

            if (sources.Length > 1)
            {
                var node = ImpalaTree.CreateWithSpan <QsiCompositeTableNode>(context);

                node.Sources.AddRange(sources);

                if (orderByClause is not null)
                {
                    node.Order.Value = ExpressionVisitor.VisitOrderByClause(orderByClause);
                }

                if (limitOffsetClauseExpr is not null)
                {
                    node.Limit.Value = limitOffsetClauseExpr;
                }

                return(node);
            }

            if (orderByClause is not null || limitOffsetClauseExpr is not null)
            {
                if (sources[0] is not QsiDerivedTableNode
                {
                    Order : { IsEmpty : true },
예제 #2
0
        private static QsiColumnsDeclarationNode VisitViewColumnDefs(View_column_defsContext context)
        {
            var node = ImpalaTree.CreateWithSpan <QsiColumnsDeclarationNode>(context);

            node.Columns.AddRange(VisitViewColumnDefList(context.view_column_def_list()));
            return(node);
        }
예제 #3
0
        public static QsiTableNode VisitQueryStmt(Query_stmtContext context)
        {
            var withClause     = context.opt_with_clause();
            var setOperandList = context.set_operand_list();

            var node = VisitSetOperandList(setOperandList);

            if (withClause is not null)
            {
                if (node is not QsiDerivedTableNode {
                    Directives : { IsEmpty : true }
                } derivedTableNode)
                {
                    derivedTableNode = ImpalaTree.CreateWithSpan <QsiDerivedTableNode>(context);
                    derivedTableNode.Columns.Value = TreeHelper.CreateAllColumnsDeclaration();
                    derivedTableNode.Source.Value  = node;

                    node = derivedTableNode;
                }

                derivedTableNode.Directives.Value = VisitWithClause(withClause);
            }

            return(node);
        }
예제 #4
0
        public static IQsiTreeNode VisitUseStmt(Use_stmtContext context)
        {
            var node = ImpalaTree.CreateWithSpan <QsiChangeSearchPathActionNode>(context);

            node.Identifiers = new[] { IdentifierVisitor.VisitIdentOrDefault(context.ident_or_default()) };
            return(node);
        }
예제 #5
0
        public static IQsiTreeNode VisitUpsertStmt(Upsert_stmtContext context)
        {
            var node = ImpalaTree.CreateWithSpan <ImpalaDataInsertActionNode>(context);

            if (context.with is not null)
            {
                node.Directives.Value = TableVisitor.VisitWithClause(context.with);
            }

            if (context.hint is not null)
            {
                node.PlanHints = context.hint.GetInputText();
            }

            node.ConflictBehavior = QsiDataConflictBehavior.Update;
            node.Target.Value     = TableVisitor.VisitTableName(context.name);

            if (context.columns is not null)
            {
                node.Columns = IdentifierVisitor.VisitIdentList(context.columns)
                               .Select(i => new QsiQualifiedIdentifier(i))
                               .ToArray();
            }

            node.ValueTable.Value = TableVisitor.VisitQueryStmt(context.query);

            return(node);
        }
예제 #6
0
        public static IQsiTreeNode VisitCreateTblAsSelectStmt(Create_tbl_as_select_stmtContext context)
        {
            var node = ImpalaTree.CreateWithSpan <ImpalaTableDefinitionNode>(context);

            node.PlanHints = context.plan_hints()?.GetInputText();
            VisitCreateTblAsSelectParams(node, context.create_tbl_as_select_params());
            return(node);
        }
예제 #7
0
        private static QsiColumnNode VisitViewColumnDef(View_column_defContext context)
        {
            var identOrDefault = context.ident_or_default();
            var node           = ImpalaTree.CreateWithSpan <QsiColumnReferenceNode>(identOrDefault);

            node.Name = new QsiQualifiedIdentifier(IdentifierVisitor.VisitIdentOrDefault(identOrDefault));
            return(node);
        }
예제 #8
0
        public static IQsiTreeNode VisitCreateViewStmt(Create_view_stmtContext context)
        {
            var node = ImpalaTree.CreateWithSpan <QsiViewDefinitionNode>(context);

            node.ConflictBehavior = context.HasRule <If_not_exists_valContext>() ?
                                    QsiDefinitionConflictBehavior.Ignore :
                                    QsiDefinitionConflictBehavior.None;

            node.Identifier = IdentifierVisitor.VisitTableName(context.table_name());

            node.Columns.Value = context.TryGetRuleContext <View_column_defsContext>(out var viewColumnDefs) ?
                                 VisitViewColumnDefs(viewColumnDefs) :
                                 TreeHelper.CreateAllColumnsDeclaration();

            node.Source.Value = TableVisitor.VisitQueryStmt(context.query_stmt());

            return(node);
        }
예제 #9
0
        public static IQsiTreeNode VisitUpdateStmt(Update_stmtContext context)
        {
            var node     = ImpalaTree.CreateWithSpan <QsiDataUpdateActionNode>(context);
            var wildcard = new QsiAllColumnNode();

            var targetTable = new QsiDerivedTableNode
            {
                Columns =
                {
                    Value       = new QsiColumnsDeclarationNode
                    {
                        Columns =
                        {
                            wildcard
                        }
                    }
                }
            };

            if (context.from is not null)
            {
                if (context.target.children.Count != 1)
                {
                    throw new QsiException(QsiError.SyntaxError, $"'{context.target.GetInputText()}' is not a valid table alias or reference.");
                }

                wildcard.Path            = IdentifierVisitor.VisitDottedPath(context.target);
                targetTable.Source.Value = TableVisitor.VisitFromClause(context.from);
            }
            else
            {
                targetTable.Source.Value = TableVisitor.VisitDottedPath(context.target);
            }

            if (context.where is not null)
            {
                targetTable.Where.Value = ExpressionVisitor.VisitWhereClause(context.where);
            }

            node.Target.Value = targetTable;
            node.SetValues.AddRange(ExpressionVisitor.VisitUpdateSetExprList(context.values));

            return(node);
        }
예제 #10
0
        private static void VisitCreateTblAsSelectParams(ImpalaTableDefinitionNode node, Create_tbl_as_select_paramsContext context)
        {
            node.IsExternal       = context.tblDef.external;
            node.ConflictBehavior = context.tblDef.ifNotExists ? QsiDefinitionConflictBehavior.Ignore : QsiDefinitionConflictBehavior.None;
            node.Identifier       = IdentifierVisitor.VisitTableName(context.tblDef.table_name());
            node.DataSource.Value = TableVisitor.VisitQueryStmt(context.query);

            if (context.options.children?.Count > 0)
            {
                var fragment = ImpalaTree.CreateWithSpan <QsiExpressionFragmentNode>(context.options);
                fragment.Text = context.options.GetInputText();

                node.Options.Value = fragment;
            }

            if (context.TryGetRuleContext <Primary_keysContext>(out var primaryKeys))
            {
                node.PrimaryKeyColumnNames = IdentifierVisitor.VisitIdentList(primaryKeys.ident_list()).ToArray();
            }

            if (context.TryGetRuleContext <Partitioned_data_layoutContext>(out var partitionedDataLayout))
            {
                var fragment = ImpalaTree.CreateWithSpan <QsiExpressionFragmentNode>(context.options);
                fragment.Text = partitionedDataLayout.GetInputText();

                node.KuduPartitionParams.Value = fragment;
            }

            if (context.TryGetRuleContext <Iceberg_partition_spec_listContext>(out var icebergPartitionSpecList))
            {
                var fragment = ImpalaTree.CreateWithSpan <QsiExpressionFragmentNode>(context.options);
                fragment.Text = icebergPartitionSpecList.GetInputText();

                node.IcebergPartitionSpecs.Value = fragment;
            }

            if (context.TryGetRuleContext <Ident_listContext>(out var identList))
            {
                node.PartitionColumnNames = IdentifierVisitor.VisitIdentList(identList).ToArray();
            }
        }