Java Code Examples for org.elasticsearch.common.lucene.BytesRefs

The following examples show how to use org.elasticsearch.common.lucene.BytesRefs. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Elasticsearch   Source File: LowerFunction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public BytesRef evaluate(Input<Object>... args) {
    Object stringValue = args[0].value();
    if (stringValue == null) {
        return null;
    }

    BytesRef inputByteRef = BytesRefs.toBytesRef(stringValue);

    char[] ref = new char[inputByteRef.length];
    int len = UnicodeUtil.UTF8toUTF16(inputByteRef.bytes, inputByteRef.offset, inputByteRef.length, ref);
    charUtils.toLowerCase(ref, 0, len);

    byte[] res = new byte[UnicodeUtil.MAX_UTF8_BYTES_PER_CHAR * len];
    len = UnicodeUtil.UTF16toUTF8(ref, 0, len, res);
    return new BytesRef(res, 0, len);
}
 
Example 2
Source Project: Elasticsearch   Source File: UpperFunction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public BytesRef evaluate(Input<Object>... args) {
    Object stringValue = args[0].value();
    if (stringValue == null) {
        return null;
    }

    BytesRef inputByteRef = BytesRefs.toBytesRef(stringValue);

    char[] ref = new char[inputByteRef.length];
    int len = UnicodeUtil.UTF8toUTF16(inputByteRef.bytes, inputByteRef.offset, inputByteRef.length, ref);
    charUtils.toUpperCase(ref, 0, len);

    byte[] res = new byte[UnicodeUtil.MAX_UTF8_BYTES_PER_CHAR * len];
    len = UnicodeUtil.UTF16toUTF8(ref, 0, len, res);
    return new BytesRef(res, 0, len);
}
 
Example 3
Source Project: Elasticsearch   Source File: ShardRecoveryExpression.java    License: Apache License 2.0 6 votes vote down vote up
private void addChildImplementations(final RecoveryState recoveryState) {
    childImplementations.put(TOTAL_TIME, new SimpleObjectExpression<Long>() {
        @Override
        public Long value() {
            return recoveryState.getTimer().time();
        }
    });
    childImplementations.put(STAGE, new SimpleObjectExpression<BytesRef>() {
        @Override
        public BytesRef value() {
            return BytesRefs.toBytesRef(recoveryState.getStage().name());
        }
    });
    childImplementations.put(TYPE, new SimpleObjectExpression<BytesRef>() {
        @Override
        public BytesRef value() {
            return BytesRefs.toBytesRef(recoveryState.getType().name());
        }
    });
    childImplementations.put(SIZE, new ShardRecoverySizeExpression(recoveryState));
    childImplementations.put(FILES, new ShardRecoveryFilesExpression(recoveryState));
}
 
Example 4
Source Project: Elasticsearch   Source File: LiteralValueFormatter.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void format(Object value, StringBuilder builder) {
    if (value == null) {
        builder.append("NULL");
    } else if (value instanceof Map) {
        formatMap((Map<String, Object>) value, builder);
    } else if(value instanceof Set) {
        formatIterable(Sorted.sortRecursive((Collection) value), builder);
    } else if(value instanceof Collection) {
        formatIterable((Iterable<?>) value, builder);
    } else if (value instanceof Object[]) {
        formatIterable(ImmutableList.copyOf((Object[]) value), builder);

    } else if (value.getClass().isArray()) {
        formatArray(value, builder);
    } else if (value instanceof CharSequence || value instanceof Character || value instanceof BytesRef) {
        builder.append(Literals.quoteStringLiteral(BytesRefs.toString(value)));
    } else {
        builder.append(value.toString());
    }

}
 
Example 5
Source Project: Elasticsearch   Source File: PartitionInfos.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static Map<String, Object> buildValuesMap(PartitionName partitionName, MappingMetaData mappingMetaData) throws Exception{
    int i = 0;
    Map<String, Object> valuesMap = new HashMap<>();
    Iterable<Tuple<ColumnIdent, DataType>> partitionColumnInfoIterable = PartitionedByMappingExtractor.extractPartitionedByColumns(mappingMetaData.sourceAsMap());
    for (Tuple<ColumnIdent, DataType> columnInfo : partitionColumnInfoIterable) {
        String columnName = columnInfo.v1().sqlFqn();
        // produce string type values as string, not bytesref
        Object value = BytesRefs.toString(partitionName.values().get(i));
        if (!columnInfo.v2().equals(DataTypes.STRING)) {
            value = columnInfo.v2().value(value);
        }
        valuesMap.put(columnName, value);
        i++;
    }
    return valuesMap;
}
 
Example 6
Source Project: Elasticsearch   Source File: MatchQueryBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public MatchQueryBuilder(MapperService mapperService,
                         IndexCache indexCache,
                         @Nullable BytesRef matchType,
                         @Nullable Map options) throws IOException {
    this.mapperService = mapperService;
    this.indexCache = indexCache;
    if (matchType == null) {
        this.matchType = MultiMatchQueryBuilder.Type.BEST_FIELDS;
    } else {
        this.matchType = SUPPORTED_TYPES.get(matchType);
        if (this.matchType == null) {
            throw illegalMatchType(BytesRefs.toString(matchType));
        }
    }
    this.options = OptionParser.parse(this.matchType, options);
}
 
Example 7
Source Project: Elasticsearch   Source File: LuceneQueryBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Query apply(Function input, Context context) throws IOException {
    Tuple<Reference, Literal> prepare = prepare(input);
    if (prepare == null) { return null; }
    String fieldName = prepare.v1().info().ident().columnIdent().fqn();
    Object value = prepare.v2().value();

    if (value instanceof BytesRef) {
        RegexQuery query = new RegexQuery(new Term(fieldName, BytesRefs.toBytesRef(value)));
        query.setRegexImplementation(new JavaUtilRegexCapabilities(
                JavaUtilRegexCapabilities.FLAG_CASE_INSENSITIVE |
                JavaUtilRegexCapabilities.FLAG_UNICODE_CASE));
        return query;
    }
    throw new IllegalArgumentException("Can only use ~* with patterns of type string");
}
 
Example 8
Source Project: Elasticsearch   Source File: ExtendedFsStats.java    License: Apache License 2.0 6 votes vote down vote up
public Info(String path,
            @Nullable String dev,
            long total,
            long free,
            long available,
            long used,
            long diskReads,
            long diskWrites,
            long diskReadBytes,
            long diskWriteBytes) {
    this.path = new BytesRef(path);
    this.dev = BytesRefs.toBytesRef(dev);
    this.total = total;
    this.free = free;
    this.available = available;
    this.used = used;
    this.diskReads = diskReads;
    this.diskWrites = diskWrites;
    this.diskReadBytes = diskReadBytes;
    this.diskWriteBytes = diskWriteBytes;
}
 
Example 9
Source Project: crate   Source File: GroupByOptimizedIterator.java    License: Apache License 2.0 6 votes vote down vote up
private static Iterable<Row> getRows(Map<BytesRef, Object[]> groupedStates,
                                     RamAccounting ramAccounting,
                                     List<AggregationContext> aggregations,
                                     AggregateMode mode) {
    return () -> groupedStates.entrySet().stream()
        .map(new Function<Map.Entry<BytesRef, Object[]>, Row>() {

            final Object[] cells = new Object[1 + aggregations.size()];
            final RowN row = new RowN(cells);

            @Override
            public Row apply(Map.Entry<BytesRef, Object[]> entry) {
                cells[0] = BytesRefs.toString(entry.getKey());
                Object[] states = entry.getValue();
                for (int i = 0, c = 1; i < states.length; i++, c++) {
                    //noinspection unchecked
                    cells[c] = mode.finishCollect(ramAccounting, aggregations.get(i).function(), states[i]);
                }
                return row;
            }
        })
        .iterator();
}
 
Example 10
Source Project: Elasticsearch   Source File: RowShardResolver.java    License: Apache License 2.0 5 votes vote down vote up
public void setNextRow(Row row) {
    for (CollectExpression<Row, ?> expression : visitorContext.collectExpressions()) {
        expression.setNextRow(row);
    }
    id = idFunction.apply(pkValues(primaryKeyInputs));
    if (routingInput == null) {
        routing = null;
    } else {
        routing = BytesRefs.toString(routingInput.value());
    }
}
 
Example 11
Source Project: Elasticsearch   Source File: Inputs.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public BytesRef apply(@Nullable Input<?> input) {
    if (input == null) {
        return null;
    }
    return BytesRefs.toBytesRef(input.value());
}
 
Example 12
Source Project: Elasticsearch   Source File: SubstrFunction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public BytesRef evaluate(Input[] args) {
    assert (args.length >= 2 && args.length <= 3);
    if (hasNullInputs(args)) {
        return null;
    }
    final Object val = args[0].value();
    if (args.length == 3) {
        return evaluate(BytesRefs.toBytesRef(val),
                ((Number) args[1].value()).intValue(),
                ((Number) args[2].value()).intValue());

    }
    return evaluate(BytesRefs.toBytesRef(val), ((Number) args[1].value()).intValue());
}
 
Example 13
Source Project: Elasticsearch   Source File: RowContextReferenceResolver.java    License: Apache License 2.0 5 votes vote down vote up
private ImmutableMap<ColumnIdent, RowCollectExpressionFactory> getSysJobsExpressions() {
    return ImmutableMap.<ColumnIdent, RowCollectExpressionFactory>builder()
            .put(SysJobsTableInfo.Columns.ID, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<JobContext, BytesRef>() {
                        @Override
                        public BytesRef value() {
                            return BytesRefs.toBytesRef(row.id);
                        }
                    };
                }
            })
            .put(SysJobsTableInfo.Columns.STMT, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<JobContext, BytesRef>() {
                        @Override
                        public BytesRef value() {
                            return new BytesRef(row.stmt);
                        }
                    };
                }
            })
            .put(SysJobsTableInfo.Columns.STARTED, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<JobContext, Long>() {
                        @Override
                        public Long value() {
                            return row.started;
                        }
                    };
                }
            })
            .build();
}
 
Example 14
public List<String> generatePartitions() {
    List<String> partitionValues = new ArrayList<>(partitionMaps.size());
    for (Map<String, String> map : partitionMaps) {
        List<BytesRef> values = new ArrayList<>(map.size());
        List<String> columnNames = partitionedByColumnNames();
        for (String columnName : columnNames) {
            values.add(BytesRefs.toBytesRef(map.get(columnName)));
        }
        PartitionName partitionName = new PartitionName(tableInfo().ident(), values);
        partitionValues.add(partitionName.asIndexName());
    }
    return partitionValues;
}
 
Example 15
Source Project: Elasticsearch   Source File: Literal.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    return "Literal{" +
            "value=" + BytesRefs.toString(value) +
            ", type=" + type +
            '}';
}
 
Example 16
Source Project: Elasticsearch   Source File: InsertFromValuesAnalyzer.java    License: Apache License 2.0 5 votes vote down vote up
private void addPrimaryKeyValue(int index, Object value, List<BytesRef> primaryKeyValues) {
    if (value == null) {
        throw new IllegalArgumentException("Primary key value must not be NULL");
    }
    if (primaryKeyValues.size() > index) {
        primaryKeyValues.add(index, BytesRefs.toBytesRef(value));
    } else {
        primaryKeyValues.add(BytesRefs.toBytesRef(value));
    }
}
 
Example 17
Source Project: Elasticsearch   Source File: MatchQueryBuilder.java    License: Apache License 2.0 5 votes vote down vote up
protected IllegalArgumentException illegalMatchType(String matchType) {
    throw new IllegalArgumentException(String.format(Locale.ENGLISH,
            "Unknown matchType \"%s\". Possible matchTypes are: %s", matchType,
            Joiner.on(", ").join(Iterables.transform(SUPPORTED_TYPES.keySet(), new Function<BytesRef, String>() {
                        @Nullable
                        @Override
                        public String apply(@Nullable BytesRef input) {
                            return BytesRefs.toString(input);
                        }
                    }

            ))));
}
 
Example 18
Source Project: Elasticsearch   Source File: LuceneQueryBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Query applyArrayReference(Reference arrayReference, Literal literal, Context context) throws IOException {
    String regexString = LikeOperator.patternToRegex(BytesRefs.toString(literal.value()), LikeOperator.DEFAULT_ESCAPE, false);
    regexString = regexString.substring(1, regexString.length() - 1);
    String notLike = negateWildcard(regexString);

    return new RegexpQuery(new Term(
            arrayReference.info().ident().columnIdent().fqn(),
            notLike),
            RegexpFlag.COMPLEMENT.value()
    );
}
 
Example 19
Source Project: Elasticsearch   Source File: BytesRefUtils.java    License: Apache License 2.0 5 votes vote down vote up
private static String[] objectArrayToStringArray(Object[] values) {
    String[] strings = new String[values.length];
    for (int i = 0; i < strings.length; i++) {
        strings[i] = BytesRefs.toString(values[i]);
    }
    return strings;
}
 
Example 20
Source Project: Elasticsearch   Source File: Uid.java    License: Apache License 2.0 5 votes vote down vote up
public static BytesRef[] createUidsForTypesAndIds(Collection<String> types, Collection<?> ids) {
    BytesRef[] uids = new BytesRef[types.size() * ids.size()];
    BytesRefBuilder typeBytes = new BytesRefBuilder();
    BytesRefBuilder idBytes = new BytesRefBuilder();
    int index = 0;
    for (String type : types) {
        typeBytes.copyChars(type);
        for (Object id : ids) {
            uids[index++] = Uid.createUidAsBytes(typeBytes.get(), BytesRefs.toBytesRef(id, idBytes));
        }
    }
    return uids;
}
 
Example 21
Source Project: Elasticsearch   Source File: TypeFieldMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query termQuery(Object value, @Nullable QueryParseContext context) {
    if (indexOptions() == IndexOptions.NONE) {
        return new ConstantScoreQuery(new PrefixQuery(new Term(UidFieldMapper.NAME, Uid.typePrefixAsBytes(BytesRefs.toBytesRef(value)))));
    }
    return new ConstantScoreQuery(new TermQuery(createTerm(value)));
}
 
Example 22
Source Project: crate   Source File: StringFieldType.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions,
        boolean transpositions) {
    failIfNotIndexed();
    return new FuzzyQuery(new Term(name(), indexedValueForSearch(value)),
            fuzziness.asDistance(BytesRefs.toString(value)), prefixLength, maxExpansions, transpositions);
}
 
Example 23
Source Project: crate   Source File: LikeQuery.java    License: Apache License 2.0 5 votes vote down vote up
public static Query like(DataType dataType, @Nullable MappedFieldType fieldType, Object value, boolean ignoreCase) {
    if (fieldType == null) {
        // column doesn't exist on this index -> no match
        return Queries.newMatchNoDocsQuery("column does not exist in this index");
    }

    if (dataType.equals(DataTypes.STRING)) {
        return createCaseAwareQuery(
            fieldType.name(),
            BytesRefs.toString(value),
            ignoreCase);
    }
    return fieldType.termQuery(value, null);
}
 
Example 24
Source Project: crate   Source File: ClientMessages.java    License: Apache License 2.0 5 votes vote down vote up
static void sendBindMessage(ByteBuf 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);
    buffer.writeShort(0); // formatCode use 0 to default to text for all
    buffer.writeShort(params.size());

    int paramsLength = 0;
    for (Object param : params) {
        BytesRef value = BytesRefs.toBytesRef(param);
        buffer.writeInt(value.length);
        // the strings here are _not_ zero-padded because we specify the length upfront
        buffer.writeBytes(value.bytes, value.offset, value.length);
        paramsLength += 4 + value.length;
    }
    buffer.writeShort(0); // numResultFormatCodes - 0 to default to text for all

    buffer.setInt(beforeLengthWriterIndex,
        4 +
        portalBytes.length + 1 +
        statementBytes.length + 1 +
        2 + // numFormatCodes
        2 + // numParams
        paramsLength +
        2); // numResultColumnFormatCodes
}
 
Example 25
Source Project: Elasticsearch   Source File: GeoJSONUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void validateGeoJson(Map value) {
    String type = BytesRefs.toString(value.get(TYPE_FIELD));
    if (type == null) {
        throw new IllegalArgumentException(invalidGeoJSON("type field missing"));
    }

    type = GEOSJON_TYPES.get(type);
    if (type == null) {
        throw new IllegalArgumentException(invalidGeoJSON("invalid type"));
    }

    if (GEOMETRY_COLLECTION.equals(type)) {
        Object geometries = value.get(GeoJSONUtils.GEOMETRIES_FIELD);
        if (geometries == null) {
            throw new IllegalArgumentException(invalidGeoJSON("geometries field missing"));
        }

        ForEach.forEach(geometries, new ForEach.Acceptor() {
            @Override
            public void accept(Object input) {
                if (!(input instanceof Map)) {
                    throw new IllegalArgumentException(invalidGeoJSON("invalid GeometryCollection"));
                } else {
                    validateGeoJson((Map)input);
                }
            }
        });
    } else {
        Object coordinates = value.get(COORDINATES_FIELD);
        if (coordinates == null) {
            throw new IllegalArgumentException(invalidGeoJSON("coordinates field missing"));
        }
        switch(type) {
            case POINT:
                validateCoordinate(coordinates);
                break;
            case MULTI_POINT:
            case LINE_STRING:
                validateCoordinates(coordinates, 1);
                break;
            case POLYGON:
            case MULTI_LINE_STRING:
                validateCoordinates(coordinates, 2);
                break;
            case MULTI_POLYGON:
                validateCoordinates(coordinates, 3);
                break;
            default:
                // shouldn't happen
                throw new IllegalArgumentException(invalidGeoJSON("invalid type"));
        }
    }
}
 
Example 26
public static Map<ColumnIdent, RowCollectExpressionFactory> columnsFactories() {
    return ImmutableMap.<ColumnIdent, RowCollectExpressionFactory>builder()
            .put(InformationColumnsTableInfo.Columns.SCHEMA_NAME, new RowCollectExpressionFactory() {

                @Override
                public RowCollectExpression create() {
                    return new InformationColumnsExpression.ColumnsSchemaNameExpression();
                }
            })
            .put(InformationColumnsTableInfo.Columns.TABLE_NAME, new RowCollectExpressionFactory() {

                @Override
                public RowCollectExpression create() {
                    return new InformationColumnsExpression.ColumnsTableNameExpression();
                }
            })
            .put(InformationColumnsTableInfo.Columns.COLUMN_NAME, new RowCollectExpressionFactory() {

                @Override
                public RowCollectExpression create() {
                    return new InformationColumnsExpression.ColumnsColumnNameExpression();
                }
            })
            .put(InformationColumnsTableInfo.Columns.ORDINAL_POSITION, new RowCollectExpressionFactory() {

                @Override
                public RowCollectExpression create() {
                    return new InformationColumnsExpression.ColumnsOrdinalExpression();
                }
            })
            .put(InformationColumnsTableInfo.Columns.DATA_TYPE, new RowCollectExpressionFactory() {

                @Override
                public RowCollectExpression create() {
                    return new InformationColumnsExpression.ColumnsDataTypeExpression();
                }
            })
            .put(InformationColumnsTableInfo.Columns.IS_GENERATED, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new InformationColumnsExpression<Boolean>() {
                        @Override
                        public Boolean value() {
                            return row.info instanceof GeneratedReferenceInfo;
                        }
                    };
                }
            })
            .put(InformationColumnsTableInfo.Columns.GENERATION_EXPRESSION, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new InformationColumnsExpression<BytesRef>() {
                        @Override
                        public BytesRef value() {
                            if (row.info instanceof GeneratedReferenceInfo) {
                                return BytesRefs.toBytesRef(((GeneratedReferenceInfo) row.info).formattedGeneratedExpression());
                            }
                            return null;
                        }
                    };
                }
            }).build();
}
 
Example 27
Source Project: Elasticsearch   Source File: TablesSettingsExpression.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public BytesRef value() {
    return BytesRefs.toBytesRef(row.tableParameters().get(paramName));
}
 
Example 28
Source Project: Elasticsearch   Source File: RowContextReferenceResolver.java    License: Apache License 2.0 4 votes vote down vote up
private Map<ColumnIdent, RowCollectExpressionFactory> getSysOperationLogExpressions() {
    return ImmutableMap.<ColumnIdent, RowCollectExpressionFactory>builder()
            .put(SysOperationsLogTableInfo.Columns.ID, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<OperationContextLog, BytesRef>() {
                        @Override
                        public BytesRef value() {
                            return BytesRefs.toBytesRef(row.id());
                        }
                    };
                }
            })
            .put(SysOperationsLogTableInfo.Columns.JOB_ID, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<OperationContextLog, BytesRef>() {
                        @Override
                        public BytesRef value() {
                            return BytesRefs.toBytesRef(row.jobId());
                        }
                    };
                }
            })
            .put(SysOperationsLogTableInfo.Columns.NAME, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<OperationContextLog, BytesRef>() {
                        @Override
                        public BytesRef value() {
                            return new BytesRef(row.name());
                        }
                    };
                }
            })
            .put(SysOperationsLogTableInfo.Columns.STARTED, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<OperationContextLog, Long>() {
                        @Override
                        public Long value() {
                            return row.started();
                        }
                    };
                }
            })
            .put(SysOperationsLogTableInfo.Columns.USED_BYTES, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<OperationContextLog, Long>() {
                        @Override
                        public Long value() {
                            long usedBytes = row.usedBytes();
                            if (usedBytes == 0) {
                                return null;
                            }
                            return usedBytes;
                        }
                    };
                }
            })
            .put(SysOperationsLogTableInfo.Columns.ERROR, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<OperationContextLog, BytesRef>() {
                        @Override
                        public BytesRef value() {
                            return BytesRefs.toBytesRef(row.errorMessage());
                        }
                    };
                }
            })
            .put(SysOperationsLogTableInfo.Columns.ENDED, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<OperationContextLog, Long>() {
                        @Override
                        public Long value() {
                            return row.ended();
                        }
                    };
                }
            })
            .build();
}
 
Example 29
Source Project: Elasticsearch   Source File: RowContextReferenceResolver.java    License: Apache License 2.0 4 votes vote down vote up
private Map<ColumnIdent, RowCollectExpressionFactory> getSysOperationExpressions() {
    return ImmutableMap.<ColumnIdent, RowCollectExpressionFactory>builder()
            .put(SysOperationsTableInfo.Columns.ID, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<OperationContext, BytesRef>() {
                        @Override
                        public BytesRef value() {
                            return BytesRefs.toBytesRef(row.id);
                        }
                    };
                }
            })
            .put(SysOperationsTableInfo.Columns.JOB_ID, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<OperationContext, BytesRef>() {
                        @Override
                        public BytesRef value() {
                            return BytesRefs.toBytesRef(row.jobId);
                        }
                    };
                }
            })
            .put(SysOperationsTableInfo.Columns.NAME, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<OperationContext, BytesRef>() {
                        @Override
                        public BytesRef value() {
                            return new BytesRef(row.name);
                        }
                    };
                }
            })
            .put(SysOperationsTableInfo.Columns.STARTED, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<OperationContext, Long>() {
                        @Override
                        public Long value() {
                            return row.started;
                        }
                    };
                }
            })
            .put(SysOperationsTableInfo.Columns.USED_BYTES, new RowCollectExpressionFactory() {
                @Override
                public RowCollectExpression create() {
                    return new RowContextCollectorExpression<OperationContext, Long>() {
                        @Override
                        public Long value() {
                            if (row.usedBytes == 0) {
                                return null;
                            }
                            return row.usedBytes;
                        }
                    };
                }
            })
            .build();
}
 
Example 30
@Inject
public BlobShardTableNameExpression(ShardId shardId) {
    this.tableName = BytesRefs.toBytesRef(BlobIndices.STRIP_PREFIX.apply(shardId.index().name()));
}