Skip to content

Commit f6aeb6b

Browse files
committed
init no tests yet
1 parent d24a0b1 commit f6aeb6b

File tree

21 files changed

+358
-0
lines changed

21 files changed

+358
-0
lines changed

kernel/kernel-api/src/main/java/io/delta/kernel/data/ColumnVector.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ default ArrayValue getArray(int rowId) {
175175
throw new UnsupportedOperationException("Invalid value request for data type");
176176
}
177177

178+
/**
179+
* Return the variant value located at {@code rowId}. Returns null if the slot for {@code rowId}
180+
* is null
181+
*/
182+
default VariantValue getVariant(int rowId) {
183+
throw new UnsupportedOperationException("Invalid value request for data type");
184+
}
185+
178186
/**
179187
* Get the child vector associated with the given ordinal. This method is applicable only to the
180188
* {@code struct} type columns.

kernel/kernel-api/src/main/java/io/delta/kernel/data/Row.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,10 @@ public interface Row {
117117
* Throws error if the column at given ordinal is not of map type,
118118
*/
119119
MapValue getMap(int ordinal);
120+
121+
/**
122+
* Return variant value of the column located at the given ordinal.
123+
* Throws error if the column at given ordinal is not of variant type.
124+
*/
125+
VariantValue getVariant(int ordinal);
120126
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (2024) The Delta Lake Project Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.delta.kernel.data;
17+
18+
/**
19+
* Abstraction to represent a single Variant value in a {@link ColumnVector}.
20+
*/
21+
public interface VariantValue {
22+
byte[] getValue();
23+
24+
byte[] getMetadata();
25+
}

kernel/kernel-api/src/main/java/io/delta/kernel/internal/TableFeatures.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static void validateReadSupportedTable(Protocol protocol, Metadata metada
4646
break;
4747
case "deletionVectors": // fall through
4848
case "timestampNtz": // fall through
49+
case "variantType-dev":
4950
case "vacuumProtocolCheck":
5051
break;
5152
default:

kernel/kernel-api/src/main/java/io/delta/kernel/internal/data/ChildVectorBasedRow.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.delta.kernel.data.ColumnVector;
2222
import io.delta.kernel.data.MapValue;
2323
import io.delta.kernel.data.Row;
24+
import io.delta.kernel.data.VariantValue;
2425
import io.delta.kernel.types.StructType;
2526

2627
/**
@@ -111,5 +112,10 @@ public MapValue getMap(int ordinal) {
111112
return getChild(ordinal).getMap(rowId);
112113
}
113114

115+
@Override
116+
public VariantValue getVariant(int ordinal) {
117+
return getChild(ordinal).getVariant(rowId);
118+
}
119+
114120
protected abstract ColumnVector getChild(int ordinal);
115121
}

kernel/kernel-api/src/main/java/io/delta/kernel/internal/data/GenericRow.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.delta.kernel.data.ArrayValue;
2424
import io.delta.kernel.data.MapValue;
2525
import io.delta.kernel.data.Row;
26+
import io.delta.kernel.data.VariantValue;
2627
import io.delta.kernel.types.*;
2728

2829
/**
@@ -134,6 +135,13 @@ public MapValue getMap(int ordinal) {
134135
return (MapValue) getValue(ordinal);
135136
}
136137

138+
@Override
139+
public VariantValue getVariant(int ordinal) {
140+
// TODO(r.chen): test this path somehow?
141+
throwIfUnsafeAccess(ordinal, VariantType.class, "variant");
142+
return (VariantValue) getValue(ordinal);
143+
}
144+
137145
private Object getValue(int ordinal) {
138146
return ordinalToValue.get(ordinal);
139147
}

kernel/kernel-api/src/main/java/io/delta/kernel/internal/util/VectorUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ private static Object getValueAsObject(
110110
return toJavaList(columnVector.getArray(rowId));
111111
} else if (dataType instanceof MapType) {
112112
return toJavaMap(columnVector.getMap(rowId));
113+
} else if (dataType instanceof VariantType) {
114+
return columnVector.getVariant(rowId);
113115
} else {
114116
throw new UnsupportedOperationException("unsupported data type");
115117
}

kernel/kernel-api/src/main/java/io/delta/kernel/types/BasePrimitiveType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public static List<DataType> getAllPrimitiveTypes() {
6464
put("timestamp_ntz", TimestampNTZType.TIMESTAMP_NTZ);
6565
put("binary", BinaryType.BINARY);
6666
put("string", StringType.STRING);
67+
put("variant", VariantType.VARIANT);
6768
}
6869
});
6970

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (2024) The Delta Lake Project Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.delta.kernel.types;
17+
18+
import io.delta.kernel.annotation.Evolving;
19+
20+
/**
21+
* A variant type.
22+
* <p>
23+
* todo: more comments
24+
* @since 4.0.0
25+
*/
26+
@Evolving
27+
public class VariantType extends BasePrimitiveType {
28+
public static final VariantType VARIANT = new VariantType();
29+
30+
private VariantType() {
31+
super("variant");
32+
}
33+
}

kernel/kernel-defaults/src/main/java/io/delta/kernel/defaults/internal/data/DefaultJsonRow.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import io.delta.kernel.data.ColumnVector;
3434
import io.delta.kernel.data.MapValue;
3535
import io.delta.kernel.data.Row;
36+
import io.delta.kernel.data.VariantValue;
3637
import io.delta.kernel.types.*;
3738
import io.delta.kernel.internal.util.InternalUtils;
3839

@@ -128,6 +129,11 @@ public MapValue getMap(int ordinal) {
128129
return (MapValue) parsedValues[ordinal];
129130
}
130131

132+
@Override
133+
public VariantValue getVariant(int ordinal) {
134+
throw new UnsupportedOperationException("not yet implemented");
135+
}
136+
131137
private static void throwIfTypeMismatch(String expType, boolean hasExpType, JsonNode jsonNode) {
132138
if (!hasExpType) {
133139
throw new RuntimeException(

0 commit comments

Comments
 (0)