TYPE_PRECEDENCE = initializeTypePrecedence();
/**
*
@@ -88,8 +114,8 @@ public int compare(Datum lhs, Datum rhs) {
}
// Invoke the Comparison Table
- int lhsKind = lhs.getType().getKind().ordinal();
- int rhsKind = rhs.getType().getKind().ordinal();
+ int lhsKind = lhs.getType().code();
+ int rhsKind = rhs.getType().code();
return COMPARISON_TABLE[lhsKind][rhsKind].apply(lhs, rhs, this);
}
@@ -136,46 +162,45 @@ int rhsUnknown() {
* @see #TYPE_PRECEDENCE
*/
@NotNull
- @SuppressWarnings("deprecation")
- private static Map initializeTypePrecedence() {
- Map precedence = new HashMap<>();
+ private static Map initializeTypePrecedence() {
+ Map precedence = new HashMap<>();
// Boolean Type
- precedence.put(PType.Kind.BOOL, 0);
+ precedence.put(BOOL, 0);
// Number Types
- precedence.put(PType.Kind.TINYINT, 1);
- precedence.put(PType.Kind.SMALLINT, 1);
- precedence.put(PType.Kind.INTEGER, 1);
- precedence.put(PType.Kind.BIGINT, 1);
- precedence.put(PType.Kind.NUMERIC, 1);
- precedence.put(PType.Kind.DECIMAL, 1);
- precedence.put(PType.Kind.REAL, 1);
- precedence.put(PType.Kind.DOUBLE, 1);
+ precedence.put(TINYINT, 1);
+ precedence.put(SMALLINT, 1);
+ precedence.put(INTEGER, 1);
+ precedence.put(BIGINT, 1);
+ precedence.put(NUMERIC, 1);
+ precedence.put(DECIMAL, 1);
+ precedence.put(REAL, 1);
+ precedence.put(DOUBLE, 1);
// Date Type
- precedence.put(PType.Kind.DATE, 2);
+ precedence.put(DATE, 2);
// Time Type
- precedence.put(PType.Kind.TIMEZ, 3);
- precedence.put(PType.Kind.TIME, 3);
+ precedence.put(TIMEZ, 3);
+ precedence.put(TIME, 3);
// Timestamp Types
- precedence.put(PType.Kind.TIMESTAMPZ, 4);
- precedence.put(PType.Kind.TIMESTAMP, 4);
+ precedence.put(TIMESTAMPZ, 4);
+ precedence.put(TIMESTAMP, 4);
// Text Types
- precedence.put(PType.Kind.CHAR, 5);
- precedence.put(PType.Kind.VARCHAR, 5);
- precedence.put(PType.Kind.STRING, 5);
+ precedence.put(CHAR, 5);
+ precedence.put(PType.VARCHAR, 5);
+ precedence.put(STRING, 5);
// LOB Types
- precedence.put(PType.Kind.CLOB, 6);
- precedence.put(PType.Kind.BLOB, 6);
+ precedence.put(CLOB, 6);
+ precedence.put(BLOB, 6);
// Array Type
- precedence.put(PType.Kind.ARRAY, 7);
+ precedence.put(ARRAY, 7);
// Tuple Type
- precedence.put(PType.Kind.ROW, 9);
- precedence.put(PType.Kind.STRUCT, 9);
+ precedence.put(PType.ROW, 9);
+ precedence.put(STRUCT, 9);
// Bag Type
- precedence.put(PType.Kind.BAG, 10);
+ precedence.put(BAG, 10);
// OTHER
- precedence.put(PType.Kind.DYNAMIC, 100);
- precedence.put(PType.Kind.UNKNOWN, 100);
- precedence.put(PType.Kind.VARIANT, 100);
+ precedence.put(DYNAMIC, 100);
+ precedence.put(UNKNOWN, 100);
+ precedence.put(PType.VARIANT, 100);
return precedence;
}
@@ -188,16 +213,15 @@ private static Map initializeTypePrecedence() {
* need to have their JVM primitives extracted before making comparison judgements.
*
* @return the 2D comparison table
- * @see #initializeComparatorArray(PType.Kind)
+ * @see #initializeComparatorArray(int)
* @see #fillIntComparator(DatumComparison[])
*/
- @SuppressWarnings("deprecation")
private static DatumComparison[][] initializeComparators() {
// Initialize Table
DatumComparison[][] table = new DatumComparison[TYPE_KINDS_LENGTH][TYPE_KINDS_LENGTH];
for (int i = 0; i < TYPE_KINDS_LENGTH; i++) {
@SuppressWarnings("ConstantConditions")
- PType.Kind kind = TYPE_KINDS[i];
+ int kind = TYPE_KINDS[i];
DatumComparison[] row = initializeComparatorArray(kind);
table[i] = row;
switch (kind) {
@@ -269,85 +293,85 @@ private static DatumComparison[][] initializeComparators() {
return table;
}
- @SuppressWarnings("deprecation")
+ @SuppressWarnings({"UnusedReturnValue", "deprecation"})
private static DatumComparison[] fillTinyIntComparator(DatumComparison[] comps) {
- comps[PType.Kind.TINYINT.ordinal()] = (self, tinyInt, comp) -> Byte.compare(self.getByte(), tinyInt.getByte());
- comps[PType.Kind.SMALLINT.ordinal()] = (self, smallInt, comp) -> Short.compare(self.getByte(), smallInt.getShort());
- comps[PType.Kind.INTEGER.ordinal()] = (self, intNum, comp) -> Integer.compare(self.getByte(), intNum.getInt());
- comps[PType.Kind.BIGINT.ordinal()] = (self, bigInt, comp) -> Long.compare(self.getByte(), bigInt.getLong());
- comps[PType.Kind.NUMERIC.ordinal()] = (self, intArbitrary, comp) -> BigInteger.valueOf(self.getByte()).compareTo(intArbitrary.getBigInteger());
- comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> Float.compare(self.getByte(), real.getFloat()));
- comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> Double.compare(self.getByte(), doublePrecision.getDouble()));
- comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> BigDecimal.valueOf(self.getByte()).compareTo(decimal.getBigDecimal());
+ comps[TINYINT] = (self, tinyInt, comp) -> Byte.compare(self.getByte(), tinyInt.getByte());
+ comps[SMALLINT] = (self, smallInt, comp) -> Short.compare(self.getByte(), smallInt.getShort());
+ comps[INTEGER] = (self, intNum, comp) -> Integer.compare(self.getByte(), intNum.getInt());
+ comps[BIGINT] = (self, bigInt, comp) -> Long.compare(self.getByte(), bigInt.getLong());
+ comps[NUMERIC] = (self, intArbitrary, comp) -> BigInteger.valueOf(self.getByte()).compareTo(intArbitrary.getBigInteger());
+ comps[REAL] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> Float.compare(self.getByte(), real.getFloat()));
+ comps[DOUBLE] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> Double.compare(self.getByte(), doublePrecision.getDouble()));
+ comps[DECIMAL] = (self, decimal, comp) -> BigDecimal.valueOf(self.getByte()).compareTo(decimal.getBigDecimal());
return comps;
}
- @SuppressWarnings("deprecation")
+ @SuppressWarnings({"UnusedReturnValue", "deprecation"})
private static DatumComparison[] fillSmallIntComparator(DatumComparison[] comps) {
- comps[PType.Kind.TINYINT.ordinal()] = (self, tinyInt, comp) -> Short.compare(self.getShort(), tinyInt.getByte());
- comps[PType.Kind.SMALLINT.ordinal()] = (self, smallInt, comp) -> Short.compare(self.getShort(), smallInt.getShort());
- comps[PType.Kind.INTEGER.ordinal()] = (self, intNum, comp) -> Integer.compare(self.getShort(), intNum.getInt());
- comps[PType.Kind.BIGINT.ordinal()] = (self, bigInt, comp) -> Long.compare(self.getShort(), bigInt.getLong());
- comps[PType.Kind.NUMERIC.ordinal()] = (self, intArbitrary, comp) -> BigInteger.valueOf(self.getShort()).compareTo(intArbitrary.getBigInteger());
- comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> Float.compare(self.getShort(), real.getFloat()));
- comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> Double.compare(self.getShort(), doublePrecision.getDouble()));
- comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> BigDecimal.valueOf(self.getShort()).compareTo(decimal.getBigDecimal());
+ comps[TINYINT] = (self, tinyInt, comp) -> Short.compare(self.getShort(), tinyInt.getByte());
+ comps[SMALLINT] = (self, smallInt, comp) -> Short.compare(self.getShort(), smallInt.getShort());
+ comps[INTEGER] = (self, intNum, comp) -> Integer.compare(self.getShort(), intNum.getInt());
+ comps[BIGINT] = (self, bigInt, comp) -> Long.compare(self.getShort(), bigInt.getLong());
+ comps[NUMERIC] = (self, intArbitrary, comp) -> BigInteger.valueOf(self.getShort()).compareTo(intArbitrary.getBigInteger());
+ comps[REAL] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> Float.compare(self.getShort(), real.getFloat()));
+ comps[DOUBLE] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> Double.compare(self.getShort(), doublePrecision.getDouble()));
+ comps[DECIMAL] = (self, decimal, comp) -> BigDecimal.valueOf(self.getShort()).compareTo(decimal.getBigDecimal());
return comps;
}
- @SuppressWarnings("deprecation")
+ @SuppressWarnings({"UnusedReturnValue", "deprecation"})
private static DatumComparison[] fillIntComparator(DatumComparison[] comps) {
- comps[PType.Kind.TINYINT.ordinal()] = (self, tinyInt, comp) -> Integer.compare(self.getInt(), tinyInt.getByte());
- comps[PType.Kind.SMALLINT.ordinal()] = (self, smallInt, comp) -> Integer.compare(self.getInt(), smallInt.getShort());
- comps[PType.Kind.INTEGER.ordinal()] = (self, intNum, comp) -> Integer.compare(self.getInt(), intNum.getInt());
- comps[PType.Kind.BIGINT.ordinal()] = (self, bigInt, comp) -> Long.compare(self.getInt(), bigInt.getLong());
- comps[PType.Kind.NUMERIC.ordinal()] = (self, intArbitrary, comp) -> BigInteger.valueOf(self.getInt()).compareTo(intArbitrary.getBigInteger());
- comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> Float.compare(self.getInt(), real.getFloat()));
- comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> Double.compare(self.getInt(), doublePrecision.getDouble()));
- comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> BigDecimal.valueOf(self.getInt()).compareTo(decimal.getBigDecimal());
+ comps[TINYINT] = (self, tinyInt, comp) -> Integer.compare(self.getInt(), tinyInt.getByte());
+ comps[SMALLINT] = (self, smallInt, comp) -> Integer.compare(self.getInt(), smallInt.getShort());
+ comps[INTEGER] = (self, intNum, comp) -> Integer.compare(self.getInt(), intNum.getInt());
+ comps[BIGINT] = (self, bigInt, comp) -> Long.compare(self.getInt(), bigInt.getLong());
+ comps[NUMERIC] = (self, intArbitrary, comp) -> BigInteger.valueOf(self.getInt()).compareTo(intArbitrary.getBigInteger());
+ comps[REAL] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> Float.compare(self.getInt(), real.getFloat()));
+ comps[DOUBLE] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> Double.compare(self.getInt(), doublePrecision.getDouble()));
+ comps[DECIMAL] = (self, decimal, comp) -> BigDecimal.valueOf(self.getInt()).compareTo(decimal.getBigDecimal());
return comps;
}
- @SuppressWarnings("deprecation")
+ @SuppressWarnings({"UnusedReturnValue", "deprecation"})
private static DatumComparison[] fillBigIntComparator(DatumComparison[] comps) {
- comps[PType.Kind.TINYINT.ordinal()] = (self, tinyInt, comp) -> Long.compare(self.getLong(), tinyInt.getByte());
- comps[PType.Kind.SMALLINT.ordinal()] = (self, smallInt, comp) -> Long.compare(self.getLong(), smallInt.getShort());
- comps[PType.Kind.INTEGER.ordinal()] = (self, intNum, comp) -> Long.compare(self.getLong(), intNum.getInt());
- comps[PType.Kind.BIGINT.ordinal()] = (self, bigInt, comp) -> Long.compare(self.getLong(), bigInt.getLong());
- comps[PType.Kind.NUMERIC.ordinal()] = (self, intArbitrary, comp) -> BigInteger.valueOf(self.getLong()).compareTo(intArbitrary.getBigInteger());
- comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> Float.compare(self.getLong(), real.getFloat()));
- comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> Double.compare(self.getLong(), doublePrecision.getDouble()));
- comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> BigDecimal.valueOf(self.getLong()).compareTo(decimal.getBigDecimal());
+ comps[TINYINT] = (self, tinyInt, comp) -> Long.compare(self.getLong(), tinyInt.getByte());
+ comps[SMALLINT] = (self, smallInt, comp) -> Long.compare(self.getLong(), smallInt.getShort());
+ comps[INTEGER] = (self, intNum, comp) -> Long.compare(self.getLong(), intNum.getInt());
+ comps[BIGINT] = (self, bigInt, comp) -> Long.compare(self.getLong(), bigInt.getLong());
+ comps[NUMERIC] = (self, intArbitrary, comp) -> BigInteger.valueOf(self.getLong()).compareTo(intArbitrary.getBigInteger());
+ comps[REAL] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> Float.compare(self.getLong(), real.getFloat()));
+ comps[DOUBLE] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> Double.compare(self.getLong(), doublePrecision.getDouble()));
+ comps[DECIMAL] = (self, decimal, comp) -> BigDecimal.valueOf(self.getLong()).compareTo(decimal.getBigDecimal());
return comps;
}
- @SuppressWarnings("deprecation")
+ @SuppressWarnings({"UnusedReturnValue", "deprecation"})
private static DatumComparison[] fillIntArbitraryComparator(DatumComparison[] comps) {
- comps[PType.Kind.TINYINT.ordinal()] = (self, tinyInt, comp) -> self.getBigInteger().compareTo(BigInteger.valueOf(tinyInt.getByte()));
- comps[PType.Kind.SMALLINT.ordinal()] = (self, smallInt, comp) -> self.getBigInteger().compareTo(BigInteger.valueOf(smallInt.getShort()));
- comps[PType.Kind.INTEGER.ordinal()] = (self, intNum, comp) -> self.getBigInteger().compareTo(BigInteger.valueOf(intNum.getInt()));
- comps[PType.Kind.BIGINT.ordinal()] = (self, bigInt, comp) -> self.getBigInteger().compareTo(BigInteger.valueOf(bigInt.getLong()));
- comps[PType.Kind.NUMERIC.ordinal()] = (self, intArbitrary, comp) -> self.getBigInteger().compareTo(intArbitrary.getBigInteger());
- comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> new BigDecimal(self.getBigInteger()).compareTo(BigDecimal.valueOf(real.getFloat())));
- comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> new BigDecimal(self.getBigInteger()).compareTo(BigDecimal.valueOf(doublePrecision.getDouble())));
- comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> new BigDecimal(self.getBigInteger()).compareTo(decimal.getBigDecimal());
+ comps[TINYINT] = (self, tinyInt, comp) -> self.getBigInteger().compareTo(BigInteger.valueOf(tinyInt.getByte()));
+ comps[SMALLINT] = (self, smallInt, comp) -> self.getBigInteger().compareTo(BigInteger.valueOf(smallInt.getShort()));
+ comps[INTEGER] = (self, intNum, comp) -> self.getBigInteger().compareTo(BigInteger.valueOf(intNum.getInt()));
+ comps[BIGINT] = (self, bigInt, comp) -> self.getBigInteger().compareTo(BigInteger.valueOf(bigInt.getLong()));
+ comps[NUMERIC] = (self, intArbitrary, comp) -> self.getBigInteger().compareTo(intArbitrary.getBigInteger());
+ comps[REAL] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> new BigDecimal(self.getBigInteger()).compareTo(BigDecimal.valueOf(real.getFloat())));
+ comps[DOUBLE] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> new BigDecimal(self.getBigInteger()).compareTo(BigDecimal.valueOf(doublePrecision.getDouble())));
+ comps[DECIMAL] = (self, decimal, comp) -> new BigDecimal(self.getBigInteger()).compareTo(decimal.getBigDecimal());
return comps;
}
- @SuppressWarnings("deprecation")
+ @SuppressWarnings({"UnusedReturnValue", "deprecation"})
private static DatumComparison[] fillRealComparator(DatumComparison[] comps) {
- comps[PType.Kind.TINYINT.ordinal()] = (self, tinyInt, comp) -> compareDoubleLhs(self.getFloat(), () -> Float.compare(self.getFloat(), tinyInt.getByte()));
- comps[PType.Kind.SMALLINT.ordinal()] = (self, smallInt, comp) -> compareDoubleLhs(self.getFloat(), () -> Float.compare(self.getFloat(), smallInt.getShort()));
- comps[PType.Kind.INTEGER.ordinal()] = (self, intNum, comp) -> compareDoubleLhs(self.getFloat(), () -> Float.compare(self.getFloat(), intNum.getInt()));
- comps[PType.Kind.BIGINT.ordinal()] = (self, bigInt, comp) -> compareDoubleLhs(self.getFloat(), () -> Float.compare(self.getFloat(), bigInt.getLong()));
- comps[PType.Kind.NUMERIC.ordinal()] = (self, intArbitrary, comp) -> compareDoubleLhs(self.getFloat(), () -> Float.compare(self.getFloat(), intArbitrary.getBigInteger().floatValue()));
- comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubles(self.getFloat(), real.getFloat(), () -> Float.compare(self.getFloat(), real.getFloat()));
- comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> {
+ comps[TINYINT] = (self, tinyInt, comp) -> compareDoubleLhs(self.getFloat(), () -> Float.compare(self.getFloat(), tinyInt.getByte()));
+ comps[SMALLINT] = (self, smallInt, comp) -> compareDoubleLhs(self.getFloat(), () -> Float.compare(self.getFloat(), smallInt.getShort()));
+ comps[INTEGER] = (self, intNum, comp) -> compareDoubleLhs(self.getFloat(), () -> Float.compare(self.getFloat(), intNum.getInt()));
+ comps[BIGINT] = (self, bigInt, comp) -> compareDoubleLhs(self.getFloat(), () -> Float.compare(self.getFloat(), bigInt.getLong()));
+ comps[NUMERIC] = (self, intArbitrary, comp) -> compareDoubleLhs(self.getFloat(), () -> Float.compare(self.getFloat(), intArbitrary.getBigInteger().floatValue()));
+ comps[REAL] = (self, real, comp) -> compareDoubles(self.getFloat(), real.getFloat(), () -> Float.compare(self.getFloat(), real.getFloat()));
+ comps[DOUBLE] = (self, doublePrecision, comp) -> {
float selfFlt = self.getFloat();
double otherDbl = doublePrecision.getDouble();
return compareDoubles(selfFlt, otherDbl, () -> Double.compare(selfFlt, otherDbl));
};
- comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> compareDoubleLhs(self.getFloat(), () -> BigDecimal.valueOf(self.getFloat()).compareTo(decimal.getBigDecimal()));
+ comps[DECIMAL] = (self, decimal, comp) -> compareDoubleLhs(self.getFloat(), () -> BigDecimal.valueOf(self.getFloat()).compareTo(decimal.getBigDecimal()));
return comps;
}
@@ -445,106 +469,112 @@ private static int compareDoubleRhs(double rhs, Supplier comparison) {
return comparison.get();
}
- @SuppressWarnings("deprecation")
+ @SuppressWarnings({"UnusedReturnValue", "deprecation"})
private static DatumComparison[] fillDoubleComparator(DatumComparison[] comps) {
- comps[PType.Kind.TINYINT.ordinal()] = (self, tinyInt, comp) -> compareDoubleLhs(self.getDouble(), () -> Double.compare(self.getDouble(), tinyInt.getByte()));
- comps[PType.Kind.SMALLINT.ordinal()] = (self, smallInt, comp) -> compareDoubleLhs(self.getDouble(), () -> Double.compare(self.getDouble(), smallInt.getShort()));
- comps[PType.Kind.INTEGER.ordinal()] = (self, intNum, comp) -> compareDoubleLhs(self.getDouble(), () -> Double.compare(self.getDouble(), intNum.getInt()));
- comps[PType.Kind.BIGINT.ordinal()] = (self, bigInt, comp) -> compareDoubleLhs(self.getDouble(), () -> Double.compare(self.getDouble(), bigInt.getLong()));
- comps[PType.Kind.NUMERIC.ordinal()] = (self, intArbitrary, comp) -> compareDoubleLhs(self.getDouble(), () -> Double.compare(self.getDouble(), intArbitrary.getBigInteger().doubleValue()));
- comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> {
+ comps[TINYINT] = (self, tinyInt, comp) -> compareDoubleLhs(self.getDouble(), () -> Double.compare(self.getDouble(), tinyInt.getByte()));
+ comps[SMALLINT] = (self, smallInt, comp) -> compareDoubleLhs(self.getDouble(), () -> Double.compare(self.getDouble(), smallInt.getShort()));
+ comps[INTEGER] = (self, intNum, comp) -> compareDoubleLhs(self.getDouble(), () -> Double.compare(self.getDouble(), intNum.getInt()));
+ comps[BIGINT] = (self, bigInt, comp) -> compareDoubleLhs(self.getDouble(), () -> Double.compare(self.getDouble(), bigInt.getLong()));
+ comps[NUMERIC] = (self, intArbitrary, comp) -> compareDoubleLhs(self.getDouble(), () -> Double.compare(self.getDouble(), intArbitrary.getBigInteger().doubleValue()));
+ comps[REAL] = (self, real, comp) -> {
double selfDbl = self.getDouble();
float otherFlt = real.getFloat();
return compareDoubles(selfDbl, otherFlt, () -> Double.compare(selfDbl, otherFlt));
};
- comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubles(self.getDouble(), doublePrecision.getDouble(), () -> Double.compare(self.getDouble(), doublePrecision.getDouble()));
- comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> compareDoubleLhs(self.getDouble(), () -> BigDecimal.valueOf(self.getDouble()).compareTo(decimal.getBigDecimal()));
+ comps[DOUBLE] = (self, doublePrecision, comp) -> compareDoubles(self.getDouble(), doublePrecision.getDouble(), () -> Double.compare(self.getDouble(), doublePrecision.getDouble()));
+ comps[DECIMAL] = (self, decimal, comp) -> compareDoubleLhs(self.getDouble(), () -> BigDecimal.valueOf(self.getDouble()).compareTo(decimal.getBigDecimal()));
return comps;
}
- @SuppressWarnings("deprecation")
+ @SuppressWarnings({"UnusedReturnValue", "deprecation"})
private static DatumComparison[] fillDecimalComparator(DatumComparison[] comps) {
- comps[PType.Kind.TINYINT.ordinal()] = (self, tinyInt, comp) -> self.getBigDecimal().compareTo(BigDecimal.valueOf(tinyInt.getByte()));
- comps[PType.Kind.SMALLINT.ordinal()] = (self, smallInt, comp) -> self.getBigDecimal().compareTo(BigDecimal.valueOf(smallInt.getShort()));
- comps[PType.Kind.INTEGER.ordinal()] = (self, intNum, comp) -> self.getBigDecimal().compareTo(BigDecimal.valueOf(intNum.getInt()));
- comps[PType.Kind.BIGINT.ordinal()] = (self, bigInt, comp) -> self.getBigDecimal().compareTo(BigDecimal.valueOf(bigInt.getLong()));
- comps[PType.Kind.NUMERIC.ordinal()] = (self, intArbitrary, comp) -> self.getBigDecimal().compareTo(new BigDecimal(intArbitrary.getBigInteger()));
- comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> self.getBigDecimal().compareTo(BigDecimal.valueOf(real.getFloat())));
- comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> self.getBigDecimal().compareTo(BigDecimal.valueOf(doublePrecision.getDouble())));
- comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> self.getBigDecimal().compareTo(decimal.getBigDecimal());
+ comps[TINYINT] = (self, tinyInt, comp) -> self.getBigDecimal().compareTo(BigDecimal.valueOf(tinyInt.getByte()));
+ comps[SMALLINT] = (self, smallInt, comp) -> self.getBigDecimal().compareTo(BigDecimal.valueOf(smallInt.getShort()));
+ comps[INTEGER] = (self, intNum, comp) -> self.getBigDecimal().compareTo(BigDecimal.valueOf(intNum.getInt()));
+ comps[BIGINT] = (self, bigInt, comp) -> self.getBigDecimal().compareTo(BigDecimal.valueOf(bigInt.getLong()));
+ comps[NUMERIC] = (self, intArbitrary, comp) -> self.getBigDecimal().compareTo(new BigDecimal(intArbitrary.getBigInteger()));
+ comps[REAL] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> self.getBigDecimal().compareTo(BigDecimal.valueOf(real.getFloat())));
+ comps[DOUBLE] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> self.getBigDecimal().compareTo(BigDecimal.valueOf(doublePrecision.getDouble())));
+ comps[DECIMAL] = (self, decimal, comp) -> self.getBigDecimal().compareTo(decimal.getBigDecimal());
return comps;
}
+ @SuppressWarnings({"UnusedReturnValue"})
private static DatumComparison[] fillDateComparator(DatumComparison[] comps) {
- comps[PType.Kind.DATE.ordinal()] = (self, date, comp) -> self.getDate().compareTo(date.getDate());
+ comps[DATE] = (self, date, comp) -> self.getDate().compareTo(date.getDate());
return comps;
}
/**
- * Used for both {@link PType.Kind#TIME} and {@link PType.Kind#TIMEZ}
+ * Used for both {@link PType#TIME} and {@link PType#TIMEZ}
* @param comps the array of {@link DatumComparison} to modify. Each {@link DatumComparison} is indexed by the other
- * {@link Datum}'s {@link PType.Kind#ordinal()}.
+ * {@link Datum}'s {@link PType#code()}.
* @return the modified array
*/
+ @SuppressWarnings({"UnusedReturnValue"})
private static DatumComparison[] fillTimeComparator(DatumComparison[] comps) {
- comps[PType.Kind.TIME.ordinal()] = (self, time, comp) -> self.getTime().compareTo(time.getTime());
- comps[PType.Kind.TIMEZ.ordinal()] = (self, time, comp) -> self.getTime().compareTo(time.getTime());
+ comps[TIME] = (self, time, comp) -> self.getTime().compareTo(time.getTime());
+ comps[TIMEZ] = (self, time, comp) -> self.getTime().compareTo(time.getTime());
return comps;
}
/**
- * Used for both {@link PType.Kind#TIMESTAMP} and {@link PType.Kind#TIMESTAMPZ}
+ * Used for both {@link PType#TIMESTAMP} and {@link PType#TIMESTAMPZ}
* @param comps the array of {@link DatumComparison} to modify. Each {@link DatumComparison} is indexed by the other
- * {@link Datum}'s {@link PType.Kind#ordinal()}.
+ * {@link Datum}'s {@link PType#code()}.
* @return the modified array
*/
+ @SuppressWarnings({"UnusedReturnValue"})
private static DatumComparison[] fillTimestampComparator(DatumComparison[] comps) {
- comps[PType.Kind.TIMESTAMPZ.ordinal()] = (self, timestamp, comp) -> self.getTimestamp().compareTo(timestamp.getTimestamp());
- comps[PType.Kind.TIMESTAMP.ordinal()] = (self, timestamp, comp) -> self.getTimestamp().compareTo(timestamp.getTimestamp());
+ comps[TIMESTAMPZ] = (self, timestamp, comp) -> self.getTimestamp().compareTo(timestamp.getTimestamp());
+ comps[TIMESTAMP] = (self, timestamp, comp) -> self.getTimestamp().compareTo(timestamp.getTimestamp());
return comps;
}
/**
- * Used for {@link PType.Kind#STRING}, {@link PType.Kind#CHAR}, {@link PType.Kind#VARCHAR}.
+ * Used for {@link PType#STRING}, {@link PType#CHAR}, {@link PType#VARCHAR}.
* @param comps the array of {@link DatumComparison} to modify. Each {@link DatumComparison} is indexed by the other
- * {@link Datum}'s {@link PType.Kind#ordinal()}.
+ * {@link Datum}'s {@link PType#code()}.
* @return the modified array
*/
- @SuppressWarnings("deprecation")
+ @SuppressWarnings({"UnusedReturnValue"})
private static DatumComparison[] fillStringComparator(DatumComparison[] comps) {
- comps[PType.Kind.STRING.ordinal()] = (self, string, comp) -> self.getString().compareTo(string.getString());
- comps[PType.Kind.CHAR.ordinal()] = (self, string, comp) -> self.getString().compareTo(string.getString());
- comps[PType.Kind.VARCHAR.ordinal()] = (self, string, comp) -> self.getString().compareTo(string.getString());
+ comps[STRING] = (self, string, comp) -> self.getString().compareTo(string.getString());
+ comps[CHAR] = (self, string, comp) -> self.getString().compareTo(string.getString());
+ comps[PType.VARCHAR] = (self, string, comp) -> self.getString().compareTo(string.getString());
return comps;
}
/**
* @param comps the array of {@link DatumComparison} to modify. Each {@link DatumComparison} is indexed by the other
- * {@link Datum}'s {@link PType.Kind#ordinal()}.
+ * {@link Datum}'s {@link PType#code()}.
* @return the modified array
*/
+ @SuppressWarnings({"UnusedReturnValue"})
private static DatumComparison[] fillListComparator(DatumComparison[] comps) {
- comps[PType.Kind.ARRAY.ordinal()] = (self, list, comp) -> compareOrdered(self.iterator(), list.iterator(), comp);
+ comps[ARRAY] = (self, list, comp) -> compareOrdered(self.iterator(), list.iterator(), comp);
return comps;
}
/**
* @param comps the array of {@link DatumComparison} to modify. Each {@link DatumComparison} is indexed by the other
- * {@link Datum}'s {@link PType.Kind#ordinal()}.
+ * {@link Datum}'s {@link PType#code()}.
* @return the modified array
*/
+ @SuppressWarnings({"UnusedReturnValue"})
private static DatumComparison[] fillBagComparator(DatumComparison[] comps) {
- comps[PType.Kind.BAG.ordinal()] = DatumComparator::compareUnordered;
+ comps[BAG] = DatumComparator::compareUnordered;
return comps;
}
/**
* @param comps the array of {@link DatumComparison} to modify. Each {@link DatumComparison} is indexed by the other
- * {@link Datum}'s {@link PType.Kind#ordinal()}.
+ * {@link Datum}'s {@link PType#code()}.
* @return the modified array
*/
+ @SuppressWarnings({"UnusedReturnValue"})
private static DatumComparison[] fillBooleanComparator(DatumComparison[] comps) {
- comps[PType.Kind.BOOL.ordinal()] = (self, bool, comp) -> Boolean.compare(self.getBoolean(), bool.getBoolean());
+ comps[BOOL] = (self, bool, comp) -> Boolean.compare(self.getBoolean(), bool.getBoolean());
return comps;
}
@@ -575,28 +605,28 @@ public Byte next() {
}
/**
- * Used for both {@link PType.Kind#BLOB} and {@link PType.Kind#CLOB}.
+ * Used for both {@link PType#BLOB} and {@link PType#CLOB}.
* @param comps the array of {@link DatumComparison} to modify. Each {@link DatumComparison} is indexed by the other
- * {@link Datum}'s {@link PType.Kind#ordinal()}.
+ * {@link Datum}'s {@link PType#code()}.
* @return the modified array
*/
- @SuppressWarnings("deprecation")
+ @SuppressWarnings({"UnusedReturnValue", "deprecation"})
private static DatumComparison[] fillLobComparator(DatumComparison[] comps) {
- comps[PType.Kind.BLOB.ordinal()] = (self, blob, comp) -> compareArray(self.getBytes(), blob.getBytes());
- comps[PType.Kind.CLOB.ordinal()] = (self, blob, comp) -> compareArray(self.getBytes(), blob.getBytes());
+ comps[BLOB] = (self, blob, comp) -> compareArray(self.getBytes(), blob.getBytes());
+ comps[CLOB] = (self, blob, comp) -> compareArray(self.getBytes(), blob.getBytes());
return comps;
}
/**
- * Used for both {@link PType.Kind#STRUCT} and {@link PType.Kind#ROW}.
+ * Used for both {@link PType#STRUCT} and {@link PType#ROW}.
* @param comps the array of {@link DatumComparison} to modify. Each {@link DatumComparison} is indexed by the other
- * {@link Datum}'s {@link PType.Kind#ordinal()}.
+ * {@link Datum}'s {@link PType#code()}.
* @return the modified array
*/
- @SuppressWarnings("deprecation")
+ @SuppressWarnings({"UnusedReturnValue"})
private static DatumComparison[] fillStructComparator(DatumComparison[] comps) {
- comps[PType.Kind.STRUCT.ordinal()] = (self, struct, comp) -> compareUnordered(new DatumFieldIterable(self), new DatumFieldIterable(struct), new FieldComparator(comp));
- comps[PType.Kind.ROW.ordinal()] = (self, row, comp) -> compareOrdered(self.getFields(), row.getFields(), new FieldComparator(comp));
+ comps[STRUCT] = (self, struct, comp) -> compareUnordered(new DatumFieldIterable(self), new DatumFieldIterable(struct), new FieldComparator(comp));
+ comps[PType.ROW] = (self, row, comp) -> compareOrdered(self.getFields(), row.getFields(), new FieldComparator(comp));
return comps;
}
@@ -671,16 +701,16 @@ private static int compareUnordered(Iterable l, Iterable r, Comparator
/**
* @param lhs the original left-hand-side argument's type of {@link Comparator#compare(Object, Object)}.
* @return an array that indicates the type precedence output of {@code lhs.compare(rhs)}. This uses the
- * {@link PType.Kind#ordinal()} to make O(1) judgements. This array will be further modified by type-specific
+ * {@link PType#code() to make O(1) judgements. This array will be further modified by type-specific
* methods.
* @see #fillTinyIntComparator(DatumComparison[])
* @see #fillSmallIntComparator(DatumComparison[])
*/
@NotNull
- private static DatumComparison[] initializeComparatorArray(@NotNull PType.Kind lhs) {
+ private static DatumComparison[] initializeComparatorArray(int lhs) {
DatumComparison[] array = new DatumComparison[TYPE_KINDS_LENGTH];
for (int i = 0; i < TYPE_KINDS_LENGTH; i++) {
- PType.Kind rhs = TYPE_KINDS[i];
+ int rhs = TYPE_KINDS[i];
int lhsPrecedence = TYPE_PRECEDENCE.getOrDefault(lhs, -1);
int rhsPrecedence = TYPE_PRECEDENCE.getOrDefault(rhs, -1);
if (lhsPrecedence < 0) {
diff --git a/partiql-spi/src/main/java/org/partiql/spi/value/DatumInt.java b/partiql-spi/src/main/java/org/partiql/spi/value/DatumInt.java
index ec3e4cee2..388a82977 100644
--- a/partiql-spi/src/main/java/org/partiql/spi/value/DatumInt.java
+++ b/partiql-spi/src/main/java/org/partiql/spi/value/DatumInt.java
@@ -26,4 +26,11 @@ public int getInt() {
public PType getType() {
return _type;
}
+
+ @Override
+ public String toString() {
+ return "DatumInt{" +
+ "_value=" + _value +
+ '}';
+ }
}
diff --git a/partiql-spi/src/main/java/org/partiql/spi/value/DatumNull.java b/partiql-spi/src/main/java/org/partiql/spi/value/DatumNull.java
index b6a773e1e..70da87d9e 100644
--- a/partiql-spi/src/main/java/org/partiql/spi/value/DatumNull.java
+++ b/partiql-spi/src/main/java/org/partiql/spi/value/DatumNull.java
@@ -39,7 +39,7 @@ public PType getType() {
@Override
public boolean getBoolean() {
- if (_type.getKind() == PType.Kind.BOOL) {
+ if (_type.code() == PType.BOOL) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -48,7 +48,7 @@ public boolean getBoolean() {
@Override
public short getShort() {
- if (_type.getKind() == PType.Kind.SMALLINT) {
+ if (_type.code() == PType.SMALLINT) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -57,7 +57,7 @@ public short getShort() {
@Override
public int getInt() {
- if (_type.getKind() == PType.Kind.INTEGER) {
+ if (_type.code() == PType.INTEGER) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -66,7 +66,7 @@ public int getInt() {
@Override
public long getLong() {
- if (_type.getKind() == PType.Kind.BIGINT) {
+ if (_type.code() == PType.BIGINT) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -76,7 +76,7 @@ public long getLong() {
@NotNull
@Override
public BigInteger getBigInteger() {
- if (_type.getKind() == PType.Kind.NUMERIC) {
+ if (_type.code() == PType.NUMERIC) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -86,7 +86,7 @@ public BigInteger getBigInteger() {
@NotNull
@Override
public BigDecimal getBigDecimal() {
- if (_type.getKind() == PType.Kind.DECIMAL) {
+ if (_type.code() == PType.DECIMAL) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -95,7 +95,7 @@ public BigDecimal getBigDecimal() {
@Override
public byte getByte() {
- if (_type.getKind() == PType.Kind.TINYINT) {
+ if (_type.code() == PType.TINYINT) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -105,7 +105,7 @@ public byte getByte() {
@NotNull
@Override
public byte[] getBytes() {
- if (_type.getKind() == PType.Kind.BLOB || _type.getKind() == PType.Kind.CLOB) {
+ if (_type.code() == PType.BLOB || _type.code() == PType.CLOB) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -115,7 +115,7 @@ public byte[] getBytes() {
@NotNull
@Override
public Date getDate() {
- if (_type.getKind() == PType.Kind.DATE) {
+ if (_type.code() == PType.DATE) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -124,7 +124,7 @@ public Date getDate() {
@Override
public double getDouble() {
- if (_type.getKind() == PType.Kind.DOUBLE) {
+ if (_type.code() == PType.DOUBLE) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -133,7 +133,7 @@ public double getDouble() {
@Override
public float getFloat() {
- if (_type.getKind() == PType.Kind.REAL) {
+ if (_type.code() == PType.REAL) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -143,7 +143,7 @@ public float getFloat() {
@NotNull
@Override
public Iterator iterator() {
- if (_type.getKind() == PType.Kind.BAG || _type.getKind() == PType.Kind.ARRAY) {
+ if (_type.code() == PType.BAG || _type.code() == PType.ARRAY) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -153,7 +153,7 @@ public Iterator iterator() {
@NotNull
@Override
public Iterator getFields() {
- if (_type.getKind() == PType.Kind.STRUCT || _type.getKind() == PType.Kind.ROW) {
+ if (_type.code() == PType.STRUCT || _type.code() == PType.ROW) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -163,7 +163,7 @@ public Iterator getFields() {
@NotNull
@Override
public String getString() {
- if (_type.getKind() == PType.Kind.STRING || _type.getKind() == PType.Kind.CHAR) {
+ if (_type.code() == PType.STRING || _type.code() == PType.CHAR) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -173,7 +173,7 @@ public String getString() {
@NotNull
@Override
public Time getTime() {
- if (_type.getKind() == PType.Kind.TIMEZ || _type.getKind() == PType.Kind.TIME) {
+ if (_type.code() == PType.TIMEZ || _type.code() == PType.TIME) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
@@ -183,7 +183,7 @@ public Time getTime() {
@NotNull
@Override
public Timestamp getTimestamp() {
- if (_type.getKind() == PType.Kind.TIMESTAMPZ || _type.getKind() == PType.Kind.TIMESTAMP) {
+ if (_type.code() == PType.TIMESTAMPZ || _type.code() == PType.TIMESTAMP) {
throw new NullPointerException();
} else {
throw new UnsupportedOperationException();
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/Aggregation.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/Aggregation.kt
index 6545d93f3..b6177a345 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/Aggregation.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/Aggregation.kt
@@ -71,8 +71,8 @@ public interface Aggregation : Routine {
override fun getReturnType(args: Array): PType = returns
override fun getAccumulator(args: Array): Accumulator = accumulator()
override fun toString(): String {
- val parameters = parameters.joinToString("__") { it.getType().kind.name }
- val returnType = returns.kind.name
+ val parameters = parameters.joinToString("__") { it.getType().name() }
+ val returnType = returns.name()
return "FN_${name}___${parameters}___$returnType"
}
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/Builtins.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/Builtins.kt
index 4cdc29fa9..cdd7f2f47 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/Builtins.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/Builtins.kt
@@ -23,7 +23,7 @@ internal object Builtins {
Fn_ABS__INT16__INT16,
Fn_ABS__INT32__INT32,
Fn_ABS__INT64__INT64,
- Fn_ABS__INT__INT,
+ Fn_ABS__NUMERIC__NUMERIC,
Fn_ABS__FLOAT32__FLOAT32,
Fn_ABS__FLOAT64__FLOAT64,
Fn_ABS__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY,
@@ -261,7 +261,7 @@ internal object Builtins {
Agg_AVG__INT16__INT16,
Agg_AVG__INT32__INT32,
Agg_AVG__INT64__INT64,
- Agg_AVG__INT__INT,
+ Agg_AVG__NUMERIC__NUMERIC,
Agg_AVG__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY,
Agg_AVG__FLOAT32__FLOAT32,
Agg_AVG__FLOAT64__FLOAT64,
@@ -273,7 +273,7 @@ internal object Builtins {
Agg_MAX__INT16__INT16,
Agg_MAX__INT32__INT32,
Agg_MAX__INT64__INT64,
- Agg_MAX__INT__INT,
+ Agg_MAX__NUMERIC__NUMERIC,
Agg_MAX__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY,
Agg_MAX__FLOAT32__FLOAT32,
Agg_MAX__FLOAT64__FLOAT64,
@@ -293,7 +293,7 @@ internal object Builtins {
Agg_SUM__INT16__INT16,
Agg_SUM__INT32__INT32,
Agg_SUM__INT64__INT64,
- Agg_SUM__INT__INT,
+ Agg_SUM__NUMERIC__NUMERIC,
Agg_SUM__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY,
Agg_SUM__FLOAT32__FLOAT32,
Agg_SUM__FLOAT64__FLOAT64,
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/Function.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/Function.kt
index 64cc0a649..1d949caab 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/Function.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/Function.kt
@@ -123,8 +123,8 @@ public interface Function : Routine {
override fun getInstance(args: Array): Instance = instance
override fun toString(): String {
// TODO debug strings for SqlTypeFamily
- // val parameters = parameters.joinToString("__") { it.getType().kind.name }
- val returnType = returns.kind.name
+ // val parameters = parameters.joinToString("__") { it.getType().PType.name }
+ val returnType = returns.name()
return "FN_${name}___${parameters}___$returnType"
}
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/Parameter.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/Parameter.kt
index 433c251f3..2fa564500 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/Parameter.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/Parameter.kt
@@ -3,7 +3,7 @@ package org.partiql.spi.function
import org.partiql.spi.internal.SqlTypeFamily
import org.partiql.spi.internal.SqlTypes
import org.partiql.types.PType
-import org.partiql.types.PType.Kind.DYNAMIC
+import org.partiql.types.PType.DYNAMIC
/**
* [Parameter] is a formal argument's definition.
@@ -47,7 +47,7 @@ public class Parameter private constructor(
* @param type Parameter type used for function resolution.
*/
public constructor(name: String, type: PType) : this(name, SqlTypeFamily(type)) {
- dynamic = type.kind == DYNAMIC
+ dynamic = type.code() == DYNAMIC
variadic = false
}
@@ -77,7 +77,7 @@ public class Parameter private constructor(
if (dynamic || arg in type) {
return arg // exact match
}
- if (arg.kind == DYNAMIC || SqlTypes.isAssignable(arg, type.preferred)) {
+ if (arg.code() == DYNAMIC || SqlTypes.isAssignable(arg, type.preferred)) {
return type.preferred
}
return null
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggAvg.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggAvg.kt
index 596ff59f9..d78de2bd4 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggAvg.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggAvg.kt
@@ -45,12 +45,12 @@ internal val Agg_AVG__INT64__INT64 = Aggregation.static(
accumulator = ::AccumulatorAvg,
)
-internal val Agg_AVG__INT__INT = Aggregation.static(
+internal val Agg_AVG__NUMERIC__NUMERIC = Aggregation.static(
name = "avg",
returns = AVG_DECIMAL,
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("value", PType.numeric()),
+ Parameter("value", DefaultNumeric.NUMERIC),
),
accumulator = ::AccumulatorAvg,
)
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggMax.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggMax.kt
index 2832b0a60..de8831d7b 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggMax.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggMax.kt
@@ -48,12 +48,12 @@ internal val Agg_MAX__INT64__INT64 = Aggregation.static(
accumulator = ::AccumulatorMax,
)
-internal val Agg_MAX__INT__INT = Aggregation.static(
+internal val Agg_MAX__NUMERIC__NUMERIC = Aggregation.static(
name = "max",
- returns = PType.numeric(),
+ returns = DefaultNumeric.NUMERIC,
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("value", PType.numeric()),
+ Parameter("value", DefaultNumeric.NUMERIC),
),
accumulator = ::AccumulatorMax,
)
@@ -61,9 +61,9 @@ internal val Agg_MAX__INT__INT = Aggregation.static(
internal val Agg_MAX__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY = Aggregation.static(
name = "max",
- returns = PType.decimal(),
+ returns = PType.decimal(38, 19),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("value", PType.decimal()),
+ Parameter("value", PType.decimal(38, 19)), // TODO: Rewrite aggregations using new function modeling.
),
accumulator = ::AccumulatorMax,
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggMin.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggMin.kt
index df1aba810..140f569fe 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggMin.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggMin.kt
@@ -46,18 +46,18 @@ internal val Agg_MIN__INT64__INT64 = Aggregation.static(
internal val Agg_MIN__INT__INT = Aggregation.static(
name = "min",
- returns = PType.numeric(),
+ returns = DefaultNumeric.NUMERIC,
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("value", PType.numeric()),
+ Parameter("value", DefaultNumeric.NUMERIC), // TODO: Rewrite aggregations using new function modeling.
),
accumulator = ::AccumulatorMin,
)
internal val Agg_MIN__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY = Aggregation.static(
name = "min",
- returns = PType.decimal(),
+ returns = PType.decimal(38, 19),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("value", PType.decimal()),
+ Parameter("value", PType.decimal(38, 19)), // TODO: Rewrite aggregations using new function modeling.
),
accumulator = ::AccumulatorMin,
)
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggSum.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggSum.kt
index 8e6ec801e..b661e6dc7 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggSum.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/AggSum.kt
@@ -44,22 +44,22 @@ internal val Agg_SUM__INT64__INT64 = Aggregation.static(
accumulator = { AccumulatorSum(PType.bigint()) },
)
-internal val Agg_SUM__INT__INT = Aggregation.static(
+internal val Agg_SUM__NUMERIC__NUMERIC = Aggregation.static(
name = "sum",
- returns = PType.numeric(),
+ returns = DefaultNumeric.NUMERIC,
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("value", PType.numeric()),
+ Parameter("value", DefaultNumeric.NUMERIC),
),
- accumulator = { AccumulatorSum(PType.numeric()) },
+ accumulator = { AccumulatorSum(DefaultNumeric.NUMERIC) },
)
internal val Agg_SUM__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY = Aggregation.static(
name = "sum",
- returns = PType.decimal(),
+ returns = PType.decimal(38, 19),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("value", PType.decimal()),
+ Parameter("value", PType.decimal(38, 19)), // TODO: Rewrite aggregations using new function modeling.
),
- accumulator = { AccumulatorSum(PType.decimal()) },
+ accumulator = { AccumulatorSum(PType.decimal(38, 19)) },
)
internal val Agg_SUM__FLOAT32__FLOAT32 = Aggregation.static(
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/DefaultNumeric.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/DefaultNumeric.kt
new file mode 100644
index 000000000..cb9d44a30
--- /dev/null
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/DefaultNumeric.kt
@@ -0,0 +1,8 @@
+package org.partiql.spi.function.builtins
+
+import org.partiql.types.PType
+
+internal object DefaultNumeric {
+ // TODO: Once all functions are converted to use the new function modeling, this can be removed.
+ val NUMERIC: PType = PType.numeric(38, 19)
+}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/DiadicComparisonOperator.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/DiadicComparisonOperator.kt
index 9e7a4e82a..948d5af29 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/DiadicComparisonOperator.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/DiadicComparisonOperator.kt
@@ -26,7 +26,7 @@ internal abstract class DiadicComparisonOperator(name: String) : DiadicOperator(
override fun getInstance(args: Array): Function.Instance? {
val lhs = args[0]
val rhs = args[1]
- val hasDecimal = lhs.kind == PType.Kind.DECIMAL || rhs.kind == PType.Kind.DECIMAL
+ val hasDecimal = lhs.code() == PType.DECIMAL || rhs.code() == PType.DECIMAL
val allNumbers = (SqlTypeFamily.NUMBER.contains(lhs) && SqlTypeFamily.NUMBER.contains(rhs))
if (hasDecimal && allNumbers) {
return getNumberInstance(lhs, rhs)
@@ -45,15 +45,15 @@ internal abstract class DiadicComparisonOperator(name: String) : DiadicOperator(
abstract fun getNumberComparison(lhs: Number, rhs: Number): Boolean
private fun Datum.getNumber(): Number {
- return when (this.type.kind) {
- PType.Kind.TINYINT -> this.byte
- PType.Kind.INTEGER -> this.int
- PType.Kind.SMALLINT -> this.short
- PType.Kind.BIGINT -> this.long
- PType.Kind.REAL -> this.float
- PType.Kind.DOUBLE -> this.double
- PType.Kind.DECIMAL -> this.bigDecimal
- PType.Kind.NUMERIC -> this.bigInteger
+ return when (this.type.code()) {
+ PType.TINYINT -> this.byte
+ PType.INTEGER -> this.int
+ PType.SMALLINT -> this.short
+ PType.BIGINT -> this.long
+ PType.REAL -> this.float
+ PType.DOUBLE -> this.double
+ PType.DECIMAL -> this.bigDecimal
+ PType.NUMERIC -> this.bigInteger
else -> error("Unexpected type: ${this.type}")
}
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/DiadicOperator.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/DiadicOperator.kt
index 7e5640974..bd233083c 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/DiadicOperator.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/DiadicOperator.kt
@@ -18,6 +18,13 @@ internal abstract class DiadicOperator(
private val rhs: Parameter
) : Function {
+ companion object {
+ private val DEC_TINY_INT = PType.decimal(3, 0)
+ private val DEC_SMALL_INT = PType.decimal(5, 0)
+ private val DEC_INT = PType.decimal(10, 0)
+ private val DEC_BIG_INT = PType.decimal(19, 0)
+ }
+
override fun getName(): String {
return name
}
@@ -29,14 +36,14 @@ internal abstract class DiadicOperator(
override fun getInstance(args: Array): Function.Instance? {
val lhs = args[0]
val rhs = args[1]
- val lhsPrecedence = TYPE_PRECEDENCE[lhs.kind] ?: throw IllegalArgumentException("Type not supported -- LHS = $lhs")
- val rhsPrecedence = TYPE_PRECEDENCE[rhs.kind] ?: throw IllegalArgumentException("Type not supported -- RHS = $rhs")
+ val lhsPrecedence = TYPE_PRECEDENCE[lhs.code()] ?: throw IllegalArgumentException("Type not supported -- LHS = $lhs")
+ val rhsPrecedence = TYPE_PRECEDENCE[rhs.code()] ?: throw IllegalArgumentException("Type not supported -- RHS = $rhs")
val (newLhs, newRhs) = when (lhsPrecedence.compareTo(rhsPrecedence)) {
-1 -> (rhs to rhs)
0 -> (lhs to rhs)
else -> (lhs to lhs)
}
- val instance = instances[lhs.kind.ordinal][rhs.kind.ordinal]
+ val instance = instances[lhs.code()][rhs.code()]
return instance(newLhs, newRhs)
}
@@ -202,26 +209,26 @@ internal abstract class DiadicOperator(
* This is a lookup table for finding the appropriate instance for the given types. The table is
* initialized on construction using the get*Instance methods.
*/
- protected val instances: Array Function.Instance?>> = Array(PType.Kind.entries.size) {
- Array(PType.Kind.entries.size) {
+ protected val instances: Array Function.Instance?>> = Array(PType.codes().size) {
+ Array(PType.codes().size) {
{ _, _ -> null }
}
}
- protected fun fillTable(lhs: PType.Kind, rhs: PType.Kind, instance: (PType, PType) -> Function.Instance?) {
- instances[lhs.ordinal][rhs.ordinal] = instance
+ protected fun fillTable(lhs: Int, rhs: Int, instance: (PType, PType) -> Function.Instance?) {
+ instances[lhs][rhs] = instance
}
- protected fun fillNumberTable(highPrecedence: PType.Kind, instance: (PType, PType) -> Function.Instance?) {
+ protected fun fillNumberTable(highPrecedence: Int, instance: (PType, PType) -> Function.Instance?) {
return fillPrioritizedTable(highPrecedence, SqlTypeFamily.NUMBER, instance)
}
- private fun fillCharacterStringTable(highPrecedence: PType.Kind, instance: (PType, PType) -> Function.Instance?) {
+ private fun fillCharacterStringTable(highPrecedence: Int, instance: (PType, PType) -> Function.Instance?) {
return fillPrioritizedTable(highPrecedence, SqlTypeFamily.TEXT, instance)
}
- protected fun fillPrioritizedTable(highPrecedence: PType.Kind, family: SqlTypeFamily, instance: (PType, PType) -> Function.Instance?) {
- val members = family.members + setOf(PType.Kind.UNKNOWN)
+ protected fun fillPrioritizedTable(highPrecedence: Int, family: SqlTypeFamily, instance: (PType, PType) -> Function.Instance?) {
+ val members = family.members + setOf(PType.UNKNOWN)
members.filter {
(TYPE_PRECEDENCE[highPrecedence]!! > TYPE_PRECEDENCE[it]!!)
}.forEach {
@@ -232,67 +239,90 @@ internal abstract class DiadicOperator(
}
private fun fillBooleanTable(instance: (PType, PType) -> Function.Instance?) {
- fillTable(PType.Kind.BOOL, PType.Kind.BOOL) { lhs, rhs -> instance(lhs, rhs) }
- fillTable(PType.Kind.BOOL, PType.Kind.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
- fillTable(PType.Kind.UNKNOWN, PType.Kind.BOOL) { _, rhs -> instance(rhs, rhs) }
+ fillTable(PType.BOOL, PType.BOOL) { lhs, rhs -> instance(lhs, rhs) }
+ fillTable(PType.BOOL, PType.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
+ fillTable(PType.UNKNOWN, PType.BOOL) { _, rhs -> instance(rhs, rhs) }
}
private fun fillTimestampTable(instance: (PType, PType) -> Function.Instance?) {
- fillTable(PType.Kind.TIMESTAMPZ, PType.Kind.TIMESTAMPZ) { lhs, rhs -> instance(lhs, rhs) }
- fillTable(PType.Kind.TIMESTAMP, PType.Kind.TIMESTAMP) { lhs, rhs -> instance(lhs, rhs) }
- fillTable(PType.Kind.TIMESTAMPZ, PType.Kind.TIMESTAMP) { lhs, rhs -> instance(lhs, rhs) }
- fillTable(PType.Kind.TIMESTAMP, PType.Kind.TIMESTAMPZ) { lhs, rhs -> instance(lhs, rhs) }
- fillTable(PType.Kind.TIMESTAMP, PType.Kind.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
- fillTable(PType.Kind.TIMESTAMPZ, PType.Kind.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
- fillTable(PType.Kind.UNKNOWN, PType.Kind.TIMESTAMP) { _, rhs -> instance(rhs, rhs) }
- fillTable(PType.Kind.UNKNOWN, PType.Kind.TIMESTAMPZ) { _, rhs -> instance(rhs, rhs) }
+ fillTable(PType.TIMESTAMPZ, PType.TIMESTAMPZ) { lhs, rhs -> instance(lhs, rhs) }
+ fillTable(PType.TIMESTAMP, PType.TIMESTAMP) { lhs, rhs -> instance(lhs, rhs) }
+ fillTable(PType.TIMESTAMPZ, PType.TIMESTAMP) { lhs, rhs -> instance(lhs, rhs) }
+ fillTable(PType.TIMESTAMP, PType.TIMESTAMPZ) { lhs, rhs -> instance(lhs, rhs) }
+ fillTable(PType.TIMESTAMP, PType.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
+ fillTable(PType.TIMESTAMPZ, PType.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
+ fillTable(PType.UNKNOWN, PType.TIMESTAMP) { _, rhs -> instance(rhs, rhs) }
+ fillTable(PType.UNKNOWN, PType.TIMESTAMPZ) { _, rhs -> instance(rhs, rhs) }
}
private fun fillTimeTable(instance: (PType, PType) -> Function.Instance?) {
- fillTable(PType.Kind.TIMEZ, PType.Kind.TIMEZ) { lhs, rhs -> instance(lhs, rhs) }
- fillTable(PType.Kind.TIME, PType.Kind.TIME) { lhs, rhs -> instance(lhs, rhs) }
- fillTable(PType.Kind.TIMEZ, PType.Kind.TIME) { lhs, rhs -> instance(lhs, rhs) }
- fillTable(PType.Kind.TIME, PType.Kind.TIMEZ) { lhs, rhs -> instance(lhs, rhs) }
- fillTable(PType.Kind.TIMEZ, PType.Kind.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
- fillTable(PType.Kind.TIME, PType.Kind.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
- fillTable(PType.Kind.UNKNOWN, PType.Kind.TIME) { _, rhs -> instance(rhs, rhs) }
- fillTable(PType.Kind.UNKNOWN, PType.Kind.TIMEZ) { _, rhs -> instance(rhs, rhs) }
+ fillTable(PType.TIMEZ, PType.TIMEZ) { lhs, rhs -> instance(lhs, rhs) }
+ fillTable(PType.TIME, PType.TIME) { lhs, rhs -> instance(lhs, rhs) }
+ fillTable(PType.TIMEZ, PType.TIME) { lhs, rhs -> instance(lhs, rhs) }
+ fillTable(PType.TIME, PType.TIMEZ) { lhs, rhs -> instance(lhs, rhs) }
+ fillTable(PType.TIMEZ, PType.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
+ fillTable(PType.TIME, PType.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
+ fillTable(PType.UNKNOWN, PType.TIME) { _, rhs -> instance(rhs, rhs) }
+ fillTable(PType.UNKNOWN, PType.TIMEZ) { _, rhs -> instance(rhs, rhs) }
}
private fun fillDateTable(instance: (PType, PType) -> Function.Instance?) {
- fillTable(PType.Kind.DATE, PType.Kind.DATE) { lhs, rhs -> instance(lhs, rhs) }
- fillTable(PType.Kind.DATE, PType.Kind.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
- fillTable(PType.Kind.UNKNOWN, PType.Kind.DATE) { _, rhs -> instance(rhs, rhs) }
+ fillTable(PType.DATE, PType.DATE) { lhs, rhs -> instance(lhs, rhs) }
+ fillTable(PType.DATE, PType.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
+ fillTable(PType.UNKNOWN, PType.DATE) { _, rhs -> instance(rhs, rhs) }
}
private fun fillBlobTable(instance: (PType, PType) -> Function.Instance?) {
- fillTable(PType.Kind.BLOB, PType.Kind.BLOB) { lhs, rhs -> instance(lhs, rhs) }
- fillTable(PType.Kind.BLOB, PType.Kind.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
- fillTable(PType.Kind.UNKNOWN, PType.Kind.BLOB) { _, rhs -> instance(rhs, rhs) }
+ fillTable(PType.BLOB, PType.BLOB) { lhs, rhs -> instance(lhs, rhs) }
+ fillTable(PType.BLOB, PType.UNKNOWN) { lhs, _ -> instance(lhs, lhs) }
+ fillTable(PType.UNKNOWN, PType.BLOB) { _, rhs -> instance(rhs, rhs) }
}
- open fun fillDecimalTable() {
- fillNumberTable(PType.Kind.DECIMAL, ::getDecimalInstance)
+ private fun fillDecimalTable() {
+ // Tiny Int
+ fillTable(PType.TINYINT, PType.DECIMAL) { lhs, rhs -> getDecimalInstance(DEC_TINY_INT, rhs) }
+ fillTable(PType.DECIMAL, PType.TINYINT) { lhs, rhs -> getDecimalInstance(lhs, DEC_TINY_INT) }
+
+ // Small Int
+ fillTable(PType.SMALLINT, PType.DECIMAL) { lhs, rhs -> getDecimalInstance(DEC_SMALL_INT, rhs) }
+ fillTable(PType.DECIMAL, PType.SMALLINT) { lhs, rhs -> getDecimalInstance(lhs, DEC_SMALL_INT) }
+
+ // Integer
+ fillTable(PType.INTEGER, PType.DECIMAL) { lhs, rhs -> getDecimalInstance(DEC_INT, rhs) }
+ fillTable(PType.DECIMAL, PType.INTEGER) { lhs, rhs -> getDecimalInstance(lhs, DEC_INT) }
+
+ // Big Int
+ fillTable(PType.BIGINT, PType.DECIMAL) { lhs, rhs -> getDecimalInstance(DEC_BIG_INT, rhs) }
+ fillTable(PType.DECIMAL, PType.BIGINT) { lhs, rhs -> getDecimalInstance(lhs, DEC_BIG_INT) }
+
+ // Numeric
+ fillTable(PType.NUMERIC, PType.DECIMAL) { lhs, rhs -> getDecimalInstance(PType.decimal(38, 19), rhs) } // TODO: Convert numeric to decimal once numeric is not modeled as BigInteger
+ fillTable(PType.DECIMAL, PType.NUMERIC) { lhs, rhs -> getDecimalInstance(lhs, PType.decimal(38, 19)) } // TODO: Convert numeric to decimal once numeric is not modeled as BigInteger
+
+ // Decimal
+ fillTable(PType.DECIMAL, PType.DECIMAL) { lhs, rhs -> getDecimalInstance(lhs, rhs) }
+ fillTable(PType.UNKNOWN, PType.DECIMAL) { lhs, rhs -> getDecimalInstance(rhs, rhs) }
+ fillTable(PType.DECIMAL, PType.UNKNOWN) { lhs, rhs -> getDecimalInstance(lhs, lhs) }
}
- open fun fillTable() {
+ protected fun fillTable() {
fillBooleanTable(::getBooleanInstance)
- fillNumberTable(PType.Kind.TINYINT, ::getTinyIntInstance)
- fillNumberTable(PType.Kind.SMALLINT, ::getSmallIntInstance)
- fillNumberTable(PType.Kind.INTEGER, ::getIntegerInstance)
- fillNumberTable(PType.Kind.BIGINT, ::getBigIntInstance)
+ fillNumberTable(PType.TINYINT, ::getTinyIntInstance)
+ fillNumberTable(PType.SMALLINT, ::getSmallIntInstance)
+ fillNumberTable(PType.INTEGER, ::getIntegerInstance)
+ fillNumberTable(PType.BIGINT, ::getBigIntInstance)
fillDecimalTable()
- fillNumberTable(PType.Kind.NUMERIC, ::getNumericInstance)
- fillNumberTable(PType.Kind.REAL, ::getRealInstance)
- fillNumberTable(PType.Kind.DOUBLE, ::getDoubleInstance)
+ fillNumberTable(PType.NUMERIC, ::getNumericInstance)
+ fillNumberTable(PType.REAL, ::getRealInstance)
+ fillNumberTable(PType.DOUBLE, ::getDoubleInstance)
fillTimeTable(::getTimeInstance)
fillDateTable(::getDateInstance)
fillBlobTable(::getBlobInstance)
fillTimestampTable(::getTimestampInstance)
- fillCharacterStringTable(PType.Kind.STRING, ::getStringInstance)
- fillCharacterStringTable(PType.Kind.CHAR, ::getCharInstance)
- fillCharacterStringTable(PType.Kind.VARCHAR, ::getVarcharInstance)
- fillCharacterStringTable(PType.Kind.CLOB, ::getClobInstance)
+ fillCharacterStringTable(PType.STRING, ::getStringInstance)
+ fillCharacterStringTable(PType.CHAR, ::getCharInstance)
+ fillCharacterStringTable(PType.VARCHAR, ::getVarcharInstance)
+ fillCharacterStringTable(PType.CLOB, ::getClobInstance)
}
protected fun basic(returns: PType, lhs: PType, rhs: PType, invocation: (Array) -> Datum): Function.Instance {
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnAbs.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnAbs.kt
index a54f71d14..d97538786 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnAbs.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnAbs.kt
@@ -47,10 +47,10 @@ internal val Fn_ABS__INT64__INT64 = Function.static(
Datum.bigint(value.absoluteValue)
}
-internal val Fn_ABS__INT__INT = Function.static(
+internal val Fn_ABS__NUMERIC__NUMERIC = Function.static(
name = "abs",
- returns = PType.numeric(),
- parameters = arrayOf(Parameter("value", PType.numeric())),
+ returns = DefaultNumeric.NUMERIC,
+ parameters = arrayOf(Parameter("value", DefaultNumeric.NUMERIC)),
) { args ->
val value = args[0].bigInteger
Datum.numeric(value.abs())
@@ -58,8 +58,8 @@ internal val Fn_ABS__INT__INT = Function.static(
internal val Fn_ABS__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY = Function.static(
name = "abs",
- returns = PType.decimal(),
- parameters = arrayOf(Parameter("value", PType.decimal())),
+ returns = PType.decimal(39, 19), // TODO: Rewrite using new function modeling.
+ parameters = arrayOf(Parameter("value", PType.decimal(38, 19))),
) { args ->
val value = args[0].bigDecimal
Datum.decimal(value.abs())
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBetween.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBetween.kt
index 7b5ffe259..3df72bc16 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBetween.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBetween.kt
@@ -81,9 +81,9 @@ internal val Fn_BETWEEN__INT_INT_INT__BOOL = Function.static(
name = "between",
returns = PType.bool(),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("value", PType.numeric()),
- @Suppress("DEPRECATION") Parameter("lower", PType.numeric()),
- @Suppress("DEPRECATION") Parameter("upper", PType.numeric()),
+ Parameter("value", DefaultNumeric.NUMERIC),
+ Parameter("lower", DefaultNumeric.NUMERIC),
+ Parameter("upper", DefaultNumeric.NUMERIC),
),
) { args ->
@@ -98,9 +98,9 @@ internal val Fn_BETWEEN__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__
name = "between",
returns = PType.bool(),
parameters = arrayOf(
- Parameter("value", PType.decimal()),
- Parameter("lower", PType.decimal()),
- Parameter("upper", PType.decimal()),
+ Parameter("value", PType.decimal(38, 19)), // TODO: Rewrite using new function modeling.
+ Parameter("lower", PType.decimal(38, 19)),
+ Parameter("upper", PType.decimal(38, 19)),
),
) { args ->
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBitwiseAnd.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBitwiseAnd.kt
index cdba43d3c..f2e1db52b 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBitwiseAnd.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBitwiseAnd.kt
@@ -48,7 +48,7 @@ internal object FnBitwiseAnd : DiadicArithmeticOperator("bitwise_and") {
// TODO: Probably remove this if we don't expose NUMERIC
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
- return basic(PType.numeric()) { args ->
+ return basic(DefaultNumeric.NUMERIC) { args ->
val arg0 = args[0].bigInteger
val arg1 = args[1].bigInteger
Datum.numeric(arg0 and arg1)
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddDay.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddDay.kt
index 8a2d0fb92..98f9e4f5a 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddDay.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddDay.kt
@@ -49,7 +49,7 @@ internal val Fn_DATE_ADD_DAY__INT_DATE__DATE = Function.static(
name = "date_add_day",
returns = PType.date(),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
+ Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.date()),
),
@@ -104,7 +104,7 @@ internal val Fn_DATE_ADD_DAY__INT_TIMESTAMP__TIMESTAMP = Function.static(
name = "date_add_day",
returns = PType.timestamp(6),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
+ Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.timestamp(6)),
),
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddHour.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddHour.kt
index 31c919426..be21e3c08 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddHour.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddHour.kt
@@ -49,7 +49,7 @@ internal val Fn_DATE_ADD_HOUR__INT_TIME__TIME = Function.static(
name = "date_add_hour",
returns = PType.time(6),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
+ Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.time(6)),
),
@@ -104,7 +104,7 @@ internal val Fn_DATE_ADD_HOUR__INT_TIMESTAMP__TIMESTAMP = Function.static(
name = "date_add_hour",
returns = PType.timestamp(6),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
+ Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.timestamp(6)),
),
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddMinute.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddMinute.kt
index 4e26500c4..9811538a9 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddMinute.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddMinute.kt
@@ -49,7 +49,7 @@ internal val Fn_DATE_ADD_MINUTE__INT_TIME__TIME = Function.static(
name = "date_add_minute",
returns = PType.time(6),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
+ Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.time(6)),
),
@@ -104,7 +104,7 @@ internal val Fn_DATE_ADD_MINUTE__INT_TIMESTAMP__TIMESTAMP = Function.static(
name = "date_add_minute",
returns = PType.timestamp(6),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
+ Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.timestamp(6)),
),
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddMonth.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddMonth.kt
index 443d26a81..5a61e31c5 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddMonth.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddMonth.kt
@@ -49,7 +49,7 @@ internal val Fn_DATE_ADD_MONTH__INT_DATE__DATE = Function.static(
name = "date_add_month",
returns = PType.date(),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
+ Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.date()),
),
@@ -104,7 +104,7 @@ internal val Fn_DATE_ADD_MONTH__INT_TIMESTAMP__TIMESTAMP = Function.static(
name = "date_add_month",
returns = PType.timestamp(6),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
+ Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.timestamp(6)),
),
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddSecond.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddSecond.kt
index 995ecfd11..53c3415e5 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddSecond.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddSecond.kt
@@ -49,7 +49,7 @@ internal val Fn_DATE_ADD_SECOND__INT_TIME__TIME = Function.static(
name = "date_add_second",
returns = PType.time(6),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
+ Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.time(6)),
),
@@ -104,7 +104,7 @@ internal val Fn_DATE_ADD_SECOND__INT_TIMESTAMP__TIMESTAMP = Function.static(
name = "date_add_second",
returns = PType.timestamp(6),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
+ Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.timestamp(6)),
),
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddYear.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddYear.kt
index 3ba1f66e1..4beae8cbb 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddYear.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDateAddYear.kt
@@ -49,7 +49,7 @@ internal val Fn_DATE_ADD_YEAR__INT_DATE__DATE = Function.static(
name = "date_add_year",
returns = PType.date(),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
+ Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.date()),
),
@@ -104,7 +104,7 @@ internal val Fn_DATE_ADD_YEAR__INT_TIMESTAMP__TIMESTAMP = Function.static(
name = "date_add_year",
returns = PType.timestamp(6),
parameters = arrayOf(
- @Suppress("DEPRECATION") Parameter("interval", PType.numeric()),
+ Parameter("interval", DefaultNumeric.NUMERIC),
Parameter("datetime", PType.timestamp(6)),
),
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDivide.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDivide.kt
index e8d243d1c..cc1f6f1a2 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDivide.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnDivide.kt
@@ -46,7 +46,7 @@ internal object FnDivide : DiadicArithmeticOperator("divide") {
}
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
- return basic(PType.numeric()) { args ->
+ return basic(DefaultNumeric.NUMERIC) { args ->
val arg0 = args[0].bigInteger
val arg1 = args[1].bigInteger
Datum.numeric(arg0 / arg1)
@@ -59,7 +59,7 @@ internal object FnDivide : DiadicArithmeticOperator("divide") {
override fun getDecimalInstance(decimalLhs: PType, decimalRhs: PType): Function.Instance {
val p = decimalLhs.precision - decimalLhs.scale + decimalRhs.scale + Math.max(6, decimalLhs.scale + decimalRhs.precision + 1)
val s = Math.max(6, decimalLhs.scale + decimalRhs.precision + 1)
- return basic(PType.decimal()) { args ->
+ return basic(PType.decimal(p, s), decimalLhs, decimalRhs) { args ->
val arg0 = args[0].bigDecimal
val arg1 = args[1].bigDecimal
Datum.decimal(arg0 / arg1, p, s)
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnEq.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnEq.kt
index 09f6dcd54..22d8582bb 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnEq.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnEq.kt
@@ -5,7 +5,6 @@ package org.partiql.spi.function.builtins
import org.partiql.spi.function.Function
import org.partiql.spi.function.Parameter
-import org.partiql.spi.function.builtins.FnPlus.fillTable
import org.partiql.spi.value.Datum
import org.partiql.types.PType
@@ -25,10 +24,6 @@ import org.partiql.types.PType
*/
internal object FnEq : Function {
- init {
- fillTable()
- }
-
// Memoize shared variables
private val comparator = Datum.comparator()
private val boolType = PType.bool()
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnExtract.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnExtract.kt
index aca766682..dfe6db4cb 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnExtract.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnExtract.kt
@@ -161,7 +161,7 @@ internal val Fn_EXTRACT_MINUTE__TIMESTAMP__INT32 = Function.static(
internal val Fn_EXTRACT_SECOND__TIME__DECIMAL_ARBITRARY = Function.static(
name = "extract_second",
- returns = PType.decimal(),
+ returns = PType.decimal(38, 19), // TODO: Rewrite using new function modeling.
parameters = arrayOf(
Parameter("datetime", PType.time(6)),
),
@@ -174,7 +174,7 @@ internal val Fn_EXTRACT_SECOND__TIME__DECIMAL_ARBITRARY = Function.static(
internal val Fn_EXTRACT_SECOND__TIMESTAMP__DECIMAL_ARBITRARY = Function.static(
name = "extract_second",
- returns = PType.decimal(),
+ returns = PType.decimal(38, 19), // TODO: Rewrite using new function modeling.
parameters = arrayOf(
Parameter("datetime", PType.timestamp(6)),
),
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGt.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGt.kt
index da1efb025..c0077be00 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGt.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGt.kt
@@ -52,7 +52,7 @@ internal object FnGt : DiadicComparisonOperator("gt") {
// TODO: Update numeric to use bigDecimal rather than bigInteger.
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
- return basic(PType.bool(), PType.numeric()) { args ->
+ return basic(PType.bool(), DefaultNumeric.NUMERIC) { args ->
val lhs = args[0].bigInteger
val rhs = args[1].bigInteger
Datum.bool(lhs > rhs)
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGte.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGte.kt
index 714be6a7a..9a581b5c2 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGte.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGte.kt
@@ -52,7 +52,7 @@ internal object FnGte : DiadicComparisonOperator("gte") {
// TODO: Update
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
- return basic(PType.bool(), PType.numeric()) { args ->
+ return basic(PType.bool(), DefaultNumeric.NUMERIC) { args ->
val lhs = args[0].bigInteger
val rhs = args[1].bigInteger
Datum.bool(lhs >= rhs)
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnInCollection.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnInCollection.kt
index 5afb5aae6..c54fe8f12 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnInCollection.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnInCollection.kt
@@ -25,7 +25,7 @@ internal object FnInCollection : Function {
override fun getInstance(args: Array): Function.Instance? {
val vType = args[0]
val cType = args[1]
- if (cType.kind !in setOf(PType.Kind.UNKNOWN, PType.Kind.ARRAY, PType.Kind.BAG)) {
+ if (cType.code() !in setOf(PType.UNKNOWN, PType.ARRAY, PType.BAG)) {
return null
}
return object : Function.Instance(
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsBag.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsBag.kt
index 28709fa63..e35758ea2 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsBag.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsBag.kt
@@ -7,12 +7,11 @@ import org.partiql.spi.function.Function
import org.partiql.spi.function.Parameter
import org.partiql.spi.value.Datum
import org.partiql.types.PType
-import org.partiql.types.PType.Kind
internal val Fn_IS_BAG__ANY__BOOL = Function.static(
name = "is_bag",
returns = PType.bool(),
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- Datum.bool(args[0].type.kind == Kind.BAG)
+ Datum.bool(args[0].type.code() == PType.BAG)
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsBlob.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsBlob.kt
index c325f43b8..abefbf0bb 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsBlob.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsBlob.kt
@@ -13,5 +13,5 @@ internal val Fn_IS_BLOB__ANY__BOOL = Function.static(
returns = PType.bool(),
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- Datum.bool(args[0].type.kind == PType.Kind.BLOB)
+ Datum.bool(args[0].type.code() == PType.BLOB)
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsBool.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsBool.kt
index dc6c584e7..2ca7040c4 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsBool.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsBool.kt
@@ -13,5 +13,5 @@ internal val Fn_IS_BOOL__ANY__BOOL = Function.static(
returns = PType.bool(),
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- Datum.bool(args[0].type.kind == PType.Kind.BOOL)
+ Datum.bool(args[0].type.code() == PType.BOOL)
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsChar.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsChar.kt
index c105ca2e3..ae1da6b8f 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsChar.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsChar.kt
@@ -14,12 +14,12 @@ internal val Fn_IS_CHAR__ANY__BOOL = Function.static(
returns = PType.bool(),
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- Datum.bool(args[0].type.kind == PType.Kind.CHAR)
+ Datum.bool(args[0].type.code() == PType.CHAR)
}
private val TEXT_TYPES_WITH_LENGTH = setOf(
- PType.Kind.CHAR,
- PType.Kind.VARCHAR
+ PType.CHAR,
+ PType.VARCHAR
)
internal val Fn_IS_CHAR__INT32_ANY__BOOL = Function.static(
@@ -31,7 +31,7 @@ internal val Fn_IS_CHAR__INT32_ANY__BOOL = Function.static(
),
) { args ->
val value = args[0]
- if (value.type.kind in TEXT_TYPES_WITH_LENGTH) {
+ if (value.type.code() in TEXT_TYPES_WITH_LENGTH) {
Datum.bool(false)
}
val length = args[0].int
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsClob.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsClob.kt
index b7d80d212..d88d0849e 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsClob.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsClob.kt
@@ -15,5 +15,5 @@ internal val Fn_IS_CLOB__ANY__BOOL = Function.static(
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- Datum.bool(args[0].type.kind == PType.Kind.CLOB)
+ Datum.bool(args[0].type.code() == PType.CLOB)
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDate.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDate.kt
index 77f2ac370..adf281acd 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDate.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDate.kt
@@ -15,5 +15,5 @@ internal val Fn_IS_DATE__ANY__BOOL = Function.static(
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- Datum.bool(args[0].type.kind == PType.Kind.DATE)
+ Datum.bool(args[0].type.code() == PType.DATE)
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDecimal.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDecimal.kt
index 8dcab3f5f..3cc07bb7e 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDecimal.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDecimal.kt
@@ -15,7 +15,7 @@ internal val Fn_IS_DECIMAL__ANY__BOOL = Function.static(
returns = PType.bool(),
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- Datum.bool(args[0].type.kind == PType.Kind.DECIMAL)
+ Datum.bool(args[0].type.code() == PType.DECIMAL)
}
internal val Fn_IS_DECIMAL__INT32_INT32_ANY__BOOL = Function.static(
@@ -45,7 +45,7 @@ internal val Fn_IS_DECIMAL__INT32_INT32_ANY__BOOL = Function.static(
*/
{ args ->
val v = args[2]
- if (v.type.kind != PType.Kind.DECIMAL) {
+ if (v.type.code() != PType.DECIMAL) {
return@static Datum.bool(false)
}
val p = args[0].int
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsFloat32.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsFloat32.kt
index 8db6e5af9..0f873d9f8 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsFloat32.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsFloat32.kt
@@ -16,9 +16,9 @@ internal val Fn_IS_FLOAT32__ANY__BOOL = Function.static(
) { args ->
val arg = args[0]
- when (arg.type.kind) {
- PType.Kind.REAL -> Datum.bool(true)
- PType.Kind.DOUBLE -> {
+ when (arg.type.code()) {
+ PType.REAL -> Datum.bool(true)
+ PType.DOUBLE -> {
val v = arg.double
Datum.bool(Float.MIN_VALUE <= v && v <= Float.MAX_VALUE)
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsFloat64.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsFloat64.kt
index 9955af77a..424c0a86d 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsFloat64.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsFloat64.kt
@@ -15,9 +15,9 @@ internal val Fn_IS_FLOAT64__ANY__BOOL = Function.static(
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- when (args[0].type.kind) {
- PType.Kind.REAL,
- PType.Kind.DOUBLE,
+ when (args[0].type.code()) {
+ PType.REAL,
+ PType.DOUBLE,
-> Datum.bool(true)
else -> Datum.bool(false)
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt.kt
index b5d20a516..09bdf95c6 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt.kt
@@ -9,11 +9,11 @@ import org.partiql.spi.value.Datum
import org.partiql.types.PType
private val INT_TYPES = setOf(
- PType.Kind.TINYINT,
- PType.Kind.SMALLINT,
- PType.Kind.INTEGER,
- PType.Kind.BIGINT,
- PType.Kind.NUMERIC
+ PType.TINYINT,
+ PType.SMALLINT,
+ PType.INTEGER,
+ PType.BIGINT,
+ PType.NUMERIC
)
internal val Fn_IS_INT__ANY__BOOL = Function.static(
@@ -22,5 +22,5 @@ internal val Fn_IS_INT__ANY__BOOL = Function.static(
parameters = arrayOf(Parameter("value", PType.dynamic()))
) { args ->
val arg = args[0]
- Datum.bool(arg.type.kind in INT_TYPES)
+ Datum.bool(arg.type.code() in INT_TYPES)
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt16.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt16.kt
index 536774a68..8bf34170e 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt16.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt16.kt
@@ -16,19 +16,19 @@ internal val Fn_IS_INT16__ANY__BOOL = Function.static(
) { args ->
val arg = args[0]
- when (arg.type.kind) {
- PType.Kind.TINYINT,
- PType.Kind.SMALLINT,
+ when (arg.type.code()) {
+ PType.TINYINT,
+ PType.SMALLINT,
-> Datum.bool(true)
- PType.Kind.INTEGER -> {
+ PType.INTEGER -> {
val v = arg.int
Datum.bool(Short.MIN_VALUE <= v && v <= Short.MAX_VALUE)
}
- PType.Kind.BIGINT -> {
+ PType.BIGINT -> {
val v = arg.long
Datum.bool(Short.MIN_VALUE <= v && v <= Short.MAX_VALUE)
}
- PType.Kind.NUMERIC -> {
+ PType.NUMERIC -> {
val v = arg.bigInteger
try {
v.shortValueExact()
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt32.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt32.kt
index 86d19ae3b..3c16b7383 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt32.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt32.kt
@@ -16,16 +16,16 @@ internal val Fn_IS_INT32__ANY__BOOL = Function.static(
) { args ->
val arg = args[0]
- when (arg.type.kind) {
- PType.Kind.TINYINT,
- PType.Kind.SMALLINT,
- PType.Kind.INTEGER,
+ when (arg.type.code()) {
+ PType.TINYINT,
+ PType.SMALLINT,
+ PType.INTEGER,
-> Datum.bool(true)
- PType.Kind.BIGINT -> {
+ PType.BIGINT -> {
val v = arg
Datum.bool(Integer.MIN_VALUE <= v.long && v.long <= Integer.MAX_VALUE)
}
- PType.Kind.NUMERIC -> {
+ PType.NUMERIC -> {
val v = arg.bigInteger
try {
v.intValueExact()
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt64.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt64.kt
index 0a38b2063..1a55a5155 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt64.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt64.kt
@@ -16,13 +16,13 @@ internal val Fn_IS_INT64__ANY__BOOL = Function.static(
) { args ->
val arg = args[0]
- when (arg.type.kind) {
- PType.Kind.TINYINT,
- PType.Kind.SMALLINT,
- PType.Kind.INTEGER,
- PType.Kind.BIGINT,
+ when (arg.type.code()) {
+ PType.TINYINT,
+ PType.SMALLINT,
+ PType.INTEGER,
+ PType.BIGINT,
-> Datum.bool(true)
- PType.Kind.NUMERIC -> {
+ PType.NUMERIC -> {
val v = arg.bigInteger
try {
v.longValueExact()
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt8.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt8.kt
index 0de805c9e..46379417b 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt8.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsInt8.kt
@@ -16,21 +16,21 @@ internal val Fn_IS_INT8__ANY__BOOL = Function.static(
) { args ->
val arg = args[0]
- when (arg.type.kind) {
- PType.Kind.TINYINT -> Datum.bool(true)
- PType.Kind.SMALLINT -> {
+ when (arg.type.code()) {
+ PType.TINYINT -> Datum.bool(true)
+ PType.SMALLINT -> {
val v = arg.short
Datum.bool(Byte.MIN_VALUE <= v && v <= Byte.MAX_VALUE)
}
- PType.Kind.INTEGER -> {
+ PType.INTEGER -> {
val v = arg.int
Datum.bool(Byte.MIN_VALUE <= v && v <= Byte.MAX_VALUE)
}
- PType.Kind.BIGINT -> {
+ PType.BIGINT -> {
val v = arg.long
Datum.bool(Byte.MIN_VALUE <= v && v <= Byte.MAX_VALUE)
}
- PType.Kind.NUMERIC -> {
+ PType.NUMERIC -> {
val v = arg.bigInteger
try {
v.byteValueExact()
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsList.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsList.kt
index 24a54dbaa..0bf3d3819 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsList.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsList.kt
@@ -15,5 +15,5 @@ internal val Fn_IS_LIST__ANY__BOOL = Function.static(
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- Datum.bool(args[0].type.kind == PType.Kind.ARRAY)
+ Datum.bool(args[0].type.code() == PType.ARRAY)
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsString.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsString.kt
index eb7cf5ac3..2d6c98133 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsString.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsString.kt
@@ -15,7 +15,7 @@ internal val Fn_IS_STRING__ANY__BOOL = Function.static(
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- Datum.bool(args[0].type.kind == PType.Kind.STRING)
+ Datum.bool(args[0].type.code() == PType.STRING)
}
internal val Fn_IS_STRING__INT32_ANY__BOOL = Function.static(
@@ -27,7 +27,7 @@ internal val Fn_IS_STRING__INT32_ANY__BOOL = Function.static(
),
) { args ->
val v = args[1]
- if (v.type.kind != PType.Kind.STRING) {
+ if (v.type.code() != PType.STRING) {
return@static Datum.bool(false)
}
val length = args[0].int
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsStruct.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsStruct.kt
index df12f7ef0..e83155c0c 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsStruct.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsStruct.kt
@@ -15,5 +15,5 @@ internal val Fn_IS_STRUCT__ANY__BOOL = Function.static(
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- Datum.bool(args[0].type.kind == PType.Kind.STRUCT)
+ Datum.bool(args[0].type.code() == PType.STRUCT)
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsTime.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsTime.kt
index 8d6905487..ae3f6b36c 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsTime.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsTime.kt
@@ -15,8 +15,8 @@ internal val Fn_IS_TIME__ANY__BOOL = Function.static(
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- val argKind = args[0].type.kind
- Datum.bool(argKind == PType.Kind.TIMEZ || argKind == PType.Kind.TIME)
+ val argKind = args[0].type.code()
+ Datum.bool(argKind == PType.TIMEZ || argKind == PType.TIME)
}
internal val Fn_IS_TIME__BOOL_INT32_ANY__BOOL = Function.static(
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsTimestamp.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsTimestamp.kt
index a05dbae20..63f798281 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsTimestamp.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsTimestamp.kt
@@ -15,8 +15,8 @@ internal val Fn_IS_TIMESTAMP__ANY__BOOL = Function.static(
parameters = arrayOf(Parameter("value", PType.dynamic())),
) { args ->
- val argKind = args[0].type.kind
- Datum.bool(argKind == PType.Kind.TIMESTAMPZ || argKind == PType.Kind.TIMESTAMP)
+ val argKind = args[0].type.code()
+ Datum.bool(argKind == PType.TIMESTAMPZ || argKind == PType.TIMESTAMP)
}
internal val Fn_IS_TIMESTAMP__BOOL_INT32_ANY__BOOL = Function.static(
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLt.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLt.kt
index cf685ea4e..8e526a2be 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLt.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLt.kt
@@ -48,7 +48,7 @@ internal object FnLt : DiadicComparisonOperator("lt") {
// TODO: Update
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
- return basic(PType.bool(), PType.numeric()) { args ->
+ return basic(PType.bool(), DefaultNumeric.NUMERIC) { args ->
val lhs = args[0].bigInteger
val rhs = args[1].bigInteger
Datum.bool(lhs < rhs)
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLte.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLte.kt
index 11a9208a8..35d6cba0e 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLte.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLte.kt
@@ -52,7 +52,7 @@ internal object FnLte : DiadicComparisonOperator("lte") {
// TODO: Update
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
- return basic(PType.bool(), PType.numeric()) { args ->
+ return basic(PType.bool(), DefaultNumeric.NUMERIC) { args ->
val lhs = args[0].bigInteger
val rhs = args[1].bigInteger
Datum.bool(lhs <= rhs)
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnMinus.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnMinus.kt
index 348300ce3..df7de273c 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnMinus.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnMinus.kt
@@ -48,7 +48,7 @@ internal object FnMinus : DiadicArithmeticOperator("minus") {
// TODO: Delete this
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
- return basic(PType.numeric()) { args ->
+ return basic(DefaultNumeric.NUMERIC) { args ->
val arg0 = args[0].bigInteger
val arg1 = args[1].bigInteger
Datum.numeric(arg0 - arg1)
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnModulo.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnModulo.kt
index 772390887..a785a020e 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnModulo.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnModulo.kt
@@ -46,7 +46,7 @@ internal object FnModulo : DiadicArithmeticOperator("modulo") {
}
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
- return basic(PType.numeric()) { args ->
+ return basic(DefaultNumeric.NUMERIC) { args ->
val arg0 = args[0].bigInteger
val arg1 = args[1].bigInteger
Datum.numeric(arg0 % arg1)
@@ -61,7 +61,7 @@ internal object FnModulo : DiadicArithmeticOperator("modulo") {
override fun getDecimalInstance(decimalLhs: PType, decimalRhs: PType): Function.Instance {
val p = Math.min(decimalLhs.precision - decimalLhs.scale, decimalRhs.precision - decimalRhs.scale) + Math.max(decimalLhs.scale, decimalRhs.scale)
val s = Math.max(decimalLhs.scale, decimalRhs.scale)
- return basic(PType.decimal()) { args ->
+ return basic(PType.decimal(p, s), decimalLhs, decimalRhs) { args ->
val arg0 = args[0].bigDecimal
val arg1 = args[1].bigDecimal
Datum.decimal(arg0 % arg1, p, s)
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnNeg.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnNeg.kt
index a7e2a4936..0ebc9380c 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnNeg.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnNeg.kt
@@ -57,8 +57,8 @@ internal val Fn_NEG__INT64__INT64 = Function.static(
internal val Fn_NEG__INT__INT = Function.static(
name = "neg",
- returns = PType.numeric(),
- parameters = arrayOf(Parameter("value", PType.numeric())),
+ returns = DefaultNumeric.NUMERIC,
+ parameters = arrayOf(Parameter("value", DefaultNumeric.NUMERIC)),
) { args ->
val value = args[0].bigInteger
@@ -68,8 +68,8 @@ internal val Fn_NEG__INT__INT = Function.static(
internal val Fn_NEG__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY = Function.static(
name = "neg",
- returns = PType.decimal(),
- parameters = arrayOf(Parameter("value", PType.decimal())),
+ returns = PType.decimal(38, 19), // TODO: Rewrite using new function modeling.
+ parameters = arrayOf(Parameter("value", PType.decimal(38, 19))),
) { args ->
val value = args[0].bigDecimal
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPlus.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPlus.kt
index f3ca315e3..576951390 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPlus.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPlus.kt
@@ -48,7 +48,7 @@ internal object FnPlus : DiadicArithmeticOperator("plus") {
// TODO: Probably remove this if we don't expose NUMERIC
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
- return basic(PType.numeric()) { args ->
+ return basic(DefaultNumeric.NUMERIC) { args ->
val arg0 = args[0].bigInteger
val arg1 = args[1].bigInteger
Datum.numeric(arg0 + arg1)
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPos.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPos.kt
index 474ed6f7e..bb0ab5085 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPos.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPos.kt
@@ -50,8 +50,8 @@ internal val Fn_POS__INT64__INT64 = Function.static(
internal val Fn_POS__INT__INT = Function.static(
name = "pos",
- returns = PType.numeric(),
- parameters = arrayOf(Parameter("value", PType.numeric())),
+ returns = DefaultNumeric.NUMERIC,
+ parameters = arrayOf(Parameter("value", DefaultNumeric.NUMERIC)),
) { args ->
args[0]
@@ -60,8 +60,8 @@ internal val Fn_POS__INT__INT = Function.static(
internal val Fn_POS__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY = Function.static(
name = "pos",
- returns = PType.decimal(),
- parameters = arrayOf(Parameter("value", PType.decimal())),
+ returns = PType.decimal(38, 19), // TODO: Rewrite this using the new modeling
+ parameters = arrayOf(Parameter("value", PType.decimal(38, 19))),
) { args ->
args[0]
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTimes.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTimes.kt
index ec2fbc4f9..9e3b00f64 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTimes.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTimes.kt
@@ -46,7 +46,7 @@ internal object FnTimes : DiadicArithmeticOperator("times") {
}
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
- return basic(PType.numeric()) { args ->
+ return basic(DefaultNumeric.NUMERIC) { args ->
val arg0 = args[0].bigInteger
val arg1 = args[1].bigInteger
Datum.numeric(arg0 * arg1)
@@ -59,7 +59,7 @@ internal object FnTimes : DiadicArithmeticOperator("times") {
override fun getDecimalInstance(decimalLhs: PType, decimalRhs: PType): Function.Instance {
val p = decimalLhs.precision + decimalRhs.precision + 1
val s = decimalLhs.scale + decimalRhs.scale
- return basic(PType.decimal()) { args ->
+ return basic(PType.decimal(p, s), decimalLhs, decimalRhs) { args ->
val arg0 = args[0].bigDecimal
val arg1 = args[1].bigDecimal
Datum.decimal(arg0 * arg1, p, s)
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/TypePrecedence.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/TypePrecedence.kt
index fdb4b03a2..3cfc527e6 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/TypePrecedence.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/TypePrecedence.kt
@@ -1,38 +1,38 @@
package org.partiql.spi.function.builtins
-import org.partiql.types.PType.Kind
+import org.partiql.types.PType
internal object TypePrecedence {
/**
* @return the precedence of the types for the PartiQL comparator.
- * @see .TYPE_PRECEDENCE
+ * @see TYPE_PRECEDENCE
*/
- internal val TYPE_PRECEDENCE: Map = listOf(
- Kind.UNKNOWN,
- Kind.BOOL,
- Kind.TINYINT,
- Kind.SMALLINT,
- Kind.INTEGER,
- Kind.BIGINT,
- Kind.NUMERIC,
- Kind.DECIMAL,
- Kind.REAL,
- Kind.DOUBLE,
- Kind.CHAR,
- Kind.VARCHAR,
- Kind.STRING,
- Kind.CLOB,
- Kind.BLOB,
- Kind.DATE,
- Kind.TIME,
- Kind.TIMEZ,
- Kind.TIMESTAMP,
- Kind.TIMESTAMPZ,
- Kind.ARRAY,
- Kind.BAG,
- Kind.ROW,
- Kind.STRUCT,
- Kind.DYNAMIC
+ internal val TYPE_PRECEDENCE: Map = listOf(
+ PType.UNKNOWN,
+ PType.BOOL,
+ PType.TINYINT,
+ PType.SMALLINT,
+ PType.INTEGER,
+ PType.BIGINT,
+ PType.NUMERIC,
+ PType.DECIMAL,
+ PType.REAL,
+ PType.DOUBLE,
+ PType.CHAR,
+ PType.VARCHAR,
+ PType.STRING,
+ PType.CLOB,
+ PType.BLOB,
+ PType.DATE,
+ PType.TIME,
+ PType.TIMEZ,
+ PType.TIMESTAMP,
+ PType.TIMESTAMPZ,
+ PType.ARRAY,
+ PType.BAG,
+ PType.ROW,
+ PType.STRUCT,
+ PType.DYNAMIC
).mapIndexed { precedence, type -> type to precedence }.toMap()
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/internal/Accumulator.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/internal/Accumulator.kt
index b6e4bba14..6e8ae0082 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/internal/Accumulator.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/internal/Accumulator.kt
@@ -97,37 +97,37 @@ private fun Long.checkOverflowPlus(other: Long): Number {
}
internal fun checkIsBooleanType(funcName: String, value: Datum) {
- if (value.type.kind != PType.Kind.BOOL) {
- throw TypeCheckException("Expected ${PType.Kind.BOOL} but received ${value.type}.")
+ if (value.type.code() != PType.BOOL) {
+ throw TypeCheckException("Expected ${PType.BOOL} but received ${value.type}.")
}
}
-internal fun Datum.numberValue(): Number = when (this.type.kind) {
- PType.Kind.TINYINT -> this.byte
- PType.Kind.SMALLINT -> this.short
- PType.Kind.INTEGER -> this.int
- PType.Kind.BIGINT -> this.long
- PType.Kind.NUMERIC -> this.bigInteger
- PType.Kind.REAL -> this.float
- PType.Kind.DOUBLE -> this.double
- PType.Kind.DECIMAL -> this.bigDecimal
+internal fun Datum.numberValue(): Number = when (this.type.code()) {
+ PType.TINYINT -> this.byte
+ PType.SMALLINT -> this.short
+ PType.INTEGER -> this.int
+ PType.BIGINT -> this.long
+ PType.NUMERIC -> this.bigInteger
+ PType.REAL -> this.float
+ PType.DOUBLE -> this.double
+ PType.DECIMAL -> this.bigDecimal
else -> error("Cannot convert PartiQLValue ($this) to number.")
}
-internal fun Datum.booleanValue(): Boolean = when (this.type.kind) {
- PType.Kind.BOOL -> this.boolean
+internal fun Datum.booleanValue(): Boolean = when (this.type.code()) {
+ PType.BOOL -> this.boolean
else -> error("Cannot convert PartiQLValue ($this) to boolean.")
}
-internal fun PType.isNumber(): Boolean = when (this.kind) {
- PType.Kind.INTEGER,
- PType.Kind.TINYINT,
- PType.Kind.SMALLINT,
- PType.Kind.BIGINT,
- PType.Kind.NUMERIC,
- PType.Kind.REAL,
- PType.Kind.DOUBLE,
- PType.Kind.DECIMAL,
+internal fun PType.isNumber(): Boolean = when (this.code()) {
+ PType.INTEGER,
+ PType.TINYINT,
+ PType.SMALLINT,
+ PType.BIGINT,
+ PType.NUMERIC,
+ PType.REAL,
+ PType.DOUBLE,
+ PType.DECIMAL,
-> true
else -> false
}
@@ -140,11 +140,11 @@ internal fun nullToTargetType(type: PType): Datum = Datum.nullValue(type)
/**
* This is specifically for SUM/AVG
*/
-internal fun Number.toTargetType(type: PType): Datum = when (type.kind) {
- PType.Kind.DYNAMIC -> this.toDatum()
- PType.Kind.REAL -> Datum.real(this.toFloat())
- PType.Kind.DOUBLE -> Datum.doublePrecision(this.toDouble())
- PType.Kind.DECIMAL -> {
+internal fun Number.toTargetType(type: PType): Datum = when (type.code()) {
+ PType.DYNAMIC -> this.toDatum()
+ PType.REAL -> Datum.real(this.toFloat())
+ PType.DOUBLE -> Datum.doublePrecision(this.toDouble())
+ PType.DECIMAL -> {
when (this) {
is BigDecimal -> Datum.decimal(this, this.precision(), this.scale())
is BigInteger -> {
@@ -157,11 +157,11 @@ internal fun Number.toTargetType(type: PType): Datum = when (type.kind) {
}
}
}
- PType.Kind.TINYINT -> Datum.tinyint(this.toByte())
- PType.Kind.SMALLINT -> Datum.smallint(this.toShort())
- PType.Kind.INTEGER -> Datum.integer(this.toInt())
- PType.Kind.BIGINT -> Datum.bigint(this.toLong())
- PType.Kind.NUMERIC -> when (this) {
+ PType.TINYINT -> Datum.tinyint(this.toByte())
+ PType.SMALLINT -> Datum.smallint(this.toShort())
+ PType.INTEGER -> Datum.integer(this.toInt())
+ PType.BIGINT -> Datum.bigint(this.toLong())
+ PType.NUMERIC -> when (this) {
is BigInteger -> Datum.numeric(this)
is BigDecimal -> Datum.numeric(this.toBigInteger())
else -> Datum.numeric(BigInteger.valueOf(this.toLong()))
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/internal/AccumulatorAvg.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/internal/AccumulatorAvg.kt
index 04590b175..1b5b6a462 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/internal/AccumulatorAvg.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/internal/AccumulatorAvg.kt
@@ -5,7 +5,7 @@ import org.partiql.types.PType
internal class AccumulatorAvg : Accumulator() {
- private var targetType = PType.decimal()
+ private var targetType = PType.decimal(38, 19)
private var sum: Number = 0.0
private var count: Long = 0L
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/internal/SqlTypeFamily.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/internal/SqlTypeFamily.kt
index 1cd6ae1cf..cc2dabd86 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/internal/SqlTypeFamily.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/internal/SqlTypeFamily.kt
@@ -1,7 +1,6 @@
package org.partiql.spi.internal
import org.partiql.types.PType
-import org.partiql.types.PType.Kind
/**
* A basic "set" representation for type categorization; perhaps we optimize later..
@@ -26,15 +25,15 @@ import org.partiql.types.PType.Kind
*/
internal class SqlTypeFamily private constructor(
@JvmField val preferred: PType,
- @JvmField val members: Set,
+ @JvmField val members: Set,
) {
/**
* Constructor a singleton [SqlTypeFamily].
*/
- constructor(preferred: PType) : this(preferred, setOf(preferred.kind))
+ constructor(preferred: PType) : this(preferred, setOf(preferred.code()))
- operator fun contains(type: PType) = type.kind in members
+ operator fun contains(type: PType) = type.code() in members
companion object {
@@ -42,10 +41,10 @@ internal class SqlTypeFamily private constructor(
val TEXT = SqlTypeFamily(
preferred = PType.string(),
members = setOf(
- Kind.CHAR,
- Kind.VARCHAR,
- Kind.STRING,
- Kind.CLOB,
+ PType.CHAR,
+ PType.VARCHAR,
+ PType.STRING,
+ PType.CLOB,
)
)
@@ -53,23 +52,23 @@ internal class SqlTypeFamily private constructor(
val COLLECTION = SqlTypeFamily(
preferred = PType.bag(),
members = setOf(
- Kind.ARRAY,
- Kind.BAG
+ PType.ARRAY,
+ PType.BAG
)
)
@JvmStatic
val NUMBER = SqlTypeFamily(
- preferred = PType.decimal(),
+ preferred = PType.decimal(38, 19),
members = setOf(
- Kind.TINYINT,
- Kind.SMALLINT,
- Kind.INTEGER,
- Kind.BIGINT,
- Kind.NUMERIC,
- Kind.REAL,
- Kind.DOUBLE,
- Kind.DECIMAL,
+ PType.TINYINT,
+ PType.SMALLINT,
+ PType.INTEGER,
+ PType.BIGINT,
+ PType.NUMERIC,
+ PType.REAL,
+ PType.DOUBLE,
+ PType.DECIMAL,
)
)
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/internal/SqlTypes.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/internal/SqlTypes.kt
index 550c751f6..9a327825c 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/spi/internal/SqlTypes.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/spi/internal/SqlTypes.kt
@@ -2,7 +2,6 @@ package org.partiql.spi.internal
import org.partiql.types.Field
import org.partiql.types.PType
-import org.partiql.types.PType.Kind
/**
* Important SQL Definitions:
@@ -49,7 +48,7 @@ internal object SqlTypes {
* for the [PType.getTypeParameter] and [PType.getFields]
*/
private fun areAssignableDynamicTypes(target: PType): Boolean {
- return target.kind == Kind.DYNAMIC
+ return target.code() == PType.DYNAMIC
}
/**
@@ -66,10 +65,10 @@ internal object SqlTypes {
*/
private fun areAssignableStructuralTypes(input: PType, target: PType): Boolean {
return when {
- input.kind == Kind.ROW && target.kind == Kind.ROW -> fieldsAreAssignable(input.fields.toList(), target.fields!!.toList())
- input.kind == Kind.STRUCT && target.kind == Kind.ROW -> true
- input.kind == Kind.ROW && target.kind == Kind.STRUCT -> true
- input.kind == Kind.STRUCT && target.kind == Kind.STRUCT -> true
+ input.code() == PType.ROW && target.code() == PType.ROW -> fieldsAreAssignable(input.fields.toList(), target.fields!!.toList())
+ input.code() == PType.STRUCT && target.code() == PType.ROW -> true
+ input.code() == PType.ROW && target.code() == PType.STRUCT -> true
+ input.code() == PType.STRUCT && target.code() == PType.STRUCT -> true
else -> false
}
}
@@ -130,7 +129,7 @@ internal object SqlTypes {
* ```
*/
private fun areAssignableBooleanTypes(input: PType, target: PType): Boolean {
- return input.kind == Kind.BOOL && target.kind == Kind.BOOL
+ return input.code() == PType.BOOL && target.code() == PType.BOOL
}
/**
@@ -156,12 +155,12 @@ internal object SqlTypes {
* ```
*/
private fun areAssignableDateTimeTypes(input: PType, target: PType): Boolean {
- val i = input.kind
- val t = target.kind
+ val i = input.code()
+ val t = target.code()
return when {
- i == Kind.DATE && t == Kind.DATE -> true
- (i == Kind.TIMEZ || i == Kind.TIME) && (t == Kind.TIMEZ || t == Kind.TIME) -> true
- (i == Kind.TIMESTAMPZ || i == Kind.TIMESTAMP) && (t == Kind.TIMESTAMPZ || t == Kind.TIMESTAMP) -> true
+ i == PType.DATE && t == PType.DATE -> true
+ (i == PType.TIMEZ || i == PType.TIME) && (t == PType.TIMEZ || t == PType.TIME) -> true
+ (i == PType.TIMESTAMPZ || i == PType.TIMESTAMP) && (t == PType.TIMESTAMPZ || t == PType.TIMESTAMP) -> true
else -> false
}
}
diff --git a/partiql-spi/src/main/kotlin/org/partiql/value/PartiQLValueType.kt b/partiql-spi/src/main/kotlin/org/partiql/value/PartiQLValueType.kt
index 47873ec25..770712958 100644
--- a/partiql-spi/src/main/kotlin/org/partiql/value/PartiQLValueType.kt
+++ b/partiql-spi/src/main/kotlin/org/partiql/value/PartiQLValueType.kt
@@ -70,7 +70,7 @@ public enum class PartiQLValueType {
)
public fun toPType(): PType {
return when (this) {
- DECIMAL -> PType.decimal()
+ DECIMAL -> PType.decimal(38, 0)
DECIMAL_ARBITRARY -> error("DECIMAL_ARB has been removed.")
INT8 -> PType.tinyint()
CHAR -> PType.character(255)
@@ -84,7 +84,7 @@ public enum class PartiQLValueType {
LIST -> PType.array()
BAG -> PType.bag()
FLOAT32 -> PType.real()
- INT -> PType.numeric()
+ INT -> PType.numeric(38, 0)
INT64 -> PType.bigint()
INT32 -> PType.integer()
INT16 -> PType.smallint()
diff --git a/partiql-spi/src/test/kotlin/org/partiql/eval/value/DatumComparatorTest.kt b/partiql-spi/src/test/kotlin/org/partiql/eval/value/DatumComparatorTest.kt
index aac37eec0..9b19422c3 100644
--- a/partiql-spi/src/test/kotlin/org/partiql/eval/value/DatumComparatorTest.kt
+++ b/partiql-spi/src/test/kotlin/org/partiql/eval/value/DatumComparatorTest.kt
@@ -100,7 +100,7 @@ class DatumComparatorTest {
Datum.missing(), // missing
Datum.nullValue(), // TODO: annotations = listOf("a")), // `a::null`
Datum.missing(), // TODO: annotations = listOf("a")), // `a::missing`
- Datum.nullValue(PType.numeric()), // `null.int`,
+ Datum.nullValue(PType.numeric(38, 0)), // `null.int`,
Datum.nullValue(PType.struct()) // `null.struct`
)
)
diff --git a/partiql-types/api/partiql-types.api b/partiql-types/api/partiql-types.api
index 6145bbbf8..27e71076c 100644
--- a/partiql-types/api/partiql-types.api
+++ b/partiql-types/api/partiql-types.api
@@ -1,10 +1,45 @@
+public abstract class org/partiql/types/Enum {
+ protected fun (I)V
+ public final fun code ()I
+ public fun equals (Ljava/lang/Object;)Z
+ public fun hashCode ()I
+ public abstract fun name ()Ljava/lang/String;
+}
+
public abstract interface class org/partiql/types/Field {
public abstract fun getName ()Ljava/lang/String;
public abstract fun getType ()Lorg/partiql/types/PType;
public static fun of (Ljava/lang/String;Lorg/partiql/types/PType;)Lorg/partiql/types/Field;
}
-public abstract interface class org/partiql/types/PType {
+public abstract class org/partiql/types/PType : org/partiql/types/Enum {
+ public static final field ARRAY I
+ public static final field BAG I
+ public static final field BIGINT I
+ public static final field BLOB I
+ public static final field BOOL I
+ public static final field CHAR I
+ public static final field CLOB I
+ public static final field DATE I
+ public static final field DECIMAL I
+ public static final field DOUBLE I
+ public static final field DYNAMIC I
+ public static final field INTEGER I
+ public static final field NUMERIC I
+ public static final field REAL I
+ public static final field ROW I
+ public static final field SMALLINT I
+ public static final field STRING I
+ public static final field STRUCT I
+ public static final field TIME I
+ public static final field TIMESTAMP I
+ public static final field TIMESTAMPZ I
+ public static final field TIMEZ I
+ public static final field TINYINT I
+ public static final field UNKNOWN I
+ public static final field VARCHAR I
+ public static final field VARIANT I
+ protected fun (I)V
public static fun array ()Lorg/partiql/types/PType;
public static fun array (Lorg/partiql/types/PType;)Lorg/partiql/types/PType;
public static fun bag ()Lorg/partiql/types/PType;
@@ -14,20 +49,19 @@ public abstract interface class org/partiql/types/PType {
public static fun bool ()Lorg/partiql/types/PType;
public static fun character (I)Lorg/partiql/types/PType;
public static fun clob (I)Lorg/partiql/types/PType;
+ public static fun codes ()[I
public static fun date ()Lorg/partiql/types/PType;
- public static fun decimal ()Lorg/partiql/types/PType;
- public static fun decimal (I)Lorg/partiql/types/PType;
public static fun decimal (II)Lorg/partiql/types/PType;
public static fun doublePrecision ()Lorg/partiql/types/PType;
public static fun dynamic ()Lorg/partiql/types/PType;
public fun getFields ()Ljava/util/Collection;
- public abstract fun getKind ()Lorg/partiql/types/PType$Kind;
public fun getLength ()I
public fun getPrecision ()I
public fun getScale ()I
public fun getTypeParameter ()Lorg/partiql/types/PType;
public static fun integer ()Lorg/partiql/types/PType;
- public static fun numeric ()Lorg/partiql/types/PType;
+ public fun name ()Ljava/lang/String;
+ public static fun numeric (II)Lorg/partiql/types/PType;
public static fun real ()Lorg/partiql/types/PType;
public static fun row (Ljava/util/Collection;)Lorg/partiql/types/PType;
public static fun row ([Lorg/partiql/types/Field;)Lorg/partiql/types/PType;
@@ -44,34 +78,3 @@ public abstract interface class org/partiql/types/PType {
public static fun variant (Ljava/lang/String;)Lorg/partiql/types/PType;
}
-public final class org/partiql/types/PType$Kind : java/lang/Enum {
- public static final field ARRAY Lorg/partiql/types/PType$Kind;
- public static final field BAG Lorg/partiql/types/PType$Kind;
- public static final field BIGINT Lorg/partiql/types/PType$Kind;
- public static final field BLOB Lorg/partiql/types/PType$Kind;
- public static final field BOOL Lorg/partiql/types/PType$Kind;
- public static final field CHAR Lorg/partiql/types/PType$Kind;
- public static final field CLOB Lorg/partiql/types/PType$Kind;
- public static final field DATE Lorg/partiql/types/PType$Kind;
- public static final field DECIMAL Lorg/partiql/types/PType$Kind;
- public static final field DOUBLE Lorg/partiql/types/PType$Kind;
- public static final field DYNAMIC Lorg/partiql/types/PType$Kind;
- public static final field INTEGER Lorg/partiql/types/PType$Kind;
- public static final field NUMERIC Lorg/partiql/types/PType$Kind;
- public static final field REAL Lorg/partiql/types/PType$Kind;
- public static final field ROW Lorg/partiql/types/PType$Kind;
- public static final field SMALLINT Lorg/partiql/types/PType$Kind;
- public static final field STRING Lorg/partiql/types/PType$Kind;
- public static final field STRUCT Lorg/partiql/types/PType$Kind;
- public static final field TIME Lorg/partiql/types/PType$Kind;
- public static final field TIMESTAMP Lorg/partiql/types/PType$Kind;
- public static final field TIMESTAMPZ Lorg/partiql/types/PType$Kind;
- public static final field TIMEZ Lorg/partiql/types/PType$Kind;
- public static final field TINYINT Lorg/partiql/types/PType$Kind;
- public static final field UNKNOWN Lorg/partiql/types/PType$Kind;
- public static final field VARCHAR Lorg/partiql/types/PType$Kind;
- public static final field VARIANT Lorg/partiql/types/PType$Kind;
- public static fun valueOf (Ljava/lang/String;)Lorg/partiql/types/PType$Kind;
- public static fun values ()[Lorg/partiql/types/PType$Kind;
-}
-
diff --git a/partiql-types/src/main/java/org/partiql/types/Enum.java b/partiql-types/src/main/java/org/partiql/types/Enum.java
new file mode 100644
index 000000000..d44926067
--- /dev/null
+++ b/partiql-types/src/main/java/org/partiql/types/Enum.java
@@ -0,0 +1,50 @@
+package org.partiql.types;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Objects;
+
+/**
+ * All enumerated types should extend this class for backward/forward compatibility.
+ */
+public abstract class Enum {
+
+ /**
+ * Enum variants are represented with integers.
+ */
+ private final int code;
+
+ /**
+ * Creates an {@link Enum} with the specified {@code code}.
+ * @param code the unique code of this enum.
+ */
+ protected Enum(int code) {
+ this.code = code;
+ }
+
+ /**
+ * @return a unique integer corresponding with the variant of the enum.
+ */
+ public final int code() {
+ return code;
+ }
+
+ /**
+ * @return the name of the enum variant.
+ */
+ @NotNull
+ public abstract String name();
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Enum)) return false;
+ Enum other = (Enum) o;
+ return code == other.code;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(code);
+ }
+}
diff --git a/partiql-types/src/main/java/org/partiql/types/PType.java b/partiql-types/src/main/java/org/partiql/types/PType.java
index 094e3c769..afc74138a 100644
--- a/partiql-types/src/main/java/org/partiql/types/PType.java
+++ b/partiql-types/src/main/java/org/partiql/types/PType.java
@@ -8,11 +8,11 @@
/**
* This represents a PartiQL type, whether it be a PartiQL primitive or user-defined.
*
- * This implementation allows for parameterization of the core type ({@link Kind}) while allowing for APIs
+ * This implementation allows for parameterization of the core type ({@link PType#code()}) while allowing for APIs
* to access their parameters ({@link PType#getPrecision()}, {@link PType#getTypeParameter()}, etc.)
*
* Before using these methods, please be careful to read each method's documentation to ensure that it applies to the current
- * {@link PType#getKind()}. If one carelessly invokes the wrong method, an {@link UnsupportedOperationException} will be
+ * {@link PType#code()}. If one carelessly invokes the wrong method, an {@link UnsupportedOperationException} will be
* thrown.
*
* This representation of a PartiQL type is intentionally modeled as a "fat" interface -- holding all methods relevant
@@ -23,34 +23,25 @@
* Users should NOT author their own implementation. The current recommendation is to use the static methods
* (exposed by this interface) to instantiate a type.
*/
-public interface PType {
-
- /**
- * Dictates the associates {@link Kind} of this instance. This method should be called and its return should be
- * analyzed before calling any other method. For example:
- *
- * {@code
- * public int getPrecisionOrNull(PType type) {
- * if (type.base == {@link Kind#DECIMAL}) {
- * return type.getPrecision();
- * }
- * return null;
- * }
- * }
+public abstract class PType extends Enum {
+
+ /**
+ * Creates an {@link java.lang.Enum} with the specified {@code code}.
*
- * @return the corresponding PartiQL {@link Kind}.
+ * @param code the unique code of this enum.
*/
- @NotNull
- Kind getKind();
+ protected PType(int code) {
+ super(code);
+ }
/**
* The fields of the type
*
- * @throws UnsupportedOperationException if this is called on a type whose {@link Kind} is not:
- * {@link Kind#ROW}
+ * @throws UnsupportedOperationException if this is called on a type whose {@link PType#code()} is not:
+ * {@link PType#ROW}
*/
@NotNull
- default Collection getFields() throws UnsupportedOperationException {
+ public Collection getFields() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@@ -58,11 +49,11 @@ default Collection getFields() throws UnsupportedOperationException {
* The decimal precision of the type
*
* @return decimal precision
- * @throws UnsupportedOperationException if this is called on a type whose {@link Kind} is not:
- * {@link Kind#DECIMAL}, {@link Kind#TIMESTAMPZ}, {@link Kind#TIMESTAMP}, {@link Kind#TIMEZ},
- * {@link Kind#TIME}, {@link Kind#REAL}, {@link Kind#DOUBLE}
+ * @throws UnsupportedOperationException if this is called on a type whose {@link PType#code()} is not:
+ * {@link PType#DECIMAL}, {@link PType#TIMESTAMPZ}, {@link PType#TIMESTAMP}, {@link PType#TIMEZ},
+ * {@link PType#TIME}, {@link PType#REAL}, {@link PType#DOUBLE}
*/
- default int getPrecision() throws UnsupportedOperationException {
+ public int getPrecision() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@@ -70,10 +61,10 @@ default int getPrecision() throws UnsupportedOperationException {
* The max length of the type
*
* @return max length of a type
- * @throws UnsupportedOperationException if this is called on a type whose {@link Kind} is not:
- * {@link Kind#CHAR}, {@link Kind#CLOB}, {@link Kind#BLOB}
+ * @throws UnsupportedOperationException if this is called on a type whose {@link PType#code()} is not:
+ * {@link PType#CHAR}, {@link PType#CLOB}, {@link PType#BLOB}
*/
- default int getLength() throws UnsupportedOperationException {
+ public int getLength() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@@ -81,10 +72,10 @@ default int getLength() throws UnsupportedOperationException {
* The scale of the type. Example: DECIMAL(<param>, <scale>)
*
* @return the scale of the type
- * @throws UnsupportedOperationException if this is called on a type whose {@link Kind} is not:
- * {@link Kind#DECIMAL}
+ * @throws UnsupportedOperationException if this is called on a type whose {@link PType#code()} is not:
+ * {@link PType#DECIMAL}
*/
- default int getScale() throws UnsupportedOperationException {
+ public int getScale() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@@ -92,567 +83,616 @@ default int getScale() throws UnsupportedOperationException {
* The type parameter of the type. Example: BAG(<param>)
*
* @return type parameter of the type
- * @throws UnsupportedOperationException if this is called on a type whose {@link Kind} is not:
- * {@link Kind#ARRAY}, {@link Kind#BAG}
+ * @throws UnsupportedOperationException if this is called on a type whose {@link PType#code()} is not:
+ * {@link PType#ARRAY}, {@link PType#BAG}
*/
@NotNull
- default PType getTypeParameter() throws UnsupportedOperationException {
+ public PType getTypeParameter() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
+ public static int[] codes() {
+ return new int[] {
+ PType.DYNAMIC,
+ PType.BOOL,
+ PType.TINYINT,
+ PType.SMALLINT,
+ PType.INTEGER,
+ PType.BIGINT,
+ PType.NUMERIC,
+ PType.DECIMAL,
+ PType.REAL,
+ PType.DOUBLE,
+ PType.CHAR,
+ PType.VARCHAR,
+ PType.STRING,
+ PType.BLOB,
+ PType.CLOB,
+ PType.DATE,
+ PType.TIME,
+ PType.TIMEZ,
+ PType.TIMESTAMP,
+ PType.TIMESTAMPZ,
+ PType.ARRAY,
+ PType.BAG,
+ PType.ROW,
+ PType.STRUCT,
+ PType.UNKNOWN,
+ PType.VARIANT,
+ };
+ }
+
+ @Override
+ public @NotNull String name() {
+ switch (code()) {
+ case PType.DYNAMIC:
+ return "DYNAMIC";
+ case PType.BOOL:
+ return "BOOL";
+ case PType.TINYINT:
+ return "TINYINT";
+ case PType.SMALLINT:
+ return "SMALLINT";
+ case PType.INTEGER:
+ return "INTEGER";
+ case PType.BIGINT:
+ return "BIGINT";
+ case PType.NUMERIC:
+ return "NUMERIC";
+ case PType.DECIMAL:
+ return "DECIMAL";
+ case PType.REAL:
+ return "REAL";
+ case PType.DOUBLE:
+ return "DOUBLE";
+ case PType.CHAR:
+ return "CHAR";
+ case PType.VARCHAR:
+ return "VARCHAR";
+ case PType.STRING:
+ return "STRING";
+ case PType.BLOB:
+ return "BLOB";
+ case PType.CLOB:
+ return "CLOB";
+ case PType.DATE:
+ return "DATE";
+ case PType.TIME:
+ return "TIME";
+ case PType.TIMEZ:
+ return "TIMEZ";
+ case PType.TIMESTAMP:
+ return "TIMESTAMP";
+ case PType.TIMESTAMPZ:
+ return "TIMESTAMPZ";
+ case PType.ARRAY:
+ return "ARRAY";
+ case PType.BAG:
+ return "BAG";
+ case PType.ROW:
+ return "ROW";
+ case PType.STRUCT:
+ return "STRUCT";
+ case PType.UNKNOWN:
+ return "UNKNOWN";
+ case PType.VARIANT:
+ return "VARIANT";
+ default:
+ return "UNKNOWN";
+ }
+ }
+
+ /**
+ * PartiQL's dynamic type. This is solely used during compilation -- it is not a possible runtime type.
+ *
+ *
+ * Type Syntax: DYNAMIC
+ *
+ * Applicable methods: NONE
+ */
+ public static final int DYNAMIC = 0;
+
+ /**
+ * SQL's boolean type.
+ *
+ *
+ * Type Syntax: BOOL
, BOOLEAN
+ *
+ * Applicable methods: NONE
+ */
+ public static final int BOOL = 1;
+
+ /**
+ * PartiQL's tiny integer type.
+ *
+ *
+ * Type Syntax: TINYINT
+ *
+ * Applicable methods: NONE
+ */
+ public static final int TINYINT = 2;
+
+ /**
+ * SQL's small integer type.
+ *
+ *
+ * Type Syntax: SMALLINT
+ *
+ * Applicable methods: NONE
+ */
+ public static final int SMALLINT = 3;
+
+ /**
+ * SQL's integer type.
+ *
+ *
+ * Type Syntax: INT
, INTEGER
+ *
+ * Applicable methods: NONE
+ */
+ public static final int INTEGER = 4;
+
+ /**
+ * PartiQL's big integer type.
+ *
+ *
+ * Type Syntax: BIGINT
+ *
+ * Applicable methods: NONE
+ */
+ public static final int BIGINT = 5;
+
+ /**
+ * PartiQL's big integer type.
+ *
+ *
+ * Type Syntax: NUMERIC
+ *
+ * Applicable methods: {@link PType#getPrecision()}, {@link PType#getScale()}
+ */
+ public static final int NUMERIC = 6;
+
/**
- * PartiQL Core Type Kinds
- *
- * Each of these types correspond with a subset of APIs established in {@link PType}. Each of these can be seen as
- * a category of types, distinguished only by the APIs available to them. For instance, all instances of {@link Kind#DECIMAL}
- * may utilize {@link PType#getPrecision()} (and may return different results), however, they may never return a
- * valid value for {@link PType#getFields()}. Consumers of this API should be careful to read the documentation
- * for each API exposed in {@link PType} before using them.
- *
- * Future additions may add enums such as INTERVAL_YEAR_MONTH, INTERVAL_DAY_TIME, and more.
- *
- * @see PType
- */
- enum Kind {
-
- /**
- * PartiQL's dynamic type. This is solely used during compilation -- it is not a possible runtime type.
- *
- *
- * Type Syntax: DYNAMIC
- *
- * Applicable methods: NONE
- */
- DYNAMIC,
-
- /**
- * SQL's boolean type.
- *
- *
- * Type Syntax: BOOL
, BOOLEAN
- *
- * Applicable methods: NONE
- */
- BOOL,
-
- /**
- * PartiQL's tiny integer type.
- *
- *
- * Type Syntax: TINYINT
- *
- * Applicable methods: {@link PType#getPrecision()}, {@link PType#getScale()}
- */
- TINYINT,
-
- /**
- * SQL's small integer type.
- *
- *
- * Type Syntax: SMALLINT
- *
- * Applicable methods: {@link PType#getPrecision()}, {@link PType#getScale()}
- */
- SMALLINT,
-
- /**
- * SQL's integer type.
- *
- *
- * Type Syntax: INT
, INTEGER
- *
- * Applicable methods: {@link PType#getPrecision()}, {@link PType#getScale()}
- */
- INTEGER,
-
- /**
- * PartiQL's big integer type.
- *
- *
- * Type Syntax: BIGINT
- *
- * Applicable methods: {@link PType#getPrecision()}, {@link PType#getScale()}
- */
- BIGINT,
-
- /**
- * PartiQL's big integer type.
- *
- *
- * Type Syntax: NUMERIC
- *
- * Applicable methods: {@link PType#getPrecision()}, {@link PType#getScale()}
- */
- NUMERIC,
-
- /**
- * SQL's decimal type.
- *
- *
- * Type Syntax: DECIMAL(<precision>, <scale>)
, DECIMAL(<precision>)
- *
- * Applicable methods: {@link PType#getPrecision()}, {@link PType#getScale()}
- */
- DECIMAL,
-
- /**
- * SQL's real type.
- *
- *
- * Type Syntax: REAL
- *
- * Applicable methods: {@link PType#getPrecision()}
- */
- REAL,
-
- /**
- * SQL's double precision type.
- *
- *
- * Type Syntax: DOUBLE PRECISION
- *
- * Applicable methods: {@link PType#getPrecision()}
- */
- DOUBLE,
-
- /**
- * SQL's character type.
- *
- *
- * Type Syntax: CHAR(<length>)
, CHARACTER(<length>)
, CHAR
, CHARACTER
- *
- * Applicable methods: {@link PType#getLength()}
- */
- CHAR,
-
- /**
- * SQL's character varying type.
- *
- *
- * Type Syntax: VARCHAR(<length>)
, CHAR VARYING(<length>)
,
- * CHARACTER VARYING(<length>)
,
- * VARCHAR
, CHAR VARYING
, CHARACTER VARYING
- *
- * Applicable methods: {@link PType#getLength()}
- */
- VARCHAR,
-
- /**
- * PartiQL's string type.
- *
- *
- * Type Syntax: TO_BE_DETERMINED
- *
- * Applicable methods: NONE
- */
- STRING,
-
- /**
- * SQL's blob type.
- *
- *
- * Type Syntax: BLOB
, BLOB(<large object length>)
,
- * BINARY LARGE OBJECT
, BINARY LARGE OBJECT(<large object length>)
- *
- * Applicable methods: {@link PType#getLength()}
- *
- * @deprecated this is an experimental API and is subject to modification/deletion without prior notice.
- */
- @Deprecated
- BLOB,
-
- /**
- * SQL's clob type.
- *
- *
- * Type Syntax: CLOB
, CLOB(<large object length>)
,
- * CHAR LARGE OBJECT
, CHAR LARGE OBJECT(<large object length>)
- * CHARACTER LARGE OBJECT
, CHARACTER LARGE OBJECT(<large object length>)
- *
- * Applicable methods: {@link PType#getLength()}
- *
- * @deprecated this is an experimental API and is subject to modification/deletion without prior notice.
- */
- @Deprecated
- CLOB,
-
- /**
- * SQL's date type.
- *
- *
- * Type Syntax: DATE
- *
- * Applicable methods: NONE
- */
- DATE,
-
- /**
- * SQL's time without timezone type.
- *
- *
- * Type Syntax: TIME
, TIME WITHOUT TIME ZONE
,
- * TIME(<precision>)
, TIME(<precision>) WITHOUT TIME ZONE
- *
- * Applicable methods: NONE
- */
- TIME,
-
- /**
- * SQL's time with timezone type.
- *
- *
- * Type Syntax: TIME WITH TIME ZONE
, TIME(<precision>) WITH TIME ZONE
- *
- * Applicable methods: NONE
- */
- TIMEZ,
-
- /**
- * SQL's timestamp without timezone type.
- *
- *
- * Type Syntax: TIMESTAMP
, TIMESTAMP WITHOUT TIME ZONE
,
- * TIMESTAMP(<precision>)
, TIMESTAMP(<precision>) WITHOUT TIME ZONE
- *
- * Applicable methods: NONE
- */
- TIMESTAMP,
-
- /**
- * SQL's timestamp with timezone type.
- *
- *
- * Type Syntax: TIMESTAMP WITH TIME ZONE
, TIMESTAMP(<precision>) WITH TIME ZONE
- *
- * Applicable methods: NONE
- */
- TIMESTAMPZ,
-
- /**
- * ARRAY (LIST) represents an ordered collection of elements with type T.
- *
- *
- * Type Syntax
- *
- * ARRAY
- * T ARRAY[N]
- * ARRAY{@literal }[N]
- *
- *
- *
- * Equivalences
- *
- * T ARRAY[N] {@literal <->} ARRAY{@literal }[N]
- * ARRAY[N] {@literal <->} DYNAMIC ARRAY[N] {@literal <->} ARRAY{@literal }[N]
- * ARRAY {@literal <->} DYNAMIC ARRAY {@literal <->} ARRAY{@literal } {@literal <->} LIST
- *
- *
- * Applicable methods:
- * {@link PType#getTypeParameter()}
- */
- ARRAY,
-
- /**
- * BAG represents an unordered collection of elements with type T.
- *
- *
- * Type Syntax
- *
- * BAG
- * T BAG[N]
- * BAG{@literal }[N]
- *
- *
- *
- * Equivalences
- *
- * T BAG[N] {@literal <->} BAG{@literal }[N]
- * BAG[N] {@literal <->} DYNAMIC BAG[N] {@literal <->} BAG{@literal }[N]
- * BAG {@literal <->} DYNAMIC BAG {@literal <->} BAG{@literal }
- *
- *
- * Applicable methods:
- * {@link PType#getTypeParameter()}
- */
- BAG,
-
- /**
- * SQL's row type. Characterized as a closed, ordered collection of fields.
- *
- *
- * Type Syntax: ROW(<str>: <type>, ...)
- *
- * Applicable methods:
- * {@link PType#getFields()}
- *
- * @deprecated this is an experimental API and is subject to modification/deletion without prior notice.
- */
- @Deprecated
- ROW,
-
- /**
- * Ion's struct type. Characterized as an open, unordered collection of fields (duplicates allowed).
- *
- *
- * Type Syntax: STRUCT
- *
- * Applicable methods: NONE
- */
- STRUCT,
-
- /**
- * PartiQL's unknown type. This temporarily represents literal null and missing values.
- *
- *
- * Type Syntax: NONE
- *
- * Applicable methods: NONE
- *
- * @deprecated this is an experimental API and is subject to modification/deletion without prior notice.
- */
- @Deprecated
- UNKNOWN,
-
- /**
- * The variant type.
- *
- *
- * Type Syntax: T VARIANT or VARIANT[T]
- *
- */
- VARIANT,
- }
+ * SQL's decimal type.
+ *
+ *
+ * Type Syntax: DECIMAL(<precision>, <scale>)
, DECIMAL(<precision>)
+ *
+ * Applicable methods: {@link PType#getPrecision()}, {@link PType#getScale()}
+ */
+ public static final int DECIMAL = 7;
/**
- * @return a PartiQL dynamic type
+ * SQL's real type.
+ *
+ *
+ * Type Syntax: REAL
+ *
+ * Applicable methods: NONE
*/
- @NotNull
- static PType dynamic() {
- return new PTypePrimitive(Kind.DYNAMIC);
- }
+ public static final int REAL = 8;
/**
- * @return a PartiQL boolean type
+ * SQL's double precision type.
+ *
+ *
+ * Type Syntax: DOUBLE PRECISION
+ *
+ * Applicable methods: NONE
*/
- @NotNull
- static PType bool() {
- return new PTypePrimitive(Kind.BOOL);
- }
+ public static final int DOUBLE = 9;
/**
- * @return a PartiQL tiny integer type
+ * SQL's character type.
+ *
+ *
+ * Type Syntax: CHAR(<length>)
, CHARACTER(<length>)
, CHAR
, CHARACTER
+ *
+ * Applicable methods: {@link PType#getLength()}
+ */
+ public static final int CHAR = 10;
+
+ /**
+ * SQL's character varying type.
+ *
+ *
+ * Type Syntax: VARCHAR(<length>)
, CHAR VARYING(<length>)
,
+ * CHARACTER VARYING(<length>)
,
+ * VARCHAR
, CHAR VARYING
, CHARACTER VARYING
+ *
+ * Applicable methods: {@link PType#getLength()}
+ */
+ public static final int VARCHAR = 11;
+
+ /**
+ * PartiQL's string type.
+ *
+ *
+ * Type Syntax: TO_BE_DETERMINED
+ *
+ * Applicable methods: NONE
+ */
+ public static final int STRING = 12;
+
+ /**
+ * SQL's blob type.
+ *
+ *
+ * Type Syntax: BLOB
, BLOB(<large object length>)
,
+ * BINARY LARGE OBJECT
, BINARY LARGE OBJECT(<large object length>)
+ *
+ * Applicable methods: {@link PType#getLength()}
+ */
+ public static final int BLOB = 13;
+
+ /**
+ * SQL's clob type.
+ *
+ *
+ * Type Syntax: CLOB
, CLOB(<large object length>)
,
+ * CHAR LARGE OBJECT
, CHAR LARGE OBJECT(<large object length>)
+ * CHARACTER LARGE OBJECT
, CHARACTER LARGE OBJECT(<large object length>)
+ *
+ * Applicable methods: {@link PType#getLength()}
+ */
+ public static final int CLOB = 14;
+
+ /**
+ * SQL's date type.
+ *
+ *
+ * Type Syntax: DATE
+ *
+ * Applicable methods: NONE
+ */
+ public static final int DATE = 15;
+
+ /**
+ * SQL's time without timezone type.
+ *
+ *
+ * Type Syntax: TIME
, TIME WITHOUT TIME ZONE
,
+ * TIME(<precision>)
, TIME(<precision>) WITHOUT TIME ZONE
+ *
+ * Applicable methods: NONE
+ */
+ public static final int TIME = 16;
+
+ /**
+ * SQL's time with timezone type.
+ *
+ *
+ * Type Syntax: TIME WITH TIME ZONE
, TIME(<precision>) WITH TIME ZONE
+ *
+ * Applicable methods: NONE
+ */
+ public static final int TIMEZ = 17;
+
+ /**
+ * SQL's timestamp without timezone type.
+ *
+ *
+ * Type Syntax: TIMESTAMP
, TIMESTAMP WITHOUT TIME ZONE
,
+ * TIMESTAMP(<precision>)
, TIMESTAMP(<precision>) WITHOUT TIME ZONE
+ *
+ * Applicable methods: NONE
+ */
+ public static final int TIMESTAMP = 18;
+
+ /**
+ * SQL's timestamp with timezone type.
+ *
+ *
+ * Type Syntax: TIMESTAMP WITH TIME ZONE
, TIMESTAMP(<precision>) WITH TIME ZONE
+ *
+ * Applicable methods: NONE
+ */
+ public static final int TIMESTAMPZ = 19;
+
+ /**
+ * ARRAY (LIST) represents an ordered collection of elements with type T.
+ *
+ *
+ * Type Syntax
+ *
+ * ARRAY
+ * T ARRAY[N]
+ * ARRAY{@literal }[N]
+ *
+ *
+ *
+ * Equivalences
+ *
+ * T ARRAY[N] {@literal <->} ARRAY{@literal }[N]
+ * ARRAY[N] {@literal <->} DYNAMIC ARRAY[N] {@literal <->} ARRAY{@literal }[N]
+ * ARRAY {@literal <->} DYNAMIC ARRAY {@literal <->} ARRAY{@literal } {@literal <->} LIST
+ *
+ *
+ * Applicable methods:
+ * {@link PType#getTypeParameter()}
+ */
+ public static final int ARRAY = 20;
+
+ /**
+ * BAG represents an unordered collection of elements with type T.
+ *
+ *
+ * Type Syntax
+ *
+ * BAG
+ * T BAG[N]
+ * BAG{@literal }[N]
+ *
+ *
+ *
+ * Equivalences
+ *
+ * T BAG[N] {@literal <->} BAG{@literal }[N]
+ * BAG[N] {@literal <->} DYNAMIC BAG[N] {@literal <->} BAG{@literal }[N]
+ * BAG {@literal <->} DYNAMIC BAG {@literal <->} BAG{@literal }
+ *
+ *
+ * Applicable methods:
+ * {@link PType#getTypeParameter()}
+ */
+ public static final int BAG = 21;
+
+ /**
+ * SQL's row type. Characterized as a closed, ordered collection of fields.
+ *
+ *
+ * Type Syntax: ROW(<str>: <type>, ...)
+ *
+ * Applicable methods:
+ * {@link PType#getFields()}
+ */
+ public static final int ROW = 22;
+
+ /**
+ * Ion's struct type. Characterized as an open, unordered collection of fields (duplicates allowed).
+ *
+ *
+ * Type Syntax: STRUCT
+ *
+ * Applicable methods: NONE
+ */
+ public static final int STRUCT = 23;
+
+ /**
+ * PartiQL's unknown type. This temporarily represents literal null and missing values.
+ *
+ *
+ * Type Syntax: NONE
+ *
+ * Applicable methods: NONE
+ */
+ public static final int UNKNOWN = 24;
+
+ /**
+ * The variant type.
+ *
+ *
+ * Type Syntax: T VARIANT or VARIANT[T]
+ *
+ */
+ public static final int VARIANT = 25;
+
+ /**
+ * @return a PartiQL dynamic type
*/
@NotNull
- static PType tinyint() {
- return new PTypePrimitive(Kind.TINYINT);
+ public static PType dynamic() {
+ return new PTypePrimitive(DYNAMIC);
}
/**
- * @return a PartiQL small integer type
+ * @return a PartiQL boolean type
*/
@NotNull
- static PType smallint() {
- return new PTypePrimitive(Kind.SMALLINT);
+ public static PType bool() {
+ return new PTypePrimitive(BOOL);
}
/**
- * @return a PartiQL integer type
+ * @return a PartiQL tiny integer type
*/
@NotNull
- static PType integer() {
- return new PTypePrimitive(Kind.INTEGER);
+ @SuppressWarnings("unused")
+ public static PType tinyint() {
+ return new PTypePrimitive(TINYINT);
}
/**
- * @return a PartiQL big integer type
+ * @return a PartiQL small integer type
*/
@NotNull
- static PType bigint() {
- return new PTypePrimitive(Kind.BIGINT);
+ public static PType smallint() {
+ return new PTypePrimitive(SMALLINT);
}
/**
- * @return a PartiQL int (arbitrary precision) type
- * @deprecated this API is experimental and is subject to modification/deletion without prior notice.
+ * @return a PartiQL integer type
*/
@NotNull
- @Deprecated
- static PType numeric() {
- return new PTypePrimitive(Kind.NUMERIC);
+ public static PType integer() {
+ return new PTypePrimitive(INTEGER);
}
/**
- * @return a PartiQL decimal type
- * @deprecated this API is experimental and is subject to modification/deletion without prior notice.
+ * @return a PartiQL big integer type
*/
@NotNull
- static PType decimal() {
- return new PTypeDecimal(38, 0);
+ public static PType bigint() {
+ return new PTypePrimitive(BIGINT);
}
/**
- * @return a decimal with user-specified precision and default scale (0)
+ * @return a SQL:1999 NUMERIC type.
*/
@NotNull
- static PType decimal(int precision) {
- return new PTypeDecimal(precision, 0);
+ public static PType numeric(int precision, int scale) {
+ return new PTypeDecimal(NUMERIC, precision, scale);
}
/**
* @return a PartiQL decimal type
*/
@NotNull
- static PType decimal(int precision, int scale) {
- return new PTypeDecimal(precision, scale);
+ public static PType decimal(int precision, int scale) {
+ return new PTypeDecimal(PType.DECIMAL, precision, scale);
}
/**
* @return a PartiQL real type.
*/
@NotNull
- static PType real() {
- return new PTypePrimitive(Kind.REAL);
+ @SuppressWarnings("unused")
+ public static PType real() {
+ return new PTypePrimitive(REAL);
}
/**
* @return a PartiQL double precision type
*/
@NotNull
- static PType doublePrecision() {
- return new PTypePrimitive(Kind.DOUBLE);
+ public static PType doublePrecision() {
+ return new PTypePrimitive(DOUBLE);
}
/**
* @return a PartiQL char type
*/
@NotNull
- static PType character(int length) {
- return new PTypeWithMaxLength(Kind.CHAR, length);
+ @SuppressWarnings("unused")
+ public static PType character(int length) {
+ return new PTypeWithMaxLength(CHAR, length);
}
/**
* @return a PartiQL char type
*/
@NotNull
- static PType varchar(int length) {
- return new PTypeWithMaxLength(Kind.VARCHAR, length);
+ @SuppressWarnings("unused")
+ public static PType varchar(int length) {
+ return new PTypeWithMaxLength(VARCHAR, length);
}
/**
* @return a PartiQL string type
- *
- * TODO remove in favor of non-parameterized VARCHAR
*/
@NotNull
- static PType string() {
- return new PTypePrimitive(Kind.STRING);
+ public static PType string() {
+ return new PTypePrimitive(STRING);
}
/**
* @return a PartiQL clob type
- * @deprecated this API is experimental and is subject to modification/deletion without prior notice.
*/
@NotNull
- static PType clob(int length) {
- return new PTypeWithMaxLength(Kind.CLOB, length);
+ @SuppressWarnings("SameParameterValue")
+ public static PType clob(int length) {
+ return new PTypeWithMaxLength(CLOB, length);
}
/**
* @return a PartiQL blob type
- * @deprecated this API is experimental and is subject to modification/deletion without prior notice.
*/
@NotNull
- static PType blob(int length) {
- return new PTypeWithMaxLength(Kind.BLOB, length);
+ @SuppressWarnings("SameParameterValue")
+ public static PType blob(int length) {
+ return new PTypeWithMaxLength(BLOB, length);
}
/**
* @return a PartiQL date type
*/
@NotNull
- static PType date() {
- return new PTypePrimitive(Kind.DATE);
+ public static PType date() {
+ return new PTypePrimitive(DATE);
}
/**
* @return a PartiQL time without timezone type
*/
@NotNull
- static PType time(int precision) {
- return new PTypeWithPrecisionOnly(Kind.TIME, precision);
+ public static PType time(int precision) {
+ return new PTypeWithPrecisionOnly(TIME, precision);
}
/**
* @return a PartiQL time with timezone type
*/
@NotNull
- static PType timez(int precision) {
- return new PTypeWithPrecisionOnly(Kind.TIMEZ, precision);
+ @SuppressWarnings("unused")
+ public static PType timez(int precision) {
+ return new PTypeWithPrecisionOnly(TIMEZ, precision);
}
/**
* @return a PartiQL timestamp without timezone type
*/
@NotNull
- static PType timestamp(int precision) {
- return new PTypeWithPrecisionOnly(Kind.TIMESTAMP, precision);
+ public static PType timestamp(int precision) {
+ return new PTypeWithPrecisionOnly(TIMESTAMP, precision);
}
/**
* @return a PartiQL timestamp with timezone type
*/
@NotNull
- static PType timestampz(int precision) {
- return new PTypeWithPrecisionOnly(Kind.TIMESTAMPZ, precision);
+ @SuppressWarnings("unused")
+ public static PType timestampz(int precision) {
+ return new PTypeWithPrecisionOnly(TIMESTAMPZ, precision);
}
/**
* @return a PartiQL list type with a component type of dynamic
*/
@NotNull
- static PType array() {
- return new PTypeCollection(Kind.ARRAY, PType.dynamic());
+ @SuppressWarnings("unused")
+ public static PType array() {
+ return new PTypeCollection(ARRAY, PType.dynamic());
}
/**
* @return a PartiQL list type with a component type of {@code typeParam}
*/
@NotNull
- static PType array(@NotNull PType typeParam) {
- return new PTypeCollection(Kind.ARRAY, typeParam);
+ public static PType array(@NotNull PType typeParam) {
+ return new PTypeCollection(ARRAY, typeParam);
}
/**
* @return a PartiQL bag type with a component type of dynamic
*/
@NotNull
- static PType bag() {
- return new PTypeCollection(Kind.BAG, PType.dynamic());
+ @SuppressWarnings("unused")
+ public static PType bag() {
+ return new PTypeCollection(BAG, PType.dynamic());
}
/**
* @return a PartiQL bag type with a component type of {@code typeParam}
*/
@NotNull
- static PType bag(@NotNull PType typeParam) {
- return new PTypeCollection(Kind.BAG, typeParam);
+ public static PType bag(@NotNull PType typeParam) {
+ return new PTypeCollection(BAG, typeParam);
}
/**
* @return a PartiQL row type
- * @deprecated this API is experimental and is subject to modification/deletion without prior notice.
*/
@NotNull
- static PType row(@NotNull Collection fields) {
+ public static PType row(@NotNull Collection fields) {
return new PTypeRow(fields);
}
/**
* @return a PartiQL row type
- * @deprecated this API is experimental and is subject to modification/deletion without prior notice.
*/
@NotNull
- static PType row(@NotNull Field... fields) {
+ @SuppressWarnings("unused")
+ public static PType row(@NotNull Field... fields) {
return new PTypeRow(Arrays.asList(fields));
}
@@ -660,17 +700,17 @@ static PType row(@NotNull Field... fields) {
* @return a PartiQL struct type
*/
@NotNull
- static PType struct() {
- return new PTypePrimitive(Kind.STRUCT);
+ public static PType struct() {
+ return new PTypePrimitive(STRUCT);
}
/**
* @return a PartiQL unknown type
- * @deprecated this API is experimental and is subject to modification/deletion without prior notice.
*/
@NotNull
- static PType unknown() {
- return new PTypePrimitive(Kind.UNKNOWN);
+ @SuppressWarnings("unused")
+ public static PType unknown() {
+ return new PTypePrimitive(UNKNOWN);
}
/**
@@ -678,7 +718,8 @@ static PType unknown() {
* @return a PartiQL variant type.
*/
@NotNull
- static PType variant(String encoding) {
+ @SuppressWarnings("unused")
+ public static PType variant(String encoding) {
return new PTypeVariant(encoding);
}
}
diff --git a/partiql-types/src/main/java/org/partiql/types/PTypeCollection.java b/partiql-types/src/main/java/org/partiql/types/PTypeCollection.java
index ce1df809d..3cd4c8816 100644
--- a/partiql-types/src/main/java/org/partiql/types/PTypeCollection.java
+++ b/partiql-types/src/main/java/org/partiql/types/PTypeCollection.java
@@ -4,16 +4,13 @@
import java.util.Objects;
-class PTypeCollection implements PType {
+class PTypeCollection extends PType {
@NotNull
final PType _typeParam;
- @NotNull
- final Kind _kind;
-
- PTypeCollection(@NotNull Kind base, @NotNull PType typeParam) {
- _kind = base;
+ PTypeCollection(int code, @NotNull PType typeParam) {
+ super(code);
_typeParam = typeParam;
}
@@ -23,26 +20,20 @@ public PType getTypeParameter() {
return _typeParam;
}
- @NotNull
- @Override
- public Kind getKind() {
- return _kind;
- }
-
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PType)) return false;
- return ((PType) o).getKind() == this._kind && ((PType) o).getTypeParameter().equals(_typeParam);
+ return ((PType) o).code() == this.code() && ((PType) o).getTypeParameter().equals(_typeParam);
}
@Override
public String toString() {
- return _kind.name() + "(" + _typeParam + ")";
+ return name() + "(" + _typeParam + ")";
}
@Override
public int hashCode() {
- return Objects.hash(_kind, _typeParam);
+ return Objects.hash(code(), _typeParam);
}
}
diff --git a/partiql-types/src/main/java/org/partiql/types/PTypeDecimal.java b/partiql-types/src/main/java/org/partiql/types/PTypeDecimal.java
index 805fc33d2..12beb62a7 100644
--- a/partiql-types/src/main/java/org/partiql/types/PTypeDecimal.java
+++ b/partiql-types/src/main/java/org/partiql/types/PTypeDecimal.java
@@ -1,25 +1,20 @@
package org.partiql.types;
-import org.jetbrains.annotations.NotNull;
-
import java.util.Objects;
-class PTypeDecimal implements PType {
+/**
+ * Relevant to only {@link PType#DECIMAL} and {@link PType#NUMERIC}.
+ */
+class PTypeDecimal extends PType {
final int _precision;
final int _scale;
- PTypeDecimal(int precision, int scale) {
+ PTypeDecimal(int code, int precision, int scale) {
+ super(code);
_precision = precision;
_scale = scale;
}
- @NotNull
- @Override
- public Kind getKind() {
- return Kind.DECIMAL;
- }
-
- @Override
public int getPrecision() {
return _precision;
}
@@ -33,16 +28,16 @@ public int getScale() {
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PType)) return false;
- return ((PType) o).getKind() == Kind.DECIMAL && _precision == ((PType) o).getPrecision() && _scale == ((PType) o).getScale();
+ return ((PType) o).code() == code() && _precision == ((PType) o).getPrecision() && _scale == ((PType) o).getScale();
}
@Override
public String toString() {
- return Kind.DECIMAL.name() + "(" + _precision + ", " + _scale + ")";
+ return name() + "(" + _precision + ", " + _scale + ")";
}
@Override
public int hashCode() {
- return Objects.hash(Kind.DECIMAL, _precision, _scale);
+ return Objects.hash(PType.DECIMAL, _precision, _scale);
}
}
diff --git a/partiql-types/src/main/java/org/partiql/types/PTypePrimitive.java b/partiql-types/src/main/java/org/partiql/types/PTypePrimitive.java
index ea92bb213..3497595f7 100644
--- a/partiql-types/src/main/java/org/partiql/types/PTypePrimitive.java
+++ b/partiql-types/src/main/java/org/partiql/types/PTypePrimitive.java
@@ -1,38 +1,27 @@
package org.partiql.types;
-import org.jetbrains.annotations.NotNull;
-
import java.util.Objects;
-class PTypePrimitive implements PType {
-
- @NotNull
- final Kind _kind;
+class PTypePrimitive extends PType {
- PTypePrimitive(@NotNull Kind type) {
- _kind = type;
- }
-
- @NotNull
- @Override
- public Kind getKind() {
- return _kind;
+ PTypePrimitive(int code) {
+ super(code);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PType)) return false;
- return _kind == ((PType) o).getKind();
+ return code() == ((PType) o).code();
}
@Override
public String toString() {
- return _kind.name();
+ return name();
}
@Override
public int hashCode() {
- return Objects.hashCode(_kind);
+ return Objects.hashCode(code());
}
}
diff --git a/partiql-types/src/main/java/org/partiql/types/PTypeRow.java b/partiql-types/src/main/java/org/partiql/types/PTypeRow.java
index 419b3b87c..82393b7cf 100644
--- a/partiql-types/src/main/java/org/partiql/types/PTypeRow.java
+++ b/partiql-types/src/main/java/org/partiql/types/PTypeRow.java
@@ -8,22 +8,17 @@
import java.util.stream.Collectors;
/**
- * Applicable to {@link PType.Kind#ROW}.
+ * Applicable to {@link PType#ROW}.
*/
-class PTypeRow implements PType {
+class PTypeRow extends PType {
final Collection _fields;
PTypeRow(@NotNull Collection fields) {
+ super(PType.ROW);
_fields = fields;
}
- @NotNull
- @Override
- public Kind getKind() {
- return Kind.ROW;
- }
-
@NotNull
@Override
public Collection getFields() {
@@ -34,7 +29,7 @@ public Collection getFields() {
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PType)) return false;
- if (Kind.ROW != ((PType) o).getKind()) {
+ if (PType.ROW != ((PType) o).code()) {
return false;
}
Collection otherFields = ((PType) o).getFields();
@@ -58,11 +53,11 @@ public boolean equals(Object o) {
public String toString() {
Collection fieldStringList = _fields.stream().map((f) -> f.getName() + ": " + f.getType()).collect(Collectors.toList());
String fieldStrings = String.join(", ", fieldStringList);
- return Kind.ROW.name() + "(" + fieldStrings + ")";
+ return "ROW(" + fieldStrings + ")";
}
@Override
public int hashCode() {
- return Objects.hash(Kind.ROW, _fields);
+ return Objects.hash(code(), _fields);
}
}
diff --git a/partiql-types/src/main/java/org/partiql/types/PTypeVariant.java b/partiql-types/src/main/java/org/partiql/types/PTypeVariant.java
index b636bf2e7..c8ac2a8d2 100644
--- a/partiql-types/src/main/java/org/partiql/types/PTypeVariant.java
+++ b/partiql-types/src/main/java/org/partiql/types/PTypeVariant.java
@@ -1,19 +1,12 @@
package org.partiql.types;
-import org.jetbrains.annotations.NotNull;
-
-class PTypeVariant implements PType {
+class PTypeVariant extends PType {
+ // TODO: Use this somehow
private final String encoding;
public PTypeVariant(String encoding) {
+ super(VARIANT);
this.encoding = encoding;
}
-
- @NotNull
- @Override
- public Kind getKind() {
- return Kind.VARIANT;
- }
-
}
diff --git a/partiql-types/src/main/java/org/partiql/types/PTypeWithMaxLength.java b/partiql-types/src/main/java/org/partiql/types/PTypeWithMaxLength.java
index 7c6704422..fb97228de 100644
--- a/partiql-types/src/main/java/org/partiql/types/PTypeWithMaxLength.java
+++ b/partiql-types/src/main/java/org/partiql/types/PTypeWithMaxLength.java
@@ -1,26 +1,16 @@
package org.partiql.types;
-import org.jetbrains.annotations.NotNull;
-
import java.util.Objects;
-class PTypeWithMaxLength implements PType {
+class PTypeWithMaxLength extends PType {
final int _maxLength;
- final Kind _kind;
-
- PTypeWithMaxLength(@NotNull Kind type, int maxLength) {
- _kind = type;
+ PTypeWithMaxLength(int code, int maxLength) {
+ super(code);
_maxLength = maxLength;
}
- @NotNull
- @Override
- public Kind getKind() {
- return _kind;
- }
-
@Override
public int getLength() {
return _maxLength;
@@ -30,16 +20,16 @@ public int getLength() {
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PType)) return false;
- return _kind == ((PType) o).getKind() && _maxLength == ((PType) o).getLength();
+ return code() == ((PType) o).code() && _maxLength == ((PType) o).getLength();
}
@Override
public String toString() {
- return _kind.name() + "(" + _maxLength + ")";
+ return name() + "(" + _maxLength + ")";
}
@Override
public int hashCode() {
- return Objects.hash(_kind, _maxLength);
+ return Objects.hash(code(), _maxLength);
}
}
diff --git a/partiql-types/src/main/java/org/partiql/types/PTypeWithPrecisionOnly.java b/partiql-types/src/main/java/org/partiql/types/PTypeWithPrecisionOnly.java
index 05b94dc77..4a1916601 100644
--- a/partiql-types/src/main/java/org/partiql/types/PTypeWithPrecisionOnly.java
+++ b/partiql-types/src/main/java/org/partiql/types/PTypeWithPrecisionOnly.java
@@ -1,28 +1,16 @@
package org.partiql.types;
-import org.jetbrains.annotations.NotNull;
-
import java.util.Objects;
-class PTypeWithPrecisionOnly implements PType {
+class PTypeWithPrecisionOnly extends PType {
final int _precision;
- @NotNull
- final Kind _kind;
-
- PTypeWithPrecisionOnly(@NotNull Kind base, int precision) {
+ PTypeWithPrecisionOnly(int code, int precision) {
+ super(code);
_precision = precision;
- _kind = base;
- }
-
- @NotNull
- @Override
- public Kind getKind() {
- return _kind;
}
- @Override
public int getPrecision() {
return _precision;
}
@@ -31,16 +19,16 @@ public int getPrecision() {
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PType)) return false;
- return _kind == ((PType) o).getKind() && _precision == ((PType) o).getPrecision();
+ return code() == ((PType) o).code() && _precision == ((PType) o).getPrecision();
}
@Override
public String toString() {
- return _kind.name() + "(" + _precision + ")";
+ return name() + "(" + _precision + ")";
}
@Override
public int hashCode() {
- return Objects.hash(_kind, _precision);
+ return Objects.hash(code(), _precision);
}
}
diff --git a/partiql-types/src/testFixtures/kotlin/org/partiql/types/FromStaticType.kt b/partiql-types/src/testFixtures/kotlin/org/partiql/types/FromStaticType.kt
index e006a2878..b7fa411be 100644
--- a/partiql-types/src/testFixtures/kotlin/org/partiql/types/FromStaticType.kt
+++ b/partiql-types/src/testFixtures/kotlin/org/partiql/types/FromStaticType.kt
@@ -36,7 +36,7 @@ fun fromStaticType(type: StaticType): PType {
} else if (type is DecimalType) {
val precScale = type.precisionScaleConstraint
if (precScale is DecimalType.PrecisionScaleConstraint.Unconstrained) {
- return PType.decimal()
+ return PType.decimal(38, 0)
} else if (precScale is DecimalType.PrecisionScaleConstraint.Constrained) {
val precisionScaleConstraint = precScale
return PType.decimal(precisionScaleConstraint.precision, precisionScaleConstraint.scale)
@@ -54,7 +54,7 @@ fun fromStaticType(type: StaticType): PType {
} else if (cons == IntType.IntRangeConstraint.LONG) {
PType.bigint()
} else if (cons == IntType.IntRangeConstraint.UNCONSTRAINED) {
- PType.numeric()
+ PType.numeric(38, 0)
} else {
throw IllegalStateException()
}