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.operation.reference.doc.lucene.IpColumnReference.java

License:Apache License

@Override
public BytesRef value() {
    switch (values.count()) {
    case 0:/*  ww w  . ja  v  a  2s . co m*/
        return null;
    case 1:
        return new BytesRef(IpFieldMapper.longToIp(values.valueAt(0)));
    default:
        throw new GroupByOnArrayUnsupportedException(columnName());
    }
}

From source file:io.crate.operation.reference.doc.lucene.LegacyIPColumnReference.java

License:Apache License

@Override
public void setNextDocId(int docId) {
    super.setNextDocId(docId);
    values.setDocument(docId);//  ww w  .ja  va2  s .  c  o m
    switch (values.count()) {
    case 0:
        value = null;
        break;
    case 1:
        value = new BytesRef(LegacyIpFieldMapper.longToIp(values.valueAt(0)));
        break;
    default:
        throw new GroupByOnArrayUnsupportedException(columnName);
    }
}

From source file:io.crate.operation.reference.file.ColumnExtractingLineExpression.java

License:Apache License

@Override
public Object value() {
    Object value = context.get(columnIdent);
    if (!columnIdent.equals(DocSysColumns.RAW) && value instanceof String) {
        return new BytesRef((String) value);
    }//w ww .j  a  v  a2s.  co m
    return value;
}

From source file:io.crate.operation.reference.information.InformationSchemaExpressionFactories.java

License:Apache License

public static Map<ColumnIdent, RowCollectExpressionFactory> tablesFactories() {
    return ImmutableMap.<ColumnIdent, RowCollectExpressionFactory>builder()
            .put(InformationTablesTableInfo.Columns.SCHEMA_NAME, new RowCollectExpressionFactory() {

                @Override//w w w  . j  a va2  s  .c  om
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<TableInfo, BytesRef>() {

                        @Override
                        public BytesRef value() {
                            return new BytesRef(row.ident().schema());
                        }
                    };
                }
            }).put(InformationTablesTableInfo.Columns.TABLE_NAME, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<TableInfo, BytesRef>() {

                        @Override
                        public BytesRef value() {
                            return new BytesRef(row.ident().name());
                        }
                    };
                }
            }).put(InformationTablesTableInfo.Columns.NUMBER_OF_SHARDS, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<TableInfo, Integer>() {

                        @Override
                        public Integer value() {
                            if (row instanceof ShardedTable) {
                                return ((ShardedTable) row).numberOfShards();
                            }
                            return 1;
                        }
                    };
                }
            }).put(InformationTablesTableInfo.Columns.NUMBER_OF_REPLICAS, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<TableInfo, BytesRef>() {
                        private final BytesRef ZERO_REPLICAS = new BytesRef("0");

                        @Override
                        public BytesRef value() {
                            if (row instanceof ShardedTable) {
                                return ((ShardedTable) row).numberOfReplicas();
                            }
                            return ZERO_REPLICAS;
                        }
                    };
                }
            }).put(InformationTablesTableInfo.Columns.CLUSTERED_BY, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<TableInfo, BytesRef>() {

                        @Override
                        public BytesRef value() {
                            if (row instanceof ShardedTable) {
                                ColumnIdent clusteredBy = ((ShardedTable) row).clusteredBy();
                                if (clusteredBy == null) {
                                    return null;
                                }
                                return new BytesRef(clusteredBy.fqn());
                            }
                            return null;
                        }
                    };
                }
            }).put(InformationTablesTableInfo.Columns.PARTITIONED_BY, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<TableInfo, BytesRef[]>() {

                        @Override
                        public BytesRef[] value() {
                            if (row instanceof DocTableInfo) {
                                List<ColumnIdent> partitionedBy = ((DocTableInfo) row).partitionedBy();
                                if (partitionedBy == null || partitionedBy.isEmpty()) {
                                    return null;
                                }

                                BytesRef[] partitions = new BytesRef[partitionedBy.size()];
                                for (int i = 0; i < partitions.length; i++) {
                                    partitions[i] = new BytesRef(partitionedBy.get(i).fqn());
                                }
                                return partitions;
                            }
                            return null;
                        }
                    };
                }
            }).put(InformationTablesTableInfo.Columns.COLUMN_POLICY, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<TableInfo, BytesRef>() {

                        @Override
                        public BytesRef value() {
                            if (row instanceof DocTableInfo) {
                                return new BytesRef(((DocTableInfo) row).columnPolicy().value());
                            }
                            return new BytesRef(ColumnPolicy.STRICT.value());
                        }
                    };
                }
            }).put(InformationTablesTableInfo.Columns.BLOBS_PATH, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<TableInfo, BytesRef>() {

                        @Override
                        public BytesRef value() {
                            if (row instanceof BlobTableInfo) {
                                return ((BlobTableInfo) row).blobsPath();
                            }
                            return null;
                        }
                    };
                }
            }).put(InformationTablesTableInfo.Columns.TABLE_SETTINGS, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new TablesSettingsExpression();
                }
            }).build();
}

From source file:io.crate.operation.reference.information.SchemataSchemaNameExpression.java

License:Apache License

@Override
public BytesRef value() {
    return new BytesRef(this.row.name());
}

From source file:io.crate.operation.reference.sys.check.AbstractSysNodeCheck.java

License:Apache License

@Override
public BytesRef nodeId() {
    if (nodeId == null) {
        nodeId = new BytesRef(clusterService.localNode().id());
    }
    return nodeId;
}

From source file:io.crate.operation.reference.sys.check.checks.MinMasterNodesSysCheck.java

License:Apache License

@Inject
public MinMasterNodesSysCheck(ClusterService clusterService, NestedReferenceResolver nestedReferenceResolver) {
    super(ID, new BytesRef(DESCRIPTION), Severity.HIGH);
    this.clusterService = clusterService;
    this.nestedReferenceResolver = nestedReferenceResolver;
}