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

Add UDF support to import/export workflows #2253

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

MnkyGns
Copy link

@MnkyGns MnkyGns commented Mar 17, 2025

Adding support for User Defined Functions (UDFs) to be imported from and exported to Avro files. Supported format follows the syntax -

CREATE FUNCTION
  function_name ([ parameter_name data_type [DEFAULT default_value], ...])
  [ RETURNS data_type ]
  [ SQL SECURITY INVOKER ]
  AS ( function_body )

Copy link

codecov bot commented Mar 25, 2025

Codecov Report

Attention: Patch coverage is 59.13043% with 94 lines in your changes missing coverage. Please review.

Project coverage is 48.87%. Comparing base (095c8d4) to head (375a8ab).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...ava/com/google/cloud/teleport/spanner/ddl/Udf.java 63.63% 27 Missing and 1 partial ⚠️
...google/cloud/teleport/spanner/ImportTransform.java 0.00% 21 Missing and 2 partials ⚠️
...google/cloud/teleport/spanner/ExportTransform.java 9.52% 19 Missing ⚠️
...oogle/cloud/teleport/spanner/ddl/UdfParameter.java 64.28% 12 Missing and 3 partials ⚠️
...ava/com/google/cloud/teleport/spanner/ddl/Ddl.java 73.07% 4 Missing and 3 partials ⚠️
...oud/teleport/spanner/AvroSchemaToDdlConverter.java 94.73% 0 Missing and 1 partial ⚠️
...oogle/cloud/teleport/spanner/common/NameUtils.java 0.00% 0 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (59.13%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2253      +/-   ##
============================================
+ Coverage     48.83%   48.87%   +0.03%     
- Complexity     4514     4542      +28     
============================================
  Files           905      907       +2     
  Lines         55061    55290     +229     
  Branches       5881     5921      +40     
============================================
+ Hits          26891    27024     +133     
- Misses        26251    26335      +84     
- Partials       1919     1931      +12     
Components Coverage Δ
spanner-templates 69.69% <59.13%> (-0.14%) ⬇️
spanner-import-export 67.77% <59.13%> (-0.28%) ⬇️
spanner-live-forward-migration 77.64% <ø> (ø)
spanner-live-reverse-replication 79.69% <ø> (ø)
spanner-bulk-migration 88.39% <ø> (ø)
Files with missing lines Coverage Δ
...va/com/google/cloud/teleport/spanner/AvroUtil.java 93.75% <ø> (ø)
...oud/teleport/spanner/DdlToAvroSchemaConverter.java 93.63% <100.00%> (+0.45%) ⬆️
...oud/teleport/spanner/AvroSchemaToDdlConverter.java 85.17% <94.73%> (+0.44%) ⬆️
...oogle/cloud/teleport/spanner/common/NameUtils.java 55.17% <0.00%> (-3.45%) ⬇️
...ava/com/google/cloud/teleport/spanner/ddl/Ddl.java 71.36% <73.07%> (+0.10%) ⬆️
...oogle/cloud/teleport/spanner/ddl/UdfParameter.java 64.28% <64.28%> (ø)
...google/cloud/teleport/spanner/ExportTransform.java 15.73% <9.52%> (-0.28%) ⬇️
...google/cloud/teleport/spanner/ImportTransform.java 21.41% <0.00%> (-0.99%) ⬇️
...ava/com/google/cloud/teleport/spanner/ddl/Udf.java 63.63% <63.63%> (ø)

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@darshan-sj darshan-sj left a comment

Choose a reason for hiding this comment

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

Changes look good overall. Left few comments, Please take a look.

@@ -143,6 +153,31 @@ public View toView(String viewName, Schema schema) {
return builder.build();
}

public Udf toUdf(String functionSpecificName, Schema schema) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is functionSpecificName?

Copy link
Author

Choose a reason for hiding this comment

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

That would be the full name, including the schema/namespace prefix

recordBuilder.prop(SPANNER_NAME, udf.specificName());
recordBuilder.prop(GOOGLE_FORMAT_VERSION, version);
recordBuilder.prop(GOOGLE_STORAGE, "CloudSpanner");
// Indicate that this is a "CREATE FUNCTION", not a table or a view.
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking, is this a TODO comment?

Copy link
Author

Choose a reason for hiding this comment

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

No, it's just pointing out that this property is to distinguish the type of object

@@ -490,6 +491,7 @@ public void processElement(ProcessContext c) {
List<KV<String, Schema>> missingViews = new ArrayList<>();
List<KV<String, Schema>> missingChangeStreams = new ArrayList<>();
List<KV<String, Schema>> missingSequences = new ArrayList<>();
List<KV<String, Schema>> missingFunctions = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are calling it UDF in other places, Lets call it UDFs everywhere? rename to missingUDFs

Copy link
Author

Choose a reason for hiding this comment

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

Renamed

mergedDdl.addUdf(udf);
}
Ddl newDdl = builder.build();
ddlStatements.addAll(newDdl.createUdfStatements());
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that the missingTables and views are getting added to ddlStatements in Next lines. If UDFs would depend on tables, views etc, they should added to ddlStatements later. The order of statements in ddlStatements matters.

Copy link
Author

Choose a reason for hiding this comment

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

This is intentional, the plan is to initially only support "UDF_without_SELECT"

https://docs.google.com/document/d/1FeMWmvvQzymWhceNawC_QLmarZe9mDK408RQax7eiSw/edit?pli=1&tab=t.0#bookmark=id.k49vu7dbcae7

@@ -798,6 +817,12 @@ public void processElement(ProcessContext c) {
c.output(KV.of(sequence.getName(), fullPath));
}
}
for (Export.Table udf : proto.getFunctionsList()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The proto here is Export.proto is it? We should call it udf consistently everywhere.

Copy link
Author

Choose a reason for hiding this comment

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

Updated

@@ -1004,6 +1008,112 @@ private void listViews(Ddl.Builder builder) {
}
}

private void listFunctions(Ddl.Builder builder) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please confirm that all the information schema table names, and columns used in the queries here are present in production. Also, can you get the changes in this file reviewed by one of your team members?

Copy link
Author

Choose a reason for hiding this comment

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

Confirmed, and @seanfox agreed to review these changes

@@ -1004,6 +1008,112 @@ private void listViews(Ddl.Builder builder) {
}
}

private void listFunctions(Ddl.Builder builder) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, please add unit tests for changes in this file. In InformationSchemaScannerTest.java

Copy link
Author

Choose a reason for hiding this comment

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

Added testListFunctionParametersSQL

* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.cloud.teleport.spanner.ddl;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add unit tests and cover all the lines in this file.

Copy link
Author

Choose a reason for hiding this comment

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

Added UdfTest.java

@@ -0,0 +1,136 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add unit tests and cover all the lines in this file.

Copy link
Author

Choose a reason for hiding this comment

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

Added UdfParameterTest.java

@@ -30,7 +30,7 @@ message Export {
// change stream or sequence name. Both `data_files` and `manifest_file` can
// be used to locate the corresponding data files.
message Table {
// The name of the table, view, change stream or sequence.
// The name of the table, view, change stream, sequence, or function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please call this as udf for consistency.

Copy link
Author

Choose a reason for hiding this comment

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

Updated

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

Successfully merging this pull request may close these issues.

2 participants