Redis Data Structure design for 2 string as select - java

I need to store below data in Redis :
Calling Number : String
Called Number : String
Calling Name : String
Called Name : String
Time : TimeStamp
SPS Name : String
Num Id : Number
My retrieval is based on Calling Number and Called Number
This means if Calling Number and Called Number both are matched the get other details like Calling Name, Called Name etc.
Can anyone suggest best data structure from a performance perspective? I will have around 50K records for select.
If there is one 1 key then i could have used Hash but here i need to select data based Calling Number and Called Number.
One option is to concat Calling Number, Called Number and use it as key but I dont think it a correct and performance wise good solution

Related

Generate an account number with sequence

I have a requirement where I need to generate an account number and insert it into a table column in the following format.
"TBA2222011300000001" = where "TBA" is the value of another column or user sent data "22220113" implies the current date and "00000001" is a seven digit sequence that needs to be incremented and appended for every insert.
How can I append the sequence to the column, Should I do it in java or can it be done at DB end. I am currently using postgres with java and spring boot.
https://www.postgresql.org/docs/current/ddl-generated-columns.html
A generated column is a special column that is always computed from
other columns.
Several restrictions apply to the definition of
generated columns and tables involving generated columns:
The generation expression can only use immutable functions and cannot use subqueries or reference anything other than the current row
in any way.
now() is mutable function, so you cannot use Generated columns.
I am not sure why Default not working.
https://www.postgresql.org/docs/current/ddl-default.html
So now the only option is trigger.
CREATE TABLE account_info(
account_id INT GENERATED ALWAYS AS IDENTITY,
account_type text not null,
acconut_number text ) ;
So what you want is to automate:
UPDATE account_info set
account_number =
concat(
account_type,
to_char(CURRENT_DATE, 'yyyymmdd'),
to_char(account_id, 'FM00000000'));
create the function
create or replace function update_account_number() returns trigger as $$
BEGIN
UPDATE account_info set
account_number =
concat(
account_type,
to_char(CURRENT_DATE, 'yyyymmdd'),
to_char(account_id, 'FM00000000'));
RETURN NULL;
end;
$$ LANGUAGE plpgSQL;
create the trigger:
CREATE OR REPLACE TRIGGER udpate_accout_number
AFTER INSERT ON account_info
FOR EACH ROW
EXECUTE FUNCTION update_account_number();
Have an id column which is identity in postgres with start and end index as required.
For your reference to create identity column as desired
https://www.postgresqltutorial.com/postgresql-identity-column/
Have 1 more column for createdDate.
Then account number is simply a derived value TBA + formatted(DATE) + formatted(Id).
Ex -
No not a trigger just a function. There won't be any account number column in your table. It will simply be a function which takes date and identity as input and gives account number as output. Since account number is only dependent on id and date. No need to store this value at all, whenever you need the account number just call that function. Account number will not exist at all. It will always be calculated based on id and date. Simple.
Refer this in the article
Method 1: Derived Value called "markup"
The first method we may want to add to this table is a accountNumber method, for calculating our accountNumber based on current date and id. Since this value will always be based on two other stored values, there is no sense in storing it (other than possibly in a pre-calculated index). To do this, we:
CREATE FUNCTION accountNumber(id,date) RETURNS varchar AS
$$ SELECT TBA + format(id) + format(date)
$$ LANGUAGE SQL IMMUTABLE;
You need to put logic for format(id) and format(date) as per your requirement.
There is no point of storing the value which can be easily derived from other 2 columns. It would unnecessary consume space. Also maintaining data integrity and checks will be an overhead.
Creating function for derived values
https://ledgersmbdev.blogspot.com/2012/08/postgresql-or-modelling-part-2-intro-to.html
You can use the function in output as well as search.
Index would also be utilized as required.
I did the following to generate the desired account number.
Created a new sequence and appended zeros to it.
select to_char(nextval('finance_accounts_id_seq'), 'fm00000000')
Got the Current date in java using DateTimeFormatter
DateTimeFormatter dmf = DateTimeFormatter.ofPattern("yyyyMMdd");
String date = LocalDate.now().format(dmf);
Got the "TBA" from request param of the user.

what is the different betwen "equalTo" and "startAt & endAt" in firebase and when i should use "equalTo" or "startAt and endAt"?

I have been using two codes below when i'm trying to find record by email or phone number, sometimes first code working fine sometimes not working and also the second code same too.
what is the difference between codes below and when i should use "equalTo" or "startAt and endAt"?
ref.orderByChild("email")
.equalTo(str)
and
ref.orderByChild("email")
.startAt(str)
.endAt(str+"\\uf8ff")
ref.orderByChild("email").equalTo(str)
The above means that the email has to be equal to the value of str. It is the same as saying WHERE email= 'userx#gmail.com'
ref.orderByChild("email").startAt(str).endAt(str+"\\uf8ff")
This is like saying WHERE email LIKE ca% which will return all emails that start with "ca"
public Query startAt (String value)
Create a query constrained to only return child nodes with a value greater than or equal to the given value, using the given orderBy directive or priority as default.
public Query endAt (String value)
Create a query constrained to only return child nodes with a value less than or equal to the given value, using the given orderBy directive or priority as default.
The \uf8ff is simply the last character in unicode, so acts as an end guard.
Check this for queries:
https://www.youtube.com/watch?v=sKFLI5FOOHs
It's true that in "some" cases, you can achieve the same thing using either the first approach or either the other but from the official documentation regarding filtering data, each method has a difference purpose as:
equalTo() - Return items equal to the specified key or value depending on the order-by method chosen.
startAt() - Return items greater than or equal to the specified key or value depending on the order-by method chosen.
endAt() - Return items less than or equal to the specified key or value depending on the order-by method chosen.
But as a conclusion, use the first approach when you want to have a perfect match. The second approach is used usually for a search query when you want to filter data that starts with some characters. In terms of SQL, note that there isn't an equivalent to LIKE clause in Firebase but with the second approach we simulate the exact same behaviour.

How to get sequence number in windchill through API

How to get sequence number for WT.Part or Wt.Document in Windchill through API?
When I create WT.Part - number automatically generated. But I can not find any method that returns the next number. I'm using Info*Engine.
At the time of object WTPart creation windchill use OOTB oracle_seqence in order to auto generate the number.
The sequence name is mentioned in the OIR of respective object.
Like
For
WTPart it is : WTPARTID_seq
For
WTDocument it is : WTDOCUMENTID_seq
etc .
So, if you want to get next number of WTPart then you can directly call the method wt.fc.PersistenceHelper.manager.getNextSequence("WTPARTID_seq");
from your info*engine task.
For different object the name of the sequence will be different.
In 10.2 PTC introduce another method getCurrentSequence("SEQ_NAME") to get the current sequence value without incrementing the same.
Are you familar with using Java with InfoEngine? If so, you can get the sequence by:
wt.fc.PersistenceHelper.manager.getNextSequence("SEQUENCE_NUMBER_OF_YOUR_OBJECT")
The sequence number will be specified inside the "Object Initialization Rule" that is associated with your object type.
As a temporary solution - create a new Part, read the number and either use it or delete.

how can i generate a item code value with auto increment integer plus an identification integer

i'm creating a Itemcode for my inventory system i want the number system of integer values like this using java
for example this
for group 1 the code would be 001 -
0010001,
0010002
for group 2 the code would be 002-
0020003,
0020004
for group 3 the code would be 003-
0030005,
0030006
the items are encoded individually so when i add a new entry it will detect which group it belongs to and generate it desired item code the first 3 digits will be the corresponding Value identification in which group it belongs to the the next 4 digit code will just be the increment value..and would be stored as one integer using MySQL database
You need to decide:
Are the item codes to be represented as: one integer, a pair of integers (group & item), a string ... or something else.
Is the numbering scheme per the first example or the second one. (You seem to have chosen one scheme now ...)
How you are going to populate the items and codes. Do you read the codes? Do you generate them all in one go while loading items from a file. Do you create items and item ids one at a time (e.g. interactively).
How is this information going to be "stored"? In memory only? In a flat file? In a database? (MySQL ... ?)
These decisions will largely dictate how you implement the item id "generation".
Basically, your problem here is that >>you<< need to figure out what the requirements are. Once you have done that, the set of possible solutions will reduce to a manageable size, and you can then either work it out for yourself or ask a sensible question.

How to have multiple values for a key in cypher query for neo4j?

I am working with a program that i have a record for every user. My users have a property with key, PhoneNumber , and its value is an array of strings, [454457,897356]. For example if i wanted to use cypher query:
Start n=node(1)
Return n
It returns 1 record for my node(one row) that the value of column PhoneNumber is an array.
But i want to have record numbers according to the number of values in my array, means that for my example, the query returns 2 records(2 rows) and all of its attributes be the same but in the PhoneNumber column one of them has the value 454457 and the other has the value 897356. Is any way to do that? do i change my cypher query or make some changes in my java code?
Thanks.
There is no way to do that yet, within Cypher. I've submitted a request for it, though:
https://github.com/neo4j/neo4j/issues/30

Categories