Skip to content

Commit

Permalink
add example and fix some problems in core
Browse files Browse the repository at this point in the history
  • Loading branch information
asavinov committed Oct 9, 2017
1 parent b6cbcff commit 34f2fd3
Show file tree
Hide file tree
Showing 18 changed files with 756 additions and 10 deletions.
12 changes: 6 additions & 6 deletions core/README.md
Expand Up @@ -10,7 +10,7 @@ Bistro-core is a core library of Bistro for schema management, data representati

First of all, it is necessary to create a *schema* which can be thought of as a database and will be a collection of all other elements and parameters:
```java
Bistro schema = new Bistro("My Bistro");
Schema schema = new Schema("My Schema");
```

A schema like tables and columns has an arbitrary (case sensitive) name. The schema is then used to create and access other elements as well as perform various operations with data.
Expand Down Expand Up @@ -73,7 +73,7 @@ For example, we could define a calculate column which increments the value store
Column calc = schema.createColumn("length", table, objects);
calc.calc(
(p, o) -> ((String)p[0]).length(), // How to compute
Arrays.asList(name) // Parameters for computing
new Column[] {name}) // Parameters for computing
);
```
The first parameter is a function which takes two arguments. The first argument `p` is an array of outputs of other columns that have to be processed. The second argument `o` is the current output of this same column which is not used for calculate columns. The second parameter of the definition specifies the input columns the outputs of which have to be processed. In this example, we use a previously defined no-definition column the outputs of which will be incremented. The size of the `p` array has to be equal to the length of the second parameter.
Expand All @@ -85,7 +85,7 @@ calc.eval();
Now, if there were no errors, we can retrieve the output values:
```java
value = calc.getValue(1); // value = 3
value = calc.getValue(1); // value = 7
value = calc.getValue(2); // value = 7
```

There exist also other ways to define calculate columns which can be more convenient in different situations, for example, in the case of complex arithmetic operations or in the case of complex computations implemented programmatically. Note also that column outputs could contain `null` and all lambda functions must guarantee the validity of its computations including null-safety and type-safety.
Expand All @@ -110,8 +110,8 @@ This property however cannot be used to access the elements of the "Table". Ther
```java
Column link = schema.createColumn("link to table", facts, table);
link.link(
Arrays.asList(name) // Columns to be used for searching (in the type table)
Arrays.asList(group) // Columns providing criteria for search (in this input table)
new Column[] {name}, // Columns to be used for searching (in the type table)
new Column[] {group} // Columns providing criteria for search (in this input table)
);
```
This definition essentially means that the new column will reference elements of its type table which have the same `name` as this table `group` column.
Expand Down Expand Up @@ -178,7 +178,7 @@ We can find the sum of the measure for each element in the "Table" using this ac
Column sums = schema.createColumn("sum measure", table, objects);
sums.accu(
(p, o) -> (Double)o + (Double)p[0], // Add the measure for each new fact
Arrays.asList(measure) // Measure
new Column[] {measure} // Measure
link // Grouping column
);

Expand Down
Expand Up @@ -359,11 +359,11 @@ public void accu(Evaluator accuEval, ColumnPath[] params, ColumnPath accuPath) {
}

// Evaluator + parameters
public void accu(Evaluator accuEval, Column[] params, ColumnPath accuPath) {
public void accu(Evaluator accuEval, Column[] params, Column accuPath) {
this.setDefinitionType(ColumnDefinitionType.ACCU); // Reset definition

Expression accuExpr = new Expr(accuEval, params);
this.definition = new ColumnDefinitionAccu(this, accuExpr, accuPath);
this.definition = new ColumnDefinitionAccu(this, accuExpr, new ColumnPath(accuPath));

if(this.isInCyle()) {
this.definitionErrors.add(new BistroError(BistroErrorCode.DEFINITION_ERROR, "Cyclic dependency.", "This column depends on itself directly or indirectly."));
Expand Down
Expand Up @@ -48,7 +48,11 @@ protected void evaluateExpr(Expression expr, ColumnPath accuLinkPath) {
result = expr.evaluate(paramValues, out);
}
catch(BistroError e) {
definitionErrors.add(e);
this.definitionErrors.add(e);
return;
}
catch(Exception e) {
this.definitionErrors.add( new BistroError(BistroErrorCode.EVALUATION_ERROR, e.getMessage(), "") );
return;
}

Expand Down
Expand Up @@ -94,6 +94,10 @@ protected void evaluateLink(List<Column> columns, List<Expression> exprs) {
definitionErrors.add(e);
return;
}
catch(Exception e) {
this.definitionErrors.add( new BistroError(BistroErrorCode.EVALUATION_ERROR, e.getMessage(), "") );
return;
}

rhsResults.set(mmbrNo, result);
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/conceptoriented/bistro/core/Expr.java
Expand Up @@ -21,11 +21,14 @@ public class Expr implements Expression {

public Expr(Evaluator eval, ColumnPath[] params) {
this.evaluateLambda = eval;

if(params == null) params = new ColumnPath[]{};
this.setParameterPaths(Arrays.asList(params));
}
public Expr(Evaluator eval, Column[] params) {
this.evaluateLambda = eval;

if(params == null) params = new Column[]{};
List<ColumnPath> paths = new ArrayList<>();
for(int i=0; i<params.length; i++) {
paths.add(new ColumnPath(params[i]));
Expand Down
179 changes: 179 additions & 0 deletions examples/.gitignore
@@ -0,0 +1,179 @@

# Created by https://www.gitignore.io/api/java,maven,gradle,eclipse,intellij

### Eclipse ###

.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

### Eclipse Patch ###
# Eclipse Core
.project

# JDT-specific (Eclipse Java Development Tools)
.classpath

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/sonarlint

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties

# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar

### Gradle ###
.gradle
/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

# End of https://www.gitignore.io/api/java,maven,gradle,eclipse,intellij
9 changes: 9 additions & 0 deletions examples/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions examples/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions examples/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions examples/.idea/modules/examples_main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions examples/.idea/modules/examples_test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 34f2fd3

Please sign in to comment.