Add: Postgres SP and UDF descriptions (#22021)

This commit is contained in:
Suman Maharana 2025-06-30 10:39:09 +05:30 committed by GitHub
parent 10b377590c
commit b4cd7b7046
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 8 deletions

View File

@ -40,7 +40,11 @@ from metadata.generated.schema.entity.services.ingestionPipelines.status import
from metadata.generated.schema.metadataIngestion.workflow import (
Source as WorkflowSource,
)
from metadata.generated.schema.type.basic import EntityName, FullyQualifiedEntityName
from metadata.generated.schema.type.basic import (
EntityName,
FullyQualifiedEntityName,
Markdown,
)
from metadata.ingestion.api.models import Either
from metadata.ingestion.api.steps import InvalidSourceException
from metadata.ingestion.models.ometa_classification import OMetaTagAndClassification
@ -300,9 +304,15 @@ class PostgresSource(CommonDbSourceService, MultiDBSource):
"""List stored procedures"""
if self.source_config.includeStoredProcedures:
yield from self._get_stored_procedures_internal(
POSTGRES_GET_STORED_PROCEDURES
POSTGRES_GET_STORED_PROCEDURES.format(
schema_name=self.context.get().database_schema
)
)
yield from self._get_stored_procedures_internal(
POSTGRES_GET_FUNCTIONS.format(
schema_name=self.context.get().database_schema
)
)
yield from self._get_stored_procedures_internal(POSTGRES_GET_FUNCTIONS)
def yield_stored_procedure(
self, stored_procedure
@ -311,7 +321,9 @@ class PostgresSource(CommonDbSourceService, MultiDBSource):
try:
stored_procedure_request = CreateStoredProcedureRequest(
name=EntityName(stored_procedure.name),
description=None,
description=Markdown(stored_procedure.description)
if stored_procedure.description
else None,
storedProcedureCode=StoredProcedureCode(
language=STORED_PROC_LANGUAGE_MAP.get(stored_procedure.language),
code=stored_procedure.definition,

View File

@ -24,3 +24,4 @@ class PostgresStoredProcedure(BaseModel):
definition: str
language: Optional[str] = None
procedure_type: Optional[str] = Field(None, alias="procedure_type")
description: Optional[str] = Field(None, alias="description")

View File

@ -225,10 +225,12 @@ POSTGRES_GET_STORED_PROCEDURES = """
proargtypes AS argument_types,
prorettype::regtype AS return_type,
prosrc AS definition,
'StoredProcedure' as procedure_type
'StoredProcedure' as procedure_type,
obj_description(pg_proc.oid, 'pg_proc') AS description
FROM pg_proc
JOIN pg_namespace ON pg_proc.pronamespace = pg_namespace.oid
WHERE prokind = 'p';
WHERE prokind = 'p'
and pg_namespace.nspname = '{schema_name}';
"""
POSTGRES_GET_FUNCTIONS = """
@ -238,11 +240,12 @@ SELECT
proargtypes AS argument_types,
prorettype :: regtype AS return_type,
prosrc AS definition,
'Function' as procedure_type
'Function' as procedure_type,
obj_description(pg_proc.oid, 'pg_proc') AS description
FROM
pg_proc
JOIN pg_namespace ON pg_proc.pronamespace = pg_namespace.oid
WHERE
prokind = 'f'
and pg_namespace.nspname NOT IN ('pg_catalog', 'information_schema');
and pg_namespace.nspname = '{schema_name}';
"""