Skip to content

Commit

Permalink
Prepared statement definition for new queries
Browse files Browse the repository at this point in the history
  • Loading branch information
vogti committed Dec 3, 2020
1 parent 6710eb0 commit d29c396
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Map;
import java.util.Random;
import kong.unirest.HttpRequest;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.polypheny.simpleclient.query.CottontailQuery;
import org.polypheny.simpleclient.query.CottontailQuery.QueryType;
import org.polypheny.simpleclient.query.Query;
Expand Down Expand Up @@ -65,9 +66,9 @@ public synchronized Query getNewQuery() {

private static class SimpleKnnIdIntFeatureQuery extends Query {

private static final String SQL_1 = "SELECT id FROM knn_intfeature ORDER BY distance(feature, ARRAY";
private static final String SQL_2 = ", '";
private static final String SQL_3 = "') ASC LIMIT ";
private static final String SQL_1 = "SELECT id FROM knn_intfeature ORDER BY distance(feature, ";
private static final String SQL_2 = ", ";
private static final String SQL_3 = ") ASC LIMIT ";

private final Integer[] target;
private final int limit;
Expand All @@ -84,7 +85,21 @@ public SimpleKnnIdIntFeatureQuery( Integer[] target, int limit, String norm ) {

@Override
public String getSql() {
return SQL_1 + Arrays.toString( target ) + SQL_2 + norm + SQL_3 + limit;
return SQL_1 + "ARRAY" + Arrays.toString( target ) + SQL_2 + "'" + norm + "'" + SQL_3 + limit;
}


@Override
public String getParameterizedSqlQuery() {
return SQL_1 + "?" + SQL_2 + "'" + norm + "'" + SQL_3 + limit;
}


@Override
public Map<Integer, ImmutablePair<DataTypes, Object>> getParameterValues() {
Map<Integer, ImmutablePair<DataTypes, Object>> map = new HashMap<>();
map.put( 1, new ImmutablePair<>( DataTypes.ARRAY_INT, target ) );
return map;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Map;
import java.util.Random;
import kong.unirest.HttpRequest;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.polypheny.simpleclient.query.CottontailQuery;
import org.polypheny.simpleclient.query.CottontailQuery.QueryType;
import org.polypheny.simpleclient.query.Query;
Expand All @@ -14,7 +15,6 @@
import org.vitrivr.cottontail.grpc.CottontailGrpc.Entity;
import org.vitrivr.cottontail.grpc.CottontailGrpc.FloatVector;
import org.vitrivr.cottontail.grpc.CottontailGrpc.From;
import org.vitrivr.cottontail.grpc.CottontailGrpc.IntVector;
import org.vitrivr.cottontail.grpc.CottontailGrpc.Knn;
import org.vitrivr.cottontail.grpc.CottontailGrpc.Knn.Distance;
import org.vitrivr.cottontail.grpc.CottontailGrpc.Projection;
Expand Down Expand Up @@ -66,9 +66,9 @@ public synchronized Query getNewQuery() {

private static class SimpleKnnIdRealFeatureQuery extends Query {

private static final String SQL_1 = "SELECT id FROM knn_realfeature ORDER BY distance(feature, ARRAY";
private static final String SQL_2 = ", '";
private static final String SQL_3 = "') ASC LIMIT ";
private static final String SQL_1 = "SELECT id FROM knn_realfeature ORDER BY distance(feature, ";
private static final String SQL_2 = ", ";
private static final String SQL_3 = ") ASC LIMIT ";

private final Float[] target;
private final int limit;
Expand All @@ -85,7 +85,21 @@ public SimpleKnnIdRealFeatureQuery( Float[] target, int limit, String norm ) {

@Override
public String getSql() {
return SQL_1 + Arrays.toString( target ) + SQL_2 + norm + SQL_3 + limit;
return SQL_1 + "ARRAY" + Arrays.toString( target ) + SQL_2 + "'" + norm + "'" + SQL_3 + limit;
}


@Override
public String getParameterizedSqlQuery() {
return SQL_1 + "?" + SQL_2 + "'" + norm + "'" + SQL_3 + limit;
}


@Override
public Map<Integer, ImmutablePair<DataTypes, Object>> getParameterValues() {
Map<Integer, ImmutablePair<DataTypes, Object>> map = new HashMap<>();
map.put( 1, new ImmutablePair<>( DataTypes.ARRAY_REAL, target ) );
return map;
}


Expand Down

0 comments on commit d29c396

Please sign in to comment.