haoyangeng-db commented on code in PR #51190: URL: https://github.com/apache/spark/pull/51190#discussion_r2158005491
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SemiStructuredExtract.scala: ########## @@ -0,0 +1,61 @@ +/* + * 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.AnalysisException +import org.apache.spark.sql.catalyst.expressions.variant.VariantGet +import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan +import org.apache.spark.sql.catalyst.rules.Rule +import org.apache.spark.sql.catalyst.trees.TreePattern.{SEMI_STRUCTURED_EXTRACT, TreePattern} +import org.apache.spark.sql.types.{DataType, StringType, VariantType} +import org.apache.spark.unsafe.types.UTF8String + +/** + * Represents the extraction of data from a field that contains semi-structured data. The + * semi-structured format can be anything (JSON, key-value delimited, etc), and that information Review Comment: Done. ########## sql/core/src/test/resources/sql-tests/inputs/variant-field-extractions.sql: ########## @@ -0,0 +1,13 @@ +-- Simple field extraction and type casting. +select parse_json('{ "price": 5 }'):price; Review Comment: Great suggestion. Done. ########## sql/core/src/test/resources/sql-tests/inputs/variant-field-extractions.sql: ########## @@ -0,0 +1,13 @@ +-- Simple field extraction and type casting. +select parse_json('{ "price": 5 }'):price; +select parse_json('{ "price": 30 }'):price::decimal(5, 2); +select parse_json('{ "price": 30 }'):price::string; +-- Applying an invalid function. +select parse_json('{ "price": 12345.678 }'):price::decimal(3, 2); +-- Access field in an array and feed it into functions. +select parse_json('{ "item": [ { "model" : "basic", "price" : 6.12 }, { "model" : "medium", "price" : 9.24 } ] }'):item[0].price::double; Review Comment: Added more syntaxes -- PTAL. BTW I intentionally didn't add things like "using ':' in group by", e.g.: ``` select multi_field_variant:city::string, count(*) from variant_test_data group by multi_field_variant:city::string ``` Because the "group by" here has to use the result after an explicit type cast (::string), making these tests less interesting. But please let me know if you feel covering those cases would still be helpful, and I can add those in. -- 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]
