Skip to content

Commit 915a43a

Browse files
committed
[SPARK-58403][SQL] Assign appropriate error condition for _LEGACY_ERROR_TEMP_3201-3205: MALFORMED_EXPRESSION_INFO
1 parent 8ed480d commit 915a43a

3 files changed

Lines changed: 57 additions & 41 deletions

File tree

common/utils/src/main/resources/error/error-conditions.json

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5574,6 +5574,39 @@
55745574
],
55755575
"sqlState" : "KD000"
55765576
},
5577+
"MALFORMED_EXPRESSION_INFO" : {
5578+
"message" : [
5579+
"'<fieldName>' is malformed in the expression [<exprName>]:"
5580+
],
5581+
"subClass" : {
5582+
"DEPRECATED" : {
5583+
"message" : [
5584+
"it should start with a newline and 4 leading spaces; end with a newline and two spaces; however, got [<deprecated>]."
5585+
]
5586+
},
5587+
"GROUP" : {
5588+
"message" : [
5589+
"it should be a value in <validGroups>; however, got [<group>]."
5590+
]
5591+
},
5592+
"NOTE" : {
5593+
"message" : [
5594+
"it should start with a newline and 4 leading spaces; end with a newline and two spaces; however, got [<note>]."
5595+
]
5596+
},
5597+
"SINCE" : {
5598+
"message" : [
5599+
"it should not start with a negative number; however, got [<since>]."
5600+
]
5601+
},
5602+
"SOURCE" : {
5603+
"message" : [
5604+
"it should be a value in <validSources>; however, got [<source>]."
5605+
]
5606+
}
5607+
},
5608+
"sqlState" : "22023"
5609+
},
55775610
"MALFORMED_LOG_FILE" : {
55785611
"message" : [
55795612
"Log file was malformed: failed to read correct log version from <text>."
@@ -11857,31 +11890,6 @@
1185711890
"Read-ahead limit < 0"
1185811891
]
1185911892
},
11860-
"_LEGACY_ERROR_TEMP_3201" : {
11861-
"message" : [
11862-
"'note' is malformed in the expression [<exprName>]. It should start with a newline and 4 leading spaces; end with a newline and two spaces; however, got [<note>]."
11863-
]
11864-
},
11865-
"_LEGACY_ERROR_TEMP_3202" : {
11866-
"message" : [
11867-
"'group' is malformed in the expression [<exprName>]. It should be a value in <validGroups>; however, got <group>."
11868-
]
11869-
},
11870-
"_LEGACY_ERROR_TEMP_3203" : {
11871-
"message" : [
11872-
"'source' is malformed in the expression [<exprName>]. It should be a value in <validSources>; however, got [<source>]."
11873-
]
11874-
},
11875-
"_LEGACY_ERROR_TEMP_3204" : {
11876-
"message" : [
11877-
"'since' is malformed in the expression [<exprName>]. It should not start with a negative number; however, got [<since>]."
11878-
]
11879-
},
11880-
"_LEGACY_ERROR_TEMP_3205" : {
11881-
"message" : [
11882-
"'deprecated' is malformed in the expression [<exprName>]. It should start with a newline and 4 leading spaces; end with a newline and two spaces; however, got [<deprecated>]."
11883-
]
11884-
},
1188511893
"_LEGACY_ERROR_TEMP_3206" : {
1188611894
"message" : [
1188711895
"<value> is not a boolean string."

sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/ExpressionInfo.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,36 +150,39 @@ public ExpressionInfo(
150150
if (!note.isEmpty()) {
151151
if (!note.contains(" ") || !note.endsWith(" ")) {
152152
throw new SparkIllegalArgumentException(
153-
"_LEGACY_ERROR_TEMP_3201", Map.of("exprName", this.name, "note", note));
153+
"MALFORMED_EXPRESSION_INFO.NOTE",
154+
Map.of("fieldName", "note", "exprName", this.name, "note", note));
154155
}
155156
this.extended += "\n Note:\n " + note.trim() + "\n";
156157
}
157158
if (!group.isEmpty() && !validGroups.contains(group)) {
158159
throw new SparkIllegalArgumentException(
159-
"_LEGACY_ERROR_TEMP_3202",
160-
Map.of("exprName", this.name,
160+
"MALFORMED_EXPRESSION_INFO.GROUP",
161+
Map.of("fieldName", "group", "exprName", this.name,
161162
"validGroups", String.valueOf(validGroups.stream().sorted().toList()),
162163
"group", group));
163164
}
164165
if (!source.isEmpty() && !validSources.contains(source)) {
165166
throw new SparkIllegalArgumentException(
166-
"_LEGACY_ERROR_TEMP_3203",
167-
Map.of("exprName", this.name,
167+
"MALFORMED_EXPRESSION_INFO.SOURCE",
168+
Map.of("fieldName", "source", "exprName", this.name,
168169
"validSources", String.valueOf(validSources.stream().sorted().toList()),
169170
"source", source));
170171
}
171172
if (!since.isEmpty()) {
172173
if (Integer.parseInt(since.split("\\.")[0]) < 0) {
173174
throw new SparkIllegalArgumentException(
174-
"_LEGACY_ERROR_TEMP_3204", Map.of("exprName", this.name, "since", since));
175+
"MALFORMED_EXPRESSION_INFO.SINCE",
176+
Map.of("fieldName", "since", "exprName", this.name, "since", since));
175177
}
176178
this.extended += "\n Since: " + since + "\n";
177179
}
178180
if (!deprecated.isEmpty()) {
179181
if (!deprecated.contains(" ") || !deprecated.endsWith(" ")) {
180182
throw new SparkIllegalArgumentException(
181-
"_LEGACY_ERROR_TEMP_3205",
182-
Map.of("exprName", this.name, "deprecated", deprecated));
183+
"MALFORMED_EXPRESSION_INFO.DEPRECATED",
184+
Map.of("fieldName", "deprecated", "exprName", this.name,
185+
"deprecated", deprecated));
183186
}
184187
this.extended += "\n Deprecated:\n " + deprecated.trim() + "\n";
185188
}

sql/core/src/test/scala/org/apache/spark/sql/expressions/ExpressionInfoSuite.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ class ExpressionInfoSuite extends SharedSparkSession {
6868
new ExpressionInfo(
6969
"testClass", null, "testName", null, "", "", "", invalidGroupName, "", "", "")
7070
},
71-
condition = "_LEGACY_ERROR_TEMP_3202",
71+
condition = "MALFORMED_EXPRESSION_INFO.GROUP",
7272
parameters = Map(
73+
"fieldName" -> "group",
7374
"exprName" -> "testName",
7475
"group" -> invalidGroupName,
7576
"validGroups" -> validGroups.mkString("[", ", ", "]")))
@@ -93,8 +94,9 @@ class ExpressionInfoSuite extends SharedSparkSession {
9394
new ExpressionInfo(
9495
"testClass", null, "testName", null, "", "", "", "", "", "", invalidSource)
9596
},
96-
condition = "_LEGACY_ERROR_TEMP_3203",
97+
condition = "MALFORMED_EXPRESSION_INFO.SOURCE",
9798
parameters = Map(
99+
"fieldName" -> "source",
98100
"exprName" -> "testName",
99101
"source" -> invalidSource,
100102
"validSources" -> validSources.sorted.mkString("[", ", ", "]")))
@@ -106,26 +108,29 @@ class ExpressionInfoSuite extends SharedSparkSession {
106108
exception = intercept[SparkIllegalArgumentException] {
107109
new ExpressionInfo("testClass", null, "testName", null, "", "", invalidNote, "", "", "", "")
108110
},
109-
condition = "_LEGACY_ERROR_TEMP_3201",
110-
parameters = Map("exprName" -> "testName", "note" -> invalidNote))
111+
condition = "MALFORMED_EXPRESSION_INFO.NOTE",
112+
parameters = Map("fieldName" -> "note", "exprName" -> "testName", "note" -> invalidNote))
111113

112114
val invalidSince = "-3.0.0"
113115
checkError(
114116
exception = intercept[SparkIllegalArgumentException] {
115117
new ExpressionInfo(
116118
"testClass", null, "testName", null, "", "", "", "", invalidSince, "", "")
117119
},
118-
condition = "_LEGACY_ERROR_TEMP_3204",
119-
parameters = Map("since" -> invalidSince, "exprName" -> "testName"))
120+
condition = "MALFORMED_EXPRESSION_INFO.SINCE",
121+
parameters = Map("fieldName" -> "since", "since" -> invalidSince, "exprName" -> "testName"))
120122

121123
val invalidDeprecated = " invalid deprecated"
122124
checkError(
123125
exception = intercept[SparkIllegalArgumentException] {
124126
new ExpressionInfo(
125127
"testClass", null, "testName", null, "", "", "", "", "", invalidDeprecated, "")
126128
},
127-
condition = "_LEGACY_ERROR_TEMP_3205",
128-
parameters = Map("exprName" -> "testName", "deprecated" -> invalidDeprecated))
129+
condition = "MALFORMED_EXPRESSION_INFO.DEPRECATED",
130+
parameters = Map(
131+
"fieldName" -> "deprecated",
132+
"exprName" -> "testName",
133+
"deprecated" -> invalidDeprecated))
129134
}
130135

131136
test("using _FUNC_ instead of function names in examples") {

0 commit comments

Comments
 (0)