-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Simple version of patterned_text with a single doc value for arguments #129292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
d0c9a2e
78ef582
6bb95ac
ad728f3
a97bbc4
3a0e349
cda6b0a
30ae746
387757d
03b9fde
f9344bf
e4d4830
fca0f83
f9b030b
4429474
10147ad
4a3ba41
b7450c2
8efac46
cd2f9aa
906ca11
0815760
6856d2d
4b63ed0
fa022e6
8cd70fd
526fef1
39e9d88
eb4212f
e026a5c
a2bc5fa
f0da074
4e0c337
109afd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| apply plugin: 'elasticsearch.internal-es-plugin' | ||
| apply plugin: 'elasticsearch.internal-yaml-rest-test' | ||
|
|
||
| esplugin { | ||
| name = 'patterned-text' | ||
parkertimmins marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| description = 'Module for the patterned_text field type.' | ||
| classname ='org.elasticsearch.xpack.patternedtext.PatternedTextMapperPlugin' | ||
| extendedPlugins = ['x-pack-core'] | ||
| } | ||
| base { | ||
| archivesName = 'x-pack-patterned-text' | ||
| } | ||
|
|
||
| dependencies { | ||
| compileOnly project(path: xpackModule('core')) | ||
| implementation project(':modules:mapper-extras') | ||
| } | ||
|
|
||
| if (buildParams.getSnapshotBuild() == false) { | ||
| tasks.named("test").configure { | ||
| systemProperty 'es.index_mode_feature_flag_registered', 'true' | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.patternedtext; | ||
|
|
||
| import org.apache.lucene.index.DocValues; | ||
| import org.apache.lucene.index.LeafReaderContext; | ||
| import org.apache.lucene.index.SortedDocValues; | ||
| import org.apache.lucene.index.SortedSetDocValues; | ||
| import org.elasticsearch.index.mapper.BlockDocValuesReader; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class PatternedTextBlockLoader extends BlockDocValuesReader.DocValuesBlockLoader { | ||
|
|
||
| private final String name; | ||
| private final String templateFieldName; | ||
| private final String argsFieldName; | ||
|
|
||
| PatternedTextBlockLoader(String name, String templateFieldName, String argsFieldName) { | ||
| this.name = name; | ||
| this.templateFieldName = templateFieldName; | ||
| this.argsFieldName = argsFieldName; | ||
| } | ||
|
|
||
| @Override | ||
| public BytesRefBuilder builder(BlockFactory factory, int expectedCount) { | ||
| return factory.bytesRefs(expectedCount); | ||
| } | ||
|
|
||
| @Override | ||
| public AllReader reader(LeafReaderContext context) throws IOException { | ||
| SortedSetDocValues combinedDocValues = ordinals(context); | ||
| if (combinedDocValues != null) { | ||
| SortedDocValues singleton = DocValues.unwrapSingleton(combinedDocValues); | ||
| if (singleton != null) { | ||
| return new BlockDocValuesReader.SingletonOrdinals(singleton); | ||
| } | ||
| return new BlockDocValuesReader.Ordinals(combinedDocValues); | ||
| } | ||
| return new ConstantNullsReader(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean supportsOrdinals() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public SortedSetDocValues ordinals(LeafReaderContext context) throws IOException { | ||
| return PatternedTextDocValues.from(context.reader(), templateFieldName, argsFieldName); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "PatternedTextBlockLoader[" + name + "]"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.patternedtext; | ||
|
|
||
| import org.apache.lucene.index.DocValues; | ||
| import org.apache.lucene.index.LeafReader; | ||
| import org.apache.lucene.index.SortedSetDocValues; | ||
| import org.apache.lucene.util.BytesRef; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class PatternedTextDocValues extends SortedSetDocValues { | ||
| private final SortedSetDocValues templateDocValues; | ||
| private final SortedSetDocValues argsDocValues; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, there should only be one template and one concatenated args per doc |
||
|
|
||
| PatternedTextDocValues(SortedSetDocValues templateDocValues, SortedSetDocValues argsDocValues) { | ||
| this.templateDocValues = templateDocValues; | ||
| this.argsDocValues = argsDocValues; | ||
| } | ||
|
|
||
| static PatternedTextDocValues from(LeafReader leafReader, String templateFieldName, String argsFieldName) throws IOException { | ||
| SortedSetDocValues templateDocValues = DocValues.getSortedSet(leafReader, templateFieldName); | ||
| if (templateDocValues.getValueCount() == 0) { | ||
| return null; | ||
| } | ||
|
|
||
| SortedSetDocValues argsDocValues = DocValues.getSortedSet(leafReader, argsFieldName); | ||
| return new PatternedTextDocValues(templateDocValues, argsDocValues); | ||
| } | ||
|
|
||
| @Override | ||
| public long nextOrd() throws IOException { | ||
| return templateDocValues.nextOrd(); | ||
| } | ||
|
|
||
| @Override | ||
| public int docValueCount() { | ||
| return templateDocValues.docValueCount(); | ||
| } | ||
|
|
||
| @Override | ||
| public BytesRef lookupOrd(long l) throws IOException { | ||
| return new BytesRef(lookupOrdAsString(l)); | ||
| } | ||
|
|
||
| String lookupOrdAsString(long l) throws IOException { | ||
| String template = templateDocValues.lookupOrd(l).utf8ToString(); | ||
| int argsCount = PatternedTextValueProcessor.countArgs(template); | ||
| List<String> args = new ArrayList<>(argsCount); | ||
| if (argsCount > 0) { | ||
| var mergedArgs = argsDocValues.lookupOrd(argsDocValues.nextOrd()); | ||
| PatternedTextValueProcessor.decodeRemainingArgs(args, mergedArgs.utf8ToString()); | ||
| } | ||
| return PatternedTextValueProcessor.merge(new PatternedTextValueProcessor.Parts(template, args)); | ||
| } | ||
|
|
||
| @Override | ||
| public long getValueCount() { | ||
| return templateDocValues.getValueCount(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean advanceExact(int i) throws IOException { | ||
| argsDocValues.advanceExact(i); | ||
| return templateDocValues.advanceExact(i); | ||
| } | ||
|
|
||
| @Override | ||
| public int docID() { | ||
| return templateDocValues.docID(); | ||
| } | ||
|
|
||
| @Override | ||
| public int nextDoc() throws IOException { | ||
| return templateDocValues.nextDoc(); | ||
| } | ||
|
|
||
| @Override | ||
| public int advance(int i) throws IOException { | ||
| return templateDocValues.advance(i); | ||
| } | ||
|
|
||
| @Override | ||
| public long cost() { | ||
| return templateDocValues.cost() + argsDocValues.cost(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.patternedtext; | ||
|
|
||
| import org.elasticsearch.index.fielddata.SortedBinaryDocValues; | ||
| import org.elasticsearch.script.field.BaseKeywordDocValuesField; | ||
|
|
||
| public class PatternedTextDocValuesField extends BaseKeywordDocValuesField { | ||
| public PatternedTextDocValuesField(SortedBinaryDocValues input, String name) { | ||
| super(input, name); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.