-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
12 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
82 changes: 82 additions & 0 deletions
82
src/main/java/org/polypheny/simpleclient/scenario/knnbench/queryBuilder/SimpleMetadata.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,82 @@ | ||
package org.polypheny.simpleclient.scenario.knnbench.queryBuilder; | ||
|
||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Random; | ||
import kong.unirest.HttpRequest; | ||
import org.apache.commons.lang3.tuple.ImmutablePair; | ||
import org.polypheny.simpleclient.query.Query; | ||
import org.polypheny.simpleclient.query.QueryBuilder; | ||
|
||
|
||
public class SimpleMetadata extends QueryBuilder { | ||
|
||
private static final boolean EXPECT_RESULT = true; | ||
|
||
private final long randomSeed; | ||
private final int numOfEntries; | ||
|
||
private final Random random; | ||
|
||
|
||
public SimpleMetadata( long randomSeed, int numOfEntries ) { | ||
this.randomSeed = randomSeed; | ||
this.numOfEntries = numOfEntries; | ||
|
||
this.random = new Random( randomSeed ); | ||
} | ||
|
||
|
||
private int getRandomId() { | ||
return this.random.nextInt( this.numOfEntries ); | ||
} | ||
|
||
|
||
@Override | ||
public Query getNewQuery() { | ||
return new SimpleMetadataQuery( this.getRandomId() ); | ||
} | ||
|
||
|
||
private static class SimpleMetadataQuery extends Query { | ||
|
||
private static final String SQL = "SELECT id, textdata FROM knn_metadata WHERE id = "; | ||
|
||
private final int id; | ||
|
||
|
||
private SimpleMetadataQuery( int id ) { | ||
super( EXPECT_RESULT ); | ||
this.id = id; | ||
} | ||
|
||
|
||
@Override | ||
public String getSql() { | ||
return SQL + id; | ||
} | ||
|
||
|
||
@Override | ||
public String getParameterizedSqlQuery() { | ||
return SQL + "?"; | ||
} | ||
|
||
|
||
@Override | ||
public Map<Integer, ImmutablePair<DataTypes, Object>> getParameterValues() { | ||
Map<Integer, ImmutablePair<DataTypes, Object>> map = new HashMap<>(); | ||
map.put( 1, new ImmutablePair<>( DataTypes.INTEGER, id ) ); | ||
return map; | ||
} | ||
|
||
|
||
@Override | ||
public HttpRequest<?> getRest() { | ||
return null; | ||
} | ||
|
||
} | ||
|
||
} |