"Cannot evaluate expression: NamePlaceholder" when extracting Avro schema from multiple columns
See original GitHub issueimport org.apache.spark.sql.DataFrame
import org.scalatest.FunSuite
import za.co.absa.utils.spark.test.SparkSessionFixture
import org.apache.spark.sql.avro.SchemaConverters.toAvroType
import org.apache.spark.sql.functions.struct
case class TestData(name: String, id: Int)
class TestConversion extends FunSuite with SparkSessionFixture {
test(testName = "whatever") {
val data = getTestDataFrame()
data.show()
print(getSchema(data))
}
private def getTestDataFrame(): DataFrame = {
val testData = Seq(
TestData("a", 1),
TestData("b", 2),
TestData("c", 3)
)
spark.createDataFrame(testData)
}
private def getSchema(data: DataFrame) = {
val columns = struct(data.columns.head, data.columns.tail: _*)
val expression = columns.expr
toAvroType(expression.dataType, expression.nullable)
}
}
is throwing
Cannot evaluate expression: NamePlaceholder
java.lang.UnsupportedOperationException: Cannot evaluate expression: NamePlaceholder
at org.apache.spark.sql.catalyst.expressions.Unevaluable$class.eval(Expression.scala:258)
at org.apache.spark.sql.catalyst.expressions.NamePlaceholder$.eval(complexTypeCreator.scala:317)
at org.apache.spark.sql.catalyst.expressions.CreateNamedStructLike$$anonfun$names$1.apply(complexTypeCreator.scala:363)
at org.apache.spark.sql.catalyst.expressions.CreateNamedStructLike$$anonfun$names$1.apply(complexTypeCreator.scala:363)
at scala.collection.immutable.List.map(List.scala:273)
at org.apache.spark.sql.catalyst.expressions.CreateNamedStructLike$class.names(complexTypeCreator.scala:363)
at org.apache.spark.sql.catalyst.expressions.CreateNamedStruct.names$lzycompute(complexTypeCreator.scala:425)
at org.apache.spark.sql.catalyst.expressions.CreateNamedStruct.names(complexTypeCreator.scala:425)
at org.apache.spark.sql.catalyst.expressions.CreateNamedStructLike$class.dataType(complexTypeCreator.scala:370)
at org.apache.spark.sql.catalyst.expressions.CreateNamedStruct.dataType$lzycompute(complexTypeCreator.scala:425)
at org.apache.spark.sql.catalyst.expressions.CreateNamedStruct.dataType(complexTypeCreator.scala:425)
at org.apache.spark.sql.catalyst.expressions.CreateNamedStruct.dataType(complexTypeCreator.scala:425)
Probably because running
val expression = columns.expr
is resulting in
named_struct(NamePlaceHolder(), name, NamePlaceHolder(), id)
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
Cannot evalute expression: .. when adding new column ...
UnsupportedOperationException: Cannot evaluate expression: is really the df.show() action. I could confirm that by executing the code snippet ...
Read more >"Cannot evaluate expression" when filtering on parquet ...
In pyspark, when filtering on a parquet partition column, the following error occurs: py4j.protocol.Py4JJavaError: An error occurred while ...
Read more >Spring Cloud Stream App Starters Reference Guide
This section will provide you with a detailed overview of Spring Cloud Stream Application Starters, their purpose, and how to use them.
Read more >How to debug NodeJs applications like a pro - Morioh
In this blog post, I will show you three techniques to debug NodeJS applications. Although these techniques are primarily for NodeJS developers, they...
Read more >shell script | Noise | Page 2
By command-line this document really means bash. There are many types of command-line shells. Windows has two, 'cmd.exe' and 'PowerShell'. Unix started with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
dataFrame.columns.map(col)
This creates a new generic column instead of getting one from the dataframe. The column is not associated with dataframe so it makes sense it doesn’t work.col
Is supposed to be used insideselect
.That makes sense, however I also tried using
which fails with the NamePlaceholder exception.
So it can’t be only because of the
Column
type, there must be something implementation-specific, but I couldn’t figure out yet, what it is.