Skip to content

Commit

Permalink
chore: add quotes around default aliases in postgres collection (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
saxenakshitiz authored Jul 13, 2023
1 parent 1f5a02b commit fb5e855
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ public static String getSelections(PostgresQueryParser postgresQueryParser) {
private static String getAlias(
SelectionSpec selectionSpec,
PostgresIdentifierExpressionVisitor identifierExpressionVisitor) {
return !StringUtils.isEmpty(selectionSpec.getAlias())
? PostgresUtils.wrapAliasWithDoubleQuotes(selectionSpec.getAlias())
: PostgresUtils.encodeAliasForNestedField(
selectionSpec.getExpression().accept(identifierExpressionVisitor));
return PostgresUtils.wrapAliasWithDoubleQuotes(
!StringUtils.isEmpty(selectionSpec.getAlias())
? selectionSpec.getAlias()
: PostgresUtils.encodeAliasForNestedField(
selectionSpec.getExpression().accept(identifierExpressionVisitor)));
}

private static void memorizedSelectionForUserDefinedAlias(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ void testUpdateAtomicWithFilter() throws IOException, SQLException {
final String selectQuery =
String.format(
"SELECT "
+ "document->'quantity' AS quantity, "
+ "document->'price' AS price, "
+ "document->'date' AS date, "
+ "document->'props' AS props, "
+ "document->'quantity' AS \"quantity\", "
+ "document->'price' AS \"price\", "
+ "document->'date' AS \"date\", "
+ "document->'props' AS \"props\", "
+ "id AS _implicit_id "
+ "FROM %s "
+ "WHERE (document->>'item' = ?) "
Expand Down Expand Up @@ -188,10 +188,10 @@ void testUpdateAtomicWithFilter_getNone() throws IOException, SQLException {
final String selectQuery =
String.format(
"SELECT "
+ "document->'quantity' AS quantity, "
+ "document->'price' AS price, "
+ "document->'date' AS date, "
+ "document->'props' AS props, "
+ "document->'quantity' AS \"quantity\", "
+ "document->'price' AS \"price\", "
+ "document->'date' AS \"date\", "
+ "document->'props' AS \"props\", "
+ "id AS _implicit_id "
+ "FROM %s "
+ "WHERE (document->>'item' = ?) "
Expand Down Expand Up @@ -284,10 +284,10 @@ void testUpdateAtomicWithFilter_emptyResults() throws IOException, SQLException
final String selectQuery =
String.format(
"SELECT "
+ "document->'quantity' AS quantity, "
+ "document->'price' AS price, "
+ "document->'date' AS date, "
+ "document->'props' AS props, "
+ "document->'quantity' AS \"quantity\", "
+ "document->'price' AS \"price\", "
+ "document->'date' AS \"date\", "
+ "document->'props' AS \"props\", "
+ "id AS _implicit_id "
+ "FROM %s "
+ "WHERE (document->>'item' = ?) "
Expand Down Expand Up @@ -334,10 +334,10 @@ void testUpdateAtomicWithFilter_throwsException() throws Exception {
final String selectQuery =
String.format(
"SELECT "
+ "document->'quantity' AS quantity, "
+ "document->'price' AS price, "
+ "document->'date' AS date, "
+ "document->'props' AS props, "
+ "document->'quantity' AS \"quantity\", "
+ "document->'price' AS \"price\", "
+ "document->'date' AS \"date\", "
+ "document->'props' AS \"props\", "
+ "id AS _implicit_id "
+ "FROM %s "
+ "WHERE (document->>'item' = ?) "
Expand Down Expand Up @@ -439,10 +439,10 @@ void testUpdateBulkWithFilter() throws IOException, SQLException {
final String selectQuery =
String.format(
"SELECT "
+ "document->'quantity' AS quantity, "
+ "document->'price' AS price, "
+ "document->'date' AS date, "
+ "document->'props' AS props "
+ "document->'quantity' AS \"quantity\", "
+ "document->'price' AS \"price\", "
+ "document->'date' AS \"date\", "
+ "document->'props' AS \"props\" "
+ "FROM %s "
+ "WHERE (document->>'item' = ?) "
+ "AND (document->>'date' < ?) "
Expand Down Expand Up @@ -608,10 +608,10 @@ void testUpdateBulkWithFilter_emptyResults() throws IOException, SQLException {
final String selectQuery =
String.format(
"SELECT "
+ "document->'quantity' AS quantity, "
+ "document->'price' AS price, "
+ "document->'date' AS date, "
+ "document->'props' AS props "
+ "document->'quantity' AS \"quantity\", "
+ "document->'price' AS \"price\", "
+ "document->'date' AS \"date\", "
+ "document->'props' AS \"props\" "
+ "FROM %s "
+ "WHERE (document->>'item' = ?) "
+ "AND (document->>'date' < ?) "
Expand Down Expand Up @@ -701,10 +701,10 @@ void testUpdateBulkWithFilter_throwsExceptionBeforeUpdate() throws IOException,
final String selectQuery =
String.format(
"SELECT "
+ "document->'quantity' AS quantity, "
+ "document->'price' AS price, "
+ "document->'date' AS date, "
+ "document->'props' AS props "
+ "document->'quantity' AS \"quantity\", "
+ "document->'price' AS \"price\", "
+ "document->'date' AS \"date\", "
+ "document->'props' AS \"props\" "
+ "FROM %s "
+ "WHERE (document->>'item' = ?) "
+ "AND (document->>'date' < ?) "
Expand Down Expand Up @@ -740,10 +740,10 @@ void testUpdateBulkWithFilter_throwsExceptionAfterUpdate() throws IOException, S
final String selectQuery =
String.format(
"SELECT "
+ "document->'quantity' AS quantity, "
+ "document->'price' AS price, "
+ "document->'date' AS date, "
+ "document->'props' AS props "
+ "document->'quantity' AS \"quantity\", "
+ "document->'price' AS \"price\", "
+ "document->'date' AS \"date\", "
+ "document->'props' AS \"props\" "
+ "FROM %s "
+ "WHERE (document->>'item' = ?) "
+ "AND (document->>'date' < ?) "
Expand Down
Loading

0 comments on commit fb5e855

Please sign in to comment.