grepros 1.3.0
grep for ROS bag files and live topics
Loading...
Searching...
No Matches
PostgresSink Class Reference
Inheritance diagram for PostgresSink:
Inheritance graph

Public Member Functions

 __init__ (self, args=None, **kwargs)
 
 autodetect (cls, target)
 
 validate (self)
 
- Public Member Functions inherited from BaseDataSink
 close (self)
 
 close_output (self)
 
 emit (self, topic, msg, stamp=None, match=None, index=None)
 
- Public Member Functions inherited from Sink
 __enter__ (self)
 
 __exit__ (self, exc_type, exc_value, traceback)
 
 bind (self, source)
 
 configure (self, args=None, **kwargs)
 
 emit_meta (self)
 
 flush (self)
 
 is_highlighting (self)
 
 thread_excepthook (self, text, exc)
 

Public Attributes

 ID_SEQUENCE_STEP
 
 SELECT_TYPE_COLUMNS
 
 valid
 
- Public Attributes inherited from BaseDataSink
 close
 
 COMMIT_INTERVAL
 
 db
 Database connection.
 
- Public Attributes inherited from Sink
 args
 
 source
 inputs.Source instance bound to this sink
 
 valid
 Result of validate()
 
- Public Attributes inherited from SqlMixin
 DIALECTS
 

Static Public Attributes

str ENGINE = "Postgres"
 Database engine name.
 
int ID_SEQUENCE_STEP = 100
 Sequence length per table to reserve for inserted message IDs.
 
list MESSAGE_TYPE_BASECOLS
 Default columns for pkg/MsgType tables.
 
list MESSAGE_TYPE_NESTCOLS
 Additional default columns for pkg/MsgType tables with nesting output.
 
list MESSAGE_TYPE_TOPICCOLS
 Default topic-related columns for pkg/MsgType tables, as [(name, SQL type)].
 
str SELECT_TYPE_COLUMNS
 SQL statement for selecting metainfo on pkg/MsgType table columns.
 
- Static Public Attributes inherited from BaseDataSink
int COMMIT_INTERVAL = 1000
 Number of emits between commits; 0 is autocommit.
 
 DEFAULT_ARGS = dict(META=False, WRITE_OPTIONS={}, VERBOSE=False)
 Constructor argument defaults.
 
 ENGINE = None
 Database engine name, overridden in subclasses.
 
list MESSAGE_TYPE_BASECOLS
 Default columns for pkg/MsgType tables.
 
list MESSAGE_TYPE_NESTCOLS
 Additional default columns for pkg/MsgType tables with nesting output.
 
list MESSAGE_TYPE_TOPICCOLS
 Default topic-related columns for pkg/MsgType tables.
 
- Static Public Attributes inherited from Sink
 DEFAULT_ARGS = dict(META=False)
 Constructor argument defaults.
 
tuple FILE_EXTENSIONS = ()
 Auto-detection file extensions for subclasses, as (".ext", )
 
- Static Public Attributes inherited from SqlMixin
 DEFAULT_ARGS = dict(WRITE_OPTIONS={})
 Constructor argument defaults.
 
str DEFAULT_DIALECT = "sqlite"
 Default SQL dialect used if dialect not specified.
 
dict DIALECTS
 Supported SQL dialects and options.
 
list KEYWORDS
 Words that need quoting if in name context, like table name.
 

Detailed Description

Writes messages to a Postgres database.

Output will have:
- table "topics", with topic and message type names
- table "types", with message type definitions

plus:
- table "pkg/MsgType" for each topic message type, with detailed fields,
  BYTEA fields for uint8[], array fields for scalar list attributes,
  and JSONB fields for lists of ROS messages;
  with foreign keys if nesting else subtype values as JSON dictionaries;
  plus underscore-prefixed fields for metadata, like `_topic` as the topic name.
  If not nesting, only topic message type tables are created.
- view "/full/topic/name" for each topic, selecting from the message type table

If a message type table already exists but for a type with a different MD5 hash,
the new table will have its MD5 hash appended to end, as "pkg/MsgType (hash)".

Definition at line 30 of file postgres.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
  args = None,
**  kwargs 
)
@param   args                 arguments as namespace or dictionary, case-insensitive;
                              or a single item as the database connection string
@param   args.write           Postgres connection string like "postgresql://user@host/db"
@param   args.write_options   ```
                              {"commit-interval": transaction size (0 is autocommit),
                               "nesting": "array" to recursively insert arrays
                                          of nested types, or "all" for any nesting)}
                              ```
@param   args.meta            whether to emit metainfo
@param   args.verbose         whether to emit debug information
@param   kwargs               any and all arguments as keyword overrides, case-insensitive

Reimplemented from BaseDataSink.

Definition at line 79 of file postgres.py.

Member Function Documentation

◆ autodetect()

autodetect (   cls,
  target 
)
Returns true if target is recognizable as a Postgres connection string.

Reimplemented from Sink.

Definition at line 211 of file postgres.py.

◆ validate()

validate (   self)
Returns whether Postgres driver is available,
and "commit-interval" and "nesting" in args.write_options have valid value, if any,
and database is connectable.

Reimplemented from BaseDataSink.

Definition at line 97 of file postgres.py.

Member Data Documentation

◆ ENGINE

str ENGINE = "Postgres"
static

Database engine name.

Definition at line 52 of file postgres.py.

◆ ID_SEQUENCE_STEP [1/2]

int ID_SEQUENCE_STEP = 100
static

Sequence length per table to reserve for inserted message IDs.

Definition at line 55 of file postgres.py.

◆ ID_SEQUENCE_STEP [2/2]

ID_SEQUENCE_STEP

Definition at line 166 of file postgres.py.

◆ MESSAGE_TYPE_BASECOLS

list MESSAGE_TYPE_BASECOLS
static
Initial value:
= [("_dt", "TIMESTAMP"),
("_timestamp", "NUMERIC"),
("_id", "BIGSERIAL PRIMARY KEY"), ]

Default columns for pkg/MsgType tables.

Definition at line 71 of file postgres.py.

◆ MESSAGE_TYPE_NESTCOLS

list MESSAGE_TYPE_NESTCOLS
static
Initial value:
= [("_parent_type", "TEXT"),
("_parent_id", "BIGINT"), ]

Additional default columns for pkg/MsgType tables with nesting output.

Definition at line 75 of file postgres.py.

◆ MESSAGE_TYPE_TOPICCOLS

list MESSAGE_TYPE_TOPICCOLS
static
Initial value:
= [("_topic", "TEXT"),
("_topic_id", "BIGINT"), ]

Default topic-related columns for pkg/MsgType tables, as [(name, SQL type)].

Definition at line 68 of file postgres.py.

◆ SELECT_TYPE_COLUMNS [1/2]

str SELECT_TYPE_COLUMNS
static
Initial value:
= """
SELECT c.table_name, c.column_name, c.data_type
FROM information_schema.columns c INNER JOIN information_schema.tables t
ON t.table_name = c.table_name
WHERE c.table_schema = current_schema() AND t.table_type = 'BASE TABLE' AND
c.table_name LIKE '%/%'
ORDER BY c.table_name, CAST(c.dtd_identifier AS INTEGER)
"""

SQL statement for selecting metainfo on pkg/MsgType table columns.

Definition at line 58 of file postgres.py.

◆ SELECT_TYPE_COLUMNS [2/2]

SELECT_TYPE_COLUMNS

Definition at line 127 of file postgres.py.

◆ valid

valid

Definition at line 112 of file postgres.py.


The documentation for this class was generated from the following file: