Ejemplo n.º 1
0
        public void GetFileNameFromQuery()
        {
            string queryString = "select * from ipl.csv where season > 2014 and city = 'Bangalore'";
            string fileName    = "ipl.csv";

            Assert.Equal(fileName, BasicQueryOperations.GetFileNameFromQuery(queryString));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            ConsoleKeyInfo c;

            do
            {
                Console.Clear();
                string queryString = "";
                int    operation   = 0;

                Console.WriteLine();

                Console.WriteLine("Choose operation: ");
                Console.WriteLine("1. Split query");
                Console.WriteLine("2. Get file name");
                Console.WriteLine("3. Get base part");
                Console.WriteLine("4. Get selected fields");
                Console.WriteLine("5. Get filter part");
                Console.WriteLine("6. Get condition in filter part");
                Console.WriteLine("7. Get logical operators in filter part");
                Console.WriteLine("8. Get order by field");
                Console.WriteLine("9. Get group by field");
                Console.WriteLine("10. Get aggegate functions");
                Console.WriteLine();
                Console.WriteLine("-> ");

                try
                {
                    operation = Convert.ToInt32(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    operation = 0;
                }

                Console.WriteLine();
                Console.Write("Enter Input string: ");
                Console.WriteLine();
                queryString = Console.ReadLine();
                Console.WriteLine();

                switch (operation)
                {
                case 1:
                    //Split the querseley into words
                    DisplaySplitResult(BasicQueryOperations.SplitQueryWords(queryString));
                    break;

                case 2:
                    //Get filename from query
                    DisplayResult(BasicQueryOperations.GetFileNameFromQuery(queryString));
                    break;

                case 3:
                    //Get base part of query
                    DisplayResult(BasicQueryOperations.GetBasePartFromQuery(queryString));
                    break;

                case 4:
                    //Get selected fields fo query
                    DisplaySplitResult(QueryPartsOperations.GetSelectedFields(queryString));
                    break;

                case 5:
                    //Get filter part
                    DisplayResult(QueryPartsOperations.GetFilterPart(queryString));
                    break;

                case 6:
                    //Get conditions in filter part
                    DisplaySplitResult(QueryPartsOperations.GetConditionInFilter(queryString));
                    break;

                case 7:
                    //Get logical operators in filter part
                    DisplaySplitResult(LogicalAndOrderFields.GetLogicalOperators(queryString));
                    break;

                case 8:
                    //Get order by fields
                    DisplaySplitResult(LogicalAndOrderFields.GetOrderField(queryString));
                    break;

                case 9:
                    //Get group by fields
                    DisplaySplitResult(GroupAndAggregateFields.GetGroupByField(queryString));
                    break;

                case 10:
                    //Get aggregate functions
                    DisplaySplitResult(GroupAndAggregateFields.GetAggregateFunctions(queryString));
                    break;

                default:
                    Console.WriteLine("Not a valid operation!!!");
                    break;
                }

                Console.WriteLine("\nPress any key to continue('esc' to stop)");
                c = Console.ReadKey();
            } while (c.Key != ConsoleKey.Escape);
        }
Ejemplo n.º 3
0
        public void QueryNoFileTest()
        {
            string queryString = "select * from t where season > 2014 and city = 'Bangalore'";

            Assert.Equal(BasicQueryOperations.GetFileNameFromQuery(queryString), $"Query doesn't contain any file name");
        }
Ejemplo n.º 4
0
        public void QueryInvalidTest(string queryString)
        {
            Exception ex = Assert.Throws <InvalidQueryException>(() => BasicQueryOperations.GetFileNameFromQuery(queryString));

            Assert.Equal(ex.Message, $"The query is invalid!!");
        }