You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A very useful application of the Replacer API is to replace a Table<?> by another. For example, when implementing CockroachDB UDF support (#13947), the INFORMATION_SCHEMA.ROUTINES and INFORMATION_SCHEMA.PARAMETERS views cannot be used yet (see cockroachdb/cockroach#104083), so it would be useful to be able to substitute all references to these views by their definition in the form of a correlated subquery. E.g. instead of:
selectr1.routine_schema,
r1.routine_name,
r1.specific_name,
r1.routine_type,
case
when (
r1.data_type='USER-DEFINED'andr1.type_udt_name='geometry'
) then 'geometry'
when (pg_catalog.pg_proc.proargmodes && ARRAY['o','b']::"char"[]) then 'void'
when r1.data_type='ARRAY' then (substring(r1.type_udt_name, 2) ||' ARRAY')
else r1.data_type
end as data_type,
r1.character_maximum_length,
case
when (
r1.numeric_precision is nullandr1.data_typein (
'time', 'timetz', 'time without time zone', 'time with time zone', 'timestamp',
'timestamptz', 'timestamp without time zone', 'timestamp with time zone'
)
) then 6
else r1.numeric_precision
end as numeric_precision,
r1.numeric_scale,
r1.type_udt_schema,
case
when r1.data_type='ARRAY' then substring(r1.type_udt_name, 2)
else r1.type_udt_name
end as type_udt_name,
case
when count(*) over (partition by r1.routine_schema, r1.routine_name) >1 then row_number() over (
partition by r1.routine_schema, r1.routine_nameorder byr1.specific_name
)
end as overload,
(pg_catalog.pg_proc.prokind ='a') as is_agg
frominformation_schema.routinesas r1
join (
pg_catalog.pg_procjoinpg_catalog.pg_namespaceas alias_120026365
onpg_catalog.pg_proc.pronamespace =alias_120026365.oid
)
on (
alias_120026365.nspname=r1.specific_schemaand ((pg_catalog.pg_proc.proname ||'_') || cast(pg_catalog.pg_proc.oidas string)) =r1.specific_name
)
left outer joinpg_catalog.pg_typeas rett
onpg_catalog.pg_proc.prorettype =rett.oidwhere (
r1.routine_schemain ('public')
and not (pg_catalog.pg_proc.proretset)
andr1.data_type is distinct from'trigger'
)
order byr1.routine_schemaasc, r1.routine_nameasc, overload asc
We'll run:
selectr1.routine_schema,
r1.routine_name,
r1.specific_name,
r1.routine_type,
case
when (
r1.data_type='USER-DEFINED'andr1.type_udt_name='geometry'
) then 'geometry'
when (pg_catalog.pg_proc.proargmodes && ARRAY['o','b']::"char"[]) then 'void'
when r1.data_type='ARRAY' then (substring(r1.type_udt_name, 2) ||' ARRAY')
else r1.data_type
end as data_type,
r1.character_maximum_length,
case
when (
r1.numeric_precision is nullandr1.data_typein (
'time', 'timetz', 'time without time zone', 'time with time zone', 'timestamp',
'timestamptz', 'timestamp without time zone', 'timestamp with time zone'
)
) then 6
else r1.numeric_precision
end as numeric_precision,
r1.numeric_scale,
r1.type_udt_schema,
case
when r1.data_type='ARRAY' then substring(r1.type_udt_name, 2)
else r1.type_udt_name
end as type_udt_name,
case
when count(*) over (partition by r1.routine_schema, r1.routine_name) >1 then row_number() over (
partition by r1.routine_schema, r1.routine_nameorder byr1.specific_name
)
end as overload,
(pg_catalog.pg_proc.prokind ='a') as is_agg
from (
selectalias_29657451.nspnameas specific_schema,
((p.proname||'_') || cast(p.oidas string)) as specific_name,
alias_29657451.nspnameas routine_schema,
p.pronameas routine_name,
'f'as routine_type,
case
when p.prokind='p' then null
when (
alias_95693412.typelem<>0andalias_95693412.typlen=-1
) then 'ARRAY'
when alias_100611083.nspname='pg_catalog' then format_type(alias_95693412.oid, null)
else 'USER-DEFINED'
end as data_type,
alias_95693412.typnameas type_udt_name,
alias_100611083.nspnameas type_udt_schema,
nullas character_maximum_length,
nullas numeric_precision,
nullas numeric_scale,
nullas type_udt_schema
from (
pg_catalog.pg_procas p
joinpg_catalog.pg_namespaceas alias_29657451
onp.pronamespace=alias_29657451.oidjoin (
pg_catalog.pg_typeas alias_95693412
joinpg_catalog.pg_namespaceas alias_100611083
onalias_95693412.typnamespace=alias_100611083.oid
)
onp.prorettype=alias_95693412.oid
)
) as r1
join (
pg_catalog.pg_procjoinpg_catalog.pg_namespaceas alias_120026365
onpg_catalog.pg_proc.pronamespace =alias_120026365.oid
)
on (
alias_120026365.nspname=r1.specific_schemaand ((pg_catalog.pg_proc.proname ||'_') || cast(pg_catalog.pg_proc.oidas string)) =r1.specific_name
)
left outer joinpg_catalog.pg_typeas rett
onpg_catalog.pg_proc.prorettype =rett.oidwhere (
r1.routine_schemain ('public')
and not (pg_catalog.pg_proc.proretset)
andr1.data_type is distinct from'trigger'
)
order byr1.routine_schemaasc, r1.routine_nameasc, overload asc
Users can obviously write the Replacer themselves, but they'd have to think of all the edge cases, including:
Direct references to TableImpl
Aliased TableImpl
Direct references to TableFieldImpl
Aliased TableImpl references to TableFieldImpl
Possibly others
Tasks:
Add a simple Replacers.replacingTable() utility
Add an SPI that allows for composing these more simply, in case multiple such replacements are necessary
Possibly add a feature set that pulls up all these replacements to CTE
The text was updated successfully, but these errors were encountered:
A very useful application of the
Replacer
API is to replace aTable<?>
by another. For example, when implementing CockroachDB UDF support (#13947), theINFORMATION_SCHEMA.ROUTINES
andINFORMATION_SCHEMA.PARAMETERS
views cannot be used yet (see cockroachdb/cockroach#104083), so it would be useful to be able to substitute all references to these views by their definition in the form of a correlated subquery. E.g. instead of:We'll run:
Users can obviously write the
Replacer
themselves, but they'd have to think of all the edge cases, including:TableImpl
TableImpl
TableFieldImpl
TableImpl
references toTableFieldImpl
Tasks:
Replacers.replacingTable()
utilityThe text was updated successfully, but these errors were encountered: