-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from cirnoooo123/main
add secure KNN query framework
- Loading branch information
Showing
6 changed files
with
376 additions
and
11 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
85 changes: 85 additions & 0 deletions
85
core/src/main/java/com/hufudb/openhufu/core/implementor/spatial/knn/BinarySearchKNN.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,85 @@ | ||
package com.hufudb.openhufu.core.implementor.spatial.knn; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.hufudb.openhufu.expression.AggFuncType; | ||
import com.hufudb.openhufu.expression.ExpressionFactory; | ||
import com.hufudb.openhufu.plan.LeafPlan; | ||
import com.hufudb.openhufu.plan.Plan; | ||
import com.hufudb.openhufu.plan.UnaryPlan; | ||
import com.hufudb.openhufu.proto.OpenHuFuData; | ||
import com.hufudb.openhufu.proto.OpenHuFuPlan; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
|
||
public class BinarySearchKNN { | ||
static final Logger LOG = LoggerFactory.getLogger(BinarySearchKNN.class); | ||
|
||
public static Plan generateKNNRadiusQueryPlan(UnaryPlan originalPlan) { | ||
LOG.info("rewriting KNNRadiusQueryPlan"); | ||
LeafPlan originalLeaf = (LeafPlan) originalPlan.getChildren().get(0); | ||
LeafPlan leafPlan = new LeafPlan(); | ||
leafPlan.setTableName(originalLeaf.getTableName()); | ||
OpenHuFuPlan.Expression distance = originalLeaf.getSelectExps() | ||
.get(originalLeaf.getOrders().get(0).getRef()); | ||
leafPlan.setSelectExps(ImmutableList.of(distance)); | ||
leafPlan.setOrders(ImmutableList.of(OpenHuFuPlan.Collation.newBuilder().setRef(0) | ||
.setDirection(OpenHuFuPlan.Direction.ASC).build())); | ||
leafPlan.setOffset(originalLeaf.getFetch() - 1); | ||
leafPlan.setFetch(1); | ||
LOG.info(leafPlan.toString()); | ||
return leafPlan; | ||
} | ||
public static Plan generateDPRangeCountPlan(UnaryPlan originalPlan) { | ||
return null; | ||
} | ||
public static Plan generatePrivacyComparePlan(UnaryPlan originalPlan, double range) { | ||
LOG.info("rewriting PrivacyComparePlan"); | ||
LeafPlan originalLeaf = (LeafPlan) originalPlan.getChildren().get(0); | ||
LeafPlan leafPlan = new LeafPlan(); | ||
leafPlan.setTableName(originalLeaf.getTableName()); | ||
leafPlan.setSelectExps(originalLeaf.getSelectExps()); | ||
OpenHuFuPlan.Expression distance = originalLeaf.getSelectExps() | ||
.get(originalLeaf.getOrders().get(0).getRef()); | ||
OpenHuFuPlan.Expression dwithin = ExpressionFactory.createScalarFunc(OpenHuFuData.ColumnType.BOOLEAN, "dwithin", | ||
ImmutableList.of(distance.getIn(0), | ||
distance.getIn(1), | ||
ExpressionFactory.createLiteral(OpenHuFuData.ColumnType.DOUBLE, range))); | ||
|
||
|
||
List<OpenHuFuPlan.Expression> whereExps = ImmutableList.of(dwithin); | ||
leafPlan.setWhereExps(whereExps); | ||
leafPlan.setAggExps(ImmutableList.of(ExpressionFactory.createAggFunc(OpenHuFuData.ColumnType.LONG, | ||
OpenHuFuData.Modifier.PROTECTED, AggFuncType.COUNT.getId(), ImmutableList.of()))); | ||
leafPlan.setOrders(originalLeaf.getOrders()); | ||
|
||
UnaryPlan unaryPlan = new UnaryPlan(leafPlan); | ||
unaryPlan.setSelectExps(ImmutableList.of(ExpressionFactory | ||
.createInputRef(0, OpenHuFuData.ColumnType.LONG, OpenHuFuData.Modifier.PROTECTED))); | ||
unaryPlan.setAggExps(ImmutableList.of(ExpressionFactory | ||
.createAggFunc(OpenHuFuData.ColumnType.LONG, OpenHuFuData.Modifier.PROTECTED, AggFuncType.SUM.getId(), | ||
ImmutableList.of(ExpressionFactory | ||
.createInputRef(0, OpenHuFuData.ColumnType.LONG, OpenHuFuData.Modifier.PROTECTED))))); | ||
LOG.info(unaryPlan.toString()); | ||
return unaryPlan; | ||
} | ||
public static Plan generateKNNCircleRangeQueryPlan(UnaryPlan originalPlan, double range) { | ||
LeafPlan originalLeaf = (LeafPlan) originalPlan.getChildren().get(0); | ||
LeafPlan leafPlan = new LeafPlan(); | ||
leafPlan.setTableName(originalLeaf.getTableName()); | ||
leafPlan.setSelectExps(originalLeaf.getSelectExps()); | ||
OpenHuFuPlan.Expression distance = originalLeaf.getSelectExps() | ||
.get(originalLeaf.getOrders().get(0).getRef()); | ||
OpenHuFuPlan.Expression dwithin = ExpressionFactory.createScalarFunc(OpenHuFuData.ColumnType.BOOLEAN, "dwithin", | ||
ImmutableList.of(distance.getIn(0), | ||
distance.getIn(1), | ||
ExpressionFactory.createLiteral(OpenHuFuData.ColumnType.DOUBLE, range))); | ||
LOG.info("rewriting KNNCircleRangeQueryPlan"); | ||
List<OpenHuFuPlan.Expression> whereExps = ImmutableList.of(dwithin); | ||
leafPlan.setWhereExps(whereExps); | ||
leafPlan.setOrders(originalLeaf.getOrders()); | ||
LOG.info(leafPlan.toString()); | ||
return leafPlan; | ||
} | ||
} |
Oops, something went wrong.