Skip to content

Initializes PType #1488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion partiql-cli/src/main/kotlin/org/partiql/cli/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ package org.partiql.cli

import com.amazon.ion.system.IonSystemBuilder
import com.amazon.ion.system.IonTextWriterBuilder
import com.amazon.ionelement.api.IonElement
import com.amazon.ionelement.api.ionString
import org.partiql.cli.pico.PartiQLCommand
import org.partiql.cli.shell.info
import org.partiql.lang.eval.EvaluationSession
import org.partiql.parser.PartiQLParser
import org.partiql.plan.Statement
import org.partiql.plan.debug.PlanPrinter
import org.partiql.planner.PartiQLPlanner
import org.partiql.plugins.local.toIon
import org.partiql.types.PType
import picocli.CommandLine
import java.io.PrintStream
import java.nio.file.Paths
Expand Down Expand Up @@ -92,4 +94,8 @@ object Debug {

return "OK"
}

private fun PType.toIon(): IonElement {
return ionString(this.toString())
}
}
6 changes: 3 additions & 3 deletions partiql-eval/api/partiql-eval.api
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ public abstract interface class org/partiql/eval/value/Datum : java/lang/Iterabl
public fun getString ()Ljava/lang/String;
public fun getTime ()Lorg/partiql/value/datetime/Time;
public fun getTimestamp ()Lorg/partiql/value/datetime/Timestamp;
public abstract fun getType ()Lorg/partiql/value/PartiQLValueType;
public abstract fun getType ()Lorg/partiql/types/PType;
public static fun int32Value (I)Lorg/partiql/eval/value/Datum;
public static fun int64Value (J)Lorg/partiql/eval/value/Datum;
public fun isMissing ()Z
public fun isNull ()Z
public fun iterator ()Ljava/util/Iterator;
public static fun listValue (Ljava/lang/Iterable;)Lorg/partiql/eval/value/Datum;
public static fun missingValue ()Lorg/partiql/eval/value/Datum;
public static fun missingValue (Lorg/partiql/value/PartiQLValueType;)Lorg/partiql/eval/value/Datum;
public static fun missingValue (Lorg/partiql/types/PType;)Lorg/partiql/eval/value/Datum;
public static fun nullValue ()Lorg/partiql/eval/value/Datum;
public static fun nullValue (Lorg/partiql/value/PartiQLValueType;)Lorg/partiql/eval/value/Datum;
public static fun nullValue (Lorg/partiql/types/PType;)Lorg/partiql/eval/value/Datum;
public static fun of (Lorg/partiql/value/PartiQLValue;)Lorg/partiql/eval/value/Datum;
public static fun sexpValue (Ljava/lang/Iterable;)Lorg/partiql/eval/value/Datum;
public static fun stringValue (Ljava/lang/String;)Lorg/partiql/eval/value/Datum;
Expand Down
92 changes: 45 additions & 47 deletions partiql-eval/src/main/java/org/partiql/eval/value/Datum.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import kotlin.NotImplementedError;
import kotlin.Pair;
import org.jetbrains.annotations.NotNull;
import org.partiql.types.PType;
import org.partiql.value.PartiQL;
import org.partiql.value.PartiQLValue;
import org.partiql.value.PartiQLValueType;
Expand All @@ -11,7 +12,6 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.BitSet;
import java.util.Iterator;
import java.util.Objects;

Expand Down Expand Up @@ -60,7 +60,7 @@ default boolean isMissing() {
* @return the type of the data at the cursor.
*/
@NotNull
PartiQLValueType getType();
PType getType();

/**
* @return the underlying value applicable to the types:
Expand Down Expand Up @@ -346,64 +346,63 @@ default Datum getInsensitive(@NotNull String name) {
@NotNull
@Deprecated
default PartiQLValue toPartiQLValue() {
PartiQLValueType type = this.getType();
switch (type) {
PType type = this.getType();
switch (type.getKind()) {
case BOOL:
return this.isNull() ? PartiQL.boolValue(null) : PartiQL.boolValue(this.getBoolean());
case INT8:
case TINYINT:
return this.isNull() ? PartiQL.int8Value(null) : PartiQL.int8Value(this.getByte());
case INT16:
case SMALLINT:
return this.isNull() ? PartiQL.int16Value(null) : PartiQL.int16Value(this.getShort());
case INT32:
case INT:
return this.isNull() ? PartiQL.int32Value(null) : PartiQL.int32Value(this.getInt());
case INT64:
case BIGINT:
return this.isNull() ? PartiQL.int64Value(null) : PartiQL.int64Value(this.getLong());
case INT:
case INT_ARBITRARY:
return this.isNull() ? PartiQL.intValue(null) : PartiQL.intValue(this.getBigInteger());
case DECIMAL:
case DECIMAL_ARBITRARY:
return this.isNull() ? PartiQL.decimalValue(null) : PartiQL.decimalValue(this.getBigDecimal());
case FLOAT32:
case REAL:
return this.isNull() ? PartiQL.float32Value(null) : PartiQL.float32Value(this.getFloat());
case FLOAT64:
case DOUBLE_PRECISION:
return this.isNull() ? PartiQL.float64Value(null) : PartiQL.float64Value(this.getDouble());
case CHAR:
return this.isNull() ? PartiQL.charValue(null) : PartiQL.charValue(this.getString().charAt(0));
case STRING:
return this.isNull() ? PartiQL.stringValue(null) : PartiQL.stringValue(this.getString());
case SYMBOL:
return this.isNull() ? PartiQL.symbolValue(null) : PartiQL.symbolValue(this.getString());
case BINARY:
return this.isNull() ? PartiQL.binaryValue(null) : PartiQL.binaryValue(BitSet.valueOf(this.getBytes()));
case BYTE:
return this.isNull() ? PartiQL.byteValue(null) : PartiQL.byteValue(this.getByte());
case BLOB:
return this.isNull() ? PartiQL.blobValue(null) : PartiQL.blobValue(this.getBytes());
case CLOB:
return this.isNull() ? PartiQL.clobValue(null) : PartiQL.clobValue(this.getBytes());
case DATE:
return this.isNull() ? PartiQL.dateValue(null) : PartiQL.dateValue(this.getDate());
case TIME:
case TIME_WITH_TZ:
case TIME_WITHOUT_TZ: // TODO
return this.isNull() ? PartiQL.timeValue(null) : PartiQL.timeValue(this.getTime());
case TIMESTAMP:
case TIMESTAMP_WITH_TZ:
case TIMESTAMP_WITHOUT_TZ:
return this.isNull() ? PartiQL.timestampValue(null) : PartiQL.timestampValue(this.getTimestamp());
case INTERVAL:
return this.isNull() ? PartiQL.intervalValue(null) : PartiQL.intervalValue(this.getInterval());
case BAG:
return this.isNull() ? PartiQL.bagValue((Iterable<? extends PartiQLValue>) null) : PartiQL.bagValue(new PQLToPartiQLIterable(this));
case LIST:
return this.isNull() ? PartiQL.listValue((Iterable<? extends PartiQLValue>) null) : PartiQL.listValue(new PQLToPartiQLIterable(this));
case SEXP:
return this.isNull() ? PartiQL.sexpValue((Iterable<? extends PartiQLValue>) null) : PartiQL.sexpValue(new PQLToPartiQLIterable(this));
case STRUCT:
case ROW:
return this.isNull() ? PartiQL.structValue((Iterable<? extends Pair<String, ? extends PartiQLValue>>) null) : PartiQL.structValue(new PQLToPartiQLStruct(this));
case NULL: // TODO: This will probably be deleted very soon due to the deprecation of NULL and MISSING types
return PartiQL.nullValue();
case MISSING: // TODO: This will probably be deleted very soon due to the deprecation of NULL and MISSING types
return PartiQL.missingValue();
case ANY:
case DYNAMIC:
case UNKNOWN:
if (this.isNull()) {
return PartiQL.nullValue();
} else if (this.isMissing()) {
return PartiQL.missingValue();
}
default:
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("Unsupported datum type: " + type);
}
}

Expand All @@ -417,7 +416,7 @@ default PartiQLValue toPartiQLValue() {
static Datum of(PartiQLValue value) {
PartiQLValueType type = value.getType();
if (value.isNull()) {
return new DatumNull(type);
return new DatumNull(PType.fromPartiQLValueType(type));
}
switch (type) {
case MISSING:
Expand All @@ -426,13 +425,13 @@ static Datum of(PartiQLValue value) {
return new DatumNull();
case INT8:
org.partiql.value.Int8Value int8Value = (org.partiql.value.Int8Value) value;
return new DatumByte(Objects.requireNonNull(int8Value.getValue()), PartiQLValueType.INT8);
return new DatumByte(Objects.requireNonNull(int8Value.getValue()), PType.typeTinyInt());
case STRUCT:
@SuppressWarnings("unchecked") org.partiql.value.StructValue<PartiQLValue> STRUCTValue = (org.partiql.value.StructValue<PartiQLValue>) value;
return new DatumStruct(new PartiQLToPQLStruct(Objects.requireNonNull(STRUCTValue)));
case STRING:
org.partiql.value.StringValue STRINGValue = (org.partiql.value.StringValue) value;
return new DatumString(Objects.requireNonNull(STRINGValue.getValue()), PartiQLValueType.STRING);
return new DatumString(Objects.requireNonNull(STRINGValue.getValue()), PType.typeString());
case INT64:
org.partiql.value.Int64Value INT64Value = (org.partiql.value.Int64Value) value;
return new DatumLong(Objects.requireNonNull(INT64Value.getValue()));
Expand All @@ -444,10 +443,10 @@ static Datum of(PartiQLValue value) {
return new DatumShort(Objects.requireNonNull(INT16Value.getValue()));
case SEXP:
@SuppressWarnings("unchecked") org.partiql.value.SexpValue<PartiQLValue> sexpValue = (org.partiql.value.SexpValue<PartiQLValue>) value;
return new DatumCollection(new PartiQLToPQLIterable(Objects.requireNonNull(sexpValue)), PartiQLValueType.SEXP);
return new DatumCollection(new PartiQLToPQLIterable(Objects.requireNonNull(sexpValue)), PType.typeSexp());
case LIST:
@SuppressWarnings("unchecked") org.partiql.value.ListValue<PartiQLValue> LISTValue = (org.partiql.value.ListValue<PartiQLValue>) value;
return new DatumCollection(new PartiQLToPQLIterable(Objects.requireNonNull(LISTValue)), PartiQLValueType.LIST);
return new DatumCollection(new PartiQLToPQLIterable(Objects.requireNonNull(LISTValue)), PType.typeList());
case BOOL:
org.partiql.value.BoolValue BOOLValue = (org.partiql.value.BoolValue) value;
return new DatumBoolean(Objects.requireNonNull(BOOLValue.getValue()));
Expand All @@ -456,10 +455,9 @@ static Datum of(PartiQLValue value) {
return new DatumBigInteger(Objects.requireNonNull(INTValue.getValue()));
case BAG:
@SuppressWarnings("unchecked") org.partiql.value.BagValue<PartiQLValue> BAGValue = (org.partiql.value.BagValue<PartiQLValue>) value;
return new DatumCollection(new PartiQLToPQLIterable(Objects.requireNonNull(BAGValue)), PartiQLValueType.BAG);
return new DatumCollection(new PartiQLToPQLIterable(Objects.requireNonNull(BAGValue)), PType.typeBag());
case BINARY:
org.partiql.value.BinaryValue BINARYValue = (org.partiql.value.BinaryValue) value;
return new DatumBytes(Objects.requireNonNull(Objects.requireNonNull(BINARYValue.getValue()).toByteArray()), PartiQLValueType.BINARY);
throw new UnsupportedOperationException();
case DATE:
org.partiql.value.DateValue DATEValue = (org.partiql.value.DateValue) value;
return new DatumDate(Objects.requireNonNull(DATEValue.getValue()));
Expand All @@ -480,25 +478,25 @@ static Datum of(PartiQLValue value) {
return new DatumDouble(Objects.requireNonNull(FLOAT64Value.getValue()));
case DECIMAL:
org.partiql.value.DecimalValue DECIMALValue = (org.partiql.value.DecimalValue) value;
return new DatumDecimal(Objects.requireNonNull(DECIMALValue.getValue()), PartiQLValueType.DECIMAL);
return new DatumDecimal(Objects.requireNonNull(DECIMALValue.getValue()), PType.typeDecimalArbitrary());
case CHAR:
org.partiql.value.CharValue CHARValue = (org.partiql.value.CharValue) value;
return new DatumChars(Objects.requireNonNull(Objects.requireNonNull(CHARValue.getValue()).toString()));
String charString = Objects.requireNonNull(CHARValue.getValue()).toString();
return new DatumChars(charString, charString.length());
case SYMBOL:
org.partiql.value.SymbolValue SYMBOLValue = (org.partiql.value.SymbolValue) value;
return new DatumString(Objects.requireNonNull(SYMBOLValue.getValue()), PartiQLValueType.SYMBOL);
return new DatumString(Objects.requireNonNull(SYMBOLValue.getValue()), PType.typeSymbol());
case CLOB:
org.partiql.value.ClobValue CLOBValue = (org.partiql.value.ClobValue) value;
return new DatumBytes(Objects.requireNonNull(CLOBValue.getValue()), PartiQLValueType.CLOB);
return new DatumBytes(Objects.requireNonNull(CLOBValue.getValue()), PType.typeClob(Integer.MAX_VALUE)); // TODO
case BLOB:
org.partiql.value.BlobValue BLOBValue = (org.partiql.value.BlobValue) value;
return new DatumBytes(Objects.requireNonNull(BLOBValue.getValue()), PartiQLValueType.BLOB);
return new DatumBytes(Objects.requireNonNull(BLOBValue.getValue()), PType.typeBlob(Integer.MAX_VALUE)); // TODO
case BYTE:
org.partiql.value.ByteValue BYTEValue = (org.partiql.value.ByteValue) value;
return new DatumByte(Objects.requireNonNull(BYTEValue.getValue()), PartiQLValueType.BYTE);
throw new UnsupportedOperationException();
case DECIMAL_ARBITRARY:
org.partiql.value.DecimalValue DECIMAL_ARBITRARYValue = (org.partiql.value.DecimalValue) value;
return new DatumDecimal(Objects.requireNonNull(DECIMAL_ARBITRARYValue.getValue()), PartiQLValueType.DECIMAL_ARBITRARY);
return new DatumDecimal(Objects.requireNonNull(DECIMAL_ARBITRARYValue.getValue()), PType.typeDecimalArbitrary());
case ANY:
default:
throw new NotImplementedError();
Expand All @@ -516,7 +514,7 @@ static Datum missingValue() {
}

@NotNull
static Datum nullValue(@NotNull PartiQLValueType type) {
static Datum nullValue(@NotNull PType type) {
return new DatumNull(type);
}

Expand All @@ -529,13 +527,13 @@ static Datum nullValue(@NotNull PartiQLValueType type) {
*/
@Deprecated
@NotNull
static Datum missingValue(@NotNull PartiQLValueType type) {
static Datum missingValue(@NotNull PType type) {
return new DatumMissing(type);
}

@NotNull
static Datum bagValue(@NotNull Iterable<Datum> values) {
return new DatumCollection(values, PartiQLValueType.BAG);
return new DatumCollection(values, PType.typeBag());
}

@NotNull
Expand All @@ -555,12 +553,12 @@ static Datum boolValue(boolean value) {

@NotNull
static Datum sexpValue(@NotNull Iterable<Datum> values) {
return new DatumCollection(values, PartiQLValueType.SEXP);
return new DatumCollection(values, PType.typeSexp());
}

@NotNull
static Datum listValue(@NotNull Iterable<Datum> values) {
return new DatumCollection(values, PartiQLValueType.LIST);
return new DatumCollection(values, PType.typeList());
}

@NotNull
Expand All @@ -570,6 +568,6 @@ static Datum structValue(@NotNull Iterable<Field> values) {

@NotNull
static Datum stringValue(@NotNull String value) {
return new DatumString(value, PartiQLValueType.STRING);
return new DatumString(value, PType.typeString());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.partiql.eval.value;

import org.jetbrains.annotations.NotNull;
import org.partiql.value.PartiQLValueType;
import org.partiql.types.PType;

import java.math.BigInteger;

Expand All @@ -13,6 +13,8 @@ class DatumBigInteger implements Datum {
@NotNull
private final BigInteger _value;

private final static PType _type = PType.typeIntArbitrary();

DatumBigInteger(@NotNull BigInteger value) {
_value = value;
}
Expand All @@ -25,7 +27,7 @@ public BigInteger getBigInteger() {

@NotNull
@Override
public PartiQLValueType getType() {
return PartiQLValueType.INT;
public PType getType() {
return _type;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.partiql.eval.value;

import org.jetbrains.annotations.NotNull;
import org.partiql.value.PartiQLValueType;
import org.partiql.types.PType;

/**
* This shall always be package-private (internal).
Expand All @@ -10,6 +10,8 @@ class DatumBoolean implements Datum {

private final boolean _value;

private final static PType _type = PType.typeBool();

DatumBoolean(boolean value) {
_value = value;
}
Expand All @@ -21,7 +23,7 @@ public boolean getBoolean() {

@NotNull
@Override
public PartiQLValueType getType() {
return PartiQLValueType.BOOL;
public PType getType() {
return _type;
}
}
12 changes: 5 additions & 7 deletions partiql-eval/src/main/java/org/partiql/eval/value/DatumByte.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package org.partiql.eval.value;

import org.jetbrains.annotations.NotNull;
import org.partiql.value.PartiQLValueType;
import org.partiql.types.PType;

/**
* This shall always be package-private (internal).
* <p></p>
* This is specifically for:
* {@link PartiQLValueType#BYTE},
* {@link PartiQLValueType#INT8}
* {@link PType.Kind#TINYINT}
*/
class DatumByte implements Datum {

private final byte _value;

@NotNull
private final PartiQLValueType _type;
private final PType _type;

DatumByte(byte value, @NotNull PartiQLValueType type) {
assert(type == PartiQLValueType.BYTE || type == PartiQLValueType.INT8);
DatumByte(byte value, @NotNull PType type) {
_value = value;
_type = type;
}
Expand All @@ -30,7 +28,7 @@ public byte getByte() {

@NotNull
@Override
public PartiQLValueType getType() {
public PType getType() {
return _type;
}
}
Loading
Loading