-
Notifications
You must be signed in to change notification settings - Fork 705
Add intermediate representation struct #810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tonyyang-svail
merged 3 commits into
sql-machine-learning:develop
from
tonyyang-svail:add_intermediate_represenstation
Sep 13, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright 2019 The SQLFlow Authors. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package codegen | ||
|
|
||
| // NumericColumn represents a dense tensor for the model input. | ||
| // | ||
| // FieldMeta indicates the meta information for decoding the field. Please be aware | ||
| // that FieldMeta also contains information for dimension and data type. | ||
| type NumericColumn struct { | ||
| FieldMeta *FieldMeta | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // Copyright 2019 The SQLFlow Authors. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package codegen | ||
|
|
||
| // FieldType indicates the field type of a table column | ||
| type FieldType int | ||
|
|
||
| const ( | ||
| // Int indicates the corresponding table column is an integer | ||
| Int FieldType = iota | ||
| // Float indicates the corresponding table column is a float | ||
| Float | ||
| // String indicates the corresponding table column is a string | ||
| String | ||
| ) | ||
|
|
||
| // FieldMeta contains the meta information for decoding. A field is a selected column of a SQL result. | ||
| // | ||
| // Name indicates the name for a field. | ||
| // | ||
| // DType indicates the data type for a field. For example: Int, Float, String. | ||
| // | ||
| // Delimiter indicates the decoding method of a field. For example, the field may | ||
| // contain a string like "1,23,42" which represent a 3-D tensor [1, 23, 42]. | ||
| // | ||
| // Shape indicates the shape of the tensor represented for a field. For exmaple, the | ||
| // field may contain a string like "1,23,42" which represent a 3-D tensor, the shape | ||
| // will be [3]. | ||
| // | ||
| // IsSparse indicates the type of tensor for a field. True means the tensor is a sparse tensor. | ||
| type FieldMeta struct { | ||
| Name string `json:"name"` // e.g. "spetal_length" | ||
| DType FieldType `json:"dtype"` // e.g. "float", "int32" | ||
| Delimiter string `json:"delimiter"` // e.g. "," | ||
| Shape []int `json:"shape"` // e.g. [1], [1 2 3] | ||
| IsSparse bool `json:"is_sparse"` // e.g. false | ||
| } | ||
|
|
||
| // FeatureColumn indicates the feature column to be applied on the field. Please refer to | ||
| // github.com/sql-machine-learning/sqlflow/sql/codegen/feature_column.go for detailed list of all feature columns. | ||
| type FeatureColumn interface{} | ||
|
|
||
| // Attribute represents an parsed entry in the WITH clause. | ||
| type Attribute struct { | ||
| Key string | ||
| Value interface{} | ||
| } | ||
|
|
||
| // TrainIR is the intermediate representation for code generation of a training job. | ||
| // | ||
| // Please be aware that the TrainIR intentionally excludes the model table name in the | ||
| // INTO clause. The sql package will save the output files of a generated Python program. | ||
| // For prediction and analysis jobs, the sql will restore an identical working directly. | ||
| type TrainIR struct { | ||
| // DataSource contains the connection information. For example, "hive://root:root@localhost:10000/churn" | ||
| DataSource string | ||
| // Select specifies the query for fetching the training data. For example, "select * from iris.train;". | ||
| Select string | ||
| // ValidationSelect specifies the query for fetching the validation data. For example, "select * from iris.val;". | ||
| ValidationSelect string | ||
| // Estimator specifies the estimator type. For example, after parsing "select ... train DNNClassifier WITH ...", | ||
| // the Estimator will be "DNNClassifier". | ||
| Estimator string | ||
| // Attributes contain a list of parsed attribute in the WITH Clause. For example, after parsing | ||
| // "select ... train ... with train.epoch = 1000, model.hidden_units = [10, 10]", | ||
| // the Attributes will be {{"train.epoch", 1000}, {"model.hidden_units", [10 10]}}. | ||
| Attributes []Attribute | ||
| // Features contain a map of a list of feature columns in the COLUMN clause. | ||
| // For multiple COLUMN clauses like | ||
| // ``` | ||
| // column ... for deep_feature | ||
| // column ... for wide_feature | ||
| // ``` | ||
| // They will be parsed as {"deep_feature": {...}, "wide_feature": {...}} | ||
| // For single column clause like "column ...", "feature_columns" will be used as the default map key. | ||
| Features map[string][]FeatureColumn | ||
| // Label specifies the feature column in the LABEL clause. | ||
| Label FeatureColumn | ||
| } | ||
|
|
||
| // PredictIR is the intermediate representation for code generation of a prediction job | ||
| // | ||
| // Please be aware the PredictionIR contains the result table name, so the | ||
| // generated Python program is responsible to create and write the result table. | ||
| type PredictIR struct { | ||
| // DataSource contains the connection information. For example, "hive://root:root@localhost:10000/churn" | ||
| DataSource string | ||
| // Select specifies the query for fetching the prediction data. For example, "select * from iris.test;". | ||
| Select string | ||
| // ResultTable specifies the table to store the prediction result. | ||
| ResultTable string | ||
| // Attributes contain a list of parsed attribute in the WITH clause. For example, after parsing | ||
| // "select ... predict ... with predict.batch_size = 32 into ...", | ||
| // the Attributes will be {{"predict.batch_size", 32}} | ||
| Attributes []Attribute | ||
| // TrainIR is the TrainIR used for generating the training job of the corresponding model | ||
| TrainIR TrainIR | ||
| } | ||
|
|
||
| // AnalyzeIR is the intermediate representation for code generation of a analysis job | ||
| type AnalyzeIR struct { | ||
| // DataSource contains the connection information. For example, "hive://root:root@localhost:10000/churn" | ||
| DataSource string | ||
| // Select specifies the query for fetching the analysis data. For example, "select * from iris.test;". | ||
| Select string | ||
| // Attributes contain a list of parsed attribute in the WITH clause. For example, after parsing | ||
| // "select ... analyze ... with analyze.plot_type = "bar"", | ||
| // the Attributes will be {{"analyze.plot_type", "bar"}} | ||
| Attributes []Attribute | ||
| // TrainIR is the TrainIR used for generating the training job of the corresponding model | ||
| TrainIR TrainIR | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.