0

I have created an empty dataframe and then trying to add columns and values to the dataframe.

Dataset<Row> runMetadata = sparkSession.emptyDataFrame();
runMetadata = runMetadata.withColumn("record_count", lit(count));
runMetadata = 
         runMetadata.withColumn("start_time",lit(currTimestamp));
runMetadata.show();

count is long and currTimestamp is a timestamp.

But 'runMetadata.show()' is only showing the column names and no values. Also i am trying to save this dataframe in bigquery, there also no value is getting appended, also i am not seeing any errors in logs.

1 Answer 1

2

When you use withColumn, you're defining a transformation that it's going to be applied to all the rows of your DataFrame. Your DataFrame has no rows, so there's no rows apply the new columns to.

If you want a DataFrame with just one row you can create it using the createDataFrame method from the SparkSession passing a list with only one element.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.