graflo.hq.discovery¶
What a connection offers to read, before any model exists.
:func:discover turns one connection into candidate connectors: the tables of
a database, the classes of a SPARQL endpoint, the topics of a Kafka cluster,
the files under a files connection. A pick of them becomes a bindings block
(:meth:Discovery.bindings), sampled and ingested like any other.
Files in one directory whose names differ only in runs of digits
(part-0001.csv, part-0002.csv) are one candidate, read by a connector
whose regex lets those runs vary; a local directory and an S3 prefix are
listed alike.
A REST API cannot list its own endpoints, so its discovery is empty: its connectors come from the models that bind them.
Attributes¶
DEFAULT_DISCOVERY_LIMIT = 500
module-attribute
¶
KAFKA_METADATA_TIMEOUT_S = 10.0
module-attribute
¶
__all__ = ['DEFAULT_DISCOVERY_LIMIT', 'DiscoveredColumn', 'DiscoveredResource', 'Discovery', 'bindings_for', 'discover', 'kafka_topics', 'sparql_select']
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
DiscoveredColumn
¶
DiscoveredResource
¶
Bases: ConfigBaseModel
One thing a connection offers to read, as the connector that reads it.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Resource name the pick is sampled under; unique in its discovery. |
connector |
AnyConnector
|
The connector that reads it; its |
row_estimate |
int | None
|
Approximate rows (tables) or instances (SPARQL classes). |
size_bytes |
int | None
|
Total size of the files a file connector matches. |
file_count |
int | None
|
Files a file connector matches. |
description |
str | None
|
What the source says the thing is (a table comment). |
columns, |
(primary_key, foreign_keys)
|
What a table declares. |
Source code in graflo/hq/discovery.py
Attributes¶
columns = Field(default_factory=list)
class-attribute
instance-attribute
¶
connector
instance-attribute
¶
description = None
class-attribute
instance-attribute
¶
file_count = None
class-attribute
instance-attribute
¶
foreign_keys = Field(default_factory=list)
class-attribute
instance-attribute
¶
name
instance-attribute
¶
primary_key = Field(default_factory=list)
class-attribute
instance-attribute
¶
row_estimate = None
class-attribute
instance-attribute
¶
size_bytes = None
class-attribute
instance-attribute
¶
Discovery
¶
Bases: ConfigBaseModel
The candidates one connection offers.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
ConnectionKind
|
Kind of the connection discovered. |
resources |
list[DiscoveredResource]
|
Candidates, in the source's order. |
truncated |
bool
|
More candidates exist than were listed. |
Source code in graflo/hq/discovery.py
Attributes¶
kind
instance-attribute
¶
resources = Field(default_factory=list)
class-attribute
instance-attribute
¶
truncated = False
class-attribute
instance-attribute
¶
Methods:¶
bindings(conn_proxy, names=None)
¶
A bindings block reading the picked candidates through conn_proxy.
See :func:bindings_for.
Raises:
| Type | Description |
|---|---|
ValueError
|
A name in names is not a candidate. |
Source code in graflo/hq/discovery.py
Functions:¶
bindings_for(conn_proxy, resources)
¶
A bindings block reading resources through the connection conn_proxy names.
Each resource is read by its connector, renamed to the resource's name so connector names are unique when resource names are, and wired to conn_proxy.
Source code in graflo/hq/discovery.py
discover(conn, *, limit=DEFAULT_DISCOVERY_LIMIT)
¶
The candidates conn offers to read, at most limit of them.
Raises:
| Type | Description |
|---|---|
ValueError
|
conn is not read from (a graph database), or is a database flavour no connector reads. |
Source code in graflo/hq/discovery.py
kafka_topics(conn)
¶
The topics conn's cluster holds, internal ones (__) left out.
Source code in graflo/hq/discovery.py
sparql_select(conn, query)
¶
The bindings of a SELECT query against conn's endpoint.