Search in sources :

Example 1 with AInt64

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;
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) GroupByOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) AggregateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) AInt64(org.apache.asterix.om.base.AInt64)

Example 2 with AInt64

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);
}
Also used : ExternalFilePendingOp(org.apache.asterix.common.config.DatasetConfig.ExternalFilePendingOp) AString(org.apache.asterix.om.base.AString) AString(org.apache.asterix.om.base.AString) AInt32(org.apache.asterix.om.base.AInt32) Date(java.util.Date) ExternalFile(org.apache.asterix.external.indexing.ExternalFile) AInt64(org.apache.asterix.om.base.AInt64)

Example 3 with AInt64

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));
}
Also used : AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) AInt64(org.apache.asterix.om.base.AInt64)

Example 4 with AInt64

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;
}
Also used : AInt16(org.apache.asterix.om.base.AInt16) ARecord(org.apache.asterix.om.base.ARecord) AOrderedList(org.apache.asterix.om.base.AOrderedList) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) AInterval(org.apache.asterix.om.base.AInterval) AString(org.apache.asterix.om.base.AString) AInt64(org.apache.asterix.om.base.AInt64)

Aggregations

AInt64 (org.apache.asterix.om.base.AInt64)4 AString (org.apache.asterix.om.base.AString)2 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)2 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)2 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)2 Date (java.util.Date)1 ExternalFilePendingOp (org.apache.asterix.common.config.DatasetConfig.ExternalFilePendingOp)1 ExternalFile (org.apache.asterix.external.indexing.ExternalFile)1 AInt16 (org.apache.asterix.om.base.AInt16)1 AInt32 (org.apache.asterix.om.base.AInt32)1 AInterval (org.apache.asterix.om.base.AInterval)1 AOrderedList (org.apache.asterix.om.base.AOrderedList)1 ARecord (org.apache.asterix.om.base.ARecord)1 AOrderedListType (org.apache.asterix.om.types.AOrderedListType)1 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)1 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)1 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)1 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)1 AggregateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator)1 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)1