Query Expressions
Query expressions are used to retrieve and aggregate values from collections. Their semantics is essentially the same as SQL query semantics. A query expression evaluates to a collection, object, string, number, or boolean value.
Each query expression has the following form:
select [distinct] <select-specification>
from <identifier> [ [as] <simple-identifier>]
[where <boolean-expr>]
[group by <arithmetic-expr>[, <arithmetic-expr>]*]
[order by <arithmetic-expr> [asc | desc][, <arithmetic-expr> [asc | desc]]*]
Select clause
Each select-specification has the following form:
{<select-arg> | <simple-identifier>(<select-arg>)}
Here the simple-identifier names one of the following query aggregate functions:
first: returns the first element of the intermediate query results.
last: returns the last element of the intermediate query results.
sum: returns the sum of the values in the intermediate query results.
min: returns the smallest value in the intermediate query results.
max: returns the largest value in the intermediate query results.
count: returns the number of elements in the intermediate query results.
Each select-arg is one of the following:
*
<complex-identifier>
Note that select-arg can be the name of a formula whose right hand side includes occurrences of the from clause’s simple-identifier. See From clause for information on the from clause.
From clause
The identifier in the select clause must evaluate to the collection to be queried. Note that tables in CSL are represented as collections whose elements are objects with one field for each table column.
The simple-identifier in the select clause is an alias for a single element in the collection being queried. It can occur in the following components of the query expression:
select-specification in the select clause
boolean-expression in the where clause
arithmetic-expressions in the group by clause
arithmetic-expressions in the order by clause
This alias can also occur in the right hand side of formulas whose evaluation is necessitated by evaluation of expressions in the query. The simple-identifier is has file scope.
Examples
numManualMigWelds = _
select count(w) from welds w _
where w.type != 'Spot' and not w.isRobotic
 
componentMass = _
select sum(c.weight) from part.subcomponents c
 
finishMass = _
select sum(w.weldWeight) from childOps w _
where isWeld(w)
 
weldWeight = _
select sum(op.weldWeight) from childOps op
 
numCostableWelds = _
select count(a) from part.childArtifacts a _
where isWeld(a) and a.costable
 
computedClampTime = _
select first(entry.loadTime) from xtraLoadTime entry _
where entry.weight >=gcd.weight _
order by entry.loadTime // time (secs) for load part
coreboxCostVoids =
select sum(operation.hardToolingCost) from childOps operation _
where operation.artifactType.name =='Void' _
group by _
adaptiveRound(operation.volume, _
voxelVolumeError(voidCoreArea(operation))), _
adaptiveRound(operation.boxLength, voxelLengthError), _
adaptiveRound(operation.boxWidth,voxelLengthError), _
adaptiveRound(operation.boxHeight,voxelLengthError)