Categories
Database Development

Varchar vs UUID as primary key in terms of performance and sharding

I have these 2 tables one is the order which keep the order related information and the other table is order details which store all the items in for a particular order. CREATE TABLE `orderMain` ( `orderNumber` varchar(10) NOT NULL, `userID` mediumint(9) NOT NULL, `orderQty` tinyint(4) UNSIGNED NOT NULL, `orderAmount` float NOT NULL, `orderDateTime` timestamp […]

Categories
Mastering Development

Mysql : Get most recent value for specific users

I got a table with three colums : lastUpdate, userId, and userScore I want to filter that to get only the most recent userScore for 3 userId, and order them by userScore. So far I tried : SELECT * FROM `mybase` WHERE `userId`=”120683″ OR `userId`=”206116″ OR `userId`=”259903″ GROUP BY userId ORDER BY userScore DESC But […]

Categories
Mastering Development

Appending an array field, from another field, in MongoDB documents (with MongoClient) in Node.js

I have a collection called Users. Here is an example of a doc. {“_id”:{“$oid”:”xxxxxxxxxxxxxxxxxxx”}, “userId”:”ANKIT”, “token”:”token123″, “badge”:{“$numberInt”:”0″}, “useLocalCurrency”:true, “notifyCustomerRejected”:true, “notifyReworkRequest”:true, “notifyMoaApproved”:true, “notifyCustomerAccepted”:true, “__v”:{“$numberInt”:”0″}, “tokens”:[]} I am trying to push the token into the tokens array for all the docs in a DB migration. This is what I have tried : export function up(next) { let […]

Categories
Database Development

MariaDB – Slow GROUP BY on 55 Million row table

I have a table with ~55 million rows, which holds user music listening history. I want to generate a report for the last quarter detailing how many times songs have been played per user. The query boils down to: select userId, trackId, count(*) from events — about 9.379.254 rows in this time range where occurredAt […]

Categories
Mastering Development

base R: Aggregate and sum by two columns

I am trying to use aggregate function to achieve same result as with SQL query however: SQL: sqldf(” SELECT PhotoID, UserID, SUM(Points) AS PhotoTotalPoints FROM Photos GROUP BY PhotoId, UserId”) 116 186 rows. R base: aggregate(x = Photos[“Points”] , by = Photos[c(“PhotoId”,”UserId”)] , FUN = sum ) 114 950 rows. Using dplyr: Photos %>% group_by(PhotoId,UserId) […]

Categories
Mastering Development

How to remove two nodes from Firebase Realtime Data base at once

I am trying to create a messaging app using Firebase Realtime Database.What i am trying to do is automatically delete chats after user has seen them and didn’t respond to the messages. Messages are sent using this this logic private void sendMessage(String sender, final String receiver, String message) { HashMap<String, Object> hashMap = new HashMap<>(); […]

Categories
Mastering Development

Use object methods inside UDF function pyspark

I’m trying to update a dataframe’s column based on a complex computation (within a method inside a class). From what I’ve learned so far, you can update columns in dataframes using user defined functions. Unfortunately, user defined functions must be static. Is there any workaround? Here’s the relevant part of my code: ”’ Louvain Community […]

Categories
Mastering Development Software

DDD, Aggregate Root and entities in library application scenario

I’m building a library application. Let’s assume that we have a requirement to let registered people in the library to borrow a book for some default period of time (4 weeks). I started to model my domain with an AggregateRoot called Loan with code below: public class Loan : AggregateRoot<long> { public static int DefaultLoanPeriodInDays […]

Categories
Mastering Development System & Network

Migration of password hashes from glftpd 2.01 (PKCS5_PBKDF2_HMAC_SHA1) to proftpd + mod_sql_passwd

For migrating from the de-factor closed source glftpd 2.01 to proftpd I need to migrate password hashes of the user accounts from glftpd to proftpd. Reading about the topic I figured mod_sql_passwd should do the trick. I therefore set up my proftpd server like this: <global> SQLBackend mysql SQLAuthTypes Crypt SQLAuthenticate users groups SQLConnectInfo testdbuser@testdbhost […]

Categories
Mastering Development System & Network

Migration of password hashes from glftpd 2.01 (PKCS5_PBKDF2_HMAC_SHA1) to proftpd + mod_sql_passwd

For migrating from the de-factor closed source glftpd 2.01 to proftpd I need to migrate password hashes of the user accounts from glftpd to proftpd. Reading about the topic I figured mod_sql_passwd should do the trick. I therefore set up my proftpd server like this: <global> SQLBackend mysql SQLAuthTypes Crypt SQLAuthenticate users groups SQLConnectInfo testdbuser@testdbhost […]