PolySem: Efficient Polyglot Analytics on Semantic Data

Xinyu Liu, K. Venkatesh Emani, Avrilia Floratou, Joyce Cahoon, Philip Seamark, Carlo CurinoWorkshops @ VLDB 2023

Introduction

Data engineers invest significant effort in cleaning and modeling data within Business Intelligence (BI) tools to create "semantic data"—datasets where table relationships and business logic are predefined. However, once data enters a BI tool, it often becomes siloed. Analyzing this data using external tools like Python (Pandas) or SQL typically requires exporting raw data, which discards semantic relationships and bypasses the specialized performance of the BI engine. PolySem addresses this "data trapped in BI" problem by providing a polyglot interface that allows users to query data directly within the BI system using their preferred programming languages.

System Architecture

PolySem acts as a middleware layer that bridges the gap between flexible programming languages and the specialized requirements of BI engines. The system's architecture follows a multi-stage translation pipeline designed to move the intent of the code to the data, rather than moving the data to the code.

PolySem Architecture: From multi-modal queries to optimized DAX execution on the SSAS engine.

The pipeline consists of four main stages:

  1. Multi-Modality Input: Users can submit queries in SQL, Python (via Pandas/Ibis), or Natural Language.
  2. Intermediate Representation: All inputs are translated into Substrait, an open-source, language-agnostic intermediate representation for relational algebra.
  3. DAX Translation: A two-pass, bottom-up algorithm converts Substrait plans into Data Analysis Expressions (DAX), the functional language used by Microsoft’s Vertipaq engine.
  4. Execution: The generated DAX is executed directly on the SSAS (SQL Server Analysis Services) engine, leveraging its internal columnar optimizations.

Bridging Languages with Substrait

A key component of PolySem is its use of Substrait as a "lingua franca." By standardizing on a common intermediate representation, the system can support multiple front-end languages without needing a custom translator for every language-to-engine pair. This allows for a modular design where new query modalities can be added with minimal friction.

The translation of a SQL query (Q1) into a logical query plan and subsequently into a Substrait plan.

For Natural Language queries, PolySem employs a Large Language Model (specifically Codex) to generate Python code, which then enters the standard pipeline. This multi-step approach ensures that even complex natural language intents are grounded in a structured relational plan before execution.

Optimization and Performance

Translating logic is only half the battle; DAX is highly sensitive to query structure. PolySem implements specific rewrite rules to ensure high performance. For instance, it optimizes joins using the RELATEDTABLE construct and group-by operations using SUMMARIZECOLUMNS. These "expert" DAX patterns allow the system to leverage the BI engine’s internal columnar optimizations effectively, often making the difference between a query taking seconds versus minutes.

Evaluation using TPC-H and real-world BI datasets (TrainsUK) revealed significant performance gains:

  • Speedups over Pandas: PolySem outperformed Pandas by 2x to 700x on BI benchmarks, primarily by avoiding data egress and utilizing the Vertipaq engine's compressed columnar format.
  • Competitive with DuckDB: While DuckDB generally leads in standard SQL tasks, PolySem was faster in 20% of benchmark queries, particularly those involving specific BI-style patterns where semantic relationships are "baked-in."
  • Impact of Rewrites: Optimized DAX queries ran between 1.8x and 498x faster than non-optimized translations.

Conclusion and Future Work

PolySem demonstrates the power of "in-situ" analytics, maintaining security and avoiding expensive data egress by executing logic directly on the BI engine. Current limitations include limited query coverage (supporting 10 of 22 TPC-H queries) and a performance gap compared to hand-written expert DAX. Future work aims to expand operator support and further refine the auto-generation of complex DAX patterns. Additionally, as LLMs evolve, direct translation from Natural Language to DAX may become feasible, potentially simplifying the pipeline for simpler queries.

Summary updated

BibTeX
@inproceedings{liu2023polysem,
  author = {Xinyu Liu and K. Venkatesh Emani and Avrilia Floratou and Joyce Cahoon and Philip Seamark and Carlo Curino},
  title = {{PolySem: Efficient Polyglot Analytics on Semantic Data}},
  booktitle = {Workshops @ VLDB},
  year = {2023},
}
Figure