Browsing:

Month: September 2024

JavaScript (JS) vs TypeScript (TS) Overview:

Comparison of TypeScript with JavaScript JavaScript Example: TypeScript Example: Advantage: TypeScript enforces that both a and b are numbers, catching type errors at compile time. Type Annotations in TypeScript vs Python In TypeScript, types are applied similarly to how Python Read more…


SQL question -time interval (seven-day streak of visiting the same URL)

Given a table with event logs, find the percentage of users that had at least one seven-day streak of visiting the same URL. Note: Round the results to 2 decimal places. For example, if the result is 35.67% return 0.35. Read more…


How Pandas and PySpark handle adding a column with fewer rows than the existing DataFrame

Pandas: When you add a column with fewer rows in Pandas, the remaining rows will be filled with NaN (Not a Number) to represent the missing data. Pandas DataFrames allow mixed data types and handle missing values using NaN by Read more…


Can use the “with” statement to manage resources

Yes, you can use the with statement to manage resources for any class that implements the __enter__ and __exit__ methods. The with statement is designed to create a context for managing resources, ensuring that certain actions are automatically taken when Read more…


Implementing Before and After Logging in a Function Using a Decorator

Here’s an example of how you can write a decorator to execute logic before and after the original method: login_execution(function): my_custom_wrapper(*args, **kwargs): Pre-execution logic: Argument modification: Calling the original function: Post-execution logic: In this example, you’re creating a decorator named Read more…


SQL window function with “ORDER BY” and without “ORDER BY”

Dataset Example: Assume we have the following sales data for different employees across several months: emp_id sales month 1 100 Jan 2 200 Jan 3 300 Jan 4 150 Feb 5 250 Feb 6 350 Mar 7 400 Mar Now, Read more…


GROUP BY vs. WINDOW FUNCTIONS

These two queries use different SQL techniques (GROUP BY vs. WINDOW FUNCTIONS) and have distinct purposes, even though they both work with the same dataset. Here’s a detailed comparison: 1. First Query (Using GROUP BY): What it does: Output: Use Read more…


AWS Glue Data Catalog is schema-on-read or schema-on-write

AWS Glue Data Catalog follows a “schema-on-read” approach rather than “schema-on-write.” Explanation: AWS Glue Data Catalog: AWS Glue follows a schema-on-read model because: Thus, Glue is an example of a schema-on-read system where the schema is flexible and inferred upon Read more…


SQL questions

2. To delete duplicates by keeping first record 3. List all employees whose salaries are above their manager’s salary employee (emp_id, salary, dept_id, manager_id) , manager also could be an employee homself Explanation: This query will return all employees whose Read more…


Complex data types such as nested structures, arrays, and maps in CSV format

When dealing with complex data types such as nested structures, arrays, and maps in CSV format, handling them can be more challenging than in Parquet because CSV files are inherently flat and do not support hierarchical or complex data structures Read more…