use of org.apache.hyracks.api.context.IHyracksTaskContext in project asterixdb by apache.
the class TemporalIntervalStartTimeAccessor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable argPtr = new VoidPointable();
private final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
// possible output
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<ATime> timeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ATIME);
private final AMutableTime aTime = new AMutableTime(0);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int startOffset = argPtr.getStartOffset();
resultStorage.reset();
try {
if (bytes[startOffset] == ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG) {
byte timeType = AIntervalSerializerDeserializer.getIntervalTimeType(bytes, startOffset + 1);
long startTime = AIntervalSerializerDeserializer.getIntervalStart(bytes, startOffset + 1);
if (timeType == ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
aTime.setValue((int) (startTime));
timeSerde.serialize(aTime, out);
} else {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
}
} else {
throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
}
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.api.context.IHyracksTaskContext in project asterixdb by apache.
the class TemporalSecondAccessor method createEvaluatorFactory.
/* (non-Javadoc)
* @see org.apache.asterix.runtime.base.IScalarFunctionDynamicDescriptor#createEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory[])
*/
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable argPtr = new VoidPointable();
private final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private final GregorianCalendarSystem calSystem = GregorianCalendarSystem.getInstance();
// for output: type integer
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<AInt64> intSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
private final AMutableInt64 aMutableInt64 = new AMutableInt64(0);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int startOffset = argPtr.getStartOffset();
resultStorage.reset();
try {
if (bytes[startOffset] == ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
aMutableInt64.setValue(calSystem.getDurationSecond(ADurationSerializerDeserializer.getDayTime(bytes, startOffset + 1)));
intSerde.serialize(aMutableInt64, out);
result.set(resultStorage);
return;
}
if (bytes[startOffset] == ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG) {
aMutableInt64.setValue(calSystem.getDurationSecond(ADayTimeDurationSerializerDeserializer.getDayTime(bytes, startOffset + 1)));
intSerde.serialize(aMutableInt64, out);
result.set(resultStorage);
return;
}
long chrononTimeInMs = 0;
if (bytes[startOffset] == ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, startOffset + 1);
} else if (bytes[startOffset] == ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
chrononTimeInMs = AInt64SerializerDeserializer.getLong(bytes, startOffset + 1);
} else {
throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_TIME_TYPE_TAG, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
int sec = calSystem.getSecOfMin(chrononTimeInMs);
aMutableInt64.setValue(sec);
intSerde.serialize(aMutableInt64, out);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.api.context.IHyracksTaskContext in project asterixdb by apache.
the class ExceptionIT method testFunction.
private void testFunction(IFunctionDescriptorFactory funcFactory) throws Exception {
AbstractScalarFunctionDynamicDescriptor funcDesc = (AbstractScalarFunctionDynamicDescriptor) funcFactory.createFunctionDescriptor();
int inputArity = funcDesc.getIdentifier().getArity();
Iterator<IScalarEvaluatorFactory[]> argEvalFactoryIterator = getArgCombinations(inputArity);
while (argEvalFactoryIterator.hasNext()) {
IScalarEvaluatorFactory evalFactory = funcDesc.createEvaluatorFactory(argEvalFactoryIterator.next());
IHyracksTaskContext ctx = mock(IHyracksTaskContext.class);
IScalarEvaluator evaluator = evalFactory.createScalarEvaluator(ctx);
IPointable resultPointable = new VoidPointable();
try {
evaluator.evaluate(null, resultPointable);
} catch (Throwable e) {
String msg = e.getMessage();
if (msg == null) {
continue;
}
if (msg.startsWith("ASX")) {
// Verifies the error code.
int errorCode = Integer.parseInt(msg.substring(3, 7));
Assert.assertTrue(errorCode >= 0 && errorCode < 1000);
continue;
} else {
// Any root-level data exceptions thrown from runtime functions should have an error code.
Assert.assertTrue(!(e instanceof HyracksDataException) || (e.getCause() != null));
}
}
}
}
use of org.apache.hyracks.api.context.IHyracksTaskContext in project asterixdb by apache.
the class NullMissingTest method testFunction.
private void testFunction(IFunctionDescriptorFactory funcFactory) throws Exception {
IFunctionDescriptor functionDescriptor = funcFactory.createFunctionDescriptor();
if (!(functionDescriptor instanceof AbstractScalarFunctionDynamicDescriptor)) {
return;
}
AbstractScalarFunctionDynamicDescriptor funcDesc = (AbstractScalarFunctionDynamicDescriptor) functionDescriptor;
int inputArity = funcDesc.getIdentifier().getArity();
Iterator<IScalarEvaluatorFactory[]> argEvalFactoryIterator = getArgCombinations(inputArity);
int index = 0;
while (argEvalFactoryIterator.hasNext()) {
IScalarEvaluatorFactory evalFactory = funcDesc.createEvaluatorFactory(argEvalFactoryIterator.next());
IHyracksTaskContext ctx = mock(IHyracksTaskContext.class);
IScalarEvaluator evaluator = evalFactory.createScalarEvaluator(ctx);
IPointable resultPointable = new VoidPointable();
evaluator.evaluate(null, resultPointable);
if (index != 0) {
Assert.assertTrue(resultPointable.getByteArray()[resultPointable.getStartOffset()] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
} else {
Assert.assertTrue(resultPointable.getByteArray()[resultPointable.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG);
}
++index;
}
}
use of org.apache.hyracks.api.context.IHyracksTaskContext in project asterixdb by apache.
the class TestNodeController method createPrimaryIndex.
public void createPrimaryIndex(Dataset dataset, IAType[] primaryKeyTypes, ARecordType recordType, ARecordType metaType, ILSMMergePolicyFactory mergePolicyFactory, Map<String, String> mergePolicyProperties, int[] filterFields, IStorageComponentProvider storageComponentProvider, int[] primaryKeyIndexes, List<Integer> primaryKeyIndicators) throws AlgebricksException, HyracksDataException {
PrimaryIndexInfo primaryIndexInfo = new PrimaryIndexInfo(dataset, primaryKeyTypes, recordType, metaType, mergePolicyFactory, mergePolicyProperties, filterFields, primaryKeyIndexes, primaryKeyIndicators, storageComponentProvider);
Dataverse dataverse = new Dataverse(dataset.getDataverseName(), NonTaggedDataFormat.class.getName(), MetadataUtil.PENDING_NO_OP);
MetadataProvider mdProvider = new MetadataProvider((ICcApplicationContext) ExecutionTestUtil.integrationUtil.cc.getApplicationContext(), dataverse, storageComponentProvider);
try {
IResourceFactory resourceFactory = dataset.getResourceFactory(mdProvider, primaryIndexInfo.index, recordType, metaType, mergePolicyFactory, mergePolicyProperties);
IndexBuilderFactory indexBuilderFactory = new IndexBuilderFactory(storageComponentProvider.getStorageManager(), primaryIndexInfo.fileSplitProvider, resourceFactory, !dataset.isTemp());
IHyracksTaskContext ctx = createTestContext(false);
IIndexBuilder indexBuilder = indexBuilderFactory.create(ctx, 0);
indexBuilder.build();
} finally {
mdProvider.getLocks().unlock();
}
}
Aggregations