* [story#59956,0.5h] refactor generateParquetFile.

This commit is contained in:
qixinzhi
2024-07-09 11:15:43 +08:00
committed by 刘刚
parent e9d4788653
commit 93151c58be
2 changed files with 24 additions and 25 deletions
+6 -24
View File
@@ -22,35 +22,17 @@ class bi extends control
public function syncParquetFile()
{
$startTime = microtime(true);
$duckdb = $this->bi->getDuckDBPath();
if(!$duckdb)
{
echo("DuckDB bin path not exists.");
return;
}
$duckdbTmpPath = $this->bi->getDuckDBTmpDir();
if(!$duckdbTmpPath)
{
echo("Create DuckDB tmp dir permission denied.");
return;
}
$copySQL = $this->bi->prepareCopySQL($duckdbTmpPath);
$command = $this->bi->prepareSyncCommand($duckdb->bin, $duckdb->extension, $copySQL);
$output = shell_exec($command);
$endTime = microtime(true);
$runTime = $endTime - $startTime;
$result = $this->bi->generateParquetFile();
$endTime = microtime(true);
$runTime = $endTime - $startTime;
echo "$runTime \n";
if(empty($output))
if($result !== true)
{
echo('success');
echo $result;
return;
}
echo($output);
echo 'success';
}
/**
+18 -1
View File
@@ -829,9 +829,10 @@ class biModel extends model
* @access public
* @return string|false
*/
public function getDuckDBTmpDir()
public function getDuckDBTmpDir($static = false)
{
$duckdbTmpPath = $this->app->getTmpRoot() . 'duckdb' . DS . 'bi' . DS;
if($static) return $duckdbTmpPath;
if(!is_dir($duckdbTmpPath) && !mkdir($duckdbTmpPath, 0755, true)) return false;
return $duckdbTmpPath;
@@ -910,6 +911,22 @@ class biModel extends model
return "$sqlContent 2>&1";
}
public function generateParquetFile()
{
$duckdb = $this->getDuckDBPath();
if(!$duckdb) return $this->lang->bi->binNotExists;
$duckdbTmpPath = $this->getDuckDBTmpDir();
if(!$duckdbTmpPath) return sprintf($this->lang->bi->tmpPermissionDenied, $this->getDuckDBTmpDir(true), $this->getDuckDBTmpDir(true));
$copySQL = $this->prepareCopySQL($duckdbTmpPath);
$command = $this->prepareSyncCommand($duckdb->bin, $duckdb->extension, $copySQL);
$output = shell_exec($command);
if(!empty($output)) return $output;
return true;
}
/**
* Process filter variables in sql.
*