Socket
Book a DemoInstallSign in
Socket

com.rapid7.presto:presto-query-builder

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.rapid7.presto:presto-query-builder

A Java library that will help you create queries for Presto programmatically. This will help you test your code and create dynamic queries.

0.0.31
Source
mavenMaven
Version published
Maintainers
1
Source

PRESTO-QUERY-BUILDER

This library allows you to programmatically generate queries for Presto to enable dynamically generated queries.

Features:

SELECT

  • Union
  • With
  • Where
  • Order By
  • Group By
  • Join

INSERT

  • Mult-row inserts

DELETE

  • Where

Configuration

None required.

Usage

Select:

QueryFactory qf = new QueryFactory();
String query = qf.build(
    new SelectQueryBuilder(
    ).with(
        "with_table"
    ).select(
        false,
        projection("aliasa", ref("alias.a"))
    ).from(
        aliasedTable("alias", "b")
    ).end(
    ).select(
        false,
        projection("t1a", ref("t1.a")),
        projection("t2aliasa", ref("t2.aliasa"))
    )
    .from(
        aliasedTable("t1", "a")
    )
    .join(
        INNER,
        aliasedTable("t2", "with_table"),
        equal(ref("t1.a"), ref("t2.aliasa"))
    )
);

Insert:

QueryFactory qf = new QueryFactory();
qf.setParam("a", lit(1));
qf.setParam("b", lit(2));
qf.setParam("c", lit(3));

String query = qf.build(
    new InsertQueryBuilder(
    ).into(
        qualifiedName("t1"),
        Arrays.asList(
            identifier("a"),
            identifier("b"),
            identifier("c")
        )
    ).row(
    ).value(
        "a",
        QueryUtils.param(qf, "a")
    ).value(
        "b",
        QueryUtils.param(qf, "b")
    ).value(
        "c",
        QueryUtils.param(qf, "c")
    ).end()
);

Delete:

QueryFactory qf = new QueryFactory();
qf.setParam("a", lit(1));

String query = qf.build(
    new DeleteQueryBuilder(
    ).from(
        table("t")
    ).where(
        equal(ref("a"), QueryUtils.param(qf, "a"))
    )
);

Special Notes

  • Currently, this is pinned to Presto 0.227 but could probably be used with newer versions as well.
  • Most Presto connectors do not support INSERT and/or DELETE operations so the are not very feature rich.
  • Since you can always DELETE then INSERT, UPDATE was not prioritized. However, it's still on the TODO list.

TODO

  • add more tests
  • query builder for update queries

FAQs

Package last updated on 10 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.