Skip to content
Snippets Groups Projects
Verified Commit 39b6d02d authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: empty and null values

parent 69d49958
Branches
Tags
No related merge requests found
...@@ -799,8 +799,10 @@ public class Entity extends AbstractObservable implements EntityInterface { ...@@ -799,8 +799,10 @@ public class Entity extends AbstractObservable implements EntityInterface {
if (pe.getText() != null && pe.getTextTrim() != "") { if (pe.getText() != null && pe.getTextTrim() != "") {
vals.add(new GenericValue(pe.getTextTrim())); vals.add(new GenericValue(pe.getTextTrim()));
} else { } else if (pe.getAttribute("null") != null) {
vals.add(null); vals.add(null);
} else {
vals.add(new GenericValue(""));
} }
} else if (pe.getName().equalsIgnoreCase("Property")) { } else if (pe.getName().equalsIgnoreCase("Property")) {
// Parse sub elements which represent PROPERTIES of this // Parse sub elements which represent PROPERTIES of this
...@@ -864,6 +866,8 @@ public class Entity extends AbstractObservable implements EntityInterface { ...@@ -864,6 +866,8 @@ public class Entity extends AbstractObservable implements EntityInterface {
// Parse VALUE. // Parse VALUE.
if (vals.size() != 0) { if (vals.size() != 0) {
setValue(vals); setValue(vals);
} else if (element.getAttribute("null") != null) {
setValue(null);
} else if (element.getTextTrim() != null && !element.getTextTrim().equals("")) { } else if (element.getTextTrim() != null && !element.getTextTrim().equals("")) {
setValue(new GenericValue(element.getTextTrim())); setValue(new GenericValue(element.getTextTrim()));
} }
......
...@@ -483,7 +483,7 @@ single_quoted returns [Query.Pattern ep] locals [StringBuffer sb, int patternTyp ...@@ -483,7 +483,7 @@ single_quoted returns [Query.Pattern ep] locals [StringBuffer sb, int patternTyp
r = SINGLE_QUOTE_STAR {$sb.append($r.text); $patternType = Query.Pattern.TYPE_LIKE;} r = SINGLE_QUOTE_STAR {$sb.append($r.text); $patternType = Query.Pattern.TYPE_LIKE;}
| |
s = ~SINGLE_QUOTE_END {$sb.append($s.text);} s = ~SINGLE_QUOTE_END {$sb.append($s.text);}
)+? )*?
SINGLE_QUOTE_END SINGLE_QUOTE_END
; ;
...@@ -503,6 +503,6 @@ double_quoted returns [Query.Pattern ep] locals [StringBuffer sb, int patternTyp ...@@ -503,6 +503,6 @@ double_quoted returns [Query.Pattern ep] locals [StringBuffer sb, int patternTyp
r = DOUBLE_QUOTE_STAR {$sb.append($r.text); $patternType = Query.Pattern.TYPE_LIKE;} r = DOUBLE_QUOTE_STAR {$sb.append($r.text); $patternType = Query.Pattern.TYPE_LIKE;}
| |
s = ~DOUBLE_QUOTE_END {$sb.append($s.text);} s = ~DOUBLE_QUOTE_END {$sb.append($s.text);}
)+? )*?
DOUBLE_QUOTE_END DOUBLE_QUOTE_END
; ;
...@@ -28,6 +28,15 @@ import static org.junit.Assert.assertNotNull; ...@@ -28,6 +28,15 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import caosdb.server.CaosDBServer;
import caosdb.server.database.access.Access;
import caosdb.server.database.backend.implementation.MySQL.ConnectionException;
import caosdb.server.database.exceptions.TransactionException;
import caosdb.server.query.CQLParser.CqContext;
import caosdb.server.query.Query.Pattern;
import caosdb.server.query.Query.QueryException;
import caosdb.server.utils.Initialization;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -38,14 +47,6 @@ import org.antlr.v4.runtime.Token; ...@@ -38,14 +47,6 @@ import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTree;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import caosdb.server.CaosDBServer;
import caosdb.server.database.access.Access;
import caosdb.server.database.backend.implementation.MySQL.ConnectionException;
import caosdb.server.database.exceptions.TransactionException;
import caosdb.server.query.CQLParser.CqContext;
import caosdb.server.query.Query.Pattern;
import caosdb.server.query.Query.QueryException;
import caosdb.server.utils.Initialization;
public class TestCQL { public class TestCQL {
...@@ -235,6 +236,8 @@ public class TestCQL { ...@@ -235,6 +236,8 @@ public class TestCQL {
String referenceByLikePattern = "FIND ENTITY WHICH IS REFERENCED BY *name*"; String referenceByLikePattern = "FIND ENTITY WHICH IS REFERENCED BY *name*";
String emptyTextValue = "FIND ENTITY WITH prop=''";
@Test @Test
public void testQuery1() public void testQuery1()
throws InterruptedException, SQLException, ConnectionException, QueryException { throws InterruptedException, SQLException, ConnectionException, QueryException {
...@@ -6219,6 +6222,7 @@ public class TestCQL { ...@@ -6219,6 +6222,7 @@ public class TestCQL {
assertEquals("SAT(SimulationData/2016\\_single/2018-01-10/%)", storedAt.toString()); assertEquals("SAT(SimulationData/2016\\_single/2018-01-10/%)", storedAt.toString());
} }
@Test
public void testFilePathInQuotes2() { public void testFilePathInQuotes2() {
CQLLexer lexer = new CQLLexer(CharStreams.fromString(query_filepath_quotes_2)); CQLLexer lexer = new CQLLexer(CharStreams.fromString(query_filepath_quotes_2));
final CommonTokenStream tokens = new CommonTokenStream(lexer); final CommonTokenStream tokens = new CommonTokenStream(lexer);
...@@ -6246,11 +6250,23 @@ public class TestCQL { ...@@ -6246,11 +6250,23 @@ public class TestCQL {
final ParseTree satFilter = whichclause.getChild(1).getChild(0); final ParseTree satFilter = whichclause.getChild(1).getChild(0);
assertEquals(2, satFilter.getChildCount()); assertEquals(2, satFilter.getChildCount());
assertEquals("IS STORED AT", satFilter.getChild(0).getText()); assertEquals("IS STORED AT", satFilter.getChild(0).getText());
assertEquals("'/SimulationData/2016_single/2018-01-10/**'", satFilter.getChild(1).getText()); assertEquals("/SimulationData/2016_single/2018-01-10/**", satFilter.getChild(1).getText());
assertTrue(sfq.filter instanceof StoredAt); assertTrue(sfq.filter instanceof StoredAt);
final StoredAt storedAt = (StoredAt) sfq.filter; final StoredAt storedAt = (StoredAt) sfq.filter;
assertTrue(storedAt.pattern_matching); assertTrue(storedAt.pattern_matching);
assertEquals("SAT(SimulationData/2016\\_single/2018-01-10/%%)", storedAt.toString()); assertEquals("SAT(SimulationData/2016\\_single/2018-01-10/%)", storedAt.toString());
}
@Test
public void testEmptyTextValue() {
CQLLexer lexer = new CQLLexer(CharStreams.fromString(emptyTextValue));
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final CQLParser parser = new CQLParser(tokens);
final CqContext sfq = parser.cq();
EntityFilterInterface pov = sfq.filter;
assertEquals("POV(prop,=,)", pov.toString());
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment