Data operation method, device, equipment and storage medium
By combining relational and non-relational databases and dynamically expanding fields, the problem of insufficient scalability of relational databases in the big data era is solved, efficient field expansion and space utilization are achieved, and the applicability and efficiency of the database are improved.
Patent Information
- Application Number
- CN202010216379.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-03-25
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2040-03-25
AI Technical Summary
When relational databases face the rapid increase in data volume in the big data era, table field expansion and index addition are not flexible and efficient enough, resulting in static expansion methods with poor applicability and low efficiency, and cannot effectively avoid space waste and multiple databases. Adjustment.
Combining relational databases and non-relational databases, the relational database is retained to store subject data that does not require expansion, and the non-relational database is added to store objects that require field expansion. Field expansion is achieved through dynamic operations, reducing space waste and improving expansion efficiency.
It realizes field expansion during data operation, avoids unnecessary waste of space and multiple database adjustments, improves expansion efficiency and flexibility, and meets the high scalability requirements of big data storage.
Smart Images

Figure CN111897824B
Abstract
Description
Technical Field
[0001] The present application relates to database technology, and in particular to a data operation method, apparatus, device and storage medium. Background Art
[0002] At present, the most commonly used database types in the database field include relational databases and non-relational databases. Among them, relational databases are widely used in the Internet industry due to their diverse query syntax, support for multi-table joint queries, support for transactions and other functional features. However, with the development of cloud computing and the advent of the big data era, the amount of data has increased rapidly, and higher requirements have been placed on the scalability of databases. The shortcomings of relational databases have become increasingly obvious, and they are not flexible and efficient enough in expanding table fields and adding indexes.
[0003] In the related art, it is generally chosen to reserve some columns in the table for field expansion when building a database. However, in the face of unpredictable data volume, the number of reserved fields cannot be estimated at all, so that when the reserved amount is large, space is wasted or secondary expansion is still required when the reserved amount is small. Therefore, this static expansion method has poor applicability and low efficiency. Summary of the invention
[0004] The present application provides a data operation method, apparatus, device and storage medium to achieve dynamic expansion of database objects and improve expansion efficiency.
[0005] In a first aspect, the present application provides a data operation method, comprising: obtaining a first data operation instruction, the first data operation instruction including data attributes and an operation method of the data to be operated; determining a database corresponding to the data attributes according to the data attributes; performing corresponding operations on the data to be operated in the database according to the operation method; if the data attributes indicate that the data to be operated is data of a non-extensible field, the database is a relational database, and if the data attributes indicate that the data to be operated is data of an extensible field, the database is a non-relational database.
[0006] Optionally, if the data length of the expandable field is less than a preset length, the database is a first database; if the data length of the expandable field is greater than or equal to a preset length, the database is a second database.
[0007] Optionally, the first data operation instruction is a statement recognizable by the relational database. Before performing a corresponding operation on the data to be operated in the database, the data operation method further includes: if the data attribute indicates that the data to be operated is data of an extensible field, generating a second data operation instruction according to the first data operation instruction and the syntax of the non-relational database, the second data operation instruction including: data attribute and operation mode of the data to be operated. Performing a corresponding operation on the data to be operated in the database according to the operation mode includes: performing a corresponding operation on the data to be operated in the non-relational database according to the second data operation instruction.
[0008] Optionally, if the non-relational database is a first database, the second operation instruction is a statement recognizable by the first database. If the non-relational database is a second database, the second operation instruction is a statement recognizable by the second database.
[0009] Optionally, the operation mode is data query, or data writing, or data updating. If the operation mode is data writing or data updating, the first operation instruction also includes data to be operated.
[0010] Optionally, according to the operation mode, a corresponding operation is performed on the data to be operated in the database, including: if it is determined according to the data attribute that the data to be operated is operable data, then a corresponding operation is performed on the data to be operated in the database.
[0011] Optionally, the data operation method further includes: if it is determined according to the data attribute that the data to be operated is inoperable data, outputting prompt information, wherein the prompt information is used to indicate that the operation has failed.
[0012] In a second aspect, the present application provides a data operation device, comprising: an acquisition module, used to acquire a first data operation instruction, wherein the first data operation instruction includes data attributes and an operation method of the data to be operated; a determination module, used to determine a database corresponding to the data attributes based on the data attributes; if the data attributes indicate that the data to be operated is data of a non-extensible field, then the database is a relational database; if the data attributes indicate that the data to be operated is data of an extensible field, then the database is a non-relational database; a processing module, used to perform corresponding operations on the data to be operated in the database according to the operation method.
[0013] Optionally, if the data length of the expandable field is less than a preset length, the database is a first database; if the data length of the expandable field is greater than or equal to a preset length, the database is a second database.
[0014] Optionally, the first data operation instruction is a statement recognizable by the relational database; the data operation device further comprises: a generation module, which is used for generating a second data operation instruction according to the first data operation instruction and the syntax of the non-relational database before the processing module performs a corresponding operation on the data to be operated in the database, if the data attribute indicates that the data to be operated is data of an extensible field. The second data operation instruction comprises: data attributes and operation methods of the data to be operated. The processing module is specifically used for: performing a corresponding operation on the data to be operated in the non-relational database according to the second data operation instruction.
[0015] Optionally, if the non-relational database is a first database, the second operation instruction is a statement recognizable by the first database. If the non-relational database is a second database, the second operation instruction is a statement recognizable by the second database.
[0016] Optionally, the operation mode is data query, or data writing, or data updating. If the operation mode is data writing or data updating, the first operation instruction also includes data to be operated.
[0017] Optionally, the processing module is specifically used to: if it is determined according to the data attribute that the data to be operated is operable data, then perform a corresponding operation on the data to be operated in the database.
[0018] Optionally, the data operation device further includes: an output module, configured to output prompt information if the determination module determines, based on the data attributes, that the data to be operated is inoperable data, wherein the prompt information is used to indicate that the operation has failed.
[0019] In a third aspect, the present application provides a data operation device, comprising: a memory for storing program instructions; a processor for calling and executing the program instructions in the memory to perform the method described in the first aspect.
[0020] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect is implemented.
[0021] In a fifth aspect, the present application provides a program product, which includes a computer program, the computer program is stored in a readable storage medium, a processor can read the computer program from the readable storage medium, and the processor executes the computer program to implement the method as described in the first aspect of the present application.
[0022] The present application provides a data operation method, device, equipment and storage medium, which obtains a first data operation instruction, which includes data attributes and operation methods of the data to be operated. Then, based on the data attributes, the corresponding database can be determined. If the data attributes indicate that the data to be operated is data of a non-expandable field, the corresponding database can be determined to be a relational database. If the data attributes indicate that the data to be operated is data of an extensible field, the corresponding database can be determined to be a non-relational database. Then, based on the operation method, the corresponding operation is performed on the data to be operated in the determined database, thus completing the data operation process. This method still retains the relational database to store the main data that does not need to be expanded, and at the same time adds a non-relational database to store the objects that need to be expanded in the field. In this way, field expansion can be achieved during the data operation process, while reducing unnecessary space waste and eliminating the need to adjust the database multiple times, thereby improving expansion efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions in the present application or the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0024] Figure 1 A schematic diagram of an application scenario of a data operation method provided in an embodiment of the present application;
[0025] Figure 2 A flowchart of a data operation method provided in one embodiment of the present application;
[0026] Figure 3 A flowchart of a data operation method provided by another embodiment of the present application;
[0027] Figure 4 A flowchart of a data operation method provided by another embodiment of the present application;
[0028] Figure 5 A schematic diagram of the structure of a data operation device provided in one embodiment of the present application;
[0029] Figure 6 A schematic diagram of the structure of a data operation device provided in one embodiment of the present application;
[0030] Figure 7 A schematic diagram of the structure of a data operation device provided in another embodiment of the present application. DETAILED DESCRIPTION
[0031] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in this application. Obviously, the described embodiments are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0032] At present, the most commonly used database types in the database field include relational databases and non-relational databases. Among them, relational databases are widely used in the Internet industry due to their diverse query syntax, support for multi-table joint queries, support for transactions and other functional features. However, with the development of cloud computing and the advent of the big data era, the amount of data has increased rapidly, and higher requirements have been placed on the scalability of databases. The shortcomings of relational databases have become increasingly obvious, and they are not flexible and efficient enough in expanding table fields and adding indexes.
[0033] In the related art, it is generally chosen to reserve some columns in the table for field expansion when building a database. However, in the face of unpredictable data volume, the number of reserved fields cannot be estimated at all, so that when the reserved amount is large, space is wasted or secondary expansion is still required when the reserved amount is small. Therefore, this static expansion method has poor applicability and low efficiency.
[0034] Although non-relational databases cannot support joint queries and do not have the four elements of atomicity, consistency, isolation, and durability for executing transactions, they are suitable for the storage of unstructured data and are more suitable for field expansion than relational databases. Based on this, the present application proposes a solution that combines relational databases with non-relational databases, retaining the relational database to store the main data that does not need to be expanded, and adding a non-relational database to store objects that need field expansion. In this way, field expansion can be achieved during data operations, while avoiding unnecessary space waste and eliminating the need to make multiple adjustments to the relational database. The following is a detailed description of the solution of the present application with several related embodiments.
[0035] Figure 1 Schematic diagram of an application scenario of a data operation method provided in an embodiment of the present application. Figure 1As shown, both the terminal device 101 and the terminal device 102 can interact with the server 103. The user operates the terminal device 101 so that the terminal device 101 can send a data operation instruction to the server 103. After receiving the operation instruction, the server 103 performs the corresponding data operation according to the operation instruction and feeds back the result of the data operation to the terminal device 101. The user can also implement the same data operation process through the terminal device 102. It should be noted that the terminal device is not limited to computers, mobile phones and other devices.
[0036] Figure 2 A flowchart of a data operation method provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, the method of this embodiment may include:
[0037] S201. Obtain a first data operation instruction, where the first data operation instruction includes data attributes and an operation method of the data to be operated.
[0038] When there is a need for data operation, it needs to be executed through specific data operation instructions. The data operation instruction will include the specific operation method and the data attributes of the data to be operated. The first step of this method is to obtain this data operation instruction, which is called the first data operation instruction.
[0039] S202. Determine a database corresponding to the data attribute according to the data attribute; if the data attribute indicates that the data to be operated is data of a non-extensible field, the database is a relational database; if the data attribute indicates that the data to be operated is data of an extensible field, the database is a non-relational database.
[0040] The first data operation instruction obtained above includes data attributes of the data to be operated, and the data attributes indicate whether the data to be operated needs to be expanded. Based on this attribute, the corresponding database can be determined. If the data attribute indicates that the data to be operated is data of a non-extensible field, then the corresponding database is a relational database. If the data attribute indicates that the data to be operated is data of an extensible field, then the corresponding database is a non-relational database.
[0041] S203: Execute corresponding operations on the data to be operated in the database according to the operation mode.
[0042] The first data operation instruction also includes an operation method. After the specific database is determined, a corresponding operation can be performed on the data to be operated in the corresponding database according to the operation method in the first data operation instruction.
[0043] The method provided in this embodiment first obtains a first data operation instruction, and then determines the corresponding database according to the data attribute of the data to be operated included in the first data operation instruction. If the data attribute indicates that the data to be operated is data of a non-expandable field, it can be determined that the corresponding database is a relational database. If the data attribute indicates that the data to be operated is data of an extensible field, it can be determined that the corresponding database is a non-relational database. Then, according to the operation mode included in the first data operation instruction, the corresponding operation is performed on the data to be operated in the corresponding database that has been determined, and the data operation process of the extensible data and the non-expandable data can be completed. The database based on this method still retains the relational database to store the main data that does not need to be expanded, and at the same time adds a non-relational database to store the objects that need to be expanded in the field. With the help of this method, field expansion can be realized in the data operation process, while avoiding unnecessary space waste in the relational database, and there is no need to adjust the relational database multiple times, thereby improving the efficiency of field expansion.
[0044] Several specific embodiments are used below. Figure 1 The technical solution of the method embodiment shown is described in detail.
[0045] In some embodiments, the operation mode may be data query, data writing, or data updating. When the operation mode is data writing or data updating, the first operation instruction also includes data to be operated. When the corresponding operation is performed, the data with operation is written to the position indicated by the data attribute. When the operation mode is data query, when the corresponding operation is performed, the data at the position indicated by the data attribute is read out. At this time, the data operation method in this embodiment also includes integrating the queried data and providing feedback. The specific method of integration can adopt a merging algorithm, and the specific implementation method will not be repeated.
[0046] It is understandable that the data to be operated included in the data operation instruction or the data attribute pointed to by the data to be operated may be multiple, and the data attributes of the multiple data to be operated are not necessarily the same. Therefore, the data to be operated indicated by the same data operation instruction may all be primary data, that is, all data corresponds to a relational database, or may all be extended data, that is, all data corresponds to a non-relational database, or may include both primary data and extended data, that is, part of the data corresponds to a relational database, and part of the data corresponds to a non-relational database.
[0047] Accordingly, in some embodiments, when the data to be operated includes both main data and extended data, that is, part of the data corresponds to a relational database and part of the data corresponds to a non-relational database, when determining the corresponding database according to the data attributes, specifically, it is necessary to perform statement splitting on the first data operation instruction according to the data attributes, and the two sub-statements correspond to the two databases respectively, so as to perform operations in the two databases respectively.
[0048] Figure 3 A flowchart of a data operation method provided in another embodiment of the present application is shown in FIG. Figure 3 As shown, the method of this embodiment may include:
[0049] S301. Obtain a first data operation instruction, where the first data operation instruction is a statement recognizable by a relational database; the first data operation instruction includes data attributes and an operation method of the data to be operated.
[0050] S302: If the data attribute indicates that the data to be operated is data of an extensible field, it is determined that the database is a non-relational database.
[0051] In this embodiment, the specific implementation process of steps S301-S302 can be found in Figure 1 The relevant description of the illustrated embodiment will not be repeated here.
[0052] S303: Generate a second data operation instruction according to the first data operation instruction and the syntax of the non-relational database, where the second data operation instruction includes: data attributes of the data to be operated and an operation method.
[0053] S304: According to the second data operation instruction, a corresponding operation is performed on the data to be operated in the non-relational database.
[0054] Different databases are suitable for different syntaxes. In this embodiment, the first data operation instruction obtained is a statement recognizable by the relational database. When the data to be operated includes extended data, before executing the operation instruction in the non-relational database, the syntax of the statement recognizable by the relational database obtained must be changed to generate an operation instruction corresponding to the syntax of the non-relational database, which is referred to as the second data operation instruction. Among them, the applicable language of the relational database is the Structured Query Language (SQL), so the statement recognizable by the relational database can be an SQL statement.
[0055] The method provided in this embodiment converts the syntax of the data operation instruction before the data operation, generates the syntax applicable to the corresponding database, and completes the data operation in the corresponding database. The database based on this embodiment still retains the relational database to store the main data that does not need to be expanded, and at the same time adds a non-relational database to store the objects that need to be expanded in the field. With the help of this method, the field expansion can be realized during the data operation process, while avoiding unnecessary space waste in the relational database, and there is no need to adjust the relational database multiple times, thereby improving the efficiency of field expansion.
[0056] In non-relational databases, each specific database has its own advantages and disadvantages. You can choose different non-relational databases according to different needs, or you can choose two or more non-relational databases at the same time to complement each other's advantages and achieve better results.
[0057] In some embodiments, two non-relational databases may be used to store extended data with different field lengths. If the data length of the extendable field is less than a preset length, the database is the first database; if the data length of the extendable field is greater than or equal to the preset length, the database is the second database.
[0058] Among non-relational databases, distributed databases have better scalability. For example, MongoDB database and ElasticSearch database are both distributed storage databases. MongoDB database can store more complex data types, and the supported query language is very powerful. Its syntax is similar to object-oriented query language, which can almost realize most of the functions of single-table query similar to relational database, and also supports indexing of data, which is more suitable for frequent addition of object fields, indexes and other needs. The data of each field in the ElasticSearch database can be searched. Just set the object to be searchable, and the index field will be automatically added. Moreover, fuzzy query and matching of large object fields can be supported. Therefore, the above-mentioned first database can use MongoDB database, and the above-mentioned second database can use ElasticSearch database. Optionally, the above-mentioned preset length is, for example, a field length of 64. This is only used as an example, and the number and specific type of non-relational data are not limited.
[0059] In some implementations, when the non-relational database is the first database, the second operation instruction is a statement recognizable by the first database; if the non-relational database is the second database, the second operation instruction is a statement recognizable by the second database.
[0060] In some implementations, the data attributes may also include attributes indicating data operability, such as whether it is searchable, whether it is updateable, etc. Based on this, according to the operation mode, a corresponding operation is performed on the data to be operated in the database, specifically including: if it is determined according to the data attributes that the data to be operated is operable data, then a corresponding operation is performed on the data to be operated in the database.
[0061] For inoperable data determined according to data attributes, a prompt message is output, and the prompt message is used to indicate that the operation failed.
[0062] Since whether the data is operable is marked in the attribute, the operability of the data can be changed by modifying the attribute value, changing an inoperable data attribute to operable, or changing an operable data attribute to inoperable.
[0063] Figure 4 A flowchart of a data operation method provided in another embodiment of the present application is shown in FIG. Figure 4 As shown, the method of this embodiment may include:
[0064] S401, obtaining a first data operation instruction, where the first data operation instruction is a statement recognizable by a relational database; the first data operation instruction includes data attributes and operation methods of data to be operated; and executing S402.
[0065] S402: Determine whether the data to be operated is data of an extensible field according to data attributes, if so, execute S403, otherwise execute S406.
[0066] S403, determine whether the data length of the expandable field is less than the preset length, if so, execute S404, otherwise execute S405.
[0067] S404. Generate a data operation instruction recognizable by the second database according to the first data operation instruction and the syntax of the second database. The generated data operation instruction recognizable by the second database includes: data attributes of the data to be operated and an operation method; execute S406.
[0068] S405. Generate a data operation instruction recognizable by the first database according to the first data operation instruction and the syntax of the first database, wherein the generated data operation instruction recognizable by the first database includes: data attributes of the data to be operated and an operation method; and execute S406.
[0069] S406: Determine whether the data to be operated is operable data according to data attributes.
[0070] The data attributes may also include attribute information indicating whether the data to be operated is operable, for example, whether it is searchable, whether it is updateable, etc. When the first data operation instruction is a query, if the data attribute indicates that the data to be queried is not searchable, that is, the corresponding data is set to be query-prohibited, it is meaningless to perform the query operation, so the data attribute is first judged, and the corresponding operation is performed only when the data is operable.
[0071] If the data to be operated is data of a non-expandable field, it is determined whether the data to be operated is operable data according to the data attribute, and if so, S407 is executed, and if not, S410 is executed.
[0072] After executing S404, it is determined whether the data to be operated is operable data, if so, executing S408, otherwise executing S410.
[0073] After executing S405, it is determined whether the data to be operated is operable data, if so, S409 is executed, otherwise S410 is executed.
[0074] S407: Execute corresponding operations on the data to be operated in the relational database.
[0075] S408: Execute corresponding operations on the data to be operated in the first database.
[0076] S409: Execute corresponding operations on the data to be operated in the second database.
[0077] S410: Output prompt information, where the prompt information is used to indicate that the operation failed.
[0078] The database on which this embodiment is based still retains the relational database to store the main data that does not need to be expanded, and at the same time adds a non-relational database to store the objects that need field expansion. With the help of this method, field expansion can be achieved during the data operation process, while avoiding unnecessary space waste in the relational database and eliminating the need to adjust the relational database multiple times, thereby improving the efficiency of field expansion.
[0079] In a specific embodiment, the first database is a MongoDB database and the second database is an ElasticSearch (ES) database. The entire data storage space is divided into three layers. The first layer uses a relational database to store non-expandable main objects. The second layer uses a non-relational database, specifically a MongoDB database, to store objects that need to be expanded and whose field length is less than 64. The third layer uses an ElasticSearch (ES) database to store objects whose field length is greater than or equal to 64. Whether it is extensible, field length, and other information are set in advance as object attributes. When performing data operations, first obtain the data operation instructions. According to the information indicating the extensibility in the data attributes, divide the data operation instructions into two parts. One part contains or points to the object to be operated as the main object, and the other part contains or points to the object to be operated as the extended object. Then, according to the field length information in the data attributes, divide the extended object operation instructions into two parts. One part contains or points to the object field length less than 64, and the other part contains or points to the object field length greater than or equal to 64. Then check the three operation instructions finally formed, mainly judging whether they are operable according to the data attributes, and whether the columns in the instructions are legal, etc. If the check result shows that there is inoperable data, a prompt message is output to indicate that the operation failed. If the check result is correct, then perform the corresponding data operations in the corresponding three-layer database according to the three operation instructions, aggregate the results, etc. When the operation mode is a query operation, after the execution is completed, the query results must be integrated and then output.
[0080] The database field is usually divided into relational and non-relational databases. At present, relational databases still occupy the mainstream position. Most systems, when considering data persistence, still choose mainstream relational databases such as MySQL database and Oracle database as the first choice. The advantages and disadvantages of relational databases are obvious. Advantages: diverse query syntax, support for multi-table joint query, support for transaction ACID, etc.; Disadvantages: inflexible and inefficient in field expansion and index addition, resulting in inability to perform operations based on the database model definition language (Data Definition Language, DDL) on an existing table with a certain amount of data.
[0081] Non-relational databases also have their advantages and disadvantages. For example, they have a higher query rate per second (QPS), such as Redis database and MemCache database. They also support non-structured data storage, such as the document storage structure of MongoDB database. However, they are not good at Join queries and ACID transactions.
[0082] By combining multiple data sources, this application can achieve high scalability of data while maintaining a high level of QPS.
[0083] When Facebook was dealing with the problem of relational database field expansion in the early years, the solution it adopted was to make some columns redundant when building tables. When field expansion was needed, these columns that already existed in the database were used as extended fields.
[0084] This type of expansion is static expansion, that is, the scale of database table fields is planned through redundant fields. However, business is often immeasurable, especially in this era of data explosion. Product demand is difficult to define and perfect at the beginning. It usually takes several or even dozens of iterations to stabilize. Therefore, it is difficult to estimate how many extended object fields need to be reserved in the table at the beginning. When the fields are less redundant, there is a problem of insufficient use. At this time, it is necessary to dynamically expand the fields. When the fields are more redundant, there will be a problem of wasted space resources.
[0085] Some solutions use vertical table storage to replace the current horizontal table storage, and implement field expansion by adding key-value.
[0086] This method can solve the problem of relational database field expansion to a certain extent, but it creates other problems. The storage of key-value only is equivalent to a non-relational database (NoSql), which cannot support associated query operations such as Join and subquery. In addition, the storage problem when the object field types in the same table are inconsistent must be solved. Usually, when a horizontal table is changed to a vertical table, when the field types defined in the table are different, it is necessary to define a value for each data type in the vertical table. When storing, first determine the type of the value, and then manually save the value to the corresponding column. As a result, there will still be field redundancy.
[0087] The present application provides a solution, which no longer uses a single storage source in the data storage layer, but clearly distinguishes the main object data and the object data that needs to be expanded when building a table. For the main data object, a relational database (SQL) is used for storage, which can support complex query operations such as adding, reading, updating, deleting, and Join, nested subqueries, etc. for the main object. As for the extensible objects, because they are facing frequent expansion, non-relational databases (NoSQL) are used for storage. Under the premise of following the SQL92 specification, these objects are defined as only supporting simple query syntax, but not supporting complex queries and Join operations. In NoSQL, MongoDB database is relatively more suitable for the frequent increase of object fields and indexes, and its performance meets most current business needs. Therefore, MongoDB database can be preferred to store these object fields with a length of less than 64 bits. Users only need to query at the index level or perform simple matching queries (match) on searchable fields. For fuzzy queries such as Like statements in SQL statements and matching of large object fields with a field length greater than or equal to 64 bits, the ES database can be used to handle them. When these fields need to be searched, the object element attribute is set to searchable, and an index column will be automatically added to the ES database.
[0088] The data storage in the first solution of the present application is divided into three layers. The first layer uses a relational database to store object entities (non-extended objects, supporting all SQL query syntaxes), the second layer uses NoSQL to store objects that need to be expanded (real-time dynamic expansion, no performance bottlenecks, support index-level single-table query operations and queries with searchable object fields less than 64 bits in length, and support SQL92 protocol related syntax), and the third layer uses ES. When dynamically expanding objects, the attributes are set to searchable, and the objects are set to ES indexes, supporting fuzzy queries, queries with object field lengths greater than or equal to 64 bits, and other requirements.
[0089] The solution provided by the present application adopts the client software development kit (Software Development Kit, SDK) access method in the overall architecture of the application, intercepts the client SQL statement at the Java Database Connectivity (Java Database Connectivity, JDBC) layer, determines whether it is just a simple main data query or a query involving extended fields according to the metadata definition rules, splits the SQL statement, and automatically submits it to the server data-service. The data-service first parses the SQL to generate intermediate objects, and then performs a field pre-check. For example, whether the cloumns submitted during query, insert, update and other operations are legal, whether the conditions in the query and update operations are searchable, etc., and then generates a corresponding execution plan based on the results, such as a relational database execution plan, a NoSQL execution plan, an ES execution plan, etc., which are finally executed by the executor to aggregate the results.
[0090] A technical solution of the present application uses a mixed architecture of multiple databases, and the data source is no longer single, which solves the defects in the business scenario. The solution is more flexible and can meet business needs in terms of execution efficiency. At the same time, it is also convenient for the business end to access.
[0091] The database in this application is implemented in a plug-in manner. No matter which database is used, you only need to implement the relevant interface of the StrorageServicePlugin for plug-in access.
[0092] The client SDK access is non-invasive and the user has no perception. The user only needs to introduce the relevant Maven dependencies and configure the access address of the server data-service to the JDBC connection string in the configuration file. The SDK automatically completes the steps of splitting and submitting SQL statements, merging the returned results into object generation (deserialization), etc.
[0093] The searchability of a field (searchable attribute) can be modified dynamically and at any time. Once enabled, it will take effect immediately in the user's next SQL request. For example, before enabling the searchable attribute of a field, when the field appears as a query condition in the where condition of an SQL query statement, the server will prompt an error that the field cannot be searched. After setting the field to be searchable, no error will be reported when executing the same SQL statement, and the relevant query result set will be returned.
[0094] Figure 5 A schematic diagram of the structure of a data operation device provided in an embodiment of the present application is shown in FIG. Figure 5 As shown, the device of this embodiment may include: an acquisition module 501 , a determination module 502 , and a processing module 503 .
[0095] The acquisition module 501 is used to acquire a first data operation instruction, wherein the first data operation instruction includes data attributes and operation methods of the data to be operated.
[0096] The determination module 502 is used to determine the database corresponding to the data attribute according to the data attribute; if the data attribute indicates that the data to be operated is data of a non-extensible field, the database is a relational database; if the data attribute indicates that the data to be operated is data of an extensible field, the database is a non-relational database.
[0097] The processing module 503 is used to perform corresponding operations on the operation data in the database according to the operation mode.
[0098] Optionally, if the data length of the expandable field is less than a preset length, the database is the first database; if the data length of the expandable field is greater than or equal to the preset length, the database is the second database.
[0099] Optionally, the first data operation instruction is a statement recognizable by a relational database. The data operation device further includes: a generation module 504, which is used for generating a second data operation instruction according to the first data operation instruction and the syntax of the non-relational database before the processing module performs a corresponding operation on the data to be operated in the database, if the data attribute indicates that the data to be operated is data of an extensible field, and the second data operation instruction includes: data attributes of the data to be operated and an operation method. The processing module 503 is specifically used to: perform a corresponding operation on the data to be operated in the non-relational database according to the second data operation instruction.
[0100] Optionally, if the non-relational database is the first database, the second operation instruction is a statement recognizable by the first database; if the non-relational database is the second database, the second operation instruction is a statement recognizable by the second database.
[0101] Optionally, the operation mode is data query, or data writing, or data updating. If the operation mode is data writing or data updating, the first operation instruction also includes data to be operated.
[0102] Optionally, the processing module 503 is specifically used to: if it is determined according to the data attributes that the data to be operated is operable data, then perform a corresponding operation on the data to be operated in the database.
[0103] Optionally, the data operation device further includes: an output module 505, which is used to output prompt information if the determination module determines that the data to be operated is inoperable data according to the data attributes, and the prompt information is used to indicate that the operation fails.
[0104] Optionally, when the operation mode is a query operation, the output module 505 is further used to integrate and output the query results after the execution is completed.
[0105] The device of this embodiment can be used to execute the method of any of the above embodiments. Its implementation principle and technical effects are similar and will not be described in detail here.
[0106] Figure 6 A schematic diagram of the structure of a data operation device provided in an embodiment of the present application is shown in FIG. Figure 6 As shown, the device of this embodiment may include: a memory 601 and a processor 602 .
[0107] The memory 601 is used to store program instructions.
[0108] The processor 602 is used to call and execute program instructions in the memory, and execute: obtaining a first data operation instruction, the first data operation instruction including data attributes and operation methods of the data to be operated; determining a database corresponding to the data attributes according to the data attributes; performing corresponding operations on the data to be operated in the database according to the operation method; if the data attributes indicate that the data to be operated is data of a non-extensible field, the database is a relational database, and if the data attributes indicate that the data to be operated is data of an extensible field, the database is a non-relational database.
[0109] Optionally, if the data length of the expandable field is less than a preset length, the database is the first database; if the data length of the expandable field is greater than or equal to the preset length, the database is the second database.
[0110] Optionally, the first data operation instruction is a statement recognizable by a relational database; before performing a corresponding operation on the data to be operated in the database, the processor 602 is further used to execute: if the data attribute indicates that the data to be operated is data of an extensible field, then according to the first data operation instruction and the syntax of the non-relational database, a second data operation instruction is generated, and the second data operation instruction includes: data attributes of the data to be operated and an operation mode. Accordingly, when the processor 602 performs a corresponding operation on the data to be operated in the database according to the operation mode, it is specifically used to: perform a corresponding operation on the data to be operated in the non-relational database according to the second data operation instruction.
[0111] Optionally, if the non-relational database is the first database, the second operation instruction is a statement recognizable by the first database; if the non-relational database is the second database, the second operation instruction is a statement recognizable by the second database.
[0112] Optionally, the operation mode is data query, or data writing, or data updating; wherein, if the operation mode is data writing or data updating, the first operation instruction also includes data to be operated.
[0113] Optionally, the processor 602 is further configured to execute: if it is determined according to the data attributes that the data to be operated is operable data, then a corresponding operation is performed on the data to be operated in the database.
[0114] Optionally, the processor 602 is further configured to execute: if it is determined according to the data attribute that the data to be operated is inoperable data, outputting a prompt message, where the prompt message is used to indicate that the operation has failed.
[0115] The device of this embodiment can be used to execute the method of any of the above embodiments. The implementation principle and technical effects are similar and will not be described in detail here.
[0116] Figure 7 This is a schematic diagram of the structure of a data operation device provided in another embodiment of the present application. For example, this device can be provided as a computer. Figure 7 , the apparatus includes a processing component 701, which further includes one or more processors, and a memory resource represented by a memory 702 for storing instructions, such as an application, that can be executed by the processing component 701. The application stored in the memory 702 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 701 is configured to execute the instructions to perform the above method.
[0117] The device may also include a power supply component 703 configured to perform power management of the device, a wired or wireless network interface 704 configured to connect the device to a network, and an input / output (I / O) interface 705. The device may operate based on an operating system stored in the memory 702, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™ or the like.
[0118] The present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, any of the above methods is implemented.
[0119] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0120] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A data operation method, characterized in that: include: Acquire a first data operation instruction, wherein the first data operation instruction includes data attributes and an operation method of the data to be operated; According to the data attribute, determining a database corresponding to the data attribute; According to the operation mode, performing corresponding operations on the data to be operated in the database; If the data attribute indicates that the data to be operated is data of a non-extensible field, the database is a relational database; if the data attribute indicates that the data to be operated is data of an extensible field, the database is a non-relational database; The first data operation instruction is a statement recognizable by the relational database; Before performing a corresponding operation on the data to be operated in the database, the method further includes: if the data attribute indicates that the data to be operated is data of an extensible field, generating a second data operation instruction according to the first data operation instruction and the syntax of the non-relational database, wherein the second data operation instruction includes: the data attribute of the data to be operated and an operation mode; According to the operation mode, performing corresponding operations on the data to be operated in the database includes: According to the second data operation instruction, performing a corresponding operation on the data to be operated in the non-relational database; If the data length of the expandable field is less than the preset length, the database is the first database; if the data length of the expandable field is greater than or equal to the preset length, the database is the second database; If the non-relational database is a first database, the second operation instruction is a statement recognizable by the first database; If the non-relational database is a second database, the second operation instruction is a statement recognizable by the second database.
2. The method according to claim 1, characterized in that The operation mode is data query, data writing, or data update; If the operation mode is data writing or data updating, the first operation instruction also includes data to be operated.
3. The method according to claim 2, characterized in that According to the operation mode, performing corresponding operations on the data to be operated in the database includes: If it is determined according to the data attribute that the data to be operated is operable data, a corresponding operation is performed on the data to be operated in the database.
4. The method according to claim 3, characterized in that: Also includes: If it is determined according to the data attribute that the data to be operated is inoperable data, a prompt message is output, where the prompt message is used to indicate that the operation failed.
5. A data operation device, characterized in that: include: An acquisition module, used for acquiring a first data operation instruction, wherein the first data operation instruction includes a data attribute and an operation mode of the data to be operated; A determination module, configured to determine a database corresponding to the data attribute according to the data attribute; if the data attribute indicates that the data to be operated is data of a non-extensible field, the database is a relational database; if the data attribute indicates that the data to be operated is data of an extensible field, the database is a non-relational database; a processing module, configured to perform a corresponding operation on the data to be operated in the database according to the operation mode; if the data length of the expandable field is less than a preset length, the database is a first database; if the data length of the expandable field is greater than or equal to the preset length, the database is a second database; The first data operation instruction is a statement recognizable by the relational database; the data operation device further comprises: a generating module, which is used for generating a second data operation instruction according to the first data operation instruction and the syntax of the non-relational database before the processing module performs a corresponding operation on the data to be operated in the database, if the data attribute indicates that the data to be operated is data of an extensible field, wherein the second data operation instruction comprises: data attribute and operation mode of the data to be operated; The processing module is specifically used to: perform a corresponding operation on the data to be operated in the non-relational database according to a second data operation instruction; if the non-relational database is a first database, the second operation instruction is a statement recognizable by the first database; if the non-relational database is a second database, the second operation instruction is a statement recognizable by the second database.
6. A data operation device, characterized in that: include: A memory for storing program instructions; A processor, configured to call and execute program instructions in the memory to perform the method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
