use of org.apache.asterix.om.base.AMutableInt32 in project asterixdb by apache.
the class ClassAdUnitTester method testUtils.
/*********************************************************************
* Function: test_utils
* Purpose: Test utils
*********************************************************************/
public static void testUtils(Parameters parameters, Results results) {
System.out.println("Testing little utilities...");
test("1800 is not a leap year", !Util.isLeapYear(1800), results);
test("1900 is not a leap year", !Util.isLeapYear(1900), results);
test("2000 is a leap year", Util.isLeapYear(2000), results);
test("2001 is not a leap year", !Util.isLeapYear(2001), results);
test("2002 is not a leap year", !Util.isLeapYear(2002), results);
test("2003 is not a leap year", !Util.isLeapYear(2003), results);
test("2004 is a leap year", Util.isLeapYear(2004), results);
test("70, 9, 24 . 25469", Util.fixedFromGregorian(70, 9, 24) == 25469, results);
test("135, 10, 2 . 49217", Util.fixedFromGregorian(135, 10, 2) == 49217, results);
test("470, 1, 8 . 171307", Util.fixedFromGregorian(470, 1, 8) == 171307, results);
test("576, 5, 20 . 210155", Util.fixedFromGregorian(576, 5, 20) == 210155, results);
test("694, 11, 10 . 253427", Util.fixedFromGregorian(694, 11, 10) == 253427, results);
test("1013, 4, 25 . 369740", Util.fixedFromGregorian(1013, 4, 25) == 369740, results);
test("1096, 5, 24 . 400085", Util.fixedFromGregorian(1096, 5, 24) == 400085, results);
test("1190, 3, 23 . 434355", Util.fixedFromGregorian(1190, 3, 23) == 434355, results);
test("1240, 3, 10 . 452605", Util.fixedFromGregorian(1240, 3, 10) == 452605, results);
test("1288, 4, 2 . 470160", Util.fixedFromGregorian(1288, 4, 2) == 470160, results);
test("1298, 4, 27 . 473837", Util.fixedFromGregorian(1298, 4, 27) == 473837, results);
test("1391, 6, 12 . 507850", Util.fixedFromGregorian(1391, 6, 12) == 507850, results);
test("1436, 2, 3 . 524156", Util.fixedFromGregorian(1436, 2, 3) == 524156, results);
test("1492, 4, 9 . 544676", Util.fixedFromGregorian(1492, 4, 9) == 544676, results);
test("1553, 9, 19 . 567118", Util.fixedFromGregorian(1553, 9, 19) == 567118, results);
test("1560, 3, 5 . 569477", Util.fixedFromGregorian(1560, 3, 5) == 569477, results);
test("1648, 6, 10 . 601716", Util.fixedFromGregorian(1648, 6, 10) == 601716, results);
test("1680, 6, 30 . 613424", Util.fixedFromGregorian(1680, 6, 30) == 613424, results);
test("1716, 7, 24 . 626596", Util.fixedFromGregorian(1716, 7, 24) == 626596, results);
test("1768, 6, 19 . 645554", Util.fixedFromGregorian(1768, 6, 19) == 645554, results);
test("1819, 8, 2 . 664224", Util.fixedFromGregorian(1819, 8, 2) == 664224, results);
test("1839, 3, 27 . 671401", Util.fixedFromGregorian(1839, 3, 27) == 671401, results);
test("1903, 4, 19 . 694799", Util.fixedFromGregorian(1903, 4, 19) == 694799, results);
test("1929, 8, 25 . 704424", Util.fixedFromGregorian(1929, 8, 25) == 704424, results);
test("1941, 9, 29 . 708842", Util.fixedFromGregorian(1941, 9, 29) == 708842, results);
test("1943, 4, 19 . 709409", Util.fixedFromGregorian(1943, 4, 19) == 709409, results);
test("1943, 10, 7 . 709580", Util.fixedFromGregorian(1943, 10, 7) == 709580, results);
test("1992, 3, 17 . 727274", Util.fixedFromGregorian(1992, 3, 17) == 727274, results);
test("1996, 2, 25 . 728714", Util.fixedFromGregorian(1996, 2, 25) == 728714, results);
test("2038, 11, 10 . 744313", Util.fixedFromGregorian(2038, 11, 10) == 744313, results);
test("2094, 7, 18 . 764652", Util.fixedFromGregorian(2094, 7, 18) == 764652, results);
AMutableInt32 weekday = new AMutableInt32(0);
AMutableInt32 yearday = new AMutableInt32(0);
Util.dayNumbers(2005, 1, 1, weekday, yearday);
test("Jan 1, 2005.6, 0", weekday.getIntegerValue() == 6 && yearday.getIntegerValue() == 0, results);
Util.dayNumbers(2005, 1, 2, weekday, yearday);
test("Jan 2, 2005.6, 1", weekday.getIntegerValue() == 0 && yearday.getIntegerValue() == 1, results);
Util.dayNumbers(2005, 12, 30, weekday, yearday);
test("Dec 30, 2005.5, 363", weekday.getIntegerValue() == 5 && yearday.getIntegerValue() == 363, results);
Util.dayNumbers(2005, 12, 31, weekday, yearday);
test("Dec 31, 2005.6, 364", weekday.getIntegerValue() == 6 && yearday.getIntegerValue() == 364, results);
Util.dayNumbers(2004, 12, 31, weekday, yearday);
test("Dec 31, 2005.5, 365", weekday.getIntegerValue() == 5 && yearday.getIntegerValue() == 365, results);
return;
}
use of org.apache.asterix.om.base.AMutableInt32 in project asterixdb by apache.
the class ClassAdUnitTester method test.
/*********************************************************************
* Function: main
* Purpose: The main control loop.
*
* @throws IOException
*********************************************************************/
public static boolean test(int argc, String[] argv, ClassAdObjectPool objectPool) throws IOException {
AMutableInt32 numberOfErrors = new AMutableInt32(0);
AMutableInt32 numberOfTests = new AMutableInt32(0);
boolean have_errors;
Parameters parameters = new Parameters();
/* ----- Setup ----- */
printVersion();
parameters.ParseCommandLine(argc, argv);
Results results = new Results(parameters);
/* ----- Run tests ----- */
if (parameters.checkAll || parameters.checkParsing) {
testParsing(parameters, results, objectPool);
}
if (parameters.checkAll || parameters.checkClassad) {
try {
testClassad(parameters, results, objectPool);
} catch (Throwable th) {
th.printStackTrace();
throw th;
}
}
if (parameters.checkAll || parameters.checkExprlist) {
testExprList(parameters, results, objectPool);
}
if (parameters.checkAll || parameters.checkValue) {
testValue(parameters, results, objectPool);
}
if (parameters.checkAll || parameters.checkLiteral) {
}
if (parameters.checkAll || parameters.checkMatch) {
}
if (parameters.checkAll || parameters.checkOperator) {
}
if (parameters.checkAll || parameters.checkCollection) {
// test_collection(parameters, results);
}
if (parameters.checkAll || parameters.checkUtils) {
testUtils(parameters, results);
}
/* ----- Report ----- */
System.out.println();
results.GetResults(numberOfErrors, numberOfTests);
if (numberOfErrors.getIntegerValue() > 0) {
have_errors = true;
System.out.println("Finished with errors: ");
System.out.println(" " + numberOfErrors + " errors");
System.out.println(" " + numberOfTests + " tests");
} else {
have_errors = false;
System.out.println("Finished with no errors.");
System.out.println(" " + numberOfTests + " tests");
}
return have_errors;
}
use of org.apache.asterix.om.base.AMutableInt32 in project asterixdb by apache.
the class NumericRoundDescriptor 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 argPtr = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private AMutableDouble aDouble = new AMutableDouble(0);
private AMutableFloat aFloat = new AMutableFloat(0);
private AMutableInt64 aInt64 = new AMutableInt64(0);
private AMutableInt32 aInt32 = new AMutableInt32(0);
private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
@SuppressWarnings("rawtypes")
private ISerializerDeserializer serde;
@SuppressWarnings("unchecked")
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
byte[] data = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);
aInt8.setValue(val);
serde.serialize(aInt8, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT16);
short val = AInt16SerializerDeserializer.getShort(data, offset + 1);
aInt16.setValue(val);
serde.serialize(aInt16, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
int val = AInt32SerializerDeserializer.getInt(data, offset + 1);
aInt32.setValue(val);
serde.serialize(aInt32, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
long val = AInt64SerializerDeserializer.getLong(data, offset + 1);
aInt64.setValue(val);
serde.serialize(aInt64, out);
} else if (data[offset] == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
float val = AFloatSerializerDeserializer.getFloat(data, offset + 1);
val = Math.round(val);
aFloat.setValue(val);
serde.serialize(aFloat, out);
} else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
val = Math.round(val);
aDouble.setValue(val);
serde.serialize(aDouble, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, data[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG, ATypeTag.SERIALIZED_FLOAT_TYPE_TAG, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.om.base.AMutableInt32 in project asterixdb by apache.
the class NumericRoundHalfToEvenDescriptor 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 argPtr = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private AMutableDouble aDouble = new AMutableDouble(0);
private AMutableFloat aFloat = new AMutableFloat(0);
private AMutableInt64 aInt64 = new AMutableInt64(0);
private AMutableInt32 aInt32 = new AMutableInt32(0);
private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
@SuppressWarnings("rawtypes")
private ISerializerDeserializer serde;
@SuppressWarnings("unchecked")
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
byte[] data = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);
aInt8.setValue(val);
serde.serialize(aInt8, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT16);
short val = AInt16SerializerDeserializer.getShort(data, offset + 1);
aInt16.setValue(val);
serde.serialize(aInt16, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
int val = AInt32SerializerDeserializer.getInt(data, offset + 1);
aInt32.setValue(val);
serde.serialize(aInt32, out);
} else if (data[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
long val = AInt64SerializerDeserializer.getLong(data, offset + 1);
aInt64.setValue(val);
serde.serialize(aInt64, out);
} else if (data[offset] == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
float val = AFloatSerializerDeserializer.getFloat(data, offset + 1);
aFloat.setValue((float) Math.rint(val));
serde.serialize(aFloat, out);
} else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
aDouble.setValue(Math.rint(val));
serde.serialize(aDouble, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, data[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG, ATypeTag.SERIALIZED_FLOAT_TYPE_TAG, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.om.base.AMutableInt32 in project asterixdb by apache.
the class NumericSubtractDescriptor 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();
// one temp. buffer re-used by both children
private IPointable argPtr = new VoidPointable();
private IScalarEvaluator evalLeft = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator evalRight = args[1].createScalarEvaluator(ctx);
private double[] operands = new double[args.length];
private boolean metInt8 = false, metInt16 = false, metInt32 = false, metInt64 = false, metFloat = false, metDouble = false;
private ATypeTag typeTag;
private AMutableDouble aDouble = new AMutableDouble(0);
private AMutableFloat aFloat = new AMutableFloat(0);
private AMutableInt64 aInt64 = new AMutableInt64(0);
private AMutableInt32 aInt32 = new AMutableInt32(0);
private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
@SuppressWarnings("rawtypes")
private ISerializerDeserializer serde;
@SuppressWarnings("unchecked")
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
for (int i = 0; i < args.length; i++) {
if (i == 0) {
evalLeft.evaluate(tuple, argPtr);
} else {
evalRight.evaluate(tuple, argPtr);
}
byte[] data = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]);
switch(typeTag) {
case TINYINT:
metInt8 = true;
operands[i] = AInt8SerializerDeserializer.getByte(data, offset + 1);
break;
case SMALLINT:
metInt16 = true;
operands[i] = AInt16SerializerDeserializer.getShort(data, offset + 1);
break;
case INTEGER:
metInt32 = true;
operands[i] = AInt32SerializerDeserializer.getInt(data, offset + 1);
break;
case BIGINT:
metInt64 = true;
operands[i] = AInt64SerializerDeserializer.getLong(data, offset + 1);
break;
case FLOAT:
metFloat = true;
operands[i] = AFloatSerializerDeserializer.getFloat(data, offset + 1);
break;
case DOUBLE:
metDouble = true;
operands[i] = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
break;
default:
throw new TypeMismatchException(getIdentifier(), i, data[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG, ATypeTag.SERIALIZED_FLOAT_TYPE_TAG, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
}
}
if (metDouble) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
aDouble.setValue(operands[0] - operands[1]);
serde.serialize(aDouble, out);
} else if (metFloat) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
aFloat.setValue((float) (operands[0] - operands[1]));
serde.serialize(aFloat, out);
} else if (metInt64) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
aInt64.setValue((long) (operands[0] - operands[1]));
serde.serialize(aInt64, out);
} else if (metInt32) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
aInt32.setValue((int) (operands[0] - operands[1]));
serde.serialize(aInt32, out);
} else if (metInt16) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT16);
aInt16.setValue((short) (operands[0] - operands[1]));
serde.serialize(aInt16, out);
} else if (metInt8) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
aInt8.setValue((byte) (operands[0] - operands[1]));
serde.serialize(aInt8, out);
}
result.set(resultStorage);
}
};
}
};
}
Aggregations