diff --git a/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEvaluatorTest.kt b/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEvaluatorTest.kt index a0030fc9e..ccdb6bbe5 100644 --- a/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEvaluatorTest.kt +++ b/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEvaluatorTest.kt @@ -9,6 +9,7 @@ import org.junit.jupiter.params.provider.MethodSource import org.partiql.eval.Mode import org.partiql.eval.compiler.PartiQLCompiler import org.partiql.spi.types.PType +import org.partiql.spi.types.PTypeField import org.partiql.spi.value.Datum import org.partiql.spi.value.Field import org.partiql.value.PartiQLValue @@ -1437,7 +1438,7 @@ class PartiQLEvaluatorTest { globals = listOf( Global( name = "t", - type = PType.row(org.partiql.spi.types.Field.of("a", PType.integer())), + type = PType.row(PTypeField.of("a", PType.integer())), value = Datum.row(Field.of("a", Datum.integer(3))) ), ) diff --git a/partiql-plan/api/partiql-plan.api b/partiql-plan/api/partiql-plan.api index edcc0230a..72992801a 100644 --- a/partiql-plan/api/partiql-plan.api +++ b/partiql-plan/api/partiql-plan.api @@ -590,12 +590,12 @@ public abstract class org/partiql/plan/rel/RelSort : org/partiql/plan/rel/RelBas public final class org/partiql/plan/rel/RelType { public static final field ORDERED I public fun getDegree ()I - public fun getField (I)Lorg/partiql/spi/types/Field; - public fun getField (Ljava/lang/String;)Lorg/partiql/spi/types/Field; - public fun getFields ()[Lorg/partiql/spi/types/Field; + public fun getField (I)Lorg/partiql/spi/types/PTypeField; + public fun getField (Ljava/lang/String;)Lorg/partiql/spi/types/PTypeField; + public fun getFields ()[Lorg/partiql/spi/types/PTypeField; public fun isOrdered ()Z - public static fun of ([Lorg/partiql/spi/types/Field;)Lorg/partiql/plan/rel/RelType; - public static fun of ([Lorg/partiql/spi/types/Field;I)Lorg/partiql/plan/rel/RelType; + public static fun of ([Lorg/partiql/spi/types/PTypeField;)Lorg/partiql/plan/rel/RelType; + public static fun of ([Lorg/partiql/spi/types/PTypeField;I)Lorg/partiql/plan/rel/RelType; } public abstract class org/partiql/plan/rel/RelUnion : org/partiql/plan/rel/RelBase { diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelType.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelType.java index 0e3841b8f..8dc0ae6c0 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelType.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelType.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.spi.types.Field; +import org.partiql.spi.types.PTypeField; /** * Analogous to a ROW type, consider cardinality estimates or other hint mechanisms. @@ -10,21 +10,21 @@ public final class RelType { public static final int ORDERED = 0x01; - private final Field[] fields; + private final PTypeField[] fields; private final boolean ordered; - private RelType(Field[] fields, boolean ordered) { + private RelType(PTypeField[] fields, boolean ordered) { this.fields = fields; this.ordered = ordered; } @NotNull - public static RelType of(Field... fields) { + public static RelType of(PTypeField... fields) { return of(fields, 0); } @NotNull - public static RelType of(Field[] fields, int properties) { + public static RelType of(PTypeField[] fields, int properties) { boolean ordered = (properties & ORDERED) != 0; return new RelType(fields, ordered); } @@ -38,12 +38,12 @@ public int getDegree() { } @NotNull - public Field[] getFields() { + public PTypeField[] getFields() { return fields; } @NotNull - public Field getField(int index) { + public PTypeField getField(int index) { if (index < 0 || index >= fields.length) { throw new IllegalArgumentException("field index out of bounds: " + index); } @@ -51,8 +51,8 @@ public Field getField(int index) { } @NotNull - public Field getField(String name) { - for (Field field : fields) { + public PTypeField getField(String name) { + for (PTypeField field : fields) { if (field.getName().equals(name)) { return field; } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt index 6c2a3d322..fe966f84a 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt @@ -18,8 +18,8 @@ import org.partiql.planner.internal.ir.Rel import org.partiql.planner.internal.ir.SetQuantifier import org.partiql.planner.internal.ir.visitor.PlanBaseVisitor import org.partiql.spi.errors.PErrorListener -import org.partiql.spi.types.Field import org.partiql.spi.types.PType +import org.partiql.spi.types.PTypeField import org.partiql.planner.internal.ir.PartiQLPlan as IPlan import org.partiql.planner.internal.ir.PlanNode as INode import org.partiql.planner.internal.ir.Rel as IRel @@ -226,7 +226,7 @@ internal class PlanTransform(private val flags: Set) { override fun visitRel(node: IRel, ctx: PType): org.partiql.plan.rel.Rel { val o = visitRelOp(node.op, ctx) - val fields = node.type.schema.map { Field.of(it.name, it.type) }.toTypedArray() + val fields = node.type.schema.map { PTypeField.of(it.name, it.type) }.toTypedArray() val properties = if (node.type.props.contains(Rel.Prop.ORDERED)) RelType.ORDERED else 0 o.type = RelType.of(fields, properties) return o diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/CompilerType.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/CompilerType.kt index e50abd800..dbb413d30 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/CompilerType.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/CompilerType.kt @@ -19,11 +19,11 @@ internal class CompilerType( internal val isMissingValue: Boolean = false ) : PType(_delegate.code()) { fun getDelegate(): PType = _delegate - override fun getFields(): MutableCollection { + override fun getFields(): MutableCollection { return _delegate.fields.map { field -> when (field) { - is Field -> field - else -> Field(field.name, CompilerType(field.type)) + is PTypeField -> field + else -> PTypeField(field.name, CompilerType(field.type)) } }.toMutableList() } @@ -53,16 +53,16 @@ internal class CompilerType( return _delegate.toString() } - internal class Field( + internal class PTypeField( private val _name: String, private val _type: CompilerType - ) : org.partiql.spi.types.Field { + ) : org.partiql.spi.types.PTypeField { override fun getName(): String = _name override fun getType(): CompilerType = _type override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is org.partiql.spi.types.Field) return false + if (other !is org.partiql.spi.types.PTypeField) return false val nameMatches = _name == other.name val typeMatches = _type == other.type return nameMatches && typeMatches diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/PlanTyper.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/PlanTyper.kt index 8253f1984..828a5c744 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/PlanTyper.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/PlanTyper.kt @@ -57,8 +57,8 @@ import org.partiql.spi.Context import org.partiql.spi.catalog.Identifier import org.partiql.spi.errors.PError import org.partiql.spi.errors.PErrorListener -import org.partiql.spi.types.Field import org.partiql.spi.types.PType +import org.partiql.spi.types.PTypeField import org.partiql.spi.value.Datum import kotlin.math.max @@ -149,7 +149,7 @@ internal class PlanTyper(private val env: Env, config: Context) { } fields.forEachIndexed { index, field -> fieldTypes[index].add(field.type.toCType()) } } - val newFields = fieldTypes.mapIndexed { i, types -> Field.of(fieldNames[i], anyOfLiterals(types)!!) } + val newFields = fieldTypes.mapIndexed { i, types -> PTypeField.of(fieldNames[i], anyOfLiterals(types)!!) } return PType.row(newFields) } @@ -986,7 +986,7 @@ internal class PlanTyper(private val env: Env, config: Context) { rexOpStructField(k, v) } var structIsClosed = true - val structTypeFields = mutableListOf() + val structTypeFields = mutableListOf() for (field in fields) { val keyOp = field.k.op // TODO: Check key type @@ -994,10 +994,10 @@ internal class PlanTyper(private val env: Env, config: Context) { structIsClosed = false continue } - structTypeFields.add(CompilerType.Field(keyOp.value.string, field.v.type)) + structTypeFields.add(CompilerType.PTypeField(keyOp.value.string, field.v.type)) } val type = when (structIsClosed) { - true -> CompilerType(PType.row(structTypeFields as Collection)) + true -> CompilerType(PType.row(structTypeFields as Collection)) false -> CompilerType(PType.struct()) } return rex(type, rexOpStruct(fields)) @@ -1185,7 +1185,7 @@ internal class PlanTyper(private val env: Env, config: Context) { * unique attributes. */ private fun calculateTupleUnionOutputType(args: List): CompilerType? { - val fields = mutableListOf() + val fields = mutableListOf() var structIsOpen = false var containsDynamic = false var containsNonStruct = false @@ -1205,7 +1205,7 @@ internal class PlanTyper(private val env: Env, config: Context) { containsNonStruct -> null containsDynamic -> CompilerType(PType.dynamic()) structIsOpen -> CompilerType(PType.struct()) - else -> CompilerType(PType.row(fields as Collection)) + else -> CompilerType(PType.row(fields as Collection)) } } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/util/TypeUtils.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/util/TypeUtils.kt index 5869abbaa..85a7ad33d 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/util/TypeUtils.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/util/TypeUtils.kt @@ -44,14 +44,14 @@ internal object TypeUtils { val output = fields.mapNotNull { field -> val newField = if (substeps.isEmpty()) { if (lastStepOptional) { - CompilerType.Field(field.name, field.type) + CompilerType.PTypeField(field.name, field.type) } else { null } } else { val k = field.name val v = field.type.exclude(substeps, lastStepOptional) - CompilerType.Field(k, v) + CompilerType.PTypeField(k, v) } when (type) { is Rel.Op.Exclude.Type.StructSymbol -> { diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerPErrorReportingTests.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerPErrorReportingTests.kt index 2c96815cd..0d5b3fcf1 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerPErrorReportingTests.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerPErrorReportingTests.kt @@ -14,8 +14,8 @@ import org.partiql.spi.Context import org.partiql.spi.catalog.Catalog import org.partiql.spi.catalog.Session import org.partiql.spi.catalog.Table -import org.partiql.spi.types.Field import org.partiql.spi.types.PType +import org.partiql.spi.types.PTypeField import org.partiql.types.BagType import org.partiql.types.StaticType import org.partiql.types.StructType @@ -34,8 +34,8 @@ internal class PlannerPErrorReportingTests { .define(Table.empty("atomic", PType.smallint())) .define(Table.empty("collection_no_missing_atomic", PType.bag(PType.smallint()))) .define(Table.empty("collection_contain_missing_atomic", PType.bag(PType.smallint()))) - .define(Table.empty("struct_no_missing", PType.row(listOf(Field.of("f1", PType.smallint()))))) - .define(Table.empty("struct_with_missing", PType.row(listOf(Field.of("f1", PType.smallint()))))) + .define(Table.empty("struct_no_missing", PType.row(listOf(PTypeField.of("f1", PType.smallint()))))) + .define(Table.empty("struct_with_missing", PType.row(listOf(PTypeField.of("f1", PType.smallint()))))) .build() private val session = Session.builder() diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTest.kt index e61f2c407..6e2bf7087 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTest.kt @@ -62,13 +62,13 @@ class PlanTyperTest { ) private val LITERAL_STRUCT_1_FIRST_KEY_TYPE = PType.row( - listOf(CompilerType.Field("sEcoNd_KEY", INT4)), + listOf(CompilerType.PTypeField("sEcoNd_KEY", INT4)), ).toCType() private val LITERAL_STRUCT_1_TYPED: Rex get() { val topLevelStruct = PType.row( - listOf(CompilerType.Field("FiRsT_KeY", LITERAL_STRUCT_1_FIRST_KEY_TYPE)), + listOf(CompilerType.PTypeField("FiRsT_KeY", LITERAL_STRUCT_1_FIRST_KEY_TYPE)), ).toCType() return rex( type = topLevelStruct, @@ -95,17 +95,17 @@ class PlanTyperTest { private val ORDERED_DUPLICATES_STRUCT = PType.row( listOf( - CompilerType.Field("definition", STRING), - CompilerType.Field("definition", DOUBLE_PRECISION), - CompilerType.Field("DEFINITION", DECIMAL), + CompilerType.PTypeField("definition", STRING), + CompilerType.PTypeField("definition", DOUBLE_PRECISION), + CompilerType.PTypeField("DEFINITION", DECIMAL), ), ).toCType() private val DUPLICATES_STRUCT = PType.row( listOf( - CompilerType.Field("definition", STRING), - CompilerType.Field("definition", DOUBLE_PRECISION), - CompilerType.Field("DEFINITION", DECIMAL), + CompilerType.PTypeField("definition", STRING), + CompilerType.PTypeField("definition", DOUBLE_PRECISION), + CompilerType.PTypeField("DEFINITION", DECIMAL), ), ).toCType() diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt index b90da78a4..ce2cb88a3 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt @@ -33,8 +33,8 @@ import org.partiql.spi.catalog.Name import org.partiql.spi.catalog.Session import org.partiql.spi.errors.PError import org.partiql.spi.errors.PErrorListener -import org.partiql.spi.types.Field import org.partiql.spi.types.PType +import org.partiql.spi.types.PTypeField import org.partiql.types.BagType import org.partiql.types.DecimalType import org.partiql.types.ListType @@ -964,8 +964,8 @@ internal class PlanTyperTestsPorted { query = "SELECT * FROM <<{ 'a': 1 }>> AS t1, <<{ 'b': 2.0 }>> AS t2", expected = PType.bag( PType.row( - Field.of("a", PType.integer()), - Field.of("b", PType.decimal(2, 1)), + PTypeField.of("a", PType.integer()), + PTypeField.of("b", PType.decimal(2, 1)), ) ), ), @@ -974,8 +974,8 @@ internal class PlanTyperTestsPorted { query = "SELECT * FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'b': 2.0 }>> AS t2 ON TRUE", expected = PType.bag( PType.row( - Field.of("a", PType.integer()), - Field.of("b", PType.decimal(2, 1)) + PTypeField.of("a", PType.integer()), + PTypeField.of("b", PType.decimal(2, 1)) ) ), ), @@ -984,8 +984,8 @@ internal class PlanTyperTestsPorted { query = "SELECT b, a FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'b': 2.0 }>> AS t2 ON TRUE", expected = PType.bag( PType.row( - Field.of("b", PType.decimal(2, 1)), - Field.of("a", PType.integer()), + PTypeField.of("b", PType.decimal(2, 1)), + PTypeField.of("a", PType.integer()), ) ), ), @@ -994,8 +994,8 @@ internal class PlanTyperTestsPorted { query = "SELECT t1.a, t2.a FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'a': 2.0 }>> AS t2 ON t1.a = t2.a", expected = PType.bag( PType.row( - Field.of("a", PType.integer()), - Field.of("a", PType.decimal(2, 1)), + PTypeField.of("a", PType.integer()), + PTypeField.of("a", PType.decimal(2, 1)), ) ), ), @@ -1004,8 +1004,8 @@ internal class PlanTyperTestsPorted { query = "SELECT * FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'a': 2.0 }>> AS t2 ON t1.a = t2.a", expected = PType.bag( PType.row( - Field.of("a", PType.integer()), - Field.of("a", PType.decimal(2, 1)), + PTypeField.of("a", PType.integer()), + PTypeField.of("a", PType.decimal(2, 1)), ) ), ), @@ -1024,9 +1024,9 @@ internal class PlanTyperTestsPorted { """, expected = PType.bag( PType.row( - Field.of("a", PType.integer()), - Field.of("a", PType.decimal(2, 1)), - Field.of("a", PType.string()), + PTypeField.of("a", PType.integer()), + PTypeField.of("a", PType.decimal(2, 1)), + PTypeField.of("a", PType.string()), ) ), ), @@ -1035,8 +1035,8 @@ internal class PlanTyperTestsPorted { query = "SELECT * FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'a': 2.0 }>> AS t2 ON a = 3", expected = PType.bag( PType.row( - Field.of("a", PType.integer()), - Field.of("a", PType.decimal(2, 1)), + PTypeField.of("a", PType.integer()), + PTypeField.of("a", PType.decimal(2, 1)), ) ), problemHandler = assertProblemExists( @@ -2133,11 +2133,11 @@ internal class PlanTyperTestsPorted { key = key("exclude-34"), expected = PType.bag( PType.row( - Field.of( + PTypeField.of( "a", PType.bag( PType.row( - Field.of("b", PType.integer()) + PTypeField.of("b", PType.integer()) ) ) ), @@ -2652,7 +2652,7 @@ internal class PlanTyperTestsPorted { catalogPath = listOf("main"), expected = PType.bag( PType.row( - Field.of("breed_descriptor", PType.dynamic()), + PTypeField.of("breed_descriptor", PType.dynamic()), ) ), ), @@ -3380,10 +3380,10 @@ internal class PlanTyperTestsPorted { query = "SELECT a, COUNT(*) AS c, SUM(a) AS s, MIN(b) AS m FROM << {'a': 1.0, 'b': 2.0}, {'a': 1.0, 'b': 2.0} >> GROUP BY a", expected = PType.bag( PType.row( - Field.of("a", PType.decimal(2, 1)), - Field.of("c", PType.bigint()), - Field.of("s", PType.decimal(38, 19)), // TODO: Check this - Field.of("m", PType.decimal(38, 19)), + PTypeField.of("a", PType.decimal(2, 1)), + PTypeField.of("c", PType.bigint()), + PTypeField.of("s", PType.decimal(38, 19)), // TODO: Check this + PTypeField.of("m", PType.decimal(38, 19)), ) ), ), @@ -3721,18 +3721,18 @@ internal class PlanTyperTestsPorted { """.trimIndent(), expected = PType.bag( PType.row( - Field.of("a", PType.decimal(38, 0)), - Field.of("count_star", PType.bigint()), - Field.of("count_a", PType.bigint()), - Field.of("count_b", PType.bigint()), - Field.of("sum_a", PType.decimal(38, 0)), - Field.of("sum_b", PType.decimal(38, 0)), - Field.of("min_a", PType.decimal(38, 0)), - Field.of("min_b", PType.decimal(38, 0)), - Field.of("max_a", PType.decimal(38, 0)), - Field.of("max_b", PType.decimal(38, 0)), - Field.of("avg_a", PType.decimal(38, 0)), - Field.of("avg_b", PType.decimal(38, 0)), + PTypeField.of("a", PType.decimal(38, 0)), + PTypeField.of("count_star", PType.bigint()), + PTypeField.of("count_a", PType.bigint()), + PTypeField.of("count_b", PType.bigint()), + PTypeField.of("sum_a", PType.decimal(38, 0)), + PTypeField.of("sum_b", PType.decimal(38, 0)), + PTypeField.of("min_a", PType.decimal(38, 0)), + PTypeField.of("min_b", PType.decimal(38, 0)), + PTypeField.of("max_a", PType.decimal(38, 0)), + PTypeField.of("max_b", PType.decimal(38, 0)), + PTypeField.of("avg_a", PType.decimal(38, 0)), + PTypeField.of("avg_b", PType.decimal(38, 0)), ) ), ) @@ -4432,7 +4432,7 @@ internal class PlanTyperTestsPorted { catalogPath = DB_SCHEMA_MARKETS, query = "SELECT unknown_col FROM orders WHERE customer_id = 1", expected = PType.bag( - PType.row(Field.of("unknown_col", PType.unknown())) + PType.row(PTypeField.of("unknown_col", PType.unknown())) ), problemHandler = assertProblemExists( PErrors.varRefNotFound(null, insensitive("unknown_col"), listOf("orders")) @@ -4511,7 +4511,7 @@ internal class PlanTyperTestsPorted { query = "SELECT a FROM << [ 1, 1.0 ] >> AS a", expected = PType.bag( PType.row( - Field.of("a", PType.array()), + PTypeField.of("a", PType.array()), ) ), ), diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/ScopeTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/ScopeTest.kt index a6be37c98..fc2cb353d 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/ScopeTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/ScopeTest.kt @@ -57,7 +57,7 @@ internal class ScopeTest { private fun struct(vararg fields: Pair, open: Boolean = false): CompilerType { return when (open) { true -> PType.struct().toCType() - false -> PType.row(fields.map { CompilerType.Field(it.first, it.second) }).toCType() + false -> PType.row(fields.map { CompilerType.PTypeField(it.first, it.second) }).toCType() } } diff --git a/partiql-spi/api/partiql-spi.api b/partiql-spi/api/partiql-spi.api index 3e8dffe85..88419760e 100644 --- a/partiql-spi/api/partiql-spi.api +++ b/partiql-spi/api/partiql-spi.api @@ -457,12 +457,6 @@ public final class org/partiql/spi/function/RoutineSignature { public fun isNullCall ()Z } -public abstract interface class org/partiql/spi/types/Field { - public abstract fun getName ()Ljava/lang/String; - public abstract fun getType ()Lorg/partiql/spi/types/PType; - public static fun of (Ljava/lang/String;Lorg/partiql/spi/types/PType;)Lorg/partiql/spi/types/Field; -} - public abstract class org/partiql/spi/types/PType : org/partiql/spi/Enum { public static final field ARRAY I public static final field BAG I @@ -521,7 +515,7 @@ public abstract class org/partiql/spi/types/PType : org/partiql/spi/Enum { public static fun of (I)Lorg/partiql/spi/types/PType; public static fun real ()Lorg/partiql/spi/types/PType; public static fun row (Ljava/util/Collection;)Lorg/partiql/spi/types/PType; - public static fun row ([Lorg/partiql/spi/types/Field;)Lorg/partiql/spi/types/PType; + public static fun row ([Lorg/partiql/spi/types/PTypeField;)Lorg/partiql/spi/types/PType; public static fun smallint ()Lorg/partiql/spi/types/PType; public static fun string ()Lorg/partiql/spi/types/PType; public static fun struct ()Lorg/partiql/spi/types/PType; @@ -540,6 +534,12 @@ public abstract class org/partiql/spi/types/PType : org/partiql/spi/Enum { public static fun variant (Ljava/lang/String;)Lorg/partiql/spi/types/PType; } +public abstract interface class org/partiql/spi/types/PTypeField { + public abstract fun getName ()Ljava/lang/String; + public abstract fun getType ()Lorg/partiql/spi/types/PType; + public static fun of (Ljava/lang/String;Lorg/partiql/spi/types/PType;)Lorg/partiql/spi/types/PTypeField; +} + public abstract interface class org/partiql/spi/value/Datum : java/lang/Iterable { public static fun array (Ljava/lang/Iterable;)Lorg/partiql/spi/value/Datum; public static fun bag (Ljava/lang/Iterable;)Lorg/partiql/spi/value/Datum; diff --git a/partiql-spi/src/main/java/org/partiql/spi/types/PType.java b/partiql-spi/src/main/java/org/partiql/spi/types/PType.java index abdbc7486..48ca236de 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/types/PType.java +++ b/partiql-spi/src/main/java/org/partiql/spi/types/PType.java @@ -42,7 +42,7 @@ protected PType(int code) { * {@link PType#ROW} */ @NotNull - public Collection getFields() throws UnsupportedOperationException { + public Collection getFields() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } @@ -769,7 +769,7 @@ public static PType bag(@NotNull PType typeParam) { * @return a PartiQL row type */ @NotNull - public static PType row(@NotNull Collection fields) { + public static PType row(@NotNull Collection fields) { return new PTypeRow(fields); } @@ -778,7 +778,7 @@ public static PType row(@NotNull Collection fields) { */ @NotNull @SuppressWarnings("unused") - public static PType row(@NotNull Field... fields) { + public static PType row(@NotNull PTypeField... fields) { return new PTypeRow(Arrays.asList(fields)); } diff --git a/partiql-spi/src/main/java/org/partiql/spi/types/Field.java b/partiql-spi/src/main/java/org/partiql/spi/types/PTypeField.java similarity index 67% rename from partiql-spi/src/main/java/org/partiql/spi/types/Field.java rename to partiql-spi/src/main/java/org/partiql/spi/types/PTypeField.java index 8db6e8272..d94383313 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/types/Field.java +++ b/partiql-spi/src/main/java/org/partiql/spi/types/PTypeField.java @@ -5,7 +5,7 @@ /** * This represents a field of a structured type. */ -public interface Field { +public interface PTypeField { @NotNull public String getName(); @@ -14,13 +14,13 @@ public interface Field { /** - * Returns a simple implementation of {@link Field}. + * Returns a simple implementation of {@link PTypeField}. * @param name the key of the struct field * @param type the type of the struct field * @return a field containing the name and type */ - static Field of(@NotNull String name, @NotNull PType type) { - return new Field() { + static PTypeField of(@NotNull String name, @NotNull PType type) { + return new PTypeField() { @NotNull @Override public String getName() { @@ -36,8 +36,8 @@ public PType getType() { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof Field)) return false; - return name.equals(((Field) o).getName()) && type.equals(((Field) o).getType()); + if (!(o instanceof PTypeField)) return false; + return name.equals(((PTypeField) o).getName()) && type.equals(((PTypeField) o).getType()); } }; } diff --git a/partiql-spi/src/main/java/org/partiql/spi/types/PTypeRow.java b/partiql-spi/src/main/java/org/partiql/spi/types/PTypeRow.java index d0cbab282..1d5566445 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/types/PTypeRow.java +++ b/partiql-spi/src/main/java/org/partiql/spi/types/PTypeRow.java @@ -12,16 +12,16 @@ */ class PTypeRow extends PType { - final Collection _fields; + final Collection _fields; - PTypeRow(@NotNull Collection fields) { + PTypeRow(@NotNull Collection fields) { super(PType.ROW); _fields = fields; } @NotNull @Override - public Collection getFields() { + public Collection getFields() { return _fields; } @@ -32,16 +32,16 @@ public boolean equals(Object o) { if (PType.ROW != ((PType) o).code()) { return false; } - Collection otherFields = ((PType) o).getFields(); + Collection otherFields = ((PType) o).getFields(); int size = _fields.size(); if (size != otherFields.size()) { return false; } - Iterator thisIter = _fields.iterator(); - Iterator otherIter = otherFields.iterator(); + Iterator thisIter = _fields.iterator(); + Iterator otherIter = otherFields.iterator(); for (int i = 0; i < size; i++) { - Field thisField = thisIter.next(); - Field otherField = otherIter.next(); + PTypeField thisField = thisIter.next(); + PTypeField otherField = otherIter.next(); if (!thisField.equals(otherField)) { return false; } diff --git a/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java b/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java index 592efca0b..782615517 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java +++ b/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java @@ -8,6 +8,8 @@ import org.partiql.spi.errors.PRuntimeException; import org.partiql.spi.internal.value.ion.IonVariant; import org.partiql.spi.types.PType; +import org.partiql.spi.types.PTypeField; + import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; @@ -739,7 +741,7 @@ static Datum row(@NotNull Field... values) { * @return a value of type {@link PType#ROW} */ @NotNull - static Datum row(List typeFields, @NotNull Field... values) { + static Datum row(List typeFields, @NotNull Field... values) { return row(typeFields, Arrays.stream(values).collect(Collectors.toList())); } @@ -760,7 +762,7 @@ static Datum row(@NotNull List values) { * @return a value of type {@link PType#ROW} */ @NotNull - static Datum row(@NotNull List typeFields, @NotNull List values) { + static Datum row(@NotNull List typeFields, @NotNull List values) { PType type = PType.row(typeFields); return new DatumRow(values, type); } diff --git a/partiql-spi/src/main/java/org/partiql/spi/value/DatumRow.java b/partiql-spi/src/main/java/org/partiql/spi/value/DatumRow.java index a89376e30..e53af050f 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/value/DatumRow.java +++ b/partiql-spi/src/main/java/org/partiql/spi/value/DatumRow.java @@ -2,6 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.spi.types.PType; +import org.partiql.spi.types.PTypeField; import java.util.ArrayList; import java.util.HashMap; @@ -40,10 +41,10 @@ class DatumRow implements Datum { } private static PType getTypeFromFields(@NotNull Iterable fields) { - List fieldTypes = new ArrayList<>(); + List fieldTypes = new ArrayList<>(); fields.forEach((f) -> { PType fType = f.getValue().getType(); - org.partiql.spi.types.Field typeField = org.partiql.spi.types.Field.of(f.getName(), fType); + PTypeField typeField = PTypeField.of(f.getName(), fType); fieldTypes.add(typeField); }); return PType.row(fieldTypes); 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 2cbb5ee24..3b486f29b 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 @@ -1,7 +1,7 @@ package org.partiql.spi.internal -import org.partiql.spi.types.Field import org.partiql.spi.types.PType +import org.partiql.spi.types.PTypeField /** * Important SQL Definitions: @@ -73,7 +73,7 @@ internal object SqlTypes { } } - private fun fieldsAreAssignable(input: List, target: List): Boolean { + private fun fieldsAreAssignable(input: List, target: List): Boolean { if (input.size != target.size) { return false } val iIter = input.iterator() val tIter = target.iterator() @@ -91,7 +91,7 @@ internal object SqlTypes { * This is a PartiQL extension. We assume that structs/rows with the same field names may be assignable * if all names match AND types are assignable. */ - private fun namedFieldsAreAssignableUnordered(input: List, target: List): Boolean { + private fun namedFieldsAreAssignableUnordered(input: List, target: List): Boolean { if (input.size != target.size) { return false } val inputSorted = input.sortedBy { it.name } val targetSorted = target.sortedBy { it.name } diff --git a/partiql-spi/src/testFixtures/kotlin/org/partiql/types/FromStaticType.kt b/partiql-spi/src/testFixtures/kotlin/org/partiql/types/FromStaticType.kt index 7bf672418..b4ba5496f 100644 --- a/partiql-spi/src/testFixtures/kotlin/org/partiql/types/FromStaticType.kt +++ b/partiql-spi/src/testFixtures/kotlin/org/partiql/types/FromStaticType.kt @@ -1,7 +1,7 @@ package org.partiql.types -import org.partiql.spi.types.Field import org.partiql.spi.types.PType +import org.partiql.spi.types.PTypeField import java.util.stream.Collectors /** @@ -71,7 +71,7 @@ fun fromStaticType(type: StaticType): PType { val isOrdered = type.constraints.contains(TupleConstraint.Ordered) val isClosed = type.contentClosed val fields = type.fields.stream().map { field: StructType.Field -> - Field.of( + PTypeField.of( field.key, fromStaticType(field.value) )