eldenmoon commented on code in PR #60362: URL: https://github.com/apache/doris/pull/60362#discussion_r2757457962
########## regression-test/suites/variant_p0/predefine/test_schema_template_auto_cast.groovy: ########## @@ -0,0 +1,251 @@ +// 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. + +suite("test_schema_template_auto_cast", "p0") { Review Comment: add more test cases ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java: ########## @@ -316,6 +360,9 @@ public Expression visitUnboundSlot(UnboundSlot unboundSlot, ExpressionRewriteCon } else if (firstBound.containsType(ElementAt.class, StructElement.class)) { context.cascadesContext.getStatementContext().setHasNestedColumns(true); } + if (firstBound instanceof Alias) { Review Comment: why change this ########## fe/fe-core/src/test/java/org/apache/doris/nereids/types/VariantFieldMatchTest.java: ########## @@ -0,0 +1,278 @@ +// 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.doris.nereids.types; + +import org.apache.doris.thrift.TPatternType; + +import com.google.common.collect.ImmutableList; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +/** + * Unit tests for VariantField pattern matching and VariantType field lookup. + */ +public class VariantFieldMatchTest { + + // ==================== VariantField.matches() tests ==================== + + @Test + public void testExactMatch() { Review Comment: add more test cases ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java: ########## @@ -869,7 +1012,17 @@ public Expression visitMatch(Match match, ExpressionRewriteContext context) { @Override public Expression visitCast(Cast cast, ExpressionRewriteContext context) { - cast = (Cast) super.visitCast(cast, context); + boolean suppressVariantElementAtCast = shouldSuppressVariantElementAtCast(cast); + if (suppressVariantElementAtCast) { Review Comment: no chang this ########## fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantField.java: ########## @@ -67,6 +67,138 @@ public String getComment() { return comment; } + public TPatternType getPatternType() { + return patternType; + } + + /** + * Check if the given field name matches this field's pattern. + * This method aligns with BE's fnmatch(pattern, path, FNM_PATHNAME) behavior. + * + * Supported glob syntax: + * - '*' matches any sequence of characters except '/' + * - '?' matches any single character except '/' + * - '[...]' matches any character in the brackets + * - '[!...]' or '[^...]' matches any character not in the brackets + * + * @param fieldName the field name to check + * @return true if the field name matches the pattern + */ + public boolean matches(String fieldName) { + if (patternType == TPatternType.MATCH_NAME) { + return pattern.equals(fieldName); + } else { + // MATCH_NAME_GLOB: convert glob pattern to regex + // This aligns with BE's fnmatch(pattern, path, FNM_PATHNAME) + String regex = globToRegex(pattern); + return fieldName.matches(regex); + } + } + + /** + * Convert glob pattern to regex pattern, aligning with fnmatch(FNM_PATHNAME) behavior. + * + * fnmatch with FNM_PATHNAME flag behavior: + * - '*' matches any sequence of characters except '/' + * - '?' matches any single character except '/' + * - '[...]' matches any character in the brackets + * - '[!...]' or '[^...]' matches any character not in the brackets + * - '\' escapes the next character (e.g., '\*' matches literal '*') + */ + private static String globToRegex(String glob) { Review Comment: do not write this code -- 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]
