Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions plugins/functions/cdw-svc/src/qe/config/configDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { ruleValidator as rulesLib } from "@alp/alp-config-utils";
import { getTablePlaceholdersFromExpression } from "../utils/queryutils";
export const allowedPlaceholderRegex =
/^((((?!(_SYS|SYS|SYSTEM|HANA_XS_BASE))(\w+)|(_SYS_BIC))|("((?!(_SYS|SYS|SYSTEM|HANA_XS_BASE))([^\]]+)|(_SYS_BIC))"))\."([^"]*)")|^("([^"]*)")$/i;

// A schema must not be a HANA system schema, except _SYS_BIC.
const NOT_SYSTEM_SCHEMA = "(?!(_SYS|SYS|SYSTEM|HANA_XS_BASE))";
const UNQUOTED_SCHEMA = `(${NOT_SYSTEM_SCHEMA}\\w+|_SYS_BIC)`;
const QUOTED_SCHEMA = `"(${NOT_SYSTEM_SCHEMA}[^\\]]+|_SYS_BIC)"`;
// Resolved at query time to the dataset's own schemas.
const SCHEMA_PLACEHOLDER = "\\$\\$(SCHEMA|VOCAB_SCHEMA)\\$\\$";
const QUOTED_TABLE = '"[^"]*"';

// Accepts schema."table" or "table".
export const allowedPlaceholderRegex = new RegExp(
`^((${UNQUOTED_SCHEMA}|${QUOTED_SCHEMA}|${SCHEMA_PLACEHOLDER})\\.${QUOTED_TABLE}|${QUOTED_TABLE})$`,
"i"
);

export function getDefinition(tableMapping: any) {
// Ensure cohort definition placeholders are always defined
Expand Down
13 changes: 0 additions & 13 deletions plugins/functions/cdw-svc/src/utils/trexConnection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Logger } from "@alp/alp-base-utils";
import { translateHanaToDuckdb } from "../../../_shared/alp-base-utils/src/helpers/hanaTranslation";
import { DUCKDB_FILE_SCHEMA_NAME } from "../qe/settings/Defaults";
const logger = Logger.CreateLogger("cdw-svc: trexConnection");
const readyDestinations = new Set<string>();
const destinationLocks = new Map<string, Promise<void>>();
Expand All @@ -16,18 +15,6 @@ const parseSql = (
// $$$$SCHEMA$$$$ is the replacement, but will appear in the string as $$SCHEMA$$
temp = temp.replace(/\$\$SCHEMA_DIRECT_CONN\$\$./g, "$$$$SCHEMA$$$$.");

// This specific translation is required because the create-cachedb-flow plugin creates the duckdb file which as a different database and schema name as the file that is created by trex
if (schemaName !== DUCKDB_FILE_SCHEMA_NAME) {
temp = temp.replace(
/SELECT COUNT\(\*\) AS tableCount from tables where schema_name=(\%s|\?) and table_name=(\%s|\?)/gi,
`select count(*) as "tableCount" from pg_tables where schemaname=%s and tablename=%s`
);
temp = temp.replace(
/select count\(\*\) as \"TABLECOUNT\" from pg_tables where schemaname=(\%s|\?|\$[0-9]) and tablename=(\%s|\?|\$[0-9])/gi,
`select count(*) AS tableCount from information_schema.tables where table_schema=%s and table_name=%s`
);
}

return translateHanaToDuckdb(
temp,
schemaName,
Expand Down
Loading
Loading