noc.core.clickhouse.model

Module Contents

class noc.core.clickhouse.model.Model(**kwargs)

Bases: six.with_metaclass()

class Meta

Bases: object

engine
db_table
description
sample = False
tags
managed = True
classmethod _get_db_table(cls)
classmethod _get_raw_db_table(cls)
classmethod wrap_table(cls, table_name)
static quote_name(name)

Clickhouse-safe field names

Parameters:name
Returns:
classmethod iter_create_sql(cls)

Yields (field name, db type) for all model’s fields :return:

classmethod get_create_fields_sql(cls)

Fields creation statements

Returns:SQL code with field creation statements
classmethod get_create_sql(cls)
classmethod get_create_distributed_sql(cls)

Get CREATE TABLE for Distributed engine :return:

classmethod to_json(cls, **kwargs)

Convert dict of kwargs to JSON-serializable dict

Parameters:kwargs
Returns:
classmethod to_python(cls, row, **kwargs)
classmethod ensure_columns(cls, connect, table_name)

Create necessary table columns

Parameters:
  • connect – ClickHouse client
  • table_name – Database table name
Returns:

True, if any column has been altered

classmethod ensure_table(cls, connect=None)

Check table is exists :param connect: :return: True, if table has been altered, False otherwise

classmethod transform_query(cls, query, user)

Transform query, possibly applying access restrictions :param query: :param user: :return: query dict or None if access denied

classmethod query(cls, query, user=None, dry_run=False)

Execute query and return result :param query: dict of

“fields”: list of dicts
*expr – field expression *alias – resulting name *group – nth field in GROUP BY expression, starting from 0 *order – nth field in ORDER BY expression, starting from 0 *desc – sort in descending order, if true

“filter”: expression “having”: expression “limit”: N – limit to N rows “offset”: N – skip first N rows “sample”: 0.0-1.0 – randomly select rows @todo: group by @todo: order by

Parameters:
  • user – User doing query
  • dry_run – Do not query, only return it.
Returns:

classmethod get_pk_name(cls)

Get primary key’s name

Returns:Field name
class noc.core.clickhouse.model.NestedModel

Bases: noc.core.clickhouse.model.Model

classmethod get_create_sql(cls)