From issues-return-483780-archive-asf-public=cust-asf.ponee.io@flink.apache.org Thu Apr 29 11:59:39 2021 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mxout1-he-de.apache.org (mxout1-he-de.apache.org [95.216.194.37]) by mx-eu-01.ponee.io (Postfix) with ESMTPS id 55D2D180636 for ; Thu, 29 Apr 2021 13:59:39 +0200 (CEST) Received: from mail.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by mxout1-he-de.apache.org (ASF Mail Server at mxout1-he-de.apache.org) with SMTP id AD92760D28 for ; Thu, 29 Apr 2021 11:59:38 +0000 (UTC) Received: (qmail 86480 invoked by uid 500); 29 Apr 2021 11:59:38 -0000 Mailing-List: contact issues-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flink.apache.org Delivered-To: mailing list issues@flink.apache.org Received: (qmail 86471 invoked by uid 99); 29 Apr 2021 11:59:37 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Apr 2021 11:59:37 +0000 From: =?utf-8?q?GitBox?= To: issues@flink.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bflink=5D_todd5167_commented_on_a_change_in_pull_re?= =?utf-8?q?quest_=2315755=3A_=5BFLINK-22318=5D=5Btable=5D_Support_RENAME_col?= =?utf-8?q?umn_name_for_ALTER_TABLE_state=E2=80=A6?= Message-ID: <161969757768.15571.7152482264181976629.asfpy@gitbox.apache.org> Date: Thu, 29 Apr 2021 11:59:37 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit In-Reply-To: References: todd5167 commented on a change in pull request #15755: URL: https://github.com/apache/flink/pull/15755#discussion_r622333275 ########## File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/utils/OperationConverterUtils.java ########## @@ -144,6 +149,116 @@ public static Operation convertChangeColumn( // TODO: handle watermark and constraints } + public static Operation convertRenameColumn( + ObjectIdentifier tableIdentifier, + String originColumnName, + String newColumnName, + CatalogTable catalogTable) { + + Schema modifiedTableSchema = catalogTable.getUnresolvedSchema(); + validateColumnName(originColumnName, newColumnName, modifiedTableSchema); + + Schema.Builder builder = Schema.newBuilder(); + // build column + modifiedTableSchema.getColumns().stream() + .forEach( + column -> { + if (StringUtils.equals(column.getName(), originColumnName)) { + buildNewColumnFromOriginColumn(builder, column, newColumnName); + } else { + buildNewColumnFromOriginColumn(builder, column, column.getName()); + } + }); + // build primary key column + List originPrimaryKeyNames = + modifiedTableSchema + .getPrimaryKey() + .map(Schema.UnresolvedPrimaryKey::getColumnNames) + .orElseGet(Lists::newArrayList); + + List newPrimaryKeyNames = + originPrimaryKeyNames.stream() + .map( + pkName -> + StringUtils.equals(pkName, originColumnName) + ? newColumnName + : pkName) + .collect(Collectors.toList()); + + if (newPrimaryKeyNames.size() > 0) { + builder.primaryKey(newPrimaryKeyNames); + } + // build watermark + modifiedTableSchema.getWatermarkSpecs().stream() + .forEach( + watermarkSpec -> { + String watermarkRefColumnName = watermarkSpec.getColumnName(); + Expression watermarkExpression = watermarkSpec.getWatermarkExpression(); + if (StringUtils.equals(watermarkRefColumnName, originColumnName)) { + String newWatermarkExpression = + ((SqlCallExpression) watermarkExpression) + .getSqlExpression() + .replace(watermarkRefColumnName, newColumnName); Review comment: hi, @wuchong. If the calculated column expression contains a renamed column, it will throw 'org.apache.calcite.sql.validate.SqlValidatorException: Unknown identifier 'oldColumn' ' when resolving the schema. You said 'traverse the node tree to check whether it contains the renamed column', I don’t know where to add it. If use ResolverRule, how to distinguish it from ResolveSqlCallRule. thanks . -- 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. For queries about this service, please contact Infrastructure at: users@infra.apache.org