-
Notifications
You must be signed in to change notification settings - Fork 3k
API: Add default value core api and schema serialization #4525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0ebebaf
1b418f9
c6459c1
fab4dee
8c4c10b
b575ece
2430dae
4b0baad
43b7f7d
a134f2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,7 +149,6 @@ public boolean equals(Object other) { | |
| public int hashCode() { | ||
| return Objects.hashCode(value); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private abstract static class ComparableLiteral<C extends Comparable<C>> extends BaseLiteral<C> { | ||
|
|
@@ -399,6 +398,8 @@ static class DateLiteral extends ComparableLiteral<Integer> { | |
| public <T> Literal<T> to(Type type) { | ||
| if (type.typeId() == Type.TypeID.DATE) { | ||
| return (Literal<T>) this; | ||
| } else if (type.typeId() == Type.TypeID.STRING) { | ||
| return (Literal<T>) new StringLiteral(LocalDate.ofEpochDay(value()).format(DateTimeFormatter.ISO_LOCAL_DATE)); | ||
| } | ||
| return null; | ||
| } | ||
|
|
@@ -419,6 +420,9 @@ static class TimeLiteral extends ComparableLiteral<Long> { | |
| public <T> Literal<T> to(Type type) { | ||
| if (type.typeId() == Type.TypeID.TIME) { | ||
| return (Literal<T>) this; | ||
| } else if (type.typeId() == Type.TypeID.STRING) { | ||
| return (Literal<T>) new StringLiteral(LocalTime.ofNanoOfDay(value() * 1000) | ||
| .format(DateTimeFormatter.ISO_LOCAL_TIME)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this conversion should be done using literals. Instead, use the methods in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah since previously I remember you pointed me to the WDYT?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this conversion should be done using literals. You can see how we're doing it here, but there is no need to change the |
||
| } | ||
| return null; | ||
| } | ||
|
|
@@ -443,6 +447,10 @@ public <T> Literal<T> to(Type type) { | |
| case DATE: | ||
| return (Literal<T>) new DateLiteral((int) ChronoUnit.DAYS.between( | ||
| EPOCH_DAY, EPOCH.plus(value(), ChronoUnit.MICROS).toLocalDate())); | ||
| case STRING: | ||
| // Always return the literal without timezone. | ||
| return (Literal<T>) new StringLiteral(LocalDateTime.ofEpochSecond(value() / 1000000, | ||
| (int) (value() % 1000000) * 1000, ZoneOffset.UTC).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); | ||
| default: | ||
| } | ||
| return null; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -415,43 +415,64 @@ public int hashCode() { | |
|
|
||
| public static class NestedField implements Serializable { | ||
| public static NestedField optional(int id, String name, Type type) { | ||
| return new NestedField(true, id, name, type, null); | ||
| return new NestedField(true, id, name, type, null, null, null); | ||
| } | ||
|
|
||
| public static NestedField optional(int id, String name, Type type, String doc) { | ||
| return new NestedField(true, id, name, type, doc); | ||
| return new NestedField(true, id, name, type, doc, null, null); | ||
| } | ||
|
|
||
| public static NestedField optional(int id, String name, Type type, String doc, | ||
| Object initialDefault, Object writeDefault) { | ||
| return new NestedField(true, id, name, type, doc, initialDefault, writeDefault); | ||
| } | ||
|
|
||
| public static NestedField required(int id, String name, Type type) { | ||
| return new NestedField(false, id, name, type, null); | ||
| return new NestedField(false, id, name, type, null, null, null); | ||
| } | ||
|
|
||
| public static NestedField required(int id, String name, Type type, String doc) { | ||
| return new NestedField(false, id, name, type, doc); | ||
| return new NestedField(false, id, name, type, doc, null, null); | ||
| } | ||
|
|
||
| public static NestedField required(int id, String name, Type type, String doc, | ||
| Object initialDefault, Object writeDefault) { | ||
| return new NestedField(false, id, name, type, doc, initialDefault, writeDefault); | ||
| } | ||
|
|
||
| public static NestedField of(int id, boolean isOptional, String name, Type type) { | ||
| return new NestedField(isOptional, id, name, type, null); | ||
| return new NestedField(isOptional, id, name, type, null, null, null); | ||
| } | ||
|
|
||
| public static NestedField of(int id, boolean isOptional, String name, Type type, String doc) { | ||
| return new NestedField(isOptional, id, name, type, doc); | ||
| return new NestedField(isOptional, id, name, type, doc, null, null); | ||
| } | ||
|
|
||
| public static NestedField of(int id, boolean isOptional, String name, Type type, String doc, | ||
| Object initialDefault, Object writeDefault) { | ||
| return new NestedField(isOptional, id, name, type, doc, initialDefault, writeDefault); | ||
| } | ||
|
|
||
| private final boolean isOptional; | ||
| private final int id; | ||
| private final String name; | ||
| private final Type type; | ||
| private final String doc; | ||
| private final Object initialDefault; | ||
| private final Object writeDefault; | ||
|
|
||
rzhang10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private NestedField(boolean isOptional, int id, String name, Type type, String doc) { | ||
| private NestedField(boolean isOptional, int id, String name, Type type, String doc, | ||
| Object initialDefault, Object writeDefault) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: In Iceberg always start all argument lines at the same point, either all indented after the method declaration (aligned with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rzhang10, please don't resolve threads that are not updated yet. |
||
| Preconditions.checkNotNull(name, "Name cannot be null"); | ||
| Preconditions.checkNotNull(type, "Type cannot be null"); | ||
| this.isOptional = isOptional; | ||
| this.id = id; | ||
| this.name = name; | ||
| this.type = type; | ||
| this.doc = doc; | ||
| this.initialDefault = initialDefault; | ||
| this.writeDefault = writeDefault; | ||
| } | ||
|
|
||
| public boolean isOptional() { | ||
|
|
@@ -462,7 +483,7 @@ public NestedField asOptional() { | |
| if (isOptional) { | ||
| return this; | ||
| } | ||
| return new NestedField(true, id, name, type, doc); | ||
| return new NestedField(true, id, name, type, doc, initialDefault, writeDefault); | ||
| } | ||
|
|
||
| public boolean isRequired() { | ||
|
|
@@ -473,7 +494,11 @@ public NestedField asRequired() { | |
| if (!isOptional) { | ||
| return this; | ||
| } | ||
| return new NestedField(false, id, name, type, doc); | ||
| return new NestedField(false, id, name, type, doc, initialDefault, writeDefault); | ||
| } | ||
|
|
||
| public NestedField updateWriteDefault(Object newWriteDefault) { | ||
rzhang10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return new NestedField(isOptional, id, name, type, doc, initialDefault, newWriteDefault); | ||
| } | ||
|
|
||
| public int fieldId() { | ||
|
|
@@ -492,6 +517,14 @@ public String doc() { | |
| return doc; | ||
| } | ||
|
|
||
| public Object initialDefaultValue() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need |
||
| return initialDefault; | ||
| } | ||
|
|
||
| public Object writeDefaultValue() { | ||
| return writeDefault; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("%d: %s: %s %s", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you should need any new literal constructors. You can always convert using
toand the type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my below comment.