Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Cannot evaluate expression: NamePlaceholder" when extracting Avro schema from multiple columns

See original GitHub issue
import org.apache.spark.sql.DataFrame
import org.scalatest.FunSuite
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()

  private def getTestDataFrame(): DataFrame = {
    val testData = Seq(
      TestData("a", 1),
      TestData("b", 2),
      TestData("c", 3)


  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 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:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

cerveadacommented, Nov 18, 2020 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 inside select.

kevinwallimanncommented, Nov 18, 2020

That makes sense, however I also tried using

import org.apache.spark.sql.functions.col
val mapColumns: Array[Column] =

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot evalute expression: .. when adding new column ...
UnsupportedOperationException: Cannot evaluate expression: is really the 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found