Coverage for mindsdb / integrations / handlers / ms_one_drive_handler / ms_one_drive_tables.py: 0%

28 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-21 00:36 +0000

1from io import BytesIO 

2from typing import List, Text 

3 

4import pandas as pd 

5 

6from mindsdb.integrations.libs.api_handler import APIResource 

7from mindsdb.integrations.utilities.sql_utils import ( 

8 FilterCondition, 

9 SortColumn 

10) 

11 

12from mindsdb.integrations.utilities.files.file_reader import FileReader 

13 

14 

15class ListFilesTable(APIResource): 

16 """ 

17 The table abstraction for querying the files (tables) in Microsoft OneDrive. 

18 """ 

19 

20 def list( 

21 self, 

22 conditions: List[FilterCondition] = None, 

23 limit: int = None, 

24 sort: List[SortColumn] = None, 

25 targets: List[Text] = None, 

26 **kwargs 

27 ): 

28 """ 

29 Lists the files in Microsoft OneDrive. 

30 

31 Args: 

32 conditions (List[FilterCondition]): The conditions to filter the files. 

33 limit (int): The maximum number of files to return. 

34 sort (List[SortColumn]): The columns to sort the files by. 

35 targets (List[Text]): The columns to return in the result. 

36 

37 Returns: 

38 pd.DataFrame: The list of files in Microsoft OneDrive based on the specified clauses. 

39 """ 

40 client = self.handler.connect() 

41 files = client.get_all_items() 

42 

43 data = [] 

44 for file in files: 

45 item = { 

46 "name": file["name"], 

47 "path": file["path"], 

48 "extension": file["name"].split(".")[-1] 

49 } 

50 

51 # If the 'content' column is explicitly requested, fetch the content of the file. 

52 if targets and "content" in targets: 

53 item["content"] = client.get_item_content(file["path"]) 

54 

55 # If a SELECT * query is executed, i.e., targets is empty, set the content to None. 

56 elif not targets: 

57 item["content"] = None 

58 

59 data.append(item) 

60 

61 df = pd.DataFrame(data) 

62 return df 

63 

64 def get_columns(self): 

65 return ["name", "path", "extension", "content"] 

66 

67 

68class FileTable(APIResource): 

69 """ 

70 The table abstraction for querying the content of a file (table) in Microsoft OneDrive. 

71 """ 

72 

73 def list(self, targets: List[str] = None, table_name=None, *args, **kwargs) -> pd.DataFrame: 

74 """ 

75 Retrieves the content of the specified file (table) in Microsoft OneDrive. 

76 

77 Args: 

78 targets (List[str]): The columns to return in the result. 

79 table_name (str): The name of the file (table) to retrieve. 

80 

81 Returns: 

82 pd.DataFrame: The content of the specified file (table) in Microsoft OneDrive. 

83 """ 

84 client = self.handler.connect() 

85 

86 file_content = client.get_item_content(table_name) 

87 

88 reader = FileReader(file=BytesIO(file_content), name=table_name) 

89 

90 return reader.get_page_content()