use of java.io.DataOutput in project asterixdb by apache.
the class UnixTimeFromTimeInMsDescriptor 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(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable argPtr = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
// possible returning types
private AMutableInt64 aInt64 = new AMutableInt64(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
if (bytes[offset] != ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_TIME_TYPE_TAG);
}
long timeChronon = ATimeSerializerDeserializer.getChronon(bytes, offset + 1);
aInt64.setValue(timeChronon);
int64Serde.serialize(aInt64, out);
result.set(resultStorage);
}
};
}
};
}
use of java.io.DataOutput in project asterixdb by apache.
the class DurationFromMillisecondsDescriptor 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 IScalarEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable argPtr0 = new VoidPointable();
private IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADuration> durationSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADURATION);
AMutableDuration aDuration = new AMutableDuration(0, 0);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval0.evaluate(tuple, argPtr0);
byte[] bytes = argPtr0.getByteArray();
int offset = argPtr0.getStartOffset();
ATypeTag argPtrTypeTag = ATypeTag.VALUE_TYPE_MAPPING[bytes[offset]];
switch(argPtrTypeTag) {
case TINYINT:
aDuration.setValue(0, AInt8SerializerDeserializer.getByte(bytes, offset + 1));
break;
case SMALLINT:
aDuration.setValue(0, AInt16SerializerDeserializer.getShort(bytes, offset + 1));
break;
case INTEGER:
aDuration.setValue(0, AInt32SerializerDeserializer.getInt(bytes, offset + 1));
break;
case BIGINT:
aDuration.setValue(0, AInt64SerializerDeserializer.getLong(bytes, offset + 1));
break;
default:
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG);
}
durationSerde.serialize(aDuration, out);
result.set(resultStorage);
}
};
}
};
}
use of java.io.DataOutput in project asterixdb by apache.
the class DurationFromMonthsDescriptor 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 IScalarEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable argPtr0 = new VoidPointable();
private IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADuration> durationSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADURATION);
AMutableDuration aDuration = new AMutableDuration(0, 0);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval0.evaluate(tuple, argPtr0);
byte[] bytes = argPtr0.getByteArray();
int offset = argPtr0.getStartOffset();
aDuration.setValue(ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 0, bytes, offset), 0);
durationSerde.serialize(aDuration, out);
result.set(resultStorage);
}
};
}
};
}
use of java.io.DataOutput in project asterixdb by apache.
the class AMurmurHash3BinaryHashFunctionFamily method createBinaryHashFunction.
// This hash function family is used to promote a numeric type to a DOUBLE numeric type
// to return same hash value for the original numeric value, regardless of the numeric type.
// (e.g., h( int64("1") ) = h( double("1.0") )
@Override
public IBinaryHashFunction createBinaryHashFunction(final int seed) {
return new IBinaryHashFunction() {
private ArrayBackedValueStorage fieldValueBuffer = new ArrayBackedValueStorage();
private DataOutput fieldValueBufferOutput = fieldValueBuffer.getDataOutput();
private ATypeTag sourceTag = null;
private boolean numericTypePromotionApplied = false;
@Override
public int hash(byte[] bytes, int offset, int length) throws HyracksDataException {
// If a numeric type is encountered, then we promote each numeric type to the DOUBLE type.
fieldValueBuffer.reset();
sourceTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
switch(sourceTag) {
case TINYINT:
case SMALLINT:
case INTEGER:
case BIGINT:
try {
IntegerToDoubleTypeConvertComputer.getInstance().convertType(bytes, offset + 1, length - 1, fieldValueBufferOutput);
} catch (IOException e) {
throw new HyracksDataException("A numeric type promotion error has occurred before doing hash(). Can't continue process. Detailed Error message:" + e.getMessage());
}
numericTypePromotionApplied = true;
break;
case FLOAT:
try {
FloatToDoubleTypeConvertComputer.getInstance().convertType(bytes, offset + 1, length - 1, fieldValueBufferOutput);
} catch (IOException e) {
throw new HyracksDataException("A numeric type promotion error has occurred before doing hash(). Can't continue process. Detailed Error message:" + e.getMessage());
}
numericTypePromotionApplied = true;
break;
default:
numericTypePromotionApplied = false;
break;
}
// If a numeric type promotion happened
if (numericTypePromotionApplied) {
return MurmurHash3BinaryHash.hash(fieldValueBuffer.getByteArray(), fieldValueBuffer.getStartOffset(), fieldValueBuffer.getLength(), seed);
} else {
// Usual case for non numeric types and the DOBULE numeric type
return MurmurHash3BinaryHash.hash(bytes, offset, length, seed);
}
}
};
}
use of java.io.DataOutput in project asterixdb by apache.
the class IntegerParserFactory method createValueParser.
@Override
public IValueParser createValueParser() {
return new IValueParser() {
@Override
public void parse(char[] buffer, int start, int length, DataOutput out) throws HyracksDataException {
int n = 0;
int sign = 1;
int i = 0;
boolean pre = true;
for (; pre && i < length; ++i) {
char ch = buffer[i + start];
switch(ch) {
case ' ':
case '\t':
case '\n':
case '\r':
case '\f':
break;
case '-':
sign = -1;
pre = false;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
pre = false;
n = n * 10 + (ch - '0');
break;
default:
String errorString = new String(buffer, i + start, length - i);
throw new HyracksDataException("Integer Parser - a digit is expected. But, encountered this character: " + ch + " in the incoming input: " + errorString);
}
}
boolean post = false;
for (; !post && i < length; ++i) {
char ch = buffer[i + start];
switch(ch) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
n = n * 10 + (ch - '0');
break;
default:
String errorString = new String(buffer, i + start, length - i);
throw new HyracksDataException("Integer Parser - a digit is expected. But, encountered this character: " + ch + " in the incoming input: " + errorString);
}
}
for (; i < length; ++i) {
char ch = buffer[i + start];
switch(ch) {
case ' ':
case '\t':
case '\n':
case '\r':
case '\f':
break;
default:
String errorString = new String(buffer, i + start, length - i);
throw new HyracksDataException("Integer Parser - a whitespace, tab, new line, or " + "form-feed expected. But, encountered this character: " + ch + " in the incoming input: " + errorString);
}
}
try {
out.writeInt(n * sign);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
};
}
Aggregations