AMashenkov commented on a change in pull request #123:
URL: https://github.com/apache/ignite-3/pull/123#discussion_r633447084
##########
File path:
modules/schema/src/main/java/org/apache/ignite/internal/schema/NativeType.java
##########
@@ -104,6 +100,107 @@ public NativeTypeSpec spec() {
return typeSpec;
}
+ /**
+ * Return the native type for specified object.
+ *
+ * @return {@code null} for {@code null} value. Otherwise returns
NativeType according to the value's type.
+ */
+ public static NativeType fromObject(Object val) {
+ NativeTypeSpec spec = NativeTypeSpec.fromObject(val);
+
+ if (spec == null)
+ return null;
+
+ switch (spec) {
+ case BYTE:
+ return BYTE;
+
+ case SHORT:
+ return SHORT;
+
+ case INTEGER:
+ return INTEGER;
+
+ case LONG:
+ return LONG;
+
+ case FLOAT:
+ return FLOAT;
+
+ case DOUBLE:
+ return DOUBLE;
+
+ case UUID:
+ return UUID;
+
+ case STRING:
+ return new VarlenNativeType(NativeTypeSpec.STRING,
((CharSequence)val).length());
Review comment:
((CharSequence)val).length() return size in chars, but not bytes.
##########
File path:
modules/schema/src/main/java/org/apache/ignite/internal/schema/Columns.java
##########
@@ -309,6 +310,34 @@ public int columnIndex(String colName) {
throw new NoSuchElementException("No field '" + colName + "' defined");
}
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ Columns columns = (Columns)o;
+
+ return firstVarlenColIdx == columns.firstVarlenColIdx
+ && nullMapSize == columns.nullMapSize
+ && Arrays.equals(cols, columns.cols)
+ && Arrays.equals(foldingTbl, columns.foldingTbl)
+ && Arrays.equals(foldingMask, columns.foldingMask);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ int result = Objects.hash(firstVarlenColIdx, nullMapSize);
+
+ result = 31 * result + Arrays.hashCode(cols);
+ result = 31 * result + Arrays.hashCode(foldingTbl);
+ result = 31 * result + Arrays.hashCode(foldingMask);
Review comment:
```suggestion
int result = Arrays.hashCode(cols);
```
##########
File path:
modules/schema/src/test/java/org/apache/ignite/internal/schema/RowAssemblerTest.java
##########
@@ -243,9 +247,9 @@ public void testFixedNullableKeyFixedNullableValue() {
@Test
public void testFixedNullableKeyVarlenNullableValue() {
Column[] keyCols = new Column[] {new Column("keyIntCol", INTEGER,
true)};
- Column[] valCols = new Column[] {new Column("valStrCol", STRING,
true)};
+ Column[] valCols = new Column[] {new Column("valStrCol",
NativeType.of(ColumnType.string()), true)};
Review comment:
```suggestion
Column[] valCols = new Column[] {new Column("valStrCol",
VarlenNativeType.STRING, true)};
```
##########
File path:
modules/schema/src/test/java/org/apache/ignite/internal/schema/RowAssemblerTest.java
##########
@@ -328,10 +332,10 @@ public void testFixedNullableKeyVarlenValue() {
@Test
public void testVarlenKeyFixedNullableValue() {
- Column[] keyCols = new Column[] {new Column("keyStrCol", STRING,
false)};
+ Column[] keyCols = new Column[] {new Column("keyStrCol",
NativeType.of(ColumnType.string()), false)};
Review comment:
```suggestion
Column[] keyCols = new Column[] {new Column("keyStrCol",
VarlenNativeType.STRING, false)};
```
##########
File path:
modules/api/src/main/java/org/apache/ignite/table/ColumnNotFoundException.java
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.table;
+
+import org.apache.ignite.lang.IgniteException;
+
+/**
+ * Invalid tuple invocation exception is thrown when tuple doesn't match the
table schema.
+ */
+public class ColumnNotFoundException extends IgniteException {
Review comment:
Should ColumnNotFoundException extends InvalidSchemaException instead?
##########
File path:
modules/schema/src/main/java/org/apache/ignite/internal/schema/Columns.java
##########
@@ -309,6 +310,34 @@ public int columnIndex(String colName) {
throw new NoSuchElementException("No field '" + colName + "' defined");
}
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ Columns columns = (Columns)o;
+
+ return firstVarlenColIdx == columns.firstVarlenColIdx
+ && nullMapSize == columns.nullMapSize
+ && Arrays.equals(cols, columns.cols)
+ && Arrays.equals(foldingTbl, columns.foldingTbl)
+ && Arrays.equals(foldingMask, columns.foldingMask);
Review comment:
```suggestion
return Arrays.equals(cols, columns.cols);
```
##########
File path:
modules/schema/src/main/java/org/apache/ignite/internal/schema/VarlenNativeType.java
##########
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+/**
+ * Types with various length (STRING, BYTES).
+ */
+public class VarlenNativeType extends NativeType {
+ /**
+ *
+ */
Review comment:
```suggestion
/** */
```
##########
File path:
modules/schema/src/main/java/org/apache/ignite/internal/schema/VarlenNativeType.java
##########
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+/**
+ * Types with various length (STRING, BYTES).
+ */
+public class VarlenNativeType extends NativeType {
+ /**
+ *
+ */
+ public static final NativeType STRING = new
org.apache.ignite.internal.schema.VarlenNativeType(NativeTypeSpec.STRING, 0);
+
+ /**
+ *
+ */
Review comment:
```suggestion
/** */
```
##########
File path:
modules/schema/src/main/java/org/apache/ignite/internal/schema/NativeType.java
##########
@@ -104,6 +100,107 @@ public NativeTypeSpec spec() {
return typeSpec;
}
+ /**
+ * Return the native type for specified object.
+ *
+ * @return {@code null} for {@code null} value. Otherwise returns
NativeType according to the value's type.
+ */
+ public static NativeType fromObject(Object val) {
+ NativeTypeSpec spec = NativeTypeSpec.fromObject(val);
+
+ if (spec == null)
+ return null;
+
+ switch (spec) {
+ case BYTE:
+ return BYTE;
+
+ case SHORT:
+ return SHORT;
+
+ case INTEGER:
+ return INTEGER;
+
+ case LONG:
+ return LONG;
+
+ case FLOAT:
+ return FLOAT;
+
+ case DOUBLE:
+ return DOUBLE;
+
+ case UUID:
+ return UUID;
+
+ case STRING:
+ return new VarlenNativeType(NativeTypeSpec.STRING,
((CharSequence)val).length());
+
+ case BYTES:
+ return new VarlenNativeType(NativeTypeSpec.BYTES,
((byte[])val).length);
+
+ case BITMASK:
+ return BitmaskNativeType.of(((BitSet)val).length());
+
+ default:
+ assert false : "Unexpected type: " + spec;
+ return null;
+ }
+ }
+
+ /** */
+ public static NativeType of(ColumnType type) {
+ switch (type.typeSpec()) {
+ case INT8:
+ return BYTE;
+
+ case INT16:
+ return SHORT;
+
+ case INT32:
+ return INTEGER;
+
+ case INT64:
+ return LONG;
+
+ case UINT8:
+ case UINT16:
+ case UINT32:
+ case UINT64:
+ throw new UnsupportedOperationException("Unsigned types are
not supported yet.");
+
+ case FLOAT:
+ return FLOAT;
+
+ case DOUBLE:
+ return DOUBLE;
+
+ case DECIMAL:
+ ColumnType.NumericColumnType numType =
(ColumnType.NumericColumnType)type;
+ return new NumericNativeType(numType.precision(),
numType.scale());
+
+ case UUID:
+ return UUID;
+
+ case BITMASK:
+ return new
BitmaskNativeType(((ColumnType.VarLenColumnType)type).length());
+
+ case STRING:
+ return new VarlenNativeType(NativeTypeSpec.STRING,
((ColumnType.VarLenColumnType)type).length());
+
+ case BLOB:
+ return new VarlenNativeType(NativeTypeSpec.BYTES,
((ColumnType.VarLenColumnType)type).length());
+
+ default:
+ throw new InvalidTypeException("Unexpected type " + type);
+ }
+ }
+
+ /** */
+ public boolean mismatch(NativeType type) {
Review comment:
```suggestion
public boolean mismatch(@NotNull NativeType type) {
assert type != null;
```
##########
File path:
modules/schema/src/main/java/org/apache/ignite/internal/schema/RowAssembler.java
##########
@@ -301,7 +302,7 @@ public void appendUuid(UUID uuid) {
* @param val Column value.
*/
public void appendString(String val) {
- checkType(NativeType.STRING);
+ checkType(NativeType.of(ColumnType.stringOf(10)));
Review comment:
Why ColumnType.stringOf(10) ?
##########
File path:
modules/schema/src/test/java/org/apache/ignite/internal/schema/RowAssemblerTest.java
##########
@@ -132,9 +136,9 @@ public void testFixedKeyVarlenNullableValue() {
@Test
public void testFixedKeyVarlenValue() {
Column[] keyCols = new Column[] {new Column("keyShortCol", SHORT,
false)};
- Column[] valCols = new Column[] {new Column("valStrCol", STRING,
false)};
+ Column[] valCols = new Column[] {new Column("valStrCol",
NativeType.of(ColumnType.string()), false)};
Review comment:
```suggestion
Column[] valCols = new Column[] {new Column("valStrCol",
VarlenNativeType.STRING, false)};
```
##########
File path:
modules/schema/src/test/java/org/apache/ignite/internal/schema/RowAssemblerTest.java
##########
@@ -98,9 +102,9 @@ public void testFixedKeyFixedValue() {
@Test
public void testFixedKeyVarlenNullableValue() {
Column[] keyCols = new Column[] {new Column("keyShortCol", SHORT,
false)};
- Column[] valCols = new Column[] {new Column("valStrCol", STRING,
true)};
+ Column[] valCols = new Column[] {new Column("valStrCol",
NativeType.of(ColumnType.string()), true)};
Review comment:
```suggestion
Column[] valCols = new Column[] {new Column("valStrCol",
VarlenNativeType.STRING, true)};
```
##########
File path:
modules/schema/src/test/java/org/apache/ignite/internal/schema/RowAssemblerTest.java
##########
@@ -364,10 +368,10 @@ public void testVarlenKeyFixedNullableValue() {
@Test
public void testVarlenKeyFixedValue() {
- Column[] keyCols = new Column[] {new Column("keyStrCol", STRING,
false)};
+ Column[] keyCols = new Column[] {new Column("keyStrCol",
NativeType.of(ColumnType.string()), false)};
Review comment:
```suggestion
Column[] keyCols = new Column[] {new Column("keyStrCol",
VarlenNativeType.STRING, false)};
```
##########
File path:
modules/schema/src/main/java/org/apache/ignite/internal/schema/Columns.java
##########
@@ -309,6 +310,34 @@ public int columnIndex(String colName) {
throw new NoSuchElementException("No field '" + colName + "' defined");
}
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ Columns columns = (Columns)o;
+
+ return firstVarlenColIdx == columns.firstVarlenColIdx
+ && nullMapSize == columns.nullMapSize
+ && Arrays.equals(cols, columns.cols)
+ && Arrays.equals(foldingTbl, columns.foldingTbl)
+ && Arrays.equals(foldingMask, columns.foldingMask);
Review comment:
Fields that are calculated from Columns can be omited as they hold
cached values for performance reasons.
##########
File path:
modules/table/src/test/java/org/apache/ignite/internal/table/StrictSchemaOperationsTest.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.table;
+
+import org.apache.ignite.internal.schema.Column;
+import org.apache.ignite.internal.schema.InvalidTypeException;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.SchemaDescriptor;
+import org.apache.ignite.internal.table.impl.DummyInternalTableImpl;
+import org.apache.ignite.internal.table.impl.DummySchemaManagerImpl;
+import org.apache.ignite.schema.ColumnType;
+import org.apache.ignite.table.ColumnNotFoundException;
+import org.apache.ignite.table.Table;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * Check data by strict schema.
+ * <p>
+ */
+public class StrictSchemaOperationsTest {
Review comment:
Let's add positive test cases.
Let's add positive test for string of 3 chars with high surrogates (a string
which doesn't fit 3 bytes).
##########
File path:
modules/schema/src/test/java/org/apache/ignite/internal/schema/RowAssemblerTest.java
##########
@@ -391,10 +395,10 @@ public void testVarlenKeyFixedValue() {
@Test
public void testVarlenKeyVarlenNullableValue() {
- Column[] keyCols = new Column[] {new Column("keyStrCol", STRING,
false)};
+ Column[] keyCols = new Column[] {new Column("keyStrCol",
NativeType.of(ColumnType.string()), false)};
Review comment:
```suggestion
Column[] keyCols = new Column[] {new Column("keyStrCol",
VarlenNativeType.STRING, false)};
```
##########
File path:
modules/schema/src/test/java/org/apache/ignite/internal/schema/RowAssemblerTest.java
##########
@@ -295,9 +299,9 @@ public void testFixedNullableKeyVarlenNullableValue() {
@Test
public void testFixedNullableKeyVarlenValue() {
Column[] keyCols = new Column[] {new Column("keyByteCol", BYTE, true)};
- Column[] valCols = new Column[] {new Column("valStrCol", STRING,
false)};
+ Column[] valCols = new Column[] {new Column("valStrCol",
NativeType.of(ColumnType.string()), false)};
Review comment:
```suggestion
Column[] valCols = new Column[] {new Column("valStrCol",
VarlenNativeType.STRING, false)};
```
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]