dtenedor commented on code in PR #46977: URL: https://github.com/apache/spark/pull/46977#discussion_r1640550210
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/toFromAvroSqlFunctions.scala: ########## @@ -0,0 +1,169 @@ +/* + * 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.spark.sql.catalyst.expressions + +import org.apache.spark.sql.catalyst.analysis.TypeCheckResult +import org.apache.spark.sql.catalyst.util.ArrayBasedMapData +import org.apache.spark.sql.types.{MapType, NullType, StringType} +import org.apache.spark.unsafe.types.UTF8String +import org.apache.spark.util.Utils + +/** + * Converts a binary column of Avro format into its corresponding Catalyst value. + * This is a thin wrapper over the [[AvroDataToCatalyst]] class to create a SQL function. + * + * @param child the Catalyst binary input column. + * @param jsonFormatSchema the Avro schema in JSON string format. + * @param options the options to use when performing the conversion. + * + * @since 4.0.0 + */ +@ExpressionDescription( + usage = """ + _FUNC_(child, jsonFormatSchema, options) - Converts a binary Avro value into a Catalyst value. + """, + examples = """ + > SELECT IS_NULL(_FUNC_(result, '{"type": "record", "name": "struct", "fields": [{ "name": "u", "type": ["int","string"] }]}')) AS result FROM (SELECT NAMED_STRUCT('u', NAMED_STRUCT('member0', member0, 'member1', member1)) AS s FROM VALUES (1, NULL), (NULL, 'a') tab(member0, member1)); + [false] + """, + note = """ + The specified schema must match actual schema of the read data, otherwise the behavior + is undefined: it may fail or return arbitrary result. + To deserialize the data with a compatible and evolved schema, the expected Avro schema can be + set via the corresponding option. + """, + group = "misc_funcs", Review Comment: Sounds good, done. ########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/toFromAvroSqlFunctions.scala: ########## @@ -0,0 +1,169 @@ +/* + * 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.spark.sql.catalyst.expressions + +import org.apache.spark.sql.catalyst.analysis.TypeCheckResult +import org.apache.spark.sql.catalyst.util.ArrayBasedMapData +import org.apache.spark.sql.types.{MapType, NullType, StringType} +import org.apache.spark.unsafe.types.UTF8String +import org.apache.spark.util.Utils + +/** + * Converts a binary column of Avro format into its corresponding Catalyst value. + * This is a thin wrapper over the [[AvroDataToCatalyst]] class to create a SQL function. + * + * @param child the Catalyst binary input column. + * @param jsonFormatSchema the Avro schema in JSON string format. + * @param options the options to use when performing the conversion. + * + * @since 4.0.0 + */ +@ExpressionDescription( + usage = """ + _FUNC_(child, jsonFormatSchema, options) - Converts a binary Avro value into a Catalyst value. + """, + examples = """ + > SELECT IS_NULL(_FUNC_(result, '{"type": "record", "name": "struct", "fields": [{ "name": "u", "type": ["int","string"] }]}')) AS result FROM (SELECT NAMED_STRUCT('u', NAMED_STRUCT('member0', member0, 'member1', member1)) AS s FROM VALUES (1, NULL), (NULL, 'a') tab(member0, member1)); + [false] + """, + note = """ + The specified schema must match actual schema of the read data, otherwise the behavior + is undefined: it may fail or return arbitrary result. + To deserialize the data with a compatible and evolved schema, the expected Avro schema can be + set via the corresponding option. + """, + group = "misc_funcs", + since = "4.0.0" +) +case class FromAvroSqlFunction(child: Expression, jsonFormatSchema: Expression, options: Expression) Review Comment: Sounds good, 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]
