[ https://issues.apache.org/jira/browse/TRAFODION-1473?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15085814#comment-15085814 ]
ASF GitHub Bot commented on TRAFODION-1473: ------------------------------------------- Github user sandhyasun commented on a diff in the pull request: https://github.com/apache/incubator-trafodion/pull/248#discussion_r48979457 --- Diff: core/sql/clitest/blobtest.cpp --- @@ -0,0 +1,255 @@ +/********************************************************************** +// @@@ 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 @@@ +**********************************************************************/ +/* -*-C++-*- +**************************************************************************** +* +* File: Helper functions for use by bin/clitest.cpp +* Description: Test driver useing exe util cli interface +* +* +* +* +**************************************************************************** +*/ +#include "blobtest.h" + +Int32 extractLengthOfLobColumn(CliGlobals *cliglob, char *lobHandle, + Int64 &lengthOfLob, + char *lobColumnName, char *tableName) +{ + Int32 retcode = 0; + char * query = new char[4096]; + ExeCliInterface cliInterface((cliglob->currContext())->exHeap(), (Int32)SQLCHARSETCODE_UTF8, cliglob->currContext(),NULL); + //Use lob handle to retrieve the lob length. + char lobLengthResult[200]; + str_cpy_all(lobLengthResult," ",200); + Int32 lobLengthResultLen = 0; + str_sprintf(query,"extract loblength (lob '%s') LOCATION %Ld ",lobHandle, &lengthOfLob); + retcode = cliInterface.executeImmediate(query,lobLengthResult,&lobLengthResultLen,FALSE); + + delete query; + return retcode; + +} + +Int32 extractLobHandle(CliGlobals *cliglob, char *& lobHandle, + char *lobColumnName, char *tableName) +{ + Int32 retcode = 0; + ExeCliInterface cliInterface((cliglob->currContext())->exHeap(), (Int32)SQLCHARSETCODE_UTF8, cliglob->currContext(),NULL); + char * query = new char[4096]; + Int32 lobHandleLen = 0; + str_sprintf(query,"select %s from %s",lobColumnName,tableName); + + retcode = cliInterface.executeImmediate(query,lobHandle,&lobHandleLen,FALSE); + + if (retcode) + return retcode; + lobHandle[lobHandleLen]='\0'; + delete query; + + return retcode; + +} + +Int32 extractLobToBuffer(CliGlobals *cliglob, char * lobHandle, Int64 &lengthOfLob, + char *lobColumnName, char *tableName) +{ + Int32 retcode = 0; + ExeCliInterface cliInterface((cliglob->currContext())->exHeap(), (Int32)SQLCHARSETCODE_UTF8, cliglob->currContext(),NULL); + // Extract lob data into a buffer. + char * query = new char [500]; + + char *lobFinalBuf = new char[lengthOfLob]; + char statusBuf[200] = {'\0'}; + Int32 statusBufLen = 0; + Int64 lobExtractLen = 1000; + char *lobDataBuf = new char[lobExtractLen]; + + str_sprintf(query,"extract lobtobuffer(lob '%s', LOCATION %Ld, SIZE %Ld) ", lobHandle, (Int64)lobDataBuf, &lobExtractLen); + + + retcode = cliInterface.executeImmediatePrepare(query); + short i = 0; + while ((retcode != 100) && !(retcode<0)) + { + retcode = cliInterface.clearExecFetchClose(NULL,NULL,statusBuf, &statusBufLen); + if (!retcode) + { + memcpy((char*)&(lobFinalBuf[i]),(char *)lobDataBuf,lobExtractLen); + i += lobExtractLen; + } + } + if (retcode ==100 || retcode ==0) + { + FILE * lobFileId = fopen("lob_output_file","w"); + + int byteCount=fwrite(lobFinalBuf,sizeof(char),lengthOfLob, lobFileId); + cout << "Writing " << byteCount << " bytes from user buffer to file lob_output_file in current directory" << endl; + + fclose(lobFileId); + } + delete lobFinalBuf; + delete query; + delete lobDataBuf; + + + return retcode; + +} + + +Int32 extractLobToFileInChunks(CliGlobals *cliglob, char * lobHandle, char *filename,Int64 &lengthOfLob, + char *lobColumnName, char *tableName) +{ + Int32 retcode = 0; + ExeCliInterface cliInterface((cliglob->currContext())->exHeap(), (Int32)SQLCHARSETCODE_UTF8, cliglob->currContext(),NULL); + // Extract lob data into a buffer. + char * query = new char [500]; + + + char statusBuf[200] = {'\0'}; + Int32 statusBufLen = 0; + Int64 lobExtractLen = 1000; + char *lobDataBuf = new char[lobExtractLen]; + Int64 *inputOutputAddr = &lobExtractLen; + + str_sprintf(query,"extract lobtobuffer(lob '%s', LOCATION %Ld, SIZE %Ld) ", lobHandle, (Int64)lobDataBuf, inputOutputAddr); + + + retcode = cliInterface.executeImmediatePrepare(query); + short i = 0; + FILE * lobFileId = fopen(filename,"a+"); + int byteCount = 0; + while ((retcode != 100) && !(retcode<0)) + { + retcode = cliInterface.clearExecFetchClose(NULL,NULL,statusBuf, &statusBufLen); + if (!retcode) + { + byteCount=fwrite(lobDataBuf,sizeof(char),*inputOutputAddr, lobFileId); + cout << "Wrote " << byteCount << " bytes to file : " << filename << endl; + } + } + + + fclose(lobFileId); + + + delete query; + delete lobDataBuf; + + + return retcode; + +} + + +Int32 insertBufferToLob(CliGlobals *cliglob, char *tableName) +{ + Int32 retcode = 0; + ExeCliInterface cliInterface((cliglob->currContext())->exHeap(), (Int32)SQLCHARSETCODE_UTF8, cliglob->currContext(),NULL); + // Extract lob data into a buffer. + char * query = new char [500]; + + + char statusBuf[200] = {'\0'}; + Int32 statusBufLen = 0; + Int64 lobInsertLen = 10; + char *lobDataBuf = new char[lobInsertLen]; + memcpy(lobDataBuf, "xxxxxyyyyy",10); + str_sprintf(query,"insert into %s values (1, buffertolob (LOCATION %Ld, SIZE %Ld))", tableName,(Int64)lobDataBuf, lobInsertLen); + + + retcode = cliInterface.executeImmediate(query); + if (retcode <0) + return retcode; --- End diff -- Fixed > Adding external buffer and file input and extract support for LOB datatypes > ----------------------------------------------------------------------------- > > Key: TRAFODION-1473 > URL: https://issues.apache.org/jira/browse/TRAFODION-1473 > Project: Apache Trafodion > Issue Type: Task > Components: sql-cmp, sql-exe > Environment: Trafodion > Reporter: Sandhya Sundaresan > Assignee: Sandhya Sundaresan > Labels: features > Fix For: 1.2-incubating > > > LOB datatype is disabled in Trafodion until the following support is fully > in. > Here are the list of tasks and items to support : > 1. Support input of linux files (on platform) into LOB columns. > 2. Support extract of LOB data into linux files on platform. > 3. Support input of hdfs files into LOB columns. > 4. Support extract of LOB data into hdfs files. > 5. Support chunking to input a very large external file into LOB columns. > 6. Use CQD concept to limit LOB max size and limit chunk size for extract > /input. > TBD > 7. Support for input/extract of external files off platform into LOB columns. > 8. Support in connectivity and driver for real LOB data type. -- This message was sent by Atlassian JIRA (v6.3.4#6332)