Skip to content

Commit ce5fc00

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix-divide
2 parents d0d4691 + d9ef4fa commit ce5fc00

File tree

6 files changed

+51
-9
lines changed

6 files changed

+51
-9
lines changed

core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ public static ExprValue exprDateDiff(
13321332
* @return ExprValue of date type.
13331333
*/
13341334
public static ExprValue exprDateTime(ExprValue timestamp, ExprValue timeZone) {
1335-
String defaultTimeZone = TimeZone.getDefault().getID();
1335+
String defaultTimeZone = TimeZone.getDefault().toZoneId().toString();
13361336

13371337
try {
13381338
LocalDateTime ldtFormatted =

ppl/src/main/antlr/OpenSearchPPLLexer.g4

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
lexer grammar OpenSearchPPLLexer;
88

99
channels { WHITESPACE, ERRORCHANNEL }
10-
10+
options { caseInsensitive = true; }
1111

1212
// COMMAND KEYWORDS
1313
SEARCH: 'SEARCH';
@@ -36,7 +36,6 @@ AD: 'AD';
3636
ML: 'ML';
3737
FILLNULL: 'FILLNULL';
3838
TRENDLINE: 'TRENDLINE';
39-
PATTERN_METHOD: 'PATTERN_METHOD';
4039
SIMPLE_PATTERN: 'SIMPLE_PATTERN';
4140
BRAIN: 'BRAIN';
4241
VARIABLE_COUNT_THRESHOLD: 'VARIABLE_COUNT_THRESHOLD';

ppl/src/main/antlr/OpenSearchPPLParser.g4

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ keywordsCanBeId
983983
| multiFieldRelevanceFunctionName
984984
| commandName
985985
| comparisonOperator
986+
| patternMethod
986987
// commands assist keywords
987988
| IN
988989
| BETWEEN
@@ -994,6 +995,9 @@ keywordsCanBeId
994995
| FROM
995996
| PATTERN
996997
| NEW_FIELD
998+
| VARIABLE_COUNT_THRESHOLD
999+
| FREQUENCY_THRESHOLD_PERCENTAGE
1000+
| WITH
9971001
| REGEX
9981002
| PUNCT
9991003
| USING
@@ -1048,10 +1052,6 @@ keywordsCanBeId
10481052
| LAST
10491053
| LIST
10501054
| VALUES
1051-
| EARLIEST
1052-
| EARLIEST_TIME
1053-
| LATEST
1054-
| LATEST_TIME
10551055
| PER_DAY
10561056
| PER_HOUR
10571057
| PER_MINUTE
@@ -1069,4 +1069,6 @@ keywordsCanBeId
10691069
| FULL
10701070
| SEMI
10711071
| ANTI
1072+
| LEFT_HINT
1073+
| RIGHT_HINT
10721074
;

protocol/src/main/java/org/opensearch/sql/protocol/response/format/FlatResponseBase.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ protected List<List<String>> formatData(List<List<String>> lines) {
8484

8585
protected String quoteIfRequired(String separator, String cell) {
8686
final String quote = "\"";
87-
if (cell.contains(separator) || cell.contains(quote)) {
87+
if (cell.contains(separator)
88+
|| cell.contains(quote)
89+
|| cell.contains("\r")
90+
|| cell.contains("\n")) {
8891
return quote + cell.replaceAll(quote, quote + quote) + quote;
8992
} else {
9093
return cell;

protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ void quoteIfRequired() {
110110
schema,
111111
Arrays.asList(
112112
tupleValue(ImmutableMap.of("na,me", "John,Smith", ",,age", "30,,,")),
113+
tupleValue(ImmutableMap.of("na,me", "Line\nBreak", ",,age", "28,,,")),
113114
tupleValue(ImmutableMap.of("na,me", "\"Janice Jones", ",,age", "26\""))));
114115
String expected =
115-
"\"na,me\",\",,age\"%n\"John,Smith\",\"30,,,\"%n\"\"\"Janice Jones\",\"26\"\"\"";
116+
"\"na,me\",\",,age\"%n\"John,Smith\",\"30,,,\"%n\"Line\nBreak\",\"28,,,\"%n"
117+
+ "\"\"\"Janice Jones\",\"26\"\"\"";
116118
assertEquals(format(expected), formatter.format(response));
117119
}
118120

protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,42 @@ void quoteIfRequired() {
135135
assertEquals(format(expectedPretty), getRawFormatterPretty().format(response));
136136
}
137137

138+
@Test
139+
void quoteIfRequiredCrlf() {
140+
ExecutionEngine.Schema schema =
141+
new ExecutionEngine.Schema(
142+
ImmutableList.of(
143+
new ExecutionEngine.Schema.Column("field1", "field1", STRING),
144+
new ExecutionEngine.Schema.Column("num", "num", INTEGER)));
145+
QueryResult response =
146+
new QueryResult(
147+
schema,
148+
Arrays.asList(
149+
tupleValue(ImmutableMap.of("field1", "abc", "num", "5")),
150+
tupleValue(ImmutableMap.of("field1", "def\r", "num", "\n6")),
151+
tupleValue(ImmutableMap.of("field1", "gh\ri", "num", "7\n")),
152+
tupleValue(ImmutableMap.of("field1", "jk\r\nl", "num", "\n\r8")),
153+
tupleValue(ImmutableMap.of("field1", "\r\nmno\r\n", "num", "9\n\r0"))));
154+
String expected =
155+
"field1|num%n"
156+
+ "abc|5%n"
157+
+ "\"def\r\"|\"\n6\"%n"
158+
+ "\"gh\ri\"|\"7\n\"%n"
159+
+ "\"jk\r\nl\"|\"\n\r8\"%n"
160+
+ "\"\r\nmno\r\n\"|\"9\n\r0\"";
161+
assertEquals(format(expected), getRawFormatter().format(response));
162+
// Pretty formatting raw or CSV data with embedded newlines and carriage
163+
// returns will still look awful on output.
164+
String expectedPretty =
165+
"field1 |num %n"
166+
+ "abc |5 %n"
167+
+ "\"def\r\" |\"\n6\" %n"
168+
+ "\"gh\ri\" |\"7\n\" %n"
169+
+ "\"jk\r\nl\" |\"\n\r8\" %n"
170+
+ "\"\r\nmno\r\n\"|\"9\n\r0\"";
171+
assertEquals(format(expectedPretty), getRawFormatterPretty().format(response));
172+
}
173+
138174
@Test
139175
void formatError() {
140176
Throwable t = new RuntimeException("This is an exception");

0 commit comments

Comments
 (0)