Search in sources :

Example 16 with SQLResponse

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

the class SQLTypeMappingTest method testTwoLevelNestedObjectInArray.

@Test
public void testTwoLevelNestedObjectInArray() throws Exception {
    execute("create table assets (\n" + "    categories array(object (dynamic) as (\n" + "       subcategories object (dynamic) as (\n" + "          id int))))");
    execute("insert into assets(categories) values ([{subcategories={id=10}}, {subcategories={id=20}}])");
    ensureYellow();
    execute("refresh table assets");
    refresh();
    waitNoPendingTasksOnAll();
    SQLResponse response = execute("select categories[1]['subcategories']['id'] from assets");
    assertEquals(response.rowCount(), 1L);
    assertThat((Integer) response.rows()[0][0], is(10));
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 17 with SQLResponse

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

the class SQLTypeMappingTest method testInsertNewColumnToObject.

@Test
public void testInsertNewColumnToObject() throws Exception {
    setUpObjectTable();
    Map<String, Object> objectContent = new HashMap<String, Object>() {

        {
            put("new_col", "a string");
            put("another_new_col", "1970-01-01T00:00:00");
        }
    };
    execute("insert into test12 (object_field) values (?)", new Object[] { objectContent });
    refresh();
    SQLResponse response = execute("select object_field from test12");
    assertEquals(1, response.rowCount());
    @SuppressWarnings("unchecked") Map<String, Object> selectedObject = (Map<String, Object>) response.rows()[0][0];
    assertThat((String) selectedObject.get("new_col"), is("a string"));
    assertEquals("1970-01-01T00:00:00", selectedObject.get("another_new_col"));
}
Also used : HashMap(java.util.HashMap) SQLResponse(io.crate.testing.SQLResponse) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 18 with SQLResponse

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

the class SQLTypeMappingTest method testInsertNewObjectColumn.

@Test
public void testInsertNewObjectColumn() throws Exception {
    setUpSimple();
    execute("insert into t1 (id, new_col) values (?,?)", new Object[] { 0, new HashMap<String, Object>() {

        {
            put("a_date", "1970-01-01");
            put("an_int", 127);
            put("a_long", Long.MAX_VALUE);
            put("a_boolean", true);
        }
    } });
    refresh();
    waitForMappingUpdateOnAll("t1", "new_col");
    SQLResponse response = execute("select id, new_col from t1 where id=0");
    @SuppressWarnings("unchecked") Map<String, Object> mapped = (Map<String, Object>) response.rows()[0][1];
    assertEquals("1970-01-01", mapped.get("a_date"));
    assertEquals(127, mapped.get("an_int"));
    assertEquals(0x7fffffffffffffffL, mapped.get("a_long"));
    assertEquals(true, mapped.get("a_boolean"));
}
Also used : SQLResponse(io.crate.testing.SQLResponse) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 19 with SQLResponse

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

the class SQLTypeMappingTest method testGetRequestMapping.

@Test
public void testGetRequestMapping() throws Exception {
    setUpSimple();
    execute("insert into t1 (id, string_field, boolean_field, byte_field, short_field, integer_field," + "long_field, float_field, double_field, object_field," + "timestamp_field, ip_field) values " + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] { 0, "Blabla", true, 120, 1000, 1200000, 120000000000L, 1.4, 3.456789, new HashMap<String, Object>() {

        {
            put("inner", "1970-01-01");
        }
    }, "1970-01-01", "127.0.0.1" });
    refresh();
    SQLResponse getResponse = execute("select * from t1 where id=0");
    SQLResponse searchResponse = execute("select * from t1 limit 1");
    for (int i = 0; i < getResponse.rows()[0].length; i++) {
        assertThat(getResponse.rows()[0][i], is(searchResponse.rows()[0][i]));
    }
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 20 with SQLResponse

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

the class Setup method setUpArrayTables.

public void setUpArrayTables() {
    transportExecutor.exec("create table any_table (" + "  id int primary key," + "  temps array(double)," + "  names array(string)," + "  tags array(string)" + ") with (number_of_replicas=0)");
    transportExecutor.ensureGreen();
    SQLResponse response = transportExecutor.exec("insert into any_table (id, temps, names, tags) values (?,?,?,?), (?,?,?,?), (?,?,?,?), (?,?,?,?)", 1, Arrays.asList(0L, 0L, 0L), Arrays.asList("Dornbirn", "Berlin", "St. Margrethen"), Arrays.asList("cool"), 2, Arrays.asList(0, 1, -1), Arrays.asList("Dornbirn", "Dornbirn", "Dornbirn"), Arrays.asList("cool", null), 3, Arrays.asList(42, -42), Arrays.asList("Hangelsberg", "Berlin"), Arrays.asList("kuhl", "cool"), 4, null, null, Arrays.asList("kuhl", null));
    assertThat(response.rowCount(), is(4L));
    transportExecutor.exec("refresh table any_table");
}
Also used : SQLResponse(io.crate.testing.SQLResponse)

Aggregations

SQLResponse (io.crate.testing.SQLResponse)109 Test (org.junit.Test)78 Map (java.util.Map)13 UseJdbc (io.crate.testing.UseJdbc)10 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)8 PartitionName (io.crate.metadata.PartitionName)4 TestingHelpers.resolveCanonicalString (io.crate.testing.TestingHelpers.resolveCanonicalString)4 Path (java.nio.file.Path)4 BytesRef (org.apache.lucene.util.BytesRef)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 TreeMap (java.util.TreeMap)2 List (java.util.List)1 UUID (java.util.UUID)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ClusterRerouteRequestBuilder (org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder)1 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)1 SearchRequest (org.elasticsearch.action.search.SearchRequest)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1