コード例 #1
0
  @Test
  public void testPartitionedBy() throws Exception {
    CreateTableAnalyzedStatement analysis =
        (CreateTableAnalyzedStatement)
            analyze(
                "create table my_table ("
                    + "  id integer,"
                    + "  no_index string index off,"
                    + "  name string,"
                    + "  date timestamp"
                    + ") partitioned by (name)");
    assertThat(analysis.partitionedBy().size(), is(1));
    assertThat(analysis.partitionedBy().get(0), contains("name", "string"));

    // partitioned columns must be not indexed in mapping
    Map<String, Object> nameMapping =
        (Map<String, Object>) analysis.mappingProperties().get("name");
    assertThat(
        mapToSortedString(nameMapping), is("doc_values=false, index=no, store=false, type=string"));

    Map<String, Object> metaMapping = (Map) analysis.mapping().get("_meta");
    assertThat((Map<String, Object>) metaMapping.get("columns"), not(hasKey("name")));
    List<List<String>> partitionedByMeta = (List<List<String>>) metaMapping.get("partitioned_by");
    assertTrue(analysis.isPartitioned());
    assertThat(partitionedByMeta.size(), is(1));
    assertThat(partitionedByMeta.get(0).get(0), is("name"));
    assertThat(partitionedByMeta.get(0).get(1), is("string"));
  }
コード例 #2
0
  @Test
  public void testPartitionedByNestedColumns() throws Exception {
    CreateTableAnalyzedStatement analysis =
        (CreateTableAnalyzedStatement)
            analyze(
                "create table my_table ("
                    + "  id integer,"
                    + "  no_index string index off,"
                    + "  o object as ("
                    + "    name string"
                    + "  ),"
                    + "  date timestamp"
                    + ") partitioned by (date, o['name'])");
    assertThat(analysis.partitionedBy().size(), is(2));
    Map<String, Object> oMapping = (Map<String, Object>) analysis.mappingProperties().get("o");
    assertThat(
        mapToSortedString(oMapping),
        is(
            "doc_values=false, dynamic=true, index=not_analyzed, properties={"
                + "name={doc_values=false, index=no, store=false, type=string}}, store=false, type=object"));
    assertThat(
        (Map<String, Object>) ((Map) analysis.mapping().get("_meta")).get("columns"),
        not(hasKey("date")));

    Map metaColumns = (Map) ((Map) analysis.mapping().get("_meta")).get("columns");
    assertNull(metaColumns);
    assertThat(analysis.partitionedBy().get(0), contains("date", "date"));
    assertThat(analysis.partitionedBy().get(1), contains("o.name", "string"));
  }
コード例 #3
0
  @Test
  public void testPartitionedByPartOfPrimaryKey() throws Exception {
    CreateTableAnalyzedStatement analysis =
        (CreateTableAnalyzedStatement)
            analyze(
                "create table my_table ("
                    + "  id1 integer,"
                    + "  id2 integer,"
                    + "  date timestamp,"
                    + "  primary key (id1, id2)"
                    + ") partitioned by (id1)");
    assertThat(analysis.partitionedBy().size(), is(1));
    assertThat(analysis.partitionedBy().get(0), contains("id1", "integer"));

    Map<String, Object> oMapping = (Map<String, Object>) analysis.mappingProperties().get("id1");
    assertThat(
        mapToSortedString(oMapping), is("doc_values=false, index=no, store=false, type=integer"));
    assertThat(
        (Map<String, Object>) ((Map) analysis.mapping().get("_meta")).get("columns"),
        not(hasKey("id1")));
  }
コード例 #4
0
 @Test
 public void testPartitionedByMultipleColumns() throws Exception {
   CreateTableAnalyzedStatement analysis =
       (CreateTableAnalyzedStatement)
           analyze(
               "create table my_table ("
                   + "  name string,"
                   + "  date timestamp"
                   + ") partitioned by (name, date)");
   assertThat(analysis.partitionedBy().size(), is(2));
   Map<String, Object> properties = analysis.mappingProperties();
   assertThat(
       mapToSortedString(properties),
       is(
           "date={doc_values=false, index=no, store=false, type=date}, "
               + "name={doc_values=false, index=no, store=false, type=string}"));
   assertThat(
       (Map<String, Object>) ((Map) analysis.mapping().get("_meta")).get("columns"),
       allOf(not(hasKey("name")), not(hasKey("date"))));
   assertThat(analysis.partitionedBy().get(0), contains("name", "string"));
   assertThat(analysis.partitionedBy().get(1), contains("date", "date"));
 }