Search in sources :

Example 56 with PartitionName

use of io.crate.metadata.PartitionName in project crate by crate.

the class PartitionedTableIntegrationTest method testDeleteFromPartitionedTableWrongPartitionedColumn.

@Test
public void testDeleteFromPartitionedTableWrongPartitionedColumn() throws Exception {
    this.setup.partitionTableSetup();
    SQLResponse response = execute("select partition_ident from information_schema.table_partitions " + "where table_name='parted' and schema_name='doc'" + "order by partition_ident");
    assertThat(response.rowCount(), is(2L));
    assertThat((String) response.rows()[0][0], is(new PartitionName("parted", ImmutableList.of(new BytesRef("1388534400000"))).ident()));
    assertThat((String) response.rows()[1][0], is(new PartitionName("parted", ImmutableList.of(new BytesRef("1391212800000"))).ident()));
    execute("delete from parted where o['dat'] = '2014-03-01'");
    refresh();
    // Test that no partitions were deleted
    SQLResponse newResponse = execute("select partition_ident from information_schema.table_partitions " + "where table_name='parted' and schema_name='doc'" + "order by partition_ident");
    assertThat(newResponse.rows(), is(response.rows()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) SQLResponse(io.crate.testing.SQLResponse) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Example 57 with PartitionName

use of io.crate.metadata.PartitionName in project crate by crate.

the class PartitionedTableIntegrationTest method testInsertPartitionedTableOnlyPartitionedColumns.

@Test
public void testInsertPartitionedTableOnlyPartitionedColumns() throws Exception {
    execute("create table parted (name string, date timestamp)" + "partitioned by (name, date)");
    ensureYellow();
    execute("insert into parted (name, date) values (?, ?)", new Object[] { "Ford", 13959981214861L });
    assertThat(response.rowCount(), is(1L));
    ensureYellow();
    refresh();
    String partitionName = new PartitionName("parted", Arrays.asList(new BytesRef("Ford"), new BytesRef(String.valueOf(13959981214861L)))).asIndexName();
    assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metaData().indices().get(partitionName).getAliases().get("parted"));
    assertThat(client().prepareSearch(partitionName).setTypes(Constants.DEFAULT_MAPPING_TYPE).setSize(0).setQuery(new MatchAllQueryBuilder()).execute().actionGet().getHits().totalHits(), is(1L));
    execute("select * from parted");
    assertThat(response.rowCount(), is(1L));
    assertThat(response.cols(), arrayContaining("date", "name"));
    assertThat((Long) response.rows()[0][0], is(13959981214861L));
    assertThat((String) response.rows()[0][1], is("Ford"));
}
Also used : PartitionName(io.crate.metadata.PartitionName) BytesRef(org.apache.lucene.util.BytesRef) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) Test(org.junit.Test)

Example 58 with PartitionName

use of io.crate.metadata.PartitionName in project crate by crate.

the class PartitionedTableIntegrationTest method testCopyFromIntoPartitionedTable.

/**
     * Test requires patch in ES 2.1 (https://github.com/crate/elasticsearch/commit/66564f88d21ad3d3be908dbe50974c448f7929d7)
     * or ES 2.x (https://github.com/elastic/elasticsearch/pull/16767).
     * Otherwise the rowCount returned from the copy from statement is ambiguous.
     */
@Test
// no copy rowcount
@UseJdbc(0)
public void testCopyFromIntoPartitionedTable() throws Exception {
    execute("create table quotes (" + "  id integer primary key, " + "  quote string index using fulltext" + ") partitioned by (id)");
    ensureYellow();
    execute("copy quotes from ?", new Object[] { copyFilePath + "test_copy_from.json" });
    assertEquals(3L, response.rowCount());
    refresh();
    ensureYellow();
    for (String id : ImmutableList.of("1", "2", "3")) {
        String partitionName = new PartitionName("quotes", ImmutableList.of(new BytesRef(id))).asIndexName();
        assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metaData().indices().get(partitionName));
        assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metaData().indices().get(partitionName).getAliases().get("quotes"));
    }
    execute("select * from quotes");
    assertEquals(3L, response.rowCount());
    assertThat(response.rows()[0].length, is(2));
}
Also used : PartitionName(io.crate.metadata.PartitionName) BytesRef(org.apache.lucene.util.BytesRef) UseJdbc(io.crate.testing.UseJdbc) Test(org.junit.Test)

Aggregations

PartitionName (io.crate.metadata.PartitionName)58 BytesRef (org.apache.lucene.util.BytesRef)50 Test (org.junit.Test)44 CrateUnitTest (io.crate.test.integration.CrateUnitTest)20 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)10 WhereClause (io.crate.analyze.WhereClause)8 TableIdent (io.crate.metadata.TableIdent)8 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)7 Settings (org.elasticsearch.common.settings.Settings)7 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 GetSettingsResponse (org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse)5 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)5 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)4 SQLResponse (io.crate.testing.SQLResponse)4 Map (java.util.Map)4 Table (io.crate.sql.tree.Table)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3 MetaData (org.elasticsearch.cluster.metadata.MetaData)3