Program data format switching method and system and storage medium
Through the combination of the preset agent and the data reading and writing component pool, the data format is automatically switched, which solves the problem of poor compatibility of the program with data in different formats and improves efficiency and accuracy.
Patent Information
- Application Number
- CN202410611419.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-16
- Publication Date
- 2024-08-27
AI Technical Summary
It is difficult to improve the compatibility of programs for data of different formats with existing technology, and manual modification of data formats is time-consuming and reduces work efficiency.
Obtain the data partition path through the preset agent, use the preset data format switching table and data reading and writing component pool to automatically switch data formats, select appropriate data reading and writing components for format conversion, and ensure data accuracy and compatibility.
It improves the program's compatibility with data in different formats, saves the time of manual data format switching, and ensures data accuracy and efficiency.
Smart Images

Figure CN118550874A
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular to a method, system and storage medium for switching the format of program data. Background Art
[0002] With the rapid development of technology, there are now a large number of program files that implement various functions. Usually, a complete executable program includes a project file and a project configuration file. However, as users' requirements for program running efficiency continue to increase, how to improve the program's compatibility with data of different formats has become a technical problem that needs to be solved urgently. In addition, due to the large amount of existing historical projects, manually modifying the data format of historical projects will greatly increase time costs and reduce work efficiency. Summary of the invention
[0003] In view of the above technical problems, the technical solution adopted by the present application is: a method for implementing data format switching in a program, the method being executed by a preset agent, comprising the following steps: S100, obtaining N data partition paths P=(P1, P2, ..., P N ), the i-th data partition path is P i , 1≤i≤N; S200, based on the data partition path P=(P1, P2, ..., P N ) Get the marked data partition path L = (L1, L2, ..., L N ), where L i By P i and F i Composition, F i P i S300, based on the marked data partition path L, the preset data format switching table and the set data format TF of the program output data path, respectively call the corresponding data read and write components from the preset data read and write component pool RW to P1, P2, ..., P N The data format of the sub-file is switched to the set data format TF; wherein the kth row of the preset data format switching table at least includes (A k , B k , C k , D k ), A k is the kth preset data partition path, B k A k The original data format of the sub-file is C k A k The target data format of the sub-file is D k To A k The following sub-file is composed of B kSwitch to C k The required field related information, 1≤k≤L, L≥N, L is the total number of data rows contained in the preset data format switching table; the preset data read and write component pool RW=(RW0, RW1, RW2, ..., RW Q ), where RW0 is the data reading and writing component of the program, and RW j It is a data reading and writing component different from RW0 and is used to switch data from a first type of data format to a second type of data format. The first type of data format is different from the second type of data format. Q=M×(M-1), M is the total number of data format categories, 1≤j≤Q.
[0004] A system for implementing data format switching in a program, the system includes a processor and a non-transitory computer-readable storage medium, the storage medium is used to store at least one instruction or at least one program, the processor loads and executes the at least one instruction or at least one program to implement the above method.
[0005] A computer-readable storage medium stores a program or instruction, wherein the program or instruction enables a computer to execute the steps of the above method.
[0006] From the above content, it can be seen that the preset agent in the present application first obtains the data partition path passed in by the program. When it is determined that the corresponding data of a data partition path needs to switch the data format, by combining the preset data format switching table and the set data format of the program data output path, the corresponding data read-write component is selected from the preset data read-write component pool to complete the automatic switching of the data format of the sub-files under different paths. For paths that do not require switching the data format, the data read-write component that comes with the program is directly used to perform automatic data reading and writing operations. Based on the above content, it can be seen that, on the one hand, the present application ensures the accuracy of the program data by utilizing the data partition path, and on the other hand, improves the program's compatibility with data of different types and formats through customized read-write components, saving the time consumed by manual data format switching. BRIEF DESCRIPTION OF THE DRAWINGS
[0007] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0008] Figure 1 A flow chart of a method for switching the format of program data provided in an embodiment of the present application. DETAILED DESCRIPTION
[0009] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0010] The present application embodiment provides a method for switching the format of program data, such as Figure 1 As shown, the method is executed by a preset agent, and the preset agent can be implemented as a program module, or an API interface, SDK, etc. In the present application, the preset agent can be implemented in any way.
[0011] Specifically, the method comprises the following steps:
[0012] S100, obtaining N data partition paths P=(P1, P2, . . . , P N ), the i-th data partition path is P i In this application, when the user completes editing of independent program engineering files and configuration files and submits them to the operating environment for execution, the preset agent obtains all data partition paths P1, P2, ..., P1, P2, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22, P23, P24, P25, P26, P27, P28, P29, P30, P31, P32, P33, P34, P35, P36, P37, P38, P39, P40, P41, P42, P43, P44, P45, P46, P47, P48, P49, P50, P51, P52, P53, P54 N ,Since the data file name usually carries the task ID, it will cause data uncertainty, ,therefore, searching for related data based on the path information of ,data partitions can fundamentally ensure the accuracy of the data.
[0013] S200, based on the data partition path P=(P1, P2, . . . , P N ) Get the marked data partition path L = (L1, L2, ..., L N ), where L i By P i and F i Composition, F i P i In this application, the data format is a commonly used data format in the program, such as txt format, parquet format, etc. Specifically, in this step, the preset agent can obtain the partition path information P i The data format of any sub-file under the hood is used to obtain the data partition path information P i Corresponding data format, preferably, any sub-file is data partition path information P iThe first sub-file under the data partition path is in the same data format. Therefore, selecting the data format of the first sub-file as the corresponding data format of the data partition path can not only obtain the correct data format information, but also avoid the time consumed by file enumeration. Furthermore, in the present application, the data format of any sub-file can be obtained by any method in the prior art, and there is no restriction on the method of obtaining the data format, for example, obtaining the naming suffix of any sub-file (such as .txt, .parquet, etc.), or judging the first few bytes in any sub-file, etc.
[0014] S300, based on the marked data partition path L, the preset data format switching table and the set data format TF of the program output data path, respectively call the corresponding data read and write components from the preset data read and write component pool RW to convert P1, P2, ..., P N The data format of the next sub-file is switched to the set data format TF.
[0015] In the present application, the kth row of the preset data format switching table at least includes (A k , B k , C k , D k ), A k is the kth preset data partition path, B k A k The original data format of the sub-file is C k A k The target data format of the sub-file is D k To A k The following sub-file is composed of B k Switch to C k The required field related information, 1≤k≤L, L≥N, L is the total number of data rows contained in the preset data format switching table, that is, the content in the kth row of the preset data format switching table is the corresponding relationship. In one embodiment of the present application, D k To A k The following sub-file is composed of B k Switch to C k All the fields required, in the preferred embodiment of this application, D k is a path or pointer, wherein the path or pointer is used to find A k The following sub-file is composed of B k Switch to C k The storage location of all the fields required can be determined to improve the security and convenience of data storage. kAn empty path or pointer indicates that field information is not needed during data switching, that is, the data content before switching itself contains field information, and the data reading and writing component can correctly switch the data format according to the data content before switching.
[0016] The preset data read-write component pool RW=(RW0, RW1, RW2, . . . , RW Q ), where RW0 is the data reading and writing component of the program, and RW j is a data reading and writing component different from RW0 and used to switch data from the first data format to the second data format, the first data format is different from the second data format, Q=M×(M-1), M is the total number of data format categories, 1≤j≤Q. Exemplarily, when the total number of data format categories is 3, it can be known that Q=3×2=6, and then the data reading and writing component RW1 corresponding to the switching of the first data format to the second data format, the data reading and writing component RW2 corresponding to the switching of the first data format to the third data format, the data reading and writing component RW3 corresponding to the switching of the second data format to the third data format, the data reading and writing component RW4 corresponding to the switching of the second data format to the first data format, the data reading and writing component RW5 corresponding to the switching of the third data format to the first data format, and the data reading and writing component RW6 corresponding to the switching of the third data format to the first data format. The data reading and writing component RW0 is a sub-file content under a certain path that is provided by the program and is used to read and write data formats that have not changed before and after.
[0017] Based on the above content, it can be seen that the preset agent in this application first obtains the data partition path passed in by the program. When it is determined that the corresponding data of a certain data partition path needs to switch the data format, by combining the preset data format switching table and the set data format of the program data output path, the corresponding data read-write component is selected from the preset data read-write component pool to complete the automatic switching of the data format of the sub-files under different paths. For the path that does not need to switch the data format, the data read-write component that comes with the program is directly used to perform automatic data read and write operations. Based on the above content, it can be seen that, on the one hand, this application ensures the accuracy of program data by utilizing the data partition path, and on the other hand, the program's compatibility with different types of format data is improved through the customized data read-write component, saving the time consumed by manual data format switching.
[0018] In one embodiment of the present application, when the switching of the data format in the program is determined by the partition path, S300 is replaced by: based on the marked data partition path L and the preset data format switching table, respectively calling the corresponding data read and write components from the preset data read and write component pool RW to switch P1, P2, ..., P N Switch the data format of the sub-file.
[0019] In this embodiment, since the target data format is determined by the partition path, the target data format can be obtained based on the partition path, and then the corresponding data information is found in the preset data format switching table, and the data format is switched in combination with the corresponding data reading and writing components.
[0020] Furthermore, in a preferred embodiment of the present application, the preset data format switching table is stored in a distributed storage, and the distributed storage has multiple forms of existence, such as system, device, cloud, platform, etc., and its specific form of existence can be any existing method that can be used to store data.
[0021] Specifically, the S300 includes:
[0022] S301, according to the marked data partition path L and the set data format TF of the program output data path, obtain the to-be-called data read / write component RWF from the preset data read / write component pool RW = (RWF1, RWF2, ..., RWF N ), where the data read and write component RWF i ∈RW, used to convert P i The data format of the sub-file is from F i Switch to TF. The data format TF of the program output data path is related to the program itself, for example, it can be txt format, parquet format, etc. Further, in this step, if the data format under a certain path does not need to be switched, the data reading and writing component of the program can be directly called, otherwise the corresponding data reading and writing component is called. Since the data formats under different paths may be the same, when the target data format is also the same, RWF1, RWF2, ..., RWF N The same data read and write components will exist in the data partition, that is, different data partition paths call the same data read and write component.
[0023] S302, the data read / write component to be called RWF=(RWF1, RWF2, ..., RWF N ) reads the data partition path P = (P1, P2, ..., P N ) The data content of the sub-file DF=(DF1,DF2,...,DF N ), DF i P i The data content of the sub-file.
[0024] S303, the data read / write component to be called RWF=(RWF1, RWF2, ..., RWF N) according to the marked data partition path L, the set data format TF of the program output data path and the preset data format switching table, obtain the format switching necessary field information G = (G1, G2, ..., G N ), where G i By utilizing P i 、F i , FT is obtained by performing a row search on the preset data format switching table, G i ∈{D1, D2, ..., D L Specifically, in this step, the preset data format switching table is searched row by row, and when it is determined that A k =P i , B k =F i , C k = FT, then D k =G i .
[0025] S304, the data read / write component to be called RWF=(RWF1, RWF2, ..., RWF N ) Based on the format switching required field information G, DF=(DF1, DF2, ..., DF N ) After switching the data format, output DFT = {DFT1, DFT2, ..., DFT N}, DFT i DF i Content after format switching. For example, when DF i txt text content. When it needs to be converted to parquet text, it is converted according to G i The obtained field performs string cutting on the txt text content, and obtains the format-converted data content DFT according to the cut fields. i . And those skilled in the art know that, since the parquet text itself has field information, the content in the parquet text can be directly cut to convert it into a text in another format, such as a txt text. At this time, it can be known that G i Is empty.
[0026] From the above content, we can know that the program's compatibility with data in different formats is improved through customized data reading and writing components. In addition, by distinguishing between paths that require format conversion and those that do not, and using different components to read and output data, different types of data can be output according to consistent rules, which is convenient for subsequent management and application of data.
[0027] Preferably, in step S304, the data read / write component to be called RWF=(RWF1, RWF2, ..., RWF N ) can also change the encoding method and / or compression method of the output data. Specifically, in this application, the data reading and writing component to be called RWF=(RWF1, RWF2, ..., RWF N ) can be obtained by DFT = {DFT1, DFT2, ..., DFT N} and then change its encoding or compression mode and then output it. The encoding and compression modes are commonly used in the art. By changing the encoding and / or compression mode of data, the effects of enhancing data security and saving storage space can be achieved.
[0028] In a preferred embodiment of the present application, the distributed storage further includes a data format table, and the kth row of the data format table at least includes (A k , E k ), E k A k When the data format under the data partition path in the program is converted, the relevant content in the data format table will be updated in time.
[0029] Preferably, the step S200 comprises: according to the data partition path P=(P1, P2, ..., P N ) and the data format table to obtain data formats F1, F2, ..., F N .
[0030] Further, in the present application, the distributed storage communicates with the public Hive data platform to periodically update the preset data format switching table. The public Hive data platform is a public platform that stores relevant information about all metadata used in the program, including fields, etc. The metadata can be used to maintain the relevant content in the preset data format switching table. By periodically updating the preset data format switching table, it can be ensured that the content in the preset data format switching table saves as much relevant content of the program data as possible, so that when the program is running, the preset data format switching table can be used to switch the data format.
[0031] An embodiment of the present application also provides a system for switching the format of program data, the system comprising a processor and a non-transitory computer-readable storage medium, the storage medium being used to store at least one instruction or at least one program, the processor loading and executing the at least one instruction or at least one program to implement the method provided in the above embodiment.
[0032] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a program or instruction, wherein the program or instruction enables a computer to execute the steps of the method provided in the above embodiment.
[0033] An embodiment of the present application also provides a non-transitory computer-readable storage medium, which can be set in an electronic device to store at least one instruction or at least one program related to implementing a method in a method embodiment. The at least one instruction or the at least one program is loaded and executed by the processor to implement the method provided in the above embodiment.
[0034] An embodiment of the present application also provides an electronic device, comprising a processor and the aforementioned non-transitory computer-readable storage medium.
[0035] An embodiment of the present application also provides a computer program product, which includes program code. When the program product is run on an electronic device, the program code is used to enable the electronic device to execute the steps of the method according to various exemplary embodiments of the present application described above in this specification.
[0036] Although some specific embodiments of the present application have been described in detail by way of example, it will be appreciated by those skilled in the art that the above examples are only for illustration and not for limiting the scope of the present application. It will also be appreciated by those skilled in the art that various modifications may be made to the embodiments without departing from the scope and spirit of the present application. The scope of the present application is defined by the appended claims.
Claims
1. A method for switching the format of program data, characterized in that: The method is executed by a preset agent and includes the following steps: S100, obtaining N data partition paths P=(P1, P2, . . . , P N ), the i-th data partition path is P i , 1≤i≤N; S200, based on the data partition path P=(P1, P2, . . . , P N ) Get the marked data partition path L = (L1, L2, ..., L N ), where L i By P i and F i Composition, F i P i The data format of the sub-files; S300, based on the marked data partition path L, the preset data format switching table and the set data format TF of the program output data path, respectively call the corresponding data read and write components from the preset data read and write component pool RW to convert P1, P2, ..., P N The data format of the next sub-file is switched to the set data format TF; Wherein, the kth row of the preset data format switching table at least includes (A k , B k , C k , D k ), A k is the kth preset data partition path, B k A k The original data format of the sub-file is C k A k The target data format of the sub-file is D k To A k The following sub-file is composed of B k Switch to C k The required field-related information, 1≤k≤L, L≥N, L is the total number of data rows contained in the preset data format switching table; The preset data read-write component pool RW=(RW0, RW1, RW2, . . . , RW Q ), where RW0 is the data reading and writing component of the program, and RW j It is a data reading and writing component different from RW0 and is used to switch data from a first type of data format to a second type of data format. The first type of data format is different from the second type of data format. Q=M×(M-1), M is the total number of data format categories, 1≤j≤Q.
2. The method according to claim 1, characterized in that S300 specifically includes: S301, according to the marked data partition path L and the set data format TF of the program output data path, obtain the to-be-called data read / write component RWF from the preset data read / write component pool RW = (RWF1, RWF2, ..., RWF N ), where the data read and write component RWF i ∈RW, used to convert P i The data format of the sub-file is from F i Switch to TF; S302, the data read / write component to be called RWF=(RWF1, RWF2, ..., RWF N ) reads the data partition path P = (P1, P2, ..., P N ) The data content of the sub-file DF=(DF1,DF2,...,DF N ), DF i P i The data content of the sub-file; S303, the data read / write component to be called RWF=(RWF1, RWF2, ..., RWF N ) according to the marked data partition path L, the set data format TF of the program output data path and the preset data format switching table, obtain the format switching necessary field information G = (G1, G2, ..., G N ), where G i By utilizing P i 、F i , FT is obtained by performing a row search on the preset data format switching table, G i ∈{D1, D2, ..., D L }; S304, the data read / write component to be called RWF=(RWF1, RWF2, ..., RWF N ) Based on the format switching required field information G, DF=(DF1, DF2, ..., DF N ) After switching the data format, output DFT = {DFT1, DFT2, ..., DFT N }, DFT i DF i Content after format switching.
3. The method according to claim 1 or 2, characterized in that: The D k is a path or pointer, wherein the path or pointer is used to find B k Switch to C k The storage location of all required fields.
4. The method according to claim 2, characterized in that: In step S304, the data read / write component to be called RWF=(RWF1, RWF2, ..., RWF N ) can also change the encoding and / or compression method of the output data.
5. The method according to any one of claims 1 to 4, characterized in that The preset data format switching table is stored in a distributed storage.
6. The method according to claim 5, characterized in that The distributed storage also includes a data format table, and the kth row of the data format table at least includes (A k , E k ), E k A k Download the latest data format of the sub-file.
7. The method according to claim 5, characterized in that The distributed storage communicates with the public Hive data platform to periodically update the preset data format switching table.
8. The method according to claim 6, characterized in that S200 specifically includes: according to the data partition path P=(P1, P2, . . . , P N ) and the data format table to obtain data formats F1, F2, ..., F N .
9. A system for implementing data format switching in a program, the system comprising a processor and a non-transitory computer-readable storage medium, the storage medium being used to store at least one instruction or at least one program, characterized in that: The processor loads and executes the at least one instruction or at least one program to implement the method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program or instruction, and the program or instruction enables a computer to execute the steps of the method according to any one of claims 1 to 8.
