Description
When calling a table function from another function with a literal boolean value (e.g., FALSE), the query compiles successfully but fails at runtime with an error about invalid integer input.
Reproduction
Given these two functions:
alerts(orgId String NOT NULL, projectId String NOT NULL, deploymentId String NOT NULL, includeSnoozed BOOLEAN NOT NULL, authOrgIds ARRAY<String> NOT NULL METADATA FROM 'auth.https://datasqrl.com/org_ids'):=
SELECT a.orgId, a.projectId, a.deploymentId,
a.service, a.alertName,
a.alertLevel AS alertLevelCode,
CASE a.alertLevel WHEN 3 THEN 'ERROR' WHEN 2 THEN 'WARN' ELSE 'NOTICE' END AS alertLevel,
a.alertTime, COALESCE(a.alertTime <= s.snoozeUntil, FALSE) AS isSnoozed
FROM _Alerts a
LEFT JOIN _AlertSnooze s ON a.deploymentId = s.deploymentId AND a.alertName = s.alertName
WHERE (
(:deploymentId <> '' AND a.deploymentId = :deploymentId)
OR (:deploymentId = '' AND :projectId <> '' AND a.projectId = :projectId)
OR (:deploymentId = '' AND :projectId = '' AND :orgId <> '' AND a.orgId = :orgId)
)
AND (:includeSnoozed OR s.snoozeUntil IS NULL OR a.alertTime > s.snoozeUntil)
AND (array_contains(cast(:authOrgIds as ARRAY<STRING>), a.orgId) OR array_contains(cast(:authOrgIds as ARRAY<STRING>), 'datasqrl_admin'))
ORDER BY a.projectId, a.deploymentId, a.alertName;
alertCount(orgId String NOT NULL, projectId String NOT NULL, deploymentId String NOT NULL, authOrgIds ARRAY<String> NOT NULL METADATA FROM 'auth.https://datasqrl.com/org_ids'):=
SELECT projectId, deploymentId,
SUM(CASE alertLevelCode WHEN 3 THEN 1 ELSE 0 END) AS numErrors,
SUM(CASE alertLevelCode WHEN 2 THEN 1 ELSE 0 END) AS numWarnings
FROM TABLE(alerts(:orgId, :projectId, :deploymentId, FALSE, :authOrgIds))
WHERE alertLevelCode >= 2
GROUP BY projectId, deploymentId
ORDER BY projectId, deploymentId;
The compilation succeeds, but at runtime the query fails with:
ERROR: invalid input syntax for type integer: "" (22P02)
Expected Behavior
Passing a literal FALSE (or TRUE) value when calling a table function should work correctly.
Workaround
Currently, the workaround is to duplicate the query logic instead of reusing the table function:
alertCount(orgId String NOT NULL, projectId String NOT NULL, deploymentId String NOT NULL, authOrgIds ARRAY<String> NOT NULL METADATA FROM 'auth.https://datasqrl.com/org_ids'):=
SELECT projectId, deploymentId,
SUM(CASE alertLevel WHEN 3 THEN 1 ELSE 0 END) AS numErrors,
SUM(CASE alertLevel WHEN 2 THEN 1 ELSE 0 END) AS numWarnings
FROM (
SELECT a.projectId, a.deploymentId, a.alertLevel FROM _Alerts a
LEFT JOIN _AlertSnooze s ON a.deploymentId = s.deploymentId AND a.alertName = s.alertName
WHERE (
(:deploymentId <> '' AND a.deploymentId = :deploymentId)
OR (:deploymentId = '' AND :projectId <> '' AND a.projectId = :projectId)
OR (:deploymentId = '' AND :projectId = '' AND :orgId <> '' AND a.orgId = :orgId)
)
AND (s.snoozeUntil IS NULL OR a.alertTime > s.snoozeUntil)
AND (array_contains(cast(:authOrgIds as ARRAY<STRING>), a.orgId) OR array_contains(cast(:authOrgIds as ARRAY<STRING>), 'datasqrl_admin'))
)
WHERE alertLevel >= 2
GROUP BY projectId, deploymentId
ORDER BY projectId, deploymentId;
Notes
This pattern works correctly when all parameters are passed as parameter references (e.g., :paramName), as seen in:
backendPendingDeploymentUpdates(authTenantId String NOT NULL METADATA FROM '...', authInstallationId String NOT NULL METADATA FROM '...') :=
SELECT * FROM Table(backendPendingDeploymentUpdatesWithTime(now(), :authTenantId, :authInstallationId));
The issue seems specific to passing literal boolean values.
Description
When calling a table function from another function with a literal boolean value (e.g.,
FALSE), the query compiles successfully but fails at runtime with an error about invalid integer input.Reproduction
Given these two functions:
The compilation succeeds, but at runtime the query fails with:
Expected Behavior
Passing a literal
FALSE(orTRUE) value when calling a table function should work correctly.Workaround
Currently, the workaround is to duplicate the query logic instead of reusing the table function:
Notes
This pattern works correctly when all parameters are passed as parameter references (e.g.,
:paramName), as seen in:The issue seems specific to passing literal boolean values.