Comments (14)
I see the confusion, Equation instances are used to build a Script if building by hand. After setting up an Equation the Script() function is called to return a Script or Filter() is called to return a Filter. You can't go the other way around from Filter to Equation. The end goal is to produce a Filter or Script and Equation is just one of the ways to do that.
from ojg.
Hi @ohler55, would it be possible to make an Equation
accessible from a Filter
?
In my code I'm iterating through each Frag
in the Expr
and I would like to add support for filter expressions, and the Frag
type that contains a filter expression is *Filter
. But I'm unable to access the filter expression (via Equation
) programmatically through a Filter
object.
I'm also willing to make a PR to support this, if you're OK with that.
from ojg.
I'm not sure using the Equation type is the best way to view the Filter internals. Can you provide a bit more on what it is you are trying to do the the Filter? Let's see if we can come up with something.
from ojg.
Hi @ohler55 , sorry for the late reply. I'll try my best to explain.
I'm currently developing an API that converts JSONPath strings into Aerospike server operations, and I'm doing this for Aerospike's Golang client. The way the API currently works is:
- It takes in JSONPath strings through an API call
- It parses the JSONPath string using the
jp
library into anExpr
object
expr, err := jp.ParseString(jsonPath)
- Then, one by one, it reads each
Frag
in the expr (which is basically a list ofFrag
objects). It determines which kind of operation it is and translates it to a server operation. For example, if the frag has a concretejp.Nth
type, we would translate that to a server operation that gets a list item at a specific index.
The problem is that filter expressions are encoded as Filter
objects (which is also a Frag
), but there's no way to access the expression itself for a Filter
object. If there's a way to access the Equation of a filter such as this, we would easily be able to convert it to the equivalent server operation.
from ojg.
I see. Right now you can get the string representation of the filter but then you would have to parse the string which would be a pity since the filter already has the info. Let's look at what would be the ideal solution first then see what can reasonably be done.
If a call was added to Filter and Script (might as well) that returned some kind of struct or slice of structs that described the Script/Filter I think that would be best for your situation. The struct should include the left side, right side, and operation. Something like:
type Foo struct {
op string
left any
right any
}
What do you think?
from ojg.
That looks good for binary operations. For unary operations like getting an item from a map (i.e @.key
), we can set the right
attribute to be nil
.
from ojg.
Exactly. That's what OjG does.
from ojg.
I started a branch named "inspect-filters". I'll be working in that branch to add this feature.
from ojg.
I have an implementation but I need more tests. Please give it a try.
Testing complete but could use some feedback about whether it works for you.
from ojg.
Hi @ohler55 , thank you so much for getting back to me. I'll check if my code works with yours
from ojg.
Please let me know if the addition works for you.
from ojg.
Hi @ohler55, I have to put my project on the backlog for a few weeks, but I will continue working on this at the start of next month. Thanks for helping me out by adding this feature!!
from ojg.
Ok, I'll merge and release anyway.
from ojg.
v1.15.0 released
from ojg.
Related Issues (20)
- Remove nth element of an array using jsonPath HOT 8
- Sponsor this project HOT 4
- not support token contain '-' ? HOT 11
- Double value parse error on iOS platform HOT 6
- preserve order of JSONPath elements (when using wildcard) HOT 6
- Getting full path of a rule in the json HOT 1
- oj.Marshal fails on embedded interface HOT 2
- Extracting Multiple Fields HOT 2
- Array indexes with last return reverse order HOT 4
- Is it possible to use JSONPath to pick the objects without a particular field? HOT 4
- Working with a collection of JSONPaths simultaneously? HOT 2
- Does JsonPath supports escaping? HOT 13
- Option to keep order of keys HOT 16
- Does support ”-“ HOT 1
- Parse '1,2,3' should not succeed HOT 3
- Expr.String() doesn't escape strings HOT 6
- Question: Using jp.Set() to set non-existent slice indices HOT 2
- Maybe a regression on path filters on version 1.18.0 HOT 3
- support for "json" tag in struct elements HOT 4
- jp feature request: Set() that only replaces existing values HOT 27
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ojg.