Browse Source

Merge pull request #2132 from nocodb/fix/formula

fix: issues related to formula
pull/2139/head
աɨռɢӄաօռɢ 3 years ago committed by GitHub
parent
commit
5873208263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      packages/nc-gui/components/project/spreadsheet/components/editColumn/FormulaOptions.vue
  2. 3
      packages/nocodb-sdk/src/lib/formulaHelpers.ts
  3. 1
      packages/nocodb/src/lib/dataMapper/lib/sql/formulav2/formulaQueryBuilderv2.ts

8
packages/nc-gui/components/project/spreadsheet/components/editColumn/FormulaOptions.vue

@ -490,7 +490,7 @@ export default {
case UITypes.PhoneNumber: case UITypes.PhoneNumber:
case UITypes.Email: case UITypes.Email:
case UITypes.URL: case UITypes.URL:
return 'string' return formulaTypes.STRING
// numeric // numeric
case UITypes.Year: case UITypes.Year:
@ -499,14 +499,14 @@ export default {
case UITypes.Rating: case UITypes.Rating:
case UITypes.Count: case UITypes.Count:
case UITypes.AutoNumber: case UITypes.AutoNumber:
return 'number' return formulaTypes.NUMERIC
// date // date
case UITypes.Date: case UITypes.Date:
case UITypes.DateTime: case UITypes.DateTime:
case UITypes.CreateTime: case UITypes.CreateTime:
case UITypes.LastModifiedTime: case UITypes.LastModifiedTime:
return 'date' return formulaTypes.DATE
// not supported // not supported
case UITypes.ForeignKey: case UITypes.ForeignKey:
@ -527,7 +527,7 @@ export default {
} }
} }
} else if (parsedTree.type === jsep.BINARY_EXP || parsedTree.type === jsep.UNARY_EXP) { } else if (parsedTree.type === jsep.BINARY_EXP || parsedTree.type === jsep.UNARY_EXP) {
return 'number' return formulaTypes.NUMERIC
} else if (parsedTree.type === jsep.LITERAL) { } else if (parsedTree.type === jsep.LITERAL) {
return typeof parsedTree.value return typeof parsedTree.value
} else { } else {

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

@ -84,9 +84,6 @@ export function substituteColumnIdWithAliasInFormula(
c.title === colNameOrId c.title === colNameOrId
); );
pt.name = column?.title || ptRaw?.name || pt?.name; pt.name = column?.title || ptRaw?.name || pt?.name;
if (pt.name[0] != '$' && pt.name[pt.name.length - 1] != '$') {
pt.name = '$' + pt.name + '$';
}
} else if (pt.type === 'BinaryExpression') { } else if (pt.type === 'BinaryExpression') {
substituteId(pt.left, ptRaw?.left); substituteId(pt.left, ptRaw?.left);
substituteId(pt.right, ptRaw?.right); substituteId(pt.right, ptRaw?.right);

1
packages/nocodb/src/lib/dataMapper/lib/sql/formulav2/formulaQueryBuilderv2.ts

@ -69,6 +69,7 @@ export default async function formulaQueryBuilderv2(
model, model,
{ ...aliasToColumn, [col.id]: null } { ...aliasToColumn, [col.id]: null }
); );
builder.sql = '(' + builder.sql + ')';
aliasToColumn[col.id] = builder; aliasToColumn[col.id] = builder;
} }
break; break;

Loading…
Cancel
Save