Search in sources :

Example 11 with BytesRef

use of org.apache.lucene.util.BytesRef 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"));
    }
}
Also used : PartitionName(io.crate.metadata.PartitionName) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) Settings(org.elasticsearch.common.settings.Settings) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Example 12 with BytesRef

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

the class ClientMessages method sendBindMessage.

static void sendBindMessage(ChannelBuffer buffer, String portalName, String statementName, List<Object> params) {
    buffer.writeByte('B');
    byte[] portalBytes = portalName.getBytes(StandardCharsets.UTF_8);
    byte[] statementBytes = statementName.getBytes(StandardCharsets.UTF_8);
    int beforeLengthWriterIndex = buffer.writerIndex();
    buffer.writeInt(0);
    writeCString(buffer, portalBytes);
    writeCString(buffer, statementBytes);
    // formatCode use 0 to default to text for all
    buffer.writeShort(0);
    buffer.writeShort(params.size());
    int paramsLength = 0;
    for (Object param : params) {
        BytesRef value = DataTypes.STRING.value(param);
        buffer.writeInt(value.length + 1);
        buffer.writeBytes(value.bytes, value.offset, value.length);
        buffer.writeByte(0);
        paramsLength += 4 + value.length + 1;
    }
    // numResultFormatCodes - 0 to default to text for all
    buffer.writeShort(0);
    buffer.setInt(beforeLengthWriterIndex, 4 + portalBytes.length + 1 + statementBytes.length + 1 + // numFormatCodes
    2 + // numParams
    2 + paramsLength + // numResultColumnFormatCodes
    2);
}
Also used : BytesRef(org.apache.lucene.util.BytesRef)

Example 13 with BytesRef

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

the class BytesRefUtils method setToStringArray.

private static String[] setToStringArray(Set<BytesRef> values) {
    String[] strings = new String[values.size()];
    int idx = 0;
    for (BytesRef value : values) {
        strings[idx] = value == null ? null : value.utf8ToString();
        idx++;
    }
    return strings;
}
Also used : BytesRef(org.apache.lucene.util.BytesRef)

Example 14 with BytesRef

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

the class MatchQueryBuilderTest method testSimpleSingleMatchTwoTerms.

@Test
public void testSimpleSingleMatchTwoTerms() throws Exception {
    Map<String, Object> fields = MapBuilder.<String, Object>newMapBuilder().put("col1", null).map();
    MatchQueryBuilder builder = new MatchQueryBuilder(mockMapperService(), null, Collections.emptyMap());
    Query query = builder.query(fields, new BytesRef("foo bar"));
    assertThat(query, instanceOf(BooleanQuery.class));
}
Also used : MultiPhrasePrefixQuery(org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery) ExtendedCommonTermsQuery(org.apache.lucene.queries.ExtendedCommonTermsQuery) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 15 with BytesRef

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

the class MatchQueryBuilderTest method testTwoFieldsSingleTerm.

@Test
public void testTwoFieldsSingleTerm() throws Exception {
    MatchQueryBuilder builder = new io.crate.lucene.match.MultiMatchQueryBuilder(mockMapperService(), null, Collections.emptyMap());
    Map<String, Object> fields = MapBuilder.<String, Object>newMapBuilder().put("col1", null).put("col2", null).map();
    Query query = builder.query(fields, new BytesRef("foo"));
    assertThat(query, instanceOf(DisjunctionMaxQuery.class));
}
Also used : MultiPhrasePrefixQuery(org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery) ExtendedCommonTermsQuery(org.apache.lucene.queries.ExtendedCommonTermsQuery) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) 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