Add index to relation in ELKI - java

I am trying to add index to relation in db, but don't know is it right?
ListParameterization spatparams = new ListParameterization();
spatparams.addParameter(INDEX_ID, RStarTreeFactory.class);
spatparams.addParameter(AbstractPageFileFactory.Parameterizer.PAGE_SIZE_ID, 300);
spatparams.addParameter(AbstractRStarTreeFactory.Parameterizer.INSERTION_STRATEGY_ID, ApproximativeLeastOverlapInsertionStrategy.class);
spatparams.addParameter(ApproximativeLeastOverlapInsertionStrategy.Parameterizer.INSERTION_CANDIDATES_ID, 1);
// Adapter to load data from an existing array.
DatabaseConnection dbc = new ArrayAdapterDatabaseConnection(data);
// Create a database (which may contain multiple relations!)
Collection<IndexFactory<?, ?>> indexFactories = new ArrayList<>();
ObjectListParameter<IndexFactory<?, ?>> indexFactoryP = new ObjectListParameter<>(INDEX_ID, IndexFactory.class, true);
indexFactories.addAll(indexFactoryP.instantiateClasses(spatparams));
Database db = new StaticArrayDatabase(dbc, indexFactories);
db.initialize();

To instantiate a class via the parameterization API, you don't need to create a new parameter.
RStarTreeFactory<DoubleVector> f =
ClassGenericsUtil.parameterizeOrAbort(RStarTreeFactory.class, params);
For the R-star tree, I suggest to use SortTileRecursive bulk loading.

Related

How to distinct query in MongoDB with projection and filters?

I have list of attributes in mongo and I am querying some nested field. Here is my code,
public List<Brand> searchBrands(Request request) {
final MongoCollection<Document> collection = mongoDatabase.getCollection("shop");
final Document query = new Document();
final Document projection = new Document();
final List<Brand> brandList = new ArrayList<>();
query.append("_id", request.getId());
query.append("isActive", true);
if (request.Year() != null) {
query.append("attributes.name", "myYear");
query.append("attributes.value", request.getYear());
}
projection.append("brand.code", 1.0);
projection.append("brand.description", 1.0);
projection.append("_id", 0.0);
Block<Document> processBlock = document -> brandList.
add(Brand.builder().code(document.get("brand",Document.class).getString("code"))
.description(document.get("brand",Document.class).getString("description"))
.build());
collection.find(query).projection(projection).forEach(processBlock);
return brandList;}
Above code return results correctly, 72 item with same brand.code. But I want to fetch distinct according to brand.code How can I do that?
I'm not sure which mongodb client library you're using to create queries for mongodb;
I'm sharing the query that you can run in mongodb console to get the results you want. I hope you know how to create this query using your mongodb client library
db.shop.distinct('brand.code', myQuery)
//Replace myQuery with your query e.g. {isActive: true}

How to extract only one value from mongoDB?

LIKE I HAVE THREE FIELD 'TO','FROM' AND 'MESSAGE', I just want to display content of message field where I have given some clause in to and from.
Document{{_id=59c7d57c674cd5673c304936, to=9915103230, from=9915103229, date=24/12/2017, message=HELLO WORLD}}
I JUST WANT TO RETRIEVE "HELLO WORLD", not the whole document.
Like I just want, String message=?????---> I need some method here so the Variable of String type gets the value Hello World.
Projection method is not working for me.
I am using JDBC MongoDB 3.5 Driver.
Use projection, the second optional argument to find(). For context, this gives you the whole document:
db.yourCollection.find({to:9915103230,from:9915103229});
This gives you only message from the results. Just name the field and set it to 1:
db.yourCollection.find({to:9915103230,from:9915103229},{message:1};
You can specify more than one thing to return:
db.yourCollection.find({to:9915103230,from:9915103229},{message:1, to:1};
Here's a functioning prog. Compile against the 3.5 drivers.
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase( "testX" );
MongoCollection<BsonDocument> coll = db.getCollection("foo", BsonDocument.class);
coll.drop();
{
BsonDocument doc = new BsonDocument();
doc.put("from", new BsonInt32(23343223));
doc.put("to", new BsonInt32(23343223));
doc.put("msg", new BsonString("hello"));
coll.insertOne(doc);
doc.remove("_id");
doc.put("from", new BsonInt32(8889));
doc.put("to", new BsonInt32(99999));
doc.put("msg", new BsonString("goodbye"));
coll.insertOne(doc);
}
{
BsonDocument query = new BsonDocument("from", new BsonInt32(8889));
BsonDocument proj = new BsonDocument("msg", new BsonInt32(1));
proj.put("_id",new BsonInt32(0));
BsonDocument d2 = coll.find(query).projection(proj).first();
System.out.println(d2);
String s2 = coll.find(query).projection(proj).first().getString("msg").getValue();
System.out.println(s2);
}

How to read a table from dynamodb using Java?

I created a table in Amazon dynamodb with primary key Issue(String) which has data stored in it.I want to read the values from my table. I'm using the following code..
#DynamoDBTable(tableName="Incident")
AmazonDynamoDBClient dynamoDBClient = new AmazonDynamoDBClient();
String tableName = "Incident";
Table table = dynamoDBClient.getTable("Incident");
Item getItem=dynamoDBClient.getItem();
I'm getting an error when calling the getTable method.... is it a predefined method just like createTable() or do we need to write our own..if so how?
And also what method should be used to read all items in the table..?
I used this link to write some of the code... http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/JavaDocumentAPIItemCRUD.html#JavaDocumentAPIGetItem
I'm new to Java please help..
Scan API can be used to get all the items from the table.
The scan should be done until LastEvaluatedKey is not null which is very important to get all the items. Otherwise, you will not get all the items if the table has many items i.e. the API will return 1 MB of data per scan.
A Scan operation performs eventually consistent reads by default, and
it can return up to 1 MB (one page) of data.
Scan API
Map<String, AttributeValue> lastKeyEvaluated = null;
do {
ScanRequest scanRequest = new ScanRequest()
.withTableName("ProductCatalog")
.withLimit(10)
.withExclusiveStartKey(lastKeyEvaluated);
ScanResult result = client.scan(scanRequest);
for (Map<String, AttributeValue> item : result.getItems()){
printItem(item);
}
lastKeyEvaluated = result.getLastEvaluatedKey();
} while (lastKeyEvaluated != null);
Here is example how to read data using Scan API :
#Override
protected ArrayList<String> doInBackground(String... params) {
String tableName = params[0];
ArrayList<String> tempList = new ArrayList<String>();
AmazonDynamoDBClient dynamoDBClient = new AmazonDynamoDBClient (
new BasicAWSCredentials(Constants.ACCESS_KEY_ID,
Constants.SECRET_KEY));
ScanRequest scanRequest = new ScanRequest()
.withTableName(tableName);
//.withAttributesToGet("name");
com.amazonaws.services.dynamodb.model.ScanResult result = dynamoDBClient.scan(scanRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
tempList.add(item.toString());
//analizeItem(tempList, item);
}
return tempList;
}
Reference from programcreeks
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withRegion(Regions.AP_SOUTH_1).build();
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("Student");
Item item = table.getItem("PK", "portion Key","SK","Sort Key");
System.out.println(item.toJSONPretty());

search Hbase record using java API?

I want to search record base on value and my application in Java
I am store record using below code
HTable table = new HTable(conf, tableName);
Put put = new Put(Bytes.toBytes(rowKey));
put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier),
Bytes.toBytes(value));
table.put(put);
I pass values
Put put = new Put(Bytes.toBytes("rowkey"));
put.add(Bytes.toBytes("family1"), Bytes.toBytes("qualifier1"),
Bytes.toBytes("this is test record"));
this is my get implementation
Get get = new Get(Bytes.toBytes("rowkey"));
String[] family = { "row1" };
get.addColumn(Bytes.toBytes("family1"),Bytes.toBytes("qualifier1"));
Result rs = table.get(get);
now I want to search this record by "this is test record" value.
help me to found this record.
using filter you can do search on any of the element and you can pass different combination
for SubstringComparator BinaryComparator
FilterList flist = new FilterList();
flist.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("Predicatevalue"))));
flist.addFilter(new QualifierFilter(CompareOp.EQUAL,new BinaryComparator(Bytes.toBytes("Subject value"))));
flist.addFilter(new ValueFilter(CompareOp.EQUAL,new BinaryComparator(Bytes.toBytes("Objectvalue"))));
This work for me.
Look at the get() method on HTable and the Get class, which are analogous to the put() method on HTable and the Put class.

How add mapping to existing dynamictype in helper - EclipseLink

I'm creating a dynamic class in EclipseLink, but after created can not add a new field to my class.
When I add a new field, eclipselink creates a column in the table but when trying to set the value in this column the EntityManager can not salver and puts NULL.
How do I add a new field to my DynamicType after adding it in JPADynamicHelper?
DynamicClassLoader dcl = new DynamicClassLoader(Thread.currentThread().getContextClassLoader());
Class<?> exClass= dcl.createDynamicClass(packagePrefix + "Example");
JPADynamicTypeBuilder exBuilder= new JPADynamicTypeBuilder(doClass, null, "Example");
// configure builber
exBuilder.setPrimaryKeyFields("ID");
exBuilder.addDirectMapping("id", int.class, "ID");
exBuilder.addDirectMapping("name", String.class, "NAME");
// configure descriptor
ClassDescriptor exDescriptor = exBuilder.getType().getDescriptor();
//configure sequence id
exBuilder.configureSequencing("DYNAMIC_SEQ", "ID");
// EntityManagerFactory
emf = createEntityManagerFactory(dcl, "default");
JPADynamicHelper helper = new JPADynamicHelper(emf);
//Here I add the helper type
helper.addTypes(true, true, exBuilder.getType());
// Create tables and relationship
new SchemaManager(helper.getSession()).extendDefaultTables(true);
//Adding a new field
exBuilder.addDirectMapping("id", int.class, "ID");
//here I add the helper again but do not add
helper.addTypes(true, true, exBuilder.getType());
Can anyone help me?
Try adding the new field before calling createEntityManagerFactory().

Categories

Resources