zstan commented on code in PR #5145:
URL: https://github.com/apache/ignite-3/pull/5145#discussion_r1944350505
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/TypeUtils.java:
##########
@@ -733,41 +745,68 @@ public static <RowT> RowT
validateCharactersOverflowAndTrimIfPossible(
for (int i = 0; i < colCount; ++i) {
RelDataType colType = rowType.getFieldList().get(i).getType();
+ SqlTypeName typeName = colType.getSqlTypeName();
Object data = rowHandler.get(i, row);
- // Skip null values and non-character types.
- if (!CHAR_TYPES.contains(colType.getSqlTypeName()) || data ==
null) {
+ if (data == null || (!BINARY_TYPES.contains(typeName) &&
!CHAR_TYPES.contains(typeName))) {
if (rowBldr != null) {
rowBldr.addField(data);
}
continue;
}
- // Otherwise validate and trim if needed.
- assert data instanceof String;
+ int colPrecision = colType.getPrecision();
- String str = (String) data;
+ // Validate and trim if needed.
- int colPrecision = colType.getPrecision();
+ if (BINARY_TYPES.contains(typeName)) {
+ assert data instanceof ByteString;
+ if (typeName == SqlTypeName.VARBINARY &&
colType.getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED) {
+ continue;
+ }
+
+ ByteString byteString = (ByteString) data;
+
+ if (byteString.length() > colPrecision) {
+ for (int pos = byteString.length(); pos > colPrecision;
--pos) {
+ if (byteString.byteAt(pos - 1) != 0) {
+ throw new SqlException(STMT_VALIDATION_ERR, "Value
too long for type: " + colType);
+ }
+ }
- assert colPrecision != RelDataType.PRECISION_NOT_SPECIFIED;
Review Comment:
add this check for both
##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/datatypes/utils/BinaryPair.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.sql.engine.planner.datatypes.utils;
+
+import org.apache.ignite.internal.type.NativeType;
+
+/**
+ * Enumerates possible binary type pairs for test purposes.
+ */
+public enum BinaryPair implements TypePair {
+ VARBINARY1_VARBINARY2(Types.VARBINARY_1, Types.VARBINARY_2),
+ VARBINARY2_VARBINARY1(Types.VARBINARY_2, Types.VARBINARY_1),
+ VARBINARY1_VARBINARY1(Types.VARBINARY_1, Types.VARBINARY_1),
+ VARBINARY_VARBINARY2(Types.VARBINARY, Types.VARBINARY_2);
Review Comment:
done
--
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]