Giter VIP home page Giter VIP logo

coral's Introduction

Coral

Coral is a SQL translation, analysis, and rewrite engine. It establishes a standard intermediate representation, Coral IR, which captures the semantics of relational algebraic expressions independently of any SQL dialect. Coral IR is defined in two forms: one is the at the abstract syntax tree (AST) layer, and the other is at the logical plan layer. Both forms are isomorphic and convertible to each other.

Coral exposes APIs for implementing conversions between SQL dialects and Coral IR in both directions. Currently, Coral supports converting HiveQL and Spark SQL to Coral IR, and converting Coral IR to HiveQL, Spark SQL, and Trino SQL. With multiple SQL dialects supported, Coral can be used to translate SQL statements and views defined in one dialect to equivalent ones in another dialect. It can also be used to interoperate between engines and SQL-powered data sources. For dialect conversion examples, see the modules coral-hive, coral-spark, and coral-trino.

Coral also exposes APIs for Coral IR rewrite and manipulation. This includes rewriting Coral IR expressions to produce semantically equivalent, but more performant expressions. For example, Coral automates incremental view maintenance by rewriting a view definition to an incremental one. See the module coral-incremental for more details. Other Coral rewrite applications include data governance and policy enforcement.

Coral can be used as a library in other projects, or as a service. See instructions below for more details.

Slack

  • Join the discussion with the community on Slack here!

Modules

Coral consists of following modules:

  • Coral-Hive: Converts HiveQL to Coral IR (can be typically used with Spark SQL as well).
  • Coral-Trino: Converts Coral IR to Trino SQL. Converting Trino SQL to Coral IR is WIP.
  • Coral-Spark: Converts Coral IR to Spark SQL (can be typically used with HiveQL as well).
  • Coral-Dbt: Integrates Coral with DBT. It enables applying Coral transformations on DBT models.
  • Coral-Incremental: Derives an incremental query from input SQL for incremental view maintenance.
  • Coral-Schema: Derives Avro schema of view using view logical plan and input Avro schemas of base tables.
  • Coral-Spark-Plan [WIP]: Converts Spark plan strings to equivalent logical plan.
  • Coral-Visualization: Visualizes Coral SqlNode and RelNode trees and renders them to an output file.
  • Coral-Service: Service that exposes REST APIs that allow users to interact with Coral (see Coral-as-a-Service for more details).

Version Upgrades

This project adheres to semantic versioning, where the format x.y.z represents major, minor, and patch version upgrades. Consideration should be given to potential changes required when integrating different versions of this project.

Major version Upgrade

A major version upgrade represents a version change that introduces backward incompatibility by removal or renaming of classes.

Minor version Upgrade

A minor version upgrade represents a version change that introduces backward incompatibility by removal or renaming of methods.

Please carefully review the release notes and documentation accompanying each version upgrade to understand the specific changes and the recommended steps for migration.

How to Build

Clone the repository:

git clone https://github.com/linkedin/coral.git

Build:

./gradlew clean build

Please note that this project requires Python 3 and Java 8 to run. Either set JAVA_HOME to the home of an appropriate version and then use ./gradlew clean build as described above, or set the org.gradle.java.home gradle property to the Java home of an appropriate version as below:

./gradlew -Dorg.gradle.java.home=/path/to/java/home clean build

Contributing

The project is under active development and we welcome contributions of different forms. Please see the Contribution Agreement.

Resources

Coral-as-a-Service

Coral-as-a-Service or simply, Coral Service is a service that exposes REST APIs that allow users to interact with Coral without necessarily coming from a compute engine. Currently, the service supports an API for query translation between different dialects and another for interacting with a local Hive Metastore to create example databases, tables, and views so they can be referenced in the translation API. The service can be used in two modes: remote Hive Metastore mode, and local Hive Metastore mode. The remote mode uses an existing (already deployed) Hive Metastore to resolve tables and views, while the local one creates an empty embedded Hive Metastore so users can add their own table and view definitions.

API Reference

/api/translations/translate

A POST API which takes JSON request body containing following parameters and returns the translated query:

  • fromLanguage: Input dialect (e.g., spark, trino, hive -- see below for supported inputs)
  • toLanguage: Output dialect (e.g., spark, trino, hive -- see below for supported outputs)
  • query: SQL query to translate between two dialects

/api/catalog-ops/execute

A POST API which takes a SQL statement to create a database/table/view in the local metastore (note: this endpoint is only available with Coral Service in local metastore mode).

Instructions to use with examples

  1. Clone Coral repo
git clone https://github.com/linkedin/coral.git  
  1. From the root directory of Coral, access the coral-service module
cd coral-service  
  1. Build
../gradlew clean build  

To run Coral Service using the local metastore:

  1. Run
../gradlew bootRun --args='--spring.profiles.active=localMetastore'  

To run Coral Service using the remote metastore:

  1. Add your kerberos client keytab file to coral-service/src/main/resources
  2. Appropriately replace all instances of SET_ME in coral-service/src/main/resources/hive.properties
  3. Run
../gradlew bootRun  

You can also specify a custom location of hive.properties file through --hivePropsLocation as follows

 ./gradlew bootRun --args='--hivePropsLocation=/tmp/hive.properties'

Then you can interact with the service using your browser or the CLI.

Coral Service UI

After running ../gradlew bootRun --args='--spring.profiles.active=localMetastore' (for local metastore mode) or ../gradlew bootRun (for remote metastore mode) from coral-service module, the UI can be accessed from the browser. Use the URL http://localhost:8080 to run the UI on a local browser.

The UI provides 2 features:

Create a database/table/view in local metastore mode

This feature is only available with Coral Service in local metastore mode, it calls /api/catalog-ops/execute API above.

You can enter a SQL statement to create a database/table/view in the local metastore:

Translate SQL from source language to target language

This feature is available with Coral Service in both local and remote metastore modes, it calls /api/translations/translate API above.

You can enter a SQL query and specify the source and target language to use Coral translation service:

Coral Service CLI

Apart from the UI above, you can also interact with the service using the CLI.

Example workflow for local metastore mode:

  1. Create a database called db1 in local metastore using the /api/catalog-ops/execute endpoint
curl --header "Content-Type: application/json" \
  --request POST \
  --data "CREATE DATABASE IF NOT EXISTS db1" \
  http://localhost:8080/api/catalog-ops/execute

Creation successful
  1. Create a table called airport within db1 in local metastore using the /api/catalog-ops/execute endpoint
curl --header "Content-Type: application/json" \
  --request POST \
  --data "CREATE TABLE IF NOT EXISTS db1.airport(name string, country string, area_code int, code string, datepartition string)" \
  http://localhost:8080/api/catalog-ops/execute

Creation successful
  1. Translate a query on db1.airport in local metastore using the /api/translations/translate endpoint
curl --header "Content-Type: application/json" \
  --request POST \
  --data '{
    "fromLanguage":"hive", 
    "toLanguage":"trino", 
    "query":"SELECT * FROM db1.airport"
  }' \
  http://localhost:8080/api/translations/translate

The translation result is:

Original query in HiveQL:
SELECT * FROM db1.airport
Translated to Trino SQL:
SELECT "name", "country", "area_code", "code", "datepartition"
FROM "db1"."airport"

Currently Supported Translation Flows

  1. Hive to Trino
  2. Hive to Spark
  3. Trino to Spark
    Note: During Trino to Spark translations, views referenced in queries are considered to be defined in HiveQL and hence cannot be used when translating a view from Trino. Currently, only referencing base tables is supported in Trino queries. This translation path is currently a POC and may need further improvements.

coral's People

Contributors

ljfgem avatar antumbde avatar funcheetah avatar aastha25 avatar wmoustafa avatar shipkit-org avatar kxu1026 avatar hotsushi avatar rzhang10 avatar findepi avatar khaitranq avatar autumnust avatar shardulm94 avatar uzshao avatar ebyhr avatar aliceyeh12 avatar cwsteinbach avatar jongn avatar losipiuk avatar 770120041 avatar huangxiaopingrd avatar nagarathnam200 avatar yiqiangin avatar sherryhli avatar kevinge00 avatar jiajunbernoulli avatar maluchari avatar findinpath avatar mockitoguy avatar wenruimeng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.