asdf2014 commented on a change in pull request #6904: add bloom filter druid 
expression
URL: https://github.com/apache/incubator-druid/pull/6904#discussion_r250488834
 
 

 ##########
 File path: 
extensions-core/druid-bloom-filter/src/main/java/org/apache/druid/query/expressions/BloomFilterExprMacro.java
 ##########
 @@ -0,0 +1,124 @@
+/*
+ * 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.
+ */
+
+package org.apache.druid.query.expressions;
+
+import com.google.common.io.BaseEncoding;
+import org.apache.druid.guice.BloomFilterSerializersModule;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.math.expr.Expr;
+import org.apache.druid.math.expr.ExprEval;
+import org.apache.druid.math.expr.ExprMacroTable;
+import org.apache.druid.math.expr.ExprType;
+import org.apache.druid.query.filter.BloomKFilter;
+
+import javax.annotation.Nonnull;
+import java.io.IOException;
+import java.util.List;
+
+public class BloomFilterExprMacro implements ExprMacroTable.ExprMacro
+{
+  public static String FN_NAME = "bloom_filter_test";
+
+  @Override
+  public String name()
+  {
+    return FN_NAME;
+  }
+
+  @Override
+  public Expr apply(List<Expr> args)
+  {
+    if (args.size() != 2) {
+      throw new IAE("Function[%s] must have 2 arguments", name());
+    }
+
+    final Expr arg = args.get(0);
+    final Expr filterExpr = args.get(1);
+
+    if (!filterExpr.isLiteral() || filterExpr.getLiteralValue() == null) {
+      throw new IAE("Function[%s] second argument must be a base64 serialized 
bloom filter", name());
+    }
+
+
+    final String serializedFilter = filterExpr.getLiteralValue().toString();
+    final byte[] decoded = BaseEncoding.base64().decode(serializedFilter);
 
 Review comment:
   Maybe use `java.util.Base64.getDecoder().decode(serializedFilter)` is a 
better choice..
   
   FYI, I found some 
[benchmark](http://java-performance.info/base64-encoding-and-decoding-performance/)
 results using the initial Java 8 release on the Xeon [email protected] Ghz
   
   | Name          | Encode, 100 bytes | Decode, 100 bytes | Encode, 1000 bytes 
| Decode, 1000 bytes | Encode, 200000000 bytes | Decode, 200000000 bytes |
   | ------------- | ----------------- | ----------------- | ------------------ 
| ------------------ | ----------------------- | ----------------------- |
   | JavaXmlImpl   | 0.721 sec         | 1.067 sec         | 0.664 sec          
| 0.947 sec          | 0.689 sec               | 0.885 sec               |
   | Java8Impl     | 0.808 sec         | 1.101 sec         | 0.712 sec          
| 0.913 sec          | 0.699 sec               | 0.887 sec               |
   | MiGBase64Impl | 0.887 sec         | 2.113 sec         | 0.788 sec          
| 1.978 sec          | 0.812 sec               | 1.928 sec               |
   | IHarderImpl   | 1.179 sec         | 2.645 sec         | 1.012 sec          
| 2.439 sec          | 0.976 sec               | 2.431 sec               |
   | ApacheImpl    | 4.113 sec         | 4.733 sec         | 2.308 sec          
| 2.667 sec          | 2.205 sec               | 2.552 sec               |
   | GuavaImpl     | 3.305 sec         | 4.178 sec         | 3.12 sec           
| 3.755 sec          | 3.102 sec               | 3.744 sec               |
   | SunImpl       | 11.153 sec        | 8.281 sec         | 3.992 sec          
| 4.533 sec          | 3.289 sec               | 4.096 sec               |

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to