Browse Source

fix: cast to string if cast prop defined and value is STRING

pull/7446/head
Pranav C 10 months ago
parent
commit
f917e17a76
  1. 9
      packages/nocodb-sdk/src/lib/formulaHelpers.ts
  2. 17
      packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts

9
packages/nocodb-sdk/src/lib/formulaHelpers.ts

@ -1679,7 +1679,7 @@ export async function validateFormulaAndExtractTreeWithType({
const validateAndExtract = async (parsedTree: any) => {
const res: {
dataType?: FormulaDataTypes;
transform?: FormulaDataTypes;
cast?: FormulaDataTypes;
errors?: Set<string>;
[key: string]: any;
} = { ...parsedTree };
@ -1790,9 +1790,6 @@ export async function validateFormulaAndExtractTreeWithType({
if (expectedArgType === FormulaDataTypes.NUMERIC) {
key = 'msg.formula.numericTypeIsExpected';
message = 'Numeric type is expected';
} else if (expectedArgType === FormulaDataTypes.STRING) {
key = 'msg.formula.stringTypeIsExpected';
message = 'String type is expected';
} else if (expectedArgType === FormulaDataTypes.BOOLEAN) {
key = 'msg.formula.booleanTypeIsExpected';
message = 'Boolean type is expected';
@ -1812,12 +1809,12 @@ export async function validateFormulaAndExtractTreeWithType({
}
}
// if expected type is string and arg type is not string, then transform it to string
// if expected type is string and arg type is not string, then cast it to string
if (
expectedArgType === FormulaDataTypes.STRING &&
expectedArgType !== argPt.dataType
) {
argPt.transform = FormulaDataTypes.STRING;
argPt.cast = FormulaDataTypes.STRING;
}
}
}

17
packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts

@ -746,6 +746,23 @@ async function _formulaQueryBuilder(
arg.fnName = pt.callee.name.toUpperCase();
arg.argsCount = pt.arguments?.length;
});
// if cast is string, then wrap with STRING() function
if (pt.cast === FormulaDataTypes.STRING) {
return fn(
{
type: 'CallExpression',
arguments: [{ ...pt, cast: null }],
callee: {
type: 'Identifier',
name: 'STRING',
},
},
a,
prevBinaryOp,
);
}
if (pt.type === 'CallExpression') {
switch (pt.callee.name.toUpperCase()) {
case 'ADD':

Loading…
Cancel
Save