Skip to content
Permalink
Browse files
IGNITE-16207 ExpressionFactoryImpl#SCALAR_CACHE usage fix (#649)
  • Loading branch information
vladErmakov07 committed Feb 9, 2022
1 parent 63e53cc commit c4c2636c3e5c66a8b58e94c1a5ad72ddf95dea22
Showing 4 changed files with 99 additions and 6 deletions.
@@ -18,6 +18,7 @@
package org.apache.ignite.internal.runner.app.jdbc;

import java.sql.Statement;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;

@@ -52,4 +53,11 @@ public static void createTable() throws Exception {
s.execute(CREATE_TABLE_SQL);
}
}

@AfterAll
public static void drop() throws Exception {
try (Statement s = conn.createStatement()) {
s.execute("DROP TABLE public.person;");
}
}
}
@@ -37,7 +37,7 @@
/**
* Base class for complex SQL tests based on JDBC driver.
*/
@Disabled("https://issues.apache.org/jira/browse/IGNITE-16207")
@Disabled("https://issues.apache.org/jira/browse/IGNITE-15655")
public class ItJdbcComplexDmlDdlSelfTest extends AbstractJdbcSelfTest {
/** Names of companies to use. */
private static final List<String> COMPANIES = Arrays.asList("ASF", "GNU", "BSD");
@@ -56,10 +56,10 @@ public void testCreateSelectDrop() throws Exception {
"CREATE TABLE person_t (ID int, NAME varchar, AGE int, COMPANY varchar, CITY varchar, "
+ "primary key (ID, NAME, CITY))");

sql(new UpdateChecker(0), "CREATE TABLE city (name varchar, population int, primary key (name))");
sql(new UpdateChecker(0), "CREATE TABLE city_t (name varchar, population int, primary key (name))");

sql(new UpdateChecker(3),
"INSERT INTO city (name, population) values(?, ?), (?, ?), (?, ?)",
"INSERT INTO city_t (name, population) values(?, ?), (?, ?), (?, ?)",
"St. Petersburg", 6000000,
"Boston", 2000000,
"London", 8000000
@@ -105,7 +105,7 @@ public void testCreateSelectDrop() throws Exception {

// Berkeley is not present in City table, although 25 people have it specified as their city.
sql(new ResultChecker(new Object[][] {{75L}}),
"SELECT COUNT(*) from person_t p inner join City c on p.city = c.name");
"SELECT COUNT(*) from person_t p inner join City_t c on p.city = c.name");

sql(new UpdateChecker(34),
"UPDATE person_t SET company = 'New Company', age = CASE WHEN MOD(id, 2) <> 0 THEN age + 5 ELSE "
@@ -134,7 +134,7 @@ public void testCreateSelectDrop() throws Exception {

assertEquals(cnt[0], 34, "Invalid rows count");

sql(new UpdateChecker(0), "DROP TABLE city");
sql(new UpdateChecker(0), "DROP TABLE city_t");
sql(new UpdateChecker(0), "DROP TABLE person_t");
}

@@ -374,7 +374,15 @@ private String digest(List<RexNode> nodes, RelDataType type, boolean biParam) {
b.append(';');
}

b.append(nodes.get(i));
RexNode node = nodes.get(i);

b.append(node);

if (node == null) {
continue;
}

b.append(':').append(node.getType().getFullTypeString());

new RexShuttle() {
@Override public RexNode visitFieldAccess(RexFieldAccess fieldAccess) {
@@ -0,0 +1,77 @@
/*
* 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.sql.engine.exec.exp;

import static org.apache.ignite.internal.sql.engine.util.BaseQueryContext.CALCITE_CONNECTION_CONFIG;
import static org.junit.jupiter.api.Assertions.assertNotSame;

import java.util.Arrays;
import java.util.Collections;
import org.apache.calcite.rel.type.RelDataTypeField;
import org.apache.calcite.rel.type.RelDataTypeFieldImpl;
import org.apache.calcite.rel.type.RelDataTypeSystem;
import org.apache.calcite.rel.type.RelRecordType;
import org.apache.calcite.rex.RexDynamicParam;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.sql.validate.SqlConformanceEnum;
import org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory;
import org.apache.ignite.internal.sql.engine.type.IgniteTypeSystem;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* ExpressionFactoryImpl test.
*/
public class ExpressionFactoryImplTest {
/** Type factory. */
private IgniteTypeFactory typeFactory;

/** Expression factory. */
private ExpressionFactoryImpl<Object[]> expFactory;

@BeforeEach
public void prepare() {
RelDataTypeSystem typeSys = CALCITE_CONNECTION_CONFIG.typeSystem(RelDataTypeSystem.class, IgniteTypeSystem.INSTANCE);

typeFactory = new IgniteTypeFactory(typeSys);

expFactory = new ExpressionFactoryImpl<>(null, typeFactory, SqlConformanceEnum.DEFAULT);
}

@Test
public void testScalarGeneration() {
RelDataTypeField field = new RelDataTypeFieldImpl(
"ID", 0, typeFactory.createSqlType(SqlTypeName.INTEGER)
);
RelRecordType type = new RelRecordType(Collections.singletonList(field));

//Imagine we have 2 columns: (id: INTEGER, val: VARCHAR)
RexDynamicParam firstNode = new RexDynamicParam(typeFactory.createSqlType(SqlTypeName.INTEGER), 0);
RexDynamicParam secondNode = new RexDynamicParam(typeFactory.createSqlType(SqlTypeName.VARCHAR), 1);

SingleScalar scalar1 = expFactory.scalar(Arrays.asList(firstNode, secondNode), type);

//Imagine we have 2 columns: (id: VARCHAR, val: INTEGER)
firstNode = new RexDynamicParam(typeFactory.createSqlType(SqlTypeName.VARCHAR), 0);
secondNode = new RexDynamicParam(typeFactory.createSqlType(SqlTypeName.INTEGER), 1);

SingleScalar scalar2 = expFactory.scalar(Arrays.asList(firstNode, secondNode), type);

assertNotSame(scalar1, scalar2);
}
}

0 comments on commit c4c2636

Please sign in to comment.