Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
grepros.plugins.sql.SqlSink Class Reference
Inheritance diagram for grepros.plugins.sql.SqlSink:
Inheritance graph
[legend]

Public Member Functions

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

Public Attributes

 valid
 
- Public Attributes inherited from grepros.outputs.Sink
 args
 
 source
 inputs.Source instance bound to this sink More...
 
 valid
 Result of validate() More...
 

Static Public Attributes

 DEFAULT_ARGS = dict(WRITE_OPTIONS={}, VERBOSE=False)
 Constructor argument defaults. More...
 
tuple FILE_EXTENSIONS = (".sql", )
 Auto-detection file extensions. More...
 
list MESSAGE_TYPE_BASECOLS
 Default columns for message type tables, as [(column name, ROS type)]. More...
 
- Static Public Attributes inherited from grepros.outputs.Sink
 DEFAULT_ARGS = dict(META=False)
 Constructor argument defaults. More...
 
tuple FILE_EXTENSIONS = ()
 Auto-detection file extensions for subclasses, as (".ext", ) More...
 
- Static Public Attributes inherited from grepros.plugins.auto.sqlbase.SqlMixin
 DEFAULT_ARGS = dict(META=False, WRITE_OPTIONS={}, MATCH_WRAPPER=None, VERBOSE=False)
 Constructor argument defaults. More...
 
string DEFAULT_DIALECT = "sqlite"
 Default SQL dialect used if dialect not specified. More...
 
dictionary DIALECTS
 Supported SQL dialects and options. More...
 
list KEYWORDS
 Words that need quoting if in name context, like table name. More...
 

Private Member Functions

def _ensure_open (self)
 
def _process_nested (self, msg, rootmsg)
 
def _process_topic (self, topic, msg)
 
def _process_type (self, msg, rootmsg=None)
 
def _write_entity (self, category, item)
 
def _write_header (self)
 

Private Attributes

 _batch
 
 _batch_metas
 
 _close_printed
 
 _file
 
 _filename
 
 _nested_types
 
 _nesting
 
 _overwrite
 

Detailed Description

Writes SQL schema file for message type tables and topic views.

Output will have:
- table "pkg/MsgType" for each topic message type, with ordinary columns for
  scalar fields, and structured columns for list fields;
  plus underscore-prefixed fields for metadata, like `_topic` as the topic name.

  If launched with nesting-option, tables will also be created for each
  nested message type.

- view "/full/topic/name" for each topic, selecting from the message type table

Definition at line 30 of file sql.py.

Constructor & Destructor Documentation

◆ __init__()

def grepros.plugins.sql.SqlSink.__init__ (   self,
  args = None,
**  kwargs 
)
@param   args                 arguments as namespace or dictionary, case-insensitive;
                      or a single path as the file to write
@param   args.write           output file path
@param   args.write_options   ```
                      {"dialect": SQL dialect if not default,
                       "nesting": true|false to created nested type tables,
                       "overwrite": whether to overwrite existing file
                                    (default false)}
                      ```
@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 grepros.outputs.Sink.

Definition at line 56 of file sql.py.

Member Function Documentation

◆ _ensure_open()

def grepros.plugins.sql.SqlSink._ensure_open (   self)
private
Opens output file if not already open, writes header.

Definition at line 160 of file sql.py.

◆ _process_nested()

def grepros.plugins.sql.SqlSink._process_nested (   self,
  msg,
  rootmsg 
)
private
Builds anr writes CREATE TABLE statements for nested types.

Definition at line 208 of file sql.py.

◆ _process_topic()

def grepros.plugins.sql.SqlSink._process_topic (   self,
  topic,
  msg 
)
private
Builds and writes CREATE VIEW statement for topic if not already built.

Definition at line 175 of file sql.py.

◆ _process_type()

def grepros.plugins.sql.SqlSink._process_type (   self,
  msg,
  rootmsg = None 
)
private
Builds and writes CREATE TABLE statement for message type if not already built.

Builds statements recursively for nested types if configured.

@return   built SQL, or None if already built

Definition at line 185 of file sql.py.

◆ _write_entity()

def grepros.plugins.sql.SqlSink._write_entity (   self,
  category,
  item 
)
private
Writes table or view SQL statement to file.

Definition at line 243 of file sql.py.

◆ _write_header()

def grepros.plugins.sql.SqlSink._write_header (   self)
private
Writes header to current file.

Definition at line 225 of file sql.py.

◆ close()

def grepros.plugins.sql.SqlSink.close (   self)
Rewrites out everything to SQL schema file, ensuring all source metas.

Reimplemented from grepros.outputs.Sink.

Definition at line 127 of file sql.py.

◆ emit()

def grepros.plugins.sql.SqlSink.emit (   self,
  topic,
  msg,
  stamp = None,
  match = None,
  index = None 
)
Writes out message type CREATE TABLE statements to SQL schema file.

Reimplemented from grepros.outputs.Sink.

Definition at line 115 of file sql.py.

◆ validate()

def grepros.plugins.sql.SqlSink.validate (   self)
Returns whether "dialect" and "nesting" and "overwrite" parameters contain supported values
and file is writable.

Reimplemented from grepros.outputs.Sink.

Definition at line 92 of file sql.py.

Member Data Documentation

◆ _batch

grepros.plugins.sql.SqlSink._batch
private

Definition at line 78 of file sql.py.

◆ _batch_metas

grepros.plugins.sql.SqlSink._batch_metas
private

Definition at line 80 of file sql.py.

◆ _close_printed

grepros.plugins.sql.SqlSink._close_printed
private

Definition at line 82 of file sql.py.

◆ _file

grepros.plugins.sql.SqlSink._file
private

Definition at line 77 of file sql.py.

◆ _filename

grepros.plugins.sql.SqlSink._filename
private

Definition at line 76 of file sql.py.

◆ _nested_types

grepros.plugins.sql.SqlSink._nested_types
private

Definition at line 79 of file sql.py.

◆ _nesting

grepros.plugins.sql.SqlSink._nesting
private

Definition at line 87 of file sql.py.

◆ _overwrite

grepros.plugins.sql.SqlSink._overwrite
private

Definition at line 81 of file sql.py.

◆ DEFAULT_ARGS

grepros.plugins.sql.SqlSink.DEFAULT_ARGS = dict(WRITE_OPTIONS={}, VERBOSE=False)
static

Constructor argument defaults.

Definition at line 53 of file sql.py.

◆ FILE_EXTENSIONS

tuple grepros.plugins.sql.SqlSink.FILE_EXTENSIONS = (".sql", )
static

Auto-detection file extensions.

Definition at line 46 of file sql.py.

◆ MESSAGE_TYPE_BASECOLS

list grepros.plugins.sql.SqlSink.MESSAGE_TYPE_BASECOLS
static
Initial value:
= [("_topic", "string"),
("_timestamp", "time"), ]

Default columns for message type tables, as [(column name, ROS type)].

Definition at line 49 of file sql.py.

◆ valid

grepros.plugins.sql.SqlSink.valid

Definition at line 111 of file sql.py.


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


grepros
Author(s): Erki Suurjaak
autogenerated on Sat Jan 6 2024 03:11:30