QuerySome
Used to iterate over a query and test whether ANY items meet the test callback.
The function will be passed 3 arguments: the row, the currentRow, and the query. You can alternatively pass a Java Predicate which will only receive the 1st arg. The function should return true if the item meets the test, and false otherwise.
Note: This operation is a short-circuit operation, meaning it will stop iterating as soon as it finds the first item that meets the test condition.
Parallel Execution
If the parallel
argument is set to true, and no max_threads
are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams.
If max_threads
is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete.
Please note that this may not be the most efficient way to iterate, as it will create a new ForkJoinPool for each invocation of the BIF. You may want to consider using a shared ForkJoinPool for better performance.
Method Signature
QuerySome(query=[query], callback=[function:Predicate], parallel=[boolean], maxThreads=[integer])
Arguments
query
query
true
The query to iterate over
callback
function:Predicate
true
The function to invoke for each item. The function will be passed 3 arguments: the row, the currentRow, the query.
parallel
boolean
false
Whether to run the filter in parallel. Defaults to false. If true, the filter will be run in parallel using a ForkJoinPool.
false
maxThreads
integer
false
The maximum number of threads to use when running the filter in parallel. If not passed it will use the default number of threads for the ForkJoinPool. If parallel is false, this argument is ignored.
Examples
The simple Querysome example
Here,we've example to check whether the 75 is exists or not in myquery mark column value.
<bx:script>
myQuery = queryNew( "id,name,mark", "integer,varchar,integer", [
[
1,
"Rahu",
75
],
[
2,
"Ravi",
80
]
] );
result = querySome( myQuery, ( Any details ) => {
return details.MARK == 75;
} );
writeOutput( (result ? "Some" : "No") & " matches Record found!" );
</bx:script>
Result: Some matches Record found!
The Query Member Function example
Here,we've example to check whether the 85 is exists or not in myquery mark column value using query member function.
<bx:script>
myQuery = queryNew( "id,name,mark", "integer,varchar,integer", [
[
1,
"Rahu",
75
],
[
2,
"Ravi",
80
]
] );
result = myQuery.Some( ( Any details ) => {
return details.MARK == 85;
} );
writeOutput( (result ? "Some" : "No") & " matches Record found!" );
</bx:script>
Result: No matches Record found!
Additional Examples
people = QueryNew( "name,dob,age", "varchar,date,int", [
[
"Susi",
CreateDate( 1970, 1, 1 ),
0
],
[
"Urs",
CreateDate( 1995, 1, 1 ),
0
],
[
"Fred",
CreateDate( 1960, 1, 1 ),
0
],
[
"Jim",
CreateDate( 1988, 1, 1 ),
0
]
] );
valid = querySome( people, ( Any row, Any rowNumber, Any qryData ) => {
return ((DateDiff( "yyyy", row.DOB, Now() ) > 0) && (DateDiff( "yyyy", row.DOB, Now() ) <= 100));
} );
writeDump( valid );
Related
Last updated
Was this helpful?