Creating an OJAI QueryCondition Object

The Java and Python OJAI clients support a QueryCondition interface. After you create a QueryCondition object, call methods in the class to construct your query condition.

Creating a QueryCondition Object

Java OJAI provides a QueryCondition.is() method for specifying query conditions. The method takes three arguments:

  • The field path to apply the condition to
  • The condition operator, represented as a QueryCondition.Op
  • The value to compare the field path against

The field path is either a field in a JSON document, a subfield within a nested document, or an array element. Starting in MapR 6.1, you can also specify a container field path. See OJAI Query Conditions Using Container Field Paths for details.

Depending on the type of the field path, you specify the comparison value as follows:

Scalar Data
You can specify the value using either a Java typed value (for example, int, float, or String) or a Java OJAI object. The API supports the following OJAI types:
  • ODate
  • OInterval
  • OTime
  • OTimestamp
Nested Documents
You can specify only equality and non-equality conditions on nested documents. You specify the nested document using a Java Map object. In the case of equality, all of the fields in the nested document must match. The order of the fields is not relevant.
Arrays
You can specify only equality and non-equality conditions on arrays. You specify an array using a Java List object. In the case of equality, the order of the elements and the element values must match.

In addition to QueryCondition.is(), QueryCondition also supports the following methods:

QueryCondition Method Description
equals()

notequals()

Match for equality or non-equality on nested documents and arrays
in() Search for individual elements in an array
like() Search for string values using SQL LIKE expressions

matches()

Search for string values using regular expressions.

You can use regular expressions that compose the Perl-Compatible Regular Expressions (PCRE) library as well as a subset of the regular expressions that are supported in java.util.regex.pattern. See HBase Java Regular Expressions Support for a list of supported regular expressions.

and() Begins a new AND condition block
or() Begins a new OR condition block
elementAnd() Begins a new elementAnd block. See OJAI Query Condition Operators for a detailed description of this operator.
close() Closes a compound condition block
build() Builds the condition
Note: The material described in this section is a subset of the QueryCondition API. It introduces you to the basics of the API. For the complete API, see the QueryCondition interface.

Python OJAI provides a QueryCondition.is_() method for specifying query conditions. The method takes three arguments:

  • The field path to apply the condition to
  • The condition operator, represented as a QueryConditionOp
  • The value to compare the field path against

The field path is either a field in a JSON document, a sub-field within a nested document, or an array element. Starting in MapR 6.1, you can also specify a container field path. See OJAI Query Conditions Using Container Field Paths for details.

Depending on the type of the field path, you specify the comparison value as follows:

Scalar Data
You can specify the value using either a Python scalar value (for example, int, float, or str) or a Python OJAI object. The API supports the following OJAI types:
  • ODate
  • OInterval
  • OTime
  • OTimestamp
Nested Documents
You can specify only equality and non-equality conditions on nested documents. You specify the nested document using a Python dictionary object. In the case of equality, all of the fields in the nested document must match. The order of the fields is not relevant.
Arrays
You can specify only equality and non-equality conditions on arrays. You specify an array using a Python list object. In the case of equality, the order of the elements and the element values must match.

In addition to QueryCondition.is_(), QueryCondition also supports the following methods:

QueryCondition Method Description
equals_()

not_equals_()

Match for equality or non-equality on nested documents and arrays
in_() Search for individual elements in an array
like_() Search for string values using SQL LIKE expressions

matches_()

Search for string values using regular expressions.

You can use regular expressions that comprise the Perl-Compatible Regular Expressions (PCRE) library as well as a subset of the regular expressions that are supported in java.util.regex.pattern. See HBase Java Regular Expressions Support for a list of supported regular expressions.

and_() Begins a new AND condition block
or_() Begins a new OR condition block
element_and()

Begins a new elementAnd block. See OJAI Query Condition Operators for a detailed description of this operator.

close() Closes a compound condition block
build() Builds the condition
Note:
  • The material described in this section is a subset of the QueryCondition API. It introduces you to the basics of the API. For the complete API, see the QueryCondition interface.
  • The preferred approach for creating query conditions in Python is to create the condition in a JSON format. See Creating an OJAI Query Condition Using a JSON String

C# OJAI provides a QueryCondition.ls() method for specifying query conditions. The method takes three arguments:

  • The field path to apply the condition to
  • The condition operator, represented as a QueryOp
  • The value to compare the field path against

The field path is either a field in a JSON document, a sub-field within a nested document, or an array element. Starting in MapR 6.1, you can also specify a container field path. For details, see OJAI Query Conditions Using Container Field Paths.

Depending on the type of the field path, you specify the comparison value as follows:

Scalar Data
You can specify the value using either a C# scalar value (for example, int, float, or string) or a C# OJAI object. The API supports the following OJAI types:
  • OjaiDate
  • OjaiInterval
  • OjaiTime
  • OjaiTimestamp
Nested Documents
You can specify only equality and non-equality conditions on nested documents. You specify the nested document using a C# object. In the case of equality, all of the fields in the nested document must match. The order of the fields is not relevant.
Arrays
You can specify only equality and non-equality conditions on arrays. You specify an array using a C# list of values of the specified type. In the case of equality, the order of the elements and the element values must match.

In addition to QueryCondition.ls(), QueryCondition also supports the following methods:

QueryCondition Method Description
Condition() Search for values using a specific condition.
Equals()

NotEquals()

Match for equality or non-equality on nested documents and arrays.
Exists()

NotExists()

Search for a field if the given field path exists, or verify that a field path does not exist.
In()

NotIn()

Search for individual elements in an array or verify their absence.
Like()

NotLike()

Search for string values using SQL LIKE expressions or verify they do not match the specified SQL LIKE expression.

Matches()

NotMatches()

Search for string values using regular expressions.

You can use regular expressions that comprise the Perl-Compatible Regular Expressions (PCRE) library, as well as a subset of the regular expressions that are supported in java.util.regex.pattern. For a list of supported regular expressions, see HBase Java Regular Expressions Support.

SizeOf() Search for a value of the specified size. The value must be one of the following types:
  • string
  • binary
  • iDictionary
  • iList

TypeOf()

NotTypeOf()

Search for value of the specified Type or verify its absence.
And() Begins a new AND condition block.
Or() Begins a new OR condition block.
ElementAnd()

Begins a new ElementAnd block. For a detailed description of this operator, see OJAI Query Condition Operators.

Close() Closes a compound condition block.
Build() Builds the condition.
Note:

Go OJAI provides a QueryCondition.ls() function for specifying query conditions. The function takes three arguments:

  • The field path to apply the condition to
  • The condition operator, represented as a QueryOp
  • The value to compare the field path against

The field path is either a field in a JSON document, a sub-field within a nested document, or an array element. Starting in MapR 6.1, you can also specify a container field path. For details, see OJAI Query Conditions Using Container Field Paths.

Depending on the type of the field path, you specify the comparison value as follows:

Scalar Data
You can specify the value using either a Go scalar value (for example, int, float64, or string) or a Go OJAI object. The API supports the following OJAI types:
  • OjaiDate
  • OjaiTime
  • OjaiTimestamp
Nested Documents
You can specify only equality and non-equality conditions on nested documents. You specify the nested document using a Go object. In the case of equality, all of the fields in the nested document must match. The order of the fields is not relevant.
Arrays
You can specify only equality and non-equality conditions on arrays. You specify an array using a Go list of values of the specified type. In the case of equality, the order of the elements and the element values must match.

In addition to QueryCondition.ls(), QueryCondition also supports the following functions:

QueryCondition Function Description

AddCondition()

Search for values using a specific condition.
Equals()

NotEquals()

Match for equality or non-equality on nested documents and arrays.
Exists()

NotExists()

Search for a field if the given field path exists, or verify that it does not exist.
In()

NotIn()

Search for individual elements in an array or verify their absence.
Like()

NotLike()

Search for string values using SQL LIKE expressions or verify they do not match the specified SQL LIKE expression.

Matches()

NotMatches()

Search for string values using regular expressions.

You can use regular expressions that comprise the Perl-Compatible Regular Expressions (PCRE) library, as well as a subset of the regular expressions that are supported in java.util.regex.pattern. For a list of supported regular expressions, see HBase Java Regular Expressions Support.

TypeOf()

NotTypeOf()

Search for value of the specified Type or verify its absence.
And() Begins a new AND condition block.
Or() Begins a new OR condition block.
ElementAnd()

Begins a new ElementAnd block. For a detailed description of this operator, see OJAI Query Condition Operators.

Close() Closes a compound condition block.
Build() Builds the condition.
Note:

Example: Creating a QueryCondition Object

The following example shows how to define a QueryCondition object for this query condition:

(a.b.[0].boolean == false && (a.c.d != 5 || a.b[1].decimal > 1 || a.b[1].decimal < 10))
QueryCondition qc = connection.newCondition()
    .and()
        .is("a.b[0].boolean", Op.EQUAL, false)
        .or()
            .is("a.c.d", Op.NOT_EQUAL, 5)
            .is("a.b[1].decimal", Op.GREATER, 1)
            .is("a.b[1].decimal", Op.LESS, 10)
            .close()
    .close()
    .build();

Pass the QueryCondition object to the Query.where method. For a complete Java code example, see the Java - OJAI QueryCondition Object example at Querying with Conditions.

qc = connection.new_condition()
    .and_()
        .is_('a.b[0].boolean', QueryConditionOp.EQUAL, False)
        .or_()
            .is_('a.c.d', QueryConditionOp.NOT_EQUAL, 5)
            .is_('a.b[1].decimal', QueryConditionOp.GREATER, 1)
            .is_('a.b[1].decimal', QueryConditionOp.LESS, 10)
            .close()
    .close()
    .build()

Pass the QueryCondition object to the Query.where method. For a complete Python code example, see the Python - OJAI QueryCondition Object example at Querying with Conditions.

var condition = connection.NewQueryCondition()
    .And()
        .Is("a.b[0].boolean", QueryOp.EQUAL, false)
        .Or()
            .Is("a.c.d", QueryOp.NOT_EQUAL, 5)
            .Is("a.b[1].decimal", QueryOp.GREATER, 1)
            .Is("a.b[1].decimal", QueryOp.LESS, 10)
            .Close()
    .Close()
    .Build();

Pass the Condition object to the Query.Where method. For a complete C# code example, see the C# - OJAI QueryCondition Object example at Querying with Conditions.

	condition, err := client.MakeCondition(
		client.And(),
			client.Is("a.b[0].boolean", client.EQUAL, false),
			client.Or(),
			    client.Is("a.c.d", client.NOT_EQUAL, 5),
			    client.Is("a.b[1].decimal", client.GREATER, 1),
			    client.Is("a.b[1].decimal", client.LESS, 10),
			client.Close(),
		client.Close())
	condition.Build()

Pass the Condition object to the Query.WhereCondition function. For a complete Go code example, see the Go - OJAI QueryCondition Object example at Querying with Conditions.

Examples: Using the QueryCondition.elementAnd Method

The following example shows how to write the elementAnd condition described at Using elementAnd with Nested Documents, using a QueryCondition object:

QueryCondition qc = connection.newCondition()
    .elementAnd("grades[]")
        .is("course", QueryConditionOp.EQUALS, "history")
        .is("score", QueryConditionOp.EQUALS, 12)
        .close()
    .build();
qc = connection.new_condition()
    .element_and("grades[]")
        .is_("course", QueryConditionOp.EQUALS, "history")
        .is_("score", QueryConditionOp.EQUALS, 12)
        .close()
    .build()
var condition = connection.NewQueryCondition()
    .ElementAnd("grades[]")
        .Is("course", QueryOp.EQUALS, "history")
        .Is("score", QueryOp.EQUALS, 12)
        .Close()
    .Build();
	condition, err := client.MakeCondition(
		client.ElementAnd("grades[]"),
			client.Is("course", client.EQUAL, "history"),
			client.Is("score", client.EQUAL, 12), 
		client.Close())
	condition.Build()

The following code corresponds to the example described at Using elementAnd with Scalar Values using a QueryCondition object:

QueryCondition qc = connection.newCondition()
    .elementAnd("values[]")
        .is("$", QueryConditionOp.GREATER, 7)
        .is("$", QueryConditionOp.LESS, 14)
        .close()
    .build();
qc = connection.new_condition()
    .element_and("values[]")
        .is_("$", QueryConditionOp.GREATER, 7)
        .is_("$", QueryConditionOp.LESS, 14)
        .close()
    .build()
var condition = connection.NewQueryCondition()
    .EementAnd("values[]")
        .Is("$", QueryOp.GREATER, 7)
        .Is("$", QueryOp.LESS, 14)
        .Close()
    .Build();
	condition, err := client.MakeCondition(
		client.ElementAnd("values[]"),
			client.Is("$", client.EQUAL, 7),
			client.Is("$", client.EQUAL, 14), 
		client.Close())
	condition.Build()