tledkov-gridgain commented on a change in pull request #484:
URL: https://github.com/apache/ignite-3/pull/484#discussion_r761905492
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/ddl/DdlSqlToCommandConverter.java
##########
@@ -138,77 +134,147 @@ public DdlCommand convert(SqlDdl ddlNode,
PlanningContext ctx) {
*/
private CreateTableCommand convertCreateTable(IgniteSqlCreateTable
createTblNode, PlanningContext ctx) {
CreateTableCommand createTblCmd = new CreateTableCommand();
-
+
createTblCmd.schemaName(deriveSchemaName(createTblNode.name(), ctx));
createTblCmd.tableName(deriveObjectName(createTblNode.name(), ctx,
"tableName"));
createTblCmd.ifNotExists(createTblNode.ifNotExists());
-
+
if (createTblNode.createOptionList() != null) {
for (SqlNode optNode : createTblNode.createOptionList().getList())
{
IgniteSqlCreateTableOption opt = (IgniteSqlCreateTableOption)
optNode;
-
+
tblOptionProcessors.getOrDefault(opt.key(),
UNSUPPORTED_OPTION_PROCESSOR).process(opt, ctx, createTblCmd);
}
}
-
+
List<SqlColumnDeclaration> colDeclarations =
createTblNode.columnList().getList().stream()
.filter(SqlColumnDeclaration.class::isInstance)
.map(SqlColumnDeclaration.class::cast)
.collect(Collectors.toList());
-
+
IgnitePlanner planner = ctx.planner();
-
- List<ColumnDefinition> cols = new ArrayList<>();
-
+ IgniteTypeFactory typeFactory = ctx.typeFactory();
+
+ List<ColumnDefinition> cols = new ArrayList<>(colDeclarations.size());
+
for (SqlColumnDeclaration col : colDeclarations) {
if (!col.name.isSimple()) {
throw new IgniteException("Unexpected value of columnName ["
+ "expected a simple identifier, but was " + col.name
+ "; "
- + "querySql=\"" + ctx.query() + "\"]"/*,
IgniteQueryErrorCode.PARSING*/);
+ + "querySql=\"" + ctx.query() + "\"]");
}
-
+
String name = col.name.getSimple();
- RelDataType type = planner.convert(col.dataType);
-
+ RelDataType relType = planner.convert(col.dataType);
+
Object dflt = null;
if (col.expression != null) {
dflt = ((SqlLiteral) col.expression).getValue();
}
-
- cols.add(new ColumnDefinition(name, type, dflt));
+
+ ColumnDefinitionBuilder col0 = SchemaBuilders.column(name,
typeFactory.columnType(relType));
+
+ col0.asNullable(relType.isNullable());
+
+ col0.withDefaultValueExpression(dflt);
Review comment:
```suggestion
ColumnDefinitionBuilder col0 = SchemaBuilders.column(name,
typeFactory.columnType(relType))
.asNullable(relType.isNullable())
.withDefaultValueExpression(dflt);
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/ddl/DdlSqlToCommandConverter.java
##########
@@ -52,64 +46,50 @@
import org.apache.calcite.sql.ddl.SqlKeyConstraint;
import
org.apache.ignite.internal.processors.query.calcite.prepare.IgnitePlanner;
import
org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext;
+import
org.apache.ignite.internal.processors.query.calcite.sql.IgniteSqlAlterTableAddColumn;
+import
org.apache.ignite.internal.processors.query.calcite.sql.IgniteSqlAlterTableDropColumn;
+import
org.apache.ignite.internal.processors.query.calcite.sql.IgniteSqlCreateIndex;
import
org.apache.ignite.internal.processors.query.calcite.sql.IgniteSqlCreateTable;
import
org.apache.ignite.internal.processors.query.calcite.sql.IgniteSqlCreateTableOption;
import
org.apache.ignite.internal.processors.query.calcite.sql.IgniteSqlCreateTableOptionEnum;
+import
org.apache.ignite.internal.processors.query.calcite.sql.IgniteSqlDropIndex;
+import
org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory;
+import org.apache.ignite.internal.util.Pair;
import org.apache.ignite.lang.IgniteException;
+import org.apache.ignite.schema.SchemaBuilders;
+import org.apache.ignite.schema.definition.ColumnDefinition;
+import org.apache.ignite.schema.definition.builder.ColumnDefinitionBuilder;
/**
- * DdlSqlToCommandConverter.
- * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
+ * DdlSqlToCommandConverter. TODO Documentation
https://issues.apache.org/jira/browse/IGNITE-15859
*/
public class DdlSqlToCommandConverter {
- /** Processor that validates a value is a Sql Identifier. */
- private static final BiFunction<IgniteSqlCreateTableOption,
PlanningContext, String> VALUE_IS_IDENTIFIER_VALIDATOR = (opt, ctx) -> {
- if (!(opt.value() instanceof SqlIdentifier) || !((SqlIdentifier)
opt.value()).isSimple()) {
- throwOptionParsingException(opt, "a simple identifier",
ctx.query());
- }
-
- return ((SqlIdentifier) opt.value()).getSimple();
- };
-
/** Processor that unconditionally throws an AssertionException. */
private static final TableOptionProcessor<Void>
UNSUPPORTED_OPTION_PROCESSOR = new TableOptionProcessor<>(
null,
(opt, ctx) -> {
throw new AssertionError("Unsupported option " + opt.key());
},
null);
-
+
+ /** Checks positive num param. */
+ private BiFunction<IgniteSqlCreateTableOption, PlanningContext, Integer>
positiveNumValidator = (opt, ctx) -> {
+ if (!(opt.value() instanceof SqlNumericLiteral)
+ || !((SqlNumericLiteral) opt.value()).isInteger()
+ || ((SqlLiteral) opt.value()).intValue(true) < 0
+ ) {
+ throwOptionParsingException(opt, "a non-negative integer",
ctx.query());
+ }
+
+ return ((SqlLiteral) opt.value()).intValue(true);
+ };
+
/** Map of the supported table option processors. */
private final Map<IgniteSqlCreateTableOptionEnum, TableOptionProcessor<?>>
tblOptionProcessors = Stream.of(
- new TableOptionProcessor<>(TEMPLATE,
VALUE_IS_IDENTIFIER_VALIDATOR, CreateTableCommand::templateName),
- new TableOptionProcessor<>(AFFINITY_KEY,
VALUE_IS_IDENTIFIER_VALIDATOR, CreateTableCommand::affinityKey),
- new TableOptionProcessor<>(CACHE_GROUP,
VALUE_IS_IDENTIFIER_VALIDATOR, CreateTableCommand::cacheGroup),
- new TableOptionProcessor<>(CACHE_NAME,
VALUE_IS_IDENTIFIER_VALIDATOR, CreateTableCommand::cacheName),
- new TableOptionProcessor<>(DATA_REGION,
VALUE_IS_IDENTIFIER_VALIDATOR, CreateTableCommand::dataRegionName),
- new TableOptionProcessor<>(KEY_TYPE,
VALUE_IS_IDENTIFIER_VALIDATOR, CreateTableCommand::keyTypeName),
- new TableOptionProcessor<>(VALUE_TYPE,
VALUE_IS_IDENTIFIER_VALIDATOR, CreateTableCommand::valueTypeName),
- //new TableOptionProcessor<>(ATOMICITY,
validatorForEnumValue(CacheAtomicityMode.class),
CreateTableCommand::atomicityMode),
- //new TableOptionProcessor<>(WRITE_SYNCHRONIZATION_MODE,
validatorForEnumValue(CacheWriteSynchronizationMode.class),
- //CreateTableCommand::writeSynchronizationMode),
- new TableOptionProcessor<>(BACKUPS, (opt, ctx) -> {
- if (!(opt.value() instanceof SqlNumericLiteral)
- || !((SqlNumericLiteral) opt.value()).isInteger()
- || ((SqlLiteral) opt.value()).intValue(true) < 0
- ) {
- throwOptionParsingException(opt, "a non-negative integer",
ctx.query());
- }
-
- return ((SqlLiteral) opt.value()).intValue(true);
- }, CreateTableCommand::backups),
- new TableOptionProcessor<>(ENCRYPTED, (opt, ctx) -> {
- if (!(opt.value() instanceof SqlLiteral) && ((SqlLiteral)
opt.value()).getTypeName() != BOOLEAN) {
- throwOptionParsingException(opt, "a boolean", ctx.query());
- }
-
- return ((SqlLiteral) opt.value()).booleanValue();
- }, CreateTableCommand::encrypted)
+ new TableOptionProcessor<>(REPLICAS, positiveNumValidator,
CreateTableCommand::replicas),
+ new TableOptionProcessor<>(PARTITIONS, positiveNumValidator,
CreateTableCommand::partitions)
).collect(Collectors.toMap(TableOptionProcessor::key,
Function.identity()));
-
+
Review comment:
Please remove spaces at the empty lines, here and at the
TableManagerTest
--
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]