tkalkirill commented on code in PR #783:
URL: https://github.com/apache/ignite-3/pull/783#discussion_r854966655


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/DdlSqlToCommandConverter.java:
##########
@@ -388,104 +428,170 @@ private void ensureSchemaExists(PlanningContext ctx, 
String schemaName) {
     }
 
     /**
-     * Short cut for validating that option value is a simple identifier.
+     * Throws exception with message relates to validation of create table 
option.
      *
-     * @param opt An option to validate.
-     * @param ctx Planning context.
+     * @param opt An option which validation was failed.
+     * @param exp A string representing expected values.
+     * @param qry A query the validation was failed for.
      */
-    private String paramIsSqlIdentifierValidator(IgniteSqlCreateTableOption 
opt, PlanningContext ctx) {
-        if (!(opt.value() instanceof SqlIdentifier) || !((SqlIdentifier) 
opt.value()).isSimple()) {
-            throwOptionParsingException(opt, "a simple identifier", 
ctx.query());
+    private static void throwOptionParsingException(IgniteSqlCreateTableOption 
opt, String exp, String qry) {
+        throw new IgniteException("Unexpected value for param " + opt.key() + 
" ["
+                + "expected " + exp + ", but was " + opt.value() + "; "
+                + "querySql=\"" + qry + "\"]"/*, 
IgniteQueryErrorCode.PARSING*/);
+    }
+
+    /**
+     * Collects a mapping of the ID (and ID in quotes) of the data storage to 
a name.
+     *
+     * <p>Example: {@code collectDataStorageNames(Set.of("rocksdb"))} -> 
{@code Map.of("rocksdb", "rocksdb", "ROCKSDB", "rocksdb")}.
+     *
+     * @param dataStorages Names of the data storages.
+     * @throws IllegalStateException If there is a duplicate ID.
+     */
+    static Map<String, String> collectDataStorageNames(Set<String> 
dataStorages) {
+        if (dataStorages.isEmpty()) {
+            return Map.of();
         }
 
-        return ((SqlIdentifier) opt.value()).getSimple();
+        Map<String, String> res = new HashMap<>();
+
+        Set<String> ids = new HashSet<>();
+
+        for (String dataStorageName : dataStorages) {
+            addAll(ids, dataStorageName, dataStorageName.toUpperCase());
+
+            for (String id : ids) {
+                if (res.containsKey(id)) {
+                    throw new IllegalStateException("Duplicate id:" + id);
+                }
+
+                res.put(id, dataStorageName);
+            }
+
+            ids.clear();
+        }
+
+        return unmodifiableMap(res);
     }
 
     /**
-     * Creates a validator for an option which value should be value of given 
enumeration.
+     * Collects a mapping of the ID (and ID in quotes) of the table option to 
a table option info.
+     *
+     * <p>Example for "replicas": {@code Map.of("replicas", 
TableOptionInfo@123, "REPLICAS", TableOptionInfo@123)}.
      *
-     * @param clz Enumeration class to create validator for.
+     * @param tableOptionInfos Table option information's.
+     * @throws IllegalStateException If there is a duplicate ID.
      */
-    private static <T extends Enum<T>> BiFunction<IgniteSqlCreateTableOption, 
PlanningContext, T> validatorForEnumValue(
-            Class<T> clz
-    ) {
-        return (opt, ctx) -> {
-            T val = null;
-
-            if (opt.value() instanceof SqlIdentifier) {
-                val = Arrays.stream(clz.getEnumConstants())
-                        .filter(m -> 
m.name().equalsIgnoreCase(opt.value().toString()))
-                        .findFirst()
-                        .orElse(null);
-            }
+    static Map<String, TableOptionInfo<?>> 
collectTableOptionInfos(TableOptionInfo<?>... tableOptionInfos) {
+        if (ArrayUtils.nullOrEmpty(tableOptionInfos)) {
+            return Map.of();
+        }
 
-            if (val == null) {
-                throwOptionParsingException(opt, "values are "
-                        + Arrays.toString(clz.getEnumConstants()), 
ctx.query());
+        Map<String, TableOptionInfo<?>> res = new HashMap<>();
+
+        Set<String> ids = new HashSet<>();
+
+        for (TableOptionInfo<?> tableOptionInfo : tableOptionInfos) {
+            addAll(ids, tableOptionInfo.name, 
tableOptionInfo.name.toUpperCase());
+
+            for (String id : ids) {
+                if (res.containsKey(id)) {
+                    throw new IllegalStateException("Duplicate id:" + id);
+                }
+
+                res.put(id, tableOptionInfo);
             }
 
-            return val;
-        };
+            ids.clear();
+        }
+
+        return unmodifiableMap(res);
     }
 
     /**
-     * Throws exception with message relates to validation of create table 
option.
+     * Checks that there are no ID duplicates.
      *
-     * @param opt An option which validation was failed.
-     * @param exp A string representing expected values.
-     * @param qry A query the validation was failed for.
+     * @param tableOptionInfos0 Table options information.
+     * @param tableOptionInfos1 Table options information.
+     * @throws IllegalStateException If there is a duplicate ID.
      */
-    private static void throwOptionParsingException(IgniteSqlCreateTableOption 
opt, String exp, String qry) {
-        throw new IgniteException("Unexpected value for param " + opt.key() + 
" ["
-                + "expected " + exp + ", but was " + opt.value() + "; "
-                + "querySql=\"" + qry + "\"]"/*, 
IgniteQueryErrorCode.PARSING*/);
+    static void checkDuplicates(Map<String, TableOptionInfo<?>> 
tableOptionInfos0, Map<String, TableOptionInfo<?>> tableOptionInfos1) {
+        for (String id : tableOptionInfos1.keySet()) {
+            if (tableOptionInfos0.containsKey(id)) {
+                throw new IllegalStateException("Duplicate id:" + id);
+            }
+        }
     }
 
-    private static class TableOptionProcessor<T> {
-        private final IgniteSqlCreateTableOptionEnum key;
-
-        private final BiFunction<IgniteSqlCreateTableOption, PlanningContext, 
T> validator;
-
-        private final BiConsumer<CreateTableCommand, T> valSetter;
-
-        /**
-         * Constructor.
-         *
-         * @param key       Option key this processor is supopsed to handle.
-         * @param validator Validator that derives a value from a {@link 
SqlNode}, validates it and then returns if validation passed,
-         *                  throws an exeption otherwise.
-         * @param valSetter Setter sets the value recived from the validator 
to the given {@link CreateTableCommand}.
-         */
-        private TableOptionProcessor(
-                IgniteSqlCreateTableOptionEnum key,
-                BiFunction<IgniteSqlCreateTableOption, PlanningContext, T> 
validator,
-                BiConsumer<CreateTableCommand, T> valSetter
-        ) {
-            this.key = key;
-            this.validator = validator;
-            this.valSetter = valSetter;
+    private String driveDataStorage(@Nullable SqlIdentifier engineName, 
PlanningContext ctx) {

Review Comment:
   fix it.



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