Search in sources :

Example 1 with RuntimeDataException

use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.

the class SubsetCollectionDescriptor method createUnnestingEvaluatorFactory.

@Override
public IUnnestingEvaluatorFactory createUnnestingEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IUnnestingEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IUnnestingEvaluator createUnnestingEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
            return new IUnnestingEvaluator() {

                private IPointable inputVal = new VoidPointable();

                private IScalarEvaluator evalList = args[0].createScalarEvaluator(ctx);

                private IScalarEvaluator evalStart = args[1].createScalarEvaluator(ctx);

                private IScalarEvaluator evalLen = args[2].createScalarEvaluator(ctx);

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private int numItems;

                private int numItemsMax;

                private int posStart;

                private int posCrt;

                private ATypeTag itemTag;

                private boolean selfDescList = false;

                private boolean metUnknown = false;

                @Override
                public void init(IFrameTupleReference tuple) throws HyracksDataException {
                    try {
                        evalStart.evaluate(tuple, inputVal);
                        posStart = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 0, inputVal.getByteArray(), inputVal.getStartOffset());
                        evalLen.evaluate(tuple, inputVal);
                        numItems = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 1, inputVal.getByteArray(), inputVal.getStartOffset());
                        evalList.evaluate(tuple, inputVal);
                        byte[] serList = inputVal.getByteArray();
                        int offset = inputVal.getStartOffset();
                        metUnknown = false;
                        byte typeTag = serList[offset];
                        if (typeTag == ATypeTag.SERIALIZED_MISSING_TYPE_TAG || typeTag == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                            metUnknown = true;
                            return;
                        }
                        if (typeTag != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG && typeTag != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
                            throw new RuntimeDataException(ErrorCode.COERCION, getIdentifier());
                        }
                        if (typeTag == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
                            numItemsMax = AOrderedListSerializerDeserializer.getNumberOfItems(serList, offset);
                        } else {
                            numItemsMax = AUnorderedListSerializerDeserializer.getNumberOfItems(serList, offset);
                        }
                        itemTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[offset + 1]);
                        if (itemTag == ATypeTag.ANY) {
                            selfDescList = true;
                        }
                        posCrt = posStart;
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                }

                @Override
                public boolean step(IPointable result) throws HyracksDataException {
                    if (!metUnknown && posCrt < posStart + numItems && posCrt < numItemsMax) {
                        resultStorage.reset();
                        byte[] serList = inputVal.getByteArray();
                        int offset = inputVal.getStartOffset();
                        int itemLength = 0;
                        try {
                            int itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serList, offset, posCrt);
                            if (selfDescList) {
                                itemTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[itemOffset]);
                            }
                            itemLength = NonTaggedFormatUtil.getFieldValueLength(serList, itemOffset, itemTag, selfDescList);
                            if (!selfDescList) {
                                resultStorage.getDataOutput().writeByte(itemTag.serialize());
                            }
                            resultStorage.getDataOutput().write(serList, itemOffset, itemLength + (!selfDescList ? 0 : 1));
                        } catch (IOException e) {
                            throw new HyracksDataException(e);
                        } catch (AsterixException e) {
                            throw new HyracksDataException(e);
                        }
                        result.set(resultStorage);
                        ++posCrt;
                        return true;
                    }
                    return false;
                }
            };
        }
    };
}
Also used : IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IUnnestingEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IUnnestingEvaluatorFactory) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AsterixException(org.apache.asterix.common.exceptions.AsterixException) IUnnestingEvaluator(org.apache.hyracks.algebricks.runtime.base.IUnnestingEvaluator) ATypeTag(org.apache.asterix.om.types.ATypeTag) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 2 with RuntimeDataException

use of org.apache.asterix.common.exceptions.RuntimeDataException 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 3 with RuntimeDataException

use of org.apache.asterix.common.exceptions.RuntimeDataException 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 4 with RuntimeDataException

use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.

the class HDFSUtils method initializeIndexingHDFSScheduler.

public static IndexingScheduler initializeIndexingHDFSScheduler(ICCServiceContext serviceCtx) throws HyracksDataException {
    ICCContext ccContext = serviceCtx.getCCContext();
    IndexingScheduler scheduler = null;
    try {
        scheduler = new IndexingScheduler(ccContext.getClusterControllerInfo().getClientNetAddress(), ccContext.getClusterControllerInfo().getClientNetPort());
    } catch (HyracksException e) {
        throw new RuntimeDataException(ErrorCode.UTIL_HDFS_UTILS_CANNOT_OBTAIN_HDFS_SCHEDULER);
    }
    return scheduler;
}
Also used : IndexingScheduler(org.apache.asterix.external.indexing.IndexingScheduler) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) ICCContext(org.apache.hyracks.api.context.ICCContext) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 5 with RuntimeDataException

use of org.apache.asterix.common.exceptions.RuntimeDataException in project asterixdb by apache.

the class HDFSUtils method initializeHDFSScheduler.

public static Scheduler initializeHDFSScheduler(ICCServiceContext serviceCtx) throws HyracksDataException {
    ICCContext ccContext = serviceCtx.getCCContext();
    Scheduler scheduler = null;
    try {
        scheduler = new Scheduler(ccContext.getClusterControllerInfo().getClientNetAddress(), ccContext.getClusterControllerInfo().getClientNetPort());
    } catch (HyracksException e) {
        throw new RuntimeDataException(ErrorCode.UTIL_HDFS_UTILS_CANNOT_OBTAIN_HDFS_SCHEDULER);
    }
    return scheduler;
}
Also used : Scheduler(org.apache.hyracks.hdfs.scheduler.Scheduler) IndexingScheduler(org.apache.asterix.external.indexing.IndexingScheduler) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) ICCContext(org.apache.hyracks.api.context.ICCContext) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Aggregations

RuntimeDataException (org.apache.asterix.common.exceptions.RuntimeDataException)33 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)15 IOException (java.io.IOException)12 DataOutput (java.io.DataOutput)7 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)7 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)7 IPointable (org.apache.hyracks.data.std.api.IPointable)7 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)7 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)7 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)7 ATypeTag (org.apache.asterix.om.types.ATypeTag)6 IAType (org.apache.asterix.om.types.IAType)6 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)6 AsterixException (org.apache.asterix.common.exceptions.AsterixException)5 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)4 AUnionType (org.apache.asterix.om.types.AUnionType)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 RecordBuilder (org.apache.asterix.builders.RecordBuilder)2 IInputStreamFactory (org.apache.asterix.external.api.IInputStreamFactory)2