Atitit. Design of data Manipulation DSL---LINQ scenarios

Source: Internet
Author: User
Tags stream api

Atitit. Data Manipulation DSL the design ---LINQ Programme

1 . 1. SQL and API mode 1

1 . 2. the Linq scheme and the stream scheme are selected, 1

1 . 3. prefix-expression vs infix-expression 1

1 . 4. do you want the string delimiter 1

1 . 5. compatible with SQL standards as much as possible 2

1 . 6. support for multiple data sources 2

1 . 7. Conclusion 2

1 . 8. The final result is as follows 2

1.1. SQL and API mode

For data operations, the two commonly used scenarios SQL and API ,the API is also divided into the LINQ scheme and stream scheme:

One is their comparative principle, with human readability as a priority. SQL the readability is the strongest, single his machine readability is the worst ... the Api approach is the opposite, easy to parse, sacrificing some human readability in exchange for convenient machine parsing.

the parsing of SQL is difficult and is not suitable for direct use as a DSL . Of course, if the data source is a database, has implemented the SQL parsing, you can use SQL as a DSL to use. If it is another data source such as list, you can implement SQL to query the list, it is more troublesome.

1.2. the Linq scheme and the stream scheme are selected,

LINQ is a Special column of stream. A specialized DSLthat is more readable and SQL-like, while SQL is almost a standard for real-world operations DSL , it is better to conform to the standard, easy to learn. In most cases, LINQ should be used :

Part of the common data structure that can be used withthe stream API, thestream API has a more flexible and simple operation can be done for specific operations.

Author :: ★ (Attilax) >>>    nickname : old Wow's paw   (   full name:: ATTILAX AKBAR AL RAPANUI  Attilax   Baroque   Alpha   Rapa Nui   )   Kanji name: Ayron, Email:[email protected]

reprint Please indicate source: http://www.cnblogs.com/attilax/

1.3. prefix-expression vs infix-expression

There are two implementations of Linq, one of which is the API prefix expression pattern, which is easy to parse and slightly less readable. Api infix expression, easy to parse, readable, but, the workload of such patterns is huge, the general use of machine generation, will bring synchronization maintenance problems, give up.

1.4. do you want the string delimiter

SQL uses a single preference as a string delimiter, and other programming languages use double quotation marks, but with a troublesome problem.

In view of the readability, as well as the need for machine parsing, anyway, and the very small unit expression of the division, easy to parse, there is no string delimiter.

1.5. compatible with SQL standards as much as possible

1.6. support for multiple data sources

Memory data , String,list ,cache,nosql, file, Excel, database, and so on can use LINQ to query and manipulate

1.7. Conclusion

So the tradeoff is that human readability is a priority, but the simplicity of development is guaranteed. The final good solution is to use the API function pattern from where in the large operation , but the conditional expression inside uses SQL Pattern of text infix expression pattern, convenient for machine parsing.

1.8. Event Initiation Plan:

Guys, let's get together and make a LINQ , our goal:

--- support for multiple data sources: Memory data , String,list ,cache,NoSQL , files,Excel, databases, etc. can be queried and manipulated using LINQ

Implementation of the idea: the LINQ inside the expression of simple lexical analysis, converted to the entire API Function-type prefix expression structure. Build the ast, and then perform the parsing. Can..

1.9. The final result is as follows

List list=listutil.addmapfromstr ("name: Li Ming , age:11"). Addmapfromstr ("name: Philip , age:17"). ToList ();

list<map> result_list= Select ("Name,age"). from (list). WHERE ("name= Li Ming "). and ("age>12")."name,age desc");

Implementation of the idea: the LINQ inside the expression of simple lexical analysis, converted to the entire API Function-type prefix expression structure. Build the ast, and then perform the parsing. Can..

Atitit. Design of data Manipulation DSL---LINQ scenarios

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.