Ejemplo n.º 1
0
bool LeafNode::load_all_buckets(BlockReader& reader)
{
    Slice buffer;
    if (tree_->compressor_) {
        size_t buffer_length = 0;
        for (size_t i = 0; i < buckets_info_.size(); i++ ) {
            if (buffer_length < buckets_info_[i].uncompressed_length) {
                buffer_length = buckets_info_[i].uncompressed_length;
            }
        }
        buffer = Slice::alloc(buffer_length);
    }

    bool ret = true;
    for (size_t i = 0; i < buckets_info_.size(); i++) {
        reader.seek(buckets_info_[i].offset);

        RecordBucket *bucket = new RecordBucket();
        if (bucket == NULL) {
            ret = false;
            break;
        }

        if (!read_bucket(reader, buckets_info_[i].length, 
                         buckets_info_[i].uncompressed_length,
                         bucket, buffer)) {
            ret = false;
            delete bucket;
            break;
        }

        records_.set_bucket(i, bucket);
    }

    if (buffer.size()) {
        buffer.destroy();
    }

    status_ = kFullLoaded;
    return ret;
}
    /*
     * This method processes a block of rows in a single invocation.
     *
     * The inputs are retrieved via arg_reader
     * The outputs are returned via arg_writer
     */
    virtual void processBlock(ServerInterface &srvInterface,
                              BlockReader &arg_reader,
                              BlockWriter &res_writer)
    {
        // Basic error checking
        if (arg_reader.getNumCols() != 4)
            vt_report_error(0, "Function only accept 1 arguments, but %zu provided", 
                            arg_reader.getNumCols());
        
        // While we have inputs to process
        do {

            char curlresponse[1024]; 

            // Get a copy of the input string
            std::string  streetStr = arg_reader.getStringRef(0).str();
            std::string  cityStr = arg_reader.getStringRef(1).str();
            std::string  stateStr = arg_reader.getStringRef(2).str();
            std::string  zipStr = arg_reader.getStringRef(3).str();

	    // Replaces spaces with %20 for URLs
            for (size_t pos = streetStr.find(' '); 
		 pos != string::npos;
		 pos = streetStr.find(' ',pos)) 
	    {
	      	streetStr.replace(pos,1,"%20");
	    } 

  	     for (size_t pos = cityStr.find(' ');
                 pos != string::npos;
                 pos = cityStr.find(' ',pos))                         
            {
                cityStr.replace(pos,1,"%20");
            }

            // Build the URL 
            std::string URL = baseURL + "&streetAddress=" + streetStr;
            URL += "&city=" + cityStr;
            URL += "&state=" + stateStr;
            URL += "&zip=" + zipStr;

            if(curl) {
              curl_easy_setopt(curl, CURLOPT_URL, URL.c_str());
            }
    
	    // curl setup
            curl_easy_setopt(curl, CURLOPT_HEADER, 0);
            curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0);
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, &curlresponse );

	    // perform the webservice call	
            res = curl_easy_perform(curl);

            // parse webservice response to get the latitude and longitude data 
            std::vector<std::string> tokens;
            split(tokens,string(curlresponse),',');
            std::string latlong = tokens[3] + "," + tokens[4];

	    // copy data back to Vertica
            res_writer.getStringRef().copy(latlong);
            res_writer.next();
        } while (arg_reader.next());
    }
Ejemplo n.º 3
0
 //! Advances this reader to the next value.
 void Next() {
     hasCurrent_ = reader_.HasNext();
     if (hasCurrent_)
         current_ = reader_.template Next<ItemType>();
 }