mirror of https://github.com/apache/lucene.git
SOLR-12892: MapWriter to use CharSequence instead of String
This commit is contained in:
parent
a7c9c9d8ce
commit
5de6332209
|
@ -214,6 +214,8 @@ Improvements
|
||||||
* SOLR-10981: Support for stream.url or stream.file pointing to gzipped data. It's detected by either a content
|
* SOLR-10981: Support for stream.url or stream.file pointing to gzipped data. It's detected by either a content
|
||||||
encoding header or file extension. (Andrew Lundgren via David Smiley, Jan Høydahl)
|
encoding header or file extension. (Andrew Lundgren via David Smiley, Jan Høydahl)
|
||||||
|
|
||||||
|
* SOLR-12892: MapWriter to use CharSequence instead of String (noble)
|
||||||
|
|
||||||
================== 7.5.0 ==================
|
================== 7.5.0 ==================
|
||||||
|
|
||||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
||||||
|
|
|
@ -124,8 +124,8 @@ public class AutoScalingHandler extends RequestHandlerBase implements Permission
|
||||||
autoScalingConf.writeMap(new MapWriter.EntryWriter() {
|
autoScalingConf.writeMap(new MapWriter.EntryWriter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapWriter.EntryWriter put(String k, Object v) throws IOException {
|
public MapWriter.EntryWriter put(CharSequence k, Object v) {
|
||||||
rsp.getValues().add(k, v);
|
rsp.getValues().add(k.toString(), v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -107,14 +107,14 @@ public class TransactionLog implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeExternString(String s) throws IOException {
|
public void writeExternString(CharSequence s) throws IOException {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
writeTag(NULL);
|
writeTag(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// no need to synchronize globalStringMap - it's only updated before the first record is written to the log
|
// no need to synchronize globalStringMap - it's only updated before the first record is written to the log
|
||||||
Integer idx = globalStringMap.get(s);
|
Integer idx = globalStringMap.get(s.toString());
|
||||||
if (idx == null) {
|
if (idx == null) {
|
||||||
// write a normal string
|
// write a normal string
|
||||||
writeStr(s);
|
writeStr(s);
|
||||||
|
|
|
@ -203,8 +203,8 @@ public class PolicyHelper {
|
||||||
|
|
||||||
public static MapWriter getDiagnostics(Policy.Session session) {
|
public static MapWriter getDiagnostics(Policy.Session session) {
|
||||||
List<Row> sorted = session.getSortedNodes();
|
List<Row> sorted = session.getSortedNodes();
|
||||||
Set<String> alreadyWritten = new HashSet<>();
|
Set<CharSequence> alreadyWritten = new HashSet<>();
|
||||||
BiPredicate<String, Object> p = dedupeKeyPredicate(alreadyWritten)
|
BiPredicate<CharSequence, Object> p = dedupeKeyPredicate(alreadyWritten)
|
||||||
.and(ConditionalMapWriter.NON_NULL_VAL)
|
.and(ConditionalMapWriter.NON_NULL_VAL)
|
||||||
.and((s, o) -> !(o instanceof Map) || !((Map) o).isEmpty());
|
.and((s, o) -> !(o instanceof Map) || !((Map) o).isEmpty());
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class ReplicaInfo implements MapWriter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeMap(EntryWriter ew) throws IOException {
|
public void writeMap(EntryWriter ew) throws IOException {
|
||||||
BiPredicate<String, Object> p = dedupeKeyPredicate(new HashSet<>())
|
BiPredicate<CharSequence, Object> p = dedupeKeyPredicate(new HashSet<>())
|
||||||
.and(NON_NULL_VAL);
|
.and(NON_NULL_VAL);
|
||||||
ew.put(name, (MapWriter) ew1 -> {
|
ew.put(name, (MapWriter) ew1 -> {
|
||||||
ew1.put(ZkStateReader.CORE_NAME_PROP, core, p)
|
ew1.put(ZkStateReader.CORE_NAME_PROP, core, p)
|
||||||
|
|
|
@ -23,9 +23,9 @@ import java.util.function.BiPredicate;
|
||||||
|
|
||||||
public class ConditionalMapWriter implements MapWriter {
|
public class ConditionalMapWriter implements MapWriter {
|
||||||
private final MapWriter delegate;
|
private final MapWriter delegate;
|
||||||
private final BiPredicate<String, Object> predicate;
|
private final BiPredicate<CharSequence, Object> predicate;
|
||||||
|
|
||||||
public ConditionalMapWriter(MapWriter delegate, BiPredicate<String, Object> predicate) {
|
public ConditionalMapWriter(MapWriter delegate, BiPredicate<CharSequence, Object> predicate) {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
}
|
}
|
||||||
|
@ -38,33 +38,33 @@ public class ConditionalMapWriter implements MapWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntryWriter put(String k, Object v) throws IOException {
|
public EntryWriter put(CharSequence k, Object v) throws IOException {
|
||||||
if (predicate.test(k, v)) delegate.put(k, v);
|
if (predicate.test(k, v)) delegate.put(k, v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntryWriter put(String k, int v) throws IOException {
|
public EntryWriter put(CharSequence k, int v) throws IOException {
|
||||||
return put(k, Integer.valueOf(v));
|
return put(k, Integer.valueOf(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntryWriter put(String k, long v) throws IOException {
|
public EntryWriter put(CharSequence k, long v) throws IOException {
|
||||||
return put(k, Long.valueOf(v));
|
return put(k, Long.valueOf(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntryWriter put(String k, float v) throws IOException {
|
public EntryWriter put(CharSequence k, float v) throws IOException {
|
||||||
return put(k, Float.valueOf(v));
|
return put(k, Float.valueOf(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntryWriter put(String k, double v) throws IOException {
|
public EntryWriter put(CharSequence k, double v) throws IOException {
|
||||||
return put(k, Double.valueOf(v));
|
return put(k, Double.valueOf(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntryWriter put(String k, boolean v) throws IOException {
|
public EntryWriter put(CharSequence k, boolean v) throws IOException {
|
||||||
return put(k, Boolean.valueOf(v));
|
return put(k, Boolean.valueOf(v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,9 +74,9 @@ public class ConditionalMapWriter implements MapWriter {
|
||||||
if(delegate!=null) delegate.writeMap(new EntryWriterWrapper(ew));
|
if(delegate!=null) delegate.writeMap(new EntryWriterWrapper(ew));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BiPredicate<String, Object> dedupeKeyPredicate(Set<String> keys) {
|
public static BiPredicate<CharSequence, Object> dedupeKeyPredicate(Set<CharSequence> keys) {
|
||||||
return (k, v) -> keys.add(k);
|
return (k, v) -> keys.add(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final BiPredicate<String, Object> NON_NULL_VAL = (s, o) -> o != null;
|
public static final BiPredicate<CharSequence, Object> NON_NULL_VAL = (s, o) -> o != null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ public interface MapWriter extends MapSerializable {
|
||||||
try {
|
try {
|
||||||
writeMap(new EntryWriter() {
|
writeMap(new EntryWriter() {
|
||||||
@Override
|
@Override
|
||||||
public EntryWriter put(String k, Object v) {
|
public EntryWriter put(CharSequence k, Object v) {
|
||||||
if (v instanceof MapWriter) v = ((MapWriter) v).toMap(new LinkedHashMap<>());
|
if (v instanceof MapWriter) v = ((MapWriter) v).toMap(new LinkedHashMap<>());
|
||||||
if (v instanceof IteratorWriter) v = ((IteratorWriter) v).toList(new ArrayList<>());
|
if (v instanceof IteratorWriter) v = ((IteratorWriter) v).toList(new ArrayList<>());
|
||||||
if (v instanceof Iterable) {
|
if (v instanceof Iterable) {
|
||||||
|
@ -66,7 +66,7 @@ public interface MapWriter extends MapSerializable {
|
||||||
}
|
}
|
||||||
v = map;
|
v = map;
|
||||||
}
|
}
|
||||||
map.put(k, v);
|
map.put(k==null? null : k.toString(), v);
|
||||||
// note: It'd be nice to assert that there is no previous value at 'k' but it's possible the passed in
|
// note: It'd be nice to assert that there is no previous value at 'k' but it's possible the passed in
|
||||||
// map is already populated and the intention is to overwrite.
|
// map is already populated and the intention is to overwrite.
|
||||||
return this;
|
return this;
|
||||||
|
@ -139,8 +139,8 @@ public interface MapWriter extends MapSerializable {
|
||||||
* @param k The key
|
* @param k The key
|
||||||
* @param v The value can be any supported object
|
* @param v The value can be any supported object
|
||||||
*/
|
*/
|
||||||
EntryWriter put(String k, Object v) throws IOException;
|
EntryWriter put(CharSequence k, Object v) throws IOException;
|
||||||
default EntryWriter putNoEx(String k, Object v) {
|
default EntryWriter putNoEx(CharSequence k, Object v) {
|
||||||
try {
|
try {
|
||||||
put(k,v);
|
put(k,v);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -149,45 +149,45 @@ public interface MapWriter extends MapSerializable {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
default EntryWriter put(String k, Object v, BiPredicate<String, Object> p) throws IOException {
|
default EntryWriter put(CharSequence k, Object v, BiPredicate<CharSequence, Object> p) throws IOException {
|
||||||
if (p.test(k,v)) put(k, v);
|
if (p.test(k,v)) put(k, v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
default EntryWriter putIfNotNull(String k, Object v) throws IOException {
|
default EntryWriter putIfNotNull(CharSequence k, Object v) throws IOException {
|
||||||
if(v != null) put(k,v);
|
if(v != null) put(k,v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
default EntryWriter putStringIfNotNull(String k, Object v) throws IOException {
|
default EntryWriter putStringIfNotNull(CharSequence k, Object v) throws IOException {
|
||||||
if(v != null) put(k,String.valueOf(v));
|
if(v != null) put(k,String.valueOf(v));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
default EntryWriter put(String k, int v) throws IOException {
|
default EntryWriter put(CharSequence k, int v) throws IOException {
|
||||||
put(k, (Integer) v);
|
put(k, (Integer) v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
default EntryWriter put(String k, long v) throws IOException {
|
default EntryWriter put(CharSequence k, long v) throws IOException {
|
||||||
put(k, (Long) v);
|
put(k, (Long) v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
default EntryWriter put(String k, float v) throws IOException {
|
default EntryWriter put(CharSequence k, float v) throws IOException {
|
||||||
put(k, (Float) v);
|
put(k, (Float) v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
default EntryWriter put(String k, double v) throws IOException {
|
default EntryWriter put(CharSequence k, double v) throws IOException {
|
||||||
put(k, (Double) v);
|
put(k, (Double) v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
default EntryWriter put(String k, boolean v) throws IOException {
|
default EntryWriter put(CharSequence k, boolean v) throws IOException {
|
||||||
put(k, (Boolean) v);
|
put(k, (Boolean) v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -405,42 +405,42 @@ public class JavaBinCodec implements PushWriter {
|
||||||
|
|
||||||
private final MapWriter.EntryWriter ew = new MapWriter.EntryWriter() {
|
private final MapWriter.EntryWriter ew = new MapWriter.EntryWriter() {
|
||||||
@Override
|
@Override
|
||||||
public MapWriter.EntryWriter put(String k, Object v) throws IOException {
|
public MapWriter.EntryWriter put(CharSequence k, Object v) throws IOException {
|
||||||
writeExternString(k);
|
writeExternString(k);
|
||||||
JavaBinCodec.this.writeVal(v);
|
JavaBinCodec.this.writeVal(v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapWriter.EntryWriter put(String k, int v) throws IOException {
|
public MapWriter.EntryWriter put(CharSequence k, int v) throws IOException {
|
||||||
writeExternString(k);
|
writeExternString(k);
|
||||||
JavaBinCodec.this.writeInt(v);
|
JavaBinCodec.this.writeInt(v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapWriter.EntryWriter put(String k, long v) throws IOException {
|
public MapWriter.EntryWriter put(CharSequence k, long v) throws IOException {
|
||||||
writeExternString(k);
|
writeExternString(k);
|
||||||
JavaBinCodec.this.writeLong(v);
|
JavaBinCodec.this.writeLong(v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapWriter.EntryWriter put(String k, float v) throws IOException {
|
public MapWriter.EntryWriter put(CharSequence k, float v) throws IOException {
|
||||||
writeExternString(k);
|
writeExternString(k);
|
||||||
JavaBinCodec.this.writeFloat(v);
|
JavaBinCodec.this.writeFloat(v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapWriter.EntryWriter put(String k, double v) throws IOException {
|
public MapWriter.EntryWriter put(CharSequence k, double v) throws IOException {
|
||||||
writeExternString(k);
|
writeExternString(k);
|
||||||
JavaBinCodec.this.writeDouble(v);
|
JavaBinCodec.this.writeDouble(v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapWriter.EntryWriter put(String k, boolean v) throws IOException {
|
public MapWriter.EntryWriter put(CharSequence k, boolean v) throws IOException {
|
||||||
writeExternString(k);
|
writeExternString(k);
|
||||||
writeBoolean(v);
|
writeBoolean(v);
|
||||||
return this;
|
return this;
|
||||||
|
@ -1062,7 +1062,7 @@ public class JavaBinCodec implements PushWriter {
|
||||||
private Map<String, Integer> stringsMap;
|
private Map<String, Integer> stringsMap;
|
||||||
private List<String> stringsList;
|
private List<String> stringsList;
|
||||||
|
|
||||||
public void writeExternString(String s) throws IOException {
|
public void writeExternString(CharSequence s) throws IOException {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
writeTag(NULL);
|
writeTag(NULL);
|
||||||
return;
|
return;
|
||||||
|
@ -1073,7 +1073,7 @@ public class JavaBinCodec implements PushWriter {
|
||||||
if (idx == 0) {
|
if (idx == 0) {
|
||||||
writeStr(s);
|
writeStr(s);
|
||||||
if (stringsMap == null) stringsMap = new HashMap<>();
|
if (stringsMap == null) stringsMap = new HashMap<>();
|
||||||
stringsMap.put(s, ++stringsCount);
|
stringsMap.put(s.toString(), ++stringsCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,15 +165,15 @@ public interface JsonTextWriter extends TextWriter {
|
||||||
boolean isFirst = true;
|
boolean isFirst = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapWriter.EntryWriter put(String k, Object v) throws IOException {
|
public MapWriter.EntryWriter put(CharSequence k, Object v) throws IOException {
|
||||||
if (isFirst) {
|
if (isFirst) {
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
} else {
|
} else {
|
||||||
JsonTextWriter.this.writeMapSeparator();
|
JsonTextWriter.this.writeMapSeparator();
|
||||||
}
|
}
|
||||||
JsonTextWriter.this.indent();
|
JsonTextWriter.this.indent();
|
||||||
JsonTextWriter.this.writeKey(k, true);
|
JsonTextWriter.this.writeKey(k.toString(), true);
|
||||||
writeVal(k, v);
|
writeVal(k.toString(), v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -123,7 +123,7 @@ public class Utils {
|
||||||
try {
|
try {
|
||||||
m.writeMap(new MapWriter.EntryWriter() {
|
m.writeMap(new MapWriter.EntryWriter() {
|
||||||
@Override
|
@Override
|
||||||
public MapWriter.EntryWriter put(String k, Object v) {
|
public MapWriter.EntryWriter put(CharSequence k, Object v) {
|
||||||
fun.accept(k, v);
|
fun.accept(k, v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -471,8 +471,8 @@ public class Utils {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class MapWriterEntry<V> extends AbstractMap.SimpleEntry<String, V> implements MapWriter, Map.Entry<String, V> {
|
static class MapWriterEntry<V> extends AbstractMap.SimpleEntry<CharSequence, V> implements MapWriter, Map.Entry<CharSequence, V> {
|
||||||
MapWriterEntry(String key, V value) {
|
MapWriterEntry(CharSequence key, V value) {
|
||||||
super(key, value);
|
super(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,7 +495,7 @@ public class Utils {
|
||||||
((MapWriter) obj).writeMap(new MapWriter.EntryWriter() {
|
((MapWriter) obj).writeMap(new MapWriter.EntryWriter() {
|
||||||
int count = -1;
|
int count = -1;
|
||||||
@Override
|
@Override
|
||||||
public MapWriter.EntryWriter put(String k, Object v) {
|
public MapWriter.EntryWriter put(CharSequence k, Object v) {
|
||||||
if (result[0] != null) return this;
|
if (result[0] != null) return this;
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
if (k.equals(key)) result[0] = v;
|
if (k.equals(key)) result[0] = v;
|
||||||
|
|
|
@ -2661,8 +2661,8 @@ public class TestPolicy extends SolrTestCaseJ4 {
|
||||||
Set<String> writtenKeys = new HashSet<>();
|
Set<String> writtenKeys = new HashSet<>();
|
||||||
policy.writeMap(new MapWriter.EntryWriter() {
|
policy.writeMap(new MapWriter.EntryWriter() {
|
||||||
@Override
|
@Override
|
||||||
public MapWriter.EntryWriter put(String k, Object v) throws IOException {
|
public MapWriter.EntryWriter put(CharSequence k, Object v) throws IOException {
|
||||||
writtenKeys.add(k);
|
writtenKeys.add(k.toString());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2679,8 +2679,8 @@ public class TestPolicy extends SolrTestCaseJ4 {
|
||||||
assertEquals(policy.getClusterPreferences().size(), defaultPreferences.size());
|
assertEquals(policy.getClusterPreferences().size(), defaultPreferences.size());
|
||||||
policy.writeMap(new MapWriter.EntryWriter() {
|
policy.writeMap(new MapWriter.EntryWriter() {
|
||||||
@Override
|
@Override
|
||||||
public MapWriter.EntryWriter put(String k, Object v) throws IOException {
|
public MapWriter.EntryWriter put(CharSequence k, Object v) throws IOException {
|
||||||
writtenKeys.add(k);
|
writtenKeys.add(k.toString());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue