tkalkirill commented on code in PR #783:
URL: https://github.com/apache/ignite-3/pull/783#discussion_r854971533
##########
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());
Review Comment:
Discussed personally, we will support only uppercase, without bothering with
quotes.
--
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]