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

Apply Jonathan Bergeron's PR #50 from Github's snowpark-java-scala in a Coveo fork. SEARCHREL-547 #1

Open
wants to merge 4 commits into
base: v1.9.x_main
Choose a base branch
from
Open
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
174 changes: 55 additions & 119 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.snowflake</groupId>
<artifactId>snowpark</artifactId>
<version>1.9.0</version>
<version>1.9.0-coveo-2</version>
<name>${project.artifactId}</name>
<description>Snowflake's DataFrame API</description>
<url>https://www.snowflake.com/</url>
Expand Down Expand Up @@ -443,66 +443,10 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>${scoverage.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>check</goal> <!-- or integration-check -->
</goals>
<phase>prepare-package</phase> <!-- or any other phase -->
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-deploy-artifacts</id>
<phase>package</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.nicoulaj.maven.plugins</groupId>
<artifactId>checksum-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>artifacts</goal>
</goals>
</execution>
</executions>
<configuration>
<algorithms>
<algorithm>SHA-256</algorithm>
<algorithm>md5</algorithm>
</algorithms>
</configuration>
</plugin>

</plugins>

<!-- disable default maven deploy plugin since we are using gpg:sign-and-deploy-file -->
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
Expand All @@ -516,25 +460,6 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>generate-tar-zip</id>
<phase>none</phase>
</execution>
<execution>
<id>with-dependencies</id>
<phase>none</phase>
</execution>
<execution>
<id>fat-test</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<executions>
Expand All @@ -551,52 +476,63 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-deploy-artifacts</id>
<phase>none</phase>
</execution>
<execution>
<id>sign-and-deploy-file</id>
<phase>deploy</phase>
<goals>
<goal>sign-and-deploy-file</goal>
</goals>
<configuration>
<file>target/${project.artifactId}-${project.version}.jar</file>
<repositoryId>ossrh</repositoryId>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
<pomFile>pom.xml</pomFile>
<javadoc>target/${project.artifactId}-${project.version}-javadoc.jar</javadoc>
<keyname>${env.GPG_KEY_ID}</keyname>
<passphrase>${env.GPG_KEY_PASSPHRASE}</passphrase>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<reporting>
<plugins>
<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>${scoverage.plugin.version}</version>
<reportSets>
<reportSet>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>https://maven.cloud.coveo.com/artifactory/libs-release</url>
</repository>
<repository>
<releases>
<enabled>false</enabled>
</releases>
<id>snapshots</id>
<name>libs-snapshot</name>
<url>https://maven.cloud.coveo.com/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>https://maven.cloud.coveo.com/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<releases>
<enabled>false</enabled>
</releases>
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>https://maven.cloud.coveo.com/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>

<distributionManagement>
<repository>
<id>CoveoCloud</id>
<name>CoveoCloud-releases</name>
<url>https://maven.cloud.coveo.com/artifactory/libs-release-local</url>
</repository>
<snapshotRepository>
<id>CoveoCloud</id>
<name>CoveoCloud-snapshots</name>
<url>https://maven.cloud.coveo.com/artifactory/libs-snapshot-local</url>
</snapshotRepository>
<site>
<id>${project.artifactId}</id>
<name>${project.artifactId}</name>
<url>${project.artifactId}/</url>
</site>
</distributionManagement>
</project>
15 changes: 7 additions & 8 deletions src/main/java/com/snowflake/snowpark_java/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static Column toScalar(DataFrame df) {
* @return The result column
*/
public static Column lit(Object literal) {
return new Column(com.snowflake.snowpark.functions.lit(literal));
return new Column(com.snowflake.snowpark.functions.lit(JavaUtils.toScala(literal)));
}

/**
Expand Down Expand Up @@ -2365,14 +2365,13 @@ public static Column regexp_count(Column strExpr, Column pattern) {
*/
public static Column regexp_replace(Column strExpr, Column pattern) {
return new Column(
com.snowflake.snowpark.functions.regexp_replace(
strExpr.toScalaColumn(), pattern.toScalaColumn()));
com.snowflake.snowpark.functions.regexp_replace(
strExpr.toScalaColumn(), pattern.toScalaColumn()));
}

/**
* Returns the subject with the specified pattern (or all occurrences of the pattern)
* replaced by a replacement string. If no matches are found, returns the original
* subject.
* Returns the subject with the specified pattern (or all occurrences of the pattern) replaced by
* a replacement string. If no matches are found, returns the original subject.
*
* @param strExpr The input string
* @param pattern The pattern
Expand All @@ -2382,8 +2381,8 @@ public static Column regexp_replace(Column strExpr, Column pattern) {
*/
public static Column regexp_replace(Column strExpr, Column pattern, Column replacement) {
return new Column(
com.snowflake.snowpark.functions.regexp_replace(
strExpr.toScalaColumn(), pattern.toScalaColumn(), replacement.toScalaColumn()));
com.snowflake.snowpark.functions.regexp_replace(
strExpr.toScalaColumn(), pattern.toScalaColumn(), replacement.toScalaColumn()));
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/main/scala/com/snowflake/snowpark/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,19 @@ object functions {
builtin("regexp_replace")(strExpr, pattern, replacement)


def regexp_extract_all(strExpr: Column,
pattern: Column,
position: Column = lit(1),
occurrence: Column = lit(1),
regex_parameters: Column = lit("c"),
group_num_opt: Option[Column] = None): Column =
builtin("regexp_extract_all")((Seq(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the function used? I do not see usage over this PR.

strExpr,
pattern,
position,
occurrence,
regex_parameters) ++ group_num_opt): _*)

/**
* Removes all occurrences of a specified strExpr,
* and optionally replaces them with replacement.
Expand Down
12 changes: 12 additions & 0 deletions src/main/scala/com/snowflake/snowpark/internal/JavaUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,16 @@ object JavaUtils {
}
}

def toScala(element: Any): Any = {
import collection.JavaConverters._
element match {
case map: java.util.Map[_, _] =>
mapAsScalaMap(map).map {
case (k, v) => toScala(k) -> toScala(v)
}.toMap
case iterable: java.lang.Iterable[_] => iterableAsScalaIterable(iterable).map(toScala)
case iterator: java.util.Iterator[_] => asScalaIterator(iterator).map(toScala)
case _ => element
}
}
}
Loading