PlanContext leftContext = new PlanContext(context, leftBlock); stack.push(setOperation); LogicalNode leftChild = visit(leftContext, new Stack<>(), setOperation.getLeft()); PlanContext rightContext = new PlanContext(context, rightBlock); stack.push(setOperation); LogicalNode rightChild = visit(rightContext, new Stack<>(), setOperation.getRight());
throws TajoException { RelationNode relationOp = null; QueryBlock block = ctx.getQueryBlock(); Collection<QueryBlock> queryBlocks = ctx.getPlan().getQueryBlocks(); if (asteriskExpr.hasQualifier()) { String qualifier; } else { qualifier = IdentifierUtil.buildFQName( ctx.getQueryContext().get(SessionVars.CURRENT_DATABASE), asteriskExpr.getQualifier());
if (context.getQueryBlock().isConstReference(refName)) { continue; } else if (block.namedExprsMgr.isEvaluated(refName)) {
CatalogUtil.newDefaultProperty(createTableNode.getStorageType(), context.getQueryContext().getConf()));
CatalogUtil.newDefaultProperty(createTableNode.getStorageType(), context.getQueryContext().getConf()));
for (int i = 0; i < groupingKeyRefNames.length; i++) { String refName = groupingKeyRefNames[i]; if (context.getQueryBlock().isConstReference(refName)) { continue; } else if (block.namedExprsMgr.isEvaluated(groupingKeyRefNames[i])) {
throws TajoException { RelationNode relationOp = null; QueryBlock block = ctx.getQueryBlock(); Collection<QueryBlock> queryBlocks = ctx.getPlan().getQueryBlocks(); if (asteriskExpr.hasQualifier()) { String qualifier; } else { qualifier = CatalogUtil.buildFQName( ctx.getQueryContext().get(SessionVars.CURRENT_DATABASE), asteriskExpr.getQualifier());
context.generateUniqueSubQueryName()), setOperationNode); setTargetOfTableSubQuery(context, currentBlock, setOpTableSubQueryNode); currentBlock.registerNode(setOpTableSubQueryNode);
PlanContext leftContext = new PlanContext(context, leftBlock); stack.push(setOperation); LogicalNode leftChild = visit(leftContext, new Stack<Expr>(), setOperation.getLeft()); PlanContext rightContext = new PlanContext(context, rightBlock); stack.push(setOperation); LogicalNode rightChild = visit(rightContext, new Stack<Expr>(), setOperation.getRight());
EvalExprNode exprNode = ctx.getPlan().createNode(EvalExprNode.class); exprNode.setTargets(buildTargets(ctx, expr.getNamedExprs())); return exprNode; ctx.getQueryBlock().addColumnAlias(((ColumnReferenceExpr)namedExpr.getExpr()).getCanonicalName(), namedExpr.getAlias()); } else if (OpType.isLiteralType(namedExpr.getExpr().getType()) && namedExpr.hasAlias()) { Expr constExpr = namedExpr.getExpr(); ConstEval constEval = (ConstEval) annotator.createEvalNode(ctx, constExpr, NameResolvingMode.RELS_ONLY, true); ctx.getQueryBlock().addConstReference(namedExpr.getAlias(), constExpr, constEval); ProjectionNode projectionNode = ctx.getPlan().createNode(ProjectionNode.class); projectionNode.setInSchema(child.getOutSchema()); projectionNode.setOutSchema(PlannerUtil.targetToSchema(targets)); ctx.getQueryBlock().setSchema(projectionNode.getOutSchema()); return projectionNode;
EvalExprNode exprNode = ctx.getPlan().createNode(EvalExprNode.class); exprNode.setTargets(buildTargets(ctx, expr.getNamedExprs())); return exprNode; ctx.getQueryBlock().addColumnAlias(((ColumnReferenceExpr)namedExpr.getExpr()).getCanonicalName(), namedExpr.getAlias()); } else if (OpType.isLiteralType(namedExpr.getExpr().getType()) && namedExpr.hasAlias()) { Expr constExpr = namedExpr.getExpr(); ConstEval constEval = (ConstEval) annotator.createEvalNode(ctx, constExpr, NameResolvingMode.RELS_ONLY, true); ctx.getQueryBlock().addConstReference(namedExpr.getAlias(), constExpr, constEval); ProjectionNode projectionNode = ctx.getPlan().createNode(ProjectionNode.class); projectionNode.setInSchema(child.getOutSchema()); projectionNode.setOutSchema(PlannerUtil.targetToSchema(targets)); ctx.getQueryBlock().setSchema(projectionNode.getOutSchema()); return projectionNode;
context.generateUniqueSubQueryName()), setOperationNode); setTargetOfTableSubQuery(context, currentBlock, setOpTableSubQueryNode); currentBlock.registerNode(setOpTableSubQueryNode);
EvalContext evalContext = new EvalContext(); String timezoneId = context.getQueryContext().get(SessionVars.TIMEZONE); evalContext.setTimeZone(TimeZone.getTimeZone(timezoneId)); TajoScriptEngine executor = new PythonScriptEngine(evalNode.getFuncDesc()); try { executor.start(context.getQueryContext().getConf()); evalContext.addScriptEngine(evalNode, executor); evalNode.bind(evalContext, null);
EvalContext evalContext = new EvalContext(); String timezoneId = context.getQueryContext().get(SessionVars.TIMEZONE); evalContext.setTimeZone(TimeZone.getTimeZone(timezoneId)); TajoScriptEngine executor = new PythonScriptEngine(evalNode.getFuncDesc()); try { executor.start(context.getQueryContext().getConf()); evalContext.addScriptEngine(evalNode, executor); evalNode.bind(evalContext, null);
targetUri = URI.create(context.getQueryContext().get(QueryVars.DEFAULT_SPACE_ROOT_URI) + "/" + targetUri);
targetUri = URI.create(context.getQueryContext().get(QueryVars.DEFAULT_SPACE_ROOT_URI) + "/" + targetUri);
public List<Integer> normalize(PlanContext context, Projection projection, ExprNormalizedResult [] normalizedExprList, Matcher matcher) throws TajoException { List<Integer> targetIds = new ArrayList<>(); for (int i = 0; i < projection.size(); i++) { NamedExpr namedExpr = projection.getNamedExprs().get(i); if (PlannerUtil.existsAggregationFunction(namedExpr)) { context.queryBlock.setAggregationRequire(); } if (matcher.isMatch(namedExpr.getExpr())) { // If a value is constant value, it adds the constant value with a proper name to the constant map // of the current block if (!namedExpr.hasAlias() && OpType.isLiteralType(namedExpr.getExpr().getType())) { String generatedName = context.plan.generateUniqueColumnName(namedExpr.getExpr()); ConstEval constEval = (ConstEval) exprAnnotator.createEvalNode(context, namedExpr.getExpr(), NameResolvingMode.RELS_ONLY); context.getQueryBlock().addConstReference(generatedName, namedExpr.getExpr(), constEval); normalizedExprList[i] = new ExprNormalizedResult(context, false); normalizedExprList[i].baseExpr = new ColumnReferenceExpr(generatedName); } else { // dissect an expression into multiple parts (at most dissected into three parts) normalizedExprList[i] = normalizer.normalize(context, namedExpr.getExpr()); } targetIds.add(i); } } return targetIds; }
@Override public LogicalNode visitGroupBy(LogicalPlanner.PlanContext ctx, Stack<Expr> stack, Aggregation expr) throws TajoException { stack.push(expr); // <--- push LogicalNode child = visit(ctx, stack, expr.getChild()); Projection projection = ctx.getQueryBlock().getSingletonExpr(OpType.Projection); int finalTargetNum = projection.getNamedExprs().length; Target [] targets = new Target[finalTargetNum]; if (PlannerUtil.hasAsterisk(projection.getNamedExprs())) { projection.setNamedExprs(voidResolveAsteriskNamedExpr(ctx, projection.getNamedExprs())); } for (int i = 0; i < finalTargetNum; i++) { NamedExpr namedExpr = projection.getNamedExprs()[i]; EvalNode evalNode = annotator.createEvalNode(ctx, namedExpr.getExpr(), NameResolvingMode.SUBEXPRS_AND_RELS, true); if (namedExpr.hasAlias()) { targets[i] = new Target(evalNode, namedExpr.getAlias()); } else { targets[i] = new Target(evalNode, "?name_" + i); } } stack.pop(); GroupbyNode groupByNode = ctx.getPlan().createNode(GroupbyNode.class); groupByNode.setInSchema(child.getOutSchema()); groupByNode.setOutSchema(PlannerUtil.targetToSchema(targets)); return groupByNode; }
public List<Integer> normalize(PlanContext context, Projection projection, ExprNormalizedResult [] normalizedExprList, Matcher matcher) throws TajoException { List<Integer> targetIds = new ArrayList<Integer>(); for (int i = 0; i < projection.size(); i++) { NamedExpr namedExpr = projection.getNamedExprs()[i]; if (PlannerUtil.existsAggregationFunction(namedExpr)) { context.queryBlock.setAggregationRequire(); } if (matcher.isMatch(namedExpr.getExpr())) { // If a value is constant value, it adds the constant value with a proper name to the constant map // of the current block if (!namedExpr.hasAlias() && OpType.isLiteralType(namedExpr.getExpr().getType())) { String generatedName = context.plan.generateUniqueColumnName(namedExpr.getExpr()); ConstEval constEval = (ConstEval) exprAnnotator.createEvalNode(context, namedExpr.getExpr(), NameResolvingMode.RELS_ONLY); context.getQueryBlock().addConstReference(generatedName, namedExpr.getExpr(), constEval); normalizedExprList[i] = new ExprNormalizedResult(context, false); normalizedExprList[i].baseExpr = new ColumnReferenceExpr(generatedName); } else { // dissect an expression into multiple parts (at most dissected into three parts) normalizedExprList[i] = normalizer.normalize(context, namedExpr.getExpr()); } targetIds.add(i); } } return targetIds; }
@Override public LogicalNode visitGroupBy(LogicalPlanner.PlanContext ctx, Stack<Expr> stack, Aggregation expr) throws TajoException { stack.push(expr); // <--- push LogicalNode child = visit(ctx, stack, expr.getChild()); Projection projection = ctx.getQueryBlock().getSingletonExpr(OpType.Projection); int finalTargetNum = projection.getNamedExprs().size(); List<Target> targets = new ArrayList<>(); if (PlannerUtil.hasAsterisk(projection.getNamedExprs())) { projection.setNamedExprs(voidResolveAsteriskNamedExpr(ctx, projection.getNamedExprs())); } for (int i = 0; i < finalTargetNum; i++) { NamedExpr namedExpr = projection.getNamedExprs().get(i); EvalNode evalNode = annotator.createEvalNode(ctx, namedExpr.getExpr(), NameResolvingMode.SUBEXPRS_AND_RELS, true); if (namedExpr.hasAlias()) { targets.add(new Target(evalNode, namedExpr.getAlias())); } else { targets.add(new Target(evalNode, "?name_" + i)); } } stack.pop(); GroupbyNode groupByNode = ctx.getPlan().createNode(GroupbyNode.class); groupByNode.setInSchema(child.getOutSchema()); groupByNode.setOutSchema(PlannerUtil.targetToSchema(targets)); return groupByNode; }