Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

really rough prototype of 'streaming codec api'

Robert Muirb9eebb4f00b6
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/BinaryDocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/BinaryDocValuesConsumer.java
new file mode 100644
index 00000000000..80449cb8f4c
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/codecs/BinaryDocValuesConsumer.java
@@ -0,0 +1,51 @@
+package org.apache.lucene.codecs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.index.AtomicReader;
+import org.apache.lucene.index.DocValues.Source;
+import org.apache.lucene.index.FieldInfos;
+import org.apache.lucene.index.MergeState;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.BytesRef;
+
+public abstract class BinaryDocValuesConsumer {
+ public abstract void add(BytesRef value) throws IOException;
+ public abstract void finish(FieldInfos fis, int numDocs) throws IOException;
+
+ public int merge(MergeState mergeState) throws IOException {
+ int docCount = 0;
+ final BytesRef bytes = new BytesRef();
+ for (AtomicReader reader : mergeState.readers) {
+ final int maxDoc = reader.maxDoc();
+ final Bits liveDocs = reader.getLiveDocs();
+ final Source source = reader.docValues(mergeState.fieldInfo.name).getDirectSource();
+ for (int i = 0; i < maxDoc; i++) {
+ if (liveDocs == null || liveDocs.get(i)) {
+ add(source.getBytes(i, bytes));
+ }
+ docCount++;
+ mergeState.checkAbort.work(300);
+ }
+ }
+ finish(mergeState.fieldInfos, docCount);
+ return docCount;
+ }
+}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/NumericDocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/NumericDocValuesConsumer.java
new file mode 100644
index 00000000000..251798958d0
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/codecs/NumericDocValuesConsumer.java
@@ -0,0 +1,49 @@
+package org.apache.lucene.codecs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.index.AtomicReader;
+import org.apache.lucene.index.FieldInfos;
+import org.apache.lucene.index.MergeState;
+import org.apache.lucene.index.DocValues.Source;
+import org.apache.lucene.util.Bits;
+
+public abstract class NumericDocValuesConsumer {
+ public abstract void add(long value) throws IOException;
+ public abstract void finish(FieldInfos fieldInfos, int numDocs) throws IOException;
+
+ public int merge(MergeState mergeState) throws IOException {
+ int docCount = 0;
+ for (AtomicReader reader : mergeState.readers) {
+ final int maxDoc = reader.maxDoc();
+ final Bits liveDocs = reader.getLiveDocs();
+ final Source source = reader.docValues(mergeState.fieldInfo.name).getDirectSource();
+ for (int i = 0; i < maxDoc; i++) {
+ if (liveDocs == null || liveDocs.get(i)) {
+ add(source.getInt(i));
+ }
+ docCount++;
+ mergeState.checkAbort.work(300);
+ }
+ }
+ finish(mergeState.fieldInfos, docCount);
+ return docCount;
+ }
+}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/SimpleDVConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/SimpleDVConsumer.java
new file mode 100644
index 00000000000..73b23a5c995
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/codecs/SimpleDVConsumer.java
@@ -0,0 +1,113 @@
+package org.apache.lucene.codecs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.Closeable;
+import java.io.IOException;
+
+import org.apache.lucene.index.AtomicReader;
+import org.apache.lucene.index.DocValues;
+import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.MergeState;
+import org.apache.lucene.index.DocValues.Source;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.BytesRef;
+
+// prototype streaming DV api
+public abstract class SimpleDVConsumer implements Closeable {
+ // TODO: are any of these params too "infringing" on codec?
+ // we want codec to get necessary stuff from IW, but trading off against merge complexity.
+
+ public abstract NumericDocValuesConsumer addNumericField(FieldInfo field, long minValue, long maxValue) throws IOException;
+ public abstract BinaryDocValuesConsumer addBinaryField(FieldInfo field, boolean fixedLength, int maxLength) throws IOException;
+ // nocommit: figure out whats fair here.
+ public abstract SortedDocValuesConsumer addSortedField(FieldInfo field) throws IOException;
+
+ public void merge(MergeState mergeState) throws IOException {
+ for (FieldInfo field : mergeState.fieldInfos) {
+ if (field.hasDocValues()) {
+ mergeState.fieldInfo = field;
+ // nocommit: switch on 3 types: NUMBER, BYTES, SORTED
+ DocValues.Type type = field.getDocValuesType();
+ if (type == DocValues.Type.VAR_INTS) {
+ mergeNumericField(mergeState);
+ } else if (type == DocValues.Type.BYTES_VAR_STRAIGHT) {
+ mergeBinaryField(mergeState);
+ } else if (type == DocValues.Type.BYTES_VAR_SORTED) {
+ mergeSortedField(mergeState);
+ }
+ }
+ }
+ }
+
+ // dead simple impl: codec can optimize
+ protected void mergeNumericField(MergeState mergeState) throws IOException {
+ // first compute min and max value of live ones to be merged.
+ long minValue = Long.MAX_VALUE;
+ long maxValue = Long.MIN_VALUE;
+ for (AtomicReader reader : mergeState.readers) {
+ final int maxDoc = reader.maxDoc();
+ final Bits liveDocs = reader.getLiveDocs();
+ final Source source = reader.docValues(mergeState.fieldInfo.name).getDirectSource();
+ for (int i = 0; i < maxDoc; i++) {
+ if (liveDocs == null || liveDocs.get(i)) {
+ long val = source.getInt(i);
+ minValue = Math.min(val, minValue);
+ maxValue = Math.min(val, maxValue);
+ }
+ mergeState.checkAbort.work(300);
+ }
+ }
+ // now we can merge
+ NumericDocValuesConsumer field = addNumericField(mergeState.fieldInfo, minValue, maxValue);
+ field.merge(mergeState);
+ }
+
+ // dead simple impl: codec can optimize
+ protected void mergeBinaryField(MergeState mergeState) throws IOException {
+ // first compute fixedLength and maxLength of live ones to be merged.
+ boolean fixedLength = true;
+ int maxLength = -1;
+ BytesRef bytes = new BytesRef();
+ for (AtomicReader reader : mergeState.readers) {
+ final int maxDoc = reader.maxDoc();
+ final Bits liveDocs = reader.getLiveDocs();
+ final Source source = reader.docValues(mergeState.fieldInfo.name).getDirectSource();
+ for (int i = 0; i < maxDoc; i++) {
+ if (liveDocs == null || liveDocs.get(i)) {
+ source.getBytes(i, bytes);
+ if (maxLength == -1) {
+ maxLength = bytes.length;
+ } else {
+ fixedLength &= bytes.length == maxLength;
+ maxLength = Math.max(bytes.length, maxLength);
+ }
+ }
+ mergeState.checkAbort.work(300);
+ }
+ }
+ // now we can merge
+ assert maxLength >= 0; // could this happen (nothing to do?)
+ BinaryDocValuesConsumer field = addBinaryField(mergeState.fieldInfo, fixedLength, maxLength);
+ field.merge(mergeState);
+ }
+
+ protected void mergeSortedField(MergeState mergeState) throws IOException {
+
+ }
+}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/SortedDocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/SortedDocValuesConsumer.java
new file mode 100644
index 00000000000..f3829bb88a8
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/codecs/SortedDocValuesConsumer.java
@@ -0,0 +1,23 @@
+package org.apache.lucene.codecs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// TODO!
+public class SortedDocValuesConsumer {
+
+}