Пример #1
0
 def __copy__(self):
     output = object.__new__(ColumnList)
     Table.__init__(output, "meta.columns")
     output.data = {
         t: {c: list(cs) for c, cs in dd.items()} for t, dd in self.data.items()
     }
     output.locker = Lock()
     output._schema = None
     return output
Пример #2
0
    def get_columns(self, table_name, column_name=None, force=False):
        """
        RETURN METADATA COLUMNS
        """
        table_path = split_field(table_name)
        es_index_name = table_path[0]
        query_path = join_field(table_path[1:])
        table = self.get_table(es_index_name)[0]
        abs_column_name = None if column_name == None else concat_field(
            query_path, column_name)

        try:
            # LAST TIME WE GOT INFO FOR THIS TABLE
            if not table:
                table = Table(name=es_index_name,
                              url=None,
                              query_path=['.'],
                              timestamp=Date.now())
                with self.meta.tables.locker:
                    self.meta.tables.add(table)
                self._get_columns(table=es_index_name)
            elif force or table.timestamp == None or table.timestamp < Date.now(
            ) - MAX_COLUMN_METADATA_AGE:
                table.timestamp = Date.now()
                self._get_columns(table=es_index_name)

            with self.meta.columns.locker:
                columns = self.meta.columns.find(es_index_name, column_name)
            if columns:
                columns = jx.sort(columns, "names.\.")
                # AT LEAST WAIT FOR THE COLUMNS TO UPDATE
                while len(self.todo) and not all(columns.get("last_updated")):
                    if DEBUG:
                        Log.note(
                            "waiting for columns to update {{columns|json}}",
                            columns=[
                                c.es_index + "." + c.es_column for c in columns
                                if not c.last_updated
                            ])
                    Till(seconds=1).wait()
                return columns
        except Exception as e:
            Log.error("Not expected", cause=e)

        if abs_column_name:
            Log.error("no columns matching {{table}}.{{column}}",
                      table=table_name,
                      column=abs_column_name)
        else:
            self._get_columns(table=table_name)  # TO TEST WHAT HAPPENED
            Log.error("no columns for {{table}}?!", table=table_name)
Пример #3
0
 def __init__(self, db):
     Table.__init__(self, META_COLUMNS_NAME)
     self.data = {}  # MAP FROM fact_name TO (abs_column_name to COLUMNS)
     self.locker = Lock()
     self._schema = None
     self.dirty = False
     self.db = db
     self.es_index = None
     self.last_load = Null
     self.todo = Queue(
         "update columns to es"
     )  # HOLD (action, column) PAIR, WHERE action in ['insert', 'update']
     self._snowflakes = Data()
     self._load_from_database()
Пример #4
0
 def __init__(self, name):
     Table.__init__(self, "meta.columns")
     self.db_file = File("metadata." + name + ".sqlite")
     self.data = {}  # MAP FROM ES_INDEX TO (abs_column_name to COLUMNS)
     self.locker = Lock()
     self._schema = None
     self.db = sqlite3.connect(
         database=self.db_file.abspath, check_same_thread=False, isolation_level=None
     )
     self.last_load = Null
     self.todo = Queue(
         "update columns to db"
     )  # HOLD (action, column) PAIR, WHERE action in ['insert', 'update']
     self._db_load()
     Thread.run("update " + name, self._db_worker)
Пример #5
0
 def __init__(self, es_cluster):
     Table.__init__(self, META_COLUMNS_NAME)
     self.data = {}  # MAP FROM ES_INDEX TO (abs_column_name to COLUMNS)
     self.locker = Lock()
     self._schema = None
     self.dirty = False
     self.es_cluster = es_cluster
     self.es_index = None
     self.last_load = Null
     self.todo = Queue(
         "update columns to es"
     )  # HOLD (action, column) PAIR, WHERE action in ['insert', 'update']
     self._db_load()
     Thread.run("update " + META_COLUMNS_NAME,
                self._update_from_es,
                parent_thread=MAIN_THREAD)
Пример #6
0
 def __init__(self):
     Table.__init__(self, "meta.columns")
     self.data = {}  # MAP FROM ES_INDEX TO (abs_column_name to COLUMNS)
     self.locker = Lock()
     self._schema = None
     self.extend(METADATA_COLUMNS)