use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class LangRecordParseUtil method aOrderedListToString.
private static String aOrderedListToString(AOrderedList ol) throws AlgebricksException {
StringBuilder delimitedList = new StringBuilder();
IACursor cursor = ol.getCursor();
if (cursor.next()) {
IAObject next = cursor.get();
delimitedList.append(aObjToString(next));
}
while (cursor.next()) {
IAObject next = cursor.get();
delimitedList.append(",");
delimitedList.append(aObjToString(next));
}
return delimitedList.toString();
}
use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class PlanTranslationUtil method createFieldAccessExpression.
private static ScalarFunctionCallExpression createFieldAccessExpression(ILogicalExpression target, List<String> field) {
FunctionIdentifier functionIdentifier;
IAObject value;
if (field.size() > 1) {
functionIdentifier = BuiltinFunctions.FIELD_ACCESS_NESTED;
value = new AOrderedList(field);
} else {
functionIdentifier = BuiltinFunctions.FIELD_ACCESS_BY_NAME;
value = new AString(field.get(0));
}
IFunctionInfo finfoAccess = FunctionUtil.getFunctionInfo(functionIdentifier);
return new ScalarFunctionCallExpression(finfoAccess, new MutableObject<>(target), new MutableObject<>(new ConstantExpression(new AsterixConstantValue(value))));
}
use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class IDataParser method writeRecord.
/*
* The following two static methods are expensive. right now, they are used by RSSFeeds and
* Twitter feed
* TODO: Get rid of them
*/
public static void writeRecord(AMutableRecord record, DataOutput dataOutput, IARecordBuilder recordBuilder) throws HyracksDataException {
ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
int numFields = record.getType().getFieldNames().length;
for (int pos = 0; pos < numFields; pos++) {
fieldValue.reset();
IAObject obj = record.getValueByPos(pos);
IDataParser.writeObject(obj, fieldValue.getDataOutput());
recordBuilder.addField(pos, fieldValue);
}
recordBuilder.write(dataOutput, true);
}
use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class NonTaggedDataFormat method getConstantEvalFactory.
@SuppressWarnings("unchecked")
@Override
public IScalarEvaluatorFactory getConstantEvalFactory(IAlgebricksConstantValue value) throws AlgebricksException {
IAObject obj = null;
if (value.isMissing()) {
obj = AMissing.MISSING;
} else if (value.isTrue()) {
obj = ABoolean.TRUE;
} else if (value.isFalse()) {
obj = ABoolean.FALSE;
} else {
AsterixConstantValue acv = (AsterixConstantValue) value;
obj = acv.getObject();
}
ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
DataOutput dos = abvs.getDataOutput();
try {
SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(obj.getType()).serialize(obj, dos);
} catch (HyracksDataException e) {
throw new AlgebricksException(e);
}
return new ConstantEvalFactory(Arrays.copyOf(abvs.getByteArray(), abvs.getLength()));
}
use of org.apache.asterix.om.base.IAObject in project asterixdb by apache.
the class InvertedIndexAccessMethod method isEditDistanceFuncSelectOptimizable.
private boolean isEditDistanceFuncSelectOptimizable(Index index, IOptimizableFuncExpr optFuncExpr) throws AlgebricksException {
// Check for panic in selection query.
// TODO: Panic also depends on prePost which is currently hardcoded to be true.
AsterixConstantValue listOrStrConstVal = (AsterixConstantValue) ((ConstantExpression) optFuncExpr.getConstantExpr(0)).getValue();
IAObject listOrStrObj = listOrStrConstVal.getObject();
ATypeTag typeTag = listOrStrObj.getType().getTypeTag();
if (!isEditDistanceFuncCompatible(typeTag, index.getIndexType())) {
return false;
}
AsterixConstantValue intConstVal = (AsterixConstantValue) ((ConstantExpression) optFuncExpr.getConstantExpr(1)).getValue();
IAObject intObj = intConstVal.getObject();
AInt32 edThresh = null;
// Apply type casting based on numeric types of the input to INTEGER type.
try {
edThresh = (AInt32) ATypeHierarchy.convertNumericTypeObject(intObj, ATypeTag.INTEGER);
} catch (HyracksDataException e) {
throw new AlgebricksException(e);
}
int mergeThreshold = 0;
if (typeTag == ATypeTag.STRING) {
AString astr = (AString) listOrStrObj;
// Compute merge threshold depending on the query grams contain pre- and postfixing
if (optFuncExpr.containsPartialField()) {
mergeThreshold = (astr.getStringValue().length() - index.getGramLength() + 1) - edThresh.getIntegerValue() * index.getGramLength();
} else {
mergeThreshold = (astr.getStringValue().length() + index.getGramLength() - 1) - edThresh.getIntegerValue() * index.getGramLength();
}
}
if ((typeTag == ATypeTag.ARRAY) && (index.getIndexType() == IndexType.SINGLE_PARTITION_WORD_INVIX || index.getIndexType() == IndexType.LENGTH_PARTITIONED_WORD_INVIX)) {
IACollection alist = (IACollection) listOrStrObj;
// Compute merge threshold.
mergeThreshold = alist.size() - edThresh.getIntegerValue();
}
if (mergeThreshold <= 0) {
// We cannot use index to optimize expr.
return false;
}
return true;
}
Aggregations