Skip to content

Commit

Permalink
Update linting
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-evandenberg committed Oct 30, 2024
1 parent e565db0 commit e7d8b99
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/snowflake/snowpark_java/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ public DataFrame sql(String query) {
* @since 0.8.0
*/
public DataFrame sql(String query, Object... params) {
return new DataFrame(
session.sql(query, JavaUtils.objectArrayToSeq(params)));
return new DataFrame(session.sql(query, JavaUtils.objectArrayToSeq(params)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ private[snowpark] class ServerConnection(
true,
false,
getStatementParameters(isDDLOnTempObject = false, Map.empty),
Seq.empty
).rows.get
Seq.empty).rows.get
.map(r =>
r.getString(0).toLowerCase() + PackageNameDelimiter + r.getString(1).toLowerCase())
.toSet
Expand All @@ -298,7 +297,7 @@ private[snowpark] class ServerConnection(
statement: PreparedStatement,
params: Seq[Any]): Unit =
params.zipWithIndex.foreach {
case (p, i) => statement.setObject(i + 1, p)
case (p, i) => statement.setObject(i + 1, p)
}

private[snowflake] def setStatementParameters(
Expand Down Expand Up @@ -883,7 +882,8 @@ private[snowpark] class ServerConnection(
val statement = connection.prepareStatement(multipleStatements)
try {
// Note binding parameters only supported for single query
val bindingParameters = if (plan.queries.length == 1) plan.queries.last.params else Seq()
val bindingParameters =
if (plan.queries.length == 1) plan.queries.last.params else Seq()
val statementParameters = getStatementParameters() +
("MULTI_STATEMENT_COUNT" -> plan.queries.size)
setBindingParameters(statement, bindingParameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ class SnowflakePlanBuilder(session: Session) extends Logging {
selectLeft.queries.slice(0, selectLeft.queries.length - 1) ++
selectRight.queries.slice(0, selectRight.queries.length - 1) :+ Query(
sqlGenerator(lastQueryLeft.sql, lastQueryRight.sql),
lastQueryLeft.params ++ lastQueryRight.params
)
lastQueryLeft.params ++ lastQueryRight.params)
val leftSchemaQuery = schemaValueStatement(selectLeft.attributes)
val rightSchemaQuery = schemaValueStatement(selectRight.attributes)
val schemaQuery = sqlGenerator(leftSchemaQuery, rightSchemaQuery)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import com.snowflake.snowpark_java.types.StructField;
import com.snowflake.snowpark_java.types.StructType;
import java.sql.Connection;
import java.util.Arrays;

import net.snowflake.client.jdbc.SnowflakeConnection;
import org.junit.Test;

Expand Down Expand Up @@ -67,13 +65,11 @@ public void generator() {
public void sql() {
checkAnswer(
getSession().sql("select * from values(1, 2),(3, 4) as t(a, b)"),
new Row[] {Row.create(1, 2), Row.create(3, 4)}
);
new Row[] {Row.create(1, 2), Row.create(3, 4)});

checkAnswer(
getSession().sql("select * from values(?, ?),(?, ?) as t(a, b)", 1, 2, 3, 4),
new Row[] {Row.create(1, 2), Row.create(3, 4)}
);
new Row[] {Row.create(1, 2), Row.create(3, 4)});
}

@Test
Expand Down
12 changes: 6 additions & 6 deletions src/test/scala/com/snowflake/snowpark_test/SqlSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ trait SqlSuite extends SNTestBase {
}
}


test("Run sql query with bindings") {
val df1 = session.sql("select * from values (?),(?),(?)", List(1, 2, 3))
assert(df1.collect() sameElements Array[Row](Row(1), Row(2), Row(3)))
Expand All @@ -121,10 +120,10 @@ trait SqlSuite extends SNTestBase {
.filter(col("id") < 3)
assert(df3.collect() sameElements Array[Row](Row(1), Row(2)))

val df4 = session.sql("select * from values (?,?),(?,?),(?,?) as T(a, b)", Seq(1, 1, 2, 1, 3, 1))
val df5 = session.sql(
"select * from values (?,?),(?,?),(?,?) as T(a, b)",
List(1, 2, 2, 1, 4, 3))
val df4 =
session.sql("select * from values (?,?),(?,?),(?,?) as T(a, b)", Seq(1, 1, 2, 1, 3, 1))
val df5 =
session.sql("select * from values (?,?),(?,?),(?,?) as T(a, b)", List(1, 2, 2, 1, 4, 3))
val df6 = df4.union(df5).filter(col("a") < 3)
assert(df6.collect() sameElements Array[Row](Row(1, 1), Row(2, 1), Row(1, 2)))

Expand All @@ -133,7 +132,8 @@ trait SqlSuite extends SNTestBase {

// Async result
assert(df1.async.collect().getResult() sameElements Array[Row](Row(1), Row(2), Row(3)))
assert(df6.async.collect().getResult() sameElements Array[Row](Row(1, 1), Row(2, 1), Row(1, 2)))
assert(
df6.async.collect().getResult() sameElements Array[Row](Row(1, 1), Row(2, 1), Row(1, 2)))
}
}

Expand Down

0 comments on commit e7d8b99

Please sign in to comment.