Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tinybirdco/sdk",
"version": "0.0.71",
"version": "0.0.72",
"description": "TypeScript SDK for Tinybird Forward - define datasources and pipes as TypeScript",
"type": "module",
"main": "./dist/index.js",
Expand Down
29 changes: 29 additions & 0 deletions src/generator/pipe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,35 @@ describe('Pipe Generator', () => {
expect(result.content).toContain("{{ Date(start_date, '2025-03-01', required=False) }}");
expect(result.content).toContain('{{ Int32(page, 0, required=False) }}');
});

it('does not inject param metadata into non-param template helper functions', () => {
const pipe = definePipe('helper_params_pipe', {
params: {
siteIds: p
.string()
.optional()
.describe('Comma-separated list of framerSiteId. Only used for test isolation'),
groupBy: p.column().optional().describe('Column to group by'),
},
nodes: [
node({
name: 'endpoint',
sql: 'SELECT {{ column(groupBy) }}, {{ split_to_array(siteIds) }} AS site_ids FROM events',
}),
],
output: simpleOutput,
endpoint: true,
});

const result = generatePipe(pipe);

expect(result.content).toContain('{{ column(groupBy) }}');
expect(result.content).toContain('{{ split_to_array(siteIds) }}');
expect(result.content).not.toContain('split_to_array(siteIds,');
expect(result.content).not.toContain('column(groupBy,');
expect(result.content).not.toContain('required=False');
expect(result.content).not.toContain('description=');
});
});

describe('Multiple nodes', () => {
Expand Down
37 changes: 36 additions & 1 deletion src/generator/pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,31 @@ function hasPositionalDefaultArg(args: string[]): boolean {
return args.slice(1).some((arg) => !/^[a-zA-Z_][a-zA-Z0-9_]*\s*=/.test(arg.trim()));
}

const PARAM_METADATA_TEMPLATE_FUNCTIONS = new Set([
"String",
"UUID",
"Int8",
"Int16",
"Int32",
"Int64",
"Int128",
"Int256",
"UInt8",
"UInt16",
"UInt32",
"UInt64",
"UInt128",
"UInt256",
"Float32",
"Float64",
"Boolean",
"Date",
"DateTime",
"DateTime64",
"Array",
"JSON",
]);

function buildParamTemplateArgs(
args: string[],
validator: AnyParamValidator
Expand Down Expand Up @@ -165,7 +190,13 @@ function applyParamMetadataToSql(
const expression = String(rawExpression);
const rewritten = expression.replace(
/([a-zA-Z_][a-zA-Z0-9_]*)\s*\(([^()]*)\)/g,
(call, _functionName, rawArgs) => {
(call, functionName, rawArgs) => {
if (!PARAM_METADATA_TEMPLATE_FUNCTIONS.has(String(functionName))) {
if (String(functionName) !== "column") {
return call;
}
}

const args = splitTopLevelComma(String(rawArgs));
if (args.length === 0) {
return call;
Expand All @@ -181,6 +212,10 @@ function applyParamMetadataToSql(
return call;
}

if (String(functionName) === "column" && getParamTinybirdType(validator) !== "column") {
return call;
}

const nextArgs = buildParamTemplateArgs(args, validator);
if (nextArgs.length === args.length) {
return call;
Expand Down
Loading