From 54f3231db96e6e4c569a7cc94830a37da3d6cc56 Mon Sep 17 00:00:00 2001 From: Ajinkya Ghonge Date: Wed, 5 Apr 2023 12:48:59 -0700 Subject: [PATCH] Create pc_translator library. (#2265) Summary: Pull Request resolved: https://github.com/facebookresearch/fbpcs/pull/2265 # Context As per PC Translator design, we need a runtime library will be called during PC run. This library will be called at the beginning of PC run to encode specified fields in publisher side input into a encoded breakdown (aggregation) Ids based on active PC instruction sets for the run. The library will filter the active PC Instruction sets for the run based on parsing the pcs_features i.e. gatekeepers for the particular run. # Product decisions In this stack we would focus solely on functionality required for private lift runs. We would focus on the MVP implementation of the library and its integration with fbpcf ORAM encoder library in this stack. # Stack 1. Create runtime pc_translator library. 2. Add logic to retrieve and parse PC instruction set, filtered based on the active gatekeepers for the run. 3. Integrate pc_translator library with fbpcf ORAM encoder. 4. Add logic to generate transformed publisher output with encoded breakdown ID and write the output. # In this diff Create runtime pc_translator library. Differential Revision: D44617759 Privacy Context Container: L416713 fbshipit-source-id: 597c84acaaea3b63ee08e9d0b43c6dd2231b4d9a --- fbpcs/pc_translator/PCTranslator.cpp | 39 +++++++++++++++++++++ fbpcs/pc_translator/PCTranslator.h | 52 ++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 fbpcs/pc_translator/PCTranslator.cpp create mode 100644 fbpcs/pc_translator/PCTranslator.h diff --git a/fbpcs/pc_translator/PCTranslator.cpp b/fbpcs/pc_translator/PCTranslator.cpp new file mode 100644 index 000000000..abc23e908 --- /dev/null +++ b/fbpcs/pc_translator/PCTranslator.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include "fbpcs/pc_translator/PCTranslator.h" + +namespace pc_translator { + +std::string PCTranslator::encode(const std::string& /* inputDataset */) { + throw std::runtime_error("Unimplemented"); +} + +std::string PCTranslator::decode( + const std::string& /* aggregatedOutputDataset */) { + throw std::runtime_error("Unimplemented"); +} + +void PCTranslator::retrieveInstructionSets( + std::vector& /* instructionSetNames */) { + throw std::runtime_error("Unimplemented"); +} + +std::vector PCTranslator::retrieveInstructionSetNamesForRun( + const std::string& /* pcsFeatures */) { + throw std::runtime_error("Unimplemented"); +} + +void PCTranslator::transformDataset(const std::string& /* input */) { + throw std::runtime_error("Unimplemented"); +} + +void PCTranslator::parseInstructionSet( + const std::string& /* instructionSet */) { + throw std::runtime_error("Unimplemented"); +} +} // namespace pc_translator diff --git a/fbpcs/pc_translator/PCTranslator.h b/fbpcs/pc_translator/PCTranslator.h new file mode 100644 index 000000000..0107e4025 --- /dev/null +++ b/fbpcs/pc_translator/PCTranslator.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include +#include +#include + +namespace pc_translator { + +/* + * This class contains functions required for PC Translator during actual run + * i.e. retrieving the PC instruction sets, filtering the set per active GK for + * run, encoding and decoding the dataset files input as per the instruction + * set. + */ +class PCTranslator { + public: + explicit PCTranslator(const std::string& pcsFeatures) + : pcsfeatures_(pcsFeatures) {} + + /* + * Method to encode the configurable fields in input dataset as per the active + * pc instruction sets for the run. This method will output the path of + * transformed input dataset, which can be used in further PC run. + */ + std::string encode(const std::string& inputDataset); + + /* + * Method to decode final aggregated output with the encoded breakdown Ids as + * the keys. This method will decode the breakdown Ids to original group Id + * values and format the aggregated output as per the new keys. Output of this + * method would be the path of the decoded aggregated output. + */ + std::string decode(const std::string& aggregatedOutputDataset); + + private: + std::string pcsfeatures_; + void retrieveInstructionSets(std::vector& instructionSetNames); + std::vector retrieveInstructionSetNamesForRun( + const std::string& pcsfeatures); + void parseInstructionSet(const std::string& instructionSet); + void transformDataset(const std::string& input); +}; + +} // namespace pc_translator