Python-based data query method, device, equipment and storage medium

CN114138761BActive Publication Date: 2025-09-16CHINA PING AN PROPERTY INSURANCE CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202111431187.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-29
Publication Date
2025-09-16
Estimated Expiration
2041-11-29

AI Technical Summary

Technical Problem

[0003]本发明提供一种基于python的数据查询方法、装置、设备及存储介质,其主要目的在于解决利用python进行数据查询时查询效率较低的问题

Benefits of technology

[0041] The present invention uses a Python mapping program to configure a database for the original data set to obtain an in-memory database. Compared with traditional relational databases or file-based databases, the in-memory database has a significantly improved reading speed for the same data, reducing the response time of data queries, thereby increasing the query speed. At the same time, through data cleaning and data classification, the amount of data is further reduced, data segmentation is achieved, and the data query speed can also be increased. In addition, by using Python process tools to build processes instead of threads, multi-process processing can bypass the GIL and achieve program parallelism, thereby improving the efficiency of data queries. Therefore, the Python-based data query method, device, electronic device and computer-readable storage medium proposed in the present invention can solve the problem of low query efficiency when using Python to perform data queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114138761B_ABST
    Figure CN114138761B_ABST
Patent Text Reader

Abstract

The present invention relates to artificial intelligence technology and discloses a Python-based data query method, comprising: using a Python mapping program to configure a raw data set and a preset database to obtain an in-memory database; performing data cleaning and data classification on the raw data set to obtain a database table; constructing a query main process based on data query instructions; setting a timed update subprocess based on a preset Python process tool; using the timed update subprocess to update the database table; and querying the updated database table based on the query main process to obtain a data query result. Furthermore, the present invention relates to blockchain technology, and the data query result can be stored in a blockchain node. The present invention also provides a Python-based data query method device, electronic device, and computer-readable storage medium. The present invention can solve the problem of low query efficiency when using Python for data querying.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a Python-based data query method, device, electronic device, and computer-readable storage medium. Background Art

[0002] Python is a clear, simple programming language with a rich and practical third-party library. It is increasingly popular among programmers and has become the most widely used language among developers. However, due to its interpretive nature, it suffers from low efficiency and slow speed. This makes Python inefficient for scenarios involving large amounts of data or complex computations. For example, when querying data, due to the Global Interpreter Lock (GIL), a Python interpreter process has a main thread and multiple user program execution threads. However, even on multi-core CPU platforms, Python prohibits parallel execution of multiple threads, and instead uses coroutines. Python's inherent support for multi-CPU devices is limited, resulting in slow and inefficient data queries. Summary of the Invention

[0003] The present invention provides a Python-based data query method, device, equipment and storage medium, the main purpose of which is to solve the problem of low query efficiency when using Python to perform data query.

[0004] To achieve the above object, the present invention provides a data query method based on Python, comprising:

[0005] Obtaining an original data set, and performing database configuration on the original data set and a preset database using a preset Python mapping program to obtain an in-memory database;

[0006] Performing data cleaning and data classification on the original data set in the in-memory database to obtain a database table;

[0007] Receive data query instructions, build a query main process based on the data query instructions, and set a timed update sub-process based on a preset Python process tool;

[0008] The database table is updated with data using the timed update sub-process, and the updated database table is queried based on the query main process to obtain a data query result.

[0009] Optionally, the acquiring of the original data set and the use of a preset Python mapping program to perform database configuration on the original data set and a preset database to obtain an in-memory database includes:

[0010] Obtaining original data from multiple original databases to obtain an original data set;

[0011] Using the Python mapping program to establish a mapping relationship between the original data in the original data set and the original database corresponding to the original data, summarizing the mapping relationships of all original databases to obtain a database configuration file;

[0012] Perform access configuration according to the preset database to obtain an access configuration file;

[0013] The database configuration file and the access configuration file are added to the preset database to obtain the in-memory database.

[0014] Optionally, the data cleaning and data classification of the original data set to obtain a database table includes:

[0015] Deduplication, anomaly removal, and missing value filling are performed on the data in the original data set to obtain a standard data set;

[0016] The standard data set is processed into a database and table to obtain the database table.

[0017] Optionally, performing data deduplication, data anomaly removal, and data missing value filling on the data in the original data set to obtain a standard data set includes:

[0018] Calculating the distance value of the data in the original data set using a distance formula, and deduplicating the data in the original data set according to the distance value to obtain a deduplicated data set;

[0019] Using a unilateral test formula to remove outliers from the deduplication data set to obtain an outlier-free data set;

[0020] A preset missing value detection function is used to perform missing value detection on the data in the abnormal data set, and the missing values ​​are filled based on a preset filling algorithm to obtain the standard data set.

[0021] Optionally, the setting of the timed update subprocess based on a preset Python process tool includes:

[0022] Obtaining a scheduled execution event, and encapsulating the scheduled execution event into an execution function;

[0023] The python process tool is used to create a subprocess, and the execution function is encapsulated into the subprocess to obtain the timed update subprocess.

[0024] Optionally, the updating of data in the database table by using the timed update sub-process includes:

[0025] Utilize the python process tool to build a data initialization process;

[0026] Executing the timed execution event in the timed update sub-process to obtain a new set of original data;

[0027] The data initialization process is used to perform data initialization processing on the new original data set, and the processed data is filled into the database table.

[0028] Optionally, querying the updated database table based on the query main process includes:

[0029] Generate an access file according to the query main process;

[0030] Parsing the query field of the data query instruction in the query main process;

[0031] The access file is used as a query entry, and the query field is used to search for an updated database table from the query entry.

[0032] In order to solve the above problems, the present invention also provides a data query device based on Python, which includes:

[0033] A database configuration module is used to obtain an original data set and configure the original data set and a preset database using a preset Python mapping program to obtain an in-memory database;

[0034] A data processing module, configured to perform data cleaning and data classification on the original data set in the memory database to obtain a database table;

[0035] A process building module is used to receive data query instructions, build a query main process based on the data query instructions, and set a timed update sub-process based on a preset Python process tool;

[0036] The data query module is used to update the data in the database table using the timed update sub-process, and query the updated database table based on the query main process to obtain the data query result.

[0037] In order to solve the above problem, the present invention further provides an electronic device, comprising:

[0038] a memory storing at least one computer program; and

[0039] The processor executes the computer program stored in the memory to implement the above-mentioned Python-based data query method.

[0040] In order to solve the above problems, the present invention also provides a computer-readable storage medium, in which at least one computer program is stored. The at least one computer program is executed by a processor in an electronic device to implement the above-mentioned Python-based data query method.

[0041] The present invention uses a Python mapping program to configure a database for the original data set to obtain an in-memory database. Compared with traditional relational databases or file-based databases, the in-memory database has a significantly improved reading speed for the same data, reducing the response time of data queries, thereby increasing the query speed. At the same time, through data cleaning and data classification, the amount of data is further reduced, data segmentation is achieved, and the data query speed can also be increased. In addition, by using Python process tools to build processes instead of threads, multi-process processing can bypass the GIL and achieve program parallelism, thereby improving the efficiency of data queries. Therefore, the Python-based data query method, device, electronic device and computer-readable storage medium proposed in the present invention can solve the problem of low query efficiency when using Python to perform data queries. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A flowchart of a Python-based data query method provided by one embodiment of the present invention;

[0043] Figure 2 A functional module diagram of a Python-based data query device provided by one embodiment of the present invention;

[0044] Figure 3 A schematic structural diagram of an electronic device for implementing the Python-based data query method provided by one embodiment of the present invention.

[0045] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION

[0046] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0047] The embodiment of the present application provides a data query method based on Python. The execution subject of the data query method based on Python includes but is not limited to at least one of the electronic devices such as a server, a terminal, etc. that can be configured to execute the method provided by the embodiment of the present application. In other words, the data query method based on Python can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc. The server can be an independent server, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.

[0048] Reference Figure 1 FIG. 1 is a flow chart of a Python-based data query method according to an embodiment of the present invention. In this embodiment, the Python-based data query method includes:

[0049] S1. Obtain an original data set, and use a preset Python mapping program to perform database configuration on the original data set and a preset database to obtain an in-memory database.

[0050] In an embodiment of the present invention, the raw data set may include product and user information from different fields. For example, in the financial field, the raw data set may include user stock information, fund information, and trust information. The preset Python mapping program may be an ORM (Object Relational Mapping) program in Python. The preset database may be an sqlite3 in-memory database. Compared to traditional relational databases or file-based databases, in-memory databases have significantly improved data read speed, thereby improving data query response time and thereby increasing query speed.

[0051] Specifically, the original data set is obtained, and a preset Python mapping program is used to configure the original data set and a preset database to obtain an in-memory database, including:

[0052] Obtaining original data from multiple original databases to obtain an original data set;

[0053] Using the Python mapping program to establish a mapping relationship between the original data in the original data set and the original database corresponding to the original data, summarizing the mapping relationships of all original databases to obtain a database configuration file;

[0054] Perform access configuration according to the preset database to obtain an access configuration file;

[0055] The database configuration file and the access configuration file are added to the preset database to obtain the in-memory database.

[0056] In an optional embodiment of the present invention, the original database may be a relational database such as Oracle, SQL Server, DB2, or MySQL. Furthermore, by using Python's Object Relational Mapping (ORM), different original databases and data can be mapped to facilitate management and switching. For example, SQLAlchemy can be used through the ORM to uniformly configure the original databases, facilitating management and switching.

[0057] In an optional embodiment of the present invention, the access configuration may include: 1. client link access; 2. program API interface access; 3. http access.

[0058] In the embodiment of the present invention, by using the ORM in Python to configure the database of the original data set, a memory database with a faster response speed can be used to perform data query, thereby improving the speed of data query.

[0059] S2. Perform data cleaning and data classification on the original data set in the memory database to obtain a database table.

[0060] In the embodiment of the present invention, since the original data set comes from multiple databases, the large amount of data will cause query confusion. By refining the data through data cleaning and data classification, the response speed of data query can be improved.

[0061] Specifically, the raw data set is cleaned and classified to obtain a database table, including:

[0062] Deduplication, anomaly removal, and missing value filling are performed on the data in the original data set to obtain a standard data set;

[0063] The standard data set is processed into a database and table to obtain the database table.

[0064] In an embodiment of the present invention, the step of performing data deduplication, data anomaly removal, and data missing value filling on the data in the original data set to obtain a standard data set includes:

[0065] Calculating the distance value of the data in the original data set using a distance formula, and deduplicating the data in the original data set according to the distance value to obtain a deduplicated data set;

[0066] Using a unilateral test formula to remove outliers from the deduplication data set to obtain an outlier-free data set;

[0067] A preset missing value detection function is used to perform missing value detection on the data in the abnormal data set, and the missing values ​​are filled based on a preset filling algorithm to obtain the standard data set.

[0068] In an optional embodiment of the present invention, the distance formula may be:

[0069]

[0070] Among them, d represents the distance value between any two data in the original data set, w 1j and w 2j Represents any two data in the original data set. When the distance value is less than a preset distance value, either data is deleted. If the distance value is not less than the preset distance value, both data are retained. Preferably, the preset distance value can be 0.1.

[0071] In an optional embodiment of the present invention, the single-side test elimination includes minimum value single-side test elimination and maximum value single-side test elimination.

[0072] The calculation method of the minimum value unilateral test elimination includes:

[0073]

[0074] Wherein, G represents the test value, S represents the standard deviation of the data in the original data set after deduplication, represents the average value of the data in the original data set after deduplication, Y min The smallest data in the original data set after deduplication is determined. When G is greater than a preset test threshold, the smallest data is determined to be abnormal data.

[0075] The calculation method of the maximum value unilateral test elimination includes:

[0076]

[0077] Wherein, G represents the test value, S represents the standard deviation of the data in the original data set after deduplication, represents the average value of the data in the original data set after deduplication, Y maxWhen G is greater than a preset test threshold, the largest data is determined to be abnormal data.

[0078] In an optional embodiment of the present invention, the missing value detection function may be a missmap function. If no missing data value is detected, no processing is performed. If missing data value is detected, the embodiment of the present invention fills the missing value using a preset filling algorithm. The preset filling algorithm includes:

[0079]

[0080] Among them, L(θ) represents the missing value of the filled data, x i represents the i-th missing value, θ represents the probability parameter corresponding to the missing value of the filled data, n represents the number of data in the outlier data set, p(x i |θ) represents the probability of filling missing values ​​in the data.

[0081] In the embodiment of the present invention, the step of performing database and table partitioning on the standard data set to obtain the database table includes:

[0082] Dividing the in-memory database into a preset number of data sub-databases, wherein the data sub-databases include pre-built intermediate tables;

[0083] Classify the standard data set according to a preset data classification rule to obtain a classified data set;

[0084] The classified data set is filled into the intermediate table to obtain the database table.

[0085] In an optional embodiment of the present invention, an equal number of data sub-databases can be constructed based on the number of original databases. The data can then be categorized and partitioned, populated into intermediate tables within the sub-databases, resulting in database tables. For example, consider two original databases: Database 1 and Database 2. Database 1 contains stock information, while Database 2 contains fund information. The databases can then be divided into two sub-databases, and the data can be partitioned into sectors such as new energy, liquor, and healthcare, populated into pre-set blank intermediate tables, resulting in database tables.

[0086] S3. Receive a data query instruction, build a query main process based on the data query instruction, and set a timed update sub-process based on a preset Python process tool.

[0087] In the embodiment of the present invention, the data query instruction refers to a data query request sent by a user, including: a user information query request, a business information query request, a financial information query request, etc. The preset python process tool can be a multiprocessing tool in python.

[0088] In detail, the setting of the timed update sub-process based on the preset Python process tool includes:

[0089] Obtaining a scheduled execution event, and encapsulating the scheduled execution event into an execution function;

[0090] The python process tool is used to create a subprocess, and the execution function is encapsulated into the subprocess to obtain the timed update subprocess.

[0091] In an optional embodiment of the present invention, before obtaining the scheduled execution event, the method further includes:

[0092] The preset execution time and execution frequency are obtained, and the execution time and the execution frequency are encapsulated using a preset timing tool to obtain the scheduled execution event.

[0093] In an embodiment of the present invention, the apscheduler tool can be used to create scheduled execution tasks (including execution time and execution frequency). At the same time, by using the multiprocessing tool to create processes instead of threads for data processing, the purpose of program parallelism can be achieved by bypassing the GIL, thereby improving data parallel processing capabilities.

[0094] S4. Utilize the timed update sub-process to update the data in the database table, and query the updated database table based on the query main process to obtain a data query result.

[0095] In detail, the updating of data in the database table by using the timed update sub-process includes:

[0096] Utilize the python process tool to build a data initialization process;

[0097] Executing the timed execution event in the timed update sub-process to obtain a new set of original data;

[0098] The data initialization process is used to perform data initialization processing on the new original data set, and the processed data is filled into the database table.

[0099] In an optional embodiment of the present invention, since the multiprocessing tool is used to create processes instead of threads to update data, multi-process processing can bypass the GIL to achieve the purpose of program parallelism.

[0100] In an embodiment of the present invention, querying the updated database table based on the query main process includes:

[0101] Generate an access file according to the query main process;

[0102] Parsing the query field of the data query instruction in the query main process;

[0103] The access file is used as a query entry, and the query field is used to search for an updated database table from the query entry.

[0104] In the embodiments of the present invention, because in-memory databases use separate memory to store data, different processes do not share the same memory. Therefore, access must be performed using files. When the main query process starts, an access file is generated. Unlike other files, this file effectively creates an entry point in memory, allowing queries to be performed through this entry point. For example, in the financial field, a user enters a financial data query command, and the query fields in the financial data query command are parsed to obtain the financial data query results.

[0105] In another optional embodiment of the present invention, before parsing the query field of the data query instruction in the query main process, the method further includes:

[0106] Check whether a memory file exists in the memory database;

[0107] If the memory file does not exist in the memory database, no processing is performed;

[0108] If a memory file exists in the memory database, the memory file is deleted.

[0109] In an embodiment of the present invention, when a memory database using files as media is established, a file of size 0 will be generated in the main directory, occupying a certain amount of disk sectors. Therefore, when the query main process is started, it should be checked whether this file exists. If so, this file should be deleted. Otherwise, the disk sectors occupied will continue to increase each time the query main process is started, affecting the data query speed.

[0110] The present invention uses a Python mapping program to configure a database for the original data set to obtain an in-memory database. Compared with traditional relational databases or file-based databases, the in-memory database has a significantly improved reading speed for the same data, reducing the response time of data queries and thus increasing the query speed. At the same time, through data cleaning and data classification, the data volume is further reduced, data segmentation is achieved, and the data query speed can also be increased. In addition, by using Python process tools to build processes instead of threads, multi-process processing can bypass the GIL and achieve program parallelism, thereby improving the efficiency of data queries. Therefore, the Python-based data query method proposed in the present invention can solve the problem of low query efficiency when using Python to perform data queries.

[0111] like Figure 2 , which is a functional module diagram of a Python-based data query device provided by one embodiment of the present invention.

[0112] The Python-based data query device 100 of the present invention can be installed in an electronic device. Depending on the functions to be implemented, the Python-based data query device 100 can include a database configuration module 101, a data processing module 102, a process construction module 103, and a data query module 104. The modules of the present invention, also known as units, refer to a series of computer program segments that can be executed by an electronic device processor and can perform a fixed function, which are stored in the memory of the electronic device.

[0113] In this embodiment, the functions of each module / unit are as follows:

[0114] The database configuration module 101 is used to obtain an original data set, and use a preset Python mapping program to perform database configuration on the original data set and a preset database to obtain an in-memory database;

[0115] The data processing module 102 is used to perform data cleaning and data classification on the original data set in the in-memory database to obtain a database table;

[0116] The process construction module 103 is used to receive a data query instruction, construct a query main process based on the data query instruction, and set a timed update sub-process based on a preset Python process tool;

[0117] The data query module 104 is configured to update the database table using the timed update sub-process, and query the updated database table based on the query main process to obtain a data query result.

[0118] In detail, the specific implementation of each module of the Python-based data query device 100 is as follows:

[0119] Step 1: Obtain an original data set, and use a preset Python mapping program to perform database configuration on the original data set and a preset database to obtain an in-memory database.

[0120] In an embodiment of the present invention, the raw data set may include product and user information from different fields. For example, in the financial field, the raw data set may include user stock information, fund information, and trust information. The preset Python mapping program may be an ORM (Object Relational Mapping) program in Python. The preset database may be an sqlite3 in-memory database. Compared to traditional relational databases or file-based databases, in-memory databases have significantly improved data read speed, thereby improving data query response time and thereby increasing query speed.

[0121] Specifically, the original data set is obtained, and a preset Python mapping program is used to configure the original data set and a preset database to obtain an in-memory database, including:

[0122] Obtaining original data from multiple original databases to obtain an original data set;

[0123] Using the Python mapping program to establish a mapping relationship between the original data in the original data set and the original database corresponding to the original data, summarizing the mapping relationships of all original databases to obtain a database configuration file;

[0124] Perform access configuration according to the preset database to obtain an access configuration file;

[0125] The database configuration file and the access configuration file are added to the preset database to obtain the in-memory database.

[0126] In an optional embodiment of the present invention, the original database may be a relational database such as Oracle, SQL Server, DB2, or MySQL. Furthermore, by using Python's Object Relational Mapping (ORM), different original databases and data can be mapped to facilitate management and switching. For example, SQLAlchemy can be used through the ORM to uniformly configure the original databases, facilitating management and switching.

[0127] In an optional embodiment of the present invention, the access configuration may include: 1. client link access; 2. program API interface access; 3. http access.

[0128] In the embodiment of the present invention, by using the ORM in Python to configure the database of the original data set, a memory database with a faster response speed can be used to perform data query, thereby improving the speed of data query.

[0129] Step 2: Clean and classify the original data set in the memory database to obtain a database table.

[0130] In the embodiment of the present invention, since the original data set comes from multiple databases, the large amount of data will cause query confusion. By refining the data through data cleaning and data classification, the response speed of data query can be improved.

[0131] Specifically, the raw data set is cleaned and classified to obtain a database table, including:

[0132] Deduplication, anomaly removal, and missing value filling are performed on the data in the original data set to obtain a standard data set;

[0133] The standard data set is processed into a database and table to obtain the database table.

[0134] In an embodiment of the present invention, the step of performing data deduplication, data anomaly removal, and data missing value filling on the data in the original data set to obtain a standard data set includes:

[0135] Calculating the distance value of the data in the original data set using a distance formula, and deduplicating the data in the original data set according to the distance value to obtain a deduplicated data set;

[0136] Using a unilateral test formula to remove outliers from the deduplication data set to obtain an outlier-free data set;

[0137] A preset missing value detection function is used to perform missing value detection on the data in the abnormal data set, and the missing values ​​are filled based on a preset filling algorithm to obtain the standard data set.

[0138] In an optional embodiment of the present invention, the distance formula may be:

[0139]

[0140] Among them, d represents the distance value between any two data in the original data set, w 1j and w 2jRepresents any two data in the original data set. When the distance value is less than a preset distance value, either data is deleted. If the distance value is not less than the preset distance value, both data are retained. Preferably, the preset distance value can be 0.1.

[0141] In an optional embodiment of the present invention, the single-side test elimination includes minimum value single-side test elimination and maximum value single-side test elimination.

[0142] The calculation method of the minimum value unilateral test elimination includes:

[0143]

[0144] Wherein, G represents the test value, S represents the standard deviation of the data in the original data set after deduplication, represents the average value of the data in the original data set after deduplication, Y min The smallest data in the original data set after deduplication is determined. When G is greater than a preset test threshold, the smallest data is determined to be abnormal data.

[0145] The calculation method of the maximum value unilateral test elimination includes:

[0146]

[0147] Wherein, G represents the test value, S represents the standard deviation of the data in the original data set after deduplication, represents the average value of the data in the original data set after deduplication, Y max When G is greater than a preset test threshold, the largest data is determined to be abnormal data.

[0148] In an optional embodiment of the present invention, the missing value detection function may be a missmap function. If no missing data value is detected, no processing is performed. If missing data value is detected, the embodiment of the present invention fills the missing value using a preset filling algorithm. The preset filling algorithm includes:

[0149]

[0150] Among them, L(θ) represents the missing value of the filled data, x i represents the i-th missing value, θ represents the probability parameter corresponding to the missing value of the filled data, n represents the number of data in the outlier data set, p(x i |θ) represents the probability of filling missing values ​​in the data.

[0151] In the embodiment of the present invention, the step of performing database and table partitioning on the standard data set to obtain the database table includes:

[0152] Dividing the in-memory database into a preset number of data sub-databases, wherein the data sub-databases include pre-built intermediate tables;

[0153] Classify the standard data set according to a preset data classification rule to obtain a classified data set;

[0154] The classified data set is filled into the intermediate table to obtain the database table.

[0155] In an optional embodiment of the present invention, an equal number of data sub-databases can be constructed based on the number of original databases. The data can then be categorized and partitioned, populated into intermediate tables within the sub-databases, resulting in database tables. For example, consider two original databases: Database 1 and Database 2. Database 1 contains stock information, while Database 2 contains fund information. The databases can then be divided into two sub-databases, and the data can be partitioned into sectors such as new energy, liquor, and healthcare, populated into pre-set blank intermediate tables, resulting in database tables.

[0156] Step 3: Receive a data query instruction, build a query main process based on the data query instruction, and set a timed update sub-process based on a preset Python process tool.

[0157] In the embodiment of the present invention, the data query instruction refers to a data query request sent by a user, including: a user information query request, a business information query request, a financial information query request, etc. The preset python process tool can be a multiprocessing tool in python.

[0158] In detail, the setting of the timed update sub-process based on the preset Python process tool includes:

[0159] Obtaining a scheduled execution event, and encapsulating the scheduled execution event into an execution function;

[0160] The python process tool is used to create a subprocess, and the execution function is encapsulated into the subprocess to obtain the timed update subprocess.

[0161] In an optional embodiment of the present invention, before obtaining the scheduled execution event, the method further includes:

[0162] The preset execution time and execution frequency are obtained, and the execution time and the execution frequency are encapsulated using a preset timing tool to obtain the scheduled execution event.

[0163] In an embodiment of the present invention, the apscheduler tool can be used to create scheduled execution tasks (including execution time and execution frequency). At the same time, by using the multiprocessing tool to create processes instead of threads for data processing, the purpose of program parallelism can be achieved by bypassing the GIL, thereby improving data parallel processing capabilities.

[0164] Step 4: Use the scheduled update sub-process to update the data in the database table, and query the updated database table based on the query main process to obtain a data query result.

[0165] In detail, the updating of data in the database table by using the timed update sub-process includes:

[0166] Utilize the python process tool to build a data initialization process;

[0167] Executing the timed execution event in the timed update sub-process to obtain a new set of original data;

[0168] The data initialization process is used to perform data initialization processing on the new original data set, and the processed data is filled into the database table.

[0169] In an optional embodiment of the present invention, since the multiprocessing tool is used to create processes instead of threads to update data, multi-process processing can bypass the GIL to achieve the purpose of program parallelism.

[0170] In an embodiment of the present invention, querying the updated database table based on the query main process includes:

[0171] Generate an access file according to the query main process;

[0172] Parsing the query field of the data query instruction in the query main process;

[0173] The access file is used as a query entry, and the query field is used to search for an updated database table from the query entry.

[0174] In the embodiments of the present invention, because in-memory databases use separate memory to store data, different processes do not share the same memory. Therefore, access must be performed using files. When the main query process starts, an access file is generated. Unlike other files, this file effectively creates an entry point in memory, allowing queries to be performed through this entry point. For example, in the financial field, a user enters a financial data query command, and the query fields in the financial data query command are parsed to obtain the financial data query results.

[0175] In another optional embodiment of the present invention, before parsing the query field of the data query instruction in the query main process, the method further includes:

[0176] Check whether a memory file exists in the memory database;

[0177] If the memory file does not exist in the memory database, no processing is performed;

[0178] If a memory file exists in the memory database, the memory file is deleted.

[0179] In an embodiment of the present invention, when a memory database using files as media is established, a file of size 0 will be generated in the main directory, occupying a certain amount of disk sectors. Therefore, when the query main process is started, it should be checked whether this file exists. If so, this file should be deleted. Otherwise, the disk sectors occupied will continue to increase each time the query main process is started, affecting the data query speed.

[0180] The present invention uses a Python mapping program to configure a database for the original data set to obtain an in-memory database. Compared with traditional relational databases or file-based databases, the in-memory database has a significantly improved reading speed for the same data, reducing the response time of data queries, thereby increasing the query speed. At the same time, through data cleaning and data classification, the data volume is further reduced, data segmentation is achieved, and the data query speed can also be increased. In addition, by using Python process tools to build processes instead of threads, multi-process processing can bypass the GIL and achieve program parallelism, thereby improving the efficiency of data queries. Therefore, the Python-based data query device proposed by the present invention can solve the problem of low query efficiency when using Python to perform data queries.

[0181] like Figure 3 , which is a structural diagram of an electronic device for implementing a Python-based data query method provided by an embodiment of the present invention.

[0182] The electronic device may include a processor 10, a memory 11, a communication interface 12 and a bus 13, and may further include a computer program stored in the memory 11 and executable on the processor 10, such as a Python-based data query program.

[0183] Wherein, the memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a mobile hard disk, a multimedia card, a card-type memory (for example: SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the memory 11 can be an internal storage unit of an electronic device, such as a mobile hard disk of the electronic device. In other embodiments, the memory 11 can also be an external storage device of an electronic device, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. Furthermore, the memory 11 can also include both an internal storage unit of the electronic device and an external storage device. The memory 11 can not only be used to store application software and various types of data installed in the electronic device, such as the code of a data query program based on Python, but can also be used to temporarily store data that has been output or is to be output.

[0184] In some embodiments, the processor 10 may be composed of an integrated circuit, such as a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and a combination of various control chips. The processor 10 is the control core (Control Unit) of the electronic device, connecting the various components of the entire electronic device using various interfaces and lines, and executing programs or modules stored in the memory 11 (such as a Python-based data query program, etc.), as well as calling data stored in the memory 11, to perform various functions of the electronic device and process data.

[0185] The communication interface 12 is used for communication between the above-mentioned electronic device and other devices, including a network interface and a user interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a display (Display), an input unit (such as a keyboard (Keyboard)), optionally, the user interface may also be a standard wired interface, a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode, organic light-emitting diode) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visual user interface.

[0186] The bus 13 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus 13 may be divided into an address bus, a data bus, a control bus, etc. The bus 13 is configured to enable communication between the memory 11 and at least one processor 10.

[0187] Figure 3 Only the electronic device with components is shown, and it can be understood by those skilled in the art that Figure 3 The structure shown does not limit the electronic device, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.

[0188] For example, although not shown, the electronic device may further include a power source (such as a battery) for powering various components. Preferably, the power source may be logically connected to the at least one processor 10 via a power management device, thereby implementing functions such as charge management, discharge management, and power consumption management through the power management device. The power source may further include any components such as one or more DC or AC power sources, a recharging device, a power failure detection circuit, a power converter or inverter, a power status indicator, etc. The electronic device may further include various sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be described in detail here.

[0189] Furthermore, the electronic device may also include a network interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices.

[0190] Optionally, the electronic device may further include a user interface, which may be a display or an input unit (such as a keyboard). Optionally, the user interface may also be a standard wired interface or a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an OLED (Organic Light-Emitting Diode) touch device. The display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visual user interface.

[0191] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.

[0192] The PYTHON-based data query program stored in the memory 11 of the electronic device is a combination of multiple instructions. When running in the processor 10, it can achieve the following:

[0193] Obtaining an original data set, and performing database configuration on the original data set and a preset database using a preset Python mapping program to obtain an in-memory database;

[0194] Performing data cleaning and data classification on the original data set in the in-memory database to obtain a database table;

[0195] Receive data query instructions, build a query main process based on the data query instructions, and set a timed update sub-process based on a preset Python process tool;

[0196] The database table is updated with data using the timed update sub-process, and the updated database table is queried based on the query main process to obtain a data query result.

[0197] Specifically, the specific implementation method of the processor 10 for the above instructions can refer to the description of the relevant steps in the corresponding embodiment of the drawings, which will not be repeated here.

[0198] Furthermore, if the module / unit integrated into the electronic device is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable storage medium can be volatile or non-volatile. For example, the computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard drive, a magnetic disk, an optical disk, a computer memory, or a read-only memory (ROM).

[0199] The present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program. When the computer program is executed by a processor of an electronic device, the computer program can implement:

[0200] Obtaining an original data set, and performing database configuration on the original data set and a preset database using a preset Python mapping program to obtain an in-memory database;

[0201] Performing data cleaning and data classification on the original data set in the in-memory database to obtain a database table;

[0202] Receive data query instructions, build a query main process based on the data query instructions, and set a timed update sub-process based on a preset Python process tool;

[0203] The database table is updated with data using the timed update sub-process, and the updated database table is queried based on the query main process to obtain a data query result.

[0204] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the module division is merely a logical function division, and other division methods may be used in actual implementation.

[0205] The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed across multiple network elements. Some or all of the modules may be selected to achieve the purpose of the solution of this embodiment according to actual needs.

[0206] In addition, the functional modules in various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or hardware plus software functional modules.

[0207] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.

[0208] Therefore, the embodiments should be considered in all respects as illustrative and non-restrictive, and the scope of the invention is defined by the appended claims rather than the foregoing description, and all changes that come within the meaning and range of equivalents of the claims are intended to be embraced therein. Any reference to a figure in a claim should not be construed as limiting the claim to which it relates.

[0209] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) is the theory, method, technology, and application system that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use knowledge to achieve optimal results.

[0210] Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.

[0211] Blockchain, as used in this article, refers to a novel application model for computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Blockchain is essentially a decentralized database, a series of data blocks generated using cryptographic methods. Each block contains information about a batch of online transactions, used to verify the validity of this information (to prevent counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, the platform product service layer, and the application service layer.

[0212] Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in a system claim may also be implemented by a single unit or device through software or hardware. Second-order terms are used to indicate names and do not imply any particular order.

[0213] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not limiting. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention.

Claims

1. A data query method based on Python, characterized in that, The method comprises: Obtaining a raw data set, establishing a mapping relationship between raw data in the raw data set and a raw database corresponding to the raw data using a preset Python mapping program, summarizing the mapping relationships of all raw databases to obtain a database configuration file, performing access configuration on a preset database to obtain an access configuration file, adding the database configuration file and the access configuration file to the preset database to obtain an in-memory database; Performing data cleaning and data classification on the original data set in the in-memory database to obtain a database table; Receive a data query instruction, build a query main process based on the data query instruction, create a subprocess using a preset Python process tool, encapsulate the execution function corresponding to the timed execution event into the subprocess, and obtain a timed update subprocess; Execute the timed execution event in the timed update sub-process to obtain a new original data set, perform data initialization processing on the new original data set, fill the processed data into the database table to obtain an updated database table, and query the updated database table based on the query main process to obtain a data query result.

2. The Python-based data query method as described in claim 1, characterized in that: The data cleaning and data classification of the original data set to obtain a database table includes: Deduplication, anomaly removal, and missing value filling are performed on the data in the original data set to obtain a standard data set; The standard data set is processed into a database and table to obtain the database table.

3. The data query method based on Python as claimed in claim 2, characterized in that: The step of performing data deduplication, data anomaly removal, and data missing value filling on the data in the original data set to obtain a standard data set includes: Calculating the distance value of the data in the original data set using a distance formula, and deduplicating the data in the original data set according to the distance value to obtain a deduplicated data set; Using a unilateral test formula to remove outliers from the deduplication data set to obtain an outlier-free data set; A preset missing value detection function is used to perform missing value detection on the data in the abnormal data set, and the missing values ​​are filled based on a preset filling algorithm to obtain the standard data set.

4. The data query method based on Python according to claim 1, characterized in that: Before encapsulating the execution function corresponding to the timed execution event into the sub-process, the method further includes: Obtain a scheduled execution event, and encapsulate the scheduled execution event into an execution function.

5. The data query method based on Python according to claim 1, characterized in that: The performing data initialization processing on the new original data set includes: Utilize the python process tool to build a data initialization process; The data initialization process is used to perform data initialization processing on the new original data set.

6. The data query method based on Python according to claim 1, characterized in that, The querying of the updated database table based on the query main process includes: Generate an access file according to the query main process; Parsing the query field of the data query instruction in the query main process; The access file is used as a query entry, and the query field is used to search for an updated database table from the query entry.

7. A data query device based on Python, characterized in that, The device comprises: A database configuration module is configured to obtain a raw data set, establish a mapping relationship between raw data in the raw data set and the raw database corresponding to the raw data using a preset Python mapping program, summarize the mapping relationships of all raw databases to obtain a database configuration file, perform access configuration on a preset database to obtain an access configuration file, and add the database configuration file and the access configuration file to the preset database to obtain an in-memory database; A data processing module, configured to perform data cleaning and data classification on the original data set in the memory database to obtain a database table; A process construction module is used to receive a data query instruction, construct a query main process based on the data query instruction, create a subprocess using a preset Python process tool, encapsulate the execution function corresponding to the timed execution event into the subprocess, and obtain a timed update subprocess; A data query module is used to execute the scheduled execution events in the scheduled update sub-process, obtain a new original data set, perform data initialization processing on the new original data set, fill the processed data into the database table to obtain an updated database table, and query the updated database table based on the query main process to obtain a data query result.

8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the Python-based data query method according to any one of claims 1 to 6.

9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the Python-based data query method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Inter-process communication method and device

    CN106980551A

  • Human resource monitoring and analyzing method and system

    CN110046150A

  • Data query method and device

    CN110674369A

  • Big data processing method and device, electronic equipment and storage medium

    CN111124685A

  • Data updating and displaying method and device, electronic equipment and storage medium

    CN112883042A