Skip to content

Commit

Permalink
Update column record_count at table as_previ when table has content
Browse files Browse the repository at this point in the history
  • Loading branch information
mpartio committed Mar 28, 2024
1 parent 4b8a1cc commit 2d37076
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion himan-plugins/source/radon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ pair<bool, radon_record> radon::SavePrevi(const info<T>& resultInfo, bool dryRun

auto analysisTime = resultInfo.Time().OriginDateTime().String("%Y-%m-%d %H:%M:%S+00");

query << "SELECT id,schema_name,table_name,partition_name FROM as_previ WHERE producer_id = "
query << "SELECT id,schema_name,table_name,partition_name,record_count FROM as_previ WHERE producer_id = "
<< resultInfo.Producer().Id() << " AND (min_analysis_time, max_analysis_time) OVERLAPS ('" << analysisTime
<< "', '" << analysisTime << "')";

Expand All @@ -577,6 +577,7 @@ pair<bool, radon_record> radon::SavePrevi(const info<T>& resultInfo, bool dryRun
const string& schema_name = row[1];
const string& table_name = row[2];
const string& partition_name = row[3];
const string& record_count = row[4];

auto levelinfo = itsRadonDB->GetLevelFromDatabaseName(HPLevelTypeToString.at(resultInfo.Level().Type()));

Expand Down Expand Up @@ -680,6 +681,17 @@ pair<bool, radon_record> radon::SavePrevi(const info<T>& resultInfo, bool dryRun
}
}

if (record_count.empty() || record_count == "0")
{
itsLogger.Trace("Updating as_previ record_count column for " + table_name);

query.str("");
query << "UPDATE as_previ SET record_count = 1 WHERE schema_name = '" << schema_name
<< "' AND partition_name = '" << partition_name << "' AND analysis_time = '" << analysisTime << "'"
<< " AND producer_id = " << resultInfo.Producer().Id();

itsRadonDB->Execute(query.str());
}
return make_pair(true, radon_record(schema_name, table_name, partition_name, "", -1));
}

Expand Down

0 comments on commit 2d37076

Please sign in to comment.