zstan commented on code in PR #1109:
URL: https://github.com/apache/ignite-3/pull/1109#discussion_r976500995
##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/configuration/TableValidatorImpl.java:
##########
@@ -41,10 +42,9 @@ public void validate(TableValidator annotation,
ValidationContext<NamedListView<
TableView newTable = newTables.get(tableName);
try {
- TableDefinitionImpl tbl =
SchemaConfigurationConverter.convert(newTable);
-
- assert !tbl.keyColumns().isEmpty();
- assert !tbl.colocationColumns().isEmpty();
+ assert newTable.primaryKey() != null;
Review Comment:
why asserts acceptable here ?
##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/configuration/ConfigurationToSchemaDescriptorConverter.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.schema.configuration;
+
+import static
org.apache.ignite.internal.schema.configuration.ValueSerializationHelper.fromString;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.ignite.configuration.schemas.table.ColumnDefaultView;
+import org.apache.ignite.configuration.schemas.table.ColumnTypeView;
+import org.apache.ignite.configuration.schemas.table.ColumnView;
+import org.apache.ignite.configuration.schemas.table.ConstantValueDefaultView;
+import org.apache.ignite.configuration.schemas.table.FunctionCallDefaultView;
+import org.apache.ignite.configuration.schemas.table.NullValueDefaultView;
+import org.apache.ignite.configuration.schemas.table.TableView;
+import org.apache.ignite.internal.schema.Column;
+import org.apache.ignite.internal.schema.DefaultValueGenerator;
+import org.apache.ignite.internal.schema.DefaultValueProvider;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypes;
+import org.apache.ignite.internal.schema.SchemaDescriptor;
+import org.apache.ignite.internal.util.IgniteUtils;
+
+/**
+ * Utility class to convert table configuration view as well as all related
objects to a {@link SchemaDescriptor} domain.
+ */
+public final class ConfigurationToSchemaDescriptorConverter {
+ private static final Map<String, NativeType> fixSizedTypes;
Review Comment:
seems we still need all in upper case here.
##########
modules/schema/src/test/java/org/apache/ignite/internal/schema/configuration/ConfigurationToSchemaDescriptorConverterTest.java:
##########
@@ -0,0 +1,308 @@
+/*
+ * 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.schema.configuration;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+
+import java.util.ArrayList;
+import
org.apache.ignite.configuration.schemas.store.UnknownDataStorageConfigurationSchema;
+import
org.apache.ignite.configuration.schemas.table.ColumnDefaultConfigurationSchema;
+import org.apache.ignite.configuration.schemas.table.ColumnDefaultView;
+import org.apache.ignite.configuration.schemas.table.ColumnTypeView;
+import org.apache.ignite.configuration.schemas.table.ColumnView;
+import org.apache.ignite.configuration.schemas.table.ConstantValueDefaultView;
+import org.apache.ignite.configuration.schemas.table.FunctionCallDefaultView;
+import
org.apache.ignite.configuration.schemas.table.NullValueDefaultConfigurationSchema;
+import org.apache.ignite.configuration.schemas.table.NullValueDefaultView;
+import org.apache.ignite.configuration.schemas.table.TableConfiguration;
+import
org.apache.ignite.configuration.schemas.table.UnlimitedBudgetConfigurationSchema;
+import
org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import
org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.schema.BitmaskNativeType;
+import org.apache.ignite.internal.schema.Column;
+import org.apache.ignite.internal.schema.DecimalNativeType;
+import
org.apache.ignite.internal.schema.DefaultValueProvider.FunctionalValueProvider;
+import org.apache.ignite.internal.schema.DefaultValueProvider.Type;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.NativeTypes;
+import org.apache.ignite.internal.schema.NumberNativeType;
+import org.apache.ignite.internal.schema.SchemaDescriptor;
+import org.apache.ignite.internal.schema.TemporalNativeType;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import
org.apache.ignite.internal.schema.testutils.definition.DefaultValueGenerators;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Tests to verify conversion from configuration views to schema objects.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public class ConfigurationToSchemaDescriptorConverterTest extends
AbstractSchemaConverterTest {
+ private static final int TEST_LENGTH = 15;
+
+ private static final int TEST_PRECISION = 8;
+
+ private static final int TEST_SCALE = 5;
+
+ @ParameterizedTest
+ @EnumSource(value = NativeTypeSpec.class)
+ public void convertColumnTypeView(NativeTypeSpec typeSpec) {
+ ColumnTypeView typeView = TestColumnTypeView.forSpec(typeSpec);
+
+ NativeType type =
ConfigurationToSchemaDescriptorConverter.convert(typeView);
+
+ assertThat(type.spec().name(), equalTo(typeView.type()));
+
+ if (type instanceof VarlenNativeType) {
+ assertThat(((VarlenNativeType) type).length(),
equalTo(TEST_LENGTH));
+ } else if (type instanceof NumberNativeType) {
+ assertThat(((NumberNativeType) type).precision(),
equalTo(typeView.precision()));
+ } else if (type instanceof DecimalNativeType) {
+ assertThat(((DecimalNativeType) type).precision(),
equalTo(typeView.precision()));
+ assertThat(((DecimalNativeType) type).scale(),
equalTo(typeView.scale()));
+ } else if (type instanceof TemporalNativeType) {
+ assertThat(((TemporalNativeType) type).precision(),
equalTo(typeView.precision()));
+ } else if (type instanceof BitmaskNativeType) {
+ assertThat(((BitmaskNativeType) type).bits(),
equalTo(TEST_LENGTH));
+ } else {
+ assertThat("Unknown type: " + type.getClass(), type.getClass(),
equalTo(NativeType.class));
+ }
+ }
+
+ @ParameterizedTest
+ @MethodSource("generateTestArguments")
+ public void convertColumnViewConstantDefault(DefaultValueArg arg) {
+ String columnName = arg.type.spec().name();
+ ColumnTypeView typeView = TestColumnTypeView.forType(arg.type);
+ ColumnDefaultView defaultValueView = createViewForValue(arg.type,
arg.defaultValue);
+ ColumnView columnView = new TestColumnView(columnName, typeView,
defaultValueView);
+
+ Column column = ConfigurationToSchemaDescriptorConverter.convert(0,
columnView);
+
+ assertThat(column.name(), equalTo(columnName));
+ assertThat(column.type(), equalTo(arg.type));
+ assertThat(column.nullable(), equalTo(arg.defaultValue == null));
+ assertThat(column.defaultValueProvider().type(),
equalTo(Type.CONSTANT));
+ assertThat(column.defaultValue(), equalTo(arg.defaultValue));
+ }
+
+ @Test
+ public void convertColumnViewFunctionalDefault() {
+ String columnName = "UUID";
+ String functionName = DefaultValueGenerators.GEN_RANDOM_UUID;
+ ColumnTypeView typeView =
TestColumnTypeView.forSpec(NativeTypeSpec.UUID);
+ ColumnDefaultView defaultValueView = new
TestFunctionCallDefaultView(functionName);
+ ColumnView columnView = new TestColumnView(columnName, typeView,
defaultValueView);
+
+ Column column = ConfigurationToSchemaDescriptorConverter.convert(0,
columnView);
+
+ assertThat(column.name(), equalTo(columnName));
+ assertThat(column.type(), equalTo(NativeTypes.UUID));
+ assertThat(column.defaultValueProvider().type(),
equalTo(Type.FUNCTIONAL));
+ assertThat(((FunctionalValueProvider)
column.defaultValueProvider()).name(), equalTo(functionName));
+ }
+
+ @Test
+ public void convertTableView(@InjectConfiguration(
+ polymorphicExtensions = {
+ UnknownDataStorageConfigurationSchema.class,
+ NullValueDefaultConfigurationSchema.class,
+ UnlimitedBudgetConfigurationSchema.class
+ },
+ value = "mock {"
+ + "primaryKey {columns=[K1, K2], colocationColumns=[K2]},"
Review Comment:
SchemaValidationUtils#validateIndexes compares that all uniq fields contains
in colocation fields, for test it is ok, but for cleanness - you can 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]