MCPcopy Index your code
hub / github.com/uber/aresdb / createTable

Function createTable

examples/examples.go:156–185  ·  view source on GitHub ↗
(tableName string, tableSchemaPath string)

Source from the content-addressed store, hash-verified

154}
155
156func 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
187func ingestDataForTable(connector client.Connector, tableName string, dataPath string) {
188 file, err := os.Open(dataPath)

Callers 1

createTablesForDataSetFunction · 0.85

Calls 4

panicIfErrFunction · 0.85
logErrorFunction · 0.85
OpenMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected