Skip to content

Commit fa694c3

Browse files
authored
fix(schema-compiler): Add missing numeric types to scaffolding schema, thanks @XUJiahua (#10079)
1 parent 9f4c3a3 commit fa694c3

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

packages/cubejs-schema-compiler/src/scaffolding/ScaffoldingSchema.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,16 @@ export class ScaffoldingSchema {
387387

388388
if (['time', 'date'].find(t => type.includes(t))) {
389389
return ColumnType.Time;
390-
} else if (['int', 'dec', 'double', 'numb'].find(t => type.includes(t))) {
390+
} else if ([
391+
'int', // integer, bigint, smallint, tinyint, mediumint, uint8, uint16, uint32, uint64, uinteger, ubigint, usmallint, hugeint, byteint, etc.
392+
'dec', // decimal
393+
'double', // double, double precision
394+
'numb', // number, numeric, bignumeric
395+
'float', // float, float4, float8, float32, float64, binary_float
396+
'real', // real
397+
'serial', // serial, bigserial, smallserial
398+
'money', // money, smallmoney
399+
].find(t => type.includes(t))) {
391400
// enums are not Numbers
392401
return ColumnType.Number;
393402
} else if (['bool'].find(t => type.includes(t))) {

packages/cubejs-schema-compiler/test/unit/scaffolding-schema.test.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,4 +554,105 @@ describe('ScaffoldingSchema', () => {
554554
}
555555
]);
556556
});
557+
558+
describe('columnType mapping for numeric types', () => {
559+
it('should map FLOAT types to number', () => {
560+
const floatSchemas = {
561+
public: {
562+
test: [
563+
{ name: 'float_col', type: 'FLOAT', attributes: [] },
564+
{ name: 'float4_col', type: 'FLOAT4', attributes: [] },
565+
{ name: 'float8_col', type: 'FLOAT8', attributes: [] },
566+
{ name: 'float32_col', type: 'FLOAT32', attributes: [] },
567+
{ name: 'float64_col', type: 'FLOAT64', attributes: [] },
568+
]
569+
}
570+
};
571+
const schema = new ScaffoldingSchema(floatSchemas);
572+
floatSchemas.public.test.forEach(col => {
573+
expect((schema as any).columnType(col)).toBe('number');
574+
});
575+
});
576+
577+
it('should map REAL type to number', () => {
578+
const realSchemas = {
579+
public: {
580+
test: [{ name: 'real_col', type: 'REAL', attributes: [] }]
581+
}
582+
};
583+
const schema = new ScaffoldingSchema(realSchemas);
584+
expect((schema as any).columnType(realSchemas.public.test[0])).toBe('number');
585+
});
586+
587+
it('should map SERIAL types to number', () => {
588+
const serialSchemas = {
589+
public: {
590+
test: [
591+
{ name: 'serial_col', type: 'SERIAL', attributes: [] },
592+
{ name: 'bigserial_col', type: 'BIGSERIAL', attributes: [] },
593+
{ name: 'smallserial_col', type: 'SMALLSERIAL', attributes: [] },
594+
]
595+
}
596+
};
597+
const schema = new ScaffoldingSchema(serialSchemas);
598+
serialSchemas.public.test.forEach(col => {
599+
expect((schema as any).columnType(col)).toBe('number');
600+
});
601+
});
602+
603+
it('should map MONEY types to number', () => {
604+
const moneySchemas = {
605+
public: {
606+
test: [
607+
{ name: 'money_col', type: 'MONEY', attributes: [] },
608+
{ name: 'smallmoney_col', type: 'SMALLMONEY', attributes: [] },
609+
]
610+
}
611+
};
612+
const schema = new ScaffoldingSchema(moneySchemas);
613+
moneySchemas.public.test.forEach(col => {
614+
expect((schema as any).columnType(col)).toBe('number');
615+
});
616+
});
617+
618+
it('should map various integer types to number (covered by int keyword)', () => {
619+
const intSchemas = {
620+
public: {
621+
test: [
622+
// Standard integer types
623+
{ name: 'tinyint_col', type: 'TINYINT', attributes: [] },
624+
{ name: 'mediumint_col', type: 'MEDIUMINT', attributes: [] },
625+
{ name: 'hugeint_col', type: 'HUGEINT', attributes: [] },
626+
// Unsigned integer types
627+
{ name: 'uint8_col', type: 'UINT8', attributes: [] },
628+
{ name: 'uint32_col', type: 'UINT32', attributes: [] },
629+
{ name: 'uinteger_col', type: 'UINTEGER', attributes: [] },
630+
{ name: 'ubigint_col', type: 'UBIGINT', attributes: [] },
631+
// Other variants
632+
{ name: 'byteint_col', type: 'BYTEINT', attributes: [] },
633+
]
634+
}
635+
};
636+
const schema = new ScaffoldingSchema(intSchemas);
637+
intSchemas.public.test.forEach(col => {
638+
expect((schema as any).columnType(col)).toBe('number');
639+
});
640+
});
641+
642+
it('should be case insensitive for type matching', () => {
643+
const caseSchemas = {
644+
public: {
645+
test: [
646+
{ name: 'float_lower', type: 'float', attributes: [] },
647+
{ name: 'float_upper', type: 'FLOAT', attributes: [] },
648+
{ name: 'float_mixed', type: 'Float', attributes: [] },
649+
]
650+
}
651+
};
652+
const schema = new ScaffoldingSchema(caseSchemas);
653+
caseSchemas.public.test.forEach(col => {
654+
expect((schema as any).columnType(col)).toBe('number');
655+
});
656+
});
657+
});
557658
});

0 commit comments

Comments
 (0)