Search in sources :

Example 11 with LogicalVariable

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.

the class AlgebricksOptimizationContext method updatePrimaryKeys.

@Override
public void updatePrimaryKeys(Map<LogicalVariable, LogicalVariable> mappedVars) {
    for (Map.Entry<LogicalVariable, FunctionalDependency> me : varToPrimaryKey.entrySet()) {
        FunctionalDependency fd = me.getValue();
        List<LogicalVariable> hd = new ArrayList<>();
        for (LogicalVariable v : fd.getHead()) {
            LogicalVariable v2 = mappedVars.get(v);
            if (v2 == null) {
                hd.add(v);
            } else {
                hd.add(v2);
            }
        }
        List<LogicalVariable> tl = new ArrayList<>();
        for (LogicalVariable v : fd.getTail()) {
            LogicalVariable v2 = mappedVars.get(v);
            if (v2 == null) {
                tl.add(v);
            } else {
                tl.add(v2);
            }
        }
        me.setValue(new FunctionalDependency(hd, tl));
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) FunctionalDependency(org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with LogicalVariable

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.

the class PigletCompiler method translate.

private ILogicalPlan translate(List<ASTNode> ast) throws PigletException {
    Map<String, Relation> symMap = new HashMap<String, Relation>();
    List<Mutable<ILogicalOperator>> roots = new ArrayList<Mutable<ILogicalOperator>>();
    previousOp = null;
    for (ASTNode an : ast) {
        switch(an.getTag()) {
            case DUMP:
                {
                    DumpNode dn = (DumpNode) an;
                    Relation input = symMap.get(dn.getAlias());
                    List<Mutable<ILogicalExpression>> expressions = new ArrayList<Mutable<ILogicalExpression>>();
                    for (LogicalVariable v : input.schema.values()) {
                        expressions.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(v)));
                    }
                    PigletFileDataSink dataSink = new PigletFileDataSink(dn.getFile());
                    ILogicalOperator op = new WriteOperator(expressions, dataSink);
                    op.getInputs().add(new MutableObject<ILogicalOperator>(input.op));
                    roots.add(new MutableObject<ILogicalOperator>(op));
                }
                break;
            case ASSIGNMENT:
                {
                    AssignmentNode asn = (AssignmentNode) an;
                    String alias = asn.getAlias();
                    RelationNode rn = asn.getRelation();
                    Relation rel = translate(rn, symMap);
                    previousOp = rel.op;
                    rel.alias = alias;
                    symMap.put(alias, rel);
                }
                break;
        }
    }
    return new ALogicalPlanImpl(roots);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) RelationNode(org.apache.hyracks.algebricks.examples.piglet.ast.RelationNode) AssignmentNode(org.apache.hyracks.algebricks.examples.piglet.ast.AssignmentNode) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) DumpNode(org.apache.hyracks.algebricks.examples.piglet.ast.DumpNode) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ALogicalPlanImpl(org.apache.hyracks.algebricks.core.algebra.plan.ALogicalPlanImpl) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ASTNode(org.apache.hyracks.algebricks.examples.piglet.ast.ASTNode) WriteOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.WriteOperator) List(java.util.List) ArrayList(java.util.ArrayList) PigletFileDataSink(org.apache.hyracks.algebricks.examples.piglet.metadata.PigletFileDataSink) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 13 with LogicalVariable

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.

the class JobGenHelper method projectAllVariables.

public static int[] projectAllVariables(IOperatorSchema opSchema) {
    int[] projectionList = new int[opSchema.getSize()];
    int k = 0;
    for (LogicalVariable v : opSchema) {
        projectionList[k++] = opSchema.findVariable(v);
    }
    return projectionList;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)

Example 14 with LogicalVariable

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.

the class JobGenHelper method mkPrinterFactories.

public static IPrinterFactory[] mkPrinterFactories(IOperatorSchema opSchema, IVariableTypeEnvironment env, JobGenContext context, int[] printColumns) throws AlgebricksException {
    IPrinterFactory[] pf = new IPrinterFactory[printColumns.length];
    IPrinterFactoryProvider pff = context.getPrinterFactoryProvider();
    try {
        for (int i = 0; i < pf.length; i++) {
            LogicalVariable v = opSchema.getVariable(printColumns[i]);
            Object t = env.getVarType(v);
            pf[i] = pff.getPrinterFactory(t);
        }
        return pf;
    } catch (HyracksDataException e) {
        throw new AlgebricksException(e);
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) IPrinterFactory(org.apache.hyracks.algebricks.data.IPrinterFactory) IPrinterFactoryProvider(org.apache.hyracks.algebricks.data.IPrinterFactoryProvider) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 15 with LogicalVariable

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.

the class JobGenHelper method variablesToAscBinaryComparatorFactories.

public static IBinaryComparatorFactory[] variablesToAscBinaryComparatorFactories(Collection<LogicalVariable> varLogical, IVariableTypeEnvironment env, JobGenContext context) throws AlgebricksException {
    IBinaryComparatorFactory[] compFactories = new IBinaryComparatorFactory[varLogical.size()];
    IBinaryComparatorFactoryProvider bcfProvider = context.getBinaryComparatorFactoryProvider();
    int i = 0;
    for (LogicalVariable v : varLogical) {
        Object type = env.getVarType(v);
        compFactories[i++] = bcfProvider.getBinaryComparatorFactory(type, true);
    }
    return compFactories;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) IBinaryComparatorFactory(org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory) IBinaryComparatorFactoryProvider(org.apache.hyracks.algebricks.data.IBinaryComparatorFactoryProvider)

Aggregations

LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)376 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)196 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)182 ArrayList (java.util.ArrayList)171 Mutable (org.apache.commons.lang3.mutable.Mutable)136 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)127 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)92 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)79 Pair (org.apache.hyracks.algebricks.common.utils.Pair)75 HashSet (java.util.HashSet)60 MutableObject (org.apache.commons.lang3.mutable.MutableObject)60 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)60 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)54 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)46 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)36 GroupByOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator)33 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)32 AggregateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator)28 FunctionalDependency (org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency)28 IAType (org.apache.asterix.om.types.IAType)27