souffle icon indicating copy to clipboard operation
souffle copied to clipboard

Update SWIG Interface To Support Retrieving and Updating Relations

Open cwarden opened this issue 2 years ago • 8 comments

Add methods to SWIG interface to get relations and tuples, and to add tuples to relations.

  • [ ] Add tests
  • [ ] Add java/python examples
  • [x] Use type aliases

cwarden avatar Aug 16 '21 20:08 cwarden

Can you run clang-format -i src/include/souffle/swig/SwigInterface.h to ensure that the code changes are uniformly formatted.

See below,


10
diff --git a/src/include/souffle/swig/SwigInterface.h b/src/include/souffle/swig/SwigInterface.h
11
index 41aeab1..e175f37 100644
12
--- a/src/include/souffle/swig/SwigInterface.h
13
+++ b/src/include/souffle/swig/SwigInterface.h
14
@@ -24,6 +24,7 @@
15
 class SWIGSouffleTuple {
16
     souffle::tuple* t;
17
     souffle::Relation* relation;
18
+
19
 public:
20
     SWIGSouffleTuple(souffle::tuple* t, souffle::Relation* r) : t(t), relation(r) {}
21
 
22
@@ -51,7 +52,7 @@ public:
23
     }
24
 
25
     void putInteger(long long i) {
26
-            (*t) << (souffle::RamSigned)i;
27
+        (*t) << (souffle::RamSigned)i;
28
     }
29
 
30
     unsigned long long getUnsigned(unsigned int i) {
31
@@ -64,7 +65,7 @@ public:
32
     }
33
 
34
     void putUnsigned(unsigned long long i) {
35
-            (*t) << (souffle::RamUnsigned)i;
36
+        (*t) << (souffle::RamUnsigned)i;
37
     }
38
 
39
     double getFloat(unsigned int i) {
40
@@ -77,7 +78,7 @@ public:
41
     }
42
 
43
     void putFloat(double i) {
44
-            (*t) << (souffle::RamFloat)i;
45
+        (*t) << (souffle::RamFloat)i;
46
     }
47
 
48
 #else
49
@@ -91,7 +92,7 @@ public:
50
     }
51
 
52
     void putInteger(long i) {
53
-            (*t) << (souffle::RamSigned)i;
54
+        (*t) << (souffle::RamSigned)i;
55
     }
56
 
57
     unsigned long getUnsigned(unsigned int i) {
58
@@ -104,7 +105,7 @@ public:
59
     }
60
 
61
     void putUnsigned(unsigned long i) {
62
-            (*t) << (souffle::RamUnsigned)i;
63
+        (*t) << (souffle::RamUnsigned)i;
64
     }
65
 
66
     float getFloat(unsigned int i) {
67
@@ -117,7 +118,7 @@ public:
68
     }
69
 
70
     void putFloat(float i) {
71
-            (*t) << (souffle::RamFloat)i;
72
+        (*t) << (souffle::RamFloat)i;
73
     }
74
 
75
 #endif
76
@@ -125,7 +126,6 @@ public:
77
     void insert() {
78
         relation->insert(*t);
79
     }
80
-
81
 };
82
 
83
 class SWIGSouffleRelation {
84
@@ -167,7 +167,6 @@ public:
85
     unsigned int getArity() {
86
         return relation->getArity();
87
     }
88
-
89
 };
90
 
91
 /**
92
@@ -232,7 +231,6 @@ public:
93
         auto* rel = program->getRelation(relationName);
94
         return new SWIGSouffleRelation(rel);
95
     }
96
-
97
 };
98
 
99
 /**
100

b-scholz avatar Aug 17 '21 00:08 b-scholz

Can you run clang-format -i src/include/souffle/swig/SwigInterface.h to ensure that the code changes are uniformly formatted.

Cleaned up whitespace using clang-format in 7b34b5fba9ef505579ad282ed5e2329bf110dcb5.

cwarden avatar Aug 17 '21 13:08 cwarden

Codecov Report

Merging #2014 (3c45a1d) into master (23a792d) will decrease coverage by 1.42%. The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2014      +/-   ##
==========================================
- Coverage   77.67%   76.24%   -1.43%     
==========================================
  Files         445      447       +2     
  Lines       29143    26286    -2857     
==========================================
- Hits        22636    20042    -2594     
+ Misses       6507     6244     -263     
Impacted Files Coverage Δ
src/include/souffle/profile/StringUtils.h 0.00% <0.00%> (-85.30%) :arrow_down:
src/ram/transform/ReorderConditions.h 0.00% <0.00%> (-60.00%) :arrow_down:
src/GraphUtils.h 0.00% <0.00%> (-55.24%) :arrow_down:
src/ast/TranslationUnit.cpp 28.57% <0.00%> (-38.10%) :arrow_down:
src/include/souffle/RecordTable.h 45.62% <0.00%> (-30.92%) :arrow_down:
src/include/souffle/utility/StreamUtil.h 72.91% <0.00%> (-22.92%) :arrow_down:
...nclude/souffle/datastructure/EquivalenceRelation.h 75.86% <0.00%> (-18.21%) :arrow_down:
src/include/souffle/datastructure/LambdaBTree.h 74.04% <0.00%> (-11.46%) :arrow_down:
src/ast/analysis/PrecedenceGraph.cpp 35.13% <0.00%> (-9.70%) :arrow_down:
src/include/souffle/utility/ParallelUtil.h 83.96% <0.00%> (-9.63%) :arrow_down:
... and 225 more

codecov[bot] avatar Aug 18 '21 00:08 codecov[bot]

Can you provide some examples in tests/interface/swig that access the interface?

b-scholz avatar Aug 18 '21 07:08 b-scholz

Instead of an #if in the code checking for 32bit or 64bit, please could you use types as shown in this functor implementation: https://github.com/souffle-lang/souffle/blob/master/tests/interface/functors/functors.cpp

b-scholz avatar Aug 19 '21 04:08 b-scholz

Also, can you add python/java code that accesses the tuples in a relation.

b-scholz avatar Aug 19 '21 04:08 b-scholz

Do you need more help with this?

b-scholz avatar Sep 13 '21 05:09 b-scholz

Do you need more help with this?

I could use some help to finish this off. If someone has time to finish up the tests and java/python examples, I can offer a bounty of USD 300 for that work.

cwarden avatar Sep 16 '21 20:09 cwarden

Hi, I am closing this this pull request because it has been inactive for over 3 years.

quentin avatar Dec 18 '23 14:12 quentin