use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class TemporalMonthAccessor 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.getDurationMonth(ADurationSerializerDeserializer.getYearMonth(bytes, startOffset + 1)));
intSerde.serialize(aMutableInt64, out);
result.set(resultStorage);
return;
}
if (bytes[startOffset] == ATypeTag.SERIALIZED_YEAR_MONTH_DURATION_TYPE_TAG) {
aMutableInt64.setValue(calSystem.getDurationMonth(AYearMonthDurationSerializerDeserializer.getYearMonth(bytes, startOffset + 1)));
intSerde.serialize(aMutableInt64, out);
result.set(resultStorage);
return;
}
long chrononTimeInMs = 0;
if (bytes[startOffset] == ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, startOffset + 1) * GregorianCalendarSystem.CHRONON_OF_DAY;
} 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_YEAR_MONTH_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_DATE_TYPE_TAG, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
int year = calSystem.getYear(chrononTimeInMs);
int month = calSystem.getMonthOfYear(chrononTimeInMs, year);
aMutableInt64.setValue(month);
intSerde.serialize(aMutableInt64, out);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class Value method convertValueToRealValue.
public static boolean convertValueToRealValue(Value value, Value realValue, ClassAdObjectPool objectPool) throws HyracksDataException {
boolean could_convert;
AMutableCharArrayString buf = objectPool.strPool.get();
int endIndex;
char end;
AMutableInt64 ivalue = objectPool.int64Pool.get();
ClassAdTime atvalue = objectPool.classAdTimePool.get();
MutableBoolean bvalue = objectPool.boolPool.get();
double rvalue;
NumberFactor nf = NumberFactor.NO_FACTOR;
switch(value.getType()) {
case UNDEFINED_VALUE:
realValue.setUndefinedValue();
could_convert = false;
break;
case ERROR_VALUE:
case CLASSAD_VALUE:
case LIST_VALUE:
case SLIST_VALUE:
realValue.setErrorValue();
could_convert = false;
break;
case STRING_VALUE:
could_convert = true;
value.isStringValue(buf);
endIndex = buf.fistNonDoubleDigitChar();
if (endIndex < 0) {
// no non digit
String buffString = buf.toString();
if (buffString.contains("INF")) {
buffString = buffString.replace("INF", "Infinity");
}
rvalue = Double.parseDouble(buffString);
nf = NumberFactor.NO_FACTOR;
} else {
rvalue = Double.parseDouble(buf.substr(0, endIndex));
end = buf.charAt(endIndex);
switch(Character.toUpperCase(end)) {
case 'B':
nf = NumberFactor.B_FACTOR;
break;
case 'K':
nf = NumberFactor.K_FACTOR;
break;
case 'M':
nf = NumberFactor.M_FACTOR;
break;
case 'G':
nf = NumberFactor.G_FACTOR;
break;
case 'T':
nf = NumberFactor.T_FACTOR;
break;
case '\0':
nf = NumberFactor.NO_FACTOR;
break;
default:
nf = NumberFactor.NO_FACTOR;
break;
}
}
if (could_convert) {
realValue.setRealValue(rvalue * Value.ScaleFactor[nf.ordinal()]);
}
break;
case BOOLEAN_VALUE:
value.isBooleanValue(bvalue);
realValue.setRealValue(bvalue.booleanValue() ? 1.0 : 0.0);
could_convert = true;
break;
case INTEGER_VALUE:
value.isIntegerValue(ivalue);
realValue.setRealValue(ivalue.getLongValue());
could_convert = true;
break;
case REAL_VALUE:
realValue.setValue(value);
could_convert = true;
break;
case ABSOLUTE_TIME_VALUE:
value.isAbsoluteTimeValue(atvalue);
realValue.setRealValue(atvalue.getTimeInMillis() / 1000.0);
could_convert = true;
break;
case RELATIVE_TIME_VALUE:
value.isRelativeTimeValue(atvalue);
realValue.setRealValue(atvalue.getRelativeTime() / 1000.0);
could_convert = true;
break;
default:
// Make gcc's -Wuninitalized happy
could_convert = false;
throw new HyracksDataException("Should not reach here");
}
return could_convert;
}
use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class Value method convertValueToIntegerValue.
public static boolean convertValueToIntegerValue(Value value, Value integerValue, ClassAdObjectPool objectPool) throws HyracksDataException {
boolean could_convert;
AMutableCharArrayString buf = objectPool.strPool.get();
char end;
AMutableInt64 ivalue = objectPool.int64Pool.get();
AMutableDouble rtvalue = objectPool.doublePool.get();
ClassAdTime atvalue = objectPool.classAdTimePool.get();
MutableBoolean bvalue = objectPool.boolPool.get();
NumberFactor nf;
switch(value.getType()) {
case UNDEFINED_VALUE:
integerValue.setUndefinedValue();
could_convert = false;
break;
case ERROR_VALUE:
case CLASSAD_VALUE:
case LIST_VALUE:
case SLIST_VALUE:
integerValue.setErrorValue();
could_convert = false;
break;
case STRING_VALUE:
could_convert = true;
value.isStringValue(buf);
int endIndex = buf.firstNonDigitChar();
if (endIndex < 0) {
// no non digit
ivalue.setValue(Long.parseLong(buf.toString()));
nf = NumberFactor.NO_FACTOR;
break;
} else {
ivalue.setValue(Long.parseLong(buf.substr(0, endIndex)));
end = buf.charAt(endIndex);
switch(Character.toUpperCase(end)) {
case 'B':
nf = NumberFactor.B_FACTOR;
break;
case 'K':
nf = NumberFactor.K_FACTOR;
break;
case 'M':
nf = NumberFactor.M_FACTOR;
break;
case 'G':
nf = NumberFactor.G_FACTOR;
break;
case 'T':
nf = NumberFactor.T_FACTOR;
break;
case '\0':
nf = NumberFactor.NO_FACTOR;
break;
default:
nf = NumberFactor.NO_FACTOR;
break;
}
if (could_convert) {
integerValue.setIntegerValue((long) ((ivalue.getLongValue() * Value.ScaleFactor[nf.ordinal()])));
}
}
break;
case BOOLEAN_VALUE:
value.isBooleanValue(bvalue);
integerValue.setIntegerValue(bvalue.booleanValue() ? 1 : 0);
could_convert = true;
break;
case INTEGER_VALUE:
integerValue.setValue(value);
could_convert = true;
break;
case REAL_VALUE:
value.isRealValue(rtvalue);
integerValue.setIntegerValue((long) rtvalue.getDoubleValue());
could_convert = true;
break;
case ABSOLUTE_TIME_VALUE:
value.isAbsoluteTimeValue(atvalue);
integerValue.setIntegerValue(atvalue.getTimeInMillis() / 1000L);
could_convert = true;
break;
case RELATIVE_TIME_VALUE:
value.isRelativeTimeValue(atvalue);
integerValue.setIntegerValue((atvalue.getTime() / 1000L));
could_convert = true;
break;
default:
// Make gcc's -Wuninitalized happy
could_convert = false;
throw new HyracksDataException("Should not reach here");
}
return could_convert;
}
use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class Literal method privateEvaluate.
@Override
public boolean privateEvaluate(EvalState eval, Value val) throws HyracksDataException {
AMutableInt64 i = objectPool.int64Pool.get();
AMutableDouble r = objectPool.doublePool.get();
val.setValue(value);
// if integer or real, multiply by the factor
if (val.isIntegerValue(i)) {
if (factor != NumberFactor.NO_FACTOR) {
val.setRealValue((i.getLongValue()) * Value.ScaleFactor[factor.ordinal()]);
} else {
val.setIntegerValue(i.getLongValue());
}
} else if (val.isRealValue(r)) {
val.setRealValue(r.getDoubleValue() * Value.ScaleFactor[factor.ordinal()]);
}
return true;
}
use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class Literal method GetValue.
public void GetValue(Value val) throws HyracksDataException {
AMutableInt64 i = objectPool.int64Pool.get();
AMutableDouble r = objectPool.doublePool.get();
val.setValue(value);
// if integer or real, multiply by the factor
if (val.isIntegerValue(i)) {
if (factor != NumberFactor.NO_FACTOR) {
val.setRealValue((i.getLongValue()) * Value.ScaleFactor[factor.ordinal()]);
}
} else if (val.isRealValue(r)) {
if (factor != NumberFactor.NO_FACTOR) {
val.setRealValue(r.getDoubleValue() * Value.ScaleFactor[factor.ordinal()]);
}
}
}
Aggregations