timoninmaxim commented on a change in pull request #9427:
URL: https://github.com/apache/ignite/pull/9427#discussion_r721989864



##########
File path: 
modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/EnumClassImplementingIndexedInterfaceTest.java
##########
@@ -0,0 +1,249 @@
+/*
+ * 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.cache;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Objects;
+
+import org.apache.ignite.IgniteCache;
+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.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class EnumClassImplementingIndexedInterfaceTest extends 
GridCommonAbstractTest {
+    /** */
+    private static final String PERSON_CACHE = "Person";
+
+    /** */
+    private static IgniteEx ignite;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        ignite = startGrids(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        ignite.destroyCache(PERSON_CACHE);
+    }
+
+    /** */
+    @Test
+    public void testInsertTableVarColumns() {
+        checkCachePutInsert(startSqlPersonCache());
+    }
+
+    /** */
+    @Test
+    public void testInsertValueVarColumns() {
+        checkCachePutInsert(startPersonCache());
+    }
+
+    /** */
+    private void checkCachePutInsert(IgniteCache<Integer, Person> cache) {
+        Arrays.stream(RoleEnum.values()).forEach(role -> {
+            Title title = role.ordinal() % 2 == 0 ? new TitleClass1() : new 
TitleClass2();
+            Person person = new Person(role, title, role.toString());
+
+            cache.put(KEY, person);
+            assertEquals(person, cache.get(KEY));
+
+            cache.clear();
+
+            cache.query(sqlInsertQuery(role, title, role.toString()));
+            assertEquals(person, cache.get(KEY));
+
+            cache.clear();
+
+        });
+    }
+
+    /** */
+    private IgniteCache<Integer, Person> startPersonCache() {
+        return ignite.createCache(new CacheConfiguration<Integer, Person>()
+            .setName(PERSON_CACHE)
+            .setQueryEntities(Collections.singletonList(personQueryEntity())));
+    }
+
+    /** */
+    private IgniteCache<Integer, Person> startSqlPersonCache() {
+        ignite.context().query().querySqlFields(new SqlFieldsQuery(
+            "create table " + PERSON_CACHE + "(" +
+            "   id int PRIMARY KEY," +
+            "   role Object," +
+            "   title Object," +
+            "   desc varchar(5)" +
+            ") with \"CACHE_NAME=" + PERSON_CACHE + ",VALUE_TYPE=" + 
Person.class.getName() + "\""), false);
+
+        return ignite.cache(PERSON_CACHE);
+    }
+
+    /** */
+    private SqlFieldsQuery sqlInsertQuery(Role role, Title title, String 
description) {
+
+        return new SqlFieldsQuery("insert into " + PERSON_CACHE + "(id, role, 
title, desc) values (?, ?, ?, ?)")
+            .setArgs(KEY, role, title, description);
+    }
+
+    /** */
+    private QueryEntity personQueryEntity() {
+        QueryEntity entity = new QueryEntity(Integer.class, Person.class);
+        entity.setKeyFieldName("id");
+        entity.addQueryField("id", Integer.class.getName(), "ID");
+
+        return entity;
+    }
+
+    /** */
+    static interface Role {
+
+    }
+
+    /** */
+    enum RoleEnum implements Role {
+        /** */
+        ROLE1,
+
+        /** */
+        ROLE2,
+
+        /** */
+        ROlE3

Review comment:
       misprint, ROlE3 -> ROLE3

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
##########
@@ -135,6 +136,9 @@
     /** Primary key fields. */
     private Set<String> pkFields;
 
+    /** Logger. */
+    protected final IgniteLogger log;

Review comment:
       This field can be private

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
##########
@@ -721,6 +726,18 @@ else if (F.eq(idxField, valueFieldAlias()) || 
F.eq(idxField, VAL_FIELD_NAME)) {
                 }
                 else if 
(coCtx.kernalContext().cacheObjects().typeId(propType.getName()) !=
                     ((BinaryObject)propVal).type().typeId()) {
+                    // Check for classes/enums implementing indexed interfaces

Review comment:
       Please, format this code with our code guidelines. There are some issues:
   1. Comments should be end with a point
   2. There should be a new line before `try` and `if`
   3. There should not be a braces around single line with `continue`.




-- 
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]


Reply via email to