(tableName string, tableSchemaPath string)
| 154 | } |
| 155 | |
| 156 | func createTable(tableName string, tableSchemaPath string) { |
| 157 | schemaFile, err := os.Open(tableSchemaPath) |
| 158 | panicIfErr(err) |
| 159 | |
| 160 | schemaCreationURL := fmt.Sprintf("http://%s/schema/tables", fmt.Sprintf("%s:%d", viper.GetString(hostKeyName), viper.GetInt(portKeyName))) |
| 161 | rsp, err := http.Post(schemaCreationURL, "application/json", schemaFile) |
| 162 | panicIfErr(err) |
| 163 | |
| 164 | if rsp.Body != nil { |
| 165 | defer rsp.Body.Close() |
| 166 | } |
| 167 | |
| 168 | if rsp.StatusCode != http.StatusOK { |
| 169 | msg := fmt.Sprintf("schema creation failed with status code %d\n", rsp.StatusCode) |
| 170 | if rsp.Body != nil { |
| 171 | respBody, err := ioutil.ReadAll(rsp.Body) |
| 172 | panicIfErr(err) |
| 173 | // TODO(lucafuji): need a better error code mapping here to tell it's a table exists error. |
| 174 | var tableCreationResp TableCreationResp |
| 175 | err = json.Unmarshal(respBody, &tableCreationResp) |
| 176 | panicIfErr(err) |
| 177 | if tableCreationResp.Message == "Table already exists" { |
| 178 | logError(fmt.Sprintf("Table %s already exists", tableName)) |
| 179 | return |
| 180 | } |
| 181 | } |
| 182 | panic(msg) |
| 183 | } |
| 184 | fmt.Printf("table %s created\n", tableName) |
| 185 | } |
| 186 | |
| 187 | func ingestDataForTable(connector client.Connector, tableName string, dataPath string) { |
| 188 | file, err := os.Open(dataPath) |
no test coverage detected