From 5c236792387070747b4405544f52fec6dc8de46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Mon, 13 Apr 2015 22:04:46 -0700 Subject: [PATCH] add WritableSupplier and IndexedMultivalue --- .../druid/segment/data/IndexedMultivalue.java | 26 ++++++++++++ .../io/druid/segment/data/VSizeIndexed.java | 42 +++++++++++++++++-- .../druid/segment/data/VSizeIndexedInts.java | 32 +++++++++++++- .../druid/segment/data/WritableSupplier.java | 31 ++++++++++++++ 4 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 processing/src/main/java/io/druid/segment/data/IndexedMultivalue.java create mode 100644 processing/src/main/java/io/druid/segment/data/WritableSupplier.java diff --git a/processing/src/main/java/io/druid/segment/data/IndexedMultivalue.java b/processing/src/main/java/io/druid/segment/data/IndexedMultivalue.java new file mode 100644 index 00000000000..a71360f3a25 --- /dev/null +++ b/processing/src/main/java/io/druid/segment/data/IndexedMultivalue.java @@ -0,0 +1,26 @@ +/* + * Licensed to Metamarkets Group Inc. (Metamarkets) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Metamarkets 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. + */ + +package io.druid.segment.data; + +import java.io.Closeable; + +public interface IndexedMultivalue extends Indexed, Closeable +{ +} diff --git a/processing/src/main/java/io/druid/segment/data/VSizeIndexed.java b/processing/src/main/java/io/druid/segment/data/VSizeIndexed.java index 0a514759247..bba56edf8f6 100644 --- a/processing/src/main/java/io/druid/segment/data/VSizeIndexed.java +++ b/processing/src/main/java/io/druid/segment/data/VSizeIndexed.java @@ -29,7 +29,7 @@ import java.util.Iterator; /** */ -public class VSizeIndexed implements Indexed +public class VSizeIndexed implements IndexedMultivalue { private static final byte version = 0x1; @@ -140,7 +140,7 @@ public class VSizeIndexed implements Indexed } @Override - public int indexOf(VSizeIndexedInts value) + public int indexOf(IndexedInts value) { throw new UnsupportedOperationException("Reverse lookup not allowed."); } @@ -176,8 +176,44 @@ public class VSizeIndexed implements Indexed } @Override - public Iterator iterator() + public Iterator iterator() { return IndexedIterable.create(this).iterator(); } + + @Override + public void close() throws IOException + { + // no-op + } + + public WritableSupplier> asWritableSupplier() { + return new VSizeIndexedSupplier(this); + } + + public static class VSizeIndexedSupplier implements WritableSupplier> { + final VSizeIndexed delegate; + + public VSizeIndexedSupplier(VSizeIndexed delegate) { + this.delegate = delegate; + } + + @Override + public long getSerializedSize() + { + return delegate.getSerializedSize(); + } + + @Override + public void writeToChannel(WritableByteChannel channel) throws IOException + { + delegate.writeToChannel(channel); + } + + @Override + public IndexedMultivalue get() + { + return delegate; + } + } } diff --git a/processing/src/main/java/io/druid/segment/data/VSizeIndexedInts.java b/processing/src/main/java/io/druid/segment/data/VSizeIndexedInts.java index 6fc9090f940..5dd399c9449 100644 --- a/processing/src/main/java/io/druid/segment/data/VSizeIndexedInts.java +++ b/processing/src/main/java/io/druid/segment/data/VSizeIndexedInts.java @@ -151,7 +151,7 @@ public class VSizeIndexedInts implements IndexedInts, Comparable asWritableSupplier() { + return new VSizeIndexedIntsSupplier(this); + } + + public static class VSizeIndexedIntsSupplier implements WritableSupplier { + final VSizeIndexedInts delegate; + + public VSizeIndexedIntsSupplier(VSizeIndexedInts delegate) { + this.delegate = delegate; + } + + @Override + public long getSerializedSize() + { + return delegate.getSerializedSize(); + } + + @Override + public void writeToChannel(WritableByteChannel channel) throws IOException + { + delegate.writeToChannel(channel); + } + + @Override + public IndexedInts get() + { + return delegate; + } + } } diff --git a/processing/src/main/java/io/druid/segment/data/WritableSupplier.java b/processing/src/main/java/io/druid/segment/data/WritableSupplier.java new file mode 100644 index 00000000000..789f8f13e24 --- /dev/null +++ b/processing/src/main/java/io/druid/segment/data/WritableSupplier.java @@ -0,0 +1,31 @@ +/* + * Licensed to Metamarkets Group Inc. (Metamarkets) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Metamarkets 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. + */ + +package io.druid.segment.data; + +import com.google.common.base.Supplier; + +import java.io.IOException; +import java.nio.channels.WritableByteChannel; + +public interface WritableSupplier extends Supplier +{ + long getSerializedSize(); + void writeToChannel(WritableByteChannel channel) throws IOException; +}