graflo.hq.sql_inferencer¶
PostgreSQL schema inference and resource mapping (high level).
Schema sanitization for the target DB flavor is intentionally not performed
here. Use :class:graflo.hq.sanitizer.Sanitizer (or
:func:graflo.architecture.evolution.apply_sanitize) on the produced
:class:GraphManifest a posteriori.
SQLInferenceArtifacts
dataclass
¶
Shared inference artifacts derived from one PostgreSQL introspection snapshot.
Source code in graflo/hq/sql_inferencer.py
SQLInferenceManager
¶
Inference manager for PostgreSQL sources.
This class only performs introspection / schema inference / resource
creation. Sanitization for a target DB flavor (reserved words, TigerGraph
identity normalization, etc.) is the caller's responsibility and should be
applied a posteriori via
:class:graflo.hq.sanitizer.Sanitizer.
Source code in graflo/hq/sql_inferencer.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
__init__(conn, target_db_flavor=DBType.ARANGO, fuzzy_threshold=0.8)
¶
Initialize the PostgreSQL inference manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
PostgresConnection
|
PostgresConnection instance |
required |
target_db_flavor
|
DBType
|
Target database flavor (used for type mapping during inference; does NOT trigger sanitization). |
ARANGO
|
fuzzy_threshold
|
float
|
Similarity threshold for fuzzy matching (0.0 to 1.0, default 0.8) |
0.8
|
Source code in graflo/hq/sql_inferencer.py
create_resources(introspection_result, schema)
¶
Create Resources from PostgreSQL introspection result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
introspection_result
|
SchemaIntrospectionResult from PostgreSQL |
required | |
schema
|
Schema
|
Existing Schema object |
required |
Returns:
| Type | Description |
|---|---|
list[Resource]
|
list[Resource]: List of Resources for PostgreSQL tables |
Source code in graflo/hq/sql_inferencer.py
create_resources_for_schema(schema, schema_name=None)
¶
Create Resources from source for an existing schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Existing Schema object |
required |
schema_name
|
str | None
|
Schema name to introspect (source-specific) |
None
|
Returns:
| Type | Description |
|---|---|
list[Resource]
|
list[Resource]: List of Resources for the source |
Source code in graflo/hq/sql_inferencer.py
infer_artifacts(schema_name=None)
¶
Infer schema/resources from a single introspection pass.
Returns:
| Name | Type | Description |
|---|---|---|
SQLInferenceArtifacts |
SQLInferenceArtifacts
|
introspection + schema + ingestion model tuple. The output is NOT sanitized for the target DB flavor. |
Source code in graflo/hq/sql_inferencer.py
infer_complete_schema(schema_name=None)
¶
Infer a complete schema and ingestion model from source.
This is a convenience method that: 1. Introspects the source schema 2. Infers the graflo Schema 3. Creates resources and finishes ingestion init
No sanitization is performed; apply :class:graflo.hq.sanitizer.Sanitizer
a posteriori to the returned manifest if you need it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_name
|
str | None
|
Schema name to introspect (source-specific) |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Schema, IngestionModel]
|
tuple[Schema, IngestionModel]: Complete schema and ingestion model |
Source code in graflo/hq/sql_inferencer.py
infer_schema(introspection_result, schema_name=None)
¶
Infer graflo Schema from PostgreSQL introspection result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
introspection_result
|
SchemaIntrospectionResult from PostgreSQL |
required | |
schema_name
|
str | None
|
Schema name (optional, may be inferred from result) |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Schema |
Schema
|
Inferred schema with vertices and edges |
Source code in graflo/hq/sql_inferencer.py
introspect(schema_name=None, include_raw_tables=False)
¶
Introspect PostgreSQL schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_name
|
str | None
|
Schema name to introspect |
None
|
include_raw_tables
|
bool
|
Whether to build sampled per-column raw table metadata. Defaults to False for performance (binding/schema inference does not require it). |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
SchemaIntrospectionResult |
SchemaIntrospectionResult
|
PostgreSQL schema introspection result |