dan-s1 commented on code in PR #7544:
URL: https://github.com/apache/nifi/pull/7544#discussion_r1437164753


##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/UpdateDatabaseTable.java:
##########
@@ -460,15 +488,18 @@ public void onTrigger(final ProcessContext context, final 
ProcessSession session
 
     private synchronized OutputMetadataHolder checkAndUpdateTableSchema(final 
Connection conn, final DatabaseAdapter databaseAdapter, final RecordSchema 
schema,
                                                                         final 
String catalogName, final String schemaName, final String tableName,
-                                                                        final 
boolean createIfNotExists, final boolean translateFieldNames, final boolean 
updateFieldNames,
+                                                                        final 
boolean createIfNotExists, final boolean translateFieldNames,
+                                                                        final 
TranslationStrategy translationStrategy, Pattern translationRegex, final 
boolean updateFieldNames,
                                                                         final 
Set<String> primaryKeyColumnNames, final boolean quoteTableName, final boolean 
quoteColumnNames) throws IOException {
         // Read in the current table metadata, compare it to the reader's 
schema, and
         // add any columns from the schema that are missing in the table
+//        final ColumnNameNormalizer normalizer = new 
ColumnNameNormalizer(translateFieldNames, translationStrategy, 
translationRegex);

Review Comment:
   Remove commented out code



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/db/ColumnNameNormalizerUtility.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.nifi.processors.standard.db;
+
+
+import java.util.Objects;
+import java.util.regex.Pattern;
+
+/**
+ * ColumnNameNormalizerUtility is a utility class that helps to normalize 
column names. It provides various strategies to
+ * modify column names based on the TranslationStrategy enum. Column names can 
be normalized by removing underscores,
+ * spaces, all special characters, or by using a custom regular expression 
defined by the user.
+ */
+public class ColumnNameNormalizerUtility {
+    // Regular expression to remove all special characters from a string.
+    private static final Pattern REMOVE_ALL_SPECIAL_CHAR_REGEX = 
Pattern.compile("[^a-zA-Z0-9]");
+
+    /**
+     * Normalizes the given column name based on the specified strategy.
+     *
+     * @param colName The column name to be normalized.
+     * @param isTranslationEnabled Boolean value to denote normalization is 
enabled
+     * @param strategy The TranslationStrategy for normalizing column name
+     * @param translationRegex Regex For translation
+     * @return The normalized column name as a String.
+     */
+    public static String getNormalizedName(final String colName, boolean 
isTranslationEnabled, TranslationStrategy strategy, Pattern translationRegex) {
+        // If the column name is null or translation is not enabled, return 
the original column name.
+        if (colName == null || !isTranslationEnabled) {
+            return colName;
+        }
+
+        return switch (Objects.requireNonNull(strategy)) {
+            case REMOVE_UNDERSCORE -> colName.toUpperCase().replace("_", "");
+            case REMOVE_SPACE -> colName.toUpperCase().replace(" ", "");
+            case REMOVE_ALL_SPECIAL_CHAR -> REMOVE_ALL_SPECIAL_CHAR_REGEX 
.matcher(colName.toUpperCase()).replaceAll( "");

Review Comment:
   ```suggestion
               case REMOVE_ALL_SPECIAL_CHAR -> REMOVE_ALL_SPECIAL_CHAR_REGEX 
.matcher(colName.toUpperCase()).replaceAll("");
   ```



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to