Skip to content

Commit

Permalink
mtoy's take on the changes ... passes ci-snowflake
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoy-googly-moogly committed Jan 9, 2025
1 parent 4426044 commit c00b584
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"test-bigquery": "MALLOY_DATABASE=bigquery jest --runInBand",
"test-postgres": "MALLOY_DATABASE=postgres jest --runInBand",
"test-duckdb": "JEST_SILENT_REPORTER_SHOW_PATHS=true MALLOY_DATABASE=duckdb jest --runInBand --reporters jest-silent-reporter",
"ci-snowflake": "JEST_SILENT_REPORTER_SHOW_PATHS=true jest --config jest.snowflake.config.ts --reporters jest-silent-reporter --reporters summary",
"test-silent": "JEST_SILENT_REPORTER_SHOW_PATHS=true jest --runInBand --reporters jest-silent-reporter --no-color",
"test-deps": "npm run build && npx jest -t dependencies",
"third-party-licenses": "ts-node scripts/third_party_licenses",
Expand Down
30 changes: 15 additions & 15 deletions packages/malloy-db-snowflake/src/snowflake_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,24 +329,24 @@ export class SnowflakeConnection
}
// For these things, we need to sample the data to know the schema
if (variants.length > 0) {
// * decimal and integer should be treated as the same type.
// * remove null values
// * remove fields for which we have multiple types
// * make sure that the regexp path is properly escaped. we want
// something like \\[[0-9]+\\] in the final query.
// ( requires folding decimal to integer )
const sampleQuery = `
SELECT PATH, min(type) as type
FROM (
SELECT regexp_replace(PATH, '\\\\[[0-9]+\\\\]', '[*]') as PATH,
CASE WHEN lower(TYPEOF(value)) = 'integer' THEN 'decimal' ELSE lower(TYPEOF(value)) END as type
FROM (select object_construct(*) o from ${tablePath} limit 100)
,table(flatten(input => o, recursive => true)) as meta
GROUP BY 1,2
)
WHERE type != 'null_value'
group by 1
having count(*) <=1
ORDER By PATH;
select path, min(type) as type
from (
select
regexp_replace(path, '\\[[0-9]+\\]', '[*]') as path,
case when typeof(value) = 'INTEGER' then 'decimal' else lower(typeof(value)) end as type
from
(select object_construct(*) o from ${tablePath} limit 100)
,table(flatten(input => o, recursive => true)) as meta
group by 1,2
)
where type != 'null_value'
group BY 1
having count(*) <=1
order by path;
`;
const fieldPathRows = await this.executor.batch(sampleQuery);

Expand Down
10 changes: 5 additions & 5 deletions packages/malloy/src/dialect/snowflake/snowflake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ export class SnowflakeDialect extends Dialect {
const sqlName = this.sqlMaybeQuoteIdentifier(childName);
if (childName === '__row_id') {
return `"${parentAlias}".INDEX::varchar`;
} else if (
parentType === 'array[scalar]' ||
parentType === 'array[record]'
) {
const arrayRef = `"${parentAlias}".value`;
} else if (parentType.startsWith('array')) {
let arrayRef = `"${parentAlias}".value`;
if (parentType === 'array[record]') {
arrayRef += `:${sqlName}`;
}
switch (childType) {
case 'record':
case 'array':
Expand Down

0 comments on commit c00b584

Please sign in to comment.