use of io.crate.metadata.PartitionName in project crate by crate.
the class PartitionedTableIntegrationTest method testAlterTableResetPartitionedTable.
@Test
public void testAlterTableResetPartitionedTable() throws Exception {
execute("create table quotes (id integer, quote string, date timestamp) " + "partitioned by(date) clustered into 3 shards with (number_of_replicas='1-all')");
ensureYellow();
execute("insert into quotes (id, quote, date) values (?, ?, ?), (?, ?, ?)", new Object[] { 1, "Don't panic", 1395874800000L, 2, "Now panic", 1395961200000L });
assertThat(response.rowCount(), is(2L));
ensureYellow();
refresh();
execute("alter table quotes reset (number_of_replicas)");
ensureYellow();
String templateName = PartitionName.templateName(null, "quotes");
GetIndexTemplatesResponse templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(1));
assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("false"));
List<String> partitions = ImmutableList.of(new PartitionName("quotes", Collections.singletonList(new BytesRef("1395874800000"))).asIndexName(), new PartitionName("quotes", Collections.singletonList(new BytesRef("1395961200000"))).asIndexName());
Thread.sleep(1000);
GetSettingsResponse settingsResponse = client().admin().indices().prepareGetSettings(partitions.get(0), partitions.get(1)).execute().get();
for (String index : partitions) {
assertThat(settingsResponse.getSetting(index, IndexMetaData.SETTING_NUMBER_OF_REPLICAS), is("1"));
assertThat(settingsResponse.getSetting(index, IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("false"));
}
}
use of io.crate.metadata.PartitionName in project crate by crate.
the class WhereClauseAnalyzerTest method testUpdateWherePartitionedByColumn.
@Test
public void testUpdateWherePartitionedByColumn() throws Exception {
UpdateAnalyzedStatement updateAnalyzedStatement = analyzeUpdate("update parted set id = 2 where date = 1395874800000");
UpdateAnalyzedStatement.NestedAnalyzedStatement nestedAnalyzedStatement = updateAnalyzedStatement.nestedStatements().get(0);
assertThat(nestedAnalyzedStatement.whereClause().hasQuery(), is(false));
assertThat(nestedAnalyzedStatement.whereClause().noMatch(), is(false));
assertEquals(ImmutableList.of(new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000"))).asIndexName()), nestedAnalyzedStatement.whereClause().partitions());
}
use of io.crate.metadata.PartitionName in project crate by crate.
the class WhereClauseAnalyzerTest method testSelectFromPartitionedTable.
@Test
public void testSelectFromPartitionedTable() throws Exception {
String partition1 = new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000"))).asIndexName();
String partition2 = new PartitionName("parted", Arrays.asList(new BytesRef("1395961200000"))).asIndexName();
String partition3 = new PartitionName("parted", new ArrayList<BytesRef>() {
{
add(null);
}
}).asIndexName();
WhereClause whereClause = analyzeSelectWhere("select id, name from parted where date = 1395874800000");
assertEquals(ImmutableList.of(partition1), whereClause.partitions());
assertFalse(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where date = 1395874800000 " + "and substr(name, 0, 4) = 'this'");
assertEquals(ImmutableList.of(partition1), whereClause.partitions());
assertThat(whereClause.hasQuery(), is(true));
assertThat(whereClause.noMatch(), is(false));
whereClause = analyzeSelectWhere("select id, name from parted where date >= 1395874800000");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertFalse(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where date < 1395874800000");
assertEquals(ImmutableList.of(), whereClause.partitions());
assertTrue(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where date = 1395874800000 and date = 1395961200000");
assertEquals(ImmutableList.of(), whereClause.partitions());
assertTrue(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where date = 1395874800000 or date = 1395961200000");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertFalse(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where date < 1395874800000 or date > 1395874800000");
assertEquals(ImmutableList.of(partition2), whereClause.partitions());
assertFalse(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where date in (1395874800000, 1395961200000)");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertFalse(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where date in (1395874800000, 1395961200000) and id = 1");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertTrue(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
/**
*
* obj['col'] = 'undefined' => null as col doesn't exist
*
* partition1: not (true and null) -> not (null) -> null -> no match
* partition2: not (false and null) -> not (false) -> true -> match
* partition3: not (null and null) -> not (null) -> null -> no match
*/
whereClause = analyzeSelectWhere("select id, name from parted where not (date = 1395874800000 and obj['col'] = 'undefined')");
assertThat(whereClause.partitions(), containsInAnyOrder(partition2));
assertThat(whereClause.hasQuery(), is(false));
assertThat(whereClause.noMatch(), is(false));
whereClause = analyzeSelectWhere("select id, name from parted where date in (1395874800000) or date in (1395961200000)");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertFalse(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where date = 1395961200000 and id = 1");
assertEquals(ImmutableList.of(partition2), whereClause.partitions());
assertTrue(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where (date =1395874800000 or date = 1395961200000) and id = 1");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertTrue(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where date = 1395874800000 and id is null");
assertEquals(ImmutableList.of(partition1), whereClause.partitions());
assertTrue(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where date is null and id = 1");
assertEquals(ImmutableList.of(partition3), whereClause.partitions());
assertTrue(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where 1395874700000 < date and date < 1395961200001");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertFalse(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
whereClause = analyzeSelectWhere("select id, name from parted where '2014-03-16T22:58:20' < date and date < '2014-03-27T23:00:01'");
assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2));
assertFalse(whereClause.hasQuery());
assertFalse(whereClause.noMatch());
}
use of io.crate.metadata.PartitionName in project crate by crate.
the class WhereClauseAnalyzerTest method testSelectWherePartitionedByColumn.
@Test
public void testSelectWherePartitionedByColumn() throws Exception {
WhereClause whereClause = analyzeSelectWhere("select id from parted where date = 1395874800000");
assertThat(whereClause.hasQuery(), is(false));
assertThat(whereClause.noMatch(), is(false));
assertThat(whereClause.partitions(), Matchers.contains(new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000"))).asIndexName()));
}
use of io.crate.metadata.PartitionName in project crate by crate.
the class WhereClauseAnalyzerTest method registerTables.
private void registerTables(SQLExecutor.Builder builder) {
builder.addDocTable(TestingTableInfo.builder(new TableIdent("doc", "users"), twoNodeRouting).add("id", DataTypes.STRING, null).add("name", DataTypes.STRING, null).add("tags", new ArrayType(DataTypes.STRING), null).addPrimaryKey("id").clusteredBy("id").build());
builder.addDocTable(TestingTableInfo.builder(new TableIdent("doc", "parted"), twoNodeRouting).add("id", DataTypes.INTEGER, null).add("name", DataTypes.STRING, null).add("date", DataTypes.TIMESTAMP, null, true).add("obj", DataTypes.OBJECT, null, ColumnPolicy.IGNORED).addPartitions(new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000"))).asIndexName(), new PartitionName("parted", Arrays.asList(new BytesRef("1395961200000"))).asIndexName(), new PartitionName("parted", new ArrayList<BytesRef>() {
{
add(null);
}
}).asIndexName()).build());
builder.addDocTable(TestingTableInfo.builder(new TableIdent("doc", "parted_pk"), twoNodeRouting).addPrimaryKey("id").addPrimaryKey("date").add("id", DataTypes.INTEGER, null).add("name", DataTypes.STRING, null).add("date", DataTypes.TIMESTAMP, null, true).add("obj", DataTypes.OBJECT, null, ColumnPolicy.IGNORED).addPartitions(new PartitionName("parted_pk", Arrays.asList(new BytesRef("1395874800000"))).asIndexName(), new PartitionName("parted_pk", Arrays.asList(new BytesRef("1395961200000"))).asIndexName(), new PartitionName("parted_pk", new ArrayList<BytesRef>() {
{
add(null);
}
}).asIndexName()).build());
builder.addDocTable(TestingTableInfo.builder(new TableIdent("doc", "bystring"), twoNodeRouting).add("name", DataTypes.STRING, null).add("score", DataTypes.DOUBLE, null).addPrimaryKey("name").clusteredBy("name").build());
builder.addDocTable(TestingTableInfo.builder(new TableIdent("doc", "users_multi_pk"), twoNodeRouting).add("id", DataTypes.LONG, null).add("name", DataTypes.STRING, null).add("details", DataTypes.OBJECT, null).add("awesome", DataTypes.BOOLEAN, null).add("friends", new ArrayType(DataTypes.OBJECT), null, ColumnPolicy.DYNAMIC).addPrimaryKey("id").addPrimaryKey("name").clusteredBy("id").build());
builder.addDocTable(TestingTableInfo.builder(new TableIdent("doc", "pk4"), twoNodeRouting).add("i1", DataTypes.INTEGER, null).add("i2", DataTypes.INTEGER, null).add("i3", DataTypes.INTEGER, null).add("i4", DataTypes.INTEGER, null).addPrimaryKey("i1").addPrimaryKey("i2").addPrimaryKey("i3").addPrimaryKey("i4").build());
builder.addDocTable(TestingTableInfo.builder(new TableIdent("doc", "users_clustered_by_only"), twoNodeRouting).add("id", DataTypes.LONG, null).add("name", DataTypes.STRING, null).add("details", DataTypes.OBJECT, null).add("awesome", DataTypes.BOOLEAN, null).add("friends", new ArrayType(DataTypes.OBJECT), null, ColumnPolicy.DYNAMIC).clusteredBy("id").build());
}
Aggregations