Skip to content

Commit

Permalink
Bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBuzatu-Marian committed Aug 22, 2024
1 parent d7dac1b commit a1bc0c7
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/main/java/org/rumbledb/context/BuiltinFunctionCatalogue.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.rumbledb.runtime.functions.datetime.FormatDateFunctionIterator;
import org.rumbledb.runtime.functions.datetime.FormatDateTimeFunctionIterator;
import org.rumbledb.runtime.functions.datetime.FormatTimeFunctionIterator;
import org.rumbledb.runtime.functions.datetime.TimeInMillis;
import org.rumbledb.runtime.functions.datetime.components.AdjustDateTimeToTimezone;
import org.rumbledb.runtime.functions.datetime.components.AdjustDateToTimezone;
import org.rumbledb.runtime.functions.datetime.components.AdjustTimeToTimezone;
Expand Down Expand Up @@ -2894,6 +2895,17 @@ private static BuiltinFunction createBuiltinFunction(
BuiltinFunction.BuiltinFunctionExecutionMode.LOCAL
);

static final BuiltinFunction current_time_millis = createBuiltinFunction(
new Name(
Name.JN_NS,
"jn",
"current-time-milis"
),
"integer",
TimeInMillis.class,
BuiltinFunction.BuiltinFunctionExecutionMode.LOCAL
);

static {
builtinFunctions = new HashMap<>();

Expand Down Expand Up @@ -3114,6 +3126,7 @@ private static BuiltinFunction createBuiltinFunction(
builtinFunctions.put(xml_doc.getIdentifier(), xml_doc);
builtinFunctions.put(root_with_arg.getIdentifier(), root_with_arg);
builtinFunctions.put(root_without_arg.getIdentifier(), root_without_arg);
builtinFunctions.put(current_time_millis.getIdentifier(), current_time_millis);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.rumbledb.runtime.functions.datetime;

import org.rumbledb.api.Item;
import org.rumbledb.context.DynamicContext;
import org.rumbledb.context.RuntimeStaticContext;
import org.rumbledb.items.ItemFactory;
import org.rumbledb.runtime.AtMostOneItemLocalRuntimeIterator;
import org.rumbledb.runtime.RuntimeIterator;

import java.util.List;

public class TimeInMillis extends AtMostOneItemLocalRuntimeIterator {

private static final long serialVersionUID = 1L;

public TimeInMillis(
List<RuntimeIterator> arguments,
RuntimeStaticContext staticContext
) {
super(arguments, staticContext);
}

@Override
public Item materializeFirstItemOrNull(DynamicContext context) {
long time = System.currentTimeMillis();
return ItemFactory.getInstance().createLongItem(time);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public Item next() {
Document xmlDocument = documentBuilder.parse(xmlFileStream);
Item res = ItemParser.getItemFromXML(xmlDocument);
return res;
} catch (IteratorFlowException e) {
throw new IteratorFlowException(e.getJSONiqErrorMessage(), getMetadata());
} catch (ParserConfigurationException e) {
throw new OurBadException("Document builder creation failed with: " + e);
} catch (IOException e) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/rumbledb/runtime/xml/axis/AxisIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public void open(DynamicContext context) {

protected void storeNextResult() {
if (this.resultCounter == 0) {
// Remove duplicates
this.results = new ArrayList<>(new LinkedHashSet<>(this.results));
// Sort values in document order.
this.results.sort(Item::compareXmlNode);
}
if (this.resultCounter < this.results.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ declare function jsoniq_pandas:describe($dataframe as object*) {
declare function jsoniq_pandas:all_report($column, $params as object) {
let $column_type := item-type($column)
return switch($column_type)
case "xs:int" return jsoniq_pandas:numerical_report($column, $params)
case "xs:integer" return jsoniq_pandas:numerical_report($column, $params)
case "xs:decimal" return jsoniq_pandas:numerical_report($column, $params)
case "xs:float" return jsoniq_pandas:numerical_report($column, $params)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(:JIQS: ShouldRun; Output="({ "name" : [ "null", "null" ], "type" : "null", "other" : [ 1, 2, 3 ], "other2" : 1, "anotherArray" : [ 1, 2, 3 ] }, { "name" : [ "null" ], "type" : [ 1, 2, 3 ], "other" : [ "null" ], "other2" : 2, "anotherArray" : [ [ 2, 1, 2 ] ] }, { "name" : [ "null" ], "type" : "null", "other" : [ 1, 2, 3 ], "other2" : [ 1, 2, 3 ], "anotherArray" : [ [ 23 ] ] })":)
(:JIQS: ShouldRun; Output="({ "anotherArray" : [ 1, 2, 3 ], "name" : [ "null", "null" ], "other" : [ 1, 2, 3 ], "other2" : 1, "type" : "null" }, { "anotherArray" : [ [ 2, 1, 2 ] ], "name" : [ "null" ], "other" : [ "null" ], "other2" : 2, "type" : [ 1, 2, 3 ] }, { "anotherArray" : [ [ 23 ] ], "name" : [ "null" ], "other" : [ 1, 2, 3 ], "other2" : [ 1, 2, 3 ], "type" : "null" })":)
import module namespace pandas = "jsoniq_pandas.jq";

declare type local:sample-type as {
Expand All @@ -9,7 +9,17 @@ declare type local:sample-type as {
"anotherArray": [["integer"]]
};

declare function local:order-by-keys($object as object*) as object* {
for $row in $object
return
{|
for $key in keys($row)
order by $key
return {$key: $row.$key}
|}
};

declare variable $file_data := json-file("../../../queries/sample-na-data-3.json");
let $data := validate type local:sample-type* {$file_data}
return $data=>pandas:fillna({"value": [1, 2, 3]})
return local:order-by-keys($data=>pandas:fillna({"value": [1, 2, 3]}))

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(:JIQS: ShouldRun; Output="({ "label" : { "count" : 6, "mean" : 2.5, "std" : 1.8708287, "min" : 0, "max" : 5, "25%" : 1.25, "50%" : 2.5, "75%" : 3.75 } }, { "binaryLabel" : { "count" : 6, "mean" : 0.5, "std" : 0.5477226, "min" : 0, "max" : 1, "25%" : 0, "50%" : 0.5, "75%" : 1 } }, { "name" : { "count" : 6, "unique" : 6, "top" : "c", "frequency" : 1 } }, { "age" : { "count" : 6, "mean" : 22.5, "std" : 1.8708287, "min" : 20, "max" : 25, "25%" : 21.25, "50%" : 22.5, "75%" : 23.75 } }, { "weight" : { "count" : 6, "mean" : 62.95000000000001, "std" : 9.534097, "min" : 50, "max" : 75.6, "25%" : 56.625, "50%" : 63.25, "75%" : 69.2 } }, { "booleanCol" : { "count" : 6, "unique" : 3, "top" : false, "frequency" : 3 } }, { "nullCol" : { "count" : 6, "unique" : 1, "top" : null, "frequency" : 6 } }, { "stringCol" : { "count" : 6, "unique" : 6, "top" : "i am data entry 6", "frequency" : 1 } }, { "stringArrayCol" : { "count" : 6, "unique" : 5, "top" : [ "i", "am", "data", "entry", "3" ], "frequency" : 2 } }, { "intArrayCol" : { "count" : 6, "unique" : 6, "top" : [ 1, 2, 3 ], "frequency" : 1 } }, { "doubleArrayCol" : { "count" : 6, "unique" : 6, "top" : [ 1, 2, 3 ], "frequency" : 1 } }, { "doubleArrayArrayCol" : { "count" : 6, "unique" : 5, "top" : [ [ 1, 2, 3 ] ], "frequency" : 2 } })":)
(:JIQS: ShouldRun; Output="({ "label" : { "count" : 6, "mean" : 2.5, "std" : 1.8708287, "min" : 0, "max" : 5, "25%" : 1.25, "50%" : 2.5, "75%" : 3.75 } }, { "binaryLabel" : { "count" : 6, "mean" : 0.5, "std" : 0.5477226, "min" : 0, "max" : 1, "25%" : 0, "50%" : 0.5, "75%" : 1 } }, { "name" : { "count" : 6, "unique" : 6, "top" : "c", "frequency" : 1 } }, { "age" : { "count" : 6, "mean" : 22.5, "std" : 1.8708287, "min" : 20, "max" : 25, "25%" : 21.25, "50%" : 22.5, "75%" : 23.75 } }, { "weight" : { "count" : 6, "mean" : 62.95000000000001, "std" : 9.534097, "min" : 50, "max" : 75.6, "25%" : 56.625, "50%" : 63.25, "75%" : 69.2 } }, { "booleanCol" : { "count" : 4, "unique" : 2, "top" : false, "frequency" : 3 } }, { "nullCol" : { "count" : 6, "unique" : 1, "top" : null, "frequency" : 6 } }, { "stringCol" : { "count" : 6, "unique" : 6, "top" : "i am data entry 6", "frequency" : 1 } }, { "stringArrayCol" : { "count" : 6, "unique" : 5, "top" : [ "i", "am", "data", "entry", "3" ], "frequency" : 2 } }, { "intArrayCol" : { "count" : 6, "unique" : 6, "top" : [ 1, 2, 3 ], "frequency" : 1 } }, { "doubleArrayCol" : { "count" : 6, "unique" : 6, "top" : [ 1, 2, 3 ], "frequency" : 1 } }, { "doubleArrayArrayCol" : { "count" : 6, "unique" : 5, "top" : [ [ 1, 2, 3 ] ], "frequency" : 2 } })":)
import module namespace pandas = "jsoniq_pandas.jq";

declare type local:sample-type-with-arrays as {
Expand All @@ -16,6 +16,16 @@ declare type local:sample-type-with-arrays as {
"doubleArrayArrayCol": [["double"]]
};

declare function local:order-by-keys($object as object*) as object* {
for $row in $object
return
{|
for $key in keys($row)
order by $key
return {$key: $row.$key}
|}
};

declare variable $file_data := json-file("../../../queries/sample-na-data-4.json");
let $data := validate type local:sample-type-with-arrays* {$file_data}
return $data=>pandas:describe()
return local:order-by-keys($data=>pandas:describe())
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(:JIQS: ShouldRun; Output="({ "name" : false, "type" : false, "other" : true, "other2" : false, "anotherArray" : true }, { "name" : false, "type" : true, "other" : false, "other2" : false, "anotherArray" : false }, { "name" : false, "type" : false, "other" : true, "other2" : true, "anotherArray" : false })":)
(:JIQS: ShouldRun; Output="({ "anotherArray" : true, "name" : false, "other" : true, "other2" : false, "type" : false }, { "anotherArray" : false, "name" : false, "other" : false, "other2" : false, "type" : true }, { "anotherArray" : false, "name" : false, "other" : true, "other2" : true, "type" : false })":)
import module namespace pandas = "jsoniq_pandas.jq";

declare type local:sample-type as {
Expand All @@ -9,6 +9,16 @@ declare type local:sample-type as {
"anotherArray": [["integer"]]
};

declare function local:order-by-keys($object as object*) as object* {
for $row in $object
return
{|
for $key in keys($row)
order by $key
return {$key: $row.$key}
|}
};

declare variable $file_data := json-file("../../../queries/sample-na-data-3.json");
let $data := validate type local:sample-type* {$file_data}
return $data=>pandas:isnull()
return local:order-by-keys($data=>pandas:isnull())

0 comments on commit a1bc0c7

Please sign in to comment.