This is an automated email from the ASF dual-hosted git repository. tledkov pushed a commit to branch ignite-13200 in repository https://gitbox.apache.org/repos/asf/ignite.git
commit defad586e655221d1086ee7d2c568c1a737b0ee6 Author: tledkov <tled...@gridgain.com> AuthorDate: Wed Jul 1 19:27:38 2020 +0300 IGNITE-13198 add test and fix prototype --- .../processors/query/h2/CommandProcessor.java | 5 + .../query/CreateIndexOnInvalidDataTypeTest.java | 133 +++++++++++++++++++++ 2 files changed, 138 insertions(+) diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/CommandProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/CommandProcessor.java index de106eb..9e70cc0 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/CommandProcessor.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/CommandProcessor.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.processors.query.h2; +import java.sql.Date; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -1198,6 +1199,10 @@ public class CommandProcessor { if (!handleUuidAsByte) return UUID.class.getName(); + case Value.DATE: + // "java.util.Date"; + return java.util.Date.class.getName(); + default: return DataType.getTypeClassName(type); } diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/CreateIndexOnInvalidDataTypeTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/CreateIndexOnInvalidDataTypeTest.java new file mode 100644 index 0000000..6e5d972 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/CreateIndexOnInvalidDataTypeTest.java @@ -0,0 +1,133 @@ +/* + * 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; + +import java.util.Collections; +import java.util.Date; +import java.util.List; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.FieldsQueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.failure.StopNodeFailureHandler; +import org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest; +import org.junit.Test; + +/** + * Tests for local query execution in lazy mode. + */ +public class CreateIndexOnInvalidDataTypeTest extends AbstractIndexingCommonTest { + /** Keys count. */ + private static final int KEY_CNT = 10; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setFailureHandler(new StopNodeFailureHandler()) + .setDataStorageConfiguration(new DataStorageConfiguration() + .setDefaultDataRegionConfiguration(new DataRegionConfiguration() + .setPersistenceEnabled(true) + ) + ); + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + cleanPersistenceDir(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + super.afterTest(); + } + + /** + * + */ + @Test + public void testCreateIndexOnInvalidData() throws Exception { + startGrid(); + + grid().cluster().state(ClusterState.ACTIVE); + + IgniteCache<Integer, Value> c = grid().createCache(new CacheConfiguration<Integer, Value>() + .setName("test") + .setSqlSchema("PUBLIC") + .setQueryEntities(Collections.singleton(new QueryEntity(Integer.class, Value.class) + .setTableName("TEST") + ) + ) + .setBackups(1) + .setAffinity(new RendezvousAffinityFunction(false, 10))); + + for (int i = 0; i < KEY_CNT; ++i) + c.put(i, new Value(i)); + + sql("ALTER TABLE TEST ADD COLUMN (VAL_DATE DATE)"); + + List<List<?>> res = sql("SELECT * FROM TEST").getAll(); + + sql("CREATE INDEX TEST_VAL_DATE_IDX ON TEST(VAL_DATE)"); + } + + /** + * @param sql SQL query. + * @param args Query parameters. + * @return Results cursor. + */ + private FieldsQueryCursor<List<?>> sql(String sql, Object... args) { + return grid().context().query().querySqlFields(new SqlFieldsQuery(sql) + .setLazy(true) + .setArgs(args), false); + } + + /** + * + */ + private static class Value { + /** + * + */ + @QuerySqlField + int val_int; + + /** + * + */ + java.util.Date val_date; + + /** + * @param val Test value. + */ + public Value(int val) { + this.val_int = val; + val_date = new Date(val); + } + } +}