Skip to content

Commit

Permalink
changes for sql null handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Wisnesky committed Oct 20, 2024
1 parent 2fc64bd commit 4ecf870
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 33 deletions.
7 changes: 4 additions & 3 deletions src/catdata/cql/Algebra.java
Original file line number Diff line number Diff line change
Expand Up @@ -712,15 +712,16 @@ public synchronized void storeMyRecord(boolean emitIds, List<String> hdrQ, List<
}


private Map<Y, Integer> forSql = new HashMap<>();
//private Map<Y, Integer> forSql = new HashMap<>();
private Object fromTerm(int sqlty, Term<Ty, Void, Sym, Void, Void, Void, Y> term) {
if (term.obj() != null) {
Optional<?> o = (Optional<?>) term.obj();
if (o.isPresent()) {
return o.get();
}
}
if (sqlty == Types.VARCHAR || sqlty == Types.LONGVARCHAR || sqlty == Types.NVARCHAR) {
// System.out.println("ret null");
/* if (sqlty == Types.VARCHAR || sqlty == Types.LONGVARCHAR || sqlty == Types.NVARCHAR) {
if (term.sk() != null) {
if (forSql.containsKey(term.sk())) {
return "?" + forSql.get(term.sk());
Expand All @@ -729,7 +730,7 @@ private Object fromTerm(int sqlty, Term<Ty, Void, Sym, Void, Void, Void, Y> term
return "?" + forSql.get(term.sk());
}
}
}
} */
return null;
}

Expand Down
10 changes: 6 additions & 4 deletions src/catdata/cql/SqlTypeSide.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,10 @@ public static Optional<Boolean> not(Optional<Boolean> x) {
}

public static Pair<List<String>, String> boolSort = new Pair<>(Collections.emptyList(), "Boolean");
public static Sym t = Sym.Sym("true", boolSort);
public static Sym f = Sym.Sym("false", boolSort);

//todo: change to obj
public static Term<String, Void, Sym, Void, Void, Void, Void> t = Term.Obj(Optional.of(true), "Boolean");
public static Term<String, Void, Sym, Void, Void, Void, Void> f = Term.Obj(Optional.of(false), "Boolean");
public static Sym n = Sym.Sym("null", boolSort);

public static Pair<List<String>, String> boolSort1 = new Pair<>(Collections.singletonList("Boolean"), "Boolean");
Expand Down Expand Up @@ -490,8 +492,8 @@ public static Constraints makeEds(Schema<String, String, Sym, Fk, Att> schT, Aql
String x = ("x");
String y = ("y");
String z = ("z");
Term<String, String, Sym, Fk, Att, Void, Void> t = Term.Sym(SqlTypeSide.t, Collections.emptyList());
Term<String, String, Sym, Fk, Att, Void, Void> f = Term.Sym(SqlTypeSide.f, Collections.emptyList());
Term<String, String, Sym, Fk, Att, Void, Void> t = SqlTypeSide.t.convert();
Term<String, String, Sym, Fk, Att, Void, Void> f = SqlTypeSide.f.convert();

List<Term<String, String, Sym, Fk, Att, Void, Void>> lxx = new ArrayList<>(2);
lxx.add(Term.Var(x));
Expand Down
10 changes: 5 additions & 5 deletions src/catdata/cql/SqlTypeSide2.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public synchronized TypeSide<Ty, Sym> make(TypeSide<Ty, Sym> parent, AqlOptions
Collections.emptyMap(), ops);
}

public static final Sym TRUE_SYM = SqlTypeSide.t, FALSE_SYM = SqlTypeSide.f,
public static final Sym /*TRUE_SYM = null , FALSE_SYM = null/*SqlTypeSide.f, */
NOT_SYM = Sym.Sym("not", SqlTypeSide.boolSort1), IS_TRUE_SYM = Sym.Sym("isTrue", SqlTypeSide.boolSort1),
IS_FALSE_SYM = Sym.Sym("isFalse", SqlTypeSide.boolSort1), AND_SYM = Sym.Sym("and", SqlTypeSide.boolSort2),
OR_SYM = Sym.Sym("or", SqlTypeSide.boolSort2);
Expand Down Expand Up @@ -102,8 +102,8 @@ public boolean addSym(TypeSide<Ty, Sym> ts, Sym sym, List<Ty> dom, Ty cod) {
private synchronized Map<Sym, Pair<List<Ty>, Ty>> syms(TypeSide<Ty, Sym> parent) {
Map<Sym, Pair<List<Ty>, Ty>> m = Util.mk();
m.putAll(parent.syms);
m.put(TRUE_SYM, new Pair<>(Collections.emptyList(), boolTy));
m.put(FALSE_SYM, new Pair<>(Collections.emptyList(), boolTy));
// m.put(TRUE_SYM, new Pair<>(Collections.emptyList(), boolTy));
// m.put(FALSE_SYM, new Pair<>(Collections.emptyList(), boolTy));

List<Ty> x = Collections.synchronizedList(new ArrayList<>(1));
x.add(boolTy);
Expand Down Expand Up @@ -137,8 +137,8 @@ private Set<Triple<Map<String, Ty>, Term<Ty, Void, Sym, Void, Void, Void, Void>,
// null propagation
// congruence for each symbol (EDs)

Term<Ty, Void, Sym, Void, Void, Void, Void> t = Term.Sym(TRUE_SYM, Collections.emptyList());
Term<Ty, Void, Sym, Void, Void, Void, Void> f = Term.Sym(FALSE_SYM, Collections.emptyList());
Term<Ty, Void, Sym, Void, Void, Void, Void> t =SqlTypeSide.t.convert(); // Term.Sym(TRUE_SYM, Collections.emptyList());
Term<Ty, Void, Sym, Void, Void, Void, Void> f = SqlTypeSide.f.convert(); //.Sym(FALSE_SYM, Collections.emptyList());
Term<Ty, Void, Sym, Void, Void, Void, Void> u = Term.Sym(typedNull(boolTy), Collections.emptyList());

ret.add(new Triple<>(Collections.emptyMap(), Term.Sym(NOT_SYM, Collections.singletonList(t)), f));
Expand Down
4 changes: 2 additions & 2 deletions src/catdata/cql/SqlTypeSideSkolem.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ public static Constraints makeEds(Schema<String, String, Sym, Fk, Att> schT, Aql
String x = ("x");
String y = ("y");
String z = ("z");
Term<String, String, Sym, Fk, Att, Void, Void> t = Term.Sym(SqlTypeSide.t, Collections.emptyList());
Term<String, String, Sym, Fk, Att, Void, Void> f = Term.Sym(SqlTypeSide.f, Collections.emptyList());
Term<String, String, Sym, Fk, Att, Void, Void> t = SqlTypeSide.t.convert();
Term<String, String, Sym, Fk, Att, Void, Void> f = SqlTypeSide.f.convert();

List<Term<String, String, Sym, Fk, Att, Void, Void>> lxx = new ArrayList<>(2);
lxx.add(Term.Var(x));
Expand Down
6 changes: 3 additions & 3 deletions src/catdata/cql/exp/EdsExpFromMsCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public Constraints eval0(AqlEnv env, boolean isC) {
Term<String, String, Sym, Fk, Att, Void, Void> j = Term.Sym(Sym.Sym("eq",
new Pair<>(Util.list(atts.get(p.first).second, atts.get(p.first).second), SqlTypeSide.boolSort.second)),
Util.list(l, r));
ewh.add(new Pair<>(j, Term.Sym(SqlTypeSide.t, Collections.emptyList())));
ewh.add(new Pair<>(j, SqlTypeSide.t.convert()));
} else {
ewh.add(new Pair<>(l, r));
}
Expand Down Expand Up @@ -413,7 +413,7 @@ private void processNullable(AqlEnv env, List<ED> eds, String ty, Att theAtt, bo
Term<String, String, Sym, Fk, Att, Void, Void> lhs = Term.Sym(
Sym.Sym("isNull", new Pair<>(Collections.singletonList(ty), "Boolean")),
Collections.singletonList(Term.Att(theAtt, Term.Var("v"))));
Term<String, String, Sym, Fk, Att, Void, Void> rhs = Term.Sym(SqlTypeSide.f, Collections.emptyList());
Term<String, String, Sym, Fk, Att, Void, Void> rhs = SqlTypeSide.f.convert();

var ed = new ED(Collections.singletonMap("v", Chc.inRight(theAtt.en)), Collections.emptyMap(), Collections.emptySet(),
Collections.singleton(new Pair<>(lhs, rhs)), false, env.defaults);
Expand Down Expand Up @@ -445,7 +445,7 @@ private void processUniq(AqlEnv env, List<ED> eds, Map<Att, Pair<String, String>
Sym.Sym("eq",
new Pair<>(Util.list(atts.get(att).second, atts.get(att).second), SqlTypeSide.boolSort.second)),
Util.list(l, r));
awh.add(new Pair<>(j, Term.Sym(SqlTypeSide.t, Collections.emptyList())));
awh.add(new Pair<>(j, SqlTypeSide.t.convert()));
} else {
awh.add(new Pair<>(l, r));
}
Expand Down
4 changes: 2 additions & 2 deletions src/catdata/cql/exp/EdsExpSqlNull.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public static Constraints makeEds(Schema<String, String, Sym, Fk, Att> schT, Aql
String x = ("x");
String y = ("y");
String z = ("z");
Term<String, String, Sym, Fk, Att, Void, Void> t = Term.Sym(SqlTypeSide.t, Collections.emptyList());
Term<String, String, Sym, Fk, Att, Void, Void> f = Term.Sym(SqlTypeSide.f, Collections.emptyList());
Term<String, String, Sym, Fk, Att, Void, Void> t = SqlTypeSide.t.convert();
Term<String, String, Sym, Fk, Att, Void, Void> f = SqlTypeSide.f.convert();

// Term<Ty, En, Sym, Fk, Att, Void, Void> u = Term.Sym(Sym.Sym("null_Boolean"),
// Collections.emptyList());
Expand Down
16 changes: 9 additions & 7 deletions src/catdata/cql/exp/SchExpJdbcAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,19 @@ public Schema<String, String, Sym, Fk, Att> eval0(AqlEnv env, boolean isC) {
SqlSchema info = new SqlSchema(conn.getMetaData(), tick);
for (SqlTable table : info.tables) {
if (table.name.first != null && (table.name.first.toLowerCase().equals("system") || table.name.first.toLowerCase().equals("sys")
|| table.name.first.toLowerCase().equals("ctxsys")
|| table.name.first.toLowerCase().equals("ctxsys") || table.name.first.toLowerCase().equals("mdsys")
|| table.name.first.toLowerCase().equals("xdb"))) {
continue; // ignore system tables
}
String x = (table.name.second);
if (table.name.first != null) {
x = (table.name.first + "." + table.name.second);
}
if (table.name.first != null && table.name.first.toLowerCase().equals("dbo")) {
x = table.name.second;
}
if (oracleSchMode) {
x = table.name.second;
} else if (table.name.first != null && table.name.first.toLowerCase().equals("dbo")) {
x = table.name.second;
} else if (table.name.first != null) {
x = (table.name.first + "." + table.name.second);
}

// if (oracleSchMode) {
// x = x.toLowerCase();
// }
Expand Down
12 changes: 6 additions & 6 deletions src/catdata/cql/fdm/SkolemInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ public Term<Ty, En, Sym, Fk, Att, Gen, Pair<X, Att>> rewriteIsNull(Term<Ty, En,
}
Optional<Object> o = (Optional<Object>) ret.obj();
if (o.isPresent()) {
return Term.Sym(SqlTypeSide.f, Collections.EMPTY_LIST);
return SqlTypeSide.f.convert();
} else {
return Term.Sym(SqlTypeSide.t, Collections.EMPTY_LIST);
return SqlTypeSide.t.convert();
}
} else if (l.get(0).att() != null) {
X x = algebra().intoX(l.get(0).arg);
Expand All @@ -207,9 +207,9 @@ public Term<Ty, En, Sym, Fk, Att, Gen, Pair<X, Att>> rewriteIsNull(Term<Ty, En,
}
Optional<Object> o = (Optional<Object>) ret.obj();
if (o.isPresent()) {
return Term.Sym(SqlTypeSide.f, Collections.EMPTY_LIST);
return SqlTypeSide.f.convert();
} else {
return Term.Sym(SqlTypeSide.t, Collections.EMPTY_LIST);
return SqlTypeSide.t.convert();
}
}
} else {
Expand Down Expand Up @@ -237,10 +237,10 @@ public Algebra<Ty, En, Sym, Fk, Att, Gen, Pair<X, Att>, X, Pair<X, Att>> algebra

if (o.isPresent()) {
eqs.add(new Pair<>(lhs, Term.Obj(v.obj(),v.ty())));
eqs.add(new Pair(Term.Sym((Sym)lhs2, Collections.singletonList(lhs)), Term.Sym(SqlTypeSide.f, Collections.EMPTY_LIST)));
eqs.add(new Pair(Term.Sym((Sym)lhs2, Collections.singletonList(lhs)), SqlTypeSide.f));
//TODO: add isNull action
} else {
eqs.add(new Pair(Term.Sym((Sym)lhs2, Collections.singletonList(lhs)), Term.Sym(SqlTypeSide.t, Collections.EMPTY_LIST)));
eqs.add(new Pair(Term.Sym((Sym)lhs2, Collections.singletonList(lhs)), SqlTypeSide.t));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/catdata/cql/fdm/ToJdbcPragmaInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void execute() {
}
}
for (X x : I.algebra().en(en)) {
// System.out.println("store ");
//System.out.println("store ");
I.algebra().storeMyRecord(emitIds, hdrQ, hdr, II, conn, x, header, en, prefix, tick, false);
}
// System.out.println("--");
Expand Down

0 comments on commit 4ecf870

Please sign in to comment.