All Projects → zaneli → scalikejdbc-athena

zaneli / scalikejdbc-athena

Licence: Apache-2.0 license
Library for using Amazon Athena JDBC Driver with ScalikeJDBC

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to scalikejdbc-athena

Aws Data Wrangler
Pandas on AWS - Easy integration with Athena, Glue, Redshift, Timestream, QuickSight, Chime, CloudWatchLogs, DynamoDB, EMR, SecretManager, PostgreSQL, MySQL, SQLServer and S3 (Parquet, CSV, JSON and EXCEL).
Stars: ✭ 2,385 (+12452.63%)
Mutual labels:  athena, amazon-athena
athena-sqlite
A SQLite driver for S3 and Amazon Athena 😳
Stars: ✭ 82 (+331.58%)
Mutual labels:  athena, amazon-athena
Redash
Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data.
Stars: ✭ 20,147 (+105936.84%)
Mutual labels:  athena
ddd-repository-example
ScalikeJDBC example for Domain Driven Design Repository implementation.
Stars: ✭ 24 (+26.32%)
Mutual labels:  scalikejdbc
analyzing-reddit-sentiment-with-aws
Learn how to use Kinesis Firehose, AWS Glue, S3, and Amazon Athena by streaming and analyzing reddit comments in realtime. 100-200 level tutorial.
Stars: ✭ 40 (+110.53%)
Mutual labels:  amazon-athena
AWR.Athena
Short R Wrapper for Athena JDBC connections
Stars: ✭ 23 (+21.05%)
Mutual labels:  athena
rds-snapshot-export-to-s3-pipeline
RDS Snapshot Export to S3 Pipeline
Stars: ✭ 88 (+363.16%)
Mutual labels:  athena
bandar-log
Monitoring tool to measure flow throughput of data sources and processing components that are part of Data Ingestion and ETL pipelines.
Stars: ✭ 20 (+5.26%)
Mutual labels:  athena
Hello-AWS-Data-Services
Sample code for AWS data service and ML courses on LinkedIn Learning
Stars: ✭ 144 (+657.89%)
Mutual labels:  athena
noctua
Connect R to Athena using paws SDK (DBI Interface)
Stars: ✭ 35 (+84.21%)
Mutual labels:  athena
aws-usage-queries
This application bootstraps everything needed to query the AWS Cost and Usage reports through Amazon Athena. It also includes reference data and preconfigured SQL queries.
Stars: ✭ 28 (+47.37%)
Mutual labels:  amazon-athena
scalikejdbc-bigquery
ScalikeJDBC extension for Google BigQuery
Stars: ✭ 18 (-5.26%)
Mutual labels:  scalikejdbc
athenai
Have fun with Amazon Athena from command line! 🕊
Stars: ✭ 36 (+89.47%)
Mutual labels:  athena
Cube.js
📊 Cube — Open-Source Analytics API for Building Data Apps
Stars: ✭ 11,983 (+62968.42%)
Mutual labels:  athena
metis
Helpers for Accessing and Querying Amazon Athena using R, Including a lightweight RJDBC shim
Stars: ✭ 18 (-5.26%)
Mutual labels:  athena
qwery
A SQL-like language for performing ETL transformations.
Stars: ✭ 28 (+47.37%)
Mutual labels:  athena
athenadriver
A fully-featured AWS Athena database driver (+ athenareader https://github.com/uber/athenadriver/tree/master/athenareader)
Stars: ✭ 116 (+510.53%)
Mutual labels:  athena
scalikejdbc-play-support
Play Framework support
Stars: ✭ 55 (+189.47%)
Mutual labels:  scalikejdbc
hello-scalikejdbc
Lightbend Activator Template for ScalikeJDBC Beginners
Stars: ✭ 64 (+236.84%)
Mutual labels:  scalikejdbc
Athena
Test your Security Skills, and Clean Code Development as a Pythonist, Hacker & Warrior 🥷🏻
Stars: ✭ 43 (+126.32%)
Mutual labels:  athena

scalikejdbc-athena

Library for using Amazon Athena JDBC Driver with ScalikeJDBC

CI Status

setup

> mkdir lib
> curl -L -O https://s3.amazonaws.com/athena-downloads/drivers/JDBC/SimbaAthenaJDBC_2.0.7/AthenaJDBC41_2.0.7.jar
> mv AthenaJDBC41_2.0.7.jar lib/
  • Add library dependencies to sbt build settings
libraryDependencies ++= Seq(
  "org.scalikejdbc" %% "scalikejdbc" % "3.4.0",
  "com.zaneli" %% "scalikejdbc-athena" % "0.2.4"
)
  • Configure the JDBC Driver Options on resources/application.conf
athena {
  default {
    driver="com.simba.athena.jdbc.Driver"
    url="jdbc:awsathena://AwsRegion={REGION}"
    readOnly="false"
    S3OutputLocation="s3://query-results-bucket/folder/"
    AwsCredentialsProviderClass="com.simba.athena.amazonaws.auth.profile.ProfileCredentialsProvider"
    LogPath="logs/application.log"
    LogLevel=3
  }
}

If you need to update partitions etc., set readOnly="false"

Usage

Run query

import scalikejdbc._
import scalikejdbc.athena._

val name = "elb_demo_001"
DB.athena { implicit s =>
  val r = sql"""
          |SELECT * FROM default.elb_logs_raw_native
          |WHERE elb_name = $name LIMIT 10;
         """.stripMargin.map(_.toMap).list.apply()
  r.foreach(println)
}

Delete S3OutputLocation after run query

  • set S3OutputLocationPrefix instead of S3OutputLocation
athena {
  default {
    driver="com.simba.athena.jdbc.Driver"
    url="jdbc:awsathena://AwsRegion={REGION}"
    readOnly="false"
    S3OutputLocationPrefix="s3://query-results-bucket/folder"
    AwsCredentialsProviderClass="com.simba.athena.amazonaws.auth.profile.ProfileCredentialsProvider"
    LogPath="logs/application.log"
    LogLevel=3
  }
}
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.s3.model.DeleteObjectsRequest

import scalikejdbc._
import scalikejdbc.athena._

import scala.collection.JavaConverters._

val s3Client = AmazonS3ClientBuilder.standard().withCredentials(new ProfileCredentialsProvider()).build()
val regex = """s3://(.+?)/(.+)""".r

DB.athena { implicit s =>
  val r = sql"...".map(_.toMap).list.apply()
  r.foreach(println)

  s.getTmpStagingDir.foreach { // Some("s3://query-results-bucket/folder/${java.util.UUID.randomUUID}")
    case regex(bucketName, path) =>
      val keys = s3Client.listObjects(bucketName, path).getObjectSummaries.asScala
        .map(s => new DeleteObjectsRequest.KeyVersion(s.getKey))
      if (keys.nonEmpty) {
        val delReq = new DeleteObjectsRequest(bucketName)
        delReq.setKeys(keys.asJava)
        s3Client.deleteObjects(delReq)
      }
  }
}

scalikejdbc-athena is inspired by scalikejdbc-bigquery.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].