Multi-dimensional data sorting method and device based on chained comparator and medium
Through the chain comparator and quick sort algorithm, the data redundancy and time complexity problems in multidimensional data processing are solved, efficient and stable multidimensional data sorting is achieved, dynamic calculation and exception handling are supported, and strict priority of sorting results is ensured.
Patent Information
- Application Number
- CN202510853894.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-24
- Publication Date
- 2025-09-19
AI Technical Summary
In the field of data processing, existing technologies have problems such as data structure redundancy, high time complexity, inability to dynamically expand dimensions, lack of exception handling and strict priority checking when sorting in multiple dimensions.
It adopts a chain comparator construction mechanism, dynamically connects the comparison rules of each dimension through the quick sort algorithm and attribute extraction logic chain, combines parallel segmentation and cache management, verifies the dimension order of the sorting results in real time, and supports dynamic calculation and nested data structures.
It improves the efficiency of multi-dimensional data processing, reduces data redundancy and temporary storage occupancy, ensures strict priority and consistency of sorting results, and improves resource utilization.
Smart Images

Figure CN120669952A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a multidimensional data sorting method, device, and medium based on a chain comparator. Background Art
[0002] In the field of data processing, sorting algorithms, as core basic operations, directly affect the efficiency and quality of large-scale data processing. Although traditional sorting algorithms such as quick sort and merge sort can efficiently process single-dimensional data, they have significant limitations when facing multi-dimensional sorting requirements. Existing technologies usually use weight merging or multiple loop sorting methods to achieve multi-condition sorting: the former requires pre-calculation and storage of composite weights, resulting in redundant data structures and difficulty in dynamically expanding dimensions; the latter performs multiple single-dimensional sorting operations in serial, resulting in a factorial increase in time complexity, especially in scenarios with massive data, where performance drops sharply.
[0003] Furthermore, existing solutions face even more severe challenges when the sorting dimension involves dynamic calculations (such as real-time generation of comparison values) or nested data structures. Dynamic calculations require pre-generating all intermediate results before sorting, which consumes a large amount of temporary storage space. Nested structures must be manually flattened, destroying the original data's relevance. Such operations not only increase computational overhead but also introduce data consistency issues.
[0004] Furthermore, the existing sorting process lacks systematic handling of abnormal scenarios. Null-valued elements can easily cause comparison interruptions, dimension parameter errors are difficult to intercept in real time, and the correctness of sorting results relies on manual verification. Especially in scenarios with multi-level dimension priorities, traditional methods cannot guarantee a strict priority order for each dimension after sorting, requiring additional verification logic, further hindering overall efficiency. Summary of the Invention
[0005] The embodiments of the present application provide a multidimensional data sorting method, device, and medium based on a chain comparator to solve the above-mentioned technical problems.
[0006] On the one hand, an embodiment of the present application provides a multidimensional data sorting method based on a chain comparator, comprising:
[0007] Receive a data set to be sorted and a dimension parameter sequence; the dimension parameter sequence includes a plurality of dimension identifiers arranged in order of priority;
[0008] Parsing the dimension parameter sequence, generating an attribute extraction logic chain corresponding to the dimension identifier, and sequentially connecting the single-dimensional comparators corresponding to each dimension identifier in series based on the attribute extraction logic chain to construct a chain comparator;
[0009] Performing a sorting operation on the data set to be sorted by a quick sorting algorithm; wherein the quick sorting algorithm calls the chain comparator to perform a multi-dimensional data element comparison;
[0010] Verify whether the order of data dimensions in the sorting result conforms to the priority order of the dimension sequence, and output the corresponding verification result.
[0011] In one implementation of the present application, parsing the dimension parameter sequence and generating an attribute extraction logic chain corresponding to the dimension identifier specifically includes:
[0012] Mapping a dimension identifier of a string type to an object attribute access method of a data element in the data set to be sorted;
[0013] The serial connection order corresponding to each dimensional comparator is determined according to the priority order of the dimensional parameter sequence.
[0014] In one implementation of the present application, based on the attribute extraction logic chain, the single-dimensional comparators corresponding to each dimension identifier are sequentially connected in series to construct a chain comparator, specifically including:
[0015] Using the main dimension in the series sequence as a first-level comparator and generating a corresponding main dimension comparison rule;
[0016] According to the sub-priority order in the series connection sequence, the corresponding single-dimensional comparators are added to the first-stage comparators step by step; wherein each stage of sub-comparators is activated when the comparison results of the previous stage are equal.
[0017] In one implementation of the present application, the present invention further includes:
[0018] When any dimension identifier needs to obtain the comparison value through dynamic calculation, embed the calculation expression in the sub-comparator of the corresponding dimension identifier;
[0019] The calculation expression is calculated in real time when the comparison operation is executed to generate a temporary cache result, and the temporary cache result is automatically released after the sorting is completed.
[0020] In one implementation of the present application, a sorting operation is performed on the data set to be sorted using a quick sorting algorithm, specifically including:
[0021] Performing parallel segmentation on the data set to be sorted to generate multiple data subsets;
[0022] calling the sub-comparators in the chained comparator in sequence according to the priority order of the dimensional parameter sequence, performing multi-dimensional data element comparison on the multiple data subsets, and determining the size relationship between the data elements;
[0023] The sorted data subsets are merged and the data subsets are recursively processed until all data elements are sorted.
[0024] In one implementation of the present application, verifying whether the order of the data dimensions in the sorting result conforms to the priority order of the dimension sequence specifically includes:
[0025] Check whether the number of dimension levels of the output data set in the sorting result is consistent with the number of dimension identifiers in the dimension parameter sequence;
[0026] In the case of consistent quantities, continue to check whether the dimensional order of adjacent data elements in the output data set conforms to the priority order of the dimensional priority sequence.
[0027] In one implementation of the present application, the present invention further includes:
[0028] When an invalid dimension parameter is detected during the sorting process, the sorting process is interrupted and a dimension error indicator is returned;
[0029] When a data element triggers an exception due to a null value, the preset null value processing strategy is called and the sorting is continued; wherein, the null value processing strategy includes: forcing the null value element to be placed before the non-null value element, or forcing the null value element to be placed after the non-null value element.
[0030] In one implementation of the present application, the present invention further includes:
[0031] Expanding the data set to be sorted into a flat intermediate structure, and assigning an independent dimension identifier to each field in the attribute extraction logic chain;
[0032] Based on the chain comparator, a sorting operation is performed on the flattened intermediate structure, and the sorted flattened intermediate structure is restored to the original nested hierarchical structure.
[0033] On the other hand, an embodiment of the present application further provides a multidimensional data sorting device based on a chain comparator, the device comprising:
[0034] at least one processor;
[0035] and, a memory communicatively coupled to the at least one processor;
[0036] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the multidimensional data sorting method based on a chain comparator as described above.
[0037] On the other hand, an embodiment of the present application further provides a non-volatile computer storage medium storing computer executable instructions. When the computer executable instructions are executed, the multi-dimensional data sorting method based on the chain comparator as described above is implemented.
[0038] The present invention provides a method, device, and medium for sorting multidimensional data based on a chained comparator, which have at least the following beneficial effects:
[0039] Through the cascade construction mechanism of chain comparators, the comparison rules of each dimension are dynamically connected in series according to priority, avoiding data structure redundancy caused by the traditional weight merging method and eliminating the factorial time complexity overhead of multiple loop sorting; combined with the natural adaptability of the quick sort algorithm to large-scale data, while ensuring the stability of sorting, the processing efficiency of multi-dimensional data is significantly improved; based on the attribute extraction logic chain, dimension identifiers are mapped to data attributes in real time, directly supporting the embedded execution of dynamic calculation expressions in the comparator, without the need to pre-generate intermediate results, reducing temporary storage occupancy; at the same time, through the automatic release of the cache mechanism after sorting, the risk of memory leaks caused by dynamic calculations is avoided, and resource utilization is improved; before the sorting result is output, a dimension order verification link is added to automatically detect the matching of the number of dimension levels and the priority order of adjacent elements, solving the lag problem of traditional solutions relying on manual verification, and ensuring strict priority delivery required by business rules. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0041] Figure 1 A flowchart of a multidimensional data sorting method based on a chain comparator provided in an embodiment of the present application;
[0042] Figure 2 A schematic diagram of the internal structure of a multidimensional data sorting device based on a chain comparator provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] To make the purpose, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this application and the corresponding drawings. Obviously, the embodiments described are only 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 making creative efforts are within the scope of protection of this application.
[0044] The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0045] Figure 1 A flowchart of a multidimensional data sorting method based on a chain comparator provided in an embodiment of the present application.
[0046] The analysis method involved in the embodiments of the present application can be implemented by a terminal device or a server, and the present application does not impose any special restrictions on this. For ease of understanding and description, the following embodiments are described in detail using a server as an example.
[0047] It should be noted that the server can be a single device or a system composed of multiple devices, that is, a distributed server, and this application does not make any specific restrictions on this.
[0048] like Figure 1 As shown, an embodiment of the present application provides a multidimensional data sorting method based on a chain comparator, comprising:
[0049] Step 101: Receive a data set to be sorted and a dimension parameter sequence; the dimension parameter sequence includes multiple dimension identifiers arranged in order of priority.
[0050] In this embodiment, the data set to be sorted refers to a data set that needs to be sorted according to multiple rules, and its element types include simple objects (such as key-value pairs) or nested objects (such as financial documents with sub-objects). It should be noted that the dimension parameter sequence is a sorting basis defined in the form of a string array, such as ["date","currency.code","amount*rate"], where the string content directly corresponds to the attributes or calculation logic of the data element. It is understandable that external input is received through the API interface to establish the data and rule basis for subsequent sorting.
[0051] For example, for the financial voucher sorting scenario, the input data set is List <voucher>The dimension sequence of the collection is ["voucherDate","currency.foreignCode"], which means sorting by date first. If the dates are the same, sorting by foreign currency code.
[0052] Step 102: parse the dimension parameter sequence, generate an attribute extraction logic chain corresponding to the dimension identifier, and based on the attribute extraction logic chain, sequentially connect the single-dimensional comparators corresponding to each dimension identifier in series to construct a chain comparator.
[0053] In this embodiment, the generation of the attribute extraction logic chain is the core technical link. Specifically, the string dimension identifier is mapped to an executable method. A simple attribute path (such as "currency.foreignCode") is resolved to the method reference Voucher::getCurrency().getForeignCode(). The dynamic calculation expression generates the Lambda function v->v.getAmount()*v.getExchangeRate(), and the calculation expression is such as "amount*exchangeRate".
[0054] The chained comparator construction process starts with creating a base comparator (Comparator.comparing) with the primary dimension (the first in the sequence), and then appending secondary comparators to the chain in order of priority using thenComparing(). Specifically, secondary comparators are activated only when the primary dimension values are equal, implementing a cascading activation mechanism.
[0055] In this embodiment, the retrieved data is first expanded according to the number of levels of the list, the expanded list is compared with the dimension, and the data is sorted according to the level according to the rules of the quick sort algorithm. By using a chained comparator, multi-dimensional comparison of data is performed. Taking the Comparator in Java as an example, the specific method is as follows:
[0056] L of transformation order m (L n (…)) is disassembled according to P j Sort in the order of, get the sorting result, get the transformed list L mj (L nj (…)).
[0057] Sorting combines data from the inside out along the dimensions, resulting in sorted data. The sorting algorithm modifies the state of the data combined along the dimensions to create the main rule. To a certain extent, the sorting algorithm can organize the main rule according to the requirements of the sorting algorithm, creating Intermediate State 1. The data in Intermediate State 1 satisfies the sorting result under Dimension 1.
[0058] Add chained comparator P1, the secondary rule. Using P1, find a comparison order that satisfies the dimensions of intermediate state 1. Under the premise of satisfying the primary rule, use the sorting algorithm, and also satisfy the secondary rule of P1. The resulting sorting result that satisfies both the primary and secondary rules is intermediate state 2.
[0059] By analogy, using chain comparators P2 to Pj, in the intermediate state 2 to intermediate state j-1 dimensions, intermediate states P3 to Pj are obtained under the premise of satisfying the P1 rule.
[0060] Chained comparators can fully utilize algorithms with different time and space complexities. Through chained comparators, different algorithms can be used in different dimensions according to different algorithm considerations while meeting the calculation conditions.
[0061] For example, a voucher has the following dimensions: voucher date, currency, foreign currency, amount, foreign currency amount, and transaction auxiliary. Now I want to sort them according to the voucher date first, and then sort them according to the currency and foreign currency. Specifically, I do this based on a complex calculation method of pre-packaged amount and foreign currency. Finally, I sort them according to the transaction auxiliary by number.
[0062] In one embodiment of the present application, a calculation expression embedding mechanism and a temporary cache lifecycle management system are constructed for dimension identifiers that require dynamic calculations to obtain comparison values. It should be noted that dynamically calculated dimensions refer to sorting criteria that cannot be directly obtained through data object attributes and require real-time calculations to generate comparison values, such as "foreign currency equivalent amount = amount × exchange rate" in financial documents. The processing of such dimensions is a performance bottleneck for traditional solutions, as they often require pre-calculation and storage of intermediate results, resulting in data structure expansion.
[0063] Specifically, the calculation expression embedding process is as follows: when parsing the dimension parameter sequence, if a dimension identifier contains an operator (such as * or +) or a function call (such as calculateAmount()), it is determined to be a dynamically calculated dimension. For example, a Lambda expression is generated for the dimension identifier "amount*exchangeRate" and directly injected into the corresponding sub-comparator of the chained comparator.
[0064] It's important to note the cache management mechanism during real-time computation. When a chained comparator performs element comparisons, the first access to a dynamic dimension triggers expression evaluation, and the result is stored in a thread-level cache using the key-value pair "data element ID, calculated value". Subsequent comparisons of the same element directly read the cached value to avoid duplicate calculations. When the sorting thread terminates, the associated cache is automatically cleared. For example, in Java, cache isolation is implemented through ThreadLocal, and garbage collection is used to free up memory.
[0065] Step 103: Perform a sorting operation on the data set to be sorted using a quick sort algorithm; wherein the quick sort algorithm calls a chain comparator to compare multi-dimensional data elements.
[0066] In this embodiment, the dataset to be sorted is parallelized and partitioned, such as using a Fork / Join framework, to generate independently processed data subsets. Each subset uses the same chained comparator to compare elements, ensuring consistent global dimensional priorities. It should be noted that during the recursive sorting process, after selecting the pivot element, the chained comparator is used to determine multidimensional relationships in one go, e.g., element A < pivot < element B. If the subsets are already sorted in the primary dimension, such as if all dates are the same, redundant recursion is skipped.
[0067] In this embodiment, a real-time verification mechanism for dimension parameters and a strategic processing system for null value elements are constructed to address abnormal scenarios in the sorting process. It should be noted that invalid dimension parameters refer to sorting criteria that cannot be mapped to data object attributes or calculation logic, such as misspellings of field names, non-existent method calls, etc., while null value-triggered exceptions include two types of situations: the data element as a whole is null, or the target attribute value is null, such as the trader object of the voucher is null. This type of exception is a systemic defect of traditional solutions and often leads to unexpected termination of the sorting process.
[0068] Specifically, when parsing a dimension parameter sequence, accessibility validation is performed on each dimension identifier. For example, when attempting to map the field name "invalidField," reflection checks whether the data object contains this attribute. Dynamically calculated expressions are then subject to parser validation, such as detecting undefined variables. If any of these validations fail, the dimension is considered invalid.
[0069] Null value handling rules are enforced when chained comparators are initialized: nullsFirst() places null elements at the beginning of the sorted queue, and nullsLast() places null elements at the end of the sorted queue. If a comparison operation throws a NullPointerException due to a null value, the exception is caught and a pre-set policy is activated. This policy handles both null value scenarios: when the entire element is null, such as voucher = null, and when the target attribute is null, such as voucher.getContact() = null.
[0070] Step 104: Verify whether the order of the data dimensions in the sorting result complies with the priority order of the dimension sequence, and output the corresponding verification result.
[0071] In this embodiment, a dual-defense verification mechanism is implemented to ensure the correctness of the sorting results. It should be noted that the number of dimension levels refers to the number of valid dimension levels actually involved in the comparison in the sorting results, while the dimension priority sequence is a strict user-defined ordering rule (e.g., in ["Date", "Currency", "Amount"], "Date" has the highest priority). Traditional solutions lack automated verification and require manual sampling checks, making it difficult to ensure strict priority transmission for large-scale data.
[0072] Specifically, the process iterates over each element in the output dataset and counts the number of accessible dimension attributes. Consistency is determined when the number of dimensions for all elements equals the length of the input parameter sequence. If an inconsistency is detected (e.g., an element is missing the "currency" dimension), the process is terminated immediately and a "missing dimension error" is flagged.
[0073] For example, if the input dimension sequence is level 3 (["A", "B", "C"]), but an output element contains only two valid attributes, A and B, an error is triggered.
[0074] In this embodiment, a hierarchical expansion-sorting-restoration technology system is constructed to meet the sorting requirements of nested structured data. It should be noted that the original nested hierarchical structure refers to a composite data type containing object references (such as the nested contact object in the financial voucher object), while the flattened intermediate structure is a single-layer key-value pair set generated by extracting nested fields. Traditional sorting schemes cannot directly handle such structures and require manual dimensionality reduction, which leads to the destruction of data correlation.
[0075] Specifically, recursively scan all leaf node fields of the original object, such as voucherDate, contact.id, and contact.name in the voucher object. A composite key is generated for each extracted field, using the format of parent object ID@field path, such as v123@contact.name. A FlatObject is created, containing the original primary key (e.g., voucherId) and all leaf node key-value pairs.
[0076] The above is an embodiment of the method proposed in this application. Based on the same inventive concept, this application embodiment also provides a multi-dimensional data sorting device based on a chain comparator, whose structure is as follows: Figure 2 shown.
[0077] Figure 2 This is a schematic diagram of the internal structure of a multidimensional data sorting device based on a chain comparator provided in an embodiment of the present application. Figure 2 As shown, the equipment includes:
[0078] at least one processor;
[0079] and, a memory communicatively coupled to the at least one processor;
[0080] The memory stores instructions that can be executed by at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to:
[0081] Receive a data set to be sorted and a dimension parameter sequence; the dimension parameter sequence includes multiple dimension identifiers arranged in order of priority;
[0082] Parse the dimension parameter sequence, generate the attribute extraction logic chain corresponding to the dimension identifier, and based on the attribute extraction logic chain, sequentially connect the single-dimensional comparators corresponding to each dimension identifier in series to construct a chain comparator;
[0083] Perform sorting on the data set to be sorted using the quick sort algorithm, where the quick sort algorithm uses a chained comparator to compare multi-dimensional data elements.
[0084] Verify whether the order of data dimensions in the sorting result conforms to the priority order of the dimension sequence, and output the corresponding verification result.
[0085] The present application also provides a non-volatile computer storage medium storing computer-executable instructions. When the computer-executable instructions are executed, they can:
[0086] Receive a data set to be sorted and a dimension parameter sequence; the dimension parameter sequence includes multiple dimension identifiers arranged in order of priority;
[0087] Parse the dimension parameter sequence, generate the attribute extraction logic chain corresponding to the dimension identifier, and based on the attribute extraction logic chain, sequentially connect the single-dimensional comparators corresponding to each dimension identifier in series to construct a chain comparator;
[0088] Perform sorting on the data set to be sorted using the quick sort algorithm, where the quick sort algorithm uses a chained comparator to compare multi-dimensional data elements.
[0089] Verify whether the order of data dimensions in the sorting result conforms to the priority order of the dimension sequence, and output the corresponding verification result.
[0090] The various embodiments in this application are described in a progressive manner. Similar portions between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the device and medium embodiments are generally similar to the method embodiments, so their descriptions are relatively simple. For relevant portions, refer to the descriptions of the method embodiments.
[0091] The devices and media provided in the embodiments of the present application correspond one-to-one to the methods. Therefore, the devices and media also have similar beneficial technical effects to their corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the devices and media will not be repeated here.
[0092] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0093] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0094] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0095] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0096] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0097] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0098] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0099] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a..." does not preclude the presence of other identical elements in the process, method, commodity, or apparatus comprising the element.
[0100] The above are merely embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.< / voucher>
Claims
1. A multidimensional data sorting method based on a chain comparator, characterized in that: The method comprises: Receive a data set to be sorted and a dimension parameter sequence; the dimension parameter sequence includes a plurality of dimension identifiers arranged in order of priority; Parsing the dimension parameter sequence, generating an attribute extraction logic chain corresponding to the dimension identifier, and sequentially connecting the single-dimensional comparators corresponding to each dimension identifier in series based on the attribute extraction logic chain to construct a chain comparator; Performing a sorting operation on the data set to be sorted by a quick sorting algorithm; wherein the quick sorting algorithm calls the chain comparator to perform a multi-dimensional data element comparison; Verify whether the order of data dimensions in the sorting result conforms to the priority order of the dimension sequence, and output the corresponding verification result.
2. A multidimensional data sorting method based on a chain comparator according to claim 1, characterized in that: Parsing the dimension parameter sequence to generate an attribute extraction logic chain corresponding to the dimension identifier specifically includes: Mapping a dimension identifier of a string type to an object attribute access method of a data element in the data set to be sorted; The serial connection order corresponding to each dimensional comparator is determined according to the priority order of the dimensional parameter sequence.
3. The multidimensional data sorting method based on a chain comparator according to claim 2, characterized in that: Based on the attribute extraction logic chain, the single-dimensional comparators corresponding to each dimension identifier are sequentially connected in series to construct a chain comparator, specifically including: Using the main dimension in the series sequence as a first-level comparator and generating a corresponding main dimension comparison rule; According to the sub-priority order in the series connection sequence, the corresponding single-dimensional comparators are added to the first-stage comparators step by step; wherein each stage of sub-comparators is activated when the comparison results of the previous stage are equal.
4. The multidimensional data sorting method based on a chain comparator according to claim 1, characterized in that: The method further comprises: When any dimension identifier needs to obtain the comparison value through dynamic calculation, embed the calculation expression in the sub-comparator of the corresponding dimension identifier; The calculation expression is calculated in real time when the comparison operation is executed to generate a temporary cache result, and the temporary cache result is automatically released after the sorting is completed.
5. The multidimensional data sorting method based on chain comparator according to claim 1, characterized in that: Performing a sorting operation on the data set to be sorted using a quick sorting algorithm, specifically including: Performing parallel segmentation on the data set to be sorted to generate multiple data subsets; calling the sub-comparators in the chained comparator in sequence according to the priority order of the dimensional parameter sequence, performing multi-dimensional data element comparison on the multiple data subsets, and determining the size relationship between the data elements; The sorted data subsets are merged and the data subsets are recursively processed until all data elements are sorted.
6. The multidimensional data sorting method based on chain comparator according to claim 1, characterized in that: Verify whether the order of the data dimensions in the sorting result complies with the priority order of the dimension sequence, specifically including: Check whether the number of dimension levels of the output data set in the sorting result is consistent with the number of dimension identifiers in the dimension parameter sequence; In the case of consistent quantities, continue to check whether the dimensional order of adjacent data elements in the output data set conforms to the priority order of the dimensional priority sequence.
7. The multidimensional data sorting method based on chain comparator according to claim 1, characterized in that: The method further comprises: When an invalid dimension parameter is detected during the sorting process, the sorting process is interrupted and a dimension error indicator is returned; When a data element triggers an exception due to a null value, the preset null value processing strategy is called and the sorting is continued; wherein, the null value processing strategy includes: forcing the null value element to be placed before the non-null value element, or forcing the null value element to be placed after the non-null value element.
8. The multidimensional data sorting method based on chain comparator according to claim 1, characterized in that: The method further comprises: Expanding the data set to be sorted into a flat intermediate structure, and assigning an independent dimension identifier to each field in the attribute extraction logic chain; Based on the chain comparator, a sorting operation is performed on the flattened intermediate structure, and the sorted flattened intermediate structure is restored to the original nested hierarchical structure.
9. A multidimensional data sorting device based on a chain comparator, characterized in that: The device comprises: at least one processor; and, a memory communicatively coupled to the at least one processor; The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the multidimensional data sorting method based on a chain comparator as described in any one of claims 1 to 8.
10. A non-volatile computer storage medium storing computer executable instructions, characterized in that: When the computer executable instructions are executed, a multidimensional data sorting method based on a chain comparator according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Sorting method and device for multi-layer nested list and medium
CN118132032A
Sorting operator compiling method and device
CN118259918A
Method and system for implementing instruction ordering in hardware
CN118519741A
Seismic data query method, system and equipment and medium
CN119106030A
Method for designing tree data storage mode in relational database by using preorder traversal
CN119537369A