Skip to content

Commit 62f310c

Browse files
committed
init no tests yet
1 parent c06e4b4 commit 62f310c

File tree

24 files changed

+370
-10
lines changed

24 files changed

+370
-10
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/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/replay/LogReplay.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ private void validateSupportedTable(Protocol protocol, Metadata metadata) {
313313
case "columnMapping":
314314
ColumnMapping.throwOnUnsupportedColumnMappingMode(metadata);
315315
break;
316+
case "variantType-dev":
317+
break;
316318
default:
317319
throw new UnsupportedOperationException(
318320
"Unsupported table feature: " + readerFeature);

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
@@ -63,6 +63,7 @@ public static List<DataType> getAllPrimitiveTypes() {
6363
put("timestamp", TimestampType.TIMESTAMP);
6464
put("binary", BinaryType.BINARY);
6565
put("string", StringType.STRING);
66+
put("variant", VariantType.VARIANT);
6667
}
6768
});
6869

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-api/src/test/scala/io/delta/kernel/internal/SnapshotManagerSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ class SnapshotManagerSuite extends AnyFunSuite with MockFileSystemClientUtils {
618618
// corrupt incomplete multi-part checkpoint
619619
val corruptedCheckpointStatuses = FileNames.checkpointFileWithParts(logPath, 10, 5).asScala
620620
.map(p => FileStatus.of(p.toString, 10, 10))
621-
.take(4)
621+
.take(4).toSeq
622622
val deltas = deltaFileStatuses(10L to 13L)
623623
testExpectedError[RuntimeException](
624624
corruptedCheckpointStatuses ++ deltas,
@@ -667,7 +667,7 @@ class SnapshotManagerSuite extends AnyFunSuite with MockFileSystemClientUtils {
667667
// _last_checkpoint refers to incomplete multi-part checkpoint
668668
val corruptedCheckpointStatuses = FileNames.checkpointFileWithParts(logPath, 20, 5).asScala
669669
.map(p => FileStatus.of(p.toString, 10, 10))
670-
.take(4)
670+
.take(4).toSeq
671671
testExpectedError[RuntimeException](
672672
files = corruptedCheckpointStatuses ++ deltaFileStatuses(10L to 20L) ++
673673
singularCheckpointFileStatuses(Seq(10L)),

0 commit comments

Comments
 (0)