Commit ed7b8c51 authored by Ryan Wisnesky's avatar Ryan Wisnesky
Browse files

tweaks

parent 2428d65d
......@@ -31,7 +31,7 @@ command createCsvData = exec_js {
"Java.type(\"catdata.Util\").writeFile(\"eId,is\\n10,0\\n11,1\\n12,2\", \"/Users/ryan/Desktop/Employee.csv\")"
}
instance I0 = import_csv "/Users/ryan/Desktop/" : S0 {
instance I0 = import_csv "file:///Users/ryan/Desktop/" : S0 {
Employee -> {Employee -> eId eAsP -> is eSsn -> is}
//eId -> eId can be ommitted
......@@ -85,7 +85,7 @@ command createCsvData2 = exec_js {
"Java.type(\"catdata.Util\").writeFile(\"ssn,nameOf,Likes\\n0,a,a\\n1,b,\\\"a,b,d\\\"\\n2,c,\\\"\\\"\\n\", \"/Users/ryan/Desktop/Person.csv\")"
}
instance I = import_csv "/Users/ryan/Desktop/" : S {
instance I = import_csv "file:////Users/ryan/Desktop/" : S {
Person -> {
Person -> ssn
name -> nameOf
......
......@@ -12,7 +12,7 @@ public class Null<X> {
@Override
public String toString() {
return "lbl" + x ;
return x.toString() ;
}
@Override
......
......@@ -40,7 +40,7 @@ public class Lineage<Ty,En,Sym,Fk,Att,Gen,Sk> {
@Override
public String toString() {
return "[" + t + " " + i + "]";
return "[" + t + "]";
}
}
......@@ -498,7 +498,7 @@ public class CombinatorParser implements IAqlParser {
.tuple(token("{"), env(ident, "->"), options, token("}")).map(x -> new catdata.Pair<>(x.b, x.c));
Parser<Pair<List<catdata.Pair<LocStr, catdata.Pair<List<catdata.Pair<LocStr, String>>, List<catdata.Pair<String, String>>>>>, List<catdata.Pair<String, String>>>> qs = Parsers
.tuple(env(b, "->"), options).between(token("{"), token("}"));
.tuple(env(b, "->"), options).between(token("{"), token("}")).optional(new Pair<>(new LinkedList<>(), new LinkedList<>()));
Parser<InstExpCsv> ret = Parsers.tuple(token("import_csv"), ident.followedBy(token(":")), sch_ref.lazy(), qs)
.map(x -> new InstExpCsv((SchExp<Ty, En, Sym, Fk, Att>) x.c, x.d.a, x.d.b, x.b));
......
......@@ -2,7 +2,11 @@ package catdata.aql.exp;
import java.io.File;
import java.io.FileReader;
import java.lang.reflect.Field;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
......@@ -60,7 +64,7 @@ public class InstExpCsv
.isEquals();
}
public final String f;
public String f;
private static List<Pair<LocStr, Pair<List<Pair<String, String>>, List<Pair<String, String>>>>> conv(
List<Pair<LocStr, Pair<List<Pair<LocStr, String>>, List<Pair<String, String>>>>> l) {
......@@ -80,7 +84,8 @@ public class InstExpCsv
List<Pair<LocStr, Pair<List<Pair<LocStr, String>>, List<Pair<String, String>>>>> map,
List<Pair<String, String>> options, String f) {
super(schema, conv(map), options);
this.f = f;
this.f = f.endsWith("/") ? f.substring(0, f.length()-1) : f;
}
/*
......@@ -111,7 +116,7 @@ public class InstExpCsv
/**
* Expects filenames in the map
*/
public static Map<En, List<String[]>> start2(Map<String, String> map, AqlOptions op,
public static Map<En, List<String[]>> start2(Map<String, Reader> map, AqlOptions op,
Schema<Ty, En, Sym, Fk, Att> sch, boolean omitCheck) throws Exception {
Character sepChar = (Character) op.getOrDefault(AqlOption.csv_field_delim_char);
Character quoteChar = (Character) op.getOrDefault(AqlOption.csv_quote_char);
......@@ -127,15 +132,17 @@ public class InstExpCsv
throw new RuntimeException("Not an entity: " + k);
}
}
File file = new File(map.get(k));
FileReader fileReader = new FileReader(file);
Reader r = map.get(k);
//File file = new File(map.get(k));
//Reader fileReader = new FileReader(file);
final CSVReader reader = new CSVReaderBuilder(fileReader).withCSVParser(parser)
final CSVReader reader = new CSVReaderBuilder(r).withCSVParser(parser)
.withFieldAsNull(CSVReaderNullFieldIndicator.EMPTY_SEPARATORS).build();
List<String[]> rows = reader.readAll();
fileReader.close();
r.close();
ret.put(new En(k), rows);
}
......@@ -156,16 +163,22 @@ public class InstExpCsv
@Override
protected Map<En, List<String[]>> start(Schema<Ty, En, Sym, Fk, Att> sch) throws Exception {
Map<String, String> m = new HashMap<>();
Map<String, Reader> m = new HashMap<>();
for (En en : sch.ens) {
File file = new File(f, op.getOrDefault(AqlOption.csv_import_prefix) + en.toString() + "."
URL url = new URL(f + "/" + op.getOrDefault(AqlOption.csv_import_prefix) + en.toString() + "."
+ op.getOrDefault(AqlOption.csv_file_extension));
if (file.exists()) {
m.put(en.convert(), file.getAbsolutePath());
} else if (!(boolean) op.getOrDefault(AqlOption.import_missing_is_empty)) {
throw new RuntimeException("Missing file: " + file.getAbsolutePath()
try {
InputStream is = url.openStream();
Reader r = new InputStreamReader(is);
m.put(en.convert(), r);
} catch (Exception ex) {
ex.printStackTrace();
if (!(boolean) op.getOrDefault(AqlOption.import_missing_is_empty)) {
throw new RuntimeException("Missing: " + url
+ ". \n\nPossible options to consider: " + AqlOption.import_missing_is_empty + " and "
+ AqlOption.csv_import_prefix + " and " + AqlOption.csv_file_extension);
}
}
}
return start2(m, op, sch, false);
......
package catdata.aql.exp;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
......@@ -113,11 +116,12 @@ public final class InstExpCsvQuotient<Gen, Sk, X, Y>
Set<Pair<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>>> eqs0 = new HashSet<>(
J.eqs());
Map<String, String> map = new HashMap<>();
for (String q : queries) {
map.put(q, q);
}
try {
Map<String, Reader> map = new HashMap<>();
for (String q : queries) {
map.put(q, new InputStreamReader(new URL(q).openStream()));
}
Map<En, List<String[]>> ret = InstExpCsv.start2(map, strat, J.schema(), true);
for (En q : ret.keySet()) {
......
package catdata.aql.exp;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -73,7 +77,13 @@ public class TransExpCsv<X1,Y1,X2,Y2>
@Override
protected Map<En, List<String[]>> start(Schema<Ty, En, Sym, Fk, Att> sch) throws Exception {
Map<En, List<String[]>> ret = InstExpCsv.start2(map, op, sch, false);
Map<String, Reader> map2 = new HashMap<>();
for (String q : map.keySet()) {
map2.put(q, new InputStreamReader(new URL(map.get(q)).openStream()));
}
Map<En, List<String[]>> ret = InstExpCsv.start2(map2, op, sch, false);
return ret;
}
......
......@@ -48,7 +48,7 @@ public class SigmaChaseAlgebra<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2, Gen, Sk,
throw new RuntimeException("Chase cannot be used: type algebra of input instance is not necessarily free");
}
if (X.schema().typeSide.hasImplicitJavaEqs()) {
throw new RuntimeException("Chase cannot be used: type algebra of input instance uses java functions");
// throw new RuntimeException("Chase cannot be used: type algebra of input instance uses java functions");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment