@@ -70,7 +70,7 @@ public CosmosSqlQuerySpec toQuerySpec(AtomicInteger paramIndex) {
7070 // fullName.last -> @param001_fullName__last
7171 // or
7272 // "829cc727-2d49-4d60-8f91-b30f50560af7.name" -> @param001_wg31gsa.name
73- var paramName = getParamNameFromKey (this .key , paramIndex .get ());
73+ var paramName = getParamNameFromKey (this .key , paramIndex .getAndIncrement ());
7474
7575 var paramValue = this .value ;
7676
@@ -88,7 +88,6 @@ public CosmosSqlQuerySpec toQuerySpec(AtomicInteger paramIndex) {
8888 // array equals or not
8989 if (Set .of ("=" , "!=" ).contains (this .operator )) {
9090 // use = or !=
91- paramIndex .getAndIncrement ();
9291 ret .setQueryText (String .format (" (%s %s %s)" , Condition .getFormattedKey (this .key ), this .operator , paramName ));
9392 params .add (Condition .createSqlParameter (paramName , paramValue ));
9493 } else {
@@ -99,32 +98,41 @@ public CosmosSqlQuerySpec toQuerySpec(AtomicInteger paramIndex) {
9998 ret .setQueryText (" (1=0)" );
10099 } else {
101100 // use ARRAY_CONTAINS by default to minimize the sql length
102- paramIndex .getAndIncrement ();
103101 ret .setQueryText (buildArrayContains (this .key , paramName , coll , params ));
104102 }
105103 }
106104
107105 } else {
108- // single param value
106+ // single param value
109107
110- if (StringUtils .isEmpty (this .operator )) {
111- // set the default operator for scalar value
112- this .operator = "=" ;
113- }
108+ if (StringUtils .isEmpty (this .operator )) {
109+ // set the default operator for scalar value
110+ this .operator = "=" ;
111+ }
112+
113+ // paramName or fieldName
114+ var valuePart = "" ;
115+
116+ if (paramValue instanceof FieldKey ) {
117+ // valuePart should be "mail2" for "c.mail != c.mail2"
118+ valuePart = Condition .getFormattedKey (((FieldKey ) paramValue ).keyName );
119+ } else {
120+ // valuePart should be "@param001_wg31gsa"
121+ valuePart = paramName ;
122+ params .add (Condition .createSqlParameter (paramName , paramValue ));
123+ }
114124
115- paramIndex .getAndIncrement ();
116- // other types
117- var formattedKey = Condition .getFormattedKey (this .key );
125+ // other types
126+ var formattedKey = Condition .getFormattedKey (this .key );
118127 if (this .type == OperatorType .BINARY_OPERATOR ) { // operators, e.g. =, !=, <, >, LIKE
119128 //use c["key"] for cosmosdb reserved words
120- ret .setQueryText (String .format (" (%s %s %s)" , formattedKey , this .operator , paramName ));
129+ ret .setQueryText (String .format (" (%s %s %s)" , formattedKey , this .operator , valuePart ));
121130 } else if (Condition .typeCheckFunctionPattern .asMatchPredicate ().test (this .operator )) { // type check funcs: IS_DEFINED|IS_NUMBER|IS_PRIMITIVE, etc
122- ret .setQueryText (String .format (" (%s(%s) = %s)" , this .operator , formattedKey , paramName ));
131+ ret .setQueryText (String .format (" (%s(%s) = %s)" , this .operator , formattedKey , valuePart ));
123132 } else { // other binary funcs. e.g. STARTSWITH, CONTAINS, ARRAY_CONTAINS
124- ret .setQueryText (String .format (" (%s(%s, %s))" , this .operator , formattedKey , paramName ));
133+ ret .setQueryText (String .format (" (%s(%s, %s))" , this .operator , formattedKey , valuePart ));
125134 }
126135
127- params .add (Condition .createSqlParameter (paramName , paramValue ));
128136 }
129137
130138 ret .setParameters (params );
0 commit comments