Skip to content

How to pass StructType between .NET & JVM? #651

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

Closed
GoEddie opened this issue Sep 3, 2020 · 4 comments
Closed

How to pass StructType between .NET & JVM? #651

GoEddie opened this issue Sep 3, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@GoEddie
Copy link
Contributor

GoEddie commented Sep 3, 2020

For FeatureHasher I need to take a StructType and pass it over to the JVM as a parameter (https://spark.apache.org/docs/2.4.0/api/java/org/apache/spark/ml/feature/FeatureHasher.html#transformSchema-org.apache.spark.sql.types.StructType-).

At the moment I get "System.NotSupportedException : Type Microsoft.Spark.Sql.Types.StructType not supported yet".

Is the way to implement it to serialise/deserialise as json across the wire or is there a better way? StructType already has a constructor from json and a json value to get the json from it on the .NET side.

I'm not sure if I am missing something because shouldn't it just be treated like any other jvm object reference?

@GoEddie GoEddie added the enhancement New feature or request label Sep 3, 2020
@Niharikadutta
Copy link
Collaborator

I am working on adding support to pass StructType between .NET and JVM as a part of #649 . You should be able to just use it once that is in. Thanks!

@GoEddie
Copy link
Contributor Author

GoEddie commented Sep 3, 2020

Great, i'll leave that method off until 649 is ready.

@GoEddie GoEddie closed this as completed Sep 3, 2020
@suhsteve
Copy link
Member

suhsteve commented Sep 3, 2020

I'm pretty sure we solved this already. You should use

internal static JvmObjectReference FromJson(IJvmBridge jvm, string json)
{
return (JvmObjectReference)jvm.CallStaticJavaMethod(
"org.apache.spark.sql.types.DataType",
"fromJson",
json);
}

Please see this example

public DataFrameReader Schema(StructType schema)
{
_jvmObject.Invoke("schema", DataType.FromJson(_jvmObject.Jvm, schema.Json));
return this;
}

@suhsteve suhsteve reopened this Sep 3, 2020
@GoEddie
Copy link
Contributor Author

GoEddie commented Sep 3, 2020

got it, thanks

@GoEddie GoEddie closed this as completed Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants