Skip to content

Allow also URLs with additional parameters#118

Open
kamir wants to merge 1 commit into
apache:masterfrom
kamir:patch-1
Open

Allow also URLs with additional parameters#118
kamir wants to merge 1 commit into
apache:masterfrom
kamir:patch-1

Conversation

@kamir

@kamir kamir commented Mar 23, 2017

Copy link
Copy Markdown

Not all URLs end with JAR or ZIP, e.g., if we load content from an HTTPFS Service.

Examples for testing: (a,c,d work as expeced) (b => more logic needed to create a JAR name from this URL)

import java.io.{File, PrintStream}
import java.net.URL
import java.nio.file.{Files, Paths}

def getFileFromLocation(location: String): String = {
val url = new URL(location)
val file = url.getFile.split("/")
if (file.length > 0) {
if ( file.last.contains('?') ) {
file.last.split('?')(0)
}
else {
file.last
}
} else {
""
}
}

val fnA = "http://cdsw-mk4-1.gce.cloudera.com:8888/filebrowser/download=/user/systest/TOOLBOX/SparkShellUtilities.jar?user.name=123"
val a = getFileFromLocation(fnA)
a

val fnB = "https://oss.sonatype.org/service/local/artifact/maven/content?r=snapshots&g=org.gephi&a=gephi-toolkit&v=0.9.2-SNAPSHOT&c=all"
val b = getFileFromLocation(fnB)
b

val fnC = "http://cdsw-mk4-1.gce.cloudera.com:8888/filebrowser/download=/user/systest/TOOLBOX/SparkShellUtilities.jar"
val c = getFileFromLocation(fnC)
c

val fnD = "http://cdsw-mk4-1.gce.cloudera.com:8888/filebrowser/download=/user/systest/TOOLBOX/SparkShellUtilities.jar?user.name=123&doas=123456"
val d = getFileFromLocation(fnD)
d

Not all URLs end with JAR or ZIP, e.g., if we load content from an HTTPFS Service.

Examples for testing: (a,c,d work as expeced) (b => more logic needed to create a JAR name from this URL)

import java.io.{File, PrintStream}
import java.net.URL
import java.nio.file.{Files, Paths}

def getFileFromLocation(location: String): String = {
    val url = new URL(location)
    val file = url.getFile.split("/")
    if (file.length > 0) {
        if ( file.last.contains('?') ) {
          file.last.split('?')(0)
        }
        else { 
          file.last
        }  
    } else {
        ""
    }
  }

val fnA = "http://cdsw-mk4-1.gce.cloudera.com:8888/filebrowser/download=/user/systest/TOOLBOX/SparkShellUtilities.jar?user.name=123"
val a = getFileFromLocation(fnA)
a
  
val fnB = "https://oss.sonatype.org/service/local/artifact/maven/content?r=snapshots&g=org.gephi&a=gephi-toolkit&v=0.9.2-SNAPSHOT&c=all"
val b = getFileFromLocation(fnB)
b

val fnC = "http://cdsw-mk4-1.gce.cloudera.com:8888/filebrowser/download=/user/systest/TOOLBOX/SparkShellUtilities.jar"
val c = getFileFromLocation(fnC)
c
  
val fnD = "http://cdsw-mk4-1.gce.cloudera.com:8888/filebrowser/download=/user/systest/TOOLBOX/SparkShellUtilities.jar?user.name=123&doas=123456"
val d = getFileFromLocation(fnD)
d
@lresende

Copy link
Copy Markdown
Member

@kamir Could you please update AddJarSpec.scala with some tests that validate your additions.

@jodersky

Copy link
Copy Markdown
Member

Welcome @kamir! Thanks for finding this bug and working on a fix. Check out this documentation on URL https://docs.oracle.com/javase/7/docs/api/java/net/URL.html#getFile(), I think a simpler fix is to just change the "getFile" part above to "getPath"

@lresende

Copy link
Copy Markdown
Member

@kamir Could you please rebase and add a test case to the enhancements you are making.

@kamir

kamir commented Aug 20, 2017 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants