Search in sources :

Example 21 with AInt32

use of org.apache.asterix.om.base.AInt32 in project asterixdb by apache.

the class AddEquivalenceClassForRecordConstructorRule method propagateEquivalenceClassesForRecordConstructor.

@SuppressWarnings("unchecked")
private boolean propagateEquivalenceClassesForRecordConstructor(LogicalVariable recordVar, AbstractFunctionCallExpression funcExpr, AssignOperator assignOp, IOptimizationContext context) {
    List<Mutable<ILogicalExpression>> argRefs = funcExpr.getArguments();
    boolean changed = false;
    // Only odd position arguments are field value expressions.
    for (int parameterIndex = 1; parameterIndex < argRefs.size(); parameterIndex += 2) {
        ILogicalExpression fieldExpr = argRefs.get(parameterIndex).getValue();
        // Adds equivalent classes if a field is from a variable reference.
        if (fieldExpr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
            VariableReferenceExpression varExpr = (VariableReferenceExpression) fieldExpr;
            LogicalVariable fieldVar = varExpr.getVariableReference();
            Map<LogicalVariable, EquivalenceClass> ecs = context.getEquivalenceClassMap(assignOp);
            if (ecs == null) {
                ecs = new HashMap<LogicalVariable, EquivalenceClass>();
                context.putEquivalenceClassMap(assignOp, ecs);
            }
            ILogicalExpression expr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_INDEX), new MutableObject<ILogicalExpression>(new VariableReferenceExpression(recordVar)), new MutableObject<ILogicalExpression>(// Every two parameters corresponds to a field.
            new ConstantExpression(new AsterixConstantValue(new AInt32(parameterIndex / 2)))));
            EquivalenceClass equivClass = new EquivalenceClass(Collections.singletonList(fieldVar), fieldVar, Collections.singletonList(expr));
            ecs.put(fieldVar, equivClass);
            changed = true;
        }
    }
    return changed;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) AInt32(org.apache.asterix.om.base.AInt32) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) EquivalenceClass(org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Example 22 with AInt32

use of org.apache.asterix.om.base.AInt32 in project asterixdb by apache.

the class ByNameToByIndexFieldAccessRule method createFieldAccessByIndex.

@SuppressWarnings("unchecked")
private static ILogicalExpression createFieldAccessByIndex(ARecordType recType, AbstractFunctionCallExpression fce) {
    String s = ConstantExpressionUtil.getStringArgument(fce, 1);
    if (s == null) {
        return null;
    }
    int k = recType.getFieldIndex(s);
    if (k < 0) {
        return null;
    }
    return new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_INDEX), fce.getArguments().get(0), new MutableObject<>(new ConstantExpression(new AsterixConstantValue(new AInt32(k)))));
}
Also used : AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) AInt32(org.apache.asterix.om.base.AInt32) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Example 23 with AInt32

use of org.apache.asterix.om.base.AInt32 in project asterixdb by apache.

the class ExternalDatasetDetails method writeDatasetDetailsRecordType.

@SuppressWarnings("unchecked")
@Override
public void writeDatasetDetailsRecordType(DataOutput out) throws HyracksDataException {
    IARecordBuilder externalRecordBuilder = new RecordBuilder();
    OrderedListBuilder listBuilder = new OrderedListBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
    externalRecordBuilder.reset(MetadataRecordTypes.EXTERNAL_DETAILS_RECORDTYPE);
    AMutableString aString = new AMutableString("");
    ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
    ISerializerDeserializer<ADateTime> dateTimeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);
    ISerializerDeserializer<AInt32> intSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
    // write field 0
    fieldValue.reset();
    aString.setValue(this.getAdapter());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_DATASOURCE_ADAPTER_FIELD_INDEX, fieldValue);
    // write field 1
    listBuilder.reset((AOrderedListType) MetadataRecordTypes.EXTERNAL_DETAILS_RECORDTYPE.getFieldTypes()[1]);
    for (Map.Entry<String, String> property : this.properties.entrySet()) {
        String name = property.getKey();
        String value = property.getValue();
        itemValue.reset();
        DatasetUtil.writePropertyTypeRecord(name, value, itemValue.getDataOutput(), MetadataRecordTypes.DATASOURCE_ADAPTER_PROPERTIES_RECORDTYPE);
        listBuilder.addItem(itemValue);
    }
    fieldValue.reset();
    listBuilder.write(fieldValue.getDataOutput(), true);
    externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_PROPERTIES_FIELD_INDEX, fieldValue);
    // write field 2
    fieldValue.reset();
    dateTimeSerde.serialize(new ADateTime(lastRefreshTime.getTime()), fieldValue.getDataOutput());
    externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_LAST_REFRESH_TIME_FIELD_INDEX, fieldValue);
    // write field 3
    fieldValue.reset();
    intSerde.serialize(new AInt32(state.ordinal()), fieldValue.getDataOutput());
    externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_TRANSACTION_STATE_FIELD_INDEX, fieldValue);
    externalRecordBuilder.write(out, true);
}
Also used : OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) RecordBuilder(org.apache.asterix.builders.RecordBuilder) AMutableString(org.apache.asterix.om.base.AMutableString) ADateTime(org.apache.asterix.om.base.ADateTime) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) AInt32(org.apache.asterix.om.base.AInt32) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) AString(org.apache.asterix.om.base.AString) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with AInt32

use of org.apache.asterix.om.base.AInt32 in project asterixdb by apache.

the class NonTaggedDataFormat method getFieldAccessEvaluatorFactory.

@SuppressWarnings("unchecked")
@Override
public IScalarEvaluatorFactory getFieldAccessEvaluatorFactory(ARecordType recType, List<String> fldName, int recordColumn) throws AlgebricksException {
    String[] names = recType.getFieldNames();
    int n = names.length;
    boolean fieldFound = false;
    IScalarEvaluatorFactory recordEvalFactory = new ColumnAccessEvalFactory(recordColumn);
    ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
    DataOutput dos = abvs.getDataOutput();
    IScalarEvaluatorFactory evalFactory = null;
    if (fldName.size() == 1) {
        for (int i = 0; i < n; i++) {
            if (names[i].equals(fldName.get(0))) {
                fieldFound = true;
                try {
                    AInt32 ai = new AInt32(i);
                    SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(ai.getType()).serialize(ai, dos);
                } catch (HyracksDataException e) {
                    throw new AlgebricksException(e);
                }
                IScalarEvaluatorFactory fldIndexEvalFactory = new ConstantEvalFactory(Arrays.copyOf(abvs.getByteArray(), abvs.getLength()));
                evalFactory = new FieldAccessByIndexEvalFactory(recordEvalFactory, fldIndexEvalFactory, recType);
                return evalFactory;
            }
        }
    }
    if (fldName.size() > 1 || (!fieldFound && recType.isOpen())) {
        if (fldName.size() == 1) {
            AString as = new AString(fldName.get(0));
            try {
                SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(as.getType()).serialize(as, dos);
            } catch (HyracksDataException e) {
                throw new AlgebricksException(e);
            }
        } else {
            AOrderedList as = new AOrderedList(fldName);
            try {
                SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(as.getType()).serialize(as, dos);
            } catch (HyracksDataException e) {
                throw new AlgebricksException(e);
            }
        }
        IScalarEvaluatorFactory[] factories = new IScalarEvaluatorFactory[2];
        factories[0] = recordEvalFactory;
        if (fldName.size() > 1) {
            evalFactory = new FieldAccessNestedEvalFactory(recordEvalFactory, recType, fldName);
        } else {
            evalFactory = FieldAccessByNameDescriptor.FACTORY.createFunctionDescriptor().createEvaluatorFactory(factories);
        }
        return evalFactory;
    } else {
        throw new AlgebricksException("Could not find field " + fldName + " in the schema.");
    }
}
Also used : DataOutput(java.io.DataOutput) ConstantEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) AString(org.apache.asterix.om.base.AString) AInt32(org.apache.asterix.om.base.AInt32) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AOrderedList(org.apache.asterix.om.base.AOrderedList) ColumnAccessEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ColumnAccessEvalFactory) FieldAccessByIndexEvalFactory(org.apache.asterix.runtime.evaluators.functions.records.FieldAccessByIndexEvalFactory) AString(org.apache.asterix.om.base.AString) FieldAccessNestedEvalFactory(org.apache.asterix.runtime.evaluators.functions.records.FieldAccessNestedEvalFactory)

Aggregations

AInt32 (org.apache.asterix.om.base.AInt32)24 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)15 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)14 AString (org.apache.asterix.om.base.AString)13 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)13 ArrayList (java.util.ArrayList)11 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)10 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)10 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)10 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)9 Mutable (org.apache.commons.lang3.mutable.Mutable)8 List (java.util.List)7 AOrderedList (org.apache.asterix.om.base.AOrderedList)6 MutableObject (org.apache.commons.lang3.mutable.MutableObject)6 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)6 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)6 Dataset (org.apache.asterix.metadata.entities.Dataset)5 IAObject (org.apache.asterix.om.base.IAObject)5 ARecordType (org.apache.asterix.om.types.ARecordType)5 IAType (org.apache.asterix.om.types.IAType)5