Example usage for org.apache.lucene.util BytesRef BytesRef

List of usage examples for org.apache.lucene.util BytesRef BytesRef

Introduction

In this page you can find the example usage for org.apache.lucene.util BytesRef BytesRef.

Prototype

public BytesRef(CharSequence text) 

Source Link

Document

Initialize the byte[] from the UTF8 bytes for the provided String.

Usage

From source file:io.crate.analyze.IdTest.java

License:Apache License

@Test
public void testMultiplePrimaryKeyWithClusteredBy() throws Exception {
    String id = generateId(ImmutableList.of(ci("id"), ci("name")),
            ImmutableList.of(new BytesRef("1"), new BytesRef("foo")), ci("name"));
    assertThat(id, is("AgNmb28BMQ=="));
}

From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java

License:Apache License

@Test
public void testInsertWithColumns() throws Exception {
    InsertFromValuesAnalyzedStatement analysis = (InsertFromValuesAnalyzedStatement) analyze(
            "insert into users (id, name) values (1, 'Trillian')");
    assertThat(analysis.tableInfo().ident(), is(TEST_DOC_TABLE_IDENT));
    assertThat(analysis.columns().size(), is(2));

    assertThat(analysis.columns().get(0).info().ident().columnIdent().name(), is("id"));
    assertEquals(DataTypes.LONG, analysis.columns().get(0).valueType());

    assertThat(analysis.columns().get(1).info().ident().columnIdent().name(), is("name"));
    assertEquals(DataTypes.STRING, analysis.columns().get(1).valueType());

    assertThat(analysis.sourceMaps().size(), is(1));
    assertThat(analysis.sourceMaps().get(0).length, is(2));
    assertThat((Long) analysis.sourceMaps().get(0)[0], is(1L));
    assertThat((BytesRef) analysis.sourceMaps().get(0)[1], is(new BytesRef("Trillian")));
}

From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java

License:Apache License

@Test
public void testInsertWithTwistedColumns() throws Exception {
    InsertFromValuesAnalyzedStatement analysis = (InsertFromValuesAnalyzedStatement) analyze(
            "insert into users (name, id) values ('Trillian', 2)");
    assertThat(analysis.tableInfo().ident(), is(TEST_DOC_TABLE_IDENT));
    assertThat(analysis.columns().size(), is(2));

    assertThat(analysis.columns().get(0).info().ident().columnIdent().name(), is("name"));
    assertEquals(DataTypes.STRING, analysis.columns().get(0).valueType());

    assertThat(analysis.columns().get(1).info().ident().columnIdent().name(), is("id"));
    assertEquals(DataTypes.LONG, analysis.columns().get(1).valueType());

    assertThat(analysis.sourceMaps().size(), is(1));
    assertThat(analysis.sourceMaps().get(0).length, is(2));
    assertThat((BytesRef) analysis.sourceMaps().get(0)[0], is(new BytesRef("Trillian")));
    assertThat((Long) analysis.sourceMaps().get(0)[1], is(2L));
}

From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java

License:Apache License

@Test
public void testInsertWithFunction() throws Exception {
    InsertFromValuesAnalyzedStatement analysis = (InsertFromValuesAnalyzedStatement) analyze(
            "insert into users (id, name) values (ABS(-1), 'Trillian')");
    assertThat(analysis.tableInfo().ident(), is(TEST_DOC_TABLE_IDENT));
    assertThat(analysis.columns().size(), is(2));

    assertThat(analysis.columns().get(0).info().ident().columnIdent().name(), is("id"));
    assertEquals(DataTypes.LONG, analysis.columns().get(0).valueType());

    assertThat(analysis.columns().get(1).info().ident().columnIdent().name(), is("name"));
    assertEquals(DataTypes.STRING, analysis.columns().get(1).valueType());

    assertThat(analysis.sourceMaps().size(), is(1));
    assertThat(analysis.sourceMaps().get(0).length, is(2));
    assertThat((Long) analysis.sourceMaps().get(0)[0], is(1L));
    assertThat((BytesRef) analysis.sourceMaps().get(0)[1], is(new BytesRef("Trillian")));
}

From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java

License:Apache License

@Test
public void testInsertWithoutColumns() throws Exception {
    InsertFromValuesAnalyzedStatement analysis = (InsertFromValuesAnalyzedStatement) analyze(
            "insert into users values (1, 1, 'Trillian')");
    assertThat(analysis.tableInfo().ident(), is(TEST_DOC_TABLE_IDENT));
    assertThat(analysis.columns().size(), is(3));

    assertThat(analysis.columns().get(0).info().ident().columnIdent().name(), is("id"));
    assertEquals(DataTypes.LONG, analysis.columns().get(0).valueType());

    assertThat(analysis.columns().get(1).info().ident().columnIdent().name(), is("other_id"));
    assertEquals(DataTypes.LONG, analysis.columns().get(1).valueType());

    assertThat(analysis.columns().get(2).info().ident().columnIdent().name(), is("name"));
    assertEquals(DataTypes.STRING, analysis.columns().get(2).valueType());

    assertThat(analysis.sourceMaps().size(), is(1));
    assertThat(analysis.sourceMaps().get(0).length, is(3));
    assertThat((Long) analysis.sourceMaps().get(0)[0], is(1L));
    assertThat((Long) analysis.sourceMaps().get(0)[1], is(1L));
    assertThat((BytesRef) analysis.sourceMaps().get(0)[2], is(new BytesRef("Trillian")));
}

From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java

License:Apache License

@Test
public void testNestedPk() throws Exception {
    // FYI: insert nested clustered by test here too
    InsertFromValuesAnalyzedStatement analysis = (InsertFromValuesAnalyzedStatement) analyze(
            "insert into nested_pk (id, o) values (?, ?)",
            new Object[] { 1, new MapBuilder<String, Object>().put("b", 4).map() });
    assertThat(analysis.ids().size(), is(1));
    assertThat(analysis.ids().get(0),/*from ww w  . j a va2  s .com*/
            is(generateId(Arrays.asList(new ColumnIdent("id"), new ColumnIdent("o.b")),
                    Arrays.asList(new BytesRef("1"), new BytesRef("4")), new ColumnIdent("o.b"))));
}

From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java

License:Apache License

@Test
public void testNestedPkAllColumns() throws Exception {
    InsertFromValuesAnalyzedStatement analysis = (InsertFromValuesAnalyzedStatement) analyze(
            "insert into nested_pk values (?, ?)",
            new Object[] { 1, new MapBuilder<String, Object>().put("b", 4).map() });
    assertThat(analysis.ids().size(), is(1));
    assertThat(analysis.ids().get(0),//from www  .  ja va2s . c  om
            is(generateId(Arrays.asList(new ColumnIdent("id"), new ColumnIdent("o.b")),
                    Arrays.asList(new BytesRef("1"), new BytesRef("4")), new ColumnIdent("o.b"))));
}

From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java

License:Apache License

@Test
public void testTwistedNestedPk() throws Exception {
    InsertFromValuesAnalyzedStatement analysis = (InsertFromValuesAnalyzedStatement) analyze(
            "insert into nested_pk (o, id) values (?, ?)",
            new Object[] { new MapBuilder<String, Object>().put("b", 4).map(), 1 });
    assertThat(analysis.ids().get(0),//from  ww  w . j a va 2s. c  o  m
            is(generateId(Arrays.asList(new ColumnIdent("id"), new ColumnIdent("o.b")),
                    Arrays.asList(new BytesRef("1"), new BytesRef("4")), new ColumnIdent("o.b"))));

}

From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java

License:Apache License

@Test
public void testInsertMultipleValues() throws Exception {
    InsertFromValuesAnalyzedStatement analysis = (InsertFromValuesAnalyzedStatement) analyze(
            "insert into users (id, name, awesome) values (?, ?, ?), (?, ?, ?)",
            new Object[] { 99, "Marvin", true, 42, "Deep Thought", false });
    assertThat(analysis.sourceMaps().size(), is(2));

    assertThat((Long) analysis.sourceMaps().get(0)[0], is(99L));
    assertThat((BytesRef) analysis.sourceMaps().get(0)[1], is(new BytesRef("Marvin")));
    assertThat((Boolean) analysis.sourceMaps().get(0)[2], is(true));

    assertThat((Long) analysis.sourceMaps().get(1)[0], is(42L));
    assertThat((BytesRef) analysis.sourceMaps().get(1)[1], is(new BytesRef("Deep Thought")));
    assertThat((Boolean) analysis.sourceMaps().get(1)[2], is(false));
}

From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java

License:Apache License

private void validateBulkIndexPartitionedTableAnalysis(InsertFromValuesAnalyzedStatement analysis) {
    assertThat(analysis.generatePartitions(),
            contains(new PartitionName("parted", Arrays.asList(new BytesRef("13963670051500"))).asIndexName(),
                    new PartitionName("parted", Arrays.asList(new BytesRef("0"))).asIndexName(),
                    new PartitionName("parted", new ArrayList<BytesRef>() {
                        {//w w w . j av a2s.  c om
                            add(null);
                        }
                    }).asIndexName()));
    assertThat(analysis.sourceMaps().size(), is(3));

    assertThat((Integer) analysis.sourceMaps().get(0)[0], is(1));
    assertThat((BytesRef) analysis.sourceMaps().get(0)[1], is(new BytesRef("Trillian")));

    assertThat((Integer) analysis.sourceMaps().get(1)[0], is(2));
    assertThat((BytesRef) analysis.sourceMaps().get(1)[1], is(new BytesRef("Ford")));

    assertThat((Integer) analysis.sourceMaps().get(2)[0], is(3));
    assertThat((BytesRef) analysis.sourceMaps().get(2)[1], is(new BytesRef("Zaphod")));

    assertThat(analysis.partitionMaps().size(), is(3));
    assertThat(analysis.partitionMaps().get(0), hasEntry("date", "13963670051500"));
    assertThat(analysis.partitionMaps().get(1), hasEntry("date", "0"));
    assertThat(analysis.partitionMaps().get(2), hasEntry("date", null));

}