Search in sources :

Example 1 with ITypeTraitProvider

use of org.apache.hyracks.algebricks.data.ITypeTraitProvider in project asterixdb by apache.

the class RTreeResourceFactoryProvider method getTypeTraits.

private static ITypeTraits[] getTypeTraits(MetadataProvider metadataProvider, Dataset dataset, Index index, ARecordType recordType, ARecordType metaType) throws AlgebricksException {
    ITypeTraitProvider ttProvider = metadataProvider.getStorageComponentProvider().getTypeTraitProvider();
    List<List<String>> secondaryKeyFields = index.getKeyFieldNames();
    int numSecondaryKeys = secondaryKeyFields.size();
    int numPrimaryKeys = dataset.getPrimaryKeys().size();
    ITypeTraits[] primaryTypeTraits = dataset.getPrimaryTypeTraits(metadataProvider, recordType, metaType);
    if (numSecondaryKeys != 1) {
        throw new AsterixException("Cannot use " + numSecondaryKeys + " fields as a key for the R-tree index. " + "There can be only one field as a key for the R-tree index.");
    }
    ARecordType sourceType;
    List<Integer> keySourceIndicators = index.getKeyFieldSourceIndicators();
    if (keySourceIndicators == null || keySourceIndicators.get(0) == 0) {
        sourceType = recordType;
    } else {
        sourceType = metaType;
    }
    Pair<IAType, Boolean> spatialTypePair = Index.getNonNullableOpenFieldType(index.getKeyFieldTypes().get(0), secondaryKeyFields.get(0), sourceType);
    IAType spatialType = spatialTypePair.first;
    if (spatialType == null) {
        throw new AsterixException("Could not find field " + secondaryKeyFields.get(0) + " in the schema.");
    }
    int numDimensions = NonTaggedFormatUtil.getNumDimensions(spatialType.getTypeTag());
    int numNestedSecondaryKeyFields = numDimensions * 2;
    ITypeTraits[] secondaryTypeTraits = new ITypeTraits[numNestedSecondaryKeyFields + numPrimaryKeys];
    IAType nestedKeyType = NonTaggedFormatUtil.getNestedSpatialType(spatialType.getTypeTag());
    for (int i = 0; i < numNestedSecondaryKeyFields; i++) {
        secondaryTypeTraits[i] = ttProvider.getTypeTrait(nestedKeyType);
    }
    for (int i = 0; i < numPrimaryKeys; i++) {
        secondaryTypeTraits[numNestedSecondaryKeyFields + i] = primaryTypeTraits[i];
    }
    return secondaryTypeTraits;
}
Also used : ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) AsterixException(org.apache.asterix.common.exceptions.AsterixException) ITypeTraitProvider(org.apache.hyracks.algebricks.data.ITypeTraitProvider) List(java.util.List) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType)

Example 2 with ITypeTraitProvider

use of org.apache.hyracks.algebricks.data.ITypeTraitProvider in project asterixdb by apache.

the class Dataset method getPrimaryTypeTraits.

public ITypeTraits[] getPrimaryTypeTraits(MetadataProvider metadataProvider, ARecordType recordType, ARecordType metaType) throws AlgebricksException {
    IStorageComponentProvider storageComponentProvider = metadataProvider.getStorageComponentProvider();
    ITypeTraitProvider ttProvider = storageComponentProvider.getTypeTraitProvider();
    List<List<String>> partitioningKeys = getPrimaryKeys();
    int numPrimaryKeys = partitioningKeys.size();
    ITypeTraits[] typeTraits = new ITypeTraits[numPrimaryKeys + 1 + (hasMetaPart() ? 1 : 0)];
    List<Integer> indicators = null;
    if (hasMetaPart()) {
        indicators = ((InternalDatasetDetails) getDatasetDetails()).getKeySourceIndicator();
    }
    for (int i = 0; i < numPrimaryKeys; i++) {
        IAType keyType = datasetType == DatasetType.EXTERNAL ? IndexingConstants.getFieldType(i) : (indicators == null || indicators.get(i) == 0) ? recordType.getSubFieldType(partitioningKeys.get(i)) : metaType.getSubFieldType(partitioningKeys.get(i));
        typeTraits[i] = ttProvider.getTypeTrait(keyType);
    }
    typeTraits[numPrimaryKeys] = ttProvider.getTypeTrait(recordType);
    if (hasMetaPart()) {
        typeTraits[numPrimaryKeys + 1] = ttProvider.getTypeTrait(metaType);
    }
    return typeTraits;
}
Also used : IStorageComponentProvider(org.apache.asterix.common.context.IStorageComponentProvider) ITypeTraitProvider(org.apache.hyracks.algebricks.data.ITypeTraitProvider) ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) List(java.util.List) IAType(org.apache.asterix.om.types.IAType)

Example 3 with ITypeTraitProvider

use of org.apache.hyracks.algebricks.data.ITypeTraitProvider in project asterixdb by apache.

the class JobGenHelper method variablesToTypeTraits.

public static ITypeTraits[] variablesToTypeTraits(List<LogicalVariable> varLogical, int start, int size, IVariableTypeEnvironment env, JobGenContext context) throws AlgebricksException {
    ITypeTraits[] typeTraits = new ITypeTraits[size];
    ITypeTraitProvider typeTraitProvider = context.getTypeTraitProvider();
    for (int i = 0; i < size; i++) {
        Object type = env.getVarType(varLogical.get(start + i));
        typeTraits[i] = typeTraitProvider.getTypeTrait(type);
    }
    return typeTraits;
}
Also used : ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) ITypeTraitProvider(org.apache.hyracks.algebricks.data.ITypeTraitProvider)

Example 4 with ITypeTraitProvider

use of org.apache.hyracks.algebricks.data.ITypeTraitProvider in project asterixdb by apache.

the class JobGenHelper method mkRecordDescriptor.

@SuppressWarnings("rawtypes")
public static RecordDescriptor mkRecordDescriptor(IVariableTypeEnvironment env, IOperatorSchema opSchema, JobGenContext context) throws AlgebricksException {
    ISerializerDeserializer[] fields = new ISerializerDeserializer[opSchema.getSize()];
    ITypeTraits[] typeTraits = new ITypeTraits[opSchema.getSize()];
    ISerializerDeserializerProvider sdp = context.getSerializerDeserializerProvider();
    ITypeTraitProvider ttp = context.getTypeTraitProvider();
    int i = 0;
    for (LogicalVariable var : opSchema) {
        Object t = env.getVarType(var);
        if (t == null) {
            LOGGER.warning("No type for variable " + var);
        }
        fields[i] = sdp.getSerializerDeserializer(t);
        typeTraits[i] = ttp.getTypeTrait(t);
        i++;
    }
    return new RecordDescriptor(fields, typeTraits);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) ITypeTraitProvider(org.apache.hyracks.algebricks.data.ITypeTraitProvider) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) ISerializerDeserializerProvider(org.apache.hyracks.algebricks.data.ISerializerDeserializerProvider) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)

Example 5 with ITypeTraitProvider

use of org.apache.hyracks.algebricks.data.ITypeTraitProvider in project asterixdb by apache.

the class JobGenHelper method variablesToTypeTraits.

public static ITypeTraits[] variablesToTypeTraits(Collection<LogicalVariable> varLogical, IVariableTypeEnvironment env, JobGenContext context) throws AlgebricksException {
    ITypeTraits[] typeTraits = new ITypeTraits[varLogical.size()];
    ITypeTraitProvider typeTraitProvider = context.getTypeTraitProvider();
    int i = 0;
    for (LogicalVariable v : varLogical) {
        Object type = env.getVarType(v);
        typeTraits[i++] = typeTraitProvider.getTypeTrait(type);
    }
    return typeTraits;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) ITypeTraitProvider(org.apache.hyracks.algebricks.data.ITypeTraitProvider)

Aggregations

ITypeTraitProvider (org.apache.hyracks.algebricks.data.ITypeTraitProvider)8 ITypeTraits (org.apache.hyracks.api.dataflow.value.ITypeTraits)8 IAType (org.apache.asterix.om.types.IAType)5 ARecordType (org.apache.asterix.om.types.ARecordType)3 ISerializerDeserializerProvider (org.apache.hyracks.algebricks.data.ISerializerDeserializerProvider)3 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)3 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)3 List (java.util.List)2 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)2 IndexType (org.apache.asterix.common.config.DatasetConfig.IndexType)1 IStorageComponentProvider (org.apache.asterix.common.context.IStorageComponentProvider)1 AsterixException (org.apache.asterix.common.exceptions.AsterixException)1 CompilationException (org.apache.asterix.common.exceptions.CompilationException)1 IBinaryComparatorFactoryProvider (org.apache.hyracks.algebricks.data.IBinaryComparatorFactoryProvider)1