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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations