-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package fr.insee.trevas.jupyter; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Utils { | ||
|
||
public static String getURL(String path) { | ||
return path.split("\\?")[0]; | ||
} | ||
|
||
public static Map<String, String> getQueryMap(String path) { | ||
if (path == null || !path.contains("\\?")) { | ||
return Map.of(); | ||
} | ||
String[] params = path.split("\\?")[1].split("&"); | ||
Map<String, String> map = new HashMap<>(); | ||
|
||
for (String param : params) { | ||
String name = param.split("=")[0]; | ||
String value = param.split("=")[1]; | ||
map.put(name, value); | ||
} | ||
return map; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import fr.insee.trevas.jupyter.SparkUtils; | ||
import fr.insee.vtl.model.Dataset; | ||
import org.apache.spark.sql.SparkSession; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class CSVTest { | ||
|
||
private SparkSession spark; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
spark = SparkSession.builder() | ||
.appName("test") | ||
.master("local") | ||
.getOrCreate(); | ||
} | ||
|
||
@Test | ||
public void readCSVDatasetTest() throws Exception { | ||
Dataset ds1 = SparkUtils.readCSVDataset(spark, "src/test/resources/ds1.csv"); | ||
assertThat(ds1.getDataPoints().get(1).get("name")).isEqualTo("B"); | ||
Dataset ds2 = SparkUtils.readCSVDataset(spark, "src/test/resources/ds2.csv?sep=\"|\"&delimiter=\"\""); | ||
assertThat(ds2.getDataPoints().get(1).get("name")).isEqualTo("B"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"id";"name" | ||
"1";"A" | ||
"2";"B" | ||
"3";"C" | ||
"4";"D" | ||
"5";"E" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
id|name | ||
6|F | ||
7|G | ||
8|H | ||
9|I | ||
10|J |