szehon-ho commented on code in PR #14984: URL: https://github.com/apache/iceberg/pull/14984#discussion_r3755684880
########## spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkViewQueryColumnNamesParser.java: ########## @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.spark.source; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.io.UncheckedIOException; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; + +/** Converts Spark view query column names to and from a property-safe JSON representation. */ +class SparkViewQueryColumnNamesParser { + private static final ObjectMapper MAPPER = new ObjectMapper(); + + private SparkViewQueryColumnNamesParser() {} + + static String toJson(String[] columnNames) { + try { + return MAPPER.writeValueAsString(columnNames); + } catch (IOException e) { + throw new UncheckedIOException("Failed to write Spark view query column names", e); + } + } + + static String[] fromProperty(String value) { + if (value.equals("[]") || value.startsWith("[\"")) { Review Comment: This still makes the legacy key ambiguous. Released Iceberg Spark 4.1 writes arbitrary query column names to `spark.query-column-names` by joining them with commas, so a valid existing alias whose literal name is `["id"]` is silently read here as `id`; a name beginning with `["` that is not complete JSON fails parsing instead. Now that JSON has its own `spark.query-column-names-json` key, could we select the decoder by key rather than sniffing the value? The new key can always use JSON, while the legacy key can always retain its released `.split(",")` semantics. The preview-format compatibility test at `TestViews.java:223` appears to be what requires this heuristic, but preserving unreleased preview metadata seems less important than avoiding a collision with released 4.1 metadata. -- 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]
