Skip to content

Conversation

rozza
Copy link
Member

@rozza rozza commented Apr 9, 2024

Two core fixes:

  1. Support the interface change in SupportsNamespaces which added cascade to dropNamespace.
  2. Support change in API for creating serializers to and from InternalRow to Row

SPARK-413

@rozza rozza requested review from a team, jyemin and stIncMale and removed request for a team April 9, 2024 17:00
@rozza rozza marked this pull request as draft April 9, 2024 17:07
@rozza
Copy link
Member Author

rozza commented Apr 9, 2024

Apologies - seems to compile fine but there is some more work to do with integration tests.

@rozza rozza marked this pull request as ready for review April 10, 2024 14:17
- func: "upload test results"
- func: "cleanup"

variables:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variables ftw

* @return true if the namespace (database) was dropped
*/
@Override
public boolean dropNamespace(final String[] namespace, final boolean cascade) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dropNamespace(namespace) was removed in 3.4
dropNamespace(namespace, cascade) was added in 3.4 - probably with a default value for cascade.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by a default value for cascade.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scala allows default values for parameters - so they may have just done that.

/**
* An adapter for SupportsNamespaces as the API for dropNamespace changed between versions
*/
interface SupportsNamespacesAdapter {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declare both dropNamespace methods then both can be overridden

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's crazy that this works! Ingenious.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clever💡

throw new ExceptionInInitializerError("Unsupported version of Spark: " + sparkVersion);
}

MODULE_STATIC = moduleStatic;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache the methods that we looked up.

@Override
public ExpressionEncoder<Row> apply(final StructType schema) {
ExpressionEncoder<Row> rowEncoder = MethodInvoker.invoke(APPLY_METHOD, MODULE_STATIC, schema);
return rowEncoder.resolveAndBind(ATTRIBUTE_FUNCTION.apply(schema), SimpleAnalyzer$.MODULE$);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get the resolved ExpressionEncoder which can create valid serializers and deserializers


/** Shared converter helper methods and statics */
public final class ConverterHelper {
static final SchemaToExpressionEncoderFunction SCHEMA_TO_EXPRESSION_ENCODER_FUNCTION =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make static the function that is used to convert a schema to an expression encoder.

@rozza
Copy link
Member Author

rozza commented Apr 10, 2024

@jyemin & @stIncMale this is now ready for review :)

* @return true if the namespace (database) was dropped
*/
@Override
public boolean dropNamespace(final String[] namespace, final boolean cascade) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by a default value for cascade.

/**
* An adapter for SupportsNamespaces as the API for dropNamespace changed between versions
*/
interface SupportsNamespacesAdapter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's crazy that this works! Ingenious.

@rozza rozza requested a review from jyemin April 11, 2024 09:05
/**
* An adapter for SupportsNamespaces as the API for dropNamespace changed between versions
*/
interface SupportsNamespacesAdapter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clever💡

@rozza rozza requested a review from stIncMale April 12, 2024 09:53
Copy link
Contributor

@jyemin jyemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rozza rozza merged commit 07c4dc4 into mongodb:main Apr 16, 2024
@rozza rozza deleted the SPARK-413 branch April 16, 2024 08:33
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

Successfully merging this pull request may close these issues.

3 participants