This is an automated email from the ASF dual-hosted git repository.

alsuliman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 50d065483b [NO ISSUE][EXT]: Refactor external data prefix class
50d065483b is described below

commit 50d065483be7794d75598028612eb682ccb51ea3
Author: Hussain Towaileb <[email protected]>
AuthorDate: Thu Aug 3 01:01:43 2023 +0300

    [NO ISSUE][EXT]: Refactor external data prefix class
    
    Change-Id: I6305ae6f9cd1cf38a2299d8bd7fa21e80610bcc8
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17690
    Integration-Tests: Jenkins <[email protected]>
    Reviewed-by: Hussain Towaileb <[email protected]>
    Reviewed-by: Wail Alkowaileet <[email protected]>
    Tested-by: Hussain Towaileb <[email protected]>
---
 .../asterix/external/util/ExternalDataPrefix.java  | 81 ++++++++--------------
 1 file changed, 30 insertions(+), 51 deletions(-)

diff --git 
a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/ExternalDataPrefix.java
 
b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/ExternalDataPrefix.java
index c2a047b922..c3419c152d 100644
--- 
a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/ExternalDataPrefix.java
+++ 
b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/ExternalDataPrefix.java
@@ -36,6 +36,7 @@ import java.util.regex.Matcher;
 import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.BuiltinTypeMap;
 import org.apache.asterix.om.types.IAType;
@@ -52,11 +53,11 @@ public class ExternalDataPrefix {
     private final ComputedFieldDetails computedFieldDetails;
 
     public static final String PREFIX_ROOT_FIELD_NAME = "prefix-root";
-    public static final Set<IAType> supportedTypes = new HashSet<>();
+    public static final Set<ATypeTag> supportedTypes = new HashSet<>();
 
     static {
-        supportedTypes.add(BuiltinType.ASTRING);
-        supportedTypes.add(BuiltinType.AINT32);
+        supportedTypes.add(BuiltinType.ASTRING.getTypeTag());
+        supportedTypes.add(BuiltinType.AINT32.getTypeTag());
     }
 
     public ExternalDataPrefix(String prefix) throws AlgebricksException {
@@ -116,42 +117,25 @@ public class ExternalDataPrefix {
         List<Integer> computedFieldIndexes = new ArrayList<>();
 
         // check if there are any segments before doing any testing
-        if (segments.size() != 0) {
+        if (!segments.isEmpty()) {
             // search for computed fields in each segment
-            Matcher matcher = COMPUTED_FIELD_PATTERN.matcher(segments.get(0));
-            if (matcher.find()) {
-                String computedField = matcher.group();
-                String[] splits = computedField.split(":");
-                String namePart = splits[0].substring(1);
-                String typePart = splits[1].substring(0, splits[1].length() - 
1);
-
-                IAType type = 
BuiltinTypeMap.getBuiltinType(typePart.substring(0, typePart.length() - 1));
-                validateSupported(type);
-
-                List<String> nameParts = List.of(namePart.substring(1, 
segments.indexOf(":") - 1).split("\\."));
-                computedFieldsNames.add(nameParts);
-                computedFieldTypes.add(type);
-                computedFieldIndexes.add(0);
-            }
-
-            if (segments.size() > 1) {
-                for (int i = 1; i < segments.size(); i++) {
-                    matcher.reset(segments.get(i));
-
-                    while (matcher.find()) {
-                        String computedField = matcher.group();
-                        String[] splits = computedField.split(":");
-                        String namePart = splits[0].substring(1);
-                        String typePart = splits[1].substring(0, 
splits[1].length() - 1);
-
-                        IAType type = BuiltinTypeMap.getBuiltinType(typePart);
-                        validateSupported(type);
-
-                        List<String> nameParts = 
List.of(namePart.split("\\."));
-                        computedFieldsNames.add(nameParts);
-                        computedFieldTypes.add(type);
-                        computedFieldIndexes.add(i);
-                    }
+            Matcher matcher = COMPUTED_FIELD_PATTERN.matcher("");
+            for (int i = 0; i < segments.size(); i++) {
+                matcher.reset(segments.get(i));
+
+                while (matcher.find()) {
+                    String computedField = matcher.group();
+                    String[] splits = computedField.split(":");
+                    String namePart = splits[0].substring(1);
+                    String typePart = splits[1].substring(0, 
splits[1].length() - 1);
+
+                    IAType type = BuiltinTypeMap.getBuiltinType(typePart);
+                    validateSupported(type.getTypeTag());
+
+                    List<String> nameParts = List.of(namePart.split("\\."));
+                    computedFieldsNames.add(nameParts);
+                    computedFieldTypes.add(type);
+                    computedFieldIndexes.add(i);
                 }
             }
         }
@@ -159,8 +143,14 @@ public class ExternalDataPrefix {
         return new ComputedFieldDetails(computedFieldsNames, 
computedFieldTypes, computedFieldIndexes);
     }
 
-    private static void validateSupported(IAType type) throws 
CompilationException {
-        if (!isSupportedType(type)) {
+    /**
+     * Checks whether the provided type is in the supported types for dynamic 
prefixes
+     *
+     * @param type type to check
+     * @throws CompilationException exception if type is not supported
+     */
+    private static void validateSupported(ATypeTag type) throws 
CompilationException {
+        if (!supportedTypes.contains(type)) {
             throw new 
CompilationException(ErrorCode.UNSUPPORTED_COMPUTED_FIELD_TYPE, type);
         }
     }
@@ -196,17 +186,6 @@ public class ExternalDataPrefix {
         return ExternalDataUtils.appendSlash(finalRoot, this.endsWithSlash);
     }
 
-    /**
-     * Checks whether the provided type is in the supported types for dynamic 
prefixes
-     *
-     * @param type type to check
-     *
-     * @return true if type is supported, false otherwise
-     */
-    public static boolean isSupportedType(IAType type) {
-        return supportedTypes.contains(type);
-    }
-
     public static class ComputedFieldDetails {
         private final List<List<String>> computedFieldNames;
         private final List<IAType> computedFieldTypes;

Reply via email to