how to determine if the partition being deleted existed or not - cassandra

Is there a way to determine if the delete operation actually deleted a partition if the partition existed? I am running the following cql queries. I was hoping that I'll get an error when I'll specify an invalid partition but I don't
cqlsh:mypartition> select * from users;
bucket | email | authprovider | firstname | lastname | confirmed | hasher | id | password | salt
--------+---------------+--------------+-----------+----------+-----------+------------+--------------------------------------+--------------+------
1 | test#test.com | credentials | fn | ln | False | someHasher | 11111111-1111-1111-1111-111111111111 | somePassword |
(1 rows)
cqlsh:mypartition> DELETE FROM users WHERE bucket=1 AND email='test1#test.com';
cqlsh:mypartition> select * from users;
bucket | email | authprovider | firstname | lastname | confirmed | hasher | id | password | salt
--------+---------------+--------------+-----------+----------+-----------+------------+--------------------------------------+--------------+------
1 | test#test.com | credentials | fn | ln | False | someHasher | 11111111-1111-1111-1111-111111111111 | somePassword |
(1 rows)
cqlsh:mypartition> DELETE FROM users WHERE bucket=1 AND email='test#test.com';
cqlsh:codingjedi> select * from users;
bucket | email | authprovider | firstname | lastname | confirmed | hasher | id | password | salt
--------+-------+--------------+-----------+----------+-----------+--------+----+----------+------
(0 rows)
cqlsh:codingjedi>

You can't. Deletes are just writes, and Cassandra sorts it out in compaction.

Related

Sequelize - create recond with value that matches another table foreign key's value

I have the following structure for Users_Role table:
| role_id(PK) | role_name |
| ---------------| --------------|
| 1 | Admin |
| 2 | View |
And the following structure for Users table:
| user_id (PK) | user_role_id(FK) |
| -------------| --------------------|
| 12345 | 1 |
| 22434 | 1 |
The tables are connected by user_role_id and role_id
I want to create new records in Users Table, the thing is I only have the user_role value.
Is there a way to shortcut the way to get the value of the user_role_id, or the only way to do it is a seperate query before creating new record in Users?
const userRole = "Admin";
Users.create({
user_id:"1234",
user_role_id: ???
})

Problems encountered in installing Fabric Explore

I installed it according to the guide on the official website.fabricexplorer But I may be having problems initializing the database.
MacOS
$ cd blockchain-explorer/app/persistence/fabric/postgreSQL/db
$ ./createdb.sh
$ createdb whoami
psql -c '\l'
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
----------------+----------+----------+---------+-------+-----------------------
fabricexplorer | hyy | UTF8 | C | C |
heyueyue | heyueyue | UTF8 | C | C |
postgres | postgres | UTF8 | C | C | =Tc/postgres +
| | | | | postgres=CTc/postgres
template0 | heyueyue | UTF8 | C | C | =c/heyueyue +
| | | | | heyueyue=CTc/heyueyue
template1 | heyueyue | UTF8 | C | C | =c/heyueyue +
| | | | | heyueyue=CTc/heyueyue
(5 rows)
heyueyue#heyueyuedeMacBook-Pro test-network % psql $DATABASE_DATABASE -c '\d'
Did not find any relations.
However, there are tables in the database fabricexplorer.
fabricexplorer-# \d
List of relations
Schema | Name | Type | Owner
--------+---------------------------+----------+-------
public | blocks | table | hyy
public | blocks_id_seq | sequence | hyy
public | chaincodes | table | hyy
public | chaincodes_id_seq | sequence | hyy
public | channel | table | hyy
public | channel_id_seq | sequence | hyy
public | orderer | table | hyy
public | orderer_id_seq | sequence | hyy
public | peer | table | hyy
public | peer_id_seq | sequence | hyy
public | peer_ref_chaincode | table | hyy
public | peer_ref_chaincode_id_seq | sequence | hyy
public | peer_ref_channel | table | hyy
public | peer_ref_channel_id_seq | sequence | hyy
public | transactions | table | hyy
public | transactions_id_seq | sequence | hyy
public | users | table | hyy
public | users_id_seq | sequence | hyy
public | write_lock | table | hyy
And I start the service , I can’t login with the correct user and password.
enter image description here
[2022-06-19T16:29:11.875] [DEBUG] PgService - the getRowsBySQlCase select * from channel where name=$1 and channel_genesis_hash=$2 and network_name = $3
Can anybody help?

Creating an incremental model in DBT+Spark with no unique_key

I have a user table as follows
|------------|-----------------|
| user_id | visited |
|------------|-----------------|
| 1 | 12-23-2021 |
| 1 | 11-23-2021 |
| 1 | 10-23-2021 |
| 2 | 01-21-2021 |
| 3 | 02-19-2021 |
| 3 | 02-25-2021 |
|------------|-----------------|
I'm trying to create an incremental model to get the user's recent visited date.
Since the incremental model needs an unique key, I'm concatenating user_id||visited -> unique_id
DBT + Spark
{{ config(
materialized='incremental',
file_format='delta',
unique_key='unique_id',
incremental_strategy='merge'
) }}
with CTE as (
select user_id,
visited,
user_id||visited as unique_id
from my_table
{% if is_incremental() %}
where visited >= date_add(current_date, -1)
{% endif %}
)
select user_id,
unique_id,
max(visited) as recent_visited_date
from CTE
group by 1,2
This above model is giving me the result as follows
|------------|------------------|-----------------------|
| user_id | unique_id |recent_visited_date |
|------------|------------------|-----------------------|
| 1 | 112-23-2021 | 12-23-2021 |
| 1 | 111-23-2021 | 11-23-2021 |
| 1 | 110-23-2021 | 10-23-2021 |
| 2 | 201-21-2021 | 01-21-2021 |
| 3 | 302-19-2021 | 02-19-2021 |
| 3 | 302-25-2021 | 02-25-2021 |
|------------|------------------|-----------------------|
The output what I wanted is
|------------|------------------------|
| user_id | recent_visited_date |
|------------|------------------------|
| 1 | 12-23-2021 |
| 2 | 01-21-2021 |
| 3 | 02-25-2021 |
|------------|------------------------|
I know that for the incremental model with merge strategy, the unique_id should be in the final table in order to compare
but having the unique_id is giving the wrong output
Is there any other way around to get the max(visited) for the user?

Caasandra PRIMARY KEY column "user" cannot be restricted as preceding column "eventtype" is not restricted

The table i developed is below one
create table userevent(id uuid,eventtype text,sourceip text,user text,sessionid text,roleid int,menu text,action text,log text,date timestamp,PRIMARY KEY (id,eventtype,user));
id | eventtype | user | action | date | log | menu | roleid | sessionid | sourceip
--------------------------------------+-----------+---------+--------+--------------------------+----------+-----------+--------+-----------+--------------
b15c6780-d69e-11e8-bb9a-59dfa00365c6 | DemoType | Aqib | Login | 2018-10-01 04:05:00+0000 | demolog | demomenu | 1 | Demo_1 | 121.11.11.12
95df3410-d69e-11e8-bb9a-59dfa00365c6 | DemoType | Aqib | Login | 2018-09-30 22:35:00+0000 | demolog | demomenu | 1 | Demo_1 | 121.11.11.12
575b05c0-d69e-11e8-bb9a-59dfa00365c6 | DemoType | Aqib | Login | 2018-10-01 04:05:00+0000 | demolog | demomenu | 1 | Demo_1 | 121.11.11.12
e6cbc190-d69e-11e8-bb9a-59dfa00365c6 | DemoType3 | Jasim | Login | 2018-05-31 22:35:00+0000 | demolog3 | demomenu3 | 3 | Demo_3 | 121.11.11.12
d66992a0-d69e-11e8-bb9a-59dfa00365c6 | DemoType | Shafeer | Login | 2018-07-31 22:35:00+0000 | demolog | demomenu | 2 | Demo_2 | 121.11.11.12
But when i queried as below,
select * from userevent where user='Aqib';
Its showing some thing like this : InvalidRequest: Error from server: code=2200 [Invalid query] message="PRIMARY KEY column "user" cannot be restricted as preceding column "eventtype" is not restricted"
What is the error...........
You need to read about data modelling for Cassandra, or for example take DS220 course on the DataStax Academy. Every row has primary key consisting of the partition key that defines on which node the data is located, and clustering keys that define placement inside partition. In your case, your primary key consists at least from id, eventtype, user. To put condition on user you need to specify both id and eventtype.
You can add the index, or materialized view to access only by user, but I recommend to get more into data modelling first - define your queries, and then build table structures about queries that you need to perform.

Is it possible to write two different set of Examples in scenario outline

The requirement is to create three users and then create a template/file to add these three users
Can I achieve this in a single scenario outline?
Scenario Outline: Create users and load to a template
Given I create an user <username>
And the password as <password>
And the description as <description>
Example:
| username | password | description |
| user1 | pwd1 | user1creation |
| user2 | pwd2 | user2creation |
| user3 | pwd3 | user3creation |
When user create a template ??????
can anybody suggest how to write the template creation step and pass the usernames as parameters?
Scenario can be written like this:
Scenario Outline: Create users and load to a template
Given I have the following users:
| username | password | description |
| <username1> | <password1> | <description1> |
| <username2> | <password2> | <description2> |
| <username3> | <password3> | <description3> |
When I create template for users:
| username |
| <username1> |
| <username2> |
| <username3> |
Then users should be added to template
Examples:
| username1 | password1 | description1 | username2 | password2 | description2 | username3 | password3 | description3 |
| user1 | pwd1 | user1creation | user2 | pwd2 | user2creation | user3 | pwd3 | user3creation |
Or as an alternative without using scenario outline:
Scenario: Create users and load to a template
Given I have the following users:
| username | password | description |
| user1 | pwd1 | user1creation |
| user2 | pwd2 | user2creation |
| user3 | pwd3 | user3creation |
When I create template for users:
| username |
| user1 |
| user2 |
| user3 |
Then users should be added to template
In both cases in Given step users should be defined, created in step definition and put to some shared Map, where on When step they can be extraced and added to template.

Resources