Skip to content

Commit

Permalink
Set the app name in the session query tag in JSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-fgonzalezmendez committed Jul 1, 2024
1 parent 11031af commit 3b04ae9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
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

0 comments on commit 3b04ae9

Please sign in to comment.