To query HPE Ezmeral Data Fabric Database JSON tables in your OJAI
applications, you use the OJAI Query interface. The typical flow of
your application involves creating a connection, obtaining a handle to the HPE Ezmeral Data Fabric Database JSON table you want to query, constructing the
query, performing the query, and then processing the results.
The DocumentStore interface includes a
Query interface. The Query
interface allows you to build a query programmatically.
To construct an OJAI query, call the following
methods in the Query
interface:
To run the query, pass the
Query object to the DocumentStore.find method.
To construct an OJAI query, create a Node.js JSON object using OJAI Query Syntax.
To run the query, pass the
Query object to the DocumentStore.find method.
To construct an OJAI query, create a Python dictionary object using OJAI Query Syntax.
To run the query, pass the
Query object to the DocumentStore.find method.
Query methods
are available in the Python OJAI API, but creating
a Python dictionary is the preferred approach:
To construct an OJAI query, create a C# object.
To run the query, pass the
Query object to the DocumentStore.Find method.
Query methods
are available in the C# OJAI API:
To construct an OJAI query, create a Go object.
To run the query, pass the
Query object to the
DocumentStore.FindQuery
function.
Query functions
are available in the Go OJAI API:
The following steps describe the basics in developing client applications that query HPE Ezmeral Data Fabric Database JSON tables using the OJAI API.
Connection connection = DriverManager.getConnection("ojai:mapr:");DocumentStore store = connection.getStore(tablePath);
Query query = connection.newQuery();
QueryResult result = store.find(query);
The following code snippet iterates through the QueryResult and prints each document as a JSON string:
for (final Document userDocument : result) {
// Print the OJAI Document
System.out.println(userDocument.asJsonString());
}Iterable it = result.documentReaders();
for (DocumentReader reader : it) {
EventType et = null;
while ((et = reader.next()) != null) {
if (et == EventType.STRING) {
System.out.println("Value of field " + reader.getFieldName() + ": " + reader.getString());
}
}
}result.close(); store.close; connection.close();
ConnectionManager.getConnection('localhost:5678?;user=mapr;password=mapr;ssl=false')
.then((connection) => {
// Process connection
...
});connection.getStore(tablePath)
.then((store) => {
// Process store
...
});const query = {};const stream = store.find(query)
stream.on('data', (document) => console.log(document));stream.on('end', () => { console.log('end'); connection.close(); });
ConnectionFactory
class:connection_str = 'localhost:5678?;user=mapr;password=mapr;ssl=false'
connection = ConnectionFactory.get_connection(connection_str=connection_str)store = connection.get_store(table_path)
query = connection.new_query().build()
query_result = store.find(query)
The following code snippet iterates through the QueryResult and prints each document as a Python dictionary:
for doc in query_result:
print(doc)connection.close()
Connection instance to your MapR
cluster using the
ConnectionFactory
class:var connectionStr = $"localhost:5678?auth=basic;" + $"user=mapr;" + $"password=mapr;" + $"ssl=true;" + $"sslCA=/opt/mapr/conf/ssl_truststore.pem;" + $"sslTargetNameOverride=node1.mapr.com"; var connection = ConnectionFactory.CreateConnection(connectionStr);
DocumentStore handle to a
HPE Ezmeral Data Fabric Database JSON table
using the connection
object:var store = connection.GetStore(storePath);
Query object using the connection
object:var query = connection.NewQuery().Build();
var queryResult = store.Find(query);
The following code
snippet iterates through the QueryResult and prints each
document as a
JSON:
var documentStream = await queryResult.GetDocumentAsyncStream().GetAllDocuments();
foreach (var document in documentStream)
{
Console.WriteLine(document.ToJsonString());
}
connection.Close();
Connection instance to your MapR
cluster:connectionString := "localhost:5678?auth=basic;user=mapr;password=mapr;ssl=false"
connection, error := client.MakeConnection(connectionString)DocumentStore handle to a
HPE Ezmeral Data Fabric Database JSON table
using the connection
object:store, error := connection.CreateStore("/store_path")query, err := client.MakeQuery() query.Build()
queryResult, err := store.FindQuery(query, &client.FindOptions{})The following code snippet iterates through the QueryResult and prints each document as a JSON:
for _, doc := range queryResult.DocumentList() {
fmt.Println(doc)
}connection.Close()
See Examples: Querying JSON Documents for complete code examples.