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

Allow also URLs with additional parameters #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kamir
Copy link

@kamir kamir commented Mar 23, 2017

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
Member

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

@jodersky
Copy link
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
Member

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

@kamir
Copy link
Author

kamir commented Aug 20, 2017 via email

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