-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lucio Anderlini
authored and
Lucio Anderlini
committed
Aug 20, 2023
1 parent
a4a93e4
commit 3e7b915
Showing
6 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration. | ||
// | ||
// This software is distributed under the terms of the GNU General Public | ||
// Licence version 3 (GPL Version 3), copied verbatim in the file "LICENCE". | ||
// | ||
// In applying this licence, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
#pragma once | ||
|
||
// STL | ||
#include <string> | ||
#include <vector> | ||
|
||
// SQLamarr | ||
#include "SQLamarr/BaseSqlInterface.h" | ||
#include "SQLamarr/Transformer.h" | ||
|
||
namespace SQLamarr | ||
{ | ||
/** Execute a query non returning anything, but modifying the event store. | ||
* | ||
* Sometimes it may be necessary to modify the event model during the | ||
* execution of a pipeline, for example to drop tables or to add columns | ||
* to existing ones, or even to update some table. | ||
* | ||
* EditEventStore provides a generic building block which enables | ||
* executing arbitrary queries to the SQLite3 database, without storing the | ||
* output, if any. | ||
* | ||
*/ | ||
class EditEventStore: public BaseSqlInterface, public Transformer | ||
{ | ||
public: | ||
/// Constructor | ||
EditEventStore ( | ||
SQLite3DB& db, | ||
///< Reference to the database | ||
const std::vector<std::string>& queries | ||
///< Vector of queries to be executed in a single transaction | ||
); | ||
|
||
|
||
/// Execute the algorithm, cleaning the database | ||
void execute () override; | ||
|
||
private: | ||
const std::vector<std::string> m_queries; | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration. | ||
# | ||
# This software is distributed under the terms of the GNU General Public | ||
# Licence version 3 (GPL Version 3), copied verbatim in the file "LICENCE". | ||
# | ||
# In applying this licence, CERN does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an Intergovernmental Organization | ||
# or submit itself to any jurisdiction. | ||
import ctypes | ||
from ctypes import POINTER | ||
from SQLamarr import clib, c_TransformerPtr | ||
|
||
from SQLamarr.db_functions import SQLite3DB | ||
|
||
from typing import List, Union | ||
|
||
clib.new_EditEventStore.argtypes = ( | ||
ctypes.c_void_p, # void *db, | ||
ctypes.c_char_p, # const char* semicolon_separated_queries, | ||
) | ||
|
||
clib.new_EditEventStore.restype = c_TransformerPtr | ||
|
||
class EditEventStore: | ||
""" | ||
Execute a transaction with multiple custom queries without | ||
returning any output. | ||
Refer to SQLamarr::EditEventStore for implementation details. | ||
""" | ||
def __init__ (self, db: SQLite3DB, queries: Union[str,List[str]]): | ||
""" | ||
Configure a Transformer to edit the schema of the EventStore | ||
@param db: An open database connection. | ||
@param queries: One or more queries to be processed in single transaction | ||
""" | ||
if isinstance(queries, str): | ||
queries = [queries] | ||
|
||
self._self = clib.new_EditEventStore( | ||
db.get(), | ||
";".join(queries).encode('ascii') | ||
) | ||
|
||
def __del__(self): | ||
"""@private: Release the bound class instance""" | ||
clib.del_Transformer(self._self) | ||
|
||
@property | ||
def raw_pointer(self): | ||
"""@private: Return the raw pointer to the algorithm.""" | ||
return self._self | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration. | ||
// | ||
// This software is distributed under the terms of the GNU General Public | ||
// Licence version 3 (GPL Version 3), copied verbatim in the file "LICENCE". | ||
// | ||
// In applying this licence, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
|
||
// STL | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
// SQLite3 | ||
#include "sqlite3.h" | ||
|
||
// SQLamarr | ||
#include "SQLamarr/EditEventStore.h" | ||
|
||
namespace SQLamarr | ||
{ | ||
//============================================================================ | ||
// Constructor | ||
//============================================================================ | ||
EditEventStore::EditEventStore( | ||
SQLite3DB& db, | ||
const std::vector<std::string>& queries | ||
) | ||
: BaseSqlInterface(db) | ||
, m_queries (queries) | ||
{} | ||
|
||
//============================================================================ | ||
// execute | ||
//============================================================================ | ||
void EditEventStore::execute() | ||
{ | ||
int counter = 0; | ||
char buffer[1024]; | ||
exec_stmt(get_statement("BEGIN", "BEGIN EXCLUSIVE TRANSACTION")); | ||
for (auto& query: m_queries) | ||
{ | ||
sprintf(buffer, "EditEventStore%02d", counter++); | ||
exec_stmt(get_statement(buffer, query.c_str())); | ||
} | ||
|
||
exec_stmt(get_statement("COMMIT", "COMMIT TRANSACTION")); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters