展示HN:我为一个NoSQL数据库构建了一个SQL层
在所有的NoSQL数据库中,DynamoDB是查询起来最令人沮丧的之一。MongoDB拥有一种表达能力强的查询语言。Cassandra有CQL,它与SQL相似,大多数工程师可以很快上手。而DynamoDB则提供了键条件表达式、用于保留字的属性名称占位符,以及一种查询模型,要求你为每次调用手动选择正确的索引。虽然PartiQL存在,但它不支持JOIN、GROUP BY、子查询或大多数ANSI SQL功能。
我开发了DynamoSQL来解决这个问题。
它接受任何ANSI SQL SELECT语句,并将其转换为正确的DynamoDB API调用。最有趣的部分是索引选择:在接收到查询后,系统会检查表上可用的索引,找出最有效的访问模式,并构建调用。当可能时使用分区键查找,当次级索引更合适时使用次级索引,只有在最后的手段才使用扫描。
JOIN是最复杂的部分。DynamoDB本身不支持JOIN,因此在从两个表获取数据后,JOIN操作在客户端执行。支持的SQL功能包括WHERE、所有JOIN类型、GROUP BY、HAVING、ORDER BY、LIMIT、UNION、INTERSECT、EXCEPT、子查询、CTE,以及广泛的聚合和字符串函数。
我们正在寻找测试者。如果你使用DynamoDB并希望对其执行SQL查询,我很想听听你的意见。
<a href="https://dynamosql.com/" rel="nofollow">https://dynamosql.com/</a>
查看原文
Of all the NoSQL databases, DynamoDB is one of the most frustrating to query. MongoDB has an expressive query language. Cassandra has CQL, which is close enough to SQL that most engineers can pick it up quickly. DynamoDB gives you key condition expressions, attribute name placeholders for reserved words, and a query model where you have to pick the right index manually for every call. PartiQL exists but doesn't support JOINs, GROUP BY, subqueries, or most of ANSI SQL.<p>I built DynamoSQL to fix that.<p>It accepts any ANSI SQL SELECT statement and converts it to the right DynamoDB API calls. The interesting part is the index selection: given an incoming query, the system inspects the available indexes on the table, figures out the most efficient access pattern, and constructs the call. Partition key lookup when possible, secondary index when that fits better, scan only as a last resort.<p>JOINs were the most involved part. DynamoDB doesn't support them natively, so they execute client-side after fetching from both tables. The full list of supported SQL includes WHERE, all JOIN types, GROUP BY, HAVING, ORDER BY, LIMIT, UNION, INTERSECT, EXCEPT, subqueries, CTEs, and a wide range of aggregate and string functions.<p>We're looking for beta testers. If you work with DynamoDB and want to run SQL against it, I'd like to hear from you.<p><a href="https://dynamosql.com/" rel="nofollow">https://dynamosql.com/</a>