List of usage examples for org.apache.lucene.util BytesRef BytesRef
public BytesRef(CharSequence text)
From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java
License:Apache License
@Test public void testInsertNestedPartitionedColumn() throws Exception { InsertFromValuesAnalyzedStatement analysis = (InsertFromValuesAnalyzedStatement) analyze( "insert into nested_parted (id, date, obj)" + "values (?, ?, ?), (?, ?, ?)", new Object[] { 1, "1970-01-01", new MapBuilder<String, Object>().put("name", "Zaphod").map(), 2, "2014-05-21", new MapBuilder<String, Object>().put("name", "Arthur").map() }); assertThat(analysis.generatePartitions(), contains(// ww w .j a v a 2s. co m new PartitionName("nested_parted", Arrays.asList(new BytesRef("0"), new BytesRef("Zaphod"))) .asIndexName(), new PartitionName("nested_parted", Arrays.asList(new BytesRef("1400630400000"), new BytesRef("Arthur"))).asIndexName() )); assertThat(analysis.sourceMaps().size(), is(2)); }
From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java
License:Apache License
@Test public void testInsertWithBulkArgsNullValues() throws Exception { InsertFromValuesAnalyzedStatement analysis; analysis = (InsertFromValuesAnalyzedStatement) analyze("insert into users (id, name) values (?, ?)", new Object[][] { new Object[] { 10, "foo" }, new Object[] { 11, null } }); assertThat(analysis.sourceMaps().size(), is(2)); assertEquals(analysis.sourceMaps().get(0)[1], new BytesRef("foo")); assertEquals(analysis.sourceMaps().get(1)[1], null); }
From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java
License:Apache License
@Test public void testInsertWithBulkArgsNullValuesFirst() throws Exception { InsertFromValuesAnalyzedStatement analysis; analysis = (InsertFromValuesAnalyzedStatement) analyze("insert into users (id, name) values (?, ?)", new Object[][] { new Object[] { 12, null }, new Object[] { 13, "foo" }, }); assertThat(analysis.sourceMaps().size(), is(2)); assertEquals(analysis.sourceMaps().get(0)[1], null); assertEquals(analysis.sourceMaps().get(1)[1], new BytesRef("foo")); }
From source file:io.crate.analyze.InsertFromValuesAnalyzerTest.java
License:Apache License
@Test public void testInsertWithBulkArgsArrayNullValuesFirst() throws Exception { InsertFromValuesAnalyzedStatement analysis; analysis = (InsertFromValuesAnalyzedStatement) analyze("insert into users (id, new_col) values (?, ?)", new Object[][] { new Object[] { 12, new String[] { null } }, new Object[] { 13, new String[] { "foo" } }, }); assertThat(analysis.sourceMaps().size(), is(2)); assertThat((Object[]) analysis.sourceMaps().get(0)[1], arrayContaining((Object) null)); assertThat((Object[]) analysis.sourceMaps().get(1)[1], arrayContaining((Object) new BytesRef("foo"))); }
From source file:io.crate.analyze.MatchOptionsAnalyzedStatementTest.java
License:Apache License
@Test public void testValidOptions() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("analyzer", new BytesRef("english")); options.put("operator", new BytesRef("and")); options.put("fuzziness", 12); // no exception raised MatchOptionsAnalysis.validate(options); }
From source file:io.crate.analyze.MatchOptionsAnalyzedStatementTest.java
License:Apache License
@Test public void testUnknownMatchOptions() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("unknown match option 'analyzer_wrong'"); Map<String, Object> options = new HashMap<>(); options.put("analyzer_wrong", new BytesRef("english")); MatchOptionsAnalysis.validate(options); }
From source file:io.crate.analyze.MatchOptionsAnalyzedStatementTest.java
License:Apache License
@Test public void testInvalidMatchValue() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("invalid value for option 'max_expansions': abc"); Map<String, Object> options = new HashMap<>(); options.put("max_expansions", new BytesRef("abc")); MatchOptionsAnalysis.validate(options); }
From source file:io.crate.analyze.NumberOfReplicas.java
License:Apache License
public static BytesRef fromSettings(Settings settings) { BytesRef numberOfReplicas;//from www. ja v a 2 s. c o m String autoExpandReplicas = settings.get(AUTO_EXPAND_REPLICAS); if (autoExpandReplicas != null && !Booleans.isExplicitFalse(autoExpandReplicas)) { validateExpandReplicaSetting(autoExpandReplicas); numberOfReplicas = new BytesRef(autoExpandReplicas); } else { numberOfReplicas = new BytesRef(MoreObjects.firstNonNull(settings.get(NUMBER_OF_REPLICAS), "1")); } return numberOfReplicas; }
From source file:io.crate.analyze.ParameterContextTest.java
License:Apache License
@Test public void testBulkArgs() throws Exception { Object[][] bulkArgs = new Object[][] { new Object[] { true, 1, "foo", null, new String[] { null } }, new Object[] { false, 2, "bar", new Object[0], new String[] { "foo", "bar" } } }; ParameterContext ctx = new ParameterContext(EMPTY_ARGS, bulkArgs, null); assertTrue(ctx.hasBulkParams());/*from www . jav a 2 s . c o m*/ ctx.setBulkIdx(0); assertThat(ctx.getAsSymbol(0), isLiteral(true)); assertThat(ctx.getAsSymbol(1), isLiteral(1)); assertThat(ctx.getAsSymbol(2), isLiteral("foo")); assertThat(ctx.getAsSymbol(3), isLiteral(null, DataTypes.UNDEFINED)); assertThat(ctx.getAsSymbol(4), isLiteral(new BytesRef[] { null }, new ArrayType(DataTypes.UNDEFINED))); ctx.setBulkIdx(1); assertThat(ctx.getAsSymbol(0), isLiteral(false)); assertThat(ctx.getAsSymbol(1), isLiteral(2)); assertThat(ctx.getAsSymbol(2), isLiteral("bar")); assertThat(ctx.getAsSymbol(3), isLiteral(new Object[0], new ArrayType(DataTypes.UNDEFINED))); assertThat(ctx.getAsSymbol(4), isLiteral(new BytesRef[] { new BytesRef("foo"), new BytesRef("bar") }, new ArrayType(DataTypes.STRING))); }
From source file:io.crate.analyze.RefreshAnalyzerTest.java
License:Apache License
@Test public void testRefreshPartition() throws Exception { PartitionName partition = new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000"))); RefreshTableAnalyzedStatement analysis = (RefreshTableAnalyzedStatement) analyze( "refresh table parted PARTITION (date=1395874800000)"); assertThat(analysis.indexNames(), contains(".partitioned.parted.04732cpp6ks3ed1o60o30c1g")); }