Set Operators in esProc

Uncategorized 950 0

Since sets are commonly used in esProc, the latter provides comprehensive set operations.

1.Binary Operation on Sets

The most basic set in esProc is sequence. Let’s look at some basic binary operations between two sequences A and B.

  • A|B

Concatenate: Concatenate the two sequence straightforwardly, of which the member of B is added behind the members of A. If A or B or both A and B are the single-value member instead of sequence, then it will be handled as a single member sequence.

  • A&B

Union: Join the two sets and remove the members of B that already exist in A. If one of A and B or both vales are the single-value member instead of sequence, then you can take it as single member sequence to process.

  • A^B

Intersection: Intersection set of A and B. Get a sequence composed of members that not only exist in A but also exist in B.

  • A\B

Complement: Members in A but not in B. If B is not a sequence, then treat it as the single member sequence.

  • k*A

A|A|…|A, copy A for k times, positions of k and A are interchangeable in the expression.

esProc_set_operator_1

These basic operations – concatenate, complement, intersection and union – can also be used to deal with more complex set operations. Such as, to seek the “inverse intersection” of sets A and B, i.e., the set composed of all that is not the common members of A and B.

esProc_set_operator_2

The “inverse intersection” of two sets is the complement of their union and intersection. With this kind of transformation, more complex binary operations will be completed.

2. Alignment Arithmetic Operation on Sets

Two sequences which have the same length will perform the alignment computation on members, and return a new sequence.

  • A++B

[A(1)+B(1),A(2)+B(2),…]

  • A–B

[A(1)-B(1),A(2)-B(2),…]

  • A**B

[A(1)*B(1),A(2)*B(2),…]

  • A//B

[A(1)/B(1),A(2)/B(2),…]

  • A%%B

[A(1)%B(1),A(2)%B(2),…], the % here is the Mod computation.

  • A\\B

[A(1)\B(1),A(2)\B(2),…], the slash here means integer division

esProc_set_operator_3

3.Comparison of Sets

In esProc, the function cmp(A,B) can be used to compare the sequence A and B.

  • cmp(A,B)

Compare the member values of two sequences at the same location one by one, and return the 1 or -1 when encountering the first unequal member, if A is identical to B, then return 0. Specifically, cmp(A) or cmp(A,0) will compare A with the sequence with the same length and members are all 0, i.e. cmp(A,[0,0,…,0]).

esProc_set_operator_4

Comparison of two sequences can be briefly expressed as A==B, A>B.

Note that a sequence in esProc is an ordered set, so order plays an important role in comparing the size of two sequences A and B. A.eq(B) is used to see if the two sequences have common members.

esProc_set_operator_5

Because the member order in A1 and A2 is different, result in A3 is false, showing the two sequences are not equal. While result in A4 is true, showing the two sequences have the same members. 

 
Related:
The Disadvantages of SQL Computation (I), (II) ,(III)

Thinking of Set in esProc

 Thinking of Serial Number and Locating Computation in esProc

 Referencing Thoughts in esProc

Concepts of esProc Sequence, Table Sequence and Record Sequence

FAVOR (0)
Leave a Reply
Cancel
Icon

Hi,You need to fill in the Username and Email!

  • Username (*)
  • Email (*)
  • Website