def test_cte_encode_matches(self):
     source_str = basic_str
     encoded_source = EncodedSource(
         DecomposedSource(ParsedSource(Source(source_str))))
     source_str_2 = basic_whitespace_str
     encoded_source_2 = EncodedSource(
         DecomposedSource(ParsedSource(Source(source_str_2))))
     self.assertIsNotNone(encoded_source_2)
     self.assertEqual(encoded_source.encoded_sources(),
                      encoded_source_2.encoded_sources())
 def test_match_whitespace_diff(self):
     source_str = "SELECT * FROM `universe.galaxy.system`"
     target_str = "SELECT *    FROM    `universe.galaxy.system`   "
     source = Source(source_str)
     target = Source(target_str)
     encoded_source = EncodedSource(DecomposedSource(ParsedSource(source)))
     encoded_target = EncodedSource(DecomposedSource(ParsedSource(target)))
     self.assertIsNotNone(encoded_source)
     self.assertIsNotNone(encoded_target)
     self.assertNotEqual(source_str, target_str)
     self.assertNotEqual(source.source(), target.source())
     self.assertEqual(encoded_source.encoded_sources(),
                      encoded_target.encoded_sources())
Beispiel #3
0
def _apply_dependency_first(encoded_source: EncodedSource,
                            apply_func: Callable[[str, str], bool]):

    last_dependencies = encoded_source.encoded_dependencies()[-1]
    for dependency in last_dependencies:
        _apply_dependency_first(dependency, apply_func)
    last_statement = encoded_source.encoded_sources()[-1]
    last_hash = encoded_source.hashed_sources()[-1]
    return apply_func(last_hash, last_statement)
 def test_cte_complex_encode(self):
     encoded_source = EncodedSource(
         DecomposedSource(ParsedSource(Source(complex_query))))
     self.assertIsNotNone(encoded_source)
     #self.assertEqual(complex_query, all_encoded_sources.parsed_sources().source())
     for hash, encoded_source in zip(encoded_source.hashed_sources(),
                                     encoded_source.encoded_sources()):
         print(f"-----------------------------------\n"
               f"{hash}"
               f"\n-----------------------------------\n"
               f"{encoded_source}")
 def test_cte_date_dim_encode(self):
     source_str = date_dim_query
     encoded_source_root = EncodedSource(
         DecomposedSource(ParsedSource(Source(source_str))))
     self.assertIsNotNone(encoded_source_root)
     #self.assertEqual(complex_query, all_encoded_sources.parsed_sources().source())
     for hash, encoded_source in zip(encoded_source_root.hashed_sources(),
                                     encoded_source_root.encoded_sources()):
         print(f"-----------------------------------\n"
               f"{hash}"
               f"\n-----------------------------------\n"
               f"{encoded_source}")
     main_statement_encoded = EncodedSource.from_str(date_dim_select)
     self.assertEqual(
         len(main_statement_encoded.all_encoded_sources_by_name()), 1)