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));
}
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))));
}
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());
}
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'"));
}
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()));
}
Aggregations