Common Query
Function Description
Based on the Lucene syntax, CloudTable term index provides the self-developed query API LemonTable.query(LemonQuery query).
Sample Code
public void testNormalQuery() { LOG.info("Entering testNormalQuery."); try (Table table = conn.getTable(tableName)) { // Using Table instance to create LemonTable. LemonTable lemonTable = new LemonTable(table); // Build LemonQuery. LemonQuery query = LemonQuery.builder() // Set ad-hoc query condition. .setQuery("education:bachelor OR education:master") //(1) // Set how many rows should be cached on client for the initial request. .setCaching(10) //(2) // Set return column family/columns. .addFamily(FAM_M) .addColumn(FAM_N, QUA_N) //(3) // Set return return result just contains rowkeys, no any qualifier // the CF of LemonConstants.EMPTY_COLUMN_RETURN can be a random existing CF //.addColumn(FAM_M, LemonConstants.EMPTY_COLUMN_RETURN) .build(); ResultSet resultSet = lemonTable.query(query); // Read result rows. int count = resultSet.getCount(); LOG.info("the entity count of query is " + count); List<EntityEntry> entries = resultSet.listRows(); for (EntityEntry entry : entries) { Map<String, Map<String, String>> fams = entry.getColumns(); for (Map.Entry<String, Map<String, String>> familyEntry : fams.entrySet()) { String family = familyEntry.getKey(); Map<String, String> qualifiers = familyEntry.getValue(); for (Map.Entry<String, String> qualifier : qualifiers.entrySet()) { String Qua = qualifier.getKey(); String value = qualifier.getValue(); LOG.info("rowkey is " + Bytes.toString(entry.getRow()) + ", qualifier is " + family + ":" + Qua + ", value is " + value); } } } } catch (IOException e) { LOG.error("testNormalQuery failed ", e); } LOG.info("Exiting testNormalQuery."); }
Precautions
"Male ANDMarried AND AGE:25-30 AND BLOOD_TYPE:A" "Male ANDMarried AND (AGE:25-30 OR AGE:30-35)AND BLOOD_TYPE:A"
(2) Indicates the number of rows of data to be returned in the query result.
(3) Indicates which qualifiers are returned in each row of data. If only a column family is set, all columns in the column family are returned.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot