Search in sources :

Example 21 with BytesRef

use of org.apache.lucene.util.BytesRef in project crate by crate.

the class RefreshAnalyzerTest method testRefreshPartition.

@Test
public void testRefreshPartition() throws Exception {
    PartitionName partition = new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000")));
    RefreshTableAnalyzedStatement analysis = e.analyze("refresh table parted PARTITION (date=1395874800000)");
    assertThat(analysis.indexNames(), contains(".partitioned.parted.04732cpp6ks3ed1o60o30c1g"));
}
Also used : PartitionName(io.crate.metadata.PartitionName) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 22 with BytesRef

use of org.apache.lucene.util.BytesRef in project crate by crate.

the class SnapshotRestoreAnalyzerTest method testRestoreSinglePartition.

@Test
public void testRestoreSinglePartition() throws Exception {
    RestoreSnapshotAnalyzedStatement statement = analyze("RESTORE SNAPSHOT my_repo.my_snapshot TABLE parted PARTITION (date=123)");
    PartitionName partition = new PartitionName("parted", ImmutableList.of(new BytesRef("123")));
    assertThat(statement.restoreTables().size(), is(1));
    assertThat(statement.restoreTables().get(0).partitionName(), is(partition));
    assertThat(statement.restoreTables().get(0).tableIdent(), is(new TableIdent(null, "parted")));
}
Also used : PartitionName(io.crate.metadata.PartitionName) TableIdent(io.crate.metadata.TableIdent) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 23 with BytesRef

use of org.apache.lucene.util.BytesRef in project crate by crate.

the class SnapshotRestoreAnalyzerTest method testRestoreSinglePartitionToUnknownTable.

@Test
public void testRestoreSinglePartitionToUnknownTable() throws Exception {
    RestoreSnapshotAnalyzedStatement statement = analyze("RESTORE SNAPSHOT my_repo.my_snapshot TABLE unknown_parted PARTITION (date=123)");
    PartitionName partitionName = new PartitionName("unknown_parted", ImmutableList.of(new BytesRef("123")));
    assertThat(statement.restoreTables().size(), is(1));
    assertThat(statement.restoreTables().get(0).partitionName(), is(partitionName));
    assertThat(statement.restoreTables().get(0).tableIdent(), is(new TableIdent(null, "unknown_parted")));
}
Also used : PartitionName(io.crate.metadata.PartitionName) TableIdent(io.crate.metadata.TableIdent) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 24 with BytesRef

use of org.apache.lucene.util.BytesRef in project crate by crate.

the class CompoundLiteralTest method testObjectConstruction.

@SuppressWarnings("ConstantConditions")
@Test
public void testObjectConstruction() throws Exception {
    Symbol s = expressions.asSymbol("{}");
    assertThat(s, instanceOf(Literal.class));
    Literal l = (Literal) s;
    assertThat(l.value(), is((Object) new HashMap<String, Object>()));
    Literal objectLiteral = (Literal) expressions.normalize(expressions.asSymbol("{ident='value'}"));
    assertThat(objectLiteral.symbolType(), is(SymbolType.LITERAL));
    assertThat(objectLiteral.valueType(), is((DataType) ObjectType.INSTANCE));
    assertThat(objectLiteral.value(), is((Object) new MapBuilder<String, Object>().put("ident", new BytesRef("value")).map()));
    Literal multipleObjectLiteral = (Literal) expressions.normalize(expressions.asSymbol("{\"Ident\"=123.4, a={}, ident='string'}"));
    Map<String, Object> values = (Map<String, Object>) multipleObjectLiteral.value();
    assertThat(values, is(new MapBuilder<String, Object>().put("Ident", 123.4d).put("a", new HashMap<String, Object>()).put("ident", new BytesRef("string")).map()));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Literal(io.crate.analyze.symbol.Literal) MapBuilder(org.elasticsearch.common.collect.MapBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 25 with BytesRef

use of org.apache.lucene.util.BytesRef in project crate by crate.

the class CompoundLiteralTest method testObjectConstructionWithExpressionsAsValues.

@Test
public void testObjectConstructionWithExpressionsAsValues() throws Exception {
    Literal objectLiteral = (Literal) expressions.normalize(expressions.asSymbol("{name = 1 + 2}"));
    assertThat(objectLiteral.symbolType(), is(SymbolType.LITERAL));
    assertThat(objectLiteral.value(), is(new MapBuilder<String, Object>().put("name", 3L).map()));
    Literal nestedObjectLiteral = (Literal) expressions.normalize(expressions.asSymbol("{a = {name = concat('foo', 'bar')}}"));
    @SuppressWarnings("unchecked") Map<String, Object> values = (Map<String, Object>) nestedObjectLiteral.value();
    assertThat(values, is(new MapBuilder<String, Object>().put("a", new HashMap<String, Object>() {

        {
            put("name", new BytesRef("foobar"));
        }
    }).map()));
}
Also used : HashMap(java.util.HashMap) Literal(io.crate.analyze.symbol.Literal) MapBuilder(org.elasticsearch.common.collect.MapBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

BytesRef (org.apache.lucene.util.BytesRef)1448 Document (org.apache.lucene.document.Document)409 Directory (org.apache.lucene.store.Directory)370 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)266 ArrayList (java.util.ArrayList)186 Test (org.junit.Test)182 SortedDocValuesField (org.apache.lucene.document.SortedDocValuesField)164 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)152 Term (org.apache.lucene.index.Term)123 Analyzer (org.apache.lucene.analysis.Analyzer)121 IndexReader (org.apache.lucene.index.IndexReader)121 TermsEnum (org.apache.lucene.index.TermsEnum)116 SortedSetDocValuesField (org.apache.lucene.document.SortedSetDocValuesField)110 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)105 IOException (java.io.IOException)103 Field (org.apache.lucene.document.Field)101 StringField (org.apache.lucene.document.StringField)100 CrateUnitTest (io.crate.test.integration.CrateUnitTest)95 TextField (org.apache.lucene.document.TextField)94 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)87