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.metadata.PartitionNameTest.java

License:Apache License

@Test
public void testEquals() throws Exception {
    assertTrue(new PartitionName("table", Arrays.asList(new BytesRef("xxx")))
            .equals(new PartitionName("table", Arrays.asList(new BytesRef("xxx")))));
    assertTrue(new PartitionName(null, "table", Arrays.asList(new BytesRef("xxx"))).equals(
            new PartitionName(Schemas.DEFAULT_SCHEMA_NAME, "table", Arrays.asList(new BytesRef("xxx")))));
    assertFalse(new PartitionName("table", Arrays.asList(new BytesRef("xxx")))
            .equals(new PartitionName("schema", "table", Arrays.asList(new BytesRef("xxx")))));
    PartitionName name = new PartitionName(null, "table", Arrays.asList(new BytesRef("xxx")));
    assertTrue(name.equals(PartitionName.fromIndexOrTemplate(name.asIndexName())));
}

From source file:io.crate.metadata.pg_catalog.PgCatalogTables.java

License:Apache License

public static Map<ColumnIdent, RowCollectExpressionFactory> pgTypeExpressions() {
    return ImmutableMap.<ColumnIdent, RowCollectExpressionFactory>builder()
            .put(PgTypeTable.Columns.OID, () -> new RowContextCollectorExpression<PGType, Integer>() {
                @Override//from w  w w.  j a  v a 2s  .  c  o  m
                public Integer value() {
                    return row.oid();
                }
            }).put(PgTypeTable.Columns.TYPNAME, () -> new RowContextCollectorExpression<PGType, BytesRef>() {
                @Override
                public BytesRef value() {
                    return new BytesRef(row.typName());
                }
            }).put(PgTypeTable.Columns.TYPDELIM, () -> new RowContextCollectorExpression<PGType, BytesRef>() {
                @Override
                public BytesRef value() {
                    return new BytesRef(row.typDelim());
                }
            }).put(PgTypeTable.Columns.TYPELEM, () -> new RowContextCollectorExpression<PGType, Integer>() {
                @Override
                public Integer value() {
                    return row.typElem();
                }
            }).build();
}

From source file:io.crate.metadata.settings.CrateSettingsTest.java

License:Apache License

@Test
public void testFlattenSettingsConvertsBytesRef() {
    Settings.Builder builder = Settings.builder();
    CrateSettings.flattenSettings(builder, "dummy", new BytesRef("foo"));
    assertThat(builder.get("dummy"), is("foo"));
}

From source file:io.crate.metadata.shard.blob.BlobShardReferenceResolver.java

License:Apache License

public static ReferenceResolver<ReferenceImplementation<?>> create(BlobShard blobShard) {
    IndexShard indexShard = blobShard.indexShard();
    ShardId shardId = indexShard.shardId();
    HashMap<ReferenceIdent, ReferenceImplementation> implementations = new HashMap<>(15);
    implementations.put(SysShardsTableInfo.ReferenceIdents.ID,
            new LiteralReferenceImplementation<>(shardId.id()));
    implementations.put(SysShardsTableInfo.ReferenceIdents.NUM_DOCS, new BlobShardNumDocsExpression(blobShard));
    implementations.put(SysShardsTableInfo.ReferenceIdents.PRIMARY, new ShardPrimaryExpression(indexShard));
    implementations.put(SysShardsTableInfo.ReferenceIdents.RELOCATING_NODE,
            new ShardRelocatingNodeExpression(indexShard));
    implementations.put(SysShardsTableInfo.ReferenceIdents.SCHEMA_NAME,
            new LiteralReferenceImplementation<>(new BytesRef(BlobSchemaInfo.NAME)));
    implementations.put(SysShardsTableInfo.ReferenceIdents.SIZE, new BlobShardSizeExpression(blobShard));
    implementations.put(SysShardsTableInfo.ReferenceIdents.STATE, new ShardStateExpression(indexShard));
    implementations.put(SysShardsTableInfo.ReferenceIdents.ROUTING_STATE,
            new ShardRoutingStateExpression(indexShard));
    implementations.put(SysShardsTableInfo.ReferenceIdents.TABLE_NAME,
            new BlobShardTableNameExpression(shardId));
    implementations.put(SysShardsTableInfo.ReferenceIdents.PARTITION_IDENT,
            new LiteralReferenceImplementation<>(new BytesRef("")));
    implementations.put(SysShardsTableInfo.ReferenceIdents.ORPHAN_PARTITION,
            new LiteralReferenceImplementation<>(false));
    implementations.put(SysShardsTableInfo.ReferenceIdents.PATH, new ShardPathExpression(indexShard));
    implementations.put(SysShardsTableInfo.ReferenceIdents.BLOB_PATH,
            new BlobShardBlobPathExpression(blobShard));
    implementations.put(SysShardsTableInfo.ReferenceIdents.MIN_LUCENE_VERSION,
            new ShardMinLuceneVersionExpression(indexShard));
    implementations.put(SysShardsTableInfo.ReferenceIdents.RECOVERY, new ShardRecoveryExpression(indexShard));
    return new MapBackedRefResolver(implementations);
}

From source file:io.crate.metadata.shard.NodeNestableInput.java

License:Apache License

public NodeNestableInput(DiscoveryNode localNode) {
    BytesRef nodeId = new BytesRef(localNode.getId());
    BytesRef nodeName = new BytesRef(localNode.getName());
    this.nodeIdInput = new LiteralNestableInput<>(nodeId);
    this.nodeNameInput = new LiteralNestableInput<>(nodeName);
    this.value = ImmutableMap.of("id", nodeId, "name", nodeName);
}

From source file:io.crate.metadata.shard.ShardReferenceResolver.java

License:Apache License

public static ReferenceResolver<NestableInput<?>> create(ClusterService clusterService, Schemas schemas,
        IndexShard indexShard) {/*from w  ww .j  a  va2s. c o  m*/
    ShardId shardId = indexShard.shardId();
    Index index = shardId.getIndex();

    ImmutableMap.Builder<ReferenceIdent, NestableInput> builder = ImmutableMap.builder();
    if (IndexParts.isPartitioned(index.getName())) {
        addPartitions(index, schemas, builder);
    }
    IndexParts indexParts = new IndexParts(index.getName());
    builder.put(SysShardsTableInfo.ReferenceIdents.ID, new LiteralNestableInput<>(shardId.getId()));
    builder.put(SysShardsTableInfo.ReferenceIdents.SIZE, new ShardSizeExpression(indexShard));
    builder.put(SysShardsTableInfo.ReferenceIdents.NUM_DOCS, new ShardNumDocsExpression(indexShard));
    builder.put(SysShardsTableInfo.ReferenceIdents.PRIMARY, new ShardPrimaryExpression(indexShard));
    builder.put(SysShardsTableInfo.ReferenceIdents.RELOCATING_NODE,
            new ShardRelocatingNodeExpression(indexShard));
    builder.put(SysShardsTableInfo.ReferenceIdents.SCHEMA_NAME,
            new LiteralNestableInput<>(new BytesRef(indexParts.getSchema())));
    builder.put(SysShardsTableInfo.ReferenceIdents.STATE, new ShardStateExpression(indexShard));
    builder.put(SysShardsTableInfo.ReferenceIdents.ROUTING_STATE, new ShardRoutingStateExpression(indexShard));
    builder.put(SysShardsTableInfo.ReferenceIdents.TABLE_NAME,
            new LiteralNestableInput<>(new BytesRef(indexParts.getTable())));
    builder.put(SysShardsTableInfo.ReferenceIdents.PARTITION_IDENT, new ShardPartitionIdentExpression(shardId));
    builder.put(SysShardsTableInfo.ReferenceIdents.ORPHAN_PARTITION,
            new ShardPartitionOrphanedExpression(shardId, clusterService));
    builder.put(SysShardsTableInfo.ReferenceIdents.PATH, new ShardPathExpression(indexShard));
    builder.put(SysShardsTableInfo.ReferenceIdents.BLOB_PATH, new LiteralNestableInput<>(null));
    builder.put(SysShardsTableInfo.ReferenceIdents.MIN_LUCENE_VERSION,
            new ShardMinLuceneVersionExpression(indexShard));
    builder.put(SysShardsTableInfo.ReferenceIdents.RECOVERY, new ShardRecoveryExpression(indexShard));
    builder.put(SysShardsTableInfo.ReferenceIdents.NODE, new NodeNestableInput(clusterService.localNode()));
    return new MapBackedRefResolver(builder.build());
}

From source file:io.crate.metadata.sys.SysOperationsTableInfo.java

License:Apache License

public static Map<ColumnIdent, RowCollectExpressionFactory<OperationContext>> expressions(
        Supplier<DiscoveryNode> localNode) {
    return ImmutableMap.<ColumnIdent, RowCollectExpressionFactory<OperationContext>>builder()
            .put(SysOperationsTableInfo.Columns.ID,
                    () -> RowContextCollectorExpression.objToBytesRef(OperationContext::id))
            .put(SysOperationsTableInfo.Columns.JOB_ID,
                    () -> RowContextCollectorExpression.objToBytesRef(OperationContext::jobId))
            .put(SysOperationsTableInfo.Columns.NAME,
                    () -> RowContextCollectorExpression.objToBytesRef(OperationContext::name))
            .put(SysOperationsTableInfo.Columns.STARTED,
                    () -> RowContextCollectorExpression.forFunction(OperationContext::started))
            .put(SysOperationsTableInfo.Columns.USED_BYTES,
                    () -> RowContextCollectorExpression.forFunction(r -> {
                        if (r.usedBytes == 0) {
                            return null;
                        }//from   w w w. ja v  a 2 s.  c  om
                        return r.usedBytes;
                    }))
            .put(Columns.NODE, () -> RowContextCollectorExpression.forFunction(ignored -> ImmutableMap.of("id",
                    new BytesRef(localNode.get().getId()), "name", new BytesRef(localNode.get().getName()))))
            .put(Columns.NODE_ID,
                    () -> RowContextCollectorExpression
                            .forFunction(ignored -> new BytesRef(localNode.get().getId())))
            .put(Columns.NODE_NAME, () -> RowContextCollectorExpression
                    .forFunction(ignored -> new BytesRef(localNode.get().getName())))
            .build();
}

From source file:io.crate.metadata.sys.SysUsersTableInfo.java

public static Map<ColumnIdent, RowCollectExpressionFactory<User>> sysUsersExpressions() {
    return ImmutableMap.<ColumnIdent, RowCollectExpressionFactory<User>>builder()
            .put(Columns.NAME, () -> new RowContextCollectorExpression<User, BytesRef>() {
                @Override//  w  w w  .java2s.  c  o m
                public BytesRef value() {
                    return new BytesRef(row.name());
                }
            }).put(Columns.SUPERUSER, () -> new RowContextCollectorExpression<User, Boolean>() {
                @Override
                public Boolean value() {
                    return row.isSuperUser();
                }
            }).put(Columns.PASSWORD, () -> new RowContextCollectorExpression<User, BytesRef>() {
                @Override
                public BytesRef value() {
                    return row.password() != null ? PASSWORD_PLACEHOLDER : null;
                }
            }).build();
}

From source file:io.crate.metadata.sys.TableHealthService.java

License:Apache License

private Iterable<TableHealth> allAsUnavailable() {
    return StreamSupport.stream(schemas.spliterator(), false)
            .flatMap(schemaInfo -> StreamSupport.stream(schemaInfo.spliterator(), false)).flatMap(tableInfo -> {
                if (tableInfo instanceof DocTableInfo) {
                    return healthFromPartitions(tableInfo.ident(),
                            ((DocTableInfo) tableInfo).partitions().stream());
                }/*from w ww.  j  a  v  a2s  . com*/
                TableIdent ident = tableInfo.ident();
                TableHealth tableHealth = new TableHealth(new BytesRef(ident.name()),
                        new BytesRef(ident.schema()), null, TableHealth.Health.RED, -1, -1);
                return Stream.of(tableHealth);
            })::iterator;
}

From source file:io.crate.metadata.sys.TableHealthService.java

License:Apache License

private static Stream<TableHealth> healthFromPartitions(TableIdent table, Stream<PartitionName> partitions) {
    BytesRef tableName = new BytesRef(table.name());
    BytesRef tableSchema = new BytesRef(table.schema());
    return partitions.map(pn -> new TableHealth(tableName, tableSchema, new BytesRef(pn.ident()),
            TableHealth.Health.RED, -1, -1));
}