This commit is contained in:
Adria Navarro 2024-11-04 10:48:14 +01:00
parent 36bbed35e3
commit e41315fb72
1 changed files with 18 additions and 37 deletions

View File

@ -420,6 +420,7 @@ export async function coreOutputProcessing(
rows = await processFormulas(table, rows, { dynamic: true }) rows = await processFormulas(table, rows, { dynamic: true })
// remove null properties to match internal API // remove null properties to match internal API
const isExternal = isExternalTableID(table._id!)
for (const row of rows) { for (const row of rows) {
for (const key of Object.keys(row)) { for (const key of Object.keys(row)) {
if (row[key] === null) { if (row[key] === null) {
@ -434,54 +435,34 @@ export async function coreOutputProcessing(
} }
} }
} }
if (sdk.views.isView(source)) {
// We ensure calculation fields are returned as numbers. During the
// testing of this feature it was discovered that the COUNT operation
// returns a string for MySQL, MariaDB, and Postgres. But given that all
// calculation fields (except ones operating on BIGINTs) should be
// numbers, we blanket make sure of that here.
for (const [name, field] of Object.entries(
helpers.views.calculationFields(source)
)) {
if ("field" in field) {
const targetSchema = table.schema[field.field]
// We don't convert BIGINT fields to floats because we could lose
// precision.
if (targetSchema.type === FieldType.BIGINT) {
continue
}
}
for (const row of rows) {
if (typeof row[name] === "string") {
row[name] = parseFloat(row[name])
}
}
}
}
} }
if (sdk.views.isView(source)) { if (sdk.views.isView(source)) {
const calculationFields = Object.keys( // We ensure calculation fields are returned as numbers. During the
helpers.views.calculationFields(source)
)
// We ensure all calculation fields are returned as numbers. During the
// testing of this feature it was discovered that the COUNT operation // testing of this feature it was discovered that the COUNT operation
// returns a string for MySQL, MariaDB, and Postgres. But given that all // returns a string for MySQL, MariaDB, and Postgres. But given that all
// calculation fields should be numbers, we blanket make sure of that // calculation fields (except ones operating on BIGINTs) should be
// here. // numbers, we blanket make sure of that here.
for (const key of calculationFields) { for (const [name, field] of Object.entries(
helpers.views.calculationFields(source)
)) {
if ("field" in field) {
const targetSchema = table.schema[field.field]
// We don't convert BIGINT fields to floats because we could lose
// precision.
if (targetSchema.type === FieldType.BIGINT) {
continue
}
}
for (const row of rows) { for (const row of rows) {
if (typeof row[key] === "string") { if (typeof row[name] === "string") {
row[key] = parseFloat(row[key]) row[name] = parseFloat(row[name])
} }
} }
} }
} }
const isExternal = isExternalTableID(table._id!)
if (!isUserMetadataTable(table._id!)) { if (!isUserMetadataTable(table._id!)) {
const protectedColumns = isExternal const protectedColumns = isExternal
? PROTECTED_EXTERNAL_COLUMNS ? PROTECTED_EXTERNAL_COLUMNS