diff --git a/src/main/java/com/snowflake/snowpark_java/SessionBuilder.java b/src/main/java/com/snowflake/snowpark_java/SessionBuilder.java index 1e9c2c49..330e9f87 100644 --- a/src/main/java/com/snowflake/snowpark_java/SessionBuilder.java +++ b/src/main/java/com/snowflake/snowpark_java/SessionBuilder.java @@ -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. + * + *

Since version 1.13.0, the app name is set to the query tag in JSON format. For example: + *

{@code
+   * Session session = Session.builder().appName("myApp").configFile(myConfigFile).create();
+   * System.out.println(session.getQueryTag().get());
+   * {"APPNAME":"myApp"}
+   * }
+ * + *

In previous versions it is set using a key=value format. For example: + *

{@code
+   * Session session = Session.builder().appName("myApp").configFile(myConfigFile).create();
+   * System.out.println(session.getQueryTag().get());
+   * APPNAME=myApp
+   * }
* * @param appName Name of the app. * @return A {@code SessionBuilder} object diff --git a/src/main/scala/com/snowflake/snowpark/Session.scala b/src/main/scala/com/snowflake/snowpark/Session.scala index 2b6c580d..90f7b83e 100644 --- a/src/main/scala/com/snowflake/snowpark/Session.scala +++ b/src/main/scala/com/snowflake/snowpark/Session.scala @@ -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]] @@ -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 } diff --git a/src/test/java/com/snowflake/snowpark_test/JavaSessionNonStoredProcSuite.java b/src/test/java/com/snowflake/snowpark_test/JavaSessionNonStoredProcSuite.java index e651c948..04cd7822 100644 --- a/src/test/java/com/snowflake/snowpark_test/JavaSessionNonStoredProcSuite.java +++ b/src/test/java/com/snowflake/snowpark_test/JavaSessionNonStoredProcSuite.java @@ -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())); } diff --git a/src/test/scala/com/snowflake/snowpark_test/SessionSuite.scala b/src/test/scala/com/snowflake/snowpark_test/SessionSuite.scala index 3a4a2dbc..4713ea66 100644 --- a/src/test/scala/com/snowflake/snowpark_test/SessionSuite.scala +++ b/src/test/scala/com/snowflake/snowpark_test/SessionSuite.scala @@ -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) }