Search in sources :

Example 31 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class DataflowControllerProvider method getDataflowController.

// TODO: Instead, use a factory just like data source and data parser.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static IDataFlowController getDataflowController(ARecordType recordType, IHyracksTaskContext ctx, int partition, IExternalDataSourceFactory dataSourceFactory, IDataParserFactory dataParserFactory, Map<String, String> configuration, boolean indexingOp, boolean isFeed, FeedLogManager feedLogManager) throws HyracksDataException {
    try {
        switch(dataSourceFactory.getDataSourceType()) {
            case RECORDS:
                IRecordReaderFactory<?> recordReaderFactory = (IRecordReaderFactory<?>) dataSourceFactory;
                IRecordReader<?> recordReader = recordReaderFactory.createRecordReader(ctx, partition);
                IRecordDataParserFactory<?> recordParserFactory = (IRecordDataParserFactory<?>) dataParserFactory;
                IRecordDataParser<?> dataParser = recordParserFactory.createRecordParser(ctx);
                if (indexingOp) {
                    return new IndexingDataFlowController(ctx, DataflowUtils.getTupleForwarder(configuration, feedLogManager), dataParser, recordReader, ((IIndexingDatasource) recordReader).getIndexer());
                } else if (isFeed) {
                    FeedTupleForwarder tupleForwarder = (FeedTupleForwarder) DataflowUtils.getTupleForwarder(configuration, feedLogManager);
                    boolean isChangeFeed = ExternalDataUtils.isChangeFeed(configuration);
                    boolean isRecordWithMeta = ExternalDataUtils.isRecordWithMeta(configuration);
                    if (isRecordWithMeta) {
                        if (isChangeFeed) {
                            int numOfKeys = ExternalDataUtils.getNumberOfKeys(configuration);
                            return new ChangeFeedWithMetaDataFlowController(ctx, tupleForwarder, feedLogManager, numOfKeys + 2, (IRecordWithMetadataParser) dataParser, recordReader);
                        } else {
                            return new FeedWithMetaDataFlowController(ctx, tupleForwarder, feedLogManager, 2, (IRecordWithMetadataParser) dataParser, recordReader);
                        }
                    } else if (isChangeFeed) {
                        int numOfKeys = ExternalDataUtils.getNumberOfKeys(configuration);
                        return new ChangeFeedDataFlowController(ctx, tupleForwarder, feedLogManager, numOfKeys + 1, (IRecordWithPKDataParser) dataParser, recordReader);
                    } else {
                        return new FeedRecordDataFlowController(ctx, tupleForwarder, feedLogManager, 1, dataParser, recordReader);
                    }
                } else {
                    return new RecordDataFlowController(ctx, DataflowUtils.getTupleForwarder(configuration, feedLogManager), dataParser, recordReader, 1);
                }
            case STREAM:
                IInputStreamFactory streamFactory = (IInputStreamFactory) dataSourceFactory;
                AsterixInputStream stream = streamFactory.createInputStream(ctx, partition);
                IStreamDataParserFactory streamParserFactory = (IStreamDataParserFactory) dataParserFactory;
                IStreamDataParser streamParser = streamParserFactory.createInputStreamParser(ctx, partition);
                streamParser.setInputStream(stream);
                if (isFeed) {
                    return new FeedStreamDataFlowController(ctx, (FeedTupleForwarder) DataflowUtils.getTupleForwarder(configuration, feedLogManager), feedLogManager, streamParser, stream);
                } else {
                    return new StreamDataFlowController(ctx, DataflowUtils.getTupleForwarder(configuration, null), streamParser);
                }
            default:
                throw new RuntimeDataException(ErrorCode.PROVIDER_DATAFLOW_CONTROLLER_UNKNOWN_DATA_SOURCE, dataSourceFactory.getDataSourceType());
        }
    } catch (IOException | AsterixException e) {
        throw new HyracksDataException(e);
    }
}
Also used : ChangeFeedDataFlowController(org.apache.asterix.external.dataflow.ChangeFeedDataFlowController) IndexingDataFlowController(org.apache.asterix.external.dataflow.IndexingDataFlowController) IRecordWithMetadataParser(org.apache.asterix.external.api.IRecordWithMetadataParser) AsterixException(org.apache.asterix.common.exceptions.AsterixException) FeedTupleForwarder(org.apache.asterix.external.dataflow.FeedTupleForwarder) ChangeFeedWithMetaDataFlowController(org.apache.asterix.external.dataflow.ChangeFeedWithMetaDataFlowController) FeedWithMetaDataFlowController(org.apache.asterix.external.dataflow.FeedWithMetaDataFlowController) FeedStreamDataFlowController(org.apache.asterix.external.dataflow.FeedStreamDataFlowController) FeedStreamDataFlowController(org.apache.asterix.external.dataflow.FeedStreamDataFlowController) StreamDataFlowController(org.apache.asterix.external.dataflow.StreamDataFlowController) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException) RecordDataFlowController(org.apache.asterix.external.dataflow.RecordDataFlowController) FeedRecordDataFlowController(org.apache.asterix.external.dataflow.FeedRecordDataFlowController) IStreamDataParser(org.apache.asterix.external.api.IStreamDataParser) IStreamDataParserFactory(org.apache.asterix.external.api.IStreamDataParserFactory) IRecordDataParserFactory(org.apache.asterix.external.api.IRecordDataParserFactory) FeedRecordDataFlowController(org.apache.asterix.external.dataflow.FeedRecordDataFlowController) IInputStreamFactory(org.apache.asterix.external.api.IInputStreamFactory) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IRecordReaderFactory(org.apache.asterix.external.api.IRecordReaderFactory) ChangeFeedWithMetaDataFlowController(org.apache.asterix.external.dataflow.ChangeFeedWithMetaDataFlowController) AsterixInputStream(org.apache.asterix.external.api.AsterixInputStream)

Example 32 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class DatasourceFactoryProvider method getInputStreamFactory.

public static IInputStreamFactory getInputStreamFactory(ILibraryManager libraryManager, String streamSource, Map<String, String> configuration) throws HyracksDataException {
    IInputStreamFactory streamSourceFactory;
    if (ExternalDataUtils.isExternal(streamSource)) {
        String dataverse = ExternalDataUtils.getDataverse(configuration);
        streamSourceFactory = ExternalDataUtils.createExternalInputStreamFactory(libraryManager, dataverse, streamSource);
    } else {
        switch(streamSource) {
            case ExternalDataConstants.STREAM_LOCAL_FILESYSTEM:
                streamSourceFactory = new LocalFSInputStreamFactory();
                break;
            case ExternalDataConstants.SOCKET:
            case ExternalDataConstants.ALIAS_SOCKET_ADAPTER:
                streamSourceFactory = new SocketServerInputStreamFactory();
                break;
            case ExternalDataConstants.STREAM_SOCKET_CLIENT:
                streamSourceFactory = new SocketServerInputStreamFactory();
                break;
            default:
                try {
                    streamSourceFactory = (IInputStreamFactory) Class.forName(streamSource).newInstance();
                } catch (Exception e) {
                    throw new RuntimeDataException(ErrorCode.PROVIDER_DATASOURCE_FACTORY_UNKNOWN_INPUT_STREAM_FACTORY, e, streamSource);
                }
        }
    }
    return streamSourceFactory;
}
Also used : LocalFSInputStreamFactory(org.apache.asterix.external.input.stream.factory.LocalFSInputStreamFactory) IInputStreamFactory(org.apache.asterix.external.api.IInputStreamFactory) SocketServerInputStreamFactory(org.apache.asterix.external.input.stream.factory.SocketServerInputStreamFactory) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IOException(java.io.IOException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 33 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class ExprTree method toString.

@Override
public String toString() {
    ClassAdObjectPool objectPool = new ClassAdObjectPool();
    ClassAdUnParser unparser = new ClassAdUnParser(objectPool);
    AMutableCharArrayString string_representation = objectPool.strPool.get();
    try {
        unparser.unparse(string_representation, this);
    } catch (HyracksDataException e) {
        e.printStackTrace();
    }
    return string_representation.toString();
}
Also used : ClassAdObjectPool(org.apache.asterix.external.classad.object.pool.ClassAdObjectPool) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 34 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class TweetParser method writeRecord.

public void writeRecord(JsonNode obj, DataOutput out, ARecordType curRecType) throws IOException {
    IAType[] curTypes = null;
    String[] curFNames = null;
    int fieldN;
    int attrIdx;
    int expectedFieldsCount = 0;
    ArrayBackedValueStorage fieldValueBuffer = getTempBuffer();
    ArrayBackedValueStorage fieldNameBuffer = getTempBuffer();
    IARecordBuilder recBuilder = getRecordBuilder();
    if (curRecType != null) {
        curTypes = curRecType.getFieldTypes();
        curFNames = curRecType.getFieldNames();
        for (IAType curType : curTypes) {
            if (!(curType instanceof AUnionType)) {
                expectedFieldsCount++;
            }
        }
    }
    recBuilder.reset(curRecType);
    recBuilder.init();
    if (curRecType != null && !curRecType.isOpen()) {
        // closed record type
        fieldN = curFNames.length;
        for (int iter1 = 0; iter1 < fieldN; iter1++) {
            fieldValueBuffer.reset();
            DataOutput fieldOutput = fieldValueBuffer.getDataOutput();
            if (obj.get(curFNames[iter1]).isNull() && !(curTypes[iter1] instanceof AUnionType)) {
                if (curRecType.isClosedField(curFNames[iter1])) {
                    throw new RuntimeDataException(ErrorCode.PARSER_TWEET_PARSER_CLOSED_FIELD_NULL, curFNames[iter1]);
                } else {
                    continue;
                }
            } else {
                if (writeField(obj.get(curFNames[iter1]), curTypes[iter1], fieldOutput)) {
                    recBuilder.addField(iter1, fieldValueBuffer);
                }
            }
        }
    } else {
        //open record type
        int closedFieldCount = 0;
        IAType curFieldType = null;
        String attrName;
        Iterator<String> iter = obj.fieldNames();
        while (iter.hasNext()) {
            attrName = iter.next();
            if (obj.get(attrName) == null || obj.get(attrName).isNull() || obj.size() == 0) {
                continue;
            }
            attrIdx = checkAttrNameIdx(curFNames, attrName);
            if (curRecType != null) {
                curFieldType = curRecType.getFieldType(attrName);
            }
            fieldValueBuffer.reset();
            fieldNameBuffer.reset();
            DataOutput fieldOutput = fieldValueBuffer.getDataOutput();
            if (writeField(obj.get(attrName), curFieldType, fieldOutput)) {
                if (attrIdx == -1) {
                    aString.setValue(attrName);
                    stringSerde.serialize(aString, fieldNameBuffer.getDataOutput());
                    recBuilder.addField(fieldNameBuffer, fieldValueBuffer);
                } else {
                    recBuilder.addField(attrIdx, fieldValueBuffer);
                    closedFieldCount++;
                }
            }
        }
        if (curRecType != null && closedFieldCount < expectedFieldsCount) {
            throw new HyracksDataException("Non-null field is null");
        }
    }
    recBuilder.write(out, true);
}
Also used : DataOutput(java.io.DataOutput) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) AUnionType(org.apache.asterix.om.types.AUnionType) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IAType(org.apache.asterix.om.types.IAType) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 35 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class Operation method doBitwise.

public static int doBitwise(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
    AMutableInt64 i1 = objectPool.int64Pool.get();
    AMutableInt64 i2 = objectPool.int64Pool.get();
    // bitwise operations are defined only on integers
    if (op == OpKind_BITWISE_NOT_OP) {
        if (!v1.isIntegerValue(i1)) {
            result.setErrorValue();
            return SigValues.SIG_CHLD1.ordinal();
        }
    } else if (!v1.isIntegerValue(i1) || !v2.isIntegerValue(i2)) {
        result.setErrorValue();
        return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
    }
    switch(op) {
        case OpKind_BITWISE_NOT_OP:
            result.setIntegerValue(~(i1.getLongValue()));
            break;
        case OpKind_BITWISE_OR_OP:
            result.setIntegerValue(i1.getLongValue() | i2.getLongValue());
            break;
        case OpKind_BITWISE_AND_OP:
            result.setIntegerValue(i1.getLongValue() & i2.getLongValue());
            break;
        case OpKind_BITWISE_XOR_OP:
            result.setIntegerValue(i1.getLongValue() ^ i2.getLongValue());
            break;
        case OpKind_LEFT_SHIFT_OP:
            result.setIntegerValue(i1.getLongValue() << i2.getLongValue());
            break;
        case OpKind_URIGHT_SHIFT_OP:
            //               if (i1 >= 0) {
            // Could probably just use >>>
            // sign bit is not on;  >> will work fine
            result.setIntegerValue(i1.getLongValue() >>> i2.getLongValue());
            break;
        case OpKind_RIGHT_SHIFT_OP:
            // sign bit is off;  >> will work fine
            result.setIntegerValue(i1.getLongValue() >> i2.getLongValue());
            break;
        default:
            // should not get here
            throw new HyracksDataException("Should not get here");
    }
    if (op == OpKind_BITWISE_NOT_OP) {
        return SigValues.SIG_CHLD1.ordinal();
    }
    return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
}
Also used : AMutableInt64(org.apache.asterix.om.base.AMutableInt64) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)566 IOException (java.io.IOException)209 DataOutput (java.io.DataOutput)96 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)78 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)75 IPointable (org.apache.hyracks.data.std.api.IPointable)73 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)70 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)67 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)67 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)64 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)61 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)60 ArrayList (java.util.ArrayList)57 ACIDException (org.apache.asterix.common.exceptions.ACIDException)56 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)56 ATypeTag (org.apache.asterix.om.types.ATypeTag)39 AsterixException (org.apache.asterix.common.exceptions.AsterixException)36 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)32 ByteBuffer (java.nio.ByteBuffer)30 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)27