Tarantool Querying Questions - tarantool

I have the following data structure format:
unix/:/var/run/tarantool/tarantool.sock> s:format()
---
- [{'name': 'id', 'type': 'unsigned'}, {'name': 'version', 'type': 'array'}, {'name': 'data',
'type': 'array'}]
...
And I have the following data already inside it:
unix/:/var/run/tarantool/tarantool.sock> s:select{}
---
- - [0, [[21, 'action123'], [12, 'actionXYZ'], [11, 'actionABC']], [['actionXYZ',
'SOME_JAVASCRIPT_CONTENT']]]
- [1, [[33, 'action123'], [12, 'baseXYZ'], [11, 'baseABC']], [['bas123', 'SOME_CSS_CONTENT']]]
...
I have read through the references and documentation and I'm a bit lost on completing the following:
What's the "WHERE" equivalent? ie. Select to find entries that have a version of 12
Not seeing applicable examples in
https://www.tarantool.io/en/doc/2.2/reference/reference_lua/box_space/#lua-function.space_object.select
List items with the field names (so I know what block I'm looking at). In a way, sort of like having "column headers" in your results in SQL.
I have named tuples in my format() - how can I see these names when I'm querying data?
{'name': 'id', 'type': 'unsigned'}, {'name': 'version', 'type': 'array'}, {'name': 'data',
'type': 'array'}]
Pretty print! (preferably yaml)
I tried using https://www.tarantool.io/en/doc/2.2/reference/reference_lua/yaml/ to wrap around my select statements, but nothing was working.

You need to use indexes for imperative effective queries, look here:
https://www.tarantool.io/en/doc/2.2/reference/reference_lua/box_space/#lua-function.space_object.create_index
https://www.tarantool.io/en/doc/2.2/reference/reference_lua/box_index/
use tuple:tomap():
https://www.tarantool.io/en/doc/2.2/reference/reference_lua/box_tuple/#lua-function.tuple_object.tomap
It depends on where do you want it pretty. You may have to tune yaml settings, or simply chain tomap calls:
tarantool> box.space.TEST:pairs():map(function(x) return x:tomap({names_only=true}) end):totable()
---
- - COLUMN1: 1
COLUMN2: a
- COLUMN1: 13
COLUMN2: a
- COLUMN1: 1000
COLUMN2: a

Related

Boto3 Amplify list apps

I have a lot of amplify apps which I want to manage via Lambdas. What is the equivalent of the cli command aws amplify list-apps in boto3, I had multiple attempts, but none worked out for me.
My bit of code that was using nextToken looked like this:
amplify = boto3.client('amplify')
apps = amplify.list_apps()
print(apps)
print('First token is: ', apps['nextToken'])
while 'nextToken' in apps:
apps = amplify.list_apps(nextToken=apps['nextToken'])
print('=====NEW APP=====')
print(apps)
print('=================')
Then I tried to use paginators like:
paginator = amplify.get_paginator('list_apps')
response_iterator = paginator.paginate(
PaginationConfig={
'MaxItems': 100,
'PageSize': 100
}
)
for i in response_iterator:
print(i)
Both of the attempts were throwing inconsistent output. The first one was printing first token and second entry but nothing more. The second one gives only the first entry.
Edit with more attemptsinfo + output. Bellow piece of code:
apps = amplify.list_apps()
print(apps)
print('---------------')
new_app = amplify.list_apps(nextToken=apps['nextToken'], maxResults=100)
print(new_app)
print('---------------')```
Returns (some sensitive output bits were removed):
EVG_long_token_x4gbDGaAWGPGOASRtJPSI='}
---------------
{'ResponseMetadata': {'RequestId': 'f6...e9eb', 'HTTPStatusCode': 200, 'HTTPHeaders': {'content-type': 'application/json', 'content-length': ...}, 'RetryAttempts': 0}, 'apps': [{'appId': 'dym7444jed2kq', 'appArn': 'arn:aws:amplify:us-east-2:763175725735:apps/dym7444jed2kq', 'name': 'vesting-interface', 'tags': {}, 'repository': 'https://github.com/...interface', 'platform': 'WEB', 'createTime': datetime.datetime(2021, 5, 4, 3, 41, 34, 717000, tzinfo=tzlocal()), 'updateTime': datetime.datetime(2021, 5, 4, 3, 41, 34, 717000, tzinfo=tzlocal()), 'environmentVariables': {}, 'defaultDomain': 'dym7444jed2kq.amplifyapp.com', 'customRules': _rules_, 'productionBranch': {'lastDeployTime': datetime.datetime(2021, 5, 26, 15, 10, 7, 694000, tzinfo=tzlocal()), 'status': 'SUCCEED', 'thumbnailUrl': 'https://aws-amplify-', 'branchName': 'main'}, - yarn install\n build:\n commands:\n - yarn run build\n artifacts:\n baseDirectory: build\n files:\n - '**/*'\n cache:\n paths:\n - node_modules/**/*\n", 'customHeaders': '', 'enableAutoBranchCreation': False}]}
---------------
I am very confused, why next iteration doesn't has nextToken and how can I get to the next appId.
import boto3
import json
session=boto3.session.Session(profile_name='<Profile_Name>')
amplify_client=session.client('amplify',region_name='ap-south-1')
output=amplify_client.list_apps()
print(output['apps'])

Sankey amcharts nodes are not being aligned well

So I'm working with amcharts v4 and Sankey diagram.
I'm trying a dataset that is quite simple but I have the node 500 and 652 on same level and causing some visual issues as in the picture below.
I've tryied to arrange differently the dataset but having same issue.
Anyone can help?
Is even possibile to reduce the links width in order to make it fit better? (tryied everything from SankeyLink but with no results)
[{from: '100', to: '200', value: 1},
{from: '200', to: '450', value: 1},
{from: '450', to: '652', value: 1},
{from: '450', to: '652', value: 1},
{from: '652', to: '500', value: 1},
{from: '652', to: '500', value: 1},
{from: '500', to: '650', value: 1},
{from: '500', to: '650', value: 1}]
enter image description here
So it seems to be a bug becouse all nodes have names that are all numbers.
Below the reply from amcharts responsable.
It seems to be a bug caused by all-number names. If I change the name of the last node to something that starts with a letter, the chart displays fine.

Sort a dictionary into two different lists based on group

import requests
from operator import itemgetter
foods = [{'name': 'Daisy' , 'group': 'A', 'eating': 'yes', 'feasting': 'yes', 'fasting': 'no', 'sleeping': 'no'},
{'name': 'Donny', 'group': 'B', 'eating': 'maybe', 'feasting':'maybe', 'fasting':'maybe', 'sleeping': 'maybe'},
{'name': 'Dwane', 'group': 'A', 'eating': 'no', 'feasting':'yes', 'fasting': 'no', 'sleeping': 'yes'},
{'name': 'Diana', 'group': 'B', 'eating': 'never', 'feasting':'never', 'fasting':'never', 'sleeping':'never'}]
def main():
group = sorted(foods, key=itemgetter('group'))
group_a = []
group_b = []
print(group)
main()
Hi there, I need help with the next step of this code. I would like to place the two dictionaries with group "A" in the empty list group_a. I would also like to place the two dictionaries with group "B" in the empty list group_b.
I am not sure how to go about this. Previously I tried:
for row in foods:
if 'A' in row:
group_a.append(row)
else:
group_b.append(row)
How ever that did not work.
Does anyone have an idea of how to populate these two empty lists according to group?

Ask about rxjs' use of Obsevable distinct

I want to know how to use Observable.
What I want to do is duplicate deletion. The following sample 1 can be moved, but what I want to do is not this format, but how to cook when preparing an array in advance.
orgLayerDistinct(allList: LabelMasterExt[]) {
// Observable.of( allList ).distinct( );
// [sample 1] このサンプルは動くが好みの形式ではない。
// [sample 1] This sample works, but it's not a form of favorite.
Observable.of<Person>(
{ age: 4, name: 'Foo'},
{ age: 7, name: 'Bar'},
{ age: 5, name: 'Foo'},
{ age: 6, name: 'Foo'})
.distinct((p: Person) => p.name)
.subscribe(x => console.log(x));
// [sample 2 experimental] 配列を用意してある前提で利用したい。
// [sample 2 experimental] I would like to use an array on the assumption that it is prepared.
const persons: Person[] = [];
persons.push({ age: 4, name: 'Foo'});
persons.push({ age: 7, name: 'Bar'});
persons.push({ age: 5, name: 'Foo'});
persons.push({ age: 6, name: 'Foo'});
Observable.of<Person[]>(persons)
.distinct((p: Person) => p.name)
.subscribe(x => console.log(x));
}
[sample 2 experimental]
However, this gives the following error.
The type argument for type parameter 'T' cannot be inferred from the usage.
Consider specifying the type arguments explicitly.
Type argument candidate 'Person[]' is not a valid type argument
because it is not a supertype of candidate 'Person'.
Property 'includes' is missing in type 'Person'.
Is there any good plan?
You can either use Observable.from<Person>(array) or Observable.of<Person>(...array).
The problem your second example has is that Observable.of<Person[]>()s elements are arrays of Person, but the .distinct() is expecting an input of the Person type.

PouchDB: filtering, ordering and paging

Very similar to these two CouchDB questions: 3311225 and 8924793, except that these approaches don't allow partial matching. Having e.g. these entries:
[{_id: 1, status: 'NEW', name: 'a'},
{_id: 2, status: 'NEW', name: 'aab'},
{_id: 3, status: 'NEW', name: 'ab'},
{_id: 4, status: 'NEW', name: 'aaa'},
{_id: 5, status: 'NEW', name: 'aa'}]
and key
[status, name, _id]
There seems to be no way to
filter these entries by status (full string match) and name (partial string match ~ startsWith)
order them by id
paginate them
because of the partial string match on name. The high value unicode character \uffff that allows this partial match also causes to ignore the _id part of the key, meaning the resulting entries are not sorted by _id, but rather by status and name.
var status = 'NEW';
var name = 'aa'
var query = {
startkey: [status, name],
endkey: [status, name + '\uffff', {}],
skip: 0,
limit: 10
};
results in
[{_id: 5, status: 'NEW', name: 'aa'},
{_id: 4, status: 'NEW', name: 'aaa'},
{_id: 2, status: 'NEW', name: 'aab'}]
There is no option to sort in memory, as this would only sort the individual pages, and not the entire data set. Any ideas about this?

Resources