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

refactor: Break up Presto custom types into Declaration and Registration files #12393

Closed

Conversation

kevinwilfong
Copy link
Contributor

Summary:
Today Presto's custom types have a bunch of classes implemented in the same file:

  1. The Type itself
  2. The CastOperator (if any)
  3. The implementation of CustomTypeFactories
    In addition to the function registerXXXType()

While implementing an InputGenerator for TimestampWithTimeZone I ran into an issue, I needed
to take a dependency on the TimestampWithTimeZone Type itself (or at least its utility functions).

Since the InputGenerator needs to be referred to by the CustomTypeFactories implementation
this lead to a circular dependency between the so files.

One option is to add the InputGenerator to the TimestampWithTimeZoneType file, but adding yet
another class there would make these files even more monolithic. Another option was to add it
to the velox/functions/prestosql/types directory and the so it produces, but given the
InputGenerators are only used for testing it seems they should be separated from the production
code, e.g. into a separate fuzzers subdirectory like we do for InputGenerators for functions.

Excluding those options, one option I'm left with is to break up these files (which generally seems
like a good thing for clarity's sake). This change breaks the custom types into a XXXType.h file
where they Type itself is defined, and XXXRegistration.h/cpp files which define the
registerXXXType() functions. In most cases the CastOperator and the CustomTypeFactories
do not need to be exposed, so I've included those in the XXXRegistration.cpp file. The one
exception is JsonCastOperator which I gave it's own JsonCastOperator.h/cpp files.

Presto includes the registerXXXType() functions in some tests from the XXXType.h files, so this
is the first of 3 steps. Once this lands, I'll update Presto to include the XXXRegistration.h files
instead, then come back and remove the dependency on XXXRegistration.h from the XXXType.h
files, allowing us to break up the so files.

Once this is done InputGenerators can depend on the Type they're generating without
introducing a circular dependency.

Differential Revision: D69891219

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 20, 2025
Copy link

netlify bot commented Feb 20, 2025

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 598d7fd
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/67b7b66212e5ae000866188c

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69891219

Copy link
Contributor

@kagamiori kagamiori left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for cleaning up the dependency among types and input generators! I left a few nits.

@@ -18,6 +18,7 @@

#include <gtest/gtest.h>

#include "velox/common/memory/Memory.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Why is this header added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were previously getting this indirectly from JsonType.h, which through CastExpr.h depended on the Vector code which depended on Memory.h

Comment on lines +26 to +27
#include "velox/type/DecimalUtil.h"
#include "velox/vector/ComplexVector.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Why are these two headers added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were previously getting these indirectly from TimestampWithTimeZoneType.h, it had an unused dependency on velox/vector/VectorTypeUtils.h which was pulling these in indirectly.

#include "velox/type/Type.h"

namespace facebook::velox {
class JsonTypeFactories : public CustomTypeFactories {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Add namespace {} to address the internal linter complaint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed this one, didn't realize we had a lint rule for it, but that's awesome

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69891219

kevinwilfong pushed a commit to kevinwilfong/velox that referenced this pull request Feb 20, 2025
…ion files (facebookincubator#12393)

Summary:
Pull Request resolved: facebookincubator#12393

Today Presto's custom types have a bunch of classes implemented in the same file:
1) The Type itself
2) The CastOperator (if any)
3) The implementation of CustomTypeFactories
In addition to the function registerXXXType()

While implementing an InputGenerator for TimestampWithTimeZone I ran into an issue, I needed
to take a dependency on the TimestampWithTimeZone Type itself (or at least its utility functions).

Since the InputGenerator needs to be referred to by the CustomTypeFactories implementation
this lead to a circular dependency between the so files.

One option is to add the InputGenerator to the TimestampWithTimeZoneType file, but adding yet
another class there would make these files even more monolithic. Another option was to add it
to the velox/functions/prestosql/types directory and the so it produces, but given the
InputGenerators are only used for testing it seems they should be separated from the production
code, e.g. into a separate fuzzers subdirectory like we do for InputGenerators for functions.

Excluding those options, one option I'm left with is to break up these files (which generally seems
like a good thing for clarity's sake). This change breaks the custom types into a XXXType.h file
where they Type itself is defined, and XXXRegistration.h/cpp files which define the
registerXXXType() functions.  In most cases the CastOperator and the CustomTypeFactories
do not need to be exposed, so I've included those in the XXXRegistration.cpp file.  The one
exception is JsonCastOperator which I gave it's own JsonCastOperator.h/cpp files.

Presto includes the registerXXXType() functions in some tests from the XXXType.h files, so this
is the first of 3 steps.  Once this lands, I'll update Presto to include the XXXRegistration.h files
instead, then come back and remove the dependency on XXXRegistration.h from the XXXType.h
files, allowing us to break up the so files.

Once this is done InputGenerators can depend on the Type they're generating without
introducing a circular dependency.

Reviewed By: kagamiori

Differential Revision: D69891219
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69891219

kevinwilfong pushed a commit to kevinwilfong/velox that referenced this pull request Feb 20, 2025
…ion files (facebookincubator#12393)

Summary:
Pull Request resolved: facebookincubator#12393

Today Presto's custom types have a bunch of classes implemented in the same file:
1) The Type itself
2) The CastOperator (if any)
3) The implementation of CustomTypeFactories
In addition to the function registerXXXType()

While implementing an InputGenerator for TimestampWithTimeZone I ran into an issue, I needed
to take a dependency on the TimestampWithTimeZone Type itself (or at least its utility functions).

Since the InputGenerator needs to be referred to by the CustomTypeFactories implementation
this lead to a circular dependency between the so files.

One option is to add the InputGenerator to the TimestampWithTimeZoneType file, but adding yet
another class there would make these files even more monolithic. Another option was to add it
to the velox/functions/prestosql/types directory and the so it produces, but given the
InputGenerators are only used for testing it seems they should be separated from the production
code, e.g. into a separate fuzzers subdirectory like we do for InputGenerators for functions.

Excluding those options, one option I'm left with is to break up these files (which generally seems
like a good thing for clarity's sake). This change breaks the custom types into a XXXType.h file
where they Type itself is defined, and XXXRegistration.h/cpp files which define the
registerXXXType() functions.  In most cases the CastOperator and the CustomTypeFactories
do not need to be exposed, so I've included those in the XXXRegistration.cpp file.  The one
exception is JsonCastOperator which I gave it's own JsonCastOperator.h/cpp files.

Presto includes the registerXXXType() functions in some tests from the XXXType.h files, so this
is the first of 3 steps.  Once this lands, I'll update Presto to include the XXXRegistration.h files
instead, then come back and remove the dependency on XXXRegistration.h from the XXXType.h
files, allowing us to break up the so files.

Once this is done InputGenerators can depend on the Type they're generating without
introducing a circular dependency.

Reviewed By: kagamiori

Differential Revision: D69891219
…ion files (facebookincubator#12393)

Summary:
Pull Request resolved: facebookincubator#12393

Today Presto's custom types have a bunch of classes implemented in the same file:
1) The Type itself
2) The CastOperator (if any)
3) The implementation of CustomTypeFactories
In addition to the function registerXXXType()

While implementing an InputGenerator for TimestampWithTimeZone I ran into an issue, I needed
to take a dependency on the TimestampWithTimeZone Type itself (or at least its utility functions).

Since the InputGenerator needs to be referred to by the CustomTypeFactories implementation
this lead to a circular dependency between the so files.

One option is to add the InputGenerator to the TimestampWithTimeZoneType file, but adding yet
another class there would make these files even more monolithic. Another option was to add it
to the velox/functions/prestosql/types directory and the so it produces, but given the
InputGenerators are only used for testing it seems they should be separated from the production
code, e.g. into a separate fuzzers subdirectory like we do for InputGenerators for functions.

Excluding those options, one option I'm left with is to break up these files (which generally seems
like a good thing for clarity's sake). This change breaks the custom types into a XXXType.h file
where they Type itself is defined, and XXXRegistration.h/cpp files which define the
registerXXXType() functions.  In most cases the CastOperator and the CustomTypeFactories
do not need to be exposed, so I've included those in the XXXRegistration.cpp file.  The one
exception is JsonCastOperator which I gave it's own JsonCastOperator.h/cpp files.

Presto includes the registerXXXType() functions in some tests from the XXXType.h files, so this
is the first of 3 steps.  Once this lands, I'll update Presto to include the XXXRegistration.h files
instead, then come back and remove the dependency on XXXRegistration.h from the XXXType.h
files, allowing us to break up the so files.

Once this is done InputGenerators can depend on the Type they're generating without
introducing a circular dependency.

Reviewed By: kagamiori

Differential Revision: D69891219
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69891219

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 1638484.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants