use of org.apache.asterix.om.base.AInt64 in project asterixdb by apache.
the class CountVarToCountOneRule method rewritePost.
// It is only for a group-by having just one aggregate which is a count.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
if (op1.getOperatorTag() != LogicalOperatorTag.GROUP) {
return false;
}
GroupByOperator g = (GroupByOperator) op1;
if (g.getNestedPlans().size() != 1) {
return false;
}
ILogicalPlan p = g.getNestedPlans().get(0);
if (p.getRoots().size() != 1) {
return false;
}
AbstractLogicalOperator op2 = (AbstractLogicalOperator) p.getRoots().get(0).getValue();
if (op2.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
return false;
}
AggregateOperator agg = (AggregateOperator) op2;
if (agg.getExpressions().size() != 1) {
return false;
}
ILogicalExpression exp2 = agg.getExpressions().get(0).getValue();
if (exp2.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return false;
}
AbstractFunctionCallExpression fun = (AbstractFunctionCallExpression) exp2;
if (fun.getFunctionIdentifier() != BuiltinFunctions.COUNT) {
return false;
}
ILogicalExpression exp3 = fun.getArguments().get(0).getValue();
if (exp3.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
return false;
}
if (((AbstractLogicalOperator) agg.getInputs().get(0).getValue()).getOperatorTag() != LogicalOperatorTag.NESTEDTUPLESOURCE) {
return false;
}
fun.getArguments().get(0).setValue(new ConstantExpression(new AsterixConstantValue(new AInt64(1L))));
return true;
}
use of org.apache.asterix.om.base.AInt64 in project asterixdb by apache.
the class ExternalFileTupleTranslator method createExternalFileFromARecord.
private ExternalFile createExternalFileFromARecord(ARecord externalFileRecord) {
String dataverseName = ((AString) externalFileRecord.getValueByPos(MetadataRecordTypes.EXTERNAL_FILE_ARECORD_DATAVERSENAME_FIELD_INDEX)).getStringValue();
String datasetName = ((AString) externalFileRecord.getValueByPos(MetadataRecordTypes.EXTERNAL_FILE_ARECORD_DATASET_NAME_FIELD_INDEX)).getStringValue();
int fileNumber = ((AInt32) externalFileRecord.getValueByPos(MetadataRecordTypes.EXTERNAL_FILE_ARECORD_FILE_NUMBER_FIELD_INDEX)).getIntegerValue();
String fileName = ((AString) externalFileRecord.getValueByPos(MetadataRecordTypes.EXTERNAL_FILE_ARECORD_FILE_NAME_FIELD_INDEX)).getStringValue();
long fileSize = ((AInt64) externalFileRecord.getValueByPos(MetadataRecordTypes.EXTERNAL_FILE_ARECORD_FILE_SIZE_FIELD_INDEX)).getLongValue();
Date lastMoDifiedDate = new Date(((ADateTime) externalFileRecord.getValueByPos(MetadataRecordTypes.EXTERNAL_FILE_ARECORD_FILE_MOD_DATE_FIELD_INDEX)).getChrononTime());
ExternalFilePendingOp pendingOp = ExternalFilePendingOp.values()[((AInt32) externalFileRecord.getValueByPos(MetadataRecordTypes.EXTERNAL_FILE_ARECORD_FILE_PENDING_OP_FIELD_INDEX)).getIntegerValue()];
return new ExternalFile(dataverseName, datasetName, fileNumber, fileName, lastMoDifiedDate, fileSize, pendingOp);
}
use of org.apache.asterix.om.base.AInt64 in project asterixdb by apache.
the class LangExpressionToPlanTranslator method processExists.
// Processes EXISTS and NOT EXISTS.
private AssignOperator processExists(ILogicalExpression inputExpr, LogicalVariable v1, boolean not) {
AbstractFunctionCallExpression count = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.SCALAR_COUNT));
count.getArguments().add(new MutableObject<>(inputExpr));
AbstractFunctionCallExpression comparison = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(not ? BuiltinFunctions.EQ : BuiltinFunctions.NEQ));
comparison.getArguments().add(new MutableObject<>(count));
comparison.getArguments().add(new MutableObject<>(new ConstantExpression(new AsterixConstantValue(new AInt64(0L)))));
return new AssignOperator(v1, new MutableObject<>(comparison));
}
use of org.apache.asterix.om.base.AInt64 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