haridsv commented on code in PR #1866:
URL: https://github.com/apache/phoenix/pull/1866#discussion_r1561999387


##########
phoenix-core-client/src/main/java/org/apache/phoenix/util/CDCUtil.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.phoenix.util;
+
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.NavigableSet;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.util.StringUtils;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.exception.SQLExceptionInfo;
+import org.apache.phoenix.execute.DescVarLengthFastByteComparisons;
+import org.apache.phoenix.schema.PTable;
+
+public class CDCUtil {
+    public static final String CDC_INDEX_PREFIX = "__CDC__";
+    public static final String CDC_INDEX_TYPE_LOCAL = "L";
+
+    /**
+     * Make a set of CDC change scope enums from the given string containing 
comma separated scope
+     * names.
+     *
+     * @param includeScopes Comma-separated scope names.
+     * @return the set of enums, which can be empty if the string is empty or 
has no valid names.
+     */
+    public static Set<PTable.CDCChangeScope> 
makeChangeScopeEnumsFromString(String includeScopes)
+            throws SQLException {
+        Set<PTable.CDCChangeScope> cdcChangeScopes = new HashSet<>();
+        if (includeScopes != null) {
+            StringTokenizer st  = new StringTokenizer(includeScopes, ",");
+            while (st.hasMoreTokens()) {
+                String tok = st.nextToken();
+                try {
+                    
cdcChangeScopes.add(PTable.CDCChangeScope.valueOf(tok.trim().toUpperCase()));
+                }
+                catch (IllegalArgumentException e) {
+                    throw new SQLExceptionInfo.Builder(
+                            
SQLExceptionCode.UNKNOWN_INCLUDE_CHANGE_SCOPE).setCdcChangeScope(
+                                    tok).build().buildException();
+                }
+            }
+        }
+        return cdcChangeScopes;
+    }
+
+    /**
+     * Make a string of comma-separated scope names from the specified set of 
enums.
+     *
+     * @param includeScopes Set of scope enums
+     * @return the comma-separated string of scopes, which can be an empty 
string in case the set is empty.
+     */
+    public static String 
makeChangeScopeStringFromEnums(Set<PTable.CDCChangeScope> includeScopes) {
+        String cdcChangeScopes = null;
+        if (includeScopes != null) {
+            Iterable<String> tmpStream = () -> includeScopes.stream().sorted()
+                    .map(s -> s.name()).iterator();
+            cdcChangeScopes = StringUtils.join(",", tmpStream);
+        }
+        return cdcChangeScopes;
+    }
+
+    public static String getCDCIndexName(String cdcName) {
+        return CDC_INDEX_PREFIX + 
SchemaUtil.getTableNameFromFullName(cdcName.toUpperCase());
+    }
+
+    public static boolean isCDCIndex(String indexName) {
+        return indexName.startsWith(CDC_INDEX_PREFIX);
+    }
+
+    public static boolean isCDCIndex(PTable indexTable) {
+        return isCDCIndex(indexTable.getTableName().getString());
+    }
+
+    public static Scan initForRawScan(Scan scan) {

Review Comment:
   Good point! It started purely for setting raw scan attributes so the name 
was appropriate back then, but your suggestion to rename sounds good.



-- 
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]

Reply via email to