timothyw553 commented on code in PR #18859:
URL: https://github.com/apache/iceberg/pull/18859#discussion_r4723015814
##########
core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java:
##########
@@ -82,11 +82,36 @@ public static Schema convert(
}
public static Type convert(Schema schema) {
- return AvroSchemaVisitor.visit(schema, new SchemaToType(schema));
+ return convert(schema, false);
+ }
+
+ /**
+ * Converts an Avro schema to an Iceberg type.
+ *
+ * @param schema an Avro schema
+ * @param timeAsNumber if true, {@code time-millis} is converted to an int
and {@code time-micros}
+ * to a long, which is how Avro stores them, instead of to an Iceberg
time
+ * @return the Iceberg type
+ */
+ public static Type convert(Schema schema, boolean timeAsNumber) {
Review Comment:
does `convert(Schema, boolean)` need to be `public`? no caller outside this
class uses it since Flink calls `toIceberg`, so making it package-private
avoids adding to the public API.
```diff
- public static Type convert(Schema schema, boolean timeAsNumber) {
+ static Type convert(Schema schema, boolean timeAsNumber) {
```
##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/FlinkDynamicSinkOptions.java:
##########
@@ -69,6 +69,16 @@ private FlinkDynamicSinkOptions() {}
.withDescription(
"Controls whether schema field name matching should be
case-sensitive in Dynamic Sink.");
+ public static final ConfigOption<Boolean> AVRO_TIME_AS_NUMBER =
+ ConfigOptions.key("dynamic-sink.avro-time-as-number")
+ .booleanType()
+ .defaultValue(false)
+ .withDescription(
+ "Converts the Avro logical types time-millis and time-micros to
Iceberg int and long "
Review Comment:
to my understanding the default path doesn't silently drop microseconds, it
actually fails to read `BIGINT` `time-micros` as `int` (`Failed to read Variant
... of type BIGINT as int`), and only `VariantAvroDynamicTableRecordGenerator`
uses this option. could we also mention that changing it on an existing `time`
column won't work?
```diff
- "Converts the Avro logical types time-millis and time-micros
to Iceberg int and long "
- + "instead of time, for generators that derive the table
schema from an Avro schema. "
- + "A Flink time holds milliseconds only, so the
microseconds of a time-micros are lost "
- + "as a time and kept as a long.");
+ "Whether VariantAvroDynamicTableRecordGenerator maps Avro
time-millis to Iceberg int "
+ + "and time-micros to long instead of time. Numeric
values retain milliseconds "
+ + "and microseconds since midnight, respectively. The
default mapping cannot read "
+ + "BIGINT time-micros values as Flink time. Changing this
option for existing time "
+ + "columns fails because time and int/long cannot be
promoted to each other.");
```
##########
core/src/main/java/org/apache/iceberg/avro/SchemaToType.java:
##########
@@ -30,9 +30,15 @@
class SchemaToType extends AvroSchemaVisitor<Type> {
private final Schema root;
+ private final boolean timeAsNumber;
SchemaToType(Schema root) {
+ this(root, false);
Review Comment:
nit: the one-arg `SchemaToType(Schema)` constructor looks unused now, should
we remove it?
```diff
- SchemaToType(Schema root) {
- this(root, false);
- }
-
SchemaToType(Schema root, boolean timeAsNumber) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]