use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.
the class FeedMetadataUtil method validateFeed.
public static void validateFeed(Feed feed, MetadataTransactionContext mdTxnCtx, ICcApplicationContext appCtx) throws AsterixException {
try {
String adapterName = feed.getAdapterName();
Map<String, String> configuration = feed.getAdapterConfiguration();
ARecordType adapterOutputType = getOutputType(feed, configuration, ExternalDataConstants.KEY_TYPE_NAME);
ARecordType metaType = getOutputType(feed, configuration, ExternalDataConstants.KEY_META_TYPE_NAME);
ExternalDataUtils.prepareFeed(configuration, feed.getDataverseName(), feed.getFeedName());
// Get adapter from metadata dataset <Metadata dataverse>
DatasourceAdapter adapterEntity = MetadataManager.INSTANCE.getAdapter(mdTxnCtx, MetadataConstants.METADATA_DATAVERSE_NAME, adapterName);
// Get adapter from metadata dataset <The feed dataverse>
if (adapterEntity == null) {
adapterEntity = MetadataManager.INSTANCE.getAdapter(mdTxnCtx, feed.getDataverseName(), adapterName);
}
AdapterType adapterType;
IAdapterFactory adapterFactory;
if (adapterEntity != null) {
adapterType = adapterEntity.getType();
String adapterFactoryClassname = adapterEntity.getClassname();
switch(adapterType) {
case INTERNAL:
adapterFactory = (IAdapterFactory) Class.forName(adapterFactoryClassname).newInstance();
break;
case EXTERNAL:
String[] anameComponents = adapterName.split("#");
String libraryName = anameComponents[0];
ClassLoader cl = appCtx.getLibraryManager().getLibraryClassLoader(feed.getDataverseName(), libraryName);
adapterFactory = (IAdapterFactory) cl.loadClass(adapterFactoryClassname).newInstance();
break;
default:
throw new AsterixException("Unknown Adapter type " + adapterType);
}
adapterFactory.setOutputType(adapterOutputType);
adapterFactory.setMetaType(metaType);
adapterFactory.configure(appCtx.getServiceContext(), configuration);
} else {
AdapterFactoryProvider.getAdapterFactory(appCtx.getServiceContext(), adapterName, configuration, adapterOutputType, metaType);
}
if (metaType == null && configuration.containsKey(ExternalDataConstants.KEY_META_TYPE_NAME)) {
metaType = getOutputType(feed, configuration, ExternalDataConstants.KEY_META_TYPE_NAME);
if (metaType == null) {
throw new AsterixException("Unknown specified feed meta output data type " + configuration.get(ExternalDataConstants.KEY_META_TYPE_NAME));
}
}
if (adapterOutputType == null) {
if (!configuration.containsKey(ExternalDataConstants.KEY_TYPE_NAME)) {
throw new AsterixException("Unspecified feed output data type");
}
adapterOutputType = getOutputType(feed, configuration, ExternalDataConstants.KEY_TYPE_NAME);
if (adapterOutputType == null) {
throw new AsterixException("Unknown specified feed output data type " + configuration.get(ExternalDataConstants.KEY_TYPE_NAME));
}
}
} catch (Exception e) {
throw new AsterixException("Invalid feed parameters. Exception Message:" + e.getMessage(), e);
}
}
use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.
the class DatasetUtil method createDummyKeyProviderOp.
/**
* Creates a dummy key provider operator for the primary index scan.
*
* @param spec,
* the job specification.
* @param dataset,
* the dataset to scan.
* @param metadataProvider,
* the metadata provider.
* @return a dummy key provider operator.
* @throws AlgebricksException
*/
public static IOperatorDescriptor createDummyKeyProviderOp(JobSpecification spec, Dataset dataset, MetadataProvider metadataProvider) throws AlgebricksException {
Pair<IFileSplitProvider, AlgebricksPartitionConstraint> primarySplitsAndConstraint = metadataProvider.getSplitProviderAndConstraints(dataset);
AlgebricksPartitionConstraint primaryPartitionConstraint = primarySplitsAndConstraint.second;
// Build dummy tuple containing one field with a dummy value inside.
ArrayTupleBuilder tb = new ArrayTupleBuilder(1);
DataOutput dos = tb.getDataOutput();
tb.reset();
try {
// Serialize dummy value into a field.
IntegerSerializerDeserializer.INSTANCE.serialize(0, dos);
} catch (HyracksDataException e) {
throw new AsterixException(e);
}
// Add dummy field.
tb.addFieldEndOffset();
ISerializerDeserializer[] keyRecDescSers = { IntegerSerializerDeserializer.INSTANCE };
RecordDescriptor keyRecDesc = new RecordDescriptor(keyRecDescSers);
ConstantTupleSourceOperatorDescriptor keyProviderOp = new ConstantTupleSourceOperatorDescriptor(spec, keyRecDesc, tb.getFieldEndOffsets(), tb.getByteArray(), tb.getSize());
AlgebricksPartitionConstraintHelper.setPartitionConstraintInJobSpec(spec, keyProviderOp, primaryPartitionConstraint);
return keyProviderOp;
}
use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.
the class BinaryConcatDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new AbstractBinaryScalarEvaluator(ctx, args) {
private final ListAccessor listAccessor = new ListAccessor();
private final byte[] metaBuffer = new byte[5];
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ANull> nullSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AMissing> missingSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AMISSING);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evaluators[0].evaluate(tuple, pointables[0]);
byte[] data = pointables[0].getByteArray();
int offset = pointables[0].getStartOffset();
byte typeTag = data[offset];
if (typeTag != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG && typeTag != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, typeTag, ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG, ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG);
}
try {
listAccessor.reset(data, offset);
int concatLength = 0;
for (int i = 0; i < listAccessor.size(); i++) {
int itemOffset = listAccessor.getItemOffset(i);
ATypeTag itemType = listAccessor.getItemType(itemOffset);
if (itemType != ATypeTag.BINARY) {
if (serializeUnknownIfAnyUnknown(itemType)) {
result.set(resultStorage);
return;
}
throw new UnsupportedItemTypeException(getIdentifier(), itemType.serialize());
}
concatLength += ByteArrayPointable.getContentLength(data, itemOffset);
}
dataOutput.writeByte(ATypeTag.SERIALIZED_BINARY_TYPE_TAG);
int metaLen = VarLenIntEncoderDecoder.encode(concatLength, metaBuffer, 0);
dataOutput.write(metaBuffer, 0, metaLen);
for (int i = 0; i < listAccessor.size(); i++) {
int itemOffset = listAccessor.getItemOffset(i);
int length = ByteArrayPointable.getContentLength(data, itemOffset);
dataOutput.write(data, itemOffset + ByteArrayPointable.getNumberBytesToStoreMeta(length), length);
}
} catch (IOException e) {
throw new HyracksDataException(e);
} catch (AsterixException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
private boolean serializeUnknownIfAnyUnknown(ATypeTag... tags) throws HyracksDataException {
for (ATypeTag typeTag : tags) {
if (typeTag == ATypeTag.NULL) {
nullSerde.serialize(ANull.NULL, dataOutput);
return true;
}
if (typeTag == ATypeTag.MISSING) {
missingSerde.serialize(AMissing.MISSING, dataOutput);
return true;
}
}
return false;
}
};
}
};
}
use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.
the class FieldAccessByIndexEvalFactory method createScalarEvaluator.
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable inputArg0 = new VoidPointable();
private IPointable inputArg1 = new VoidPointable();
private IScalarEvaluator eval0 = recordEvalFactory.createScalarEvaluator(ctx);
private IScalarEvaluator eval1 = fieldIndexEvalFactory.createScalarEvaluator(ctx);
private int fieldIndex;
private int fieldValueOffset;
private int fieldValueLength;
private IAType fieldValueType;
private ATypeTag fieldValueTypeTag;
/*
* inputArg0: the record
* inputArg1: the index
*
* This method outputs into IHyracksTaskContext context [field type tag (1 byte)][the field data]
*/
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
eval0.evaluate(tuple, inputArg0);
byte[] serRecord = inputArg0.getByteArray();
int offset = inputArg0.getStartOffset();
if (serRecord[offset] != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
throw new TypeMismatchException(BuiltinFunctions.FIELD_ACCESS_BY_INDEX, 0, serRecord[offset], ATypeTag.SERIALIZED_RECORD_TYPE_TAG);
}
eval1.evaluate(tuple, inputArg1);
byte[] indexBytes = inputArg1.getByteArray();
int indexOffset = inputArg1.getStartOffset();
if (indexBytes[indexOffset] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
throw new TypeMismatchException(BuiltinFunctions.FIELD_ACCESS_BY_INDEX, 1, indexBytes[offset], ATypeTag.SERIALIZED_INT32_TYPE_TAG);
}
fieldIndex = IntegerPointable.getInteger(indexBytes, indexOffset + 1);
fieldValueType = recordType.getFieldTypes()[fieldIndex];
fieldValueOffset = ARecordSerializerDeserializer.getFieldOffsetById(serRecord, offset, fieldIndex, nullBitmapSize, recordType.isOpen());
if (fieldValueOffset == 0) {
// the field is null, we checked the null bit map
out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
result.set(resultStorage);
return;
}
if (fieldValueOffset < 0) {
// the field is missing, we checked the missing bit map
out.writeByte(ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
result.set(resultStorage);
return;
}
if (fieldValueType.getTypeTag().equals(ATypeTag.UNION)) {
if (((AUnionType) fieldValueType).isUnknownableType()) {
fieldValueTypeTag = ((AUnionType) fieldValueType).getActualType().getTypeTag();
fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(serRecord, fieldValueOffset, fieldValueTypeTag, false);
out.writeByte(fieldValueTypeTag.serialize());
} else {
// union .. the general case
throw new NotImplementedException();
}
} else {
fieldValueTypeTag = fieldValueType.getTypeTag();
fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(serRecord, fieldValueOffset, fieldValueTypeTag, false);
out.writeByte(fieldValueTypeTag.serialize());
}
out.write(serRecord, fieldValueOffset, fieldValueLength);
result.set(resultStorage);
} catch (IOException e) {
throw new HyracksDataException(e);
} catch (AsterixException e) {
throw new HyracksDataException(e);
}
}
};
}
use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.
the class GetRecordFieldValueEvalFactory method createScalarEvaluator.
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable inputArg0 = new VoidPointable();
private final IPointable inputArg1 = new VoidPointable();
private final IScalarEvaluator recordEval = recordEvalFactory.createScalarEvaluator(ctx);
private final IScalarEvaluator fieldNameEval = fldNameEvalFactory.createScalarEvaluator(ctx);
private final RuntimeRecordTypeInfo recTypeInfo = new RuntimeRecordTypeInfo();
{
recTypeInfo.reset(recordType);
}
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
fieldNameEval.evaluate(tuple, inputArg1);
byte[] serFldName = inputArg1.getByteArray();
int serFldNameOffset = inputArg1.getStartOffset();
int serFldNameLen = inputArg1.getLength();
recordEval.evaluate(tuple, inputArg0);
byte[] serRecord = inputArg0.getByteArray();
int serRecordOffset = inputArg0.getStartOffset();
int serRecordLen = inputArg0.getLength();
if (serRecord[serRecordOffset] != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
throw new TypeMismatchException(BuiltinFunctions.GET_RECORD_FIELD_VALUE, 0, serRecord[serRecordOffset], ATypeTag.SERIALIZED_RECORD_TYPE_TAG);
}
int subFieldOffset = -1;
int subFieldLength = -1;
// Look at closed fields first.
int subFieldIndex = recTypeInfo.getFieldIndex(serFldName, serFldNameOffset + 1, serFldNameLen - 1);
if (subFieldIndex >= 0) {
int nullBitmapSize = RecordUtil.computeNullBitmapSize(recordType);
subFieldOffset = ARecordSerializerDeserializer.getFieldOffsetById(serRecord, serRecordOffset, subFieldIndex, nullBitmapSize, recordType.isOpen());
if (subFieldOffset == 0) {
// the field is null, we checked the null bit map
out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
result.set(resultStorage);
return;
}
ATypeTag fieldTypeTag = recordType.getFieldTypes()[subFieldIndex].getTypeTag();
subFieldLength = NonTaggedFormatUtil.getFieldValueLength(serRecord, subFieldOffset, fieldTypeTag, false);
// write result.
out.writeByte(fieldTypeTag.serialize());
out.write(serRecord, subFieldOffset, subFieldLength);
result.set(resultStorage);
return;
}
// Look at open fields.
subFieldOffset = ARecordSerializerDeserializer.getFieldOffsetByName(serRecord, serRecordOffset, serRecordLen, serFldName, serFldNameOffset);
if (subFieldOffset < 0) {
out.writeByte(ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
result.set(resultStorage);
return;
}
// Get the field length.
ATypeTag fieldValueTypeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serRecord[subFieldOffset]);
subFieldLength = NonTaggedFormatUtil.getFieldValueLength(serRecord, subFieldOffset, fieldValueTypeTag, true) + 1;
// write result.
result.set(serRecord, subFieldOffset, subFieldLength);
} catch (IOException e) {
throw new HyracksDataException(e);
} catch (AsterixException e) {
throw new HyracksDataException(e);
}
}
};
}
Aggregations