An algorithm and data decoupling method and system based on logical-physical mapping
By employing a logical-physical mapping-based algorithm and data decoupling method, the coupling problem between algorithm code and physical database structure is solved, enabling seamless migration of the algorithm across different environments and efficient data processing. This reduces maintenance and delivery costs and improves security and performance.
Patent Information
- Application Number
- CN202611179358.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-05
- Publication Date
- 2026-11-27
AI Technical Summary
Existing technologies cannot achieve complete decoupling of algorithm code and physical database structure, and seamless reuse of a single codebase throughout the entire lifecycle of development, testing, and production, while ensuring high throughput transmission performance for massive amounts of data and enterprise-level security.
The algorithm and data decoupling method based on logical-physical mapping is adopted. By intercepting the logical data read and write requests issued by the algorithm, the mapping relationship of table fields and the connection information of the underlying data source are dynamically obtained and automatically converted into the physical table name and field name of the target physical database, generating physical SQL statements or data read and write instructions, thus achieving complete decoupling between the algorithm and the underlying data structure.
It enables algorithms to operate across different customers and environments without adjusting business logic, significantly improving deployment efficiency, reducing maintenance and delivery costs, ensuring the efficiency and security of massive data processing, and supporting seamless migration from development to production.
Smart Images

Figure CN123178489A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of data processing and software architecture technology, specifically relating to an algorithm and data decoupling method and system based on logical-physical mapping. Background Technology
[0002] In modern enterprise supply chain management, core business scenarios such as demand forecasting, inventory optimization, production scheduling, and logistics dispatching increasingly rely on data-driven intelligent decision-making. Enterprises typically deploy decision analytics platforms, encapsulating operations research and machine learning models as callable algorithm services and embedding them into daily business processes. A typical business scenario is as follows: A retail company needs to forecast the demand for thousands of SKUs across various regions nationwide for the next three months, generating procurement plans and inventory allocation schemes. Business personnel submit a decision task on the platform, which schedules algorithm services to perform calculations, and writes the forecast results back to the business database a few minutes later for direct use by downstream procurement and warehousing systems.
[0003] In industry practice, an algorithm typically goes through three stages from development to delivery to different enterprise clients: First, the development stage, where algorithm engineers develop and debug the algorithm logic locally using sample data; second, the testing stage, where the algorithm is deployed to a test environment and connected to a test database to verify its correctness; and finally, the production stage, where the algorithm is deployed to the client's production environment and connected to the client's real database to execute tasks. In these three stages, the data environments accessed by the algorithm are completely different. For example, local development typically uses CSV or Excel files, the test environment connects to a test database, while the production environment connects to the production databases of each client. More importantly, the database types, table structures, and field naming conventions of different clients often vary, posing a significant data adaptation challenge when deploying algorithm services across environments and delivering them to different clients.
[0004] To address the interaction and adaptation issues between algorithm services and underlying data sources, the mainstream existing technical solutions in the industry mainly include the following three types:
[0005] The first approach is direct hard-coding. In early project deliveries, this approach directly hard-codes database connection information (such as database IP, port, username, and password), physical table names, and specific field names into the data read / write logic of the algorithm source code. While this method is straightforward, it has significant drawbacks: First, for each new client, algorithm engineers need to manually locate all code locations involved in data read / write and modify table and field names one by one, resulting in the need to maintain multiple independent code branches for different clients, leading to extremely low code reuse and high maintenance costs. Second, sensitive information such as database passwords, directly written in the source code or configuration files, cannot pass enterprise-level security audits. Third, during the local development phase, algorithm engineers must build and configure a database that is isomorphic to the client's production environment, which consumes a significant amount of time just for requesting database permissions and configuring the environment, severely reducing development efficiency.
[0006] The second approach is an external configuration solution. This solution extracts database connection information and physical table names from the algorithm source code and stores them in a separate external configuration file. The algorithm code references this connection information and table names at runtime using configuration keys. While this solution addresses some of the hard-coded parameter configuration issues, it still has significant drawbacks: Firstly, it cannot solve the problem of heterogeneous table structures between different clients. The external configuration file typically defines only one fixed mapping relationship, making it difficult to dynamically adapt to the different physical table structures and field mappings of each client. Secondly, as the number of algorithm services and clients grows, maintaining the configuration file becomes a heavy and specialized task. Manual configuration is prone to errors and lacks effective validation mechanisms. Furthermore, the code still needs to maintain complex Object-Relational Mapping (ORM) model definitions for different table structures.
[0007] The third approach is the data API gateway solution. This solution builds a unified data API gateway between the algorithm service and the underlying database. The API gateway is responsible for receiving data requests from the algorithm and shielding the differences in the type and table structure of the underlying database. While this solution is close to the ideal architecture in concept, it suffers from the following serious performance and availability defects in practical applications: First, in scenarios with large data volumes (such as reading and writing millions of rows of historical sales data), transmitting massive amounts of data through the API gateway incurs huge network transmission and serialization overhead, resulting in extremely poor and unacceptable response performance. Second, the algorithm cannot directly call the underlying database's native SQL aggregation, join, window function, and other pushdown computation capabilities. Complex query logic is forced to be split into multiple API calls and processed in the algorithm's memory, resulting in serious waste of computing power. Finally, the system introduces additional gateway middleware dependencies, increasing the system link length, and any failure of the API gateway node will cause the entire algorithm service to become unavailable.
[0008] In summary, existing technical solutions cannot achieve complete decoupling of algorithm code and physical data structure, or seamless code reuse across the entire lifecycle of development, testing, and production, while ensuring high-throughput transmission performance for massive amounts of data and enterprise-level security. Therefore, a method needs to be developed to address these issues. Summary of the Invention
[0009] To address the aforementioned shortcomings, the present invention aims to propose an algorithm and data decoupling method based on logical-physical mapping, thereby solving the technical problem of high coupling between algorithm code and physical database structure in the prior art.
[0010] To achieve this objective, the present invention adopts the following technical solution:
[0011] A method for decoupling algorithms and data based on logical-physical mapping, applied to the algorithm backend of a decision analysis platform, includes the following steps:
[0012] S100, Task reception and parsing: The algorithm server receives the algorithm execution task issued by the decision analysis platform. The algorithm execution task carries the current running mode information and the current tenant identifier.
[0013] S200, Logical Request Interception: When the algorithm server executes the business logic of the algorithm execution task, it intercepts the logical data read / write request issued by the algorithm, wherein the logical data read / write request contains a logical table name and a logical field name.
[0014] S300. Mapping and connection information acquisition: The algorithm server dynamically acquires the corresponding table field mapping relationship and underlying data source connection information based on the current running mode information and the current tenant identifier.
[0015] S400, Logical to Physical Conversion: The algorithm server automatically converts the logical table name and logical field name in the logical data read / write request into the physical table name and physical field name in the target physical database according to the table field mapping relationship, and generates the corresponding physical SQL statement or data read / write instruction.
[0016] S500, Database Connection and Execution Write-back: The algorithm server establishes a connection with the target physical database based on the underlying data source connection information, executes the physical SQL statement or data read / write instruction, and writes the processing result back to the target physical database or returns it to the algorithm.
[0017] Preferably, the operating mode information in S100 includes Local mode, Database mode, and Remote mode:
[0018] When in Local mode, the data source is a local file, and the algorithm server directly reads the logical data from the local file;
[0019] When in Database mode, the data source is a test database, and the algorithm server directly connects to the test database to perform data read and write operations.
[0020] When in Remote mode, the data source is the customer's physical database in the production environment. The algorithm server obtains the physical mapping relationship and encrypted connection information of the customer's physical database through the platform API. The Local mode, Database mode and Remote mode expose a unified data access interface, and the algorithm does not need to modify the data access code in different operating modes.
[0021] Preferably, the S100 step further includes an automatic initialization step for configuring the driver before the algorithm execution task starts:
[0022] Read the algorithm configuration file, which includes a manifest file declaring the algorithm entry module, a field data definition file describing the input table and the output table, and an algorithm business parameter definition file;
[0023] Based on the field data definition file, an in-memory data model corresponding to each data table is automatically generated;
[0024] The system exposes a standardized metadata query interface and automatically registers algorithm entry functions based on the manifest file, so that when an algorithm execution task is received, it can be routed to the corresponding algorithm entry function.
[0025] Preferably, dynamically acquiring the underlying data source connection information in S300 and establishing a connection with the target physical database in S500 specifically include:
[0026] The algorithm server receives a JSON string of database connection information transmitted by the decision analysis platform via AES encryption;
[0027] The algorithm server decrypts the JSON string in memory and establishes a database connection. The decrypted sensitive credentials are stored only in memory variables and are not saved to any local files or system logs.
[0028] Based on the type of the target physical database, the corresponding database driver is automatically loaded and physical SQL statements that conform to the database dialect are generated.
[0029] Furthermore, the algorithm execution task lifecycle from S100 to S500 also includes task status detection and graceful cancellation steps:
[0030] Before or during the execution of the algorithm task, the algorithm server periodically queries the decision analysis platform for the current task status;
[0031] When it is detected that the task being executed by the algorithm has been cancelled by the user, a preset cancellation exception is thrown to interrupt the algorithm's business logic;
[0032] The cancellation exception is captured, and the task cancellation status code is sent back to the decision analysis platform to release computing resources and database connections.
[0033] Furthermore, the algorithm execution task lifecycle from S100 to S500 also includes a task-level end-to-end log tracing step:
[0034] Assign a globally unique task request identifier, request_id, to each algorithm execution task;
[0035] The extended system log module automatically injects the request_id, algorithm task ID, and current tenant identifier into the log context through metaprogramming when outputting logs at each node of the algorithm execution chain.
[0036] Logs with task context are output in structured JSON format and stored hierarchically.
[0037] A logic-physical mapping-based algorithm and data decoupling system, applied to the algorithm backend of a decision analysis platform, includes:
[0038] The task receiving module is used to execute S100, receive the algorithm execution task issued by the decision analysis platform, and parse out the current running mode information and the current tenant identifier;
[0039] The request interception and conversion module is used to execute S200 to S400. During the algorithm execution process, it intercepts logical data read and write requests containing logical table names and logical field names, and converts the logical data read and write requests into physical SQL statements or data read and write instructions containing physical table names and physical field names according to the mapping relationship between the current running mode information and the current tenant identifier.
[0040] The data source connection and execution module is used to execute S500, establish a connection with the target physical database based on the decrypted underlying data source connection information, execute the physical SQL statement or data read / write instruction, and write the result back or return it.
[0041] Furthermore, the request interception and conversion module simultaneously supports reading and writing local files in Local mode, direct reading and writing of test databases in Database mode, and reading and writing of production databases based on platform API mapping relationships in Remote mode, and provides completely consistent API call interfaces to the outside world in all three modes.
[0042] Furthermore, it also includes a configuration driver initialization module, which reads the algorithm's data definition file and automatically generates the corresponding memory object model when the system starts up, while registering the algorithm's routing entry point.
[0043] One of the above technical solutions includes the following beneficial effects: Step S200 intercepts data requests containing only logical names, and steps S300 and S400 automatically complete the logical-to-physical name conversion. Algorithm developers do not need to concern themselves with the underlying physical table names and field specifications. This achieves complete decoupling between the algorithm and the underlying data structure, eliminating the need to modify the code when delivering to different customers; only the mapping relationship needs to be configured, enabling code reuse and reducing maintenance and delivery costs. Attached Figure Description
[0044] Figure 1 This is a schematic diagram of the sorting steps of the present invention;
[0045] Figure 2 This is a schematic diagram of the system structure modules of the present invention. Detailed Implementation
[0046] Embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0047] like Figure 1 As shown, an algorithm and data decoupling method based on logical-physical mapping is applied to the algorithm backend of a decision analysis platform, including the following steps:
[0048] S100, Task reception and parsing: The algorithm server receives the algorithm execution task issued by the decision analysis platform. The algorithm execution task carries the current running mode information and the current tenant identifier.
[0049] S200, Logical Request Interception: When the algorithm server executes the business logic of the algorithm execution task, it intercepts the logical data read / write request issued by the algorithm, wherein the logical data read / write request contains a logical table name and a logical field name.
[0050] S300. Mapping and connection information acquisition: The algorithm server dynamically acquires the corresponding table field mapping relationship and underlying data source connection information based on the current running mode information and the current tenant identifier.
[0051] S400, Logical to Physical Conversion: The algorithm server automatically converts the logical table name and logical field name in the logical data read / write request into the physical table name and physical field name in the target physical database according to the table field mapping relationship, and generates the corresponding physical SQL statement and / or data read / write instruction.
[0052] S500, Database Connection and Execution Write-back: The algorithm server establishes a connection with the target physical database based on the underlying data source connection information, executes the physical SQL statement and / or data read / write instructions, and writes the processing result back to the target physical database or returns it to the algorithm.
[0053] Beneficial effects: By parsing the running mode and tenant identifier in the task in step S100, the algorithm server can dynamically match the corresponding mapping and connection information according to the tenant at runtime. The entire process is completely transparent to the algorithm code, so that the algorithm does not need to adjust the business logic when migrating between different clients and different environments, which greatly improves deployment efficiency;
[0054] Step S200 intercepts data requests containing only logical names, and steps S300 and S400 automatically convert the logical names to physical names. Algorithm developers do not need to worry about the underlying physical table names and field specifications. This achieves complete decoupling between the algorithm and the underlying data structure. When delivering to different customers, no code modification is required; only the mapping relationship needs to be configured, enabling code reuse and reducing maintenance and delivery costs.
[0055] Steps S400 and S500 generate physical SQL statements and execute them directly in the database, bypassing third-party gateways and avoiding latency caused by large-scale data transmission across networks. Simultaneously, they directly utilize the database's native aggregation and relational pushdown computing capabilities, avoiding the waste of computing power caused by data retrieval for local processing and ensuring high efficiency in handling massive amounts of data. Physical SQL statements are generated when the target physical database is a relational database, and data read / write instructions are generated when it is a non-relational database.
[0056] The operating mode information in S100 includes Local mode, Database mode, and Remote mode:
[0057] When in Local mode, the underlying data source is a local file, and the algorithm server directly reads the logical data from the local file.
[0058] When in Database mode, the underlying data source is a test database, and the algorithm server directly connects to the test database to perform data read and write operations.
[0059] When in Remote mode, the underlying data source is the customer's physical database in the production environment. The algorithm server obtains the physical mapping relationship and encrypted connection information of the customer's physical database through the platform API. The Local mode, Database mode and Remote mode expose a unified data access interface, and the algorithm does not need to modify the data access code in different operating modes.
[0060] By encapsulating data access into a unified interface, the algorithm uses completely consistent data read and write code throughout its entire lifecycle, from local development (Local mode) to testing and verification (Database mode) and production deployment (Remote mode). Developers no longer need to repeatedly modify or adapt the data access logic at different stages, achieving seamless migration from development to production and significantly shortening the project delivery cycle.
[0061] During the local development phase (Local mode), the algorithm server can directly read and write logical data in local files without relying on a real database environment, eliminating the need for complex database setup, permission application, and network debugging processes, thus lowering the development and debugging threshold for algorithm engineers.
[0062] During the production operation phase (Remote mode), the algorithm does not need to hardcode production library parameters. Instead, it dynamically obtains physical mapping relationships and encrypted connection information through the platform API, ensuring that sensitive credentials are not stored locally and greatly improving the security of the production system. At the same time, it can flexibly adapt to the heterogeneous production library environments of different customers.
[0063] Specifically, S100 includes an automatic initialization step for configuring the driver before the algorithm execution task starts:
[0064] Read the algorithm configuration file, which includes a manifest file declaring the algorithm entry module, a field data definition file describing the input table and the output table, and an algorithm business parameter definition file;
[0065] Based on the field data definition file, an in-memory data model corresponding to each data table is automatically generated;
[0066] The system exposes a standardized metadata query interface and automatically registers algorithm entry functions based on the manifest file, so that when an algorithm execution task is received, it can be routed to the corresponding algorithm entry function.
[0067] By parsing the data definition file and manifest file, the system can automatically build an in-memory data model and automatically register the algorithm entry function. Algorithm engineers no longer need to manually write cumbersome data structure object classes (ORM model) and route binding code, realizing "configuration as code" for the algorithm infrastructure and significantly improving development efficiency.
[0068] Furthermore, dynamically acquiring the underlying data source connection information in S300 and establishing a connection with the target physical database in S500 specifically include:
[0069] The algorithm server receives a JSON string of database connection information transmitted by the decision analysis platform via AES encryption;
[0070] The algorithm server decrypts the JSON string in memory and establishes a database connection. The decrypted sensitive credentials are stored only in memory variables and are not saved to any local files or system logs.
[0071] Based on the type of the target physical database, the corresponding database driver is automatically loaded and physical SQL statements that conform to the database dialect are generated.
[0072] Database connection information is transmitted using AES encryption, and decrypted sensitive credentials such as database usernames and passwords are stored only in memory variables on the algorithm server and are never written to any local files or system logs. This eliminates the risk of plaintext passwords being written to disk or exposed in logs at the source, greatly improving the data security level of the production environment.
[0073] Furthermore, the algorithm execution task lifecycle from S100 to S500 also includes task status detection and graceful cancellation steps:
[0074] Before or during the execution of the algorithm task, the algorithm server periodically queries the decision analysis platform for the current task status;
[0075] When it is detected that the task being executed by the algorithm has been cancelled by the user, a preset cancellation exception is thrown to interrupt the algorithm's business logic;
[0076] The cancellation exception is captured, and the task cancellation status code is sent back to the decision analysis platform to release computing resources and database connections.
[0077] By periodically polling the task status and throwing a preset exception when a cancellation command is detected, the algorithm can proactively and orderly interrupt business logic during execution, avoiding program crashes, data corruption during writing, or database transaction hanging problems caused by directly forcibly killing the process.
[0078] Furthermore, the algorithm execution task lifecycle from S100 to S500 also includes a task-level end-to-end log tracing step:
[0079] Assign a globally unique task request identifier, request_id, to each algorithm execution task;
[0080] The extended system log module automatically injects the request_id, algorithm task ID, and current tenant identifier into the log context through metaprogramming when outputting logs at each node of the algorithm execution chain.
[0081] Logs with task context are output in structured JSON format and stored hierarchically.
[0082] By assigning a globally unique request_id to each algorithm task and automatically injecting this identifier, along with the algorithm task ID and tenant identifier, logs scattered across different modules and execution stages can be accurately linked together. In the event of anomalies or performance bottlenecks, operations personnel can quickly extract and reconstruct the complete algorithm execution trajectory based on the request_id, eliminating the need for manual comparison and log splicing, significantly improving the efficiency of problem localization.
[0083] like Figure 2 As shown, an algorithm and data decoupling system based on logical-physical mapping is applied to the algorithm backend of a decision analysis platform, including:
[0084] The task receiving module is used to execute S100, receive the algorithm execution task issued by the decision analysis platform, and parse out the current running mode information and the current tenant identifier;
[0085] The request interception and conversion module is used to execute S200 to S400. During the algorithm execution process, it intercepts logical data read and write requests containing logical table names and logical field names, and converts the logical data read and write requests into physical SQL statements or data read and write instructions containing physical table names and physical field names according to the mapping relationship between the current running mode information and the current tenant identifier.
[0086] The data source connection and execution module is used to execute S500, establish a connection with the target physical database based on the underlying data source connection information, execute the physical SQL statement or data read / write instruction, and write back or return the result.
[0087] The system employs a task receiving module for task scheduling and parsing, a request interception and conversion module for logical-to-physical mapping, and an underlying data source connection and execution module for underlying data interaction, achieving clear functional decoupling. Each module is highly cohesive and loosely coupled, allowing for independent optimization of mapping algorithms, expansion to new database types, or upgrades to the task scheduling protocol within their respective modules without altering the overall system architecture. This results in exceptional scalability and maintainability.
[0088] The request interception and conversion module supports reading and writing local files in Local mode, direct reading and writing of test databases in Database mode, and reading and writing of production databases based on platform API mapping in Remote mode. All three modes provide a unified API call interface.
[0089] The request interception and conversion module exposes a completely consistent calling interface, shielding the underlying interaction differences between local files, test databases, and production databases. The algorithm doesn't need to be concerned with its current runtime environment or introduce multiple data access components, achieving seamless switching between development, testing, and production environments, significantly reducing the development and maintenance costs of the algorithm's backend.
[0090] It also includes a configuration driver initialization module, which reads the algorithm's data definition file and automatically generates the corresponding memory object model when the system starts up, while registering the algorithm's routing entry point.
[0091] The configuration-driven initialization module reads the data definition file during system startup and automatically generates the in-memory object model and registers the algorithm entry route. Algorithm engineers no longer need to manually write data mapping classes and route configuration code, achieving "configuration as code" for the infrastructure, effectively reducing redundant code and improving system development and deployment efficiency.
[0092] Taking Remote mode as an example, a complete algorithm execution process is as follows:
[0093] 1. Overall workflow;
[0094] (1) Task assignment: The service periodically queries the platform to see if there are any algorithm tasks to be executed.
[0095] (2) Parameter parsing: After obtaining the task, the algorithm method name and business parameters (such as the predicted SKU range, time granularity, etc.) are parsed out.
[0096] (3) Algorithm execution: The corresponding algorithm function is called. The algorithm reads and writes data through a unified read_df / write_df / read_sql interface.
[0097] (4) Automatic conversion: Each time data is accessed, the engine automatically completes the conversion of logical SQL to physical SQL, table mapping query, and database connection acquisition, which is completely transparent to the algorithm code;
[0098] (5) Write back the results: The calculation results are automatically written back to the customer's physical database according to the mapping rules;
[0099] (6) Status callback: Report the result to the platform after execution (success or failure);
[0100] 2. Three operating modes – covering the entire lifecycle;
[0101] The solution provides three operating modes, each corresponding to a different stage from algorithm development to delivery:
[0102]
[0103] All three modes expose the exact same programming interface, so the algorithm code does not need to know which mode it is in.
[0104] The value of Local mode: When developing locally, algorithm engineers only need to prepare a few CSV or Excel test data sets, and after starting the service, they can run and debug the algorithm directly locally. No need to apply for database permissions, no need to wait for the platform to issue tasks, no need for network connectivity—setting up the development environment is reduced from "half a day" to "one minute."
[0105] The value of Remote mode: The platform automatically schedules the execution of algorithms, each task automatically obtains the corresponding customer's data mapping relationship, acquires database connection information through an encrypted channel, and automatically sends back the result upon completion. The entire process requires no manual intervention.
[0106] 3. Logical-physical mapping – the key to achieving “develop once, reuse for multiple clients”;
[0107] This is the most important design of this solution. The platform maintains a mapping table that records the correspondence between the logical name and the physical name under each algorithm solution and each customer.
[0108] Example: The demand forecasting algorithm needs to read the "historical sales" table, using three fields: "product code", "time stamp", and "sales volume".
[0109] In Client A's environment:
[0110] Physical table name: `t_sales_2024`;
[0111] Product code → `product_code`;
[0112] Timestamp → `ds_date`;
[0113] Sales volume → `sale_qty`;
[0114] In Client B's environment:
[0115] Physical table name: `ods_sales_daily`;
[0116] Product code → `item_id`;
[0117] Timestamp → `data_date`;
[0118] Sales volume → quantity;
[0119] The algorithm code is always written with logical names (sales_data, ITEM_CODE, DS, VOLUME). At runtime, the engine automatically queries the mapping relationship and completes the conversion, so that two customers use the exact same algorithm code.
[0120] This mapping mechanism also solves the compatibility problem of multiple database types—regardless of whether the customer is using MySQL, StarRocks, or PostgreSQL, the engine automatically generates the corresponding database connection method and SQL dialect.
[0121] 4. Configure the driver to enable standardized algorithm integration;
[0122] To add a new algorithm to the platform, only three configuration files are needed:
[0123] 1. manifest.yaml: Declare the algorithm's method name and entry module path;
[0124] 2. algo_data_define.csv: A table describing the input and output tables of the algorithm—what are the table names, what fields are there, what are the data types of the fields, and which is the primary key;
[0125] 3. algo_param_define.md: Definition of business parameters received by the algorithm (such as prediction time range, DPU dimension, etc.);
[0126] The engine automatically reads these configurations upon startup and completes the following initialization tasks (without any manual coding):
[0127] Automatically generate object models for all data tables based on CSV;
[0128] The system exposes a standardized metadata query interface, which the front-end can use to automatically generate parameter configuration pages.
[0129] Based on the YAML registration algorithm entry point, the platform automatically routes tasks to the correct algorithm function.
[0130] 5. Task lifecycle management;
[0131] The engine has built-in complete task management capabilities, covering the entire process from receiving a task to its completion:
[0132] Task polling: Retrieve tasks to be executed from the platform at configurable time intervals;
[0133] Status detection: Periodically check whether the task has been canceled by the user during algorithm execution, and support graceful termination;
[0134] Exception handling: When an exception occurs during algorithm execution, a detailed error stack is automatically captured, the platform is called back, and a complete log is recorded;
[0135] Result callback: Regardless of success (status code 200), failure (201), or cancellation (202), the final status is reported to the platform;
[0136] Log feedback: Key logs during the execution process are fed back to the platform in real time, making it convenient to view them uniformly on the platform.
[0137] 6. Data security protection;
[0138] In SaaS platforms targeting enterprise customers, data security is the top priority. This solution is specifically designed with the following aspects in mind:
[0139] Encrypted transmission: When the platform sends database connection information, the entire connection information JSON is encrypted with AES and transmitted using Base64 encoding.
[0140] Memory decryption usage: After receiving the password, the algorithm side decrypts it and uses it. The decrypted password only exists in the memory variable and is not written to any file.
[0141] Log anonymization: Structured log output does not contain sensitive information such as database connection strings;
[0142] Tenant isolation: Each task carries a tenant identifier when executed, ensuring complete isolation of data access between different customers;
[0143] 7. Observability design;
[0144] To enable the operations and maintenance team to quickly locate problems, the system has implemented the following observability capabilities:
[0145] End-to-end tracing: Each log entry carries a `request_id` (task request ID), and all logs from receiving the task to its completion can be linked together using this ID;
[0146] Tiered storage: Logs are written to separate files according to five levels: DEBUG / INFO / WARN / ERROR / CRITICAL. You can quickly locate the anomaly by checking the error log.
[0147] Structured format: Logs are output in JSON format, which can be directly collected and parsed by centralized logging platforms such as ELK and Splunk;
[0148] Automatic archiving: Logs are rolled over by day, and the most recent 14 days are automatically retained;
[0149] In terms of technical implementation: The system extends the standard Python logging library with a custom Logger, which automatically injects the current task context (task ID, request ID, tenant ID) into the log output through metaprogramming, without requiring explicit passing of it in the business code.
[0150] The technical principles of the present invention have been described above with reference to specific embodiments. These descriptions are merely for explaining the principles of the invention and should not be construed as limiting the scope of protection of the invention in any way. Based on this explanation, those skilled in the art can readily conceive of other specific embodiments of the invention without inventive effort, and these embodiments will all fall within the scope of protection of the present invention.
Claims
1. A method for decoupling algorithms and data based on logical-physical mapping, applied to the algorithm backend of a decision analysis platform, characterized in that, Includes the following steps: S100, Task reception and parsing: The algorithm server receives the algorithm execution task issued by the decision analysis platform. The algorithm execution task carries the current running mode information and the current tenant identifier. S200, Logical Request Interception: When the algorithm server executes the business logic of the algorithm execution task, it intercepts the logical data read / write request issued by the algorithm, wherein the logical data read / write request contains a logical table name and a logical field name. S300. Mapping and connection information acquisition: The algorithm server dynamically acquires the corresponding table field mapping relationship and underlying data source connection information based on the current running mode information and the current tenant identifier. S400, Logical to Physical Conversion: The algorithm server automatically converts the logical table name and logical field name in the logical data read / write request into the physical table name and physical field name in the target physical database according to the table field mapping relationship, and generates the corresponding physical SQL statement and / or data read / write instruction. S500, Database Connection and Execution Write-back: The algorithm server establishes a connection with the target physical database based on the underlying data source connection information, executes the physical SQL statement and / or data read / write instructions, and writes the processing result back to the target physical database or returns it to the algorithm.
2. The method according to claim 1, characterized in that, The operating mode information in S100 includes Local mode, Database mode, and Remote mode: When in Local mode, the underlying data source is a local file, and the algorithm server directly reads the logical data from the local file. When in Database mode, the underlying data source is a test database, and the algorithm server directly connects to the test database to perform data read and write operations. When in Remote mode, the underlying data source is the customer's physical database in the production environment. The algorithm server obtains the physical mapping relationship and encrypted connection information of the customer's physical database through the platform API. The Local mode, Database mode and Remote mode expose a unified data access interface, and the algorithm does not need to modify the data access code in different operating modes.
3. The method according to claim 1, characterized in that, Before the algorithm execution task starts in S100, an automatic initialization step for configuring the driver is also included: Read the algorithm configuration file, which includes a manifest file declaring the algorithm entry module, a field data definition file describing the input table and the output table, and an algorithm business parameter definition file; Based on the field data definition file, an in-memory data model corresponding to each data table is automatically generated; The system exposes a standardized metadata query interface and automatically registers algorithm entry functions based on the manifest file, so that when an algorithm execution task is received, it can be routed to the corresponding algorithm entry function.
4. The method according to claim 1, characterized in that, The dynamic acquisition of underlying data source connection information in S300 and the establishment of a connection with the target physical database in S500 specifically include: The algorithm server receives a JSON string of database connection information transmitted by the decision analysis platform via AES encryption; The algorithm server decrypts the JSON string in memory and establishes a database connection. The decrypted sensitive credentials are stored only in memory variables and are not saved to any local files or system logs. Based on the type of the target physical database, the corresponding database driver is automatically loaded and physical SQL statements that conform to the database dialect are generated.
5. The method according to claim 1, characterized in that, The algorithm execution task lifecycle from S100 to S500 also includes task status detection and graceful cancellation steps: Before or during the execution of the algorithm task, the algorithm server periodically queries the decision analysis platform for the current task status; When it is detected that the task being executed by the algorithm has been cancelled by the user, a preset cancellation exception is thrown to interrupt the algorithm's business logic; The cancellation exception is captured, and the task cancellation status code is sent back to the decision analysis platform to release computing resources and database connections.
6. The method according to claim 1, characterized in that, The algorithm execution task lifecycle from S100 to S500 also includes a task-level end-to-end log tracing step: Assign a globally unique task request identifier, request_id, to each algorithm execution task; The extended system log module automatically injects the request_id, algorithm task ID, and current tenant identifier into the log context through metaprogramming when outputting logs at each node of the algorithm execution chain. Logs with task context are output in structured JSON format and stored hierarchically.
7. A system for decoupling algorithms and data based on logical-physical mapping, applied to the algorithm backend of a decision analysis platform, characterized in that, include: The task receiving module is used to execute S100, receive the algorithm execution task issued by the decision analysis platform, and parse out the current running mode information and the current tenant identifier; The request interception and conversion module is used to execute S200 to S400. During the algorithm execution process, it intercepts logical data read and write requests containing logical table names and logical field names, and converts the logical data read and write requests into physical SQL statements or data read and write instructions containing physical table names and physical field names according to the mapping relationship between the current running mode information and the current tenant identifier. The data source connection and execution module is used to execute S500, establish a connection with the target physical database based on the underlying data source connection information, execute the physical SQL statement or data read / write instruction, and write back or return the result.
8. The system according to claim 7, characterized in that, The request interception and conversion module simultaneously supports reading and writing local files in Local mode, direct reading and writing to the test database in Database mode, and reading and writing to the production database based on the platform API mapping relationship in Remote mode. All three modes provide a unified API call interface.
9. The system according to claim 7, characterized in that, It also includes a configuration driver initialization module, which reads the algorithm's data definition file and automatically generates the corresponding memory object model when the system starts up, while registering the algorithm's routing entry point.
