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

SIT-1627: Set the app name in the session query tag in JSON format #116

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/main/java/com/snowflake/snowpark_java/SessionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,21 @@ public Session getOrCreate() {
}

/**
* Adds the app name to set in the query_tag after session creation. The query tag will be set
* with this format 'APPNAME=${appName}'.
* Adds the app name to set in the query_tag after session creation.
*
* <p>Since version 1.13.0, the app name is set to the query tag in JSON format. For example:
* <pre>{@code
* Session session = Session.builder().appName("myApp").configFile(myConfigFile).create();
* System.out.println(session.getQueryTag().get());
* {"APPNAME":"myApp"}
* }</pre>
*
* <p>In previous versions it is set using a key=value format. For example:
* <pre>{@code
* Session session = Session.builder().appName("myApp").configFile(myConfigFile).create();
* System.out.println(session.getQueryTag().get());
* APPNAME=myApp
* }</pre>
*
* @param appName Name of the app.
* @return A {@code SessionBuilder} object
Expand Down
18 changes: 16 additions & 2 deletions src/main/scala/com/snowflake/snowpark/Session.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,20 @@ object Session extends Logging {

/**
* Adds the app name to set in the query_tag after session creation.
* The query tag will be set with this format 'APPNAME=${appName}'.
*
* Since version 1.13.0, the app name is set to the query tag in JSON format. For example:
* {{{
* val session = Session.builder.appName("myApp").configFile(myConfigFile).create
* print(session.getQueryTag().get)
* {"APPNAME":"myApp"}
* }}}
*
* In previous versions it is set using a key=value format. For example:
* {{{
* val session = Session.builder.appName("myApp").configFile(myConfigFile).create
* print(session.getQueryTag().get)
* APPNAME=myApp
* }}}
*
* @param appName Name of the app.
* @return A [[SessionBuilder]]
Expand Down Expand Up @@ -1576,7 +1589,8 @@ object Session extends Logging {
val session = createInternal(None)
val appName = this.appName
if (appName.isDefined) {
session.setQueryTag(s"APPNAME=${appName.get}")
val appNameTag = s"""{"APPNAME":"${appName.get}"}"""
session.updateQueryTag(appNameTag)
}
session
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void sessionBuilderConfigs() {
@Test
public void appName() {
String appName = "my-app";
String expectedAppName = String.format("APPNAME=%s", appName);
String expectedAppName = String.format("{\"APPNAME\":\"%s\"}", appName);
Session session = Session.builder().configFile(defaultProfile).appName(appName).create();
assert (expectedAppName.equals(session.getQueryTag().get()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class SessionSuite extends SNTestBase {

test("Set an app name in the query tag") {
val appName = "my_app"
val expectedAppName = s"APPNAME=$appName"
val expectedAppName = s"""{"APPNAME":"$appName"}"""
val newSession = Session.builder.appName(appName).configFile(defaultProfile).create
assert(getParameterValue("query_tag", newSession) == expectedAppName)
}
Expand Down
Loading