Posts

Featured Post

SQL Interview Success: Unlocking the Top 5 Frequently Asked Queries

Image
 Here are the five top commonly asked SQL queries in the interviews. These you can expect in Data Analyst, or, Data Engineer interviews. Top SQL Queries for Interviews 01. Joins The commonly asked question pertains to providing two tables, determining the number of rows that will return on various join types, and the resultant. Table1 -------- id ---- 1 1 2 3 Table2 -------- id ---- 1 3 1 NULL Output ------- Inner join --------------- 5 rows will return The result will be: =============== 1  1 1   1 1   1 1    1 3    3 02. Substring and Concat Here, we need to write an SQL query to make the upper case of the first letter and the small case of the remaining letter. Table1 ------ ename ===== raJu venKat kRIshna Solution: ========== SELECT CONCAT(UPPER(SUBSTRING(name, 1, 1)), LOWER(SUBSTRING(name, 2))) AS capitalized_name FROM Table1; 03. Case statement SQL Query ========= SELECT Code1, Code2,      CASE         WHEN Code1 = 'A' AND Code2 = 'AA' THEN "A" | "A

Exclusive Apache Kafka Top Features

Image
Here are the top features of Kafka. It works on the principle of publishing messages. It routes real-time information to consumers far faster. Also, it connects heterogeneous applications by sending messages among them. Here the prime component (a.k.a message router) is a broker. The top features you can read here. The exclusive Kafka features The message broker provides seamless integration, but there are two collateral objectives: the first is to not block the producers and the second is to not let the producers know who the final consumers are. Apache Kafka is a real-time publish-subscribe solution messaging system: open source, distributed, partitioned, replicated, commit-log based with a publish-subscribe schema. Its main characteristics are as follows: 1. Distributed. Cluster Centric design that supports the distribution of the messages over the cluster members, maintaining the semantics. So you can grow the cluster horizontally without downtime. 2. Multiclient. Easy integratio

Explained Ideal Structure of Python Class

Image
When you are designing a class, you need to ensure that the classification of its critical parts is outlined at the beginning. The clearer the initial design, the more performant and scalable the class is. Some of the components in the order in which they should be defined in the class are mentioned as follows. Ideal structure of a class Class variables Constants or default variables are usually defined at the top of the class. For someone who is reading the code, it comes as an easy-to-view consolidated list, and for the interpreter it ensures that all such variables are processed before diving into the main logic of the class, including any other Instance method or constructor. The __init__ method The __init__ method provides information about inputs needed and how to instantiate the class. It is also the constructor of the class, which the very first method called while initializing the class . Special Python methods These methods change the functionality of the class or provide add

How to Initialize Class Variables? The Purpose of Init Method in Python

Image
The init method is like a constructor in Java. But the usage is different in Python.  Here's the best example to write Class in Python using init method.  The init executes by default and it will initialize all the variable. The dog_1 is an instantiation of dog class. When you print the dog_1, it prints as "I am in the init method", which is from the "init" method. The self means this class. It is mandatory. Not only self, but you can also give any name in that place. Instead of "self" you can give as "This_is_Python_Self". It also will work. How to use init method class dog:    def __init__(self):          print("I am in init method") Now, instantiating the class dog_1=dog() print(dog_1) The output from the above display is as below: I am in init method <__main__.dog object at 0x7fe7b5875be0> Related posts The best Python Interview Questions

How to Unpack a List into Variables Quickly in Python

Image
Here are two examples to unpack a list in Python. You can do it easily by using splat operator. The asterisk in python is called a Splat operator. Here are two splat operators - Single and Double. Below, you will find examples. 1. Single splat operator Consider, for example, this code: abc = [1,2,3,4] print(abc)  Here the output will be: [1, 2, 3, 4] What if you didn't want the list output in list format? What if all you wanted was the list of values to be written to the output console? You could write them using a loop and one of the output functions, but Python prefers an easier way: print(*abc) 1 2 3 4 2. Double splat operator Here, I have written a function: def func(x,y,z):        return x + y + z print(func(**d)) It will show '6' as output. Since, I have assigned values for x,y, and z in a dictionary. So by using a double splat operator you assign values to the function. d = {  'x': 1,  'y': 2,  'z': 3  } Related posts 3 Advanced methods to rea

9 Top Git Terms You Should have Read By now

Image
GIT is version control system. That means it manages your code versions. However, I have given here most frequently asked terms in interviews. 1. Git Vs GitHub This is the first question you ( even me also) might confuse about. Git is the version control system. Whereas  GitHub is a repository framework . Also, you can say GitHub is Git hosting service. 2. What is Branch Git is a lightweight version control system. In simple terms, a Branch is a separate line of development. You can have any number of branches in Git. 3. What is Topic Each branch in Git refers to a particular purpose. So the topic tells about the purpose. 4. Clone In easy terms, the Clone means copying an existing repository. So you can say it is just a copy of the existing repository. 5. What is Push You can say Push means updating the existing repository. In other words, developers push their changes to a repository that you set up. 6. Merge Merge unifies two or more commit history branches. That means it merges two

3 Best Methods to Read Files in Python

Image
Python supports three specific methods to read files- read, readline, readlines. All these you use on files. Each has its unique purpose. Below are the best examples. 3 Methods to read file read readline readlines Method-1: read It reads records from file in sequence. Here, file.txt is sample file with single row. file.txt abcdefghijk file_object.read(2) ==> you will get 'ab' file_object.read(4)  ===> you will get 'cdef' Here, the multiple read methods read the data in sequence. The read(x) method will read only the number of characters that mentioned in the read method. Again, if you give multiple read methods then it will read in sequence. Method-2: readline It reads the file line by line. Here, file.txt is a file with single row. file.txt abcdefghijk f ile_object.readline() ==> you will get ' abcdefghijk ' Here, it reads the file line by line. Method-3: readlines It reads all the records at a time. Here, file.txt is a file with two rows. file.txt ab

How to Write Recursive Function in Python Quickly

Image
Here's an example to write RECURSIVE function in Python. It acts like a loop that iterate within the function to perform some operation. Precisely, if you call the same function from function is called  recursive function .     Python recursive function Here are four rules a developer should know before writing recursive function in Python: There must be a key variable, which will be responsible for the termination of recursion. To determine the base value , which the key variable has to meet to reach the termination. To make sure the key variable must approach the base value in every recursive call. To make the recursive function terminate when the key variable reaches the base value. Python recursive example Here is an example python recursive function. # This program computes the factorial of a number using recursion #function definition def fact(n): "computes factorial using recursion" if n == 0:     return 1 else :     return n * fact(n - 1) # Function call num = i