alex-plekhanov commented on code in PR #12911: URL: https://github.com/apache/ignite/pull/12911#discussion_r3028114289
########## modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/sql/JmhCacheWithInterceptorBenchmark.java: ########## @@ -0,0 +1,148 @@ +/* + * 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.benchmarks.jmh.sql; + +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheInterceptorAdapter; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.SqlConfiguration; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; + +/** + * Benchmark cache with interceptor queries. + */ +@Fork(1) +@BenchmarkMode(Mode.Throughput) +@OutputTimeUnit(TimeUnit.SECONDS) +@Warmup(iterations = 5, time = 5) +@Measurement(iterations = 10, time = 5) +@State(Scope.Benchmark) +public class JmhCacheWithInterceptorBenchmark extends JmhSqlAbstractBenchmark { Review Comment: Let's make superclass `cache` variable `protected` and simplify this class to something like: ``` @State(Scope.Benchmark) public class JmhCacheWithInterceptorBenchmark extends JmhSqlAbstractBenchmark { /** Query engine. */ @Param({"CALCITE"}) protected String engine; /** Keep binary mode. */ @Param({"true", "false"}) protected boolean keepBinary; /** {@inheritDoc} */ @Override public void setup() { super.setup(); if (keepBinary) cache = cache.withKeepBinary(); } /** {@inheritDoc} */ @Override protected CacheConfiguration<Integer, Item> cacheConfiguration() { return super.cacheConfiguration().setInterceptor(new CacheInterceptorAdapter<>()); } /** Test update operation. */ @Benchmark public void update() { int key = ThreadLocalRandom.current().nextInt(KEYS_CNT); executeSql("UPDATE CACHE.Item SET fld = fld + 1 WHERE fldIdx=?", key); } /** * Run benchmarks. * * @param args Args. * @throws Exception Exception. */ public static void main(String[] args) throws Exception { final Options options = new OptionsBuilder() .include(JmhCacheWithInterceptorBenchmark.class.getSimpleName()) .build(); new Runner(options).run(); } } ``` ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/CacheWithInterceptorIntegrationTest.java: ########## @@ -0,0 +1,198 @@ +/* + * 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.calcite.integration; + +import java.util.Collection; +import java.util.List; +import javax.cache.Cache; +import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.cache.CacheInterceptorAdapter; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.SqlConfiguration; +import org.apache.ignite.configuration.TransactionConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.transactions.Transaction; +import org.jetbrains.annotations.Nullable; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED; + +/** Cache interceptor related tests. */ +@RunWith(Parameterized.class) +public class CacheWithInterceptorIntegrationTest extends GridCommonAbstractTest { + /** Node role. */ + @Parameterized.Parameter(0) + public boolean keepBinary; + + /** */ + @Parameterized.Parameters(name = "keepBinary={0}") + public static Collection<?> parameters() { + return List.of(true, false); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(true); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + var entity0 = new QueryEntity() + .setTableName("Pure") + .setKeyType(Integer.class.getName()) + .setValueType(String.class.getName()) + .addQueryField("id", Integer.class.getName(), null) + .addQueryField("name", String.class.getName(), null) + .setKeyFieldName("id") + .setValueFieldName("name"); + + var personCfg = new CacheConfiguration<Integer, Object>("person") + .setAtomicityMode(TRANSACTIONAL) + .setSqlSchema("PUBLIC") + .setInterceptor(new TestCacheInterceptor(keepBinary)) + .setQueryEntities(List.of(new QueryEntity(Integer.class, Person.class) + .setTableName("PERSON") + .addQueryField("ID", Integer.class.getName(), null) + .setKeyFieldName("ID") + )); + + var personAtomicCfg = new CacheConfiguration<Integer, Object>("personAtomic") + .setAtomicityMode(ATOMIC) + .setSqlSchema("PUBLIC") + .setInterceptor(new TestCacheInterceptor(keepBinary)) + .setQueryEntities(List.of(new QueryEntity(Integer.class, Person.class) + .setTableName("PERSON_ATOMIC") + .addQueryField("ID", Integer.class.getName(), null) + .setKeyFieldName("ID") + )); + + var cityCfg = new CacheConfiguration<Integer, Object>("city") + .setAtomicityMode(TRANSACTIONAL) + .setSqlSchema("PUBLIC") + .setInterceptor(new TestCacheInterceptor(keepBinary)) + .setQueryEntities(List.of(new QueryEntity(Integer.class, City.class) + .setTableName("CITY") + .addQueryField("ID", Integer.class.getName(), null) + .setKeyFieldName("ID") + )); + + var pureCacheCfg = new CacheConfiguration<Integer, Object>("pure") + .setAtomicityMode(TRANSACTIONAL) + .setSqlSchema("PUBLIC") + .setInterceptor(new TestCacheInterceptor(false)) + .setQueryEntities(List.of(entity0)); + + var calciteQryEngineCfg = new CalciteQueryEngineConfiguration().setDefault(true); + + return super.getConfiguration(igniteInstanceName) + .setSqlConfiguration(new SqlConfiguration().setQueryEnginesConfiguration(calciteQryEngineCfg)) + .setTransactionConfiguration(new TransactionConfiguration().setTxAwareQueriesEnabled(true)) + .setCacheConfiguration(pureCacheCfg, cityCfg, personCfg, personAtomicCfg); + } + + /** Test object unwrapped on interceptor side if applicable. */ + @Test + public void testInterceptorUnwrapValIfNeeded() throws Exception { + startGrid(0); + IgniteEx client = startClientGrid("client"); + + int incParam = 0; + + try (Transaction tx = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) { + client.context().query().querySqlFields(new SqlFieldsQuery("INSERT INTO PUBLIC.PURE(id, name) VALUES (?, 'val')") Review Comment: Let's test not only INSERT, but also UPDATE and DELETE (with onBeforeRemove in intercepter) ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/CacheWithInterceptorIntegrationTest.java: ########## @@ -0,0 +1,198 @@ +/* + * 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.calcite.integration; + +import java.util.Collection; +import java.util.List; +import javax.cache.Cache; +import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.cache.CacheInterceptorAdapter; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.SqlConfiguration; +import org.apache.ignite.configuration.TransactionConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.transactions.Transaction; +import org.jetbrains.annotations.Nullable; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED; + +/** Cache interceptor related tests. */ +@RunWith(Parameterized.class) +public class CacheWithInterceptorIntegrationTest extends GridCommonAbstractTest { + /** Node role. */ + @Parameterized.Parameter(0) + public boolean keepBinary; + + /** */ + @Parameterized.Parameters(name = "keepBinary={0}") + public static Collection<?> parameters() { + return List.of(true, false); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(true); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + var entity0 = new QueryEntity() + .setTableName("Pure") + .setKeyType(Integer.class.getName()) + .setValueType(String.class.getName()) + .addQueryField("id", Integer.class.getName(), null) + .addQueryField("name", String.class.getName(), null) + .setKeyFieldName("id") + .setValueFieldName("name"); + + var personCfg = new CacheConfiguration<Integer, Object>("person") + .setAtomicityMode(TRANSACTIONAL) + .setSqlSchema("PUBLIC") + .setInterceptor(new TestCacheInterceptor(keepBinary)) + .setQueryEntities(List.of(new QueryEntity(Integer.class, Person.class) + .setTableName("PERSON") + .addQueryField("ID", Integer.class.getName(), null) + .setKeyFieldName("ID") + )); + + var personAtomicCfg = new CacheConfiguration<Integer, Object>("personAtomic") + .setAtomicityMode(ATOMIC) + .setSqlSchema("PUBLIC") + .setInterceptor(new TestCacheInterceptor(keepBinary)) + .setQueryEntities(List.of(new QueryEntity(Integer.class, Person.class) + .setTableName("PERSON_ATOMIC") + .addQueryField("ID", Integer.class.getName(), null) + .setKeyFieldName("ID") + )); + + var cityCfg = new CacheConfiguration<Integer, Object>("city") + .setAtomicityMode(TRANSACTIONAL) + .setSqlSchema("PUBLIC") + .setInterceptor(new TestCacheInterceptor(keepBinary)) + .setQueryEntities(List.of(new QueryEntity(Integer.class, City.class) + .setTableName("CITY") + .addQueryField("ID", Integer.class.getName(), null) + .setKeyFieldName("ID") + )); + + var pureCacheCfg = new CacheConfiguration<Integer, Object>("pure") + .setAtomicityMode(TRANSACTIONAL) + .setSqlSchema("PUBLIC") + .setInterceptor(new TestCacheInterceptor(false)) + .setQueryEntities(List.of(entity0)); + + var calciteQryEngineCfg = new CalciteQueryEngineConfiguration().setDefault(true); + + return super.getConfiguration(igniteInstanceName) + .setSqlConfiguration(new SqlConfiguration().setQueryEnginesConfiguration(calciteQryEngineCfg)) + .setTransactionConfiguration(new TransactionConfiguration().setTxAwareQueriesEnabled(true)) + .setCacheConfiguration(pureCacheCfg, cityCfg, personCfg, personAtomicCfg); + } + + /** Test object unwrapped on interceptor side if applicable. */ + @Test + public void testInterceptorUnwrapValIfNeeded() throws Exception { + startGrid(0); + IgniteEx client = startClientGrid("client"); + + int incParam = 0; + + try (Transaction tx = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) { + client.context().query().querySqlFields(new SqlFieldsQuery("INSERT INTO PUBLIC.PURE(id, name) VALUES (?, 'val')") + .setArgs(incParam++), keepBinary).getAll(); + client.context().query().querySqlFields(new SqlFieldsQuery("INSERT INTO PUBLIC.CITY(id, name) VALUES (?, 'val')") + .setArgs(incParam++), keepBinary).getAll(); + client.context().query().querySqlFields(new SqlFieldsQuery("INSERT INTO PUBLIC.PERSON(id, name, city_id) VALUES (?, 'val', 1)") + .setArgs(incParam++), keepBinary).getAll(); + + tx.commit(); + } + + client.context().query().querySqlFields(new SqlFieldsQuery("INSERT INTO PUBLIC.PURE(id, name) VALUES (?, 'val')") + .setArgs(incParam++), keepBinary).getAll(); + client.context().query().querySqlFields(new SqlFieldsQuery("INSERT INTO PUBLIC.CITY(id, name) VALUES (?, 'val')") + .setArgs(incParam++), keepBinary).getAll(); + client.context().query().querySqlFields(new SqlFieldsQuery("INSERT INTO PUBLIC.PERSON(id, name, city_id) VALUES (?, 'val', 1)") + .setArgs(incParam), keepBinary).getAll(); + client.context().query().querySqlFields(new SqlFieldsQuery("INSERT INTO PERSON_ATOMIC(id, name, city_id) VALUES (?, 'val', 1)") + .setArgs(incParam), keepBinary).getAll(); + } + + /** */ + private static class City { + /** */ + @QuerySqlField + String name; + + /** */ + City(String name) { + this.name = name; + } + } + + /** */ + private static class Person { + /** */ + @QuerySqlField + String name; + + /** */ + @QuerySqlField + int city_id; Review Comment: Let's use java style field naming (cityId) and add alias ########## modules/calcite/src/test/java/org/apache/ignite/testsuites/IntegrationTestSuite.java: ########## @@ -174,7 +175,8 @@ QueryEntityValueColumnAliasTest.class, CacheStoreTest.class, MultiDcQueryMappingTest.class, - TxWithExceptionalInterceptorTest.class + TxWithExceptionalInterceptorTest.class, + CacheWithInterceptorIntegrationTest.class Review Comment: Please add comma at the end of line ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/CacheWithInterceptorIntegrationTest.java: ########## @@ -0,0 +1,198 @@ +/* + * 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.calcite.integration; + +import java.util.Collection; +import java.util.List; +import javax.cache.Cache; +import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.cache.CacheInterceptorAdapter; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.SqlConfiguration; +import org.apache.ignite.configuration.TransactionConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.transactions.Transaction; +import org.jetbrains.annotations.Nullable; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED; + +/** Cache interceptor related tests. */ +@RunWith(Parameterized.class) +public class CacheWithInterceptorIntegrationTest extends GridCommonAbstractTest { + /** Node role. */ + @Parameterized.Parameter(0) + public boolean keepBinary; + + /** */ + @Parameterized.Parameters(name = "keepBinary={0}") + public static Collection<?> parameters() { + return List.of(true, false); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(true); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + var entity0 = new QueryEntity() + .setTableName("Pure") + .setKeyType(Integer.class.getName()) + .setValueType(String.class.getName()) + .addQueryField("id", Integer.class.getName(), null) + .addQueryField("name", String.class.getName(), null) + .setKeyFieldName("id") + .setValueFieldName("name"); + Review Comment: Let's also add entity: ``` var entity1 = new QueryEntity() .setTableName("Complex") .setKeyType(Integer.class.getName()) .setValueType("ComplexKey") .addQueryField("id", Integer.class.getName(), null) .addQueryField("name", String.class.getName(), null) .addQueryField("val", Integer.class.getName(), null) .setKeyFieldName("id"); ``` And cache ``` var complexCacheCfg = new CacheConfiguration<Integer, Object>("complex") .setAtomicityMode(TRANSACTIONAL) .setSqlSchema("PUBLIC") .setQueryEntities(List.of(entity1)); ``` Without iterceptor. DML on this cache will fail on interceptor, since there is no such class for deserialization, but without interceptor it should pass until someone add getValue for entry processor in ModifyNode. -- 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]
