Test fix
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/478fb439 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/478fb439 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/478fb439 Branch: refs/heads/ignite-6022-proto Commit: 478fb439465c55e4bf2e7862cf28a6bcfcd10d96 Parents: 790cd26 Author: Alexander Paschenko <[email protected]> Authored: Fri Dec 15 19:31:18 2017 +0300 Committer: Alexander Paschenko <[email protected]> Committed: Fri Dec 15 19:31:18 2017 +0300 ---------------------------------------------------------------------- .../ignite/jdbc/JdbcErrorsAbstractSelfTest.java | 2 +- .../query/h2/DmlStatementsProcessor.java | 82 +------------------- .../processors/query/h2/dml/DmlUtils.java | 19 +++-- 3 files changed, 16 insertions(+), 87 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/478fb439/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcErrorsAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcErrorsAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcErrorsAbstractSelfTest.java index 952baa5..fb96f31 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcErrorsAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcErrorsAbstractSelfTest.java @@ -107,7 +107,7 @@ public abstract class JdbcErrorsAbstractSelfTest extends GridCommonAbstractTest public void testDmlErrors() throws SQLException { checkErrorState("INSERT INTO \"test\".INTEGER(_key, _val) values(1, null)", "22004"); - checkErrorState("INSERT INTO \"test\".INTEGER(_key, _val) values(1, 'zzz')", "50000"); + checkErrorState("INSERT INTO \"test\".INTEGER(_key, _val) values(1, 'zzz')", "0700B"); } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/478fb439/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java index dd62c75..8de756c 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java @@ -17,16 +17,12 @@ package org.apache.ignite.internal.processors.query.h2; -import java.lang.reflect.Array; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; -import java.sql.Time; -import java.sql.Timestamp; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Date; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -54,6 +50,7 @@ import org.apache.ignite.internal.processors.query.GridQueryFieldsResultAdapter; import org.apache.ignite.internal.processors.query.IgniteSQLException; import org.apache.ignite.internal.processors.query.h2.dml.DmlBatchSender; import org.apache.ignite.internal.processors.query.h2.dml.DmlDistributedPlanInfo; +import org.apache.ignite.internal.processors.query.h2.dml.DmlUtils; import org.apache.ignite.internal.processors.query.h2.dml.FastUpdate; import org.apache.ignite.internal.processors.query.h2.dml.FastUpdateArgument; import org.apache.ignite.internal.processors.query.h2.dml.UpdateMode; @@ -75,12 +72,6 @@ import org.h2.command.dml.Delete; import org.h2.command.dml.Insert; import org.h2.command.dml.Merge; import org.h2.command.dml.Update; -import org.h2.util.DateTimeUtils; -import org.h2.util.LocalDateTimeUtils; -import org.h2.value.Value; -import org.h2.value.ValueDate; -import org.h2.value.ValueTime; -import org.h2.value.ValueTimestamp; import org.jetbrains.annotations.Nullable; import static org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode.createJdbcSqlException; @@ -437,7 +428,7 @@ public class DmlStatementsProcessor { Object colVal = argRow.get(j).apply(args); if (j == plan.keyColumnIndex() || j == plan.valueColumnIndex()) - colVal = convert(colVal, desc, j == plan.keyColumnIndex() ? desc.type().keyClass() : + colVal = DmlUtils.convert(colVal, desc, j == plan.keyColumnIndex() ? desc.type().keyClass() : desc.type().valueClass(), plan.columnTypes()[j]); row.add(colVal); @@ -624,75 +615,6 @@ public class DmlStatementsProcessor { } /** - * Convert value to column's expected type by means of H2. - * - * @param val Source value. - * @param desc Row descriptor. - * @param expCls Expected value class. - * @param type Expected column type to convert to. - * @return Converted object. - * @throws IgniteCheckedException if failed. - */ - @SuppressWarnings({"ConstantConditions", "SuspiciousSystemArraycopy"}) - private static Object convert(Object val, GridH2RowDescriptor desc, Class<?> expCls, int type) - throws IgniteCheckedException { - if (val == null) - return null; - - Class<?> currCls = val.getClass(); - - if (val instanceof Date && currCls != Date.class && expCls == Date.class) { - // H2 thinks that java.util.Date is always a Timestamp, while binary marshaller expects - // precise Date instance. Let's satisfy it. - return new Date(((Date) val).getTime()); - } - - // User-given UUID is always serialized by H2 to byte array, so we have to deserialize manually - if (type == Value.UUID && currCls == byte[].class) - return U.unmarshal(desc.context().marshaller(), (byte[]) val, - U.resolveClassLoader(desc.context().gridConfig())); - - if (LocalDateTimeUtils.isJava8DateApiPresent()) { - if (val instanceof Timestamp && LocalDateTimeUtils.isLocalDateTime(expCls)) - return LocalDateTimeUtils.valueToLocalDateTime(ValueTimestamp.get((Timestamp)val)); - - if (val instanceof Date && LocalDateTimeUtils.isLocalDate(expCls)) - return LocalDateTimeUtils.valueToLocalDate(ValueDate.fromDateValue( - DateTimeUtils.dateValueFromDate(((Date)val).getTime()))); - - if (val instanceof Time && LocalDateTimeUtils.isLocalTime(expCls)) - return LocalDateTimeUtils.valueToLocalTime(ValueTime.get((Time)val)); - } - - // We have to convert arrays of reference types manually - see https://issues.apache.org/jira/browse/IGNITE-4327 - // Still, we only can convert from Object[] to something more precise. - if (type == Value.ARRAY && currCls != expCls) { - if (currCls != Object[].class) - throw new IgniteCheckedException("Unexpected array type - only conversion from Object[] is assumed"); - - // Why would otherwise type be Value.ARRAY? - assert expCls.isArray(); - - Object[] curr = (Object[]) val; - - Object newArr = Array.newInstance(expCls.getComponentType(), curr.length); - - System.arraycopy(curr, 0, newArr, 0, curr.length); - - return newArr; - } - - Object res = H2Utils.convert(val, desc, type); - - if (res instanceof Date && res.getClass() != Date.class && expCls == Date.class) { - // We can get a Timestamp instead of Date when converting a String to Date without query - let's handle this - return new Date(((Date) res).getTime()); - } - - return res; - } - - /** * Execute MERGE statement plan. * @param cursor Cursor to take inserted data from. * @param pageSize Batch size to stream data from {@code cursor}, anything <= 0 for single page operations. http://git-wip-us.apache.org/repos/asf/ignite/blob/478fb439/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java index 6621fc2..8d4861e 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java @@ -17,6 +17,10 @@ package org.apache.ignite.internal.processors.query.h2.dml; +import java.lang.reflect.Array; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Date; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode; import org.apache.ignite.internal.processors.query.IgniteSQLException; @@ -30,11 +34,6 @@ import org.h2.value.ValueDate; import org.h2.value.ValueTime; import org.h2.value.ValueTimestamp; -import java.lang.reflect.Array; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.Date; - /** * DML utility methods. */ @@ -101,7 +100,15 @@ public class DmlUtils { return newArr; } - return H2Utils.convert(val, desc, type); + Object res = H2Utils.convert(val, desc, type); + + if (res instanceof Date && res.getClass() != Date.class && expCls == Date.class) { + // We can get a Timestamp instead of Date when converting a String to Date + // without query - let's handle this + return new Date(((Date) res).getTime()); + } + + return res; } catch (Exception e) { throw new IgniteSQLException("Value conversion failed [from=" + currCls.getName() + ", to=" +
