<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tarannum Khan on Medium]]></title>
        <description><![CDATA[Stories by Tarannum Khan on Medium]]></description>
        <link>https://medium.com/@light_khan?source=rss-e7f659b69cf6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*-nmo5vbgbzPMPBbe.</url>
            <title>Stories by Tarannum Khan on Medium</title>
            <link>https://medium.com/@light_khan?source=rss-e7f659b69cf6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 03:56:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@light_khan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What the Heck is ECID and how to Plug it in log4j]]></title>
            <link>https://medium.com/swlh/what-the-heck-is-ecid-and-how-to-plug-it-in-log4j-cd157e2a528e?source=rss-e7f659b69cf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd157e2a528e</guid>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[execution-context]]></category>
            <category><![CDATA[log4j2]]></category>
            <category><![CDATA[diagnostic-testing]]></category>
            <dc:creator><![CDATA[Tarannum Khan]]></dc:creator>
            <pubDate>Sat, 11 Jul 2020 17:49:24 GMT</pubDate>
            <atom:updated>2020-07-14T00:32:59.720Z</atom:updated>
            <content:encoded><![CDATA[<p>Every one of us, have faced bad days when we have got a production bug to solve. If you have ever faced bugs in production(i<em>f not, damn you are lucky)</em>, the first thing is to scrutinize the logs. In the vast sea of logs, finding the right sequence of logs that are relevant to your problem is a painstaking task. <em>My eyes gonna burn, but the quest never ends. </em>WebLogic&#39;s ECID makes life easier by tracking the full request from inception to conclusion.</p><h3><strong>Ok, But what is ECID?</strong></h3><p>ECID(Execution context id) is injected by middleware as a request enters the system and stays the same throughout the full cycle of request. It’s a unique way to identify a request across tiers. You can get a hold of the ECID which you have to look into the logs from the response headers of a request.</p><h3>Where to get ECID?</h3><p>Talk is cheap, here is the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de55088960ba7ae1c1da42c9f686b07d/href">https://medium.com/media/de55088960ba7ae1c1da42c9f686b07d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b6244782f49071614005d505e6e58ff/href">https://medium.com/media/8b6244782f49071614005d505e6e58ff/href</a></iframe><p>The <strong>DiagnosticContextHelper</strong> class has the static method <strong>getContextId </strong>which gives the ECID. For resolving this class, the <strong><em>wls-api</em></strong> dependency has to be added at compile time.</p><h3>How to plug ECID in Apache log4j?</h3><p>We have to create a custom pattern converter and pass the value of ECID fetched from the <strong>DiagnosticContextHelper</strong> class to log4j2. The first step is to add an additional argument ECID in the pattern in log4j2.xml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3430756c1ab8a14967253e9779c3cc53/href">https://medium.com/media/3430756c1ab8a14967253e9779c3cc53/href</a></iframe><p>The next step is to create a custom class <strong>ECIDPatternConverter</strong> which extends the <strong>LogEventPatternConverter </strong>class for passing additional attributes to the logger. The <strong>LogEventPatternConverter </strong>is a class in the log4j module.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/627c688e8b017195686cae902b82e47d/href">https://medium.com/media/627c688e8b017195686cae902b82e47d/href</a></iframe><p>The method <strong><em>format</em></strong> of the <strong>LogEventPatternConverter</strong> class is overridden to append the ECID in loggers. The value of the converter key(<strong><em>e</em></strong> in the above snippet) should be the same as given in the log4j2.xml file. For comprehending the log4j pattern converter in detail, go through <a href="https://logging.apache.org/log4j/2.x/manual/extending.html#PatternConverters">log4j2 documentation</a>.</p><p>For default Weblogic logs, we directly get the ECID. If for some reason, the ECID is not getting logged, then you need to enable it in the admin console by going to Weblogic home, then to diagnostics and then to context.</p><h3>Lastly, how do the logs look?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u5a58CTIoZ9L7SEd3UqHhw.png" /></figure><p>Filtering logs by ECID, we come out from the labyrinth of random data coming between the requisite log sequence. For getting the full code, please visit <a href="https://github.com/DartingMelody/ECIDDemo">https://github.com/DartingMelody/ECIDDemo</a>. In conclusion, let’s have good coverage of logs in the code to use ECID effectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*620x5QR-km0XmKdB2xaI-g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd157e2a528e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/what-the-heck-is-ecid-and-how-to-plug-it-in-log4j-cd157e2a528e">What the Heck is ECID and how to Plug it in log4j</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic loading of classes using Google Guice]]></title>
            <link>https://medium.com/@light_khan/dynamic-loading-of-classes-using-google-guice-5e5c263cb0fc?source=rss-e7f659b69cf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e5c263cb0fc</guid>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[abstraction]]></category>
            <category><![CDATA[guice]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[google-guice]]></category>
            <dc:creator><![CDATA[Tarannum Khan]]></dc:creator>
            <pubDate>Mon, 08 Jun 2020 18:52:31 GMT</pubDate>
            <atom:updated>2020-06-08T18:52:31.363Z</atom:updated>
            <content:encoded><![CDATA[<p>There are various scenarios when you want to cleanly separate your delicate production code with your adventurous testing code. For example, you want to pick the configuration files instead of going to the database or you don&#39;t want to go to the security store, just read it via a file in your testing world.</p><p>With the help of <a href="https://github.com/google/guice">Google Guice</a>, we will tweak the <a href="https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/Injector.html">Guice Injector</a> to create a custom one, which solves our problem to run code in a faster and efficient manner in the non-production environment. The beauty of the code to dynamically load classes will be completely abstracted out. Any developer can come and start working on different environments without ever knowing how their lives have been simplified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j-GSZ-ULUy6qVzwyqpqOVw.png" /></figure><p>There are two main ingredients of formulating this magic, Google Guice and <a href="https://en.wikipedia.org/wiki/Dependency_injection">dependency injection</a>. Generally, the Guice is used to create a Guice injector by passing the required <a href="https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/Module.html#:~:text=A%20module%20contributes%20configuration%20information,s%20and%20some%20bootstrapping%20code.">module</a> to it. Then, the Guice injector injects the class based on the bindings in the module. Let’s comprehend it better by looking at the below code. The <strong><em>ServiceModule</em></strong> class is passed to the Guice injector which contains the binding of the implementation class to the interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fe1cf5e9e35f2fe997b6012b676c5bd/href">https://medium.com/media/2fe1cf5e9e35f2fe997b6012b676c5bd/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a22d5fc39f2488d5cbb73d7f19015022/href">https://medium.com/media/a22d5fc39f2488d5cbb73d7f19015022/href</a></iframe><p>From the above code snippet, we can see the <strong><em>APIClient</em></strong> interface is binded to <strong><em>APIClientImpl.class</em></strong>, so when the APIClient interface is passed as an argument to the Guice injector, it will resolve which implementation class to instantiate by looking at the module passed to the Guice injector. So, here <strong><em>APIClientImpl</em></strong> class will be injected to the <strong><em>apiClient</em></strong> variable.</p><p>For the dynamic loading of the classes, the dependency injection will be done by a custom Guice injector. The custom Guice injector i.e. <strong><em>GuiceInjectorUtil </em></strong>class under the hood is using the Google Guice itself.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e97924572408350c9ecc7a5cb88646db/href">https://medium.com/media/e97924572408350c9ecc7a5cb88646db/href</a></iframe><p>For setting the stage of the custom Guice injector class, I am introducing <strong><em>guice.properties</em></strong> and <strong><em>guiceLocal.properties</em></strong> which stores the implementation classes corresponding to the interfaces, we want to inject into other classes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb6f68b944a2eb6c4eafad61a46e857e/href">https://medium.com/media/fb6f68b944a2eb6c4eafad61a46e857e/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ce06b66a1c21a3d84cc56f9c8b3f52c/href">https://medium.com/media/8ce06b66a1c21a3d84cc56f9c8b3f52c/href</a></iframe><p><strong><em>The GuiceInjectorUtil class is where the magic happens</em></strong>. This class first reads the <strong><em>guice.properties</em></strong> file. Then, for every property value for the key, it instantiates a module using <a href="https://www.javatpoint.com/java-reflection">reflections API</a>. The injector is created by passing the list of modules to the <em>Guice.createInjector </em>command.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afb7564608b9a04b9f8fc57c163ddbb3/href">https://medium.com/media/afb7564608b9a04b9f8fc57c163ddbb3/href</a></iframe><p>The question arises of why are we ingesting so much hassle when we can simply utilize the standard Guice injector provided by Google. To discover the answer, let’s delve into the fun part whereby a mere change in the build.xml (pom.xml for maven users), we can dynamically load the modules.</p><p>I am using ant for building the java project, you can use maven also. For production, we will go with the general command to build the war file. For non-production environments, we are creating a new command. to build the war file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4cf8cec7191d1491ffdabba7860791d/href">https://medium.com/media/c4cf8cec7191d1491ffdabba7860791d/href</a></iframe><p>To create an additional <strong><em>dist-local</em></strong> command, a piece of code is added to the build.xml. A similar code can be added to the pom.xml to achieve the same result for maven users.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c9e54f15d26e05e2883338274d08e74/href">https://medium.com/media/6c9e54f15d26e05e2883338274d08e74/href</a></iframe><p>When we run the <strong><em>ant clean dist-local </em></strong>command, it copies the content of <strong><em>guiceLocal.properties</em></strong> file to the <strong><em>guice.properties</em></strong> file in the build directory. On running ant clean command, it copies the content of <strong><em>guice.properties</em></strong> file to the <strong><em>guice.properties</em></strong> file in the build directory.</p><p>In the<strong><em> GuiceInjectorUtil </em></strong>class discussed earlier, the modules(to resolve which implementation class to inject corresponding to the interface) to be created are read from the<strong><em> guice.properties</em></strong>. On running the <strong><em>ant clean</em></strong>, it loads the <strong><em>guice.properties</em></strong> corresponding to the required implementation classes in the production environment. On running the <strong><em>ant clean dist-local </em></strong>command, the content of the <strong><em>guiceLocal.properties</em></strong> (as the content is copied to<em> guice.properties</em> while building the war file in build.xml) will be read by the custom injector.</p><p>So, different implementation classes corresponding to the interface will be injected when calling the custom Guice injector in this case. Viola, we can load different implementation classes based on different build commands(which in turn can be based on different environments).</p><p>To get the full picture of the dynamic loading of classes and leverage the beauty of Google Guice in a better way, you can visit <a href="https://github.com/DartingMelody/Guice">https://github.com/DartingMelody/Guice</a>. This Github <a href="https://github.com/DartingMelody/Guice">Guice</a> repository contains the full example to read from the config file in the testing environment and read from the database/store in the production environment. By not going to the database or another API, we can significantly enhance the efficiency and speed of the testing environment.</p><p>In this way, <strong><em>you can write different logic(simple to complex) for different environments and can load any number of modules and can bind them to any implementation class you want.</em></strong> The best part is the whole code is abstracted. After writing the modules and implementation classes, any new user can come and just inject the interface without knowing the background details of which class is getting implemented behind the scenes.</p><p>Feel free to contact me at <a href="/service/mailto:tkhaniitr@gmail.com">tkhaniitr@gmail.com</a>. I will be available to clear any doubts and interact with you, given that I am not that boring 😀.</p><p>Till then, happy coding. 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e5c263cb0fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding SQL basics]]></title>
            <link>https://medium.com/@light_khan/understanding-sql-basics-1ec1e7239796?source=rss-e7f659b69cf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ec1e7239796</guid>
            <category><![CDATA[indexeddb]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[oracle-database]]></category>
            <category><![CDATA[sql-developer]]></category>
            <category><![CDATA[query-understanding]]></category>
            <dc:creator><![CDATA[Tarannum Khan]]></dc:creator>
            <pubDate>Fri, 13 Mar 2020 03:55:01 GMT</pubDate>
            <atom:updated>2020-03-13T03:55:01.459Z</atom:updated>
            <content:encoded><![CDATA[<p>Learning essentials of database comes as a great aid for everyone. As a developer, there are scenarios where you have to write complicated sql(structured query language) queries while implementing APIs or services. This blog provides the tools to choose the right sql queries based on the use case and keeping performance in mind. Let’s embark upon the roller-coster journey to sql mastery.</p><h3><strong>QUERIES</strong></h3><p>The queries is where it all starts. The order in which the clauses should be used are as follow: <strong>SELECT, FROM, WHERE, GROUP BY, HAVING </strong>and<strong> ORDER BY</strong>. The<strong> where</strong> clause is used for restricting particular rows from the table whereas the <strong>having</strong> clause is used with <strong>group by</strong> to restrict the groups of rows returned from the query.</p><p>There are also aggregate functions which are used commonly in the queries like <strong>avg, count, min, max, sum</strong>. They can be used along with the group by clause to apply on each group or can be used without group by to apply on the whole table.</p><p>One relevant point to remember while dealing with aggregate functions is that regular columns cannot be selected along with columns on which aggregate functions are implemented until the query has a group by on the regular column. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f297d5012f1eb96e63d845327218ebc/href">https://medium.com/media/2f297d5012f1eb96e63d845327218ebc/href</a></iframe><p>This query will throw an error “not a single-group group function”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8ee45abe514c2544ea159cb6104426e/href">https://medium.com/media/d8ee45abe514c2544ea159cb6104426e/href</a></iframe><p>This query will work properly as the regular table column is used by group by clause.</p><h3><strong>TO_CHAR V/S TO_DATE</strong></h3><p>Every one of us at some point would have been confused of using to_char or to_date while getting our hands dirty with date types. So, lets clear the air. TO_CHAR converts numbers, dates, strings, etc to a specific format. Some sql queries and their output are given below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee1bff3471774af63dfc2c7490b6a543/href">https://medium.com/media/ee1bff3471774af63dfc2c7490b6a543/href</a></iframe><p><strong>Output</strong>: Rs27,000</p><p><strong>Explanation</strong>: The L character represents local currency configured in the database. It can be different for different countries. The combinations of letters and number describes how to format the data returned from the database.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c36d3721bd5d230b4d4a040ef703a0a0/href">https://medium.com/media/c36d3721bd5d230b4d4a040ef703a0a0/href</a></iframe><p><strong>Output</strong>: 11/MAR/2020</p><p><strong>Explanation</strong>: The to_char function displays the date type into the specified format.</p><p>When you are defining your query, TO_DATE function lets the sql know that the date is of this specified format and save it accordingly to db.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7f782d4ff5a8cfb6939a85d9eb2c7ce/href">https://medium.com/media/c7f782d4ff5a8cfb6939a85d9eb2c7ce/href</a></iframe><p><strong>Output</strong>: 27–01–96</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/789bb06610318c9477661009806e849f/href">https://medium.com/media/789bb06610318c9477661009806e849f/href</a></iframe><p>Output: Error as the format to be mapped to doesn’t match the data provided to the <strong>to_date</strong> function.</p><p><strong>Performance comparison between to to_char and to_date</strong></p><p>Below are two queries doing the same thing:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d279240ef840333b49f7616822d42f5/href">https://medium.com/media/3d279240ef840333b49f7616822d42f5/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a13919a5722553ec4b5ad6589e35162d/href">https://medium.com/media/a13919a5722553ec4b5ad6589e35162d/href</a></iframe><p>The first query is more expensive than the second query because every row’s start_date and end_date is converted into characters which is not in the second case. Also, if their is indexing on start_date and end_date, as these columns format has been changed now, <a href="https://oracle-base.com/articles/misc/cost-based-optimizer-and-database-statistics">cost based indexer(CBO)</a> won’t be able to do indexing on it.</p><p>A very important point to note is when expressions are converted(i.e. <a href="http://www.sqlines.com/oracle/functions/nvl"><strong>NVL</strong></a>, <a href="https://www.w3schools.com/sql/func_sqlserver_coalesce.asp"><strong>COALESCE</strong></a>, etc) in <strong>where</strong> clause CBO will not be able to use index on that column which may lead to huge reduction in performance.</p><p><strong><em>“In general, for date handling purpose like insert, update, to_date should be used. While showing the output in the preferred format, to_char should be used.”</em></strong></p><h3>JOINS</h3><p>Another construct which comes again and again are JOINS. JOIN is use to join the table through their columns. JOIN in sql queries by default means inner join. Other joins are<strong> inner join, left join, right join </strong>and<strong> full outer join</strong>. You can join the table depending on your preference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*xMgao-gIyvn20K8bvrU8Ag.png" /><figcaption>Different type of joins in sql query</figcaption></figure><h4>DML(Data manipulation language) VS DDL(Data definition language)</h4><p>These are essence to writing queries ranging from simple to complex ones. Understanding DDL and DML is core to writing efficient queries. <a href="https://www.w3schools.com/sql/sql_insert.asp"><strong>Insert</strong></a><strong>, </strong><a href="https://www.w3schools.com/sql/sql_update.asp"><strong>update</strong></a><strong>, </strong><a href="https://www.w3schools.com/sql/sql_delete.asp"><strong>delete</strong></a><strong> </strong>are<strong> </strong>DML transactions and <a href="https://www.w3schools.com/sql/sql_create_table.asp"><strong>create</strong></a><strong>, </strong><a href="https://www.w3schools.com/sql/sql_alter.asp"><strong>alter</strong></a><strong>, </strong><a href="https://www.w3schools.com/sql/sql_drop_table.asp"><strong>drop</strong></a><strong>, </strong><a href="https://www.tutorialspoint.com/sql/sql-truncate-table.htm"><strong>truncate</strong></a><strong> </strong>are DDL transactions. After DML transactions, a <strong>commit</strong> or <strong>rollback</strong> needs to be done depending on whether you want to save or not save the changes done by transaction. In DDL transactions, commit or rollback can’t be done.</p><p>The interesting aspect is DML transactions maintains the logs, so that redoing is possible whereas in DDL transactions minimum logging is in transaction log. So DDL are performance wise faster. Lets compare two queries which are doing the same thing but the first one is a DML transaction and the second one is a DDL transaction.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c6151932e0aafae106c805a2573f54c/href">https://medium.com/media/5c6151932e0aafae106c805a2573f54c/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/681b7d4f03c8dfa00f26ae6cc3560ae6/href">https://medium.com/media/681b7d4f03c8dfa00f26ae6cc3560ae6/href</a></iframe><p>The first one is slower as the DML transaction has to maintain the logs for redoing purpose. Also, Delete is executed using a row lock whereas truncate is executed using a table lock. Point to note is there can be no where clause in truncate whereas in delete where clause is possible. Truncate utilises less transaction space than delete statements.</p><p>Once you run a DML transaction on particular rows of the table, a lock is acquired for these rows. Until you commit it, the lock is not released. In between, if any other user try to access the locked rows, they won’t be able to perform their transaction and will wait for the lock to be released. It’s very important to commit once you are done with your changes, so that other apis/users hitting the same records won’t be effected.</p><h3>COMPLEX QUERIES</h3><p>A lot of times, subqueries are written as a part of the queries. The query within parenthesis or the sub query is executed first than the outer queries are executed.<strong> “<em>Subqueries can reside in the FROM, WHERE or SELECT clause”</em></strong><em>. </em>Inline query is when the subquery is in the WHERE clause. Correlated query is when the inner queries depends on the outer queries.</p><p>Correlate query example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ead3fb3dbd773cdf9fc91e4e5dc4113a/href">https://medium.com/media/ead3fb3dbd773cdf9fc91e4e5dc4113a/href</a></iframe><p>For these type of queries, the inner query is executed once for each row of the outer query.</p><h3>INDEXES</h3><p>Performance improvement discussions on databases are incomplete without indexes. The Indexes are schema objects to improve data access performance using sql queries created on specific sets of columns. Indexes can be of various types. The most common type of index is <a href="https://en.wikipedia.org/wiki/B-tree"><strong>Btree</strong>.</a> Index can be created by user by using the following query.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5be9f9d6ff36f691a962dd4e36e0b1dd/href">https://medium.com/media/5be9f9d6ff36f691a962dd4e36e0b1dd/href</a></iframe><p>The picture below show a basic view how the Btree data structure stores the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*PsYlZ7Sg7Ifg0kA2Hmqc6Q.png" /><figcaption>Indexing in Btree</figcaption></figure><p>Data is stored in the leaf blocks. Branch blocks store the range of data. Indexes should be created on those columns on which normally search is performed or the columns which are generally used in WHERE clause for those tables. On creating more indexes, the performance of the insert, update and delete is reduced as the indexes may be updated while performing these operations . For a Btree data structure, the range can be changed as more node can be added in insert or reduced in delete action in the Btree increasing the time to perform these actions. The indexes are separate objects, not specific to a table. So for a schema, each index name should be unique. On dropping or adding the indexes, the data of the table will not be effected as they are separate schema objects.</p><p>To view all the indexes of the table, this sql command is very handy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32d46cc2cf97214123de4ee4ed81bbe7/href">https://medium.com/media/32d46cc2cf97214123de4ee4ed81bbe7/href</a></iframe><h3>SEQUENCES</h3><p><a href="https://www.geeksforgeeks.org/sql-sequences/">Sequences</a> are also schema objects to generate set of integers like 1,2,3 and so on. They are independent of the tables on which they are being used. Instead of creating sequence, <a href="https://www.oracletutorial.com/oracle-basics/oracle-identity-column/">identity</a> can be created which under the hood are sequence for table. Identity are of three types:</p><ol><li><strong>ID NUMBER GENERATED ALWAYS AS IDENTITY </strong>— if a user try to insert into the identity column, an error is thrown as the identity column is always generated.</li><li><strong>ID NUMBER GENERATED BY DEFAULT AS IDENTITY</strong> — if a user try to insert into the identity column, no error will be thrown. If no value is passed for the identity column, it will be generated. If null is inserted into the identity column, an error will be thrown.</li><li><strong>ID NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY</strong> — If no value or null is inserted, a value will be generated for the identity column.</li></ol><h3>VIEWS</h3><p>Views come in handy while simplifying queries. A <a href="https://www.geeksforgeeks.org/sql-views/">view</a> is a query stored as a db object. It can be accessed through other sql queries. Views acts like table but they are not as no physical space is allocated to a view. Below is the sql query to create the view</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12c8dc756750e170790587528b822f2c/href">https://medium.com/media/12c8dc756750e170790587528b822f2c/href</a></iframe><h3>EXPLAIN PLAN</h3><p>Oracle sql developer provides an amazing tool to give an in-depth analysis of the query, with processing of joins, how the index will improve the query or not. The explain plan displays the execution plan chosen by the Oracle optimiser for SELECT, UPDATE, INSERT, and DELETE statements. A statement’s execution plan is the sequence of operations Oracle performs to run the statement.</p><p>The row source tree is the key of the execution plan. It shows the following information:</p><ol><li>An ordering of the tables referenced by the statement</li><li>An access method for each table mentioned in the statement</li><li>A join method for tables affected by join operations in the statement</li><li>Data operations like filter, sort, or aggregation</li></ol><p>There is an icon in oracle sql developer which directly runs the explain plan for the query. If you want to use the sql statements to run the explain plan, they are:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1925b677709254352bde37845e8877e0/href">https://medium.com/media/1925b677709254352bde37845e8877e0/href</a></iframe><p>The explain plan results let you determine whether the optimiser selects a particular execution plan, such as, nested loops join. It also helps in comprehending the optimiser decisions, such as why the optimiser chose a nested loops join instead of a hash join, and lets you understand the performance of a query, so you can tweak the query accordingly.</p><p>The above information are building blocks for writing complex and high performance query depending on the use case. Feel free to contact me at tkhaniitr@gmail.com, in case of any queries not necessarily sql ones 😀. Hope the article proves helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ec1e7239796" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mock testing in python using vcrpy]]></title>
            <link>https://medium.com/@light_khan/mock-testing-in-python-using-vcrpy-ff3eb05ae5ec?source=rss-e7f659b69cf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff3eb05ae5ec</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[unit-testing]]></category>
            <dc:creator><![CDATA[Tarannum Khan]]></dc:creator>
            <pubDate>Sun, 15 Jul 2018 13:19:35 GMT</pubDate>
            <atom:updated>2018-07-15T13:21:57.113Z</atom:updated>
            <content:encoded><![CDATA[<p>As a developer, someday or the other you will stumble into the world of testing. For legacy code, test is a necessity. The code is full of logic, it’s alive and it’s core to any application. We need to keep going back to the code to update it, so tests are crucial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*jvFD4cdUG2Mt2FmtqlRklw.png" /></figure><p>While working with the <a href="https://github.com/OpenHumans/open-humans-api">open human api </a>, I landed into the area of mock testing in python. I mocked the API tests using <a href="https://github.com/kevin1024/vcrpy">vcrpy</a> . It’s just like <em>Thor’s stormbreaker(Marvel fan will understand )</em> in the field of unit testing. It’s apt for those applications which make http calls to external services.</p><p><strong>Why </strong><a href="https://github.com/kevin1024/vcrpy"><strong>vcrpy</strong></a></p><p>The external service should not be tightly coupled with the application. If the external services fail, the application should still run correctly. One absolute novice testing way is to hard code error prone request and code the necessary error handling portions. But, this is highly not recommended because once you update even a few line of code, you have to manually test it again. So, we hop on to the more sophisticated way of testing: Unittesting.</p><p>Running tests which call the external service every time will be very slow. Apart from it, the tests won’t work offline and sending too many requests to the external service can be a problem too. So, here steps the protagonist, <a href="https://github.com/kevin1024/vcrpy">vcrpy</a>. 😃</p><p>You just need to run the test online once when the cassette file which stores all the important information related to the requests response has not been created. Once, it is done, the response of requests will just be compared with the cassette file and yes , it’s done 😃 . You have became successful in making your application more sturdy.</p><p><strong>How to use </strong><a href="https://github.com/kevin1024/vcrpy"><strong>vcrpy</strong></a></p><p>For each function serving a particular feature, a class for testing is created. For testing different lines of code of a particular feature, different tests(functions with assertion) is created in the test class. Tests for valid response, invalid responses are written.</p><p>A simple example for testing a message feature which uses external API is shown below. The pseudo code of the message feature is shown below for valid and invalid access token (for digging deeper about access token, you can visit <a href="https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2">OAuth2</a>).</p><pre>def message(subject, message, access_token):<br>    url = urlparse.urljoin(&#39;https://www.somexyz.org/api/message/{}&#39;.<br>                           format(urlparse.urlencode(<br>                           {&#39;access_token&#39;: access_token})))<br>    response = requests.post(url, data={&#39;subject&#39;: subject,<br>                                 &#39;message&#39;: message})<br>    return response</pre><p>The message function take three arguments: subject, message and access_token. The function just uses <a href="http://docs.python-requests.org/en/master/user/quickstart/">post</a> requests to hit an external url which give a response stored in the <em>response</em> variable. The tests for valid and invalid access_token for the message function is given below.</p><pre>import vcr<br>from api import message</pre><pre>class APITestMessage(TestCase): </pre><pre>   def setUp(self):<br>       pass</pre><pre>   @my_vcr.use_cassette() <br>   def test_message_valid_access_token(self): <br>       response = message(subject=SUBJECT, message=MESSAGE,<br>                          access_token=ACCESS_TOKEN)<br>       self.assertEqual(response.status_code, 200)</pre><pre>   @my_vcr.use_cassette()<br>   def test_message_invalid_access_token(self):<br>       with self.assertRaises(Exception):<br>           response = message(subject=SUBJECT, message=MESSAGE,<br>                              access_token=ACCESS_TOKEN)                                            <br>           assert response.json() == {&quot;detail&quot;: &quot;Invalid token.&quot;}</pre><p>In this portion of code, in the first test, subject, message and correct access_token is provided by the tester for getting the proper API response. The response is stored in a cassette file for each test. Response from the cassette file is retrieved and compared for testing. For the second test, subject, message and incorrect access_token is provided by the tester. For this function, exception will be raised accordingly. Again, in a different cassette file, response will be stored. The cassette files generated for the valid and invalid token is given below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*HB6k8iI4H-_EXpgb2AqmXw.png" /><figcaption>Cassette file for valid token</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*3X3NbJaF9iPaJRBP4sOJ-A.png" /><figcaption>Cassette file for invalid token</figcaption></figure><p>For the first time, when the test is run, the request really hits the external service and a cassette file is formed. Once the cassette is formed which contain status codes, status, etc, the response of tests is just compared with the cassette file when the tests are run again. It really speeds up the testing process and saves us from sending requests to the external service again and again. Whether you are offline at your home or 35,000 feet above the ground anytime you can test your code, once the cassettes are formed.</p><p>Want to try a hand on this cool stuff? You can follow <a href="https://github.com/OpenHumans/open-humans-api/blob/master/ohapi/tests/test_api.py">https://github.com/OpenHumans/open-humans-api/blob/master/ohapi/tests/test_api.py</a>. The link contains a lot of examples to write tests using <a href="https://github.com/kevin1024/vcrpy">vcrpy</a>. You can see the bigger picture by observing any function in the <a href="https://github.com/OpenHumans/open-humans-api/blob/master/ohapi/api.py">https://github.com/OpenHumans/open-humans-api/blob/master/ohapi/api.py</a> and how for each functions tests and cassettes are formed.</p><p>Till then, happy coding. 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff3eb05ae5ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The road to Outreachy]]></title>
            <link>https://medium.com/@light_khan/the-road-to-outreachy-4d932d6ef8cc?source=rss-e7f659b69cf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d932d6ef8cc</guid>
            <category><![CDATA[internships]]></category>
            <category><![CDATA[women-in-tech]]></category>
            <category><![CDATA[outreachy]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Tarannum Khan]]></dc:creator>
            <pubDate>Mon, 28 May 2018 13:11:00 GMT</pubDate>
            <atom:updated>2018-05-31T22:51:54.305Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Here are the key takeaways from my journey</em></h4><p>Four months ago, my amazing journey with Outreachy started. Ever since, I see a tremendous growth in myself. This growth is not limited to open source development, but also encompasses a wider set of personality traits, like a great boost in my will to continue and succeed, interact with a new bunch of people easily and learn from them.</p><p>Just clearing the fog, Outreachy is a great program for the people out there, traditionally underrepresented in tech, who are interested in open source development and don’t know where to start or try hands in this area. This is the right place to get started. Outreachy community provide an immense support for beginner like you and me to nurture our development skills by providing a superb platform for working in a collaborative environment with the mentors and other Outreachy participants.</p><p>I am working with the Open Humans organization and my project is on “<a href="https://www.outreachy.org/2018-may-august/communities/open-humans/#writing-an-python-module-for-the-open-humans-api-a">Writing an Python module for the Open Humans API &amp; a self-contained, modular Django app</a>”. Open Humans community has been very supportive throughout. I would like to thank Mad Price Ball(mentor), Bastian Greshake Tzovaras and Mike Esclante for being always there to clear my doubts. They have been a major support in this process of learning by sharing their knowledge which is pretty cool.</p><p>I got to know about Outreachy through my friends of my institute and took my first big step in this area.</p><h3><strong>START(very important)</strong></h3><h3><strong>Organisation and project selection</strong></h3><p>Select the perfect organisation with the perfect project and the perfect language to work on(<em>But life is not so perfect</em>). So let’s go practical. On the <a href="https://www.outreachy.org/">outreachy website</a>, once the projects get floated, look for each and every project of every organisation. Take a look at the repository provided by them. For the beginners, do check on the issue tagged with beginners or good first issue. If it looks understandable after having a look at the repository, you are good to go and start contributing to it.</p><p>Initially you can contribute to two or three repositories but with time you would know which one to really pick and focus on. Every mentor has a different interaction style which is mentioned in the <a href="https://www.outreachy.org/">outreachy website</a> from which you will get an idea, how to reach the mentors. I suggest that your decision to choose a project should majorly depend on the project repository, it’s issue and then on the language. Don’t hesitate to pick a language in which you are not much comfortable but you should know the basics at the least, rest assured learning with this amazing community.</p><h3>Bug fixing</h3><p>Once the project is selected, take an issue, if you think you can do it, get it assigned and start working. If you are having any trouble feel free to either raise your doubts in the organisation forum or you can contact mentors. Someone will be always there to git pull you ahead from where you were stuck. <em>You would love the feeling when your first pull request will be merged.</em> :)</p><h3>Patience is the key</h3><p>Sometimes things might get a little tough as you are a new player in this field. Just keep up with patience, keep reading documentations, keep discussing with your mentors, keep coding and you will solve the issue(<em>BA-AM</em>). After solving each issue from beginner friendly to moderate to hard level, your self-confidence will be boosted immensely. In this great learning curve, you will learn a lot of new and interesting development stuff and your stamina to read documentations will increase drastically. <em>(Life of a developer: Birth, find bug, read documentation, code, death)</em></p><h3>Outreachy proposal</h3><p>Now it’s time for the big show:<em> </em>PROPOSAL. Think clearly and meticulously about the project, the problem it’s trying to solve and make a clear plan of how you will solve the problem with the proper timeline and technical details. You can see a link to my proposal <a href="https://docs.google.com/document/d/1JC1uP75NuGmFDYFEvMRtO61B_O2pBKna0truys2FG1w/edit?usp=sharing">here</a>. Start at least two weeks before the deadline to write the proposal.</p><p>Done and dusted. After the outreachy application period, keep on contributing. Whether you get selected or not, but the road to Outreachy is totally amazing. Your knowledge and confidence will boost immensely. And maybe not immediately but definitely, you will get a project to work with the Outreachy community as Outreachy programme is held in winters as well as in summers, so just keep on coding. I was lucky enough to get selected in my first attempt and work with Open Humans. Just be ready to give your time and energy to Outreachy and keep on working. 😀</p><p>Some pre-internship suggestions will be to learn git. It really helps and will save a lot of your time. The earlier you start contributing, the better your chances will be to spend your summer or winter non-vacation. Also, if you are interested in open source development and not eligible for Outreachy, there are a lot of other programs out there. Keep exploring. :)</p><p>Feel free to contact me at <a href="/service/mailto:tkhaniitr@gmail.com">tkhaniitr@gmail.com</a>. I will be there to clear the doubts and even interact with you, given that I am not that boring 😀.</p><p>Keep your enthusiasm up and keep coding.</p><h4>More where this came from</h4><p>This story is published in <a href="http://blog.usejournal.com/">Noteworthy</a>, where thousands come every day to learn about the people &amp; ideas shaping the products we love.</p><p>Follow our publication to see more product &amp; design stories featured by the <a href="https://usejournal.com/?/utm_source=usejournal.com&amp;utm_medium=blog&amp;utm_campaign=guest_post">Journal</a> team.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d932d6ef8cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[1:10-not easy with men]]></title>
            <link>https://medium.com/techburst/1-10-not-easy-with-men-a47e970822bd?source=rss-e7f659b69cf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a47e970822bd</guid>
            <category><![CDATA[gender-discrimination]]></category>
            <category><![CDATA[iit]]></category>
            <category><![CDATA[women-in-tech]]></category>
            <dc:creator><![CDATA[Tarannum Khan]]></dc:creator>
            <pubDate>Mon, 04 Dec 2017 07:18:44 GMT</pubDate>
            <atom:updated>2017-12-19T14:53:53.710Z</atom:updated>
            <content:encoded><![CDATA[<h3>Diary of an IITian girl</h3><p>*This blog is not for the sexists*. It is to all the girls out there who heard -”<em> Tu to ladki hai, tera toh ho jaega</em>”.</p><p>Yes, you can relate to it. Yes, this has happened to you too, when your capabilities at every step is questioned just because you are a girl.</p><p>Tired of giving innumerable tests, absolutely keeping in mind my domain, I got shortlisted for many companies. It is then, people started backing me up in the most “generous way” possible. Apparently, being a girl is sufficient to get the job. I don’t know where their logic vanishes at the time as if they have cleared the test for me. To my wonder, it is not just me who had to face this. Many of my female friends have heard the same while they were interviewing for internships as well.</p><p>But not “obviously”, that’s not what happened. The real story is I was having my continuous interviews and giving my best, side-tracking my realization of being a girl. When, I was free for about half an hour in between, my utterly helpful friends came to me and said “oh in this company you are the only girl, you will be selected” and then I realized, “Oh! There is one such rubbish also there”. With so much strong predictions of my future, I was not selected in that company but in another one.</p><p>As a kid, I was never aware that what I achieved had anything to do with my gender like my JEE rank. But once I entered college, I was monotonously reminded that I am a girl, in every step of my path. Similarly, my grade point never had anything to do with my gender. It had more to do with my hard work and persistence and clearly, not having a laid-back attitude that is driven by procrastination.</p><p>When I entered into IIT, I did not make it up to here because I was a girl (at least till now), I came as equal. I was never used to get things because of my gender. I always considered myself capable enough to carve my own path. I never wanted any preferential treatment while group recruitment, coursework help, or anything else for that matter. The saddest part of the whole story is that, the guys who themselves keep cribbing about this preferential treatment, continue to perpetuate it when they become group coordinators or secy’s.</p><p>There is a lot more discussion happening, whenever a company selects a little less deserving girl but there is not one statement made when a similar guy is selected? Why is there a mere silence then? Sometimes, anyone can get selected based on their interview performance and sheer luck, then why is the judgment only for girls. Accept the fact that, if some girls are selected randomly, then there are guys too.</p><p>It’s a misconception hovering around such “brilliant minds” that girls succeed because they are girls, when we compete with boys, we excel because we are better. All the companies that visit are to hire engineers not girls. Yes, we have benefit in those hackathons, which are specifically for girls but there the story is totally different, nothing related to capabilities ;)</p><p>We belong to the premiere institute of India and sadly, we are the ones spreading sexism. It’s high time to change this culture, shut the mouth of those who remind you that you are a girl, stop taking benefits, which you feel you got due to the gender bias. Don’t let anyone do any partiality to you. If you won’t raise your voice, the gender discrimination will continue further, at the time of internships and jobs as well.</p><p>To the guys, stop giving partial treatment, walk a mile in the girl’s shoes before you comment on how she made her achievements. Stop propagating the sad banter that girls are dumb and boys are logical. If you are logical then please prove that. The average girl in IIT is exhausted of being looked down upon and being treated as inferior. Be proud of your colleagues who continue to excel. Don’t judge without knowing.</p><p>For every girl out there, you have excelled in whatever you really deserved. Never ever question yourselves.</p><p>You go girl.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a47e970822bd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/techburst/1-10-not-easy-with-men-a47e970822bd">1:10-not easy with men</a> was originally published in <a href="https://medium.com/techburst">techburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>