Skip to main content

private_sql_query

Private SQL query algorithm.

Classes

PrivateSqlQuery

class PrivateSqlQuery(    *,    query: str,    epsilon: float,    delta: float,    column_ranges: dict,    table: Optional[str] = None,    db_schema: Optional[str] = None,):

Simple algorithm for running a SQL query on a table, with privacy.

note

The values provided for the privacy budget (i.e. epsilon and delta) will be applied individually to all columns included in the SQL query provided. If the total values of the epsilon and delta exceed the maximum allowed by the pod, the provided values will be reduced to the maximum values required to remain within the allowed privacy budget.

Arguments

  • column_ranges: A dictionary of column names and their ranges.
  • db_schema: The name of the schema for a database connection. If not provided, it will be set to the default schema name for the database.
  • delta: The target delta to use for the privacy budget.
  • epsilon: The maximum epsilon to use for the privacy budget.
  • query: The SQL query to execute.
  • table: The target table name. For single table pod datasources, this will default to the pod name.

Attributes

  • class_name: The name of the algorithm class.
  • column_ranges: A dictionary of column names and their ranges.
  • db_schema: The name of the schema for a database connection. If not provided, it will be set to the default schema name for the database.
  • delta: The target delta to use for the privacy budget.
  • epsilon: The maximum epsilon to use for the privacy budget.
  • fields_dict: A dictionary mapping all attributes that will be serialized in the class to their marshamllow field type. (e.g. fields_dict = {"class_name": fields.Str()}).
  • nested_fields: A dictionary mapping all nested attributes to a registry that contains class names mapped to the respective classes. (e.g. nested_fields = {"datastructure": datastructure.registry})
  • query: The SQL query to execute.
  • table: The target table name. For single table pod datasources, this will default to the pod name.

Raises

  • DatabaseSchemaNotFoundError: If a non-existent db_schema name is provided.
  • PrivateSqlError: If there is an error executing the private SQL query (e.g. DP misconfiguration or bad query specified).
  • ValueError: If a pod identifier is not supplied, or if a join is attempted.

Ancestors

  • BaseAlgorithmFactory
  • bitfount.federated.mixins._ModellessAlgorithmMixIn
  • abc.ABC
  • bitfount.federated.roles._RolesMixIn
  • bitfount.types._BaseSerializableObjectMixIn

Variables

Methods


create

def create(self, role: Union[str, Role], **kwargs: Any)> Any:

Create an instance representing the role specified.

execute

def execute(    self,    pod_identifiers: List[str],    username: Optional[str] = None,    bitfounthub: Optional[BitfountHub] = None,    ms_config: Optional[MessageServiceConfig] = None,    message_service: Optional[_MessageService] = None,    pod_public_key_paths: Optional[Mapping[str, Path]] = None,    identity_verification_method: IdentityVerificationMethod = IdentityVerificationMethod.OIDC_DEVICE_CODE,    private_key_or_file: Optional[Union[RSAPrivateKey, Path]] = None,    idp_url: Optional[str] = None,    require_all_pods: bool = False,    aggregator: Optional[_BaseAggregatorFactory] = None,    project_id: Optional[str] = None,)> List[pd.DataFrame]:

Execute ResultsOnly compatible algorithm.

Syntactic sugar to allow the modeller to call .execute(...) on ResultsOnly compatible algorithms.

modeller

def modeller(    self, **kwargs: Any,)> bitfount.federated.algorithms.private_sql_query._ModellerSide:

Returns the modeller side of the PrivateSqlQuery algorithm.

Arguments

  • ****kwargs**: Additional keyword arguments to pass to the modeller side.

worker

def worker(    self, **kwargs: Any,)> bitfount.federated.algorithms.private_sql_query._WorkerSide:

Returns the worker side of the PrivateSqlQuery algorithm.

Arguments

  • **kwargs: Additional keyword arguments to pass to the worker side. hub must be one of these keyword arguments which provides aBitfountHub instance.