Search in sources :

Example 6 with UseJdbc

use of io.crate.testing.UseJdbc in project crate by crate.

the class InsertIntoIntegrationTest method testInsertEmptyObjectArray.

@Test
// inserting object array equires special treatment for PostgreSQL
@UseJdbc(0)
public void testInsertEmptyObjectArray() throws Exception {
    execute("create table test (" + "  id integer primary key," + "  details array(object)" + ")");
    ensureYellow();
    execute("insert into test (id, details) values (?, ?)", new Object[] { 1, new Map[0] });
    refresh();
    execute("select id, details from test");
    assertEquals(1, response.rowCount());
    assertEquals(1, response.rows()[0][0]);
    assertThat(response.rows()[0][1], instanceOf(List.class));
    List details = ((List) response.rows()[0][1]);
    assertThat(details.size(), is(0));
}
Also used : List(java.util.List) UseJdbc(io.crate.testing.UseJdbc) Test(org.junit.Test)

Example 7 with UseJdbc

use of io.crate.testing.UseJdbc in project crate by crate.

the class InsertIntoIntegrationTest method testInsertIntoGeoPointArray.

@Test
// inserting geo-point array requires special treatment for PostgreSQL
@UseJdbc(0)
public void testInsertIntoGeoPointArray() throws Exception {
    execute("create table t (id int, points array(geo_point)) clustered into 1 shards with (number_of_replicas=0)");
    ensureYellow();
    execute("insert into t (id, points) values (1, [[1.1, 2.2],[3.3, 4.4]])");
    execute("insert into t (id, points) values (2, ['POINT(5.5 6.6)','POINT(7.7 8.8)'])");
    execute("insert into t (id, points) values (?, ?)", new Object[] { 3, new Double[][] { new Double[] { 9.9, 10.10 }, new Double[] { 11.11, 12.12 } } });
    execute("refresh table t");
    execute("select points from t order by id");
    assertThat(response.rowCount(), is(3L));
    assertThat((List<Object>) response.rows()[0][0], contains(is(new PointImpl(1.1, 2.2, JtsSpatialContext.GEO)), is(new PointImpl(3.3, 4.4, JtsSpatialContext.GEO))));
    assertThat((List<Object>) response.rows()[1][0], contains(is(new PointImpl(5.5, 6.6, JtsSpatialContext.GEO)), is(new PointImpl(7.7, 8.8, JtsSpatialContext.GEO))));
    assertThat((List<Object>) response.rows()[2][0], contains(is(new PointImpl(9.9, 10.10, JtsSpatialContext.GEO)), is(new PointImpl(11.11, 12.12, JtsSpatialContext.GEO))));
}
Also used : PointImpl(org.locationtech.spatial4j.shape.impl.PointImpl) UseJdbc(io.crate.testing.UseJdbc) Test(org.junit.Test)

Example 8 with UseJdbc

use of io.crate.testing.UseJdbc in project crate by crate.

the class TransportSQLActionClassLifecycleTest method testCountWithGroupByNullArgs.

@Test
// NPE because of unused null parameter
@UseJdbc(0)
public void testCountWithGroupByNullArgs() throws Exception {
    new Setup(sqlExecutor).groupBySetup();
    SQLResponse response = execute("select count(*), race from characters group by race", new Object[] { null });
    assertEquals(3, response.rowCount());
}
Also used : SQLResponse(io.crate.testing.SQLResponse) UseJdbc(io.crate.testing.UseJdbc) Test(org.junit.Test)

Example 9 with UseJdbc

use of io.crate.testing.UseJdbc in project crate by crate.

the class TransportSQLActionTest method test_bit_string_can_be_inserted_and_queried.

@Test
@UseJdbc(0)
@UseRandomizedSchema(random = false)
public void test_bit_string_can_be_inserted_and_queried() throws Exception {
    execute("create table tbl (xs bit(4))");
    execute("insert into tbl (xs) values (B'0000'), (B'0001'), (B'0011'), (B'0111'), (B'1111'), (B'1001')");
    assertThat(response.rowCount(), is(6L));
    execute("refresh table tbl");
    execute("SELECT _doc['xs'], xs, _raw, xs::bit(3) FROM tbl WHERE xs = B'1001'");
    assertThat(TestingHelpers.printedTable(response.rows()), is("B'1001'| B'1001'| {\"xs\":\"CQ==\"}| B'100'\n"));
    // use LIMIT 1 to hit a different execution path that should load `xs` differently
    execute("SELECT _doc['xs'], xs, _raw, xs::bit(3) FROM tbl WHERE xs = B'1001' LIMIT 1");
    assertThat(TestingHelpers.printedTable(response.rows()), is("B'1001'| B'1001'| {\"xs\":\"CQ==\"}| B'100'\n"));
    var properties = new Properties();
    properties.put("user", "crate");
    properties.put("password", "");
    ArrayList<String> results = new ArrayList<>();
    try (var conn = DriverManager.getConnection(sqlExecutor.jdbcUrl(), properties)) {
        Statement stmt = conn.createStatement();
        ResultSet result = stmt.executeQuery("select xs from tbl order by xs");
        while (result.next()) {
            String string = result.getString(1);
            results.add(string);
        }
    }
    assertThat(results, Matchers.contains("B'0000'", "B'0001'", "B'0011'", "B'0111'", "B'1001'", "B'1111'"));
}
Also used : Statement(java.sql.Statement) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) Matchers.containsString(org.hamcrest.Matchers.containsString) Properties(java.util.Properties) UseJdbc(io.crate.testing.UseJdbc) Test(org.junit.Test) UseRandomizedSchema(io.crate.testing.UseRandomizedSchema)

Example 10 with UseJdbc

use of io.crate.testing.UseJdbc in project crate by crate.

the class JobLogIntegrationTest method testSetSingleStatement.

@Test
// set has no rowcount
@UseJdbc(0)
public void testSetSingleStatement() throws Exception {
    SQLResponse response = sqlExecutor.exec("select settings['stats']['jobs_log_size'] from sys.cluster");
    assertThat(response.rowCount(), is(1L));
    assertThat((Integer) response.rows()[0][0], is(CrateSettings.STATS_JOBS_LOG_SIZE.defaultValue()));
    response = sqlExecutor.exec("set global persistent stats.enabled= true, stats.jobs_log_size=7");
    assertThat(response.rowCount(), is(1L));
    response = sqlExecutor.exec("select settings['stats']['jobs_log_size'] from sys.cluster");
    assertThat(response.rowCount(), is(1L));
    assertThat((Integer) response.rows()[0][0], is(7));
    response = sqlExecutor.exec("reset global stats.enabled, stats.jobs_log_size");
    assertThat(response.rowCount(), is(1L));
    waitNoPendingTasksOnAll();
    response = sqlExecutor.exec("select settings['stats']['enabled'], settings['stats']['jobs_log_size'] from sys.cluster");
    assertThat(response.rowCount(), is(1L));
    assertThat((Boolean) response.rows()[0][0], is(CrateSettings.STATS_ENABLED.defaultValue()));
    assertThat((Integer) response.rows()[0][1], is(CrateSettings.STATS_JOBS_LOG_SIZE.defaultValue()));
}
Also used : SQLResponse(io.crate.testing.SQLResponse) UseJdbc(io.crate.testing.UseJdbc) Test(org.junit.Test)

Aggregations

UseJdbc (io.crate.testing.UseJdbc)14 Test (org.junit.Test)14 SQLResponse (io.crate.testing.SQLResponse)8 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 List (java.util.List)3 ArrayList (java.util.ArrayList)2 SQLOperations (io.crate.action.sql.SQLOperations)1 Session (io.crate.action.sql.Session)1 JobsLogService (io.crate.execution.engine.collect.stats.JobsLogService)1 JobsLogs (io.crate.execution.engine.collect.stats.JobsLogs)1 JobContextLog (io.crate.expression.reference.sys.job.JobContextLog)1 UseRandomizedSchema (io.crate.testing.UseRandomizedSchema)1 Path (java.nio.file.Path)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Properties (java.util.Properties)1 MockTerminal (org.elasticsearch.cli.MockTerminal)1 ClusterState (org.elasticsearch.cluster.ClusterState)1