def add_new_partitions(self, table_plan):
        date = DateDimension()
        now = date.date_sk_utcnow()

        # Calculate partition limits
        latest = table_plan.partitions[-1]
        step = table_plan.partition_size
        first = latest + step
        limit = now + (table_plan.partition_size *
                       (table_plan.buffer_partitions + 1))

        if limit <= first:
            return

        # Create sql statement
        partitions = []
        for partition in range(first, limit, step):
            partitions.append("PARTITION p_%d VALUES LESS THAN (%d)" %
                              (partition, partition))
        sql = "ALTER TABLE %s ADD PARTITION (%s)" % (table_plan.table,
                                                     ','.join(partitions))

        # Run partitioning command
        with analytical_transaction() as cursor:
            try:
                cursor.execute(sql)
            except:
                conf.log.exception("Adding partitions FAILED! %s" % sql)

        conf.log.info("Added partitions for %s" % table_plan.table)
예제 #2
0
    def add_new_partitions(self, table_plan):
        date = DateDimension()
        now = date.date_sk_utcnow()

        # Calculate partition limits
        latest = table_plan.partitions[-1]
        step = table_plan.partition_size
        first = latest + step
        limit = now + (table_plan.partition_size * (table_plan.buffer_partitions + 1))

        if limit <= first:
            return

        # Create sql statement
        partitions = []
        for partition in range(first, limit, step):
            partitions.append("PARTITION p_%d VALUES LESS THAN (%d)" % (partition, partition))
        sql = "ALTER TABLE %s ADD PARTITION (%s)" % (table_plan.table, ','.join(partitions))

        # Run partitioning command
        with analytical_transaction() as cursor:
            try:
                cursor.execute(sql)
            except:
                conf.log.exception("Adding partitions FAILED! %s" % sql)

        conf.log.info("Added partitions for %s" % table_plan.table)
 def needs_new_partitions(self):
     date = DateDimension()
     now = date.date_sk_utcnow()
     return self.partitions[-1] < now + (
         self.partition_size * self.buffer_partitions + 1)
예제 #4
0
 def needs_new_partitions(self):
     date = DateDimension()
     now = date.date_sk_utcnow()
     return self.partitions[-1] < now + (self.partition_size * self.buffer_partitions + 1)