Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataframe can not convert to tfrecord #39

Open
Brian1203-zz opened this issue Dec 23, 2021 · 3 comments
Open

Dataframe can not convert to tfrecord #39

Brian1203-zz opened this issue Dec 23, 2021 · 3 comments

Comments

@Brian1203-zz
Copy link

val df1: DataFrame = spark.createDataFrame(rdd,subSchema)
val df2 = df1.withColumn("entity",struct("age","salary")).
  groupBy("employee_name")

df1 can convert to tfrecord,but df2 cannot .

why is that?

@junshi15
Copy link
Contributor

df2 is the output of the groupBy operation, which is "RelationalGroupedDataset". There is no TFRecord equivalence for this kind of data schema. TFRecord supports very limited schema. It is for TF model training only.

@Brian1203-zz
Copy link
Author

May i ask how can i design my schema like this 。 I want convert RDD into DataFrame use StructType , inside of groupBy opration.
root
|-- name: string (nullable = true)
|-- age: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- _1: string (nullable = true)
| | |-- _2: string (nullable = true)
| | |-- _3: integer (nullable = false)

+-------------+--------------------+
|employee_name|collect_list(entity)|
+-------------+--------------------+
| Jen | [[53, 79000]]|
| Michae l |[[56, 86000], [30...|
| Kumar | [[34, 90000], [50...|
| Maria | [[24, 90000]]|
| Raman | [[40, 99000], [36...|
| Jeff | [[25, 80000]]|
+-------------+--------------------+

@junshi15
Copy link
Contributor

If you already have the RDD, then you can create the schema, then use createDataFrame as shown here.

https://stackoverflow.com/questions/29383578/how-to-convert-rdd-object-to-dataframe-in-spark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants