danielcweeks commented on code in PR #18250:
URL: https://github.com/apache/iceberg/pull/18250#discussion_r4136160742
##########
spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkTypeToType.java:
##########
@@ -201,4 +228,43 @@ private static EdgeAlgorithm
convertAlgorithm(EdgeInterpolationAlgorithm algorit
"Iceberg does not support Spark geography edge algorithm: " +
algorithm);
}
}
+
+ private void convertDefaultValue(Types.NestedField.Builder icebergField,
StructField sparkField) {
+ Column column = nameToColumnMap.get(sparkField.name());
+
+ if (column == null) {
+ return;
+ }
+
+ ColumnDefaultValue columnDefaultValue = column.defaultValue();
+
+ if (columnDefaultValue == null) {
+ return;
+ }
+
+ if (columnDefaultValue.getExpression() == null &&
columnDefaultValue.getSql() != null) {
+ throw new UnsupportedOperationException(
+ "Unsupported default value expression: " +
columnDefaultValue.getSql());
+ }
+
+ if (columnDefaultValue.getExpression() != null
+ && !SparkV2Filters.isLiteral(columnDefaultValue.getExpression())) {
+ throw new UnsupportedOperationException(
+ "Default value expressions are not supported in Iceberg");
+ }
+
+ // the value is equivalent to the initial value in Iceberg
+ Literal<?> initialValue = columnDefaultValue.getValue();
+ if (initialValue != null && initialValue.value() != null) {
+ icebergField.withInitialDefault(
+
Expressions.lit(SparkV2Filters.convertLiteral(columnDefaultValue.getValue())));
+ }
+
+ // the expression is evaluated for future writes
+ LiteralValue<?> writeDefault = (LiteralValue<?>)
columnDefaultValue.getExpression();
Review Comment:
Done
##########
spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkTypeToType.java:
##########
@@ -201,4 +228,43 @@ private static EdgeAlgorithm
convertAlgorithm(EdgeInterpolationAlgorithm algorit
"Iceberg does not support Spark geography edge algorithm: " +
algorithm);
}
}
+
+ private void convertDefaultValue(Types.NestedField.Builder icebergField,
StructField sparkField) {
+ Column column = nameToColumnMap.get(sparkField.name());
+
+ if (column == null) {
+ return;
+ }
+
+ ColumnDefaultValue columnDefaultValue = column.defaultValue();
+
+ if (columnDefaultValue == null) {
+ return;
+ }
+
+ if (columnDefaultValue.getExpression() == null &&
columnDefaultValue.getSql() != null) {
+ throw new UnsupportedOperationException(
+ "Unsupported default value expression: " +
columnDefaultValue.getSql());
+ }
+
+ if (columnDefaultValue.getExpression() != null
+ && !SparkV2Filters.isLiteral(columnDefaultValue.getExpression())) {
+ throw new UnsupportedOperationException(
+ "Default value expressions are not supported in Iceberg");
+ }
+
+ // the value is equivalent to the initial value in Iceberg
+ Literal<?> initialValue = columnDefaultValue.getValue();
+ if (initialValue != null && initialValue.value() != null) {
+ icebergField.withInitialDefault(
+
Expressions.lit(SparkV2Filters.convertLiteral(columnDefaultValue.getValue())));
Review Comment:
Done
--
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]