Exemple #1
0
 def test_empty_string_is_not_compilable(self):
     with self.assertRaisesRegexp(SyntaxError, r".*empty.*string.*"):
         compiler.compile("")
     with self.assertRaisesRegexp(SyntaxError, r".*empty.*string.*"):
         compiler.run("bash", "")
     with self.assertRaisesRegexp(SyntaxError, r".*empty.*string.*"):
         compiler.run("python", "")
Exemple #2
0
 def test_run_single_file_non_empty(self):
     for backend in self._backends:
         self._mock_file("foo.csv", "")
         self._mock_file("bar.csv", "a,b\na,c\nb,d\n")
         self.assertEqual(len(list(
             compiler.run(backend, "SELECT * FROM bar.csv"))), 3)
         self.assertIn(("a", "b", ), compiler.run(
             backend, "SELECT * FROM bar.csv"))
Exemple #3
0
    def test_select_first_column(self):
        for backend in self._backends:
            self._mock_file("bar.csv", "a,b\na,c\nb,d\na,c\n")
            self._mock_file("baz.csv", "a,b\na,1\n1,d\na,c\n")
            self._mock_file("foo.csv", "a,b\na,c\nb,d\na,c\n")
            results = set(compiler.run(
                backend,
                "SELECT DISTINCT #1 FROM bar.csv UNION foo.csv UNION baz.csv"))
            self.assertSetEqual(results, {("a", ), ("b", ), ("1", ), })

            results = list(compiler.run(
                backend, "SELECT #1 FROM bar.csv"))
            self.assertEqual(results, [("a", ), ("a", ), ("b", ), ("a", )])
Exemple #4
0
    def test_projection_duplicate(self):
        for backend in self._backends:
            self._mock_file("bar.csv", "a,b,3\na,c,3\nb,d,3\na,c,3\n")
            self._mock_file("baz.csv", "a,b\nb,c\n")

            results = list(compiler.run(
                backend, "SELECT #3,#2,#3 FROM bar.csv"))

            self.assertEqual(
                results,
                [("3", "b", "3", ), ("3", "c", "3", ), ("3", "d", "3", ), ("3", "c", "3", ), ])  # noqa

            results = list(compiler.run(
                backend, "SELECT #1,#1 FROM baz.csv"))

            self.assertEqual(results, [("a", "a", ), ("b", "b", )])
Exemple #5
0
 def test_run_multiple_files_one_empty(self):
     for backend in self._backends:
         self._mock_file("foo.csv", "")
         self._mock_file("bar.csv", "a,b\na,c\nb,d\n")
         results = list(compiler.run(
             backend, "SELECT * FROM bar.csv UNION foo.csv"))
         self.assertEqual(len(results), 3)
         self.assertIn(("a", "b", ), results)
         self.assertIn(("b", "d", ), results)
Exemple #6
0
    def test_select_no_first_column(self):
        for backend in self._backends:
            self._mock_file("bar.csv", "a,b,3\na,c,3\nb,d,3\na,c,3\n")
            self._mock_file("baz.csv", "a,b,3\na,1,3\n1,d,3\na,c,3\n")
            self._mock_file("foo.csv", "a,b,3\na,c,3\nb,d,3\na,c,3\n")
            results = set(compiler.run(
                backend,
                "SELECT DISTINCT #2,#3 FROM bar.csv UNION foo.csv UNION baz.csv"))  # noqa
            self.assertSetEqual(
                results, {
                    ("c", "3", ), ("b", "3", ), ("1", "3", ), ("d", "3",),
                }
            )

            results = list(compiler.run(
                backend, "SELECT #2,#3 FROM bar.csv"))
            self.assertEqual(
                results, [("b", "3"), ("c", "3"), ("d", "3"), ("c", "3")])
Exemple #7
0
 def test_select_multiple_files_distinct(self):
     for backend in self._backends:
         self._mock_file("bar.csv", "a,b\na,c\nb,d\na,c\n")
         self._mock_file("baz.csv", "a,b\na,1\nb,d\na,c\n")
         self._mock_file("foo.csv", "a,b\na,c\nb,d\na,c\n")
         results = list(compiler.run(
             backend,
             "SELECT DISTINCT * FROM bar.csv UNION foo.csv UNION baz.csv"))
         self.assertEqual(len(results), 4)
Exemple #8
0
 def test_select_distinct_single_file(self):
     for backend in self._backends:
         self._mock_file("bar.csv", "a,b\na,c\nb,d\na,c\n")
         results = list(compiler.run(
             backend, "SELECT DISTINCT * FROM bar.csv"))
         self.assertEqual(len(results), 3)
Exemple #9
0
 def test_run_single_non_existent_file(self):
     for backend in self._backends:
         self._mock_file("foo.csv", "")
         self._mock_file("bar.csv", "a,b\na,c\nb,d\n")
         with self.assertRaisesRegexp(Exception, r".*No such file.*"):
             list(compiler.run(backend, "SELECT * FROM bullshit.csv"))