how to load drivers?

master
xieguigang 5 years ago
parent c682f82647
commit 23bb1dc0d4

@ -57,7 +57,10 @@ Namespace Interpreter.Query
End Sub
Public Overrides Iterator Function PopulatesData() As IEnumerable(Of Object)
Dim driver As DataSourceDriver = env.GlobalEnvir.GetDriverByCode(symbolDeclare.type)
Dim driver As DataSourceDriver = env.GlobalEnvir.GetDriverByCode(
code:=symbolDeclare.type,
arguments:=symbolDeclare.arguments
)
For Each item As Object In driver.ReadFromUri(uri)
Yield item

@ -76,6 +76,9 @@ Namespace Interpreter.Query
.env = New Environment(parent:=env),
.throwError = context.throwError
}
Call LoadDrivers(context)
Dim skipVal As Boolean
Dim dataset As DataSet = GetDataSet(context)

@ -1,49 +1,50 @@
#Region "Microsoft.VisualBasic::c17b9f4ba6163467b2124e29397af322, LINQ\LINQ\Interpreter\Query\QueryExpression.vb"
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
' /********************************************************************************/
' Summaries:
' Class QueryExpression
'
' Properties: IsURISource
'
' Constructor: (+1 Overloads) Sub New
' Function: GetDataSet, GetSeqValue
'
'
' /********************************************************************************/
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
' /********************************************************************************/
' Summaries:
' Class QueryExpression
'
' Properties: IsURISource
'
' Constructor: (+1 Overloads) Sub New
' Function: GetDataSet, GetSeqValue
'
'
' /********************************************************************************/
#End Region
Imports LINQ.Interpreter.Expressions
Imports LINQ.Runtime
Namespace Interpreter.Query
@ -67,6 +68,12 @@ Namespace Interpreter.Query
Me.executeQueue = execQueue.ToArray
End Sub
Protected Sub LoadDrivers(context As ExecutableContext)
Dim globalEnv As GlobalEnvironment = context.env.GlobalEnvir
Dim registry As Registry = globalEnv.registry
End Sub
Public Function AddAttachDrivers(drivers As IEnumerable(Of ImportDataDriver)) As QueryExpression
attaches.AddRange(drivers)
Return Me

@ -66,7 +66,8 @@ Module Program
Dim tokens As Token() = LINQ.Language.GetTokens(file.ReadAllText).ToArray
Dim query As ProjectionExpression = tokens.PopulateQueryExpression
Dim env As New GlobalEnvironment(New Registry)
Dim result As JavaScriptObject() = query.Exec(New ExecutableContext With {.env = env, .throwError = True})
Dim context As New ExecutableContext With {.env = env, .throwError = True}
Dim result As JavaScriptObject() = query.Exec(context)
Dim table As DataFrame = result.CreateTableDataSet
Dim output As String = args <= "/output"

@ -48,7 +48,7 @@ Namespace Runtime
Public Class GlobalEnvironment : Inherits Environment
Protected ReadOnly registry As Registry
Protected Friend ReadOnly registry As Registry
Sub New(registry As Registry, ParamArray values As NamedValue(Of Object)())
Call MyBase.New(Nothing)
@ -65,8 +65,8 @@ Namespace Runtime
Me.registry = registry
End Sub
Public Function GetDriverByCode(code As String) As DataSourceDriver
Return registry.GetReader(code)
Public Function GetDriverByCode(code As String, arguments As String()) As DataSourceDriver
Return registry.GetReader(code, arguments)
End Function
End Class
End Namespace

@ -1,42 +1,42 @@
#Region "Microsoft.VisualBasic::0124b5f27111e2adaadc328227661fb0, LINQ\LINQ\Runtime\Registry.vb"
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
' /********************************************************************************/
' /********************************************************************************/
' Summaries:
' Summaries:
' Class Registry
'
' Function: GetReader, GetTypeCodeName
'
'
' /********************************************************************************/
' Class Registry
'
' Function: GetReader, GetTypeCodeName
'
'
' /********************************************************************************/
#End Region
@ -46,6 +46,8 @@ Namespace Runtime
Public Class Registry
ReadOnly drivers As New Dictionary(Of String, IDriverLoader)
Public Function GetTypeCodeName(type As Type) As String
Select Case type
Case GetType(Integer) : Return "i32"
@ -55,12 +57,17 @@ Namespace Runtime
End Select
End Function
Public Function GetReader(type As String) As DataSourceDriver
Public Function GetReader(type As String, arguments As String()) As DataSourceDriver
If type = "row" Then
Return New DataFrameDriver
ElseIf drivers.ContainsKey(type) Then
Return drivers(type)(arguments)
Else
Throw New MissingPrimaryKeyException
Throw New MissingPrimaryKeyException(type)
End If
End Function
End Class
Public Delegate Function IDriverLoader(arguments As String()) As DataSourceDriver
End Namespace

Loading…
Cancel
Save