Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.apache.ignite.IgniteException;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;

/**
* Abstract JDBC test.
*/
public abstract class AbstractJdbcTest extends GridCommonAbstractTest {
/** URL. */
protected static final String URL = "jdbc:ignite:thin://127.0.0.1";

/** */
protected void execute(Statement stmt, String sql) {
try {
stmt.execute(sql);
}
catch (SQLException e) {
throw new IgniteException(e.getMessage(), e);
}
}

/** */
protected List<List<Object>> executeQuery(Connection conn, String sql) throws SQLException {
return executeQuery(conn.createStatement(), sql);
}

/** */
protected List<List<Object>> executeQuery(Statement stmt, String sql) {
try (ResultSet rs = stmt.executeQuery(sql)) {
List<List<Object>> res = new ArrayList<>();
while (rs.next()) {
List<Object> row = new ArrayList<>();

for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++)
row.add(rs.getObject(i));

res.add(row);
}

return res;
}
catch (SQLException e) {
throw new IgniteException(e.getMessage(), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,23 @@
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.function.IntConsumer;
import org.apache.ignite.IgniteException;
import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.SqlConfiguration;
import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Test;

/**
* Cross check queries on experimental and non-experimental SQL engines.
*/
public class JdbcCrossEngineTest extends GridCommonAbstractTest {
/** URL. */
private static final String url = "jdbc:ignite:thin://127.0.0.1";

public class JdbcCrossEngineTest extends AbstractJdbcTest {
/** Nodes count. */
private static final int nodesCnt = 3;

Expand Down Expand Up @@ -76,7 +68,7 @@ public class JdbcCrossEngineTest extends GridCommonAbstractTest {
startGrids(nodesCnt);

for (int i = 0; i < engineNames.length; i++) {
conns[i] = DriverManager.getConnection(url + "?queryEngine=" + engineNames[i]);
conns[i] = DriverManager.getConnection(URL + "?queryEngine=" + engineNames[i]);
conns[i].setSchema("PUBLIC");
stmts[i] = conns[i].createStatement();

Expand Down Expand Up @@ -203,36 +195,6 @@ private void checkInsertDefaultValue(String sqlType, String sqlVal, Object expec
);
}

/** */
private void execute(Statement stmt, String sql) {
try {
stmt.execute(sql);
}
catch (SQLException e) {
throw new IgniteException(e.getMessage(), e);
}
}

/** */
private List<List<Object>> executeQuery(Statement stmt, String sql) {
try (ResultSet rs = stmt.executeQuery(sql)) {
List<List<Object>> res = new ArrayList<>();
while (rs.next()) {
List<Object> row = new ArrayList<>();

for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++)
row.add(rs.getObject(i));

res.add(row);
}

return res;
}
catch (SQLException e) {
throw new IgniteException(e.getMessage(), e);
}
}

/** */
private void crossCheck(IntConsumer consumer1, IntConsumer consumer2) {
// Execute consumer1 on indexing engine, consumer2 on calcite engine.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.List;
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.junit.Test;

/** */
public class JdbcLocalFlagTest extends AbstractJdbcTest {
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String instanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(instanceName);

cfg.setSqlConfiguration(new SqlConfiguration()
.setQueryEnginesConfiguration(new CalciteQueryEngineConfiguration().setDefault(true)));

return cfg;
}

/** {@inheritDoc} */
@Override protected void afterTest() {
stopAllGrids();
}

/** */
@Test
public void testLocalFlag() throws Exception {
IgniteEx ignite = startGrids(3);

int keys = 100;

sql(ignite, "CREATE TABLE test(id INT PRIMARY KEY, val VARCHAR)");

for (int i = 0; i < keys; i++)
sql(ignite, "INSERT INTO test(id, val) VALUES (?, ?)", i, "val" + i);

try (Connection conn = DriverManager.getConnection(URL)) {
List<List<Object>> res = executeQuery(conn, "SELECT * FROM test");

assertEquals(keys, res.size());
}

try (Connection conn = DriverManager.getConnection(URL + "?local=true")) {
List<List<Object>> res = executeQuery(conn, "SELECT * FROM test");

assertTrue(keys > res.size());
}
}

/** */
private List<List<?>> sql(IgniteEx ignite, String sql, Object... args) {
return ignite.context().query().querySqlFields(new SqlFieldsQuery(sql).setArgs(args), false).getAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

import org.apache.ignite.internal.processors.query.calcite.exec.LogicalRelImplementorTest;
import org.apache.ignite.internal.processors.query.calcite.exec.NumericTypesPrecisionsTest;
import org.apache.ignite.internal.processors.query.calcite.jdbc.JdbcConnectionEnabledPropertyTest;
import org.apache.ignite.internal.processors.query.calcite.jdbc.JdbcSetClientInfoTest;
import org.apache.ignite.internal.processors.query.calcite.jdbc.JdbcThinTransactionalSelfTest;
import org.apache.ignite.internal.processors.query.calcite.message.CalciteCommunicationMessageSerializationTest;
import org.apache.ignite.internal.processors.query.calcite.sql.SqlCustomParserTest;
import org.apache.ignite.internal.processors.query.calcite.sql.SqlReservedWordsTest;
Expand All @@ -39,6 +36,7 @@
ExecutionTestSuite.class,
IntegrationTestSuite.class,
UtilTestSuite.class,
JdbcTestSuite.class,

SqlCustomParserTest.class,
SqlReservedWordsTest.class,
Expand All @@ -51,10 +49,6 @@

SqlTransactionsIsolationTest.class,
SqlTransactionsUnsupportedModesTest.class,

JdbcThinTransactionalSelfTest.class,
JdbcSetClientInfoTest.class,
JdbcConnectionEnabledPropertyTest.class
})
public class IgniteCalciteTestSuite {
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@
import org.apache.ignite.internal.processors.query.calcite.integration.tpch.TpchScale001Test;
import org.apache.ignite.internal.processors.query.calcite.integration.tpch.TpchScale010Test;
import org.apache.ignite.internal.processors.query.calcite.integration.tpch.TpchScale100Test;
import org.apache.ignite.internal.processors.query.calcite.jdbc.JdbcCrossEngineTest;
import org.apache.ignite.internal.processors.query.calcite.jdbc.JdbcQueryTest;
import org.apache.ignite.internal.processors.query.calcite.rules.JoinCommuteRulesTest;
import org.apache.ignite.internal.processors.query.calcite.rules.JoinOrderOptimizationTest;
import org.apache.ignite.internal.processors.query.calcite.rules.OrToUnionRuleTest;
Expand All @@ -104,8 +102,6 @@
ProjectScanMergeRuleTest.class,
CalciteQueryProcessorTest.class,
CalciteErrorHandlilngIntegrationTest.class,
JdbcQueryTest.class,
JdbcCrossEngineTest.class,
CalciteBasicSecondaryIndexIntegrationTest.class,
CancelTest.class,
DateTimeTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.testsuites;

import org.apache.ignite.internal.processors.query.calcite.jdbc.JdbcConnectionEnabledPropertyTest;
import org.apache.ignite.internal.processors.query.calcite.jdbc.JdbcCrossEngineTest;
import org.apache.ignite.internal.processors.query.calcite.jdbc.JdbcLocalFlagTest;
import org.apache.ignite.internal.processors.query.calcite.jdbc.JdbcQueryTest;
import org.apache.ignite.internal.processors.query.calcite.jdbc.JdbcSetClientInfoTest;
import org.apache.ignite.internal.processors.query.calcite.jdbc.JdbcThinTransactionalSelfTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

/**
* Calcite JDBC tests.
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
JdbcQueryTest.class,
JdbcCrossEngineTest.class,
JdbcThinTransactionalSelfTest.class,
JdbcSetClientInfoTest.class,
JdbcConnectionEnabledPropertyTest.class,
JdbcLocalFlagTest.class,
})
public class JdbcTestSuite {
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
@SuppressWarnings("ThrowableNotThrown")
public class JdbcThinDataSourceSelfTest extends JdbcThinAbstractSelfTest {
/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

Expand Down Expand Up @@ -141,6 +140,10 @@ public void testResetUrl() throws Exception {
assertNull(ids.getSchema());
assertEquals(DFLT_LAZY, ids.isLazy());
assertTrue(ids.isCollocated());

ids.setUrl("jdbc:ignite:thin://127.0.0.1:10800?local=true");

assertTrue(ids.isLocal());
}

/**
Expand All @@ -161,6 +164,7 @@ public void testSqlHints() throws Exception {
assertEquals(DFLT_LAZY, io.connectionProperties().isLazy());
assertFalse(io.connectionProperties().isDistributedJoins());
assertFalse(io.connectionProperties().isReplicatedOnly());
assertFalse(io.connectionProperties().isLocal());
}
}

Expand All @@ -170,6 +174,7 @@ public void testSqlHints() throws Exception {
ids.setLazy(!DFLT_LAZY);
ids.setDistributedJoins(true);
ids.setReplicatedOnly(true);
ids.setLocal(true);

try (Connection conn = ids.getConnection()) {

Expand All @@ -180,6 +185,7 @@ public void testSqlHints() throws Exception {
assertEquals(!DFLT_LAZY, io.connectionProperties().isLazy());
assertTrue(io.connectionProperties().isDistributedJoins());
assertTrue(io.connectionProperties().isReplicatedOnly());
assertTrue(io.connectionProperties().isLocal());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,20 @@ public void setLazy(boolean lazy) {
props.setLazy(lazy);
}

/**
* @return Local query flag.
*/
public boolean isLocal() {
return props.isLocal();
}

/**
* @param loc Local query flag.
*/
public void setLocal(boolean loc) {
props.setLocal(loc);
}

/**
* @return Skip reducer on update flag.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,4 +597,14 @@ public void setPartitionAwarenessPartitionDistributionsCacheSize(
* @param transactionLabel Transaction label.
*/
public void setTransactionLabel(String transactionLabel);

/**
* @return Local flag.
*/
public boolean isLocal();

/**
* @param loc Local flag.
*/
public void setLocal(boolean loc);
}
Loading
Loading