Skip to content

Commit 0c4591e

Browse files
committed
Added a basic JsonRow
1 parent 741e85c commit 0c4591e

File tree

13 files changed

+303
-92
lines changed

13 files changed

+303
-92
lines changed

core/src/main/java/io/delta/core/data/Row.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,35 @@
88

99
public interface Row {
1010

11-
boolean isNullAt(int ordinal);
12-
13-
boolean getBoolean(int ordinal);
14-
15-
byte getByte(int ordinal);
16-
17-
short getShort(int ordinal);
18-
19-
int getInt(int ordinal);
11+
// boolean isNullAt(int ordinal);
12+
//
13+
// boolean getBoolean(int ordinal);
14+
//
15+
// byte getByte(int ordinal);
16+
//
17+
// short getShort(int ordinal);
18+
//
19+
// int getInt(int ordinal);
2020

2121
long getLong(int ordinal);
2222

23-
float getFloat(int ordinal);
24-
25-
double getDouble(int ordinal);
26-
27-
BigDecimal getDecimal(int ordinal, int precision, int scale);
28-
29-
String getString(int ordinal);
30-
31-
byte[] getBinary(int ordinal);
32-
33-
Timestamp getTimestamp(int ordinal);
34-
35-
Date getDate(int ordinal);
36-
37-
Row getRecord(int ordinal);
38-
39-
<T> List<T> getList(int ordinal);
40-
41-
<K, V> Map<K, V> getMap(int ordinal);
23+
// float getFloat(int ordinal);
24+
//
25+
// double getDouble(int ordinal);
26+
//
27+
// BigDecimal getDecimal(int ordinal, int precision, int scale);
28+
//
29+
// String getString(int ordinal);
30+
//
31+
// byte[] getBinary(int ordinal);
32+
//
33+
// Timestamp getTimestamp(int ordinal);
34+
//
35+
// Date getDate(int ordinal);
36+
//
37+
// Row getRecord(int ordinal);
38+
//
39+
// <T> List<T> getList(int ordinal);
40+
//
41+
// <K, V> Map<K, V> getMap(int ordinal);
4242
}

core/src/main/java/io/delta/core/helpers/TableHelper.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ public interface TableHelper {
1212

1313
CloseableIterator<FileStatus> listFiles(String path) throws FileNotFoundException;
1414

15-
CloseableIterator<FileStatus> listFiles(String path, String prefixToListFrom) throws FileNotFoundException;
16-
17-
// DECISION 1 OPTION 1
1815
CloseableIterator<Row> readJsonFile(String path, StructType readSchema);
19-
// each class needs a fromRow()
20-
21-
// DECISION 1 OPTION 2
22-
CloseableIterator<String> readJsonFile(String path);
23-
<T> T fromJson(String json, TypeReference<T> typeReference);
2416

2517
/** Uses the readSchema for partition pruning. */
2618
CloseableIterator<Row> readParquetFile(String path, StructType readSchema);

core/src/main/java/io/delta/core/helpers/TypeReference.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

core/src/main/java/io/delta/core/internal/checkpoint/CheckpointMetaData.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package io.delta.core.internal.checkpoint;
22

33
import io.delta.core.data.Row;
4-
import io.delta.core.helpers.TypeReference;
4+
import io.delta.core.types.LongType;
55
import io.delta.core.types.StructType;
66

77
public class CheckpointMetaData {
88

9-
// DECISION 1 OPTION 1
109
public static CheckpointMetaData fromRow(Row row) {
1110
return null;
1211
}
13-
// DECISION 1 OPTION 2
14-
public static TypeReference<CheckpointMetaData> TYPE_REFERENCE =
15-
new TypeReference<CheckpointMetaData>() { };
1612

17-
public static StructType READ_SCHEMA = null;
13+
public static StructType READ_SCHEMA = new StructType()
14+
.add("version", new LongType())
15+
.add("size", new LongType());
1816

1917
public final long version;
2018
public final long size;

core/src/main/java/io/delta/core/internal/checkpoint/Checkpointer.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,10 @@ public Optional<CheckpointMetaData> readLastCheckpointFile() {
7272

7373
/** Loads the checkpoint metadata from the _last_checkpoint file. */
7474
private Optional<CheckpointMetaData> loadMetadataFromFile(int tries) {
75-
// DECISION 1 OPTION 1
76-
final CloseableIterator<Row> data1 =
77-
tableImpl.tableHelper.readJsonFile(LAST_CHECKPOINT, CheckpointMetaData.READ_SCHEMA);
78-
final Optional<CheckpointMetaData> result1 = Optional.of(CheckpointMetaData.fromRow(data1.next()));
79-
80-
// DECISION 1 OPTION 2
81-
final CloseableIterator<String> data2 = tableImpl.tableHelper.readJsonFile(LAST_CHECKPOINT);
82-
final Optional<CheckpointMetaData> result2 = Optional.of(
83-
tableImpl.tableHelper.fromJson(data2.next(), CheckpointMetaData.TYPE_REFERENCE)
84-
);
85-
86-
return result1;
75+
final CloseableIterator<Row> data1 = tableImpl
76+
.tableHelper
77+
.readJsonFile(LAST_CHECKPOINT, CheckpointMetaData.READ_SCHEMA);
78+
79+
return Optional.of(CheckpointMetaData.fromRow(data1.next()));
8780
}
8881
}

core/src/main/java/io/delta/core/internal/snapshot/SnapshotManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ private Optional<CloseableIterator<FileStatus>> listFromOrNone(long startVersion
9696
// LIST the directory, starting from the provided lower bound (treat missing dir as empty).
9797
// NOTE: "empty/missing" is _NOT_ equivalent to "contains no useful commit files."
9898
try {
99-
// TODO: would be great to build our own better Optional class, e.g. Option.filterNot
10099
CloseableIterator<FileStatus> results = listFrom(startVersion);
101100
if (results.hasNext()) {
102101
return Optional.of(results);
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
package io.delta.core.types;
22

3-
public abstract class DataType { }
3+
import java.util.Locale;
4+
5+
public abstract class DataType {
6+
public String typeName() {
7+
String name = this.getClass().getSimpleName();
8+
if (name.endsWith("Type")) {
9+
name = name.substring(0, name.length() - 4);
10+
}
11+
return name.toLowerCase(Locale.ROOT);
12+
}
13+
}
414

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package io.delta.core.types;
2+
3+
public class LongType extends DataType {
4+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.delta.core.types;
2+
3+
public class StructField {
4+
public final String name;
5+
public final DataType dataType;
6+
public final boolean nullable;
7+
// private final FieldMetadata metadata;
8+
9+
public StructField(String name, DataType dataType, boolean nullable) {
10+
this.name = name;
11+
this.dataType = dataType;
12+
this.nullable = nullable;
13+
}
14+
}
Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
11
package io.delta.core.types;
22

3-
public final class StructType extends DataType { }
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.stream.Collectors;
6+
7+
public final class StructType extends DataType {
8+
private final List<StructField> fields;
9+
10+
public StructType() {
11+
this(new ArrayList<>());
12+
}
13+
14+
public StructType(List<StructField> fields) {
15+
this.fields = fields;
16+
}
17+
18+
public StructType add(StructField field) {
19+
final List<StructField> fieldsCopy = new ArrayList<>(fields);
20+
fieldsCopy.add(field);
21+
22+
return new StructType(fieldsCopy);
23+
}
24+
25+
public StructType add(String name, DataType dataType) {
26+
return add(new StructField(name, dataType, true /* nullable */));
27+
}
28+
29+
public List<String> fieldNames() {
30+
return fields.stream().map(f -> f.name).collect(Collectors.toList());
31+
}
32+
33+
public int length() {
34+
return fields.size();
35+
}
36+
37+
public StructField at(int index) {
38+
return fields.get(index);
39+
}
40+
41+
public String treeString() {
42+
return "TODO";
43+
}
44+
}

0 commit comments

Comments
 (0)