From a7ef6959dfa1429c19b8c61e7119c2281bf716ef Mon Sep 17 00:00:00 2001
From: Sergey Korotkov <serge.korotkov@gmail.com>
Date: Fri, 23 Jun 2023 13:18:58 +0700
Subject: [PATCH] IGNITE-19814 Add calcite test for integer column index
 inlineSize

---
 .../CalciteIntegerIndexInlineSizeTest.java    | 159 ++++++++++++++++++
 1 file changed, 159 insertions(+)
 create mode 100644 modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteIntegerIndexInlineSizeTest.java

diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteIntegerIndexInlineSizeTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteIntegerIndexInlineSizeTest.java
new file mode 100644
index 00000000000..40cd1c7afd7
--- /dev/null
+++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteIntegerIndexInlineSizeTest.java
@@ -0,0 +1,159 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.cache.query.index.Index;
+import org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndex;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/**
+ *
+ */
+@WithSystemProperty(key = "calcite.debug", value = "false")
+@RunWith(Parameterized.class)
+public class CalciteIntegerIndexInlineSizeTest extends GridCommonAbstractTest {
+    /** */
+    private static IgniteEx grid;
+
+    /** */
+    @Parameterized.Parameter
+    public String description;
+
+    /** */
+    @Parameterized.Parameter(1)
+    public String query;
+
+    @Parameterized.Parameters(name = "create with {0}")
+    public static Collection<?> parameters() {
+        List<String[]> params = new ArrayList<>();
+
+        params.add(new String[] {
+            "no key_type, no value_type",
+
+            "CREATE TABLE TEST (id INT, name VARCHAR, PRIMARY KEY(id));"
+        });
+
+        params.add(new String[] {
+            "no key_type, value_type",
+
+            "CREATE TABLE TEST (id INT, name VARCHAR, PRIMARY KEY(id)) " +
+                "WITH \"value_type=org.apache.ignite.internal.processors.query.calcite.Model\";"
+        });
+
+        params.add(new String[] {
+            "key_type, value_type",
+
+            "CREATE TABLE TEST (id INT, name VARCHAR, PRIMARY KEY(id)) " +
+                "WITH \"key_type=Integer,value_type=org.apache.ignite.internal.processors.query.calcite.Model\";"
+        });
+
+        params.add(new String[] {
+            "key_type, no value_type",
+
+            "CREATE TABLE TEST (id INT, name VARCHAR, PRIMARY KEY(id)) " +
+                "WITH \"key_type=Integer\";"
+        });
+
+        return params;
+    }
+
+    /** Tests inlineSize is 5 for index created for INT column. */
+    @Test
+    public void testIntegerIndexInlineSize() {
+        execute(grid, query);
+
+        Collection<Index> indexes = grid.context().indexProcessor().indexes("SQL_PUBLIC_TEST");
+
+        Optional<Integer> inlineSize = indexes.stream().findFirst().map(i -> ((InlineIndex)i).inlineSize());
+
+        assertTrue(inlineSize.isPresent());
+
+        assertEquals(Integer.valueOf(5), inlineSize.get());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setSqlConfiguration(
+                new SqlConfiguration()
+                    .setQueryEnginesConfiguration(
+                        new CalciteQueryEngineConfiguration().setDefault(true)
+                    )
+            );
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws InterruptedException {
+        for (Ignite ign : G.allGrids()) {
+            for (String cacheName : ign.cacheNames())
+                ign.destroyCache(cacheName);
+        }
+
+        awaitPartitionMapExchange();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        grid = startGrids(1);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() {
+        stopAllGrids();
+    }
+
+    /**
+     * Execute SQL statement on given node.
+     *
+     * @param node Node.
+     * @param sql Statement.
+     */
+    private void execute(IgniteEx node, String sql) {
+        node.context().query().querySqlFields(new SqlFieldsQuery(sql), true);
+    }
+
+    /** */
+    public static class Model {
+        /** */
+        public Integer id;
+
+        /** */
+        public String name;
+
+        /** */
+        public Model(Integer id, String name) {
+            this.id = id;
+            this.name = name;
+        }
+    }
+}
-- 
2.34.1

