コード例 #1
0
 def test_column_fetch(self):
     mock_kusto_client = MockKustoClient(
         columns_response=mock_columns_response([('foo', _KustoType.STRING),
                                                 ('bar', _KustoType.INT)]),
         record_metadata=True,
     )
     table = PyKustoClient(mock_kusto_client,
                           fetch_by_default=False)['test_db']['mock_table']
     table.blocking_refresh()
     # Fetch query
     self.assertEqual(
         [
             RecordedQuery(
                 'test_db',
                 '.show table mock_table | project AttributeName, AttributeType | limit 10000'
             )
         ],
         mock_kusto_client.recorded_queries,
     )
     # Dot notation
     self.assertEqual(type(table.foo), _StringColumn)
     self.assertEqual(type(table.bar), _NumberColumn)
     # Bracket notation
     self.assertEqual(type(table['foo']), _StringColumn)
     self.assertEqual(type(table['bar']), _NumberColumn)
     self.assertEqual(type(table['baz']), _AnyTypeColumn)
コード例 #2
0
 def test_join_with_table(self):
     table = PyKustoClient(
         MockKustoClient(columns_response=mock_columns_response([(
             'tableStringField',
             _KustoType.STRING), (
                 'numField', _KustoType.INT)])))['test_db']['mock_table']
     self.assertEqual(
         'mock_table | where numField > 4 | take 5 | join kind=inner (cluster("test_cluster.kusto.windows.net").database("test_db").table("mock_table")) '
         'on numField, $left.stringField==$right.tableStringField',
         (Query(t).where(t.numField > 4).take(5).join(
             Query(table), kind=JoinKind.INNER).on(
                 t.numField,
                 (t.stringField, table.tableStringField)).render()))
コード例 #3
0
    def test_join_chained_on(self):
        mock_client = PyKustoClient(
            MockKustoClient(columns_response=mock_columns_response([(
                'tableStringField',
                _KustoType.STRING), ('numField', _KustoType.INT)])))
        mock_table = mock_client['test_db']['mock_table']

        expected_query = (
            'mock_table | where numField > 4 | take 5 | join kind=inner '
            '(cluster("test_cluster.kusto.windows.net").database("test_db").table("mock_table")'
            ' | where numField == 2 | take 6) on numField, $left.stringField==$right.tableStringField'
        )
        actual_query = (Query(t).where(t.numField > 4).take(5).join(
            Query(mock_table).where(mock_table.numField == 2).take(6),
            kind=JoinKind.INNER).on(t.numField).on(
                (t.stringField, mock_table.tableStringField)).render())

        self.assertEqual(expected_query, actual_query)
コード例 #4
0
    def test_add_queries_with_table(self):
        table = PyKustoClient(
            MockKustoClient(columns_response=mock_columns_response([(
                'numField', _KustoType.INT)])))['test_db']['mock_table']
        query_a = Query(table).where(table.numField > 4)
        query_b = Query(t).take(5).take(2).sort_by(t.stringField, Order.ASC,
                                                   Nulls.LAST)
        query = query_a + query_b
        self.assertEqual(
            "mock_table | where numField > 4 | take 5 | take 2 | sort by stringField asc nulls last",
            query.render(),
        )

        # make sure the originals didn't change
        self.assertEqual(
            "mock_table | where numField > 4",
            query_a.render(),
        )
        self.assertEqual(
            "mock_table | take 5 | take 2 | sort by stringField asc nulls last",
            query_b.render(),
        )