-
Notifications
You must be signed in to change notification settings - Fork 28k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-12938][SQL] DataFrame API for Bloom filter
This PR integrates Bloom filter from spark-sketch into DataFrame. This version resorts to RDD.aggregate for building the filter. A more performant UDAF version can be built in future follow-up PRs. This PR also add 2 specify `put` version(`putBinary` and `putLong`) into `BloomFilter`, which makes it easier to build a Bloom filter over a `DataFrame`. Author: Wenchen Fan <wenchen@databricks.com> Closes #10937 from cloud-fan/bloom-filter.
- Loading branch information
Showing
7 changed files
with
306 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
common/sketch/src/main/java/org/apache/spark/util/sketch/Utils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.spark.util.sketch; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
|
||
public class Utils { | ||
public static byte[] getBytesFromUTF8String(String str) { | ||
try { | ||
return str.getBytes("utf-8"); | ||
} catch (UnsupportedEncodingException e) { | ||
throw new IllegalArgumentException("Only support utf-8 string", e); | ||
} | ||
} | ||
|
||
public static long integralToLong(Object i) { | ||
long longValue; | ||
|
||
if (i instanceof Long) { | ||
longValue = (Long) i; | ||
} else if (i instanceof Integer) { | ||
longValue = ((Integer) i).longValue(); | ||
} else if (i instanceof Short) { | ||
longValue = ((Short) i).longValue(); | ||
} else if (i instanceof Byte) { | ||
longValue = ((Byte) i).longValue(); | ||
} else { | ||
throw new IllegalArgumentException("Unsupported data type " + i.getClass().getName()); | ||
} | ||
|
||
return longValue; | ||
} | ||
} |
Oops, something went wrong.