smi2 / phpClickHouse

php ClickHouse wrapper
MIT License
750 stars 139 forks source link

Why is ClickHouseDB\Client::dropPartition() deprecated? #130

Closed JanMikes closed 4 years ago

JanMikes commented 4 years ago

Hello!

We have in our CI detection for deprecated methods and we got reports that dropPartition() is deprecated.

Please what is the reason of being deprecated and is there any suggested replacement? Is it same reason as #82 so we should copy this code to our codebase?

It would be awesome to add reason or replacement suggestions to deprecation annotations to prevent opening this kind of issues :-).

Thank you!

isublimity commented 4 years ago

Hello!

I consider this code dangerous for publication in driver phpCH.

1) This code is not tested, or rather not tested at all

2) i`m think it is isolated and does not apply to the client / driver

3) I do not want to claim that your code deleted me the entire database )))

4) There are different implementations of this now I have this code in prod

  private function getPartitions($table,$days_ago)
    {
        if ($days_ago<3) $days_ago=3;
        $sql='
SELECT *
FROM system.parts
WHERE 
( table=\'' . $table . '\' OR table=\'.inner.view_' . $table . '\'
)
  AND database=\'xxxx\'
AND modification_time<toDateTime(now()-3600*24*'.$days_ago.')
AND max_date<toDateTime(now()-3600*24*'.$days_ago.')';

        return $this->ch()->select($sql)->rows();
    }

 $days_ago = strtotime(date('Y-m-d 04:00:00', strtotime('-' . $days_int_ago . ' day')));
        $drop=[];
        $list_patitions=$this->getPartitions($dbt,$days_int_ago);
        $this->msg("clean $dbt find rows partitions = ".sizeof($list_patitions).' by days='.$days_int_ago);

 foreach ($list_patitions as $partion_id => $partition) {
            $max_date = strtotime($partition['max_date']);
            if ($max_date < $days_ago) {
                $drop[$partition['partition_id']] = $partition;
            }
        }
        foreach ($drop as $partition_id=>$partition) {
            $this->msg("Drop {$partition['table']} , $partition_id on {$partition['max_date']} size = ".$this->humanFileSize($partition['data_compressed_bytes']));
            $sql='ALTER TABLE `'.$partition['table'].'` DROP PARTITION ID \''.$partition_id.'\'';
            $this->ch()->write($sql);
            $this->msg($sql);
        }