alex-plekhanov commented on code in PR #12285:
URL: https://github.com/apache/ignite/pull/12285#discussion_r2372590997
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java:
##########
@@ -948,11 +948,13 @@ public static QueryClassProperty
buildClassProperty(Class<?> keyCls, Class<?> va
public static GridQueryProperty buildProperty(Class<?> keyCls, Class<?>
valCls, String keyFieldName,
String valueFieldName, String pathStr, Class<?> resType, Map<String,
String> aliases, boolean notNull,
CacheObjectContext coCtx) throws IgniteCheckedException {
+ String alias = aliases.get(pathStr);
+
if (pathStr.equals(keyFieldName))
- return new KeyOrValProperty(true, pathStr, keyCls);
+ return new KeyOrValProperty(true, pathStr, keyCls, alias);
Review Comment:
Looks like the only required change is (for key and val):
`return new KeyOrValProperty(true, alias == null ? pathStr : alias, keyCls);`
Other changes to production code are redundant.
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/cache/QueryEntityValueColumnAliasTest.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.sql.Date;
+import java.util.Collections;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.QueryEntity;
+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.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class QueryEntityValueColumnAliasTest extends GridCommonAbstractTest {
+ /** */
+ private static final String CACHE_NAME = "cache";
+
+ /** */
+ private static final String KEY_COLUMN_NAME = "id";
+
+ /** */
+ private static final String VALUE_COLUMN_NAME = "value";
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String
igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ SqlConfiguration sqlCfg = new SqlConfiguration()
+ .setQueryEnginesConfiguration(new
CalciteQueryEngineConfiguration());
+
+ cfg.setSqlConfiguration(sqlCfg);
+
+ return cfg;
+ }
+
+ /** */
+ @Test
+ public void queryEntityValueColumnAliasTest() throws Exception {
+ try (IgniteEx src = startGrid(0)) {
+ QueryEntity qryEntity = new QueryEntity()
+ .setTableName(CACHE_NAME)
+ .setKeyFieldName(KEY_COLUMN_NAME)
+ .setValueFieldName(VALUE_COLUMN_NAME)
+ .addQueryField(KEY_COLUMN_NAME, Integer.class.getName(), null)
+ .addQueryField(VALUE_COLUMN_NAME, Date.class.getName(), null);
+
+ CacheConfiguration<Integer, Object> ccfg = new
CacheConfiguration<Integer, Object>(qryEntity.getTableName())
+ .setQueryEntities(Collections.singletonList(qryEntity));
+
+ try (IgniteCache<Integer, Object> cache =
src.getOrCreateCache(ccfg)) {
+ long time = System.currentTimeMillis();
+
+ Date date = new Date(time);
+
+ cache.put(1, date);
+
+ assert cache.get(1).equals(date);
Review Comment:
`assertEquals(date, cache.get(1))`
##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java:
##########
@@ -68,12 +68,14 @@ public QueryIndexRowHandler(
for (String propName : keyDefs.keySet()) {
GridQueryProperty prop;
- if (propName.equals(QueryUtils.KEY_FIELD_NAME) ||
propName.equals(type.keyFieldName())
- || propName.equals(type.keyFieldAlias()))
- prop = new KeyOrValPropertyWrapper(true, propName,
type.keyClass());
- else if (propName.equals(QueryUtils.VAL_FIELD_NAME) ||
propName.equals(type.valueFieldName())
- || propName.equals(type.valueFieldAlias()))
- prop = new KeyOrValPropertyWrapper(false, propName,
type.valueClass());
+ if (propName.equals(QueryUtils.KEY_FIELD_NAME))
+ prop = new KeyOrValPropertyWrapper(true, propName,
type.keyClass(), null);
+ else if (propName.equals(type.keyFieldName()) ||
propName.equals(type.keyFieldAlias()))
+ prop = new KeyOrValPropertyWrapper(true, propName,
type.keyClass(), type.keyFieldAlias());
+ else if (propName.equals(QueryUtils.VAL_FIELD_NAME))
+ prop = new KeyOrValPropertyWrapper(false, propName,
type.valueClass(), null);
+ else if (propName.equals(type.valueFieldName()) ||
propName.equals(type.valueFieldAlias()))
+ prop = new KeyOrValPropertyWrapper(false, propName,
type.valueClass(), type.keyFieldAlias());
Review Comment:
Why keyFieldAlias is used for value property?
--
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]