@Override public Object clone() throws CloneNotSupportedException { CommonSubquery subQuery = (CommonSubquery) super.clone(); subQuery.subquery = (Expr) subquery.clone(); return subQuery; }
@Override public LogicalNode visitRelation(ProcessorContext ctx, Stack<Expr> stack, Relation expr) throws TajoException { LogicalPlan plan = ctx.planContext.getPlan(); QueryBlock queryBlock = plan.getBlockByExpr(expr); ScanNode scan = queryBlock.getNodeFromExpr(expr); TableDesc desc = scan.getTableDesc(); if (desc.hasEmptySchema()) { Set<Column> columns = new HashSet<>(); if (ctx.projectColumns.containsKey(getQualifiedName(ctx.planContext, expr.getName()))) { for (ColumnReferenceExpr col : ctx.projectColumns.get(getQualifiedName(ctx.planContext, expr.getName()))) { columns.add(NameResolver.resolve(plan, queryBlock, col, NameResolvingMode.RELS_ONLY, true)); } } if (expr.hasAlias()) { if (ctx.projectColumns.containsKey(getQualifiedName(ctx.planContext, expr.getAlias()))) { for (ColumnReferenceExpr col : ctx.projectColumns.get(getQualifiedName(ctx.planContext, expr.getAlias()))) { columns.add(NameResolver.resolve(plan, queryBlock, col, NameResolvingMode.RELS_ONLY, true)); } } } if (columns.isEmpty()) { // error throw new TajoInternalError( "Columns projected from " + getQualifiedName(ctx.planContext, expr.getName()) + " is not found."); } desc.setSchema(buildSchemaFromColumnSet(columns)); scan.init(desc); } return scan; }
String indexName = ctx.index_name.getText(); String tableName = buildIdentifierChain(ctx.table_name().identifier()); Relation relation = new Relation(tableName); SortSpec[] sortSpecs = buildSortSpecs(ctx.sort_specifier_list()); List<NamedExpr> targets = new ArrayList<>();
@Override public Expr visitTable_primary(Table_primaryContext ctx) { if (ctx.table_or_query_name() != null) { Relation relation = new Relation(ctx.table_or_query_name().getText()); if (ctx.alias != null) { relation.setAlias(ctx.alias.getText()); } return relation; } else if (ctx.derived_table() != null) { return new TablePrimarySubQuery(ctx.name.getText(), visit(ctx.derived_table().table_subquery())); } else { return null; } }
@Override public Expr visitRelation(Context context, Stack<Expr> stack, Relation expr) throws TajoException { assertRelationExistence(context, expr.getName()); return expr; }
@Test public void testEquals() throws Exception { Expr expr = new BinaryOperator(OpType.LessThan, new LiteralValue("1", LiteralType.Unsigned_Integer), new LiteralValue("2", LiteralType.Unsigned_Integer)); Relation relation = new Relation("employee"); Selection selection = new Selection(expr); selection.setChild(relation); Aggregation aggregation = new Aggregation(); aggregation.setTargets(new NamedExpr[]{ new NamedExpr(new ColumnReferenceExpr("col1")) } ); aggregation.setChild(selection); Sort.SortSpec spec = new Sort.SortSpec(new ColumnReferenceExpr("col2")); Sort sort = new Sort(new Sort.SortSpec[]{spec}); sort.setChild(aggregation); assertEquals(sort, sort); Expr different = generateOneExpr(); assertFalse(sort.equals(different)); }
@Override public Expr visitTable_primary(Table_primaryContext ctx) { if (ctx.table_or_query_name() != null) { Relation relation = new Relation(ctx.table_or_query_name().getText()); if (ctx.alias != null) { relation.setAlias(ctx.alias.getText()); } return relation; } else if (ctx.derived_table() != null) { return new TablePrimarySubQuery(ctx.name.getText(), visit(ctx.derived_table().table_subquery())); } else { return null; } }
@Override public Expr visitRelation(Context context, Stack<Expr> stack, Relation expr) throws TajoException { assertRelationExistence(context, expr.getName()); return expr; }
@Override public LogicalNode visitRelation(ProcessorContext ctx, Stack<Expr> stack, Relation expr) throws TajoException { LogicalPlan plan = ctx.planContext.getPlan(); QueryBlock queryBlock = plan.getBlockByExpr(expr); ScanNode scan = queryBlock.getNodeFromExpr(expr); TableDesc desc = scan.getTableDesc(); if (desc.hasEmptySchema()) { Set<Column> columns = new HashSet<>(); if (ctx.projectColumns.containsKey(getQualifiedName(ctx.planContext, expr.getName()))) { for (ColumnReferenceExpr col : ctx.projectColumns.get(getQualifiedName(ctx.planContext, expr.getName()))) { columns.add(NameResolver.resolve(plan, queryBlock, col, NameResolvingMode.RELS_ONLY, true)); } } if (expr.hasAlias()) { if (ctx.projectColumns.containsKey(getQualifiedName(ctx.planContext, expr.getAlias()))) { for (ColumnReferenceExpr col : ctx.projectColumns.get(getQualifiedName(ctx.planContext, expr.getAlias()))) { columns.add(NameResolver.resolve(plan, queryBlock, col, NameResolvingMode.RELS_ONLY, true)); } } } if (columns.isEmpty()) { // error throw new TajoInternalError( "Columns projected from " + getQualifiedName(ctx.planContext, expr.getName()) + " is not found."); } desc.setSchema(buildSchemaFromColumnSet(columns)); scan.init(desc); } return scan; }
@Test public void testJson2() { Expr expr = new BinaryOperator(OpType.LessThan, new LiteralValue("1", LiteralType.Unsigned_Integer), new LiteralValue("2", LiteralType.Unsigned_Integer)); Relation relation = new Relation("employee"); Selection selection = new Selection(expr); selection.setChild(relation); Aggregation aggregation = new Aggregation(); aggregation.setTargets(new NamedExpr[]{ new NamedExpr(new ColumnReferenceExpr("col1")) } ); aggregation.setChild(selection); Sort.SortSpec spec = new Sort.SortSpec(new ColumnReferenceExpr("col2")); Sort sort = new Sort(new Sort.SortSpec[]{spec}); sort.setChild(aggregation); String json = sort.toJson(); Expr fromJson = JsonHelper.fromJson(json, Expr.class); assertEquals(sort, fromJson); } }
@Override public boolean isEligible(PlanContext context, Expr expr) throws TajoException { Set<Relation> relations = ExprFinderIncludeSubquery.finds(expr, OpType.Relation); for (Relation eachRelation : relations) { TableDesc tableDesc = catalog.getTableDesc(getQualifiedName(context, eachRelation.getName())); if (tableDesc.hasEmptySchema()) { return true; } } return false; }
@Override public Object clone() throws CloneNotSupportedException { CommonSubquery subQuery = (CommonSubquery) super.clone(); subQuery.subquery = (Expr) subquery.clone(); return subQuery; }
@Override public LogicalNode visitRelation(LogicalPlanner.PlanContext ctx, Stack<Expr> stack, Relation relation) throws TajoException { String actualRelationName; if (IdentifierUtil.isFQTableName(relation.getName())) { actualRelationName = relation.getName(); } else { actualRelationName = IdentifierUtil.buildFQName(ctx.getQueryContext().get(SessionVars.CURRENT_DATABASE), relation.getName()); } TableDesc desc = catalog.getTableDesc(actualRelationName); ScanNode scanNode = ctx.getPlan().createNode(ScanNode.class); if (relation.hasAlias()) { scanNode.init(desc, relation.getAlias()); } else { scanNode.init(desc); } TablePropertyUtil.setTableProperty(ctx.getQueryContext(), scanNode); ctx.getQueryBlock().addRelation(scanNode); return scanNode; }
String indexName = ctx.index_name.getText(); String tableName = buildIdentifierChain(ctx.table_name().identifier()); Relation relation = new Relation(tableName); SortSpec[] sortSpecs = buildSortSpecs(ctx.sort_specifier_list()); NamedExpr[] targets = new NamedExpr[sortSpecs.length];
@Override public boolean isEligible(PlanContext context, Expr expr) throws TajoException { Set<Relation> relations = ExprFinderIncludeSubquery.finds(expr, OpType.Relation); for (Relation eachRelation : relations) { TableDesc tableDesc = catalog.getTableDesc(getQualifiedName(context, eachRelation.getName())); if (tableDesc.hasEmptySchema()) { return true; } } return false; }
@Override public LogicalNode visitRelation(LogicalPlanner.PlanContext ctx, Stack<Expr> stack, Relation relation) throws TajoException { String actualRelationName; if (CatalogUtil.isFQTableName(relation.getName())) { actualRelationName = relation.getName(); } else { actualRelationName = CatalogUtil.buildFQName(ctx.getQueryContext().get(SessionVars.CURRENT_DATABASE), relation.getName()); } TableDesc desc = catalog.getTableDesc(actualRelationName); ScanNode scanNode = ctx.getPlan().createNode(ScanNode.class); if (relation.hasAlias()) { scanNode.init(desc, relation.getAlias()); } else { scanNode.init(desc); } TablePropertyUtil.setTableProperty(ctx.getQueryContext(), scanNode); ctx.getQueryBlock().addRelation(scanNode); return scanNode; }
private Expr generateOneExpr() { Expr expr = new BinaryOperator(OpType.LessThan, new LiteralValue("1", LiteralType.Unsigned_Integer), new LiteralValue("2", LiteralType.Unsigned_Integer)); Relation relation = new Relation("employee"); Selection selection = new Selection(expr); selection.setChild(relation); Aggregation aggregation = new Aggregation(); aggregation.setTargets(new NamedExpr[]{ new NamedExpr(new ColumnReferenceExpr("col1")) }); aggregation.setChild(selection); Sort.SortSpec spec = new Sort.SortSpec(new ColumnReferenceExpr("col2"), false, false); Sort sort = new Sort(new Sort.SortSpec[]{spec}); sort.setChild(aggregation); return sort; }