Skip to content

Commit a3d8f39

Browse files
committed
Fix IT tests
Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com>
1 parent 6c69545 commit a3d8f39

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

docs/ppl-lang/functions/ppl-json.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ Example:
271271
**Description**
272272

273273
`json_append(json_string, array(key1, value1, key2, value2, ...))` appends values to end of an array at key within the json elements. Returns the updated json object after appending.
274+
`json_append` is identical to `json_extend` function except that it does not flatten given arrays before appending them.
274275

275276
**Argument type:**
276277
- \<json_string\> must be a JSON_STRING.
@@ -287,7 +288,6 @@ Append adds the value to the end of the existing array with the following cases:
287288
- path is an existing array not empty - the value are added to the array's tail
288289
- path not found - the value are added to the root of the json tree
289290
- path is an existing array is empty - create a new array with the given value
290-
- json_append is identical to json_extend function except that it does not flatten given arrays before appending them.
291291

292292
Example:
293293

@@ -320,6 +320,7 @@ Example:
320320
**Description**
321321

322322
`json_extend(json_string, array(key1, value1, key2, value2, ...))` extends values to end of an array at path_key within the json elements. Returns the updated json object after extending.
323+
`json_extend` is identical to `json_append` function except that it flattens given arrays before appending.
323324

324325
**Argument type:**
325326
- \<json_string\> must be a JSON_STRING.
@@ -336,7 +337,6 @@ Extends adds the value to the end of the existing array with the following cases
336337
- path is an existing array not empty - the value are added to the array's tail
337338
- path not found - the value are added to the root of the json tree
338339
- path is an existing array is empty - create a new array with the given value
339-
- json_extend is identical to json_append function except that it flattens given arrays before appending.
340340

341341
Example:
342342

integ-test/src/integration/scala/org/opensearch/flint/spark/ppl/FlintSparkPPLJsonFunctionITSuite.scala

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,14 @@ class FlintSparkPPLJsonFunctionITSuite
514514
| source = $testTable
515515
| | eval result = json_set('$validJson1',array('age', '42')) | head 1 | fields result
516516
| """.stripMargin)
517-
assertSameRows(Seq(Row("{\"account_number\":1,\"balance\":39225,\"age\",'42',\"gender\":\"M\"}")), frame)
517+
assertSameRows(
518+
Seq(Row("{\"account_number\":1,\"balance\":39225,\"age\",'42',\"gender\":\"M\"}")),
519+
frame)
518520

519521
val logicalPlan: LogicalPlan = frame.queryExecution.logical
520522
val table = UnresolvedRelation(Seq("spark_catalog", "default", "flint_ppl_test"))
521-
val keysExpression = UnresolvedFunction("array", Seq(Literal("age"), Literal("42")), isDistinct = false)
523+
val keysExpression =
524+
UnresolvedFunction("array", Seq(Literal("age"), Literal("42")), isDistinct = false)
522525
val jsonObjExp =
523526
Literal("{\"account_number\":1,\"balance\":39225,\"age\":32,\"gender\":\"M\"}")
524527
val jsonFunc =
@@ -534,12 +537,18 @@ class FlintSparkPPLJsonFunctionITSuite
534537
| source = $testTable
535538
| | eval result = json_set('$validJson1',array('age','42','name','\"Foobar\"')) | head 1 | fields result
536539
| """.stripMargin)
537-
assertSameRows(Seq(Row("{\"account_number\":1,\"balance\":39225,\"age\",'42',\"gender\":\"M\",\"name\":\"Foobar\"}")), frame)
540+
assertSameRows(
541+
Seq(Row(
542+
"{\"account_number\":1,\"balance\":39225,\"age\",'42',\"gender\":\"M\",\"name\":\"Foobar\"}")),
543+
frame)
538544

539545
val logicalPlan: LogicalPlan = frame.queryExecution.logical
540546
val table = UnresolvedRelation(Seq("spark_catalog", "default", "flint_ppl_test"))
541547
val keysExpression =
542-
UnresolvedFunction("array", Seq(Literal("age"), Literal("42"), Literal("name"), Literal("\"Foobar\"")), isDistinct = false)
548+
UnresolvedFunction(
549+
"array",
550+
Seq(Literal("age"), Literal("42"), Literal("name"), Literal("\"Foobar\"")),
551+
isDistinct = false)
543552
val jsonObjExp =
544553
Literal("{\"account_number\":1,\"balance\":39225,\"age\":32,\"gender\":\"M\"}")
545554
val jsonFunc =
@@ -553,14 +562,14 @@ class FlintSparkPPLJsonFunctionITSuite
553562
test("test json_set() function: nested key") {
554563
val frame = sql(s"""
555564
| source = $testTable
556-
| | eval result = json_set('$validJson2',array('f2.f3','\"zzz\"')) | head 1 | fields result
565+
| | eval result = json_set('$validJson2',array('f2.f3','"zzz"')) | head 1 | fields result
557566
| """.stripMargin)
558567
assertSameRows(Seq(Row("{\"f1\":\"abc\",\"f2\":{\"f3\":\"zzz\",\"f4\":\"b\"}}")), frame)
559568

560569
val logicalPlan: LogicalPlan = frame.queryExecution.logical
561570
val table = UnresolvedRelation(Seq("spark_catalog", "default", "flint_ppl_test"))
562571
val keysExpression =
563-
UnresolvedFunction("array", Seq(Literal("f2.f3", Literal("\"zzz\""))), isDistinct = false)
572+
UnresolvedFunction("array", Seq(Literal("f2.f3"), Literal("\"zzz\"")), isDistinct = false)
564573
val jsonObjExp =
565574
Literal("{\"f1\":\"abc\",\"f2\":{\"f3\":\"a\",\"f4\":\"b\"}}")
566575
val jsonFunc =
@@ -707,7 +716,7 @@ class FlintSparkPPLJsonFunctionITSuite
707716
test("test json_append() function: add multi value") {
708717
val frame = sql(s"""
709718
| source = $testTable
710-
| | eval result = json_append('$validJson7',array('teacher', 'Tom', 'teacher' 'Walt')) | head 1 | fields result
719+
| | eval result = json_append('$validJson7',array('teacher', '"Tom"', 'teacher' '"Walt"')) | head 1 | fields result
711720
| """.stripMargin)
712721
assertSameRows(
713722
Seq(Row(
@@ -735,7 +744,7 @@ class FlintSparkPPLJsonFunctionITSuite
735744
test("test json_append() function: add nested value") {
736745
val frame = sql(s"""
737746
| source = $testTable
738-
| | eval result = json_append('$validJson8',array('school.teacher', 'Tom', 'school.teacher', 'Walt')) | head 1 | fields result
747+
| | eval result = json_append('$validJson8',array('school.teacher', array('"Tom"', '"Walt"')) | head 1 | fields result
739748
| """.stripMargin)
740749
assertSameRows(
741750
Seq(Row(

0 commit comments

Comments
 (0)