Esempio n. 1
0
 def get_rows_not_exists_sql(self) -> str:
     sql = "SELECT count(*) as count " \
           "FROM {schema}.{table} ".format(
         schema=self.schema,
         table=build_collection_name(self.topic.name)
     )
     return sql
def execute_topic_rules(execute_topic_list, current_user):
    for execute_topic in execute_topic_list:
        rule_list = load_topic_rule_list_by_topic_id(execute_topic["topicId"])
        enabled_rules = __find_execute_rule(rule_list)

        if enabled_rules:
            topic_name = build_collection_name(execute_topic["name"])
            log.info("check topic {}".format(topic_name))
            execute_topic_rule(enabled_rules, execute_topic, "monthly", current_user)
Esempio n. 3
0
 def get_another_topic_count_sql(self) -> str:
     sql = "SELECT count(*) as count " \
           "FROM {schema}.{table} " \
           "WHERE update_time_ between timestamp '{from_date}' and timestamp '{to_date}'".format(
         schema=self.schema,
         table=build_collection_name(self.another_topic.name),
         from_date=self.from_date.format('YYYY-MM-DD HH:mm:ss'),
         to_date=self.to_date.format('YYYY-MM-DD HH:mm:ss')
     )
     return sql
 def get_field_sql_with_param(self, factor_name):
     sql = "SELECT {field} " \
           "FROM {schema}.{table} " \
           "WHERE update_time_ between timestamp '{from_date}' and timestamp '{to_date}'".format(
         field=factor_name.lower(),
         schema=self.schema,
         table=build_collection_name(self.topic.name),
         from_date=self.from_date.format('YYYY-MM-DD HH:mm:ss'),
         to_date=self.to_date.format('YYYY-MM-DD HH:mm:ss')
     )
     return sql
Esempio n. 5
0
 def match_date_sql(self):
     sql = "SELECT CAST({field} AS date) " \
           "FROM {schema}.{table} " \
           "WHERE update_time_ between timestamp '{from_date}' and timestamp '{to_date}'".format(
         field=self.factor.name.lower(),
         schema=self.schema,
         table=build_collection_name(self.topic.name),
         from_date=self.from_date.format('YYYY-MM-DD HH:mm:ss'),
         to_date=self.to_date.format('YYYY-MM-DD HH:mm:ss')
     )
     return sql
Esempio n. 6
0
 def get_factor_max_not_in_range_sql(self) -> str:
     sql = "SELECT max({field}, 1) as max " \
           "FROM {schema}.{table} " \
           "WHERE update_time_ between timestamp '{from_date}' and timestamp '{to_date}'".format(
         field=self.factor.name.lower(),
         schema=self.schema,
         table=build_collection_name(self.topic.name),
         from_date=self.from_date.format('YYYY-MM-DD HH:mm:ss'),
         to_date=self.to_date.format('YYYY-MM-DD HH:mm:ss')
     )
     return sql
 def get_value_mode_sql(self) -> str:
     sql = "SELECT {field}, count(*) AS count " \
           "FROM {schema}.{table} " \
           "WHERE update_time_ between timestamp '{from_date}' and timestamp '{to_date}' " \
           "GROUP BY {field} " \
           "ORDER BY {field} DESC " \
           "LIMIT 1".format(
         field=self.factor.name.lower(),
         schema=self.schema,
         table=build_collection_name(self.topic.name),
         from_date=self.from_date.format('YYYY-MM-DD HH:mm:ss'),
         to_date=self.to_date.format('YYYY-MM-DD HH:mm:ss')
     )
     return sql
def __run_execute_rule(execute_topic_list, enabled_rules, current_user):
    for execute_topic in execute_topic_list:
        topic_name = build_collection_name(execute_topic.name)
        log.info("check topic {}".format(topic_name))

        execute_topic_rule(enabled_rules, execute_topic, "daily", current_user)