[GitHub] incubator-trafodion pull request #1237: [TRAFODION-2726] odb support to load...
Github user asfgit closed the pull request at: https://github.com/apache/incubator-trafodion/pull/1237 ---
[GitHub] incubator-trafodion pull request #1237: [TRAFODION-2726] odb support to load...
Github user DaveBirdsall commented on a diff in the pull request: https://github.com/apache/incubator-trafodion/pull/1237#discussion_r140913298 --- Diff: core/conn/odb/src/JsonReader.c --- @@ -0,0 +1,563 @@ +//-- +// +// @@@ START COPYRIGHT @@@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. +// +// @@@ END COPYRIGHT @@@ + +#include "JsonReader.h" +#include +#include + +JsonReader *jsonReaderNew(const char *path) +{ +JsonReader *pJsonReader = (JsonReader *)calloc(1, sizeof(JsonReader)); +if (!pJsonReader) { +return NULL; +} + +pJsonReader->jsonFile = fopen(path, "r"); +if (!pJsonReader->jsonFile) { +free(pJsonReader); +return NULL; +} + +strncpy(pJsonReader->jsonFileName, path, JSON_PARSER_MAX_FILE_NAME_LEN); +pJsonReader->nestDepth = 0; +pJsonReader->state = JSON_STATE_START; +pJsonReader->errorCode = JSON_SUCCESS; +pJsonReader->currentCharPtr = pJsonReader->buf; + +return pJsonReader; +} + +JsonReaderError jsonMoveCurrentCharPtr(JsonReader *pJsonReader) +{ +if (pJsonReader->isBufReady) { +++pJsonReader->currentCharPtr; +} + +if (pJsonReader->currentCharPtr == pJsonReader->buf + pJsonReader->numberReadBuf) { +if ((pJsonReader->numberReadBuf = fread(pJsonReader->buf, sizeof(char), JSON_PARSER_BUF_LEN, pJsonReader->jsonFile))) { +pJsonReader->currentCharPtr = pJsonReader->buf; +pJsonReader->isBufReady = true; +} +else { +pJsonReader->errorCode = JSON_ERROR_PARSE_EOF; +} +} + +if (*(pJsonReader->currentCharPtr) == '\n') { --- End diff -- Might this reference the first byte past the end of the buffer in the case that line 62 was executed? If so that opens the possibility of a segmentation violation. ---
[GitHub] incubator-trafodion pull request #1237: [TRAFODION-2726] odb support to load...
Github user DaveBirdsall commented on a diff in the pull request: https://github.com/apache/incubator-trafodion/pull/1237#discussion_r140911804 --- Diff: core/conn/odb/src/JsonReader.c --- @@ -0,0 +1,563 @@ +//-- +// +// @@@ START COPYRIGHT @@@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. +// +// @@@ END COPYRIGHT @@@ + +#include "JsonReader.h" +#include +#include + +JsonReader *jsonReaderNew(const char *path) +{ +JsonReader *pJsonReader = (JsonReader *)calloc(1, sizeof(JsonReader)); +if (!pJsonReader) { +return NULL; +} + +pJsonReader->jsonFile = fopen(path, "r"); +if (!pJsonReader->jsonFile) { +free(pJsonReader); +return NULL; +} + +strncpy(pJsonReader->jsonFileName, path, JSON_PARSER_MAX_FILE_NAME_LEN); --- End diff -- If the path is too long, there won't be a null terminator. To be safe, you may want to set the last character in the buffer to the null character after the strncpy call. ---
[GitHub] incubator-trafodion pull request #1237: [TRAFODION-2726] odb support to load...
GitHub user SuJinpei opened a pull request: https://github.com/apache/incubator-trafodion/pull/1237 [TRAFODION-2726] odb support to load json file **1. Why support json?** 1. custormer needed. 2. JSON is a data inter-exchange format. When compared to XML, it is very lightweight and more human-readable. **2. Why not use existing c json lib?** Considered using the json-c and json-glibc, but seems neither them support stream parse. For a large file, the memory may not enough. **3. How odb support json loading function?** 1. Create table tbjson(id int, name char(20)); 2. cat test.json { "test":[ { "id":1 , "name":"hello" }, { "id":2 , "name":"world" }, ] } 3. `./odb64luo -l src=test.json:tgt=tbjson:jsonkey=test odb [parseopt(14249)] - Warning: this function is not fully tested "jsonkey" odb [2017-09-18 15:28:39]: starting ODBC connection(s)... 0 Connected to Trafodion [0] 2 records inserted [commit] [0] odb version 1.1.0 Load(X) statistics: [0] Target table: (null).(null).TBJSON [0] Source: test.json [0] Pre-loading time: 0.308 s (00:00:00.308) [0] Loading time: 0.021 s(00:00:00.021) [0] Total records read: 0 [0] Total records inserted: 2 [0] Total number of columns: 2 [0] Average input row size: NaN B [0] ODBC row size: 31 B (data) + 16 B (len ind) [0] Rowset size: 100 [0] Rowset buffer size: 4.59 KiB [0] Load throughput (real data): 0.000 KiB/s [0] Load throughput (ODBC): 2.883 KiB/s odb [2017-09-18 15:28:39]: exiting. Session Elapsed time 0.338 seconds (00:00:00.338) -bash-4.1$ ./odb64luo -x "select * from tbjson" odb [2017-09-18 15:29:28]: starting ODBC connection(s)... 0 1,hello 2,world [0.0.0]--- 2 row(s) selected in 0.025s (prep 0.006s, exec 0.008s, fetch 0.011s/0.006s) odb [2017-09-18 15:29:28]: exiting. Session Elapsed time 0.284 seconds (00:00:00.284)` You can merge this pull request into a Git repository by running: $ git pull https://github.com/SuJinpei/incubator-trafodion trafodion-2726 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/incubator-trafodion/pull/1237.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #1237 ---