use of org.apache.asterix.om.base.AString in project asterixdb by apache.
the class PlanTranslationUtil method prepareMetaKeyAccessExpression.
public static void prepareMetaKeyAccessExpression(List<String> field, LogicalVariable resVar, List<Mutable<ILogicalExpression>> assignExpressions, List<LogicalVariable> vars, List<Mutable<ILogicalExpression>> varRefs, IVariableContext context) {
IAObject value = (field.size() > 1) ? new AOrderedList(field) : new AString(field.get(0));
ScalarFunctionCallExpression metaKeyFunction = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.META_KEY));
metaKeyFunction.getArguments().add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(resVar)));
metaKeyFunction.getArguments().add(new MutableObject<>(new ConstantExpression(new AsterixConstantValue(value))));
assignExpressions.add(new MutableObject<ILogicalExpression>(metaKeyFunction));
LogicalVariable v = context.newVar();
vars.add(v);
if (varRefs != null) {
varRefs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(v)));
}
}
use of org.apache.asterix.om.base.AString in project asterixdb by apache.
the class FieldAccessNestedResultType method getResultType.
@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
IAType firstArgType = strippedInputTypes[0];
if (firstArgType.getTypeTag() != ATypeTag.OBJECT) {
return BuiltinType.ANY;
}
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
ILogicalExpression arg1 = funcExpr.getArguments().get(1).getValue();
if (arg1.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
return BuiltinType.ANY;
}
ConstantExpression ce = (ConstantExpression) arg1;
IAObject v = ((AsterixConstantValue) ce.getValue()).getObject();
List<String> fieldPath = new ArrayList<>();
if (v.getType().getTypeTag() == ATypeTag.ARRAY) {
for (int i = 0; i < ((AOrderedList) v).size(); i++) {
fieldPath.add(((AString) ((AOrderedList) v).getItem(i)).getStringValue());
}
} else {
fieldPath.add(((AString) v).getStringValue());
}
ARecordType recType = (ARecordType) firstArgType;
IAType fieldType = recType.getSubFieldType(fieldPath);
return fieldType == null ? BuiltinType.ANY : fieldType;
}
use of org.apache.asterix.om.base.AString in project asterixdb by apache.
the class LangRecordParseUtil method parseRecord.
public static void parseRecord(RecordConstructor recordValue, ArrayBackedValueStorage serialized, boolean tagged, List<Pair<String, String>> defaults) throws HyracksDataException {
AMutableString fieldNameString = new AMutableString(null);
ArrayBackedValueStorage fieldName = new ArrayBackedValueStorage();
ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
RecordBuilder recordBuilder = new RecordBuilder();
recordBuilder.reset(RecordUtil.FULLY_OPEN_RECORD_TYPE);
recordBuilder.init();
List<FieldBinding> fbList = recordValue.getFbList();
HashSet<String> fieldNames = new HashSet<>();
for (FieldBinding fb : fbList) {
fieldName.reset();
fieldValue.reset();
// get key
fieldNameString.setValue(exprToStringLiteral(fb.getLeftExpr()).getStringValue());
if (!fieldNames.add(fieldNameString.getStringValue())) {
throw new HyracksDataException("Field " + fieldNameString.getStringValue() + " was specified multiple times");
}
stringSerde.serialize(fieldNameString, fieldName.getDataOutput());
// get value
parseExpression(fb.getRightExpr(), fieldValue);
recordBuilder.addField(fieldName, fieldValue);
}
// defaults
for (Pair<String, String> kv : defaults) {
if (!fieldNames.contains(kv.first)) {
fieldName.reset();
fieldValue.reset();
stringSerde.serialize(new AString(kv.first), fieldName.getDataOutput());
stringSerde.serialize(new AString(kv.second), fieldValue.getDataOutput());
recordBuilder.addField(fieldName, fieldValue);
}
}
recordBuilder.write(serialized.getDataOutput(), tagged);
}
use of org.apache.asterix.om.base.AString in project asterixdb by apache.
the class RecordRemoveFieldsTypeComputer method getListFromExpression.
private List<String> getListFromExpression(String funcName, ILogicalExpression expression) throws AlgebricksException {
AbstractFunctionCallExpression funcExp = (AbstractFunctionCallExpression) expression;
List<Mutable<ILogicalExpression>> args = funcExp.getArguments();
List<String> list = new ArrayList<>();
for (Mutable<ILogicalExpression> arg : args) {
// At this point all elements has to be a constant
// Input list has only one level of nesting (list of list or list of strings)
ConstantExpression ce = (ConstantExpression) arg.getValue();
if (!(ce.getValue() instanceof AsterixConstantValue)) {
throw new InvalidExpressionException(funcName, 1, ce, LogicalExpressionTag.CONSTANT);
}
IAObject item = ((AsterixConstantValue) ce.getValue()).getObject();
ATypeTag type = item.getType().getTypeTag();
if (type == ATypeTag.STRING) {
list.add(((AString) item).getStringValue());
} else {
throw new UnsupportedTypeException(funcName, type);
}
}
return list;
}
use of org.apache.asterix.om.base.AString in project asterixdb by apache.
the class SerializerDeserializerTestUtils method generateRecords.
public static ARecord[] generateRecords(ARecordType addrRecordType, ARecordType employeeType) {
AOrderedListType addrListType = new AOrderedListType(addrRecordType, "address_history");
ARecord addr11 = new ARecord(addrRecordType, new IAObject[] { new AString("120 San Raman Street"), new AString("Irvine"), new AString("CA"), new AInt16((short) 95051), new AInterval(0, 100, (byte) 0) });
ARecord addr12 = new ARecord(addrRecordType, new IAObject[] { new AString("210 University Drive"), new AString("Philadelphia"), new AString("PA"), new AInt16((short) 10086), new AInterval(100, 300, (byte) 0) });
ARecord addr21 = new ARecord(addrRecordType, new IAObject[] { new AString("1 College Street"), new AString("Seattle"), new AString("WA"), new AInt16((short) 20012), new AInterval(400, 500, (byte) 0) });
ARecord addr22 = new ARecord(addrRecordType, new IAObject[] { new AString("20 Lindsay Avenue"), new AString("Columbus"), new AString("OH"), new AInt16((short) 30120), new AInterval(600, 900, (byte) 0) });
ARecord addr31 = new ARecord(addrRecordType, new IAObject[] { new AString("200 14th Avenue"), new AString("Long Island"), new AString("NY"), new AInt16((short) 95011), new AInterval(12000, 14000, (byte) 0) });
// With nested open field addr31.
ARecord addr32 = new ARecord(addrRecordType, new IAObject[] { new AString("51 8th Street"), new AString("Orlando"), new AString("FL"), new AInt16((short) 49045), new AInterval(190000, 200000, (byte) 0) });
ARecord record1 = new ARecord(employeeType, new IAObject[] { new AInt64(0L), new AString("Tom"), new AOrderedList(addrListType, Arrays.asList(new IAObject[] { addr11, addr12 })) });
ARecord record2 = new ARecord(employeeType, new IAObject[] { new AInt64(1L), new AString("John"), new AOrderedList(addrListType, Arrays.asList(new IAObject[] { addr21, addr22 })) });
ARecord record3 = new ARecord(employeeType, new IAObject[] { new AInt64(2L), new AString("Lindsay"), new AOrderedList(addrListType, Arrays.asList(new IAObject[] { addr31, addr32 })) });
// With nested open field addr41.
ARecord record4 = new ARecord(employeeType, new IAObject[] { new AInt64(3L), new AString("Joshua"), new AOrderedList(addrListType, Arrays.asList(new IAObject[] {})) });
ARecord[] records = new ARecord[] { record1, record2, record3, record4 };
return records;
}
Aggregations