Skip to content
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ object ExtractValue {
resolver: Resolver): Expression = {

(child.dataType, extraction) match {
case (StructType(fields), NonNullLiteral(v, StringType)) =>
case (StructType(fields), NonNullLiteral(v, _: StringType)) =>
val fieldName = v.toString
val ordinal = findField(fields, fieldName, resolver)
GetStructField(child, ordinal, Some(fieldName))

case (ArrayType(StructType(fields), containsNull), NonNullLiteral(v, StringType)) =>
case (ArrayType(StructType(fields), containsNull), NonNullLiteral(v, _: StringType)) =>
val fieldName = v.toString
val ordinal = findField(fields, fieldName, resolver)
GetArrayStructFields(child, fields(ordinal).copy(name = fieldName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,25 @@ class CollationSQLExpressionsSuite
})
}

test("ExtractValue expression with collation") {
// Supported collations
testSuppCollations.foreach(collationName => {
withSQLConf(SqlApiConf.DEFAULT_COLLATION -> collationName) {
val query =
s"""
|select col['Field1']
|from values (named_struct('Field1', 'Spark', 'Field2', 5)) as tab(col);
|""".stripMargin
// Result & data type check
val testQuery = sql(query)
val dataType = StringType(collationName)
val expectedResult = "Spark"
assert(testQuery.schema.fields.head.dataType.sameType(dataType))
checkAnswer(testQuery, Row(expectedResult))
}
})
}

test("DatePart expression with collation") {
// Supported collations
testSuppCollations.foreach(collationName => {
Expand Down