/** * Creates an ASTNode for the given token. The ASTNode is a wrapper around * antlr's CommonTree class that implements the Node interface. * * @param payload * The token. * @return Object (which is actually an ASTNode) for the token. */ @Override public Object create(Token payload) { return new ASTNode(payload); }
@Override public Tree dupNode() { return new ASTNode(this); }
/** * Creates an ASTNode for the given token. The ASTNode is a wrapper around * antlr's CommonTree class that implements the Node interface. * * @param payload * The token. * @return Object (which is actually an ASTNode) for the token. */ @Override public Object create(Token payload) { return new ASTNode(payload); }
@Override public Tree dupNode() { return new ASTNode(this); }
public static ASTNode genSelectDIAST(RowResolver rr) { LinkedHashMap<String, LinkedHashMap<String, ColumnInfo>> map = rr.getRslvMap(); ASTNode selectDI = new ASTNode(SELECTDI_TOKEN); // Note: this will determine the order of columns in the result. For now, the columns for each // table will be together; the order of the tables, as well as the columns within each // table, is deterministic, but undefined - RR stores them in the order of addition. for (String tabAlias : map.keySet()) { for (Entry<String, ColumnInfo> entry : map.get(tabAlias).entrySet()) { selectDI.addChild(buildSelExprSubTree(tabAlias, entry.getKey())); } } return selectDI; } private static ASTNode buildSelExprSubTree(String tableAlias, String col) {
private static ASTNode buildSelExprSubTree(String tableAlias, String col) { tableAlias = StringInternUtils.internIfNotNull(tableAlias); col = StringInternUtils.internIfNotNull(col); ASTNode selexpr = new ASTNode(SELEXPR_TOKEN); ASTNode tableOrCol = new ASTNode(TABLEORCOL_TOKEN); ASTNode dot = new ASTNode(DOT_TOKEN); tableOrCol.addChild(new ASTNode(new CommonToken(HiveParser.Identifier, tableAlias))); dot.addChild(tableOrCol); dot.addChild(new ASTNode(new CommonToken(HiveParser.Identifier, col))); selexpr.addChild(dot); return selexpr; }
public static ASTNode genSelectDIAST(RowResolver rr) { LinkedHashMap<String, LinkedHashMap<String, ColumnInfo>> map = rr.getRslvMap(); ASTNode selectDI = new ASTNode(new CommonToken(HiveParser.TOK_SELECTDI, "TOK_SELECTDI")); // Note: this will determine the order of columns in the result. For now, the columns for each // table will be together; the order of the tables, as well as the columns within each // table, is deterministic, but undefined - RR stores them in the order of addition. for (String tabAlias : map.keySet()) { for (Entry<String, ColumnInfo> entry : map.get(tabAlias).entrySet()) { selectDI.addChild(buildSelExprSubTree(tabAlias, entry.getKey())); } } return selectDI; } private static ASTNode buildSelExprSubTree(String tableAlias, String col) {
private static ASTNode buildSelExprSubTree(String tableAlias, String col) { ASTNode selexpr = new ASTNode(new CommonToken(HiveParser.TOK_SELEXPR, "TOK_SELEXPR")); ASTNode tableOrCol = new ASTNode(new CommonToken(HiveParser.TOK_TABLE_OR_COL, "TOK_TABLE_OR_COL")); ASTNode dot = new ASTNode(new CommonToken(HiveParser.DOT, ".")); tableOrCol.addChild(new ASTNode(new CommonToken(HiveParser.Identifier, tableAlias))); dot.addChild(tableOrCol); dot.addChild(new ASTNode(new CommonToken(HiveParser.Identifier, col))); selexpr.addChild(dot); return selexpr; }
@Test public void testCreate() throws Exception { BaseSemanticAnalyzer analyzer = SemanticAnalyzerFactory. get(queryState, new ASTNode(new CommonToken(HiveParser.TOK_CREATEMACRO))); Assert.assertTrue(analyzer.getClass().getSimpleName(), analyzer instanceof MacroSemanticAnalyzer); } @Test
@Test public void testDrop() throws Exception { BaseSemanticAnalyzer analyzer = SemanticAnalyzerFactory. get(queryState, new ASTNode(new CommonToken(HiveParser.TOK_DROPMACRO))); Assert.assertTrue(analyzer.getClass().getSimpleName(), analyzer instanceof MacroSemanticAnalyzer); } }
Table materializeCTE(String cteName, CTEClause cte) throws HiveException { ASTNode createTable = new ASTNode(new ClassicToken(HiveParser.TOK_CREATETABLE)); ASTNode tableName = new ASTNode(new ClassicToken(HiveParser.TOK_TABNAME)); tableName.addChild(new ASTNode(new ClassicToken(HiveParser.Identifier, cteName))); ASTNode temporary = new ASTNode(new ClassicToken(HiveParser.KW_TEMPORARY, MATERIALIZATION_MARKER));
@Override Table materializeCTE(String cteName, CTEClause cte) throws HiveException { ASTNode createTable = new ASTNode(new ClassicToken(HiveParser.TOK_CREATETABLE)); ASTNode tableName = new ASTNode(new ClassicToken(HiveParser.TOK_TABNAME)); tableName.addChild(new ASTNode(new ClassicToken(HiveParser.Identifier, cteName))); ASTNode temporary = new ASTNode(new ClassicToken(HiveParser.KW_TEMPORARY, MATERIALIZATION_MARKER));
Table materializeCTE(String cteName, CTEClause cte) throws HiveException { ASTNode createTable = new ASTNode(new ClassicToken(HiveParser.TOK_CREATETABLE)); ASTNode tableName = new ASTNode(new ClassicToken(HiveParser.TOK_TABNAME)); tableName.addChild(new ASTNode(new ClassicToken(HiveParser.Identifier, cteName))); ASTNode temporary = new ASTNode(new ClassicToken(HiveParser.KW_TEMPORARY, MATERIALIZATION_MARKER));
private void applyConstantPartition(WindowSpec wdwSpec) { PartitionSpec partSpec = wdwSpec.getPartition(); if ( partSpec == null ) { partSpec = new PartitionSpec(); PartitionExpression partExpr = new PartitionExpression(); partExpr.setExpression(new ASTNode(new CommonToken(HiveParser.Number, "0"))); partSpec.addExpression(partExpr); wdwSpec.setPartition(partSpec); } }
@Override Table materializeCTE(String cteName, CTEClause cte) throws HiveException { ASTNode createTable = new ASTNode(new ClassicToken(HiveParser.TOK_CREATETABLE)); ASTNode tableName = new ASTNode(new ClassicToken(HiveParser.TOK_TABNAME)); tableName.addChild(new ASTNode(new ClassicToken(HiveParser.Identifier, cteName))); ASTNode temporary = new ASTNode(new ClassicToken(HiveParser.KW_TEMPORARY, MATERIALIZATION_MARKER));
private void applyConstantPartition(WindowSpec wdwSpec) { PartitionSpec partSpec = wdwSpec.getPartition(); if ( partSpec == null ) { partSpec = new PartitionSpec(); PartitionExpression partExpr = new PartitionExpression(); partExpr.setExpression(new ASTNode(new CommonToken(HiveParser.Number, "0"))); partSpec.addExpression(partExpr); wdwSpec.setPartition(partSpec); } }
private static void applyConstantPartition(PartitionedTableFunctionSpec spec) { if (spec.getPartition() != null) { return; } PTFInputSpec iSpec = spec.getInput(); if (iSpec instanceof PTFInputSpec) { PartitionSpec partSpec = new PartitionSpec(); PartitionExpression partExpr = new PartitionExpression(); partExpr.setExpression(new ASTNode(new CommonToken(HiveParser.Number, "0"))); partSpec.addExpression(partExpr); spec.setPartition(partSpec); } }
private static void applyConstantPartition(PartitionedTableFunctionSpec spec) { if (spec.getPartition() != null) { return; } PTFInputSpec iSpec = spec.getInput(); if (iSpec instanceof PTFInputSpec) { PartitionSpec partSpec = new PartitionSpec(); PartitionExpression partExpr = new PartitionExpression(); partExpr.setExpression(new ASTNode(new CommonToken(HiveParser.Number, "0"))); partSpec.addExpression(partExpr); spec.setPartition(partSpec); } }
ASTNode newRoot = new ASTNode();