korlov42 commented on a change in pull request #484:
URL: https://github.com/apache/ignite-3/pull/484#discussion_r762967022
##########
File path:
modules/api/src/main/java/org/apache/ignite/lang/ColumnNotFoundException.java
##########
@@ -0,0 +1,15 @@
+package org.apache.ignite.lang;
+
+/**
+ * Exception is thrown when appropriate column not found.
Review comment:
```suggestion
* Exception is thrown when appropriate column is not found.
```
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/sql/IgniteSqlAlterTableAddColumn.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.sql;
+
+import java.util.List;
+import java.util.Objects;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.util.ImmutableNullableList;
+
+/**
+ * Parse tree for {@code ALTER TABLE ... ADD COLUMN} statement.
+ */
+public class IgniteSqlAlterTableAddColumn extends IgniteAbstractSqlAlterTable {
+ /** existance flag. */
+ private final boolean ifNotExistsColumn;
+
+ /** Introduced columns. */
+ private final SqlNodeList columns;
+
+ /** Constructor. */
+ public IgniteSqlAlterTableAddColumn(SqlParserPos pos, boolean ifExists,
SqlIdentifier tblName,
+ boolean ifNotExistsColumn, SqlNodeList columns) {
+ super(pos, ifExists, tblName);
+ this.ifNotExistsColumn = ifNotExistsColumn;
+ this.columns = Objects.requireNonNull(columns, "columns list");
+ }
+
+ /** {@inheritDoc} */
+ @Override public List<SqlNode> getOperandList() {
+ return ImmutableNullableList.of(name, columns);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void unparseAlterTableOperation(SqlWriter writer, int
leftPrec, int rightPrec) {
+ writer.keyword("ADD");
+ writer.keyword("COLUMN");
+
+ if (ifNotExistsColumn) {
+ writer.keyword("IF NOT EXISTS");
+ }
+
+ columns.unparse(writer, leftPrec, rightPrec);
+ }
+
+ /** ADD COLUMN IF NOT EXISTS flag. */
Review comment:
```suggestion
/** Returns whether the IF NOT EXISTS is specified for columns. */
```
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/ddl/CreateIndexCommand.java
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.prepare.ddl;
+
+import java.util.List;
+import org.apache.ignite.internal.util.Pair;
+
+/**
+ * CREATE INDEX statement.
+ */
+public class CreateIndexCommand extends AbstractDdlCommand {
Review comment:
`Create(Drop-)IndexCommand` should not be derived from
`AbstractDdlCommand` since this abstraction is table-specific
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/sql/IgniteSqlAlterTableDropColumn.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.sql;
+
+import java.util.List;
+import java.util.Objects;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.util.ImmutableNullableList;
+
+/**
+ * Parse tree for {@code ALTER TABLE ... DROP COLUMN} statement.
+ */
+public class IgniteSqlAlterTableDropColumn extends IgniteAbstractSqlAlterTable
{
+ /** Command existance flag. */
Review comment:
```suggestion
/** Whether to ignore error in case column with specified name doesn't
exist. */
```
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/sql/IgniteAbstractSqlAlterTable.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.sql;
+
+import java.util.Objects;
+import org.apache.calcite.sql.SqlDdl;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.SqlSpecialOperator;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.parser.SqlParserPos;
+
+/**
+ * Parse tree for {@code ALTER TABLE } statement.
+ */
+public abstract class IgniteAbstractSqlAlterTable extends SqlDdl {
+ /** Ident name. */
+ protected final SqlIdentifier name;
+
+ /** If exist flag. */
+ protected final boolean ifExists;
+
+ /** Alter operator. */
+ private static final SqlOperator OPERATOR =
+ new SqlSpecialOperator("ALTER TABLE", SqlKind.ALTER_TABLE);
+
+ /** Constructor. */
+ public IgniteAbstractSqlAlterTable(SqlParserPos pos, boolean ifExists,
SqlIdentifier tblName) {
+ super(OPERATOR, pos);
+ this.ifExists = ifExists;
+ name = Objects.requireNonNull(tblName, "table name");
+ }
+
+ /** {@inheritDoc} */
+ @Override public SqlOperator getOperator() {
+ return OPERATOR;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void unparse(SqlWriter writer, int leftPrec, int
rightPrec) {
+ writer.keyword(getOperator().getName());
+
+ if (ifExists) {
+ writer.keyword("IF EXISTS");
+ }
+
+ name.unparse(writer, leftPrec, rightPrec);
+
+ unparseAlterTableOperation(writer, leftPrec, rightPrec);
+ }
+
+ /**
+ * Unparse rest of the ALTER TABLE command.
+ */
+ protected abstract void unparseAlterTableOperation(SqlWriter writer, int
leftPrec, int rightPrec);
+
+ /**
+ * Ident name.
Review comment:
what name?
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/ddl/AbstractDdlCommand.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.prepare.ddl;
+
+/**
+ * ALTER TABLE ... ADD/DROP COLUMN statement.
+ */
+public abstract class AbstractDdlCommand implements DdlCommand {
Review comment:
The more suitable name is `AbstractTableDdlCommand`. And the javadoc
should be `An abstract table-related DDL command`
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/ddl/CreateTableCommand.java
##########
@@ -18,188 +18,30 @@
package org.apache.ignite.internal.processors.query.calcite.prepare.ddl;
import java.util.List;
+import org.apache.ignite.schema.definition.ColumnDefinition;
import org.jetbrains.annotations.Nullable;
/**
* CREATE TABLE statement.
*/
-public class CreateTableCommand implements DdlCommand {
- /**
- * Schema name upon which this statement has been issued - <b>not</b> the
name of the schema where this new table will be created.
- */
- private String schemaName;
-
- /** Table name. */
- private String tblName;
-
- /** Cache name upon which new cache configuration for this table must be
based. */
- private String templateName;
-
- /** Name of new cache associated with this table. */
- private String cacheName;
-
- /** Name of cache key type. */
- private String keyTypeName;
-
- /** Name of cache value type. */
- private String valTypeName;
+public class CreateTableCommand extends AbstractDdlCommand {
+ /** Replicas number. */
+ private Integer replicas;
- /** Group to put new cache into. */
- private String cacheGrp;
-
- // /** Atomicity mode for new cache. */
- // private CacheAtomicityMode atomicityMode;
- //
- // /** Write sync mode. */
- // private CacheWriteSynchronizationMode writeSyncMode;
-
- /** Backups number for new cache. */
- private Integer backups;
+ /** Number of partitions for the new table. */
+ private Integer partitions;
/** Quietly ignore this command if table already exists. */
private boolean ifNotExists;
- /** Columns. */
- private List<ColumnDefinition> cols;
-
/** Primary key columns. */
private List<String> pkCols;
- /** Name of the column that represents affinity key. */
- private String affinityKey;
-
- /** Data region. */
- private String dataRegionName;
-
- /** Encrypted flag. */
- private boolean encrypted;
+ /** Affinity key columns. */
+ private List<String> affCols;
Review comment:
Could you please file a ticket to support multiple affinity columns with
SqlParser?
##########
File path:
modules/schema/src/test/java/org/apache/ignite/internal/schema/SchemaConfigurationTest.java
##########
@@ -40,12 +40,12 @@ public void testInitialSchema() {
builder
.columns(
- // Declaring columns in user order.
Review comment:
please revert this change (only the part with spaces)
##########
File path:
modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/SchemaConfigurationConverterTest.java
##########
@@ -87,11 +87,11 @@ public void createRegistry() throws ExecutionException,
InterruptedException {
tblBuilder = SchemaBuilders.tableBuilder("SNAME", "TNAME")
.columns(
- SchemaBuilders.column("COL1",
ColumnType.DOUBLE).build(),
Review comment:
please revert this change
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/ddl/CreateTableCommand.java
##########
@@ -18,188 +18,30 @@
package org.apache.ignite.internal.processors.query.calcite.prepare.ddl;
import java.util.List;
+import org.apache.ignite.schema.definition.ColumnDefinition;
import org.jetbrains.annotations.Nullable;
/**
* CREATE TABLE statement.
*/
-public class CreateTableCommand implements DdlCommand {
- /**
- * Schema name upon which this statement has been issued - <b>not</b> the
name of the schema where this new table will be created.
- */
- private String schemaName;
-
- /** Table name. */
- private String tblName;
-
- /** Cache name upon which new cache configuration for this table must be
based. */
- private String templateName;
-
- /** Name of new cache associated with this table. */
- private String cacheName;
-
- /** Name of cache key type. */
- private String keyTypeName;
-
- /** Name of cache value type. */
- private String valTypeName;
+public class CreateTableCommand extends AbstractDdlCommand {
+ /** Replicas number. */
+ private Integer replicas;
- /** Group to put new cache into. */
- private String cacheGrp;
-
- // /** Atomicity mode for new cache. */
- // private CacheAtomicityMode atomicityMode;
- //
- // /** Write sync mode. */
- // private CacheWriteSynchronizationMode writeSyncMode;
-
- /** Backups number for new cache. */
- private Integer backups;
+ /** Number of partitions for the new table. */
+ private Integer partitions;
/** Quietly ignore this command if table already exists. */
private boolean ifNotExists;
Review comment:
you already have
`org.apache.ignite.internal.processors.query.calcite.prepare.ddl.AbstractDdlCommand#ifTableExists`.
But actually, the latter is set but never read. Do you have test to verify
this flag
##########
File path:
modules/schema/src/main/java/org/apache/ignite/internal/schema/definition/builder/PrimaryKeyDefinitionBuilderImpl.java
##########
@@ -72,14 +92,14 @@ public PrimaryKeyDefinition build() {
throw new IllegalStateException("Primary key column(s) must be
configured.");
}
- Set<String> cols = Set.of(columns);
+ Set<String> cols = new HashSet<>(columns);
Review comment:
Probably, it would be better to change to `java.util.Set#copyOf`
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/ddl/DropTableCommand.java
##########
@@ -20,7 +20,7 @@
/**
* DROP TABLE statement.
*/
-public class DropTableCommand implements DdlCommand {
+public class DropTableCommand extends AbstractDdlCommand {
Review comment:
All fields from `DropTableCommand` are duplicated in `AbstractDdlCommand`
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
##########
@@ -136,8 +140,35 @@ public Type getJavaClass(RelDataType type) {
}
/**
- * Get result type by field data type.
- * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
+ * Gets ColumnType type for given class.
+ *
+ * @param relType Rel type.
+ * @return ColumnType type or null.
+ */
+ public ColumnType columnType(RelDataType relType) {
+ assert relType != null;
+
+ Type javaType = getResultClass(relType);
+
+ if (javaType == byte[].class) {
+ return relType.getPrecision() == PRECISION_NOT_SPECIFIED ?
ColumnType.blobOf() :
+ ColumnType.blobOf(relType.getPrecision());
+ } else if (javaType == String.class) {
+ return relType.getPrecision() == PRECISION_NOT_SPECIFIED ?
ColumnType.string() :
+ ColumnType.stringOf(relType.getPrecision());
+ } else if (javaType == BigInteger.class) {
+ return relType.getPrecision() == PRECISION_NOT_SPECIFIED ?
ColumnType.numberOf() :
+ ColumnType.numberOf(relType.getPrecision());
+ } else if (javaType == BigDecimal.class) {
+ return relType.getPrecision() == PRECISION_NOT_SPECIFIED ?
ColumnType.decimalOf() :
+ ColumnType.decimalOf(relType.getPrecision(),
relType.getScale());
Review comment:
you have to check whether scale was specified as well
--
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]