Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax Error at of near "unload" #48

Open
dabalakov opened this issue Feb 11, 2019 · 1 comment
Open

Syntax Error at of near "unload" #48

dabalakov opened this issue Feb 11, 2019 · 1 comment

Comments

@dabalakov
Copy link

Hi, I'm trying to get this driver to work in Python, but wanted to test with it in Scala first. I'm unable to get the example on the readme to work.

My build.sbt file looks like:

name := "RedshiftTest"
version := "1.0"
scalaVersion := "2.11.8"
scalacOptions := Seq("-unchecked", "-deprecation", "-feature")
libraryDependencies ++= Seq(
	"jp.ne.opt" %% "redshift-fake-driver" % "1.0.11",
	"org.postgresql" % "postgresql" % "42.2.5",

	// aws sdk
	"com.amazonaws" % "aws-java-sdk" % "1.11.323"
)

and my scala code looks like:

import java.util._
import java.sql._

Class.forName("jp.ne.opt.redshiftfake.postgres.FakePostgresqlDriver")

val endpoint = "http://localhost:9444/" // in production, scheme  will be "s3://"

val url = "jdbc:postgresql://localhost:5439/testdb"
val prop = new Properties()
prop.setProperty("driver", "jp.ne.opt.redshiftfake.postgres.FakePostgresqlDriver")
prop.setProperty("user", "rsdbo")
prop.setProperty("password", "testpass")

val conn = DriverManager.getConnection(url, prop)
val stmt = conn.createStatement()

val unloadSql =
  s"""unload ('select * from tbl') to '${endpoint}foo/unloaded_'
	  |credentials 'aws_access_key_id=AKIAXXXXXXXXXXXXXXX;aws_secret_access_key=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY' 
	  |manifest""".stripMargin
	  
println(unloadSql)
stmt.execute(unloadSql)

The error i'm getting is:

org.postgresql.util.PSQLException: ERROR: syntax error at or near "unload"
  Position: 1
  at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
  at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
  at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
  at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
  at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
  at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:307)
  at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:293)
  at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:270)
  at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:266)
@ocadaruma
Copy link
Collaborator

@dabalakov Thank you for reporting.
I identified the cause.

  1. You have to use jdbc:postgresqredshiftl:// instead of jdbc:postgresql://
  2. You have to specify s3 endpoint via java system property (i.e. -Dfake.awsS3Endpoint="http://localhost:9444/") when you use fake s3 endpoint.
    • current README seems confusing. I will update README later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants