@@ -266,7 +266,7 @@ def shutDown(self):
266266 self .loop = None
267267 self .thread = None
268268
269- def getSessionId (self ) -> List [int ]:
269+ def getSessionId (self ) -> List [str ]:
270270 """Obtain Session ID of all sessions.
271271
272272 Returns:
@@ -525,7 +525,7 @@ def runFile(self, filepath: str, *args, **kwargs):
525525 script = fp .read ()
526526 return self .run (script , * args , ** kwargs )
527527
528- def getSessionId (self ) -> int :
528+ def getSessionId (self ) -> str :
529529 """Get the Session ID of the current Session.
530530
531531 Returns:
@@ -551,7 +551,7 @@ def subscribe(
551551 self , host : str , port : int , handler : Callable , tableName : str , actionName : str = None ,
552552 offset : int = - 1 , resub : bool = False , filter = None ,
553553 msgAsTable : bool = False , batchSize : int = 0 , throttle : float = 1.0 ,
554- userName : str = None , password : str = None , streamDeserializer : Optional [Type [ "streamDeserializer" ] ] = None
554+ userName : str = None , password : str = None , streamDeserializer : Optional ["streamDeserializer" ] = None
555555 ) -> None :
556556 """Subscribe to stream tables in DolphinDB.
557557
@@ -666,7 +666,7 @@ def saveTable(self, tbl: Table, dbPath: str) -> bool:
666666 self .run (s2 )
667667 return True
668668
669- def loadText (self , remoteFilePath : str , delimiter : str = "," ) -> Type [ "Table" ] :
669+ def loadText (self , remoteFilePath : str , delimiter : str = "," ) -> "Table" :
670670 """Import text files into DolphinDB as an in-memory table.
671671
672672 Args:
@@ -685,9 +685,9 @@ def loadText(self, remoteFilePath: str, delimiter: str = ",") -> Type["Table"]:
685685 return Table (data = tableName , s = self , isMaterialized = True )
686686
687687 def loadTextEx (
688- self , dbPath : str , tableName : str , partitionColumns : Optional [List [str ]] = None ,
689- remoteFilePath : str = None , delimiter : str = ","
690- ) -> Type [ "Table" ] :
688+ self , dbPath : str , tableName : str , partitionColumns : Optional [List [str ]] = None ,
689+ remoteFilePath : str = None , delimiter : str = "," , sortColumns : Optional [ List [ str ]] = None ,
690+ ) -> "Table" :
691691 """Import a partitioned in-memory table.
692692
693693 Args:
@@ -696,35 +696,43 @@ def loadTextEx(
696696 partitionColumns : list of strings indicating the partitioning columns. Defaults to None.
697697 remoteFilePath : remote file path. Defaults to None.
698698 delimiter : delimiter of each column. Defaults to ",".
699+ sortColumns : list of strings indicating the sort columns. Defaults to None.
699700
700701 Returns:
701702 a DolphinDB Table object.
702703 """
703704 if partitionColumns is None :
704705 partitionColumns = []
706+ if sortColumns is None :
707+ sortColumns = []
705708 isDBPath = True
706709 if "/" in dbPath or "\\ " in dbPath or "dfs://" in dbPath :
707- dbstr = 'db=database("' + dbPath + '")'
710+ dbstr = 'db=database("' + dbPath + '")'
708711 self .run (dbstr )
709- tbl_str = '{tableNameNEW} = loadTextEx(db, "{tableName}", {partitionColumns}, "{remoteFilePath}", {delimiter})'
712+ tbl_str = '{tableNameNEW} = loadTextEx(db, "{tableName}", {partitionColumns}, "{remoteFilePath}", {delimiter} {extraParams} )'
710713 else :
711714 isDBPath = False
712- tbl_str = '{tableNameNEW} = loadTextEx(' + dbPath + ' , "{tableName}", {partitionColumns}, "{remoteFilePath}", {delimiter})'
715+ tbl_str = '{tableNameNEW} = loadTextEx("{ dbPath}" , "{tableName}", {partitionColumns}, "{remoteFilePath}", {delimiter} {extraParams })'
713716 fmtDict = dict ()
714717 fmtDict ['tableNameNEW' ] = _generate_tablename ()
718+ fmtDict ['dbPath' ] = dbPath
715719 fmtDict ['tableName' ] = tableName
716- fmtDict ['partitionColumns' ] = str ( partitionColumns )
720+ fmtDict ['partitionColumns' ] = '[' + ',' . join ([ f'" { _ } "' for _ in partitionColumns ]) + ']'
717721 fmtDict ['remoteFilePath' ] = remoteFilePath if remoteFilePath is not None else ""
718722 fmtDict ['delimiter' ] = delimiter
719- # tbl_str = tableName+'=loadTextEx(db,"' + tableName + '",'+ str(partitionColumns) +',"'+ remoteFilePath+"\",'"+delimiter+"')"
723+ if sortColumns :
724+ extraParams = ", sortColumns=" + '[' + ',' .join ([f'"{ _ } "' for _ in sortColumns ]) + ']'
725+ else :
726+ extraParams = ""
727+ fmtDict ['extraParams' ] = extraParams
720728 tbl_str = re .sub (' +' , ' ' , tbl_str .format (** fmtDict ).strip ())
721729 self .run (tbl_str )
722730 if isDBPath :
723731 return Table (data = fmtDict ['tableName' ], dbPath = dbPath , s = self )
724732 else :
725733 return Table (data = fmtDict ['tableNameNEW' ], s = self )
726734
727- def ploadText (self , remoteFilePath : str , delimiter : str = "," ) -> Type [ "Table" ] :
735+ def ploadText (self , remoteFilePath : str , delimiter : str = "," ) -> "Table" :
728736 """Import text files in parallel into DolphinDB as a partitioned in-memory table, which is faster than method loadText.
729737
730738 Args:
@@ -742,7 +750,7 @@ def ploadText(self, remoteFilePath: str, delimiter: str = ",") -> Type["Table"]:
742750 def table (
743751 self , dbPath : str = None , data = None , tableAliasName : str = None ,
744752 inMem : bool = False , partitions : Optional [List [str ]] = None
745- ) -> Type [ "Table" ] :
753+ ) -> "Table" :
746754 """Create a DolphinDB table object and upload it to the server.
747755
748756 Deprecated:
@@ -762,7 +770,7 @@ def table(
762770 partitions = []
763771 return Table (dbPath = dbPath , data = data , tableAliasName = tableAliasName , inMem = inMem , partitions = partitions , s = self , isMaterialized = True )
764772
765- def loadTable (self , tableName : str , dbPath : Optional [str ] = None , partitions = None , memoryMode : bool = False ) -> Type [ "Table" ] :
773+ def loadTable (self , tableName : str , dbPath : Optional [str ] = None , partitions = None , memoryMode : bool = False ) -> "Table" :
766774 """Load a DolphinDB table.
767775
768776 Args:
@@ -828,7 +836,7 @@ def myStr(x):
828836 else :
829837 return Table (data = tableName , s = self , needGC = False , isMaterialized = True )
830838
831- def loadTableBySQL (self , tableName : str , dbPath : str , sql : str ) -> Type [ "Table" ] :
839+ def loadTableBySQL (self , tableName : str , dbPath : str , sql : str ) -> "Table" :
832840 """Load records that satisfy the filtering conditions in a SQL query as a partitioned in-memory table.
833841
834842 Args:
@@ -850,7 +858,7 @@ def loadTableBySQL(self, tableName: str, dbPath: str, sql: str) -> Type["Table"]
850858 def database (
851859 self , dbName : str = None , partitionType : int = None , partitions = None ,
852860 dbPath : str = None , engine : str = None , atomic : str = None , chunkGranularity : str = None
853- ) -> Type [ "Database" ] :
861+ ) -> "Database" :
854862 """Create database.
855863
856864 Args:
0 commit comments