Skip to content

Commit ff989ea

Browse files
committed
style: apply spotless formatting
Spotless drift from cherry-picking the analytics-engine patterns work across upstream's recent formatting touch-ups. No behavior change. Signed-off-by: Kai Huang <huangkaics@gmail.com> Signed-off-by: Kai Huang <ahkcs@amazon.com>
1 parent c0730cc commit ff989ea

3 files changed

Lines changed: 47 additions & 48 deletions

File tree

core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4314,8 +4314,7 @@ private void buildParseRelNode(Parse node, CalcitePlanContext context) {
43144314
"g", context.rexBuilder.getTypeFactory().createSqlType(SqlTypeName.VARCHAR), true);
43154315
innerRex =
43164316
context.rexBuilder.makeCall(
4317-
SqlLibraryOperators.REGEXP_REPLACE_PG_4,
4318-
ArrayUtils.add(rexNodeList, globalFlag));
4317+
SqlLibraryOperators.REGEXP_REPLACE_PG_4, ArrayUtils.add(rexNodeList, globalFlag));
43194318
} else {
43204319
innerRex =
43214320
PPLFuncImpTable.INSTANCE.resolve(

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalcitePPLDashboardPatternsIT.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,25 @@
1515
import org.opensearch.sql.ppl.PPLIntegTestCase;
1616

1717
/**
18-
* Pins the exact PPL query shape OpenSearch Dashboards uses to render BRAIN-pattern
19-
* panels: {@code patterns ... method=BRAIN mode=label} followed by
20-
* {@code stats count(), take(message, 1) by patterns_field | sort -pattern_count |
21-
* fields patterns_field, pattern_count, sample_logs}.
18+
* Pins the exact PPL query shape OpenSearch Dashboards uses to render BRAIN-pattern panels: {@code
19+
* patterns ... method=BRAIN mode=label} followed by {@code stats count(), take(message, 1) by
20+
* patterns_field | sort -pattern_count | fields patterns_field, pattern_count, sample_logs}.
2221
*
23-
* <p>The combination exercises three pieces that all have to be wired through the
24-
* analytics-engine route together:
22+
* <p>The combination exercises three pieces that all have to be wired through the analytics-engine
23+
* route together:
2524
*
2625
* <ul>
27-
* <li>{@code INTERNAL_PATTERN} as a window function (label mode emits one
28-
* matched wildcard pattern per row, broadcast across the partition).</li>
29-
* <li>{@code take(field, n)} aggregate to capture a representative sample log
30-
* per discovered pattern group.</li>
31-
* <li>{@code count()} aggregate + {@code sort} on the result.</li>
26+
* <li>{@code INTERNAL_PATTERN} as a window function (label mode emits one matched wildcard
27+
* pattern per row, broadcast across the partition).
28+
* <li>{@code take(field, n)} aggregate to capture a representative sample log per discovered
29+
* pattern group.
30+
* <li>{@code count()} aggregate + {@code sort} on the result.
3231
* </ul>
3332
*
34-
* <p>Schema-only assertions: BRAIN's clustering depends on a corpus large enough
35-
* that the default heuristics fire, so per-row pattern strings are sensitive to
36-
* dataset version. The schema check guarantees the query plans, executes, and
37-
* returns the dashboard's three expected columns in the right order.
33+
* <p>Schema-only assertions: BRAIN's clustering depends on a corpus large enough that the default
34+
* heuristics fire, so per-row pattern strings are sensitive to dataset version. The schema check
35+
* guarantees the query plans, executes, and returns the dashboard's three expected columns in the
36+
* right order.
3837
*
3938
* @opensearch.internal
4039
*/
@@ -47,9 +46,9 @@ public void init() throws Exception {
4746
}
4847

4948
/**
50-
* Mirrors the canonical Dashboards BRAIN-label pattern panel query. Unfiltered
51-
* variant — pins the end-to-end plan compiles and returns the dashboard's
52-
* three-column shape (matched wildcard pattern + occurrence count + sample log).
49+
* Mirrors the canonical Dashboards BRAIN-label pattern panel query. Unfiltered variant — pins the
50+
* end-to-end plan compiles and returns the dashboard's three-column shape (matched wildcard
51+
* pattern + occurrence count + sample log).
5352
*/
5453
@Test
5554
public void testDashboardBrainLabelStatsByPatternsField() throws IOException {

ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLPatternsTest.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public void testPatternsLabelMode_ShowNumberedToken_ForSimplePatternMethod() {
6464
verifyLogical(root, expectedLogical);
6565

6666
String expectedSparkSql =
67-
"SELECT `ENAME`, TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR `ENAME` = '' THEN"
68-
+ " '' ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END, `ENAME`)['pattern'] AS"
69-
+ " STRING) `patterns_field`, TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR"
67+
"SELECT `ENAME`, TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR `ENAME` = '' THEN ''"
68+
+ " ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END, `ENAME`)['pattern']"
69+
+ " AS STRING) `patterns_field`, TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR"
7070
+ " `ENAME` = '' THEN '' ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END,"
7171
+ " `ENAME`)['tokens'] AS MAP< VARCHAR, VARCHAR ARRAY >) `tokens`\n"
7272
+ "FROM `scott`.`EMP`";
@@ -85,17 +85,17 @@ public void testPatternsLabelModeWithCustomPattern_ShowNumberedToken_ForSimplePa
8585
+ " Sarg['':VARCHAR; NULL AS TRUE]:VARCHAR), '':VARCHAR, REGEXP_REPLACE($1,"
8686
+ " '[A-H]':VARCHAR, '<*>':VARCHAR, 'g':VARCHAR)), $1), 'pattern'))],"
8787
+ " tokens=[SAFE_CAST(ITEM(PATTERN_PARSER(CASE(SEARCH($1, Sarg['':VARCHAR; NULL AS"
88-
+ " TRUE]:VARCHAR), '':VARCHAR, REGEXP_REPLACE($1, '[A-H]':VARCHAR, '<*>':VARCHAR, 'g':VARCHAR)),"
89-
+ " $1), 'tokens'))])\n"
88+
+ " TRUE]:VARCHAR), '':VARCHAR, REGEXP_REPLACE($1, '[A-H]':VARCHAR, '<*>':VARCHAR,"
89+
+ " 'g':VARCHAR)), $1), 'tokens'))])\n"
9090
+ " LogicalTableScan(table=[[scott, EMP]])\n";
9191
verifyLogical(root, expectedLogical);
9292

9393
String expectedSparkSql =
94-
"SELECT `ENAME`, TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR `ENAME` = '' THEN"
95-
+ " '' ELSE REGEXP_REPLACE(`ENAME`, '[A-H]', '<*>', 'g') END, `ENAME`)['pattern'] AS STRING)"
96-
+ " `patterns_field`, TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR `ENAME` ="
97-
+ " '' THEN '' ELSE REGEXP_REPLACE(`ENAME`, '[A-H]', '<*>', 'g') END, `ENAME`)['tokens'] AS"
98-
+ " MAP< VARCHAR, VARCHAR ARRAY >) `tokens`\n"
94+
"SELECT `ENAME`, TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR `ENAME` = '' THEN ''"
95+
+ " ELSE REGEXP_REPLACE(`ENAME`, '[A-H]', '<*>', 'g') END, `ENAME`)['pattern'] AS"
96+
+ " STRING) `patterns_field`, TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR"
97+
+ " `ENAME` = '' THEN '' ELSE REGEXP_REPLACE(`ENAME`, '[A-H]', '<*>', 'g') END,"
98+
+ " `ENAME`)['tokens'] AS MAP< VARCHAR, VARCHAR ARRAY >) `tokens`\n"
9999
+ "FROM `scott`.`EMP`";
100100
verifyPPLToSparkSQL(root, expectedSparkSql);
101101
}
@@ -138,12 +138,12 @@ public void testPatternsLabelModeWithPartitionBy_ShowNumberedToken_SimplePattern
138138
verifyLogical(root, expectedLogical);
139139

140140
String expectedSparkSql =
141-
"SELECT `ENAME`, `DEPTNO`, TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR `ENAME`"
142-
+ " = '' THEN '' ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END,"
143-
+ " `ENAME`)['pattern'] AS STRING) `patterns_field`, TRY_CAST(PATTERN_PARSER(CASE"
144-
+ " WHEN `ENAME` IS NULL OR `ENAME` = '' THEN '' ELSE REGEXP_REPLACE(`ENAME`,"
145-
+ " '[a-zA-Z0-9]+', '<*>', 'g') END, `ENAME`)['tokens'] AS MAP< VARCHAR, VARCHAR ARRAY >)"
146-
+ " `tokens`\n"
141+
"SELECT `ENAME`, `DEPTNO`, TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR `ENAME` ="
142+
+ " '' THEN '' ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END,"
143+
+ " `ENAME`)['pattern'] AS STRING) `patterns_field`, TRY_CAST(PATTERN_PARSER(CASE WHEN"
144+
+ " `ENAME` IS NULL OR `ENAME` = '' THEN '' ELSE REGEXP_REPLACE(`ENAME`,"
145+
+ " '[a-zA-Z0-9]+', '<*>', 'g') END, `ENAME`)['tokens'] AS MAP< VARCHAR, VARCHAR ARRAY"
146+
+ " >) `tokens`\n"
147147
+ "FROM `scott`.`EMP`";
148148
verifyPPLToSparkSQL(root, expectedSparkSql);
149149
}
@@ -254,9 +254,9 @@ public void testPatternsAggregationMode_NotShowNumberedToken_ForSimplePatternMet
254254

255255
String expectedSparkSql =
256256
"SELECT CASE WHEN `ENAME` IS NULL OR `ENAME` = '' THEN '' ELSE REGEXP_REPLACE(`ENAME`,"
257-
+ " '[a-zA-Z0-9]+', '<*>', 'g') END `patterns_field`, COUNT(CASE WHEN `ENAME` IS NULL OR"
258-
+ " `ENAME` = '' THEN '' ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END)"
259-
+ " `pattern_count`, `TAKE`(`ENAME`, 10) `sample_logs`\n"
257+
+ " '[a-zA-Z0-9]+', '<*>', 'g') END `patterns_field`, COUNT(CASE WHEN `ENAME` IS NULL"
258+
+ " OR `ENAME` = '' THEN '' ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g')"
259+
+ " END) `pattern_count`, `TAKE`(`ENAME`, 10) `sample_logs`\n"
260260
+ "FROM `scott`.`EMP`\n"
261261
+ "GROUP BY CASE WHEN `ENAME` IS NULL OR `ENAME` = '' THEN '' ELSE"
262262
+ " REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END";
@@ -282,12 +282,13 @@ public void testPatternsAggregationMode_ShowNumberedToken_ForSimplePatternMethod
282282

283283
String expectedSparkSql =
284284
"SELECT TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR `ENAME` = '' THEN '' ELSE"
285-
+ " REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END, `TAKE`(`ENAME`, 10))['pattern']"
286-
+ " AS STRING) `patterns_field`, COUNT(CASE WHEN `ENAME` IS NULL OR `ENAME` = '' THEN"
287-
+ " '' ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END) `pattern_count`,"
288-
+ " TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR `ENAME` = '' THEN '' ELSE"
289-
+ " REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END, `TAKE`(`ENAME`, 10))['tokens']"
290-
+ " AS MAP< VARCHAR, VARCHAR ARRAY >) `tokens`, `TAKE`(`ENAME`, 10) `sample_logs`\n"
285+
+ " REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END, `TAKE`(`ENAME`,"
286+
+ " 10))['pattern'] AS STRING) `patterns_field`, COUNT(CASE WHEN `ENAME` IS NULL OR"
287+
+ " `ENAME` = '' THEN '' ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END)"
288+
+ " `pattern_count`, TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR `ENAME` = ''"
289+
+ " THEN '' ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END,"
290+
+ " `TAKE`(`ENAME`, 10))['tokens'] AS MAP< VARCHAR, VARCHAR ARRAY >) `tokens`,"
291+
+ " `TAKE`(`ENAME`, 10) `sample_logs`\n"
291292
+ "FROM `scott`.`EMP`\n"
292293
+ "GROUP BY CASE WHEN `ENAME` IS NULL OR `ENAME` = '' THEN '' ELSE"
293294
+ " REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END";
@@ -317,9 +318,9 @@ public void testPatternsAggregationModeWithGroupBy_ShowNumberedToken_ForSimplePa
317318
+ " 10))['pattern'] AS STRING) `patterns_field`, COUNT(CASE WHEN `ENAME` IS NULL OR"
318319
+ " `ENAME` = '' THEN '' ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END)"
319320
+ " `pattern_count`, TRY_CAST(PATTERN_PARSER(CASE WHEN `ENAME` IS NULL OR `ENAME` = ''"
320-
+ " THEN '' ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END, `TAKE`(`ENAME`,"
321-
+ " 10))['tokens'] AS MAP< VARCHAR, VARCHAR ARRAY >) `tokens`, `TAKE`(`ENAME`, 10)"
322-
+ " `sample_logs`\n"
321+
+ " THEN '' ELSE REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END,"
322+
+ " `TAKE`(`ENAME`, 10))['tokens'] AS MAP< VARCHAR, VARCHAR ARRAY >) `tokens`,"
323+
+ " `TAKE`(`ENAME`, 10) `sample_logs`\n"
323324
+ "FROM `scott`.`EMP`\n"
324325
+ "GROUP BY `DEPTNO`, CASE WHEN `ENAME` IS NULL OR `ENAME` = '' THEN '' ELSE"
325326
+ " REGEXP_REPLACE(`ENAME`, '[a-zA-Z0-9]+', '<*>', 'g') END";

0 commit comments

Comments
 (0)