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

Renames all hidden built-in functions using unicode non-character #1695

Merged
merged 5 commits into from
Jan 7, 2025

Conversation

johnedquinn
Copy link
Member

@johnedquinn johnedquinn commented Jan 3, 2025

Description

  • Prefixes all hidden built-in functions using unicode non-character
  • If there is a customer need for overriding these built-ins, we can standardize/publicize this and/or make it more user-friendly

License Information

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@johnedquinn johnedquinn marked this pull request as ready for review January 3, 2025 21:55
@johnedquinn johnedquinn requested a review from alancai98 January 3, 2025 21:55
@@ -65,7 +65,7 @@ internal val Fn_DATE_ADD_MONTH__INT_DATE__DATE = Function.static(
Datum.date(datetimeValue.plusMonths(intervalValue))
}

internal val Fn_DATE_ADD_MONTH__INT32_TIMESTAMP__TIMESTAMP = Function.static(
internal val Fn_DATE_ADD_MONTH__INT32_TIMESTAMP__TIMESTAMP = FunctionUtils.hidden(
Copy link
Member

Choose a reason for hiding this comment

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

See these, I recommend just adding ".hidden" or ".system" to Function rather than FunctionUtils, but I also don't know if you had to deal with visibility modifier issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that would just make them public, which I'm hoping to avoid in this PR.

@@ -1752,9 +1762,10 @@ internal class PartiQLParserDefault : PartiQLParser {
val rhs = visitExpr(ctx.expr(1))
val fieldLit = ctx.dt.text.lowercase()
// TODO error on invalid datetime fields like TIMEZONE_HOUR and TIMEZONE_MINUTE
// TODO: This should (likely) be parsed into its own node. The planner should convert this into a call.
Copy link
Member

Choose a reason for hiding this comment

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

So do we now think that DATE_ADD and DATE_DIFF should be their own nodes in the AST? For some context, we had those special form functions as their own node in v0.14 and prior. Then for the AST migration, we switched to define them as ExprCalls -- #1579 (comment).

With how it's currently modeled, it was somewhat messy to parse and perform other operations like pretty-printing in SqlDialect -- #1638 (comment). And as we can see here, it's messy to port the hidden prefix logic into the parser package.

We could defer this decision to post-v1 since adding a dedicated node for DATE_ADD and DATE_DIFF would be an additive change.

Copy link
Member Author

Choose a reason for hiding this comment

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

True. For now, I'm just adding the prefix and leaving the TODO. Post V1, it might be a good idea to reintroduce those nodes or go with the translation that Robert mentioned. I don't have a preference.

import org.partiql.spi.function.utils.StringUtils.codepointTrimTrailing
import org.partiql.spi.value.Datum
import org.partiql.types.PType

internal val Fn_TRIM_TRAILING__STRING__STRING = Function.static(
Copy link
Member

Choose a reason for hiding this comment

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

Seems like some other functions aren't hidden yet. Taking a look at the https://github.com/johnedquinn/partiql-lang-jvm/blob/main-builtins-names/partiql-spi/src/main/kotlin/org/partiql/spi/function/Builtins.kt#L21,

  • abs
  • bit_length
  • cardinality
  • char_length
  • lower
  • (some others)

Copy link
Member Author

Choose a reason for hiding this comment

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

These are public in SQL. See Section 20.70 and 6.17.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Perhaps could be good to add a comment at some place (perhaps in the FunctionUtils.kt) that these SQL99-defined scalar and aggregation function names are purposely not hidden.

/**
* Returns an implementation of a [Function] that has the [name] obfuscated via the [SYSTEM_PREFIX_INTERNAL].
*/
fun hidden(
Copy link
Member

Choose a reason for hiding this comment

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

Will aggregations also be hidden w/ the special prefix?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. See #1695 (comment). Same reasoning.

internal val Fn_NOT__BOOL__BOOL = object : Function {

private var name = "not"
private val name = FunctionUtils.SYSTEM_PREFIX_INTERNAL + "not"
Copy link
Member

Choose a reason for hiding this comment

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

There are some functions (like here and IS_MISSING, IS_NULL, etc) that do not directly use the FunctionUtils.hidden method. Is that because they haven't been migrated to use the new interface (from #1646)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not necessarily. They don't have a bunch of overloads, so they don't need to directly implement the new interface.

@RCHowell
Copy link
Member

RCHowell commented Jan 7, 2025

Overall LGTM and gets that job done, but you may want to consider not having a FunctionUtils and not listing out the names of functions. It would be better to just reference the name on the operator itself. It's not ideal to have the names floating around in multiple places because now the process of adding operators is fragile and requires updating in multiple places which does not scale well. I recommend brainstorming better ways to register and reference builtins that does not require juggling

RCHowell
RCHowell previously approved these changes Jan 7, 2025
@johnedquinn johnedquinn merged commit 0d123c2 into partiql:main Jan 7, 2025
7 checks passed
@johnedquinn johnedquinn deleted the main-builtins-names branch January 7, 2025 23:08
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