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