Skip to content

Commit

Permalink
Represent nested types (ARRAY, MAP, etc) by converting all elements t…
Browse files Browse the repository at this point in the history
…o VARIANT

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
  • Loading branch information
mihaibudiu committed Dec 7, 2024
1 parent 1875d46 commit 77a2ac6
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public GenericSqlTypeRtti(RuntimeSqlTypeName typeName, RuntimeTypeInformation...
}

public RuntimeTypeInformation getTypeArgument(int index) {
return this.typeArguments[index];
return typeArguments[index];
}

public int getArgumentCount() {
return typeArguments.length;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

/** Runtime type information for a ROW type. */
public class RowSqlTypeRtti extends RuntimeTypeInformation {
private final Map.Entry<String, RuntimeTypeInformation>[] fieldNames;
private final Map.Entry<String, RuntimeTypeInformation>[] fields;

@SafeVarargs
public RowSqlTypeRtti(Map.Entry<String, RuntimeTypeInformation>... fieldNames) {
public RowSqlTypeRtti(Map.Entry<String, RuntimeTypeInformation>... fields) {
super(RuntimeSqlTypeName.ROW);
this.fieldNames = fieldNames;
this.fields = fields;
}

@Override public String getTypeString() {
Expand All @@ -41,7 +41,7 @@ public RowSqlTypeRtti(Map.Entry<String, RuntimeTypeInformation>... fieldNames) {
StringBuilder builder = new StringBuilder();
builder.append("new RowSqlTypeRtti(");
boolean first = true;
for (Map.Entry<String, RuntimeTypeInformation> arg : this.fieldNames) {
for (Map.Entry<String, RuntimeTypeInformation> arg : this.fields) {
if (!first) {
builder.append(", ");
}
Expand All @@ -61,11 +61,20 @@ public RowSqlTypeRtti(Map.Entry<String, RuntimeTypeInformation>... fieldNames) {
}

RowSqlTypeRtti that = (RowSqlTypeRtti) o;
return Arrays.equals(fieldNames, that.fieldNames);
return Arrays.equals(fields, that.fields);
}

@Override public int hashCode() {
return Arrays.hashCode(fieldNames);
return Arrays.hashCode(fields);
}

/** Get the field with the specified index. */
public Map.Entry<String, RuntimeTypeInformation> getField(int index) {
return this.fields[index];
}

public int size() {
return this.fields.length;
}

/** Return the runtime type information of the associated field,
Expand All @@ -76,13 +85,13 @@ public RowSqlTypeRtti(Map.Entry<String, RuntimeTypeInformation>... fieldNames) {
public @Nullable RuntimeTypeInformation getFieldType(Object index) {
if (index instanceof Integer) {
int intIndex = (Integer) index;
if (intIndex < 0 || intIndex >= this.fieldNames.length) {
if (intIndex < 0 || intIndex >= this.fields.length) {
return null;
}
return this.fieldNames[intIndex].getValue();
return this.fields[intIndex].getValue();
} else if (index instanceof String) {
String stringIndex = (String) index;
for (Map.Entry<String, RuntimeTypeInformation> field : this.fieldNames) {
for (Map.Entry<String, RuntimeTypeInformation> field : this.fields) {
if (field.getKey().equalsIgnoreCase(stringIndex)) {
return field.getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public enum RuntimeSqlTypeName {
TIMESTAMP_TZ(false),
INTERVAL_LONG(false),
INTERVAL_SHORT(false),
// "Name" is used for structure field names
NAME(false),
// CHAR is represented as VARCHAR
VARCHAR(false),
// BINARY is represented as VARBINARY
Expand Down Expand Up @@ -118,6 +120,11 @@ public boolean isScalar() {
}
}

public GenericSqlTypeRtti asGeneric() {
assert this instanceof GenericSqlTypeRtti;
return (GenericSqlTypeRtti) this;
}

/**
* Creates and returns an expression that creates a runtime type that
* reflects the information in the statically-known type 'type'.
Expand Down
Loading

0 comments on commit 77a2ac6

Please sign in to comment.