Permalink
Browse files

Update template package to reflect new format

  • Loading branch information...
1 parent fd080db commit 467303ec24aba7e24d5ad03be450068d104e3dd1 @alamb alamb committed Nov 22, 2011
@@ -0,0 +1,28 @@
+
+Portions of this software Copyright (c) 2011 by Vertica, an HP
+Company. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+- Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
View
@@ -0,0 +1,89 @@
+############################
+# Vertica Analytic Database
+#
+# Makefile to build package directory
+#
+# Copyright 2011 Vertica Systems, an HP Company
+############################
+
+SDK?=/opt/vertica/sdk
+VSQL?=vsql
+
+VERTICA_SDK_INCLUDE = $(SDK)/include
+SIMULATOR_PATH = $(SDK)/simulator
+
+THIRD_PARTY = $(shell pwd)/src/third-party
+THIRD_PARTY_INCLUDE = $(THIRD_PARTY)/include
+
+# Add in your source files below
+BUILD_FILES = build/Vertica.o \
+ $(addprefix build/,RemoveSpace.o)
+
+# Define the .so name here (and update the references in ddl/install.sql and ddl/uninstall.sql)
+PACKAGE_LIBNAME = lib/Template.so
+
+CXX=g++
+CXXFLAGS=-g -D HAVE_LONG_LONG_INT_64 -c -I ../include -Wall -Wno-unused-value -fPIC -I $(VERTICA_SDK_INCLUDE) -I $(THIRD_PARTY_INCLUDE)
+LDFLAGS=-shared
+
+# add optimization if not a debug build
+# (make DEBUG=true" will make a non-optimized build)
+ifndef DEBUG
+CXXFLAGS+= -O3 -DNDEBUG
+CFLAGS+= -O3 -DNDEBUG
+endif
+
+.PHONEY: $(PACKAGE_LIBNAME)
+all: $(PACKAGE_LIBNAME)
+
+# Main target that builds the package library
+$(PACKAGE_LIBNAME): $(BUILD_FILES)
+ mkdir -p lib
+ $(CXX) $(LDFLAGS) -o $@ $(BUILD_FILES)
+
+# rule to make build/XXX.so from src/XXX.so
+build/%.o: src/%.cpp
+ @mkdir -p build
+ $(CXX) $(CXXFLAGS) $< -o $@
+
+# rule to compile symbols from the vertica SDK:
+build/Vertica.o: $(VERTICA_SDK_INCLUDE)/Vertica.cpp
+ @mkdir -p build
+ $(CXX) $(CXXFLAGS) $(VERTICA_SDK_INCLUDE)/Vertica.cpp -o $@
+
+# example rule to make build/XX.o from third-party/src/*.c
+#build/%.o: $(THIRD_PARTY)/src/%.c
+# @mkdir -p build
+# $(CXX) $(CXXFLAGS) $< -o $@
+
+
+# Targets to install and uninstall the library and functions
+install: $(PACKAGE_LIBNAME) ddl/install.sql
+ $(VSQL) -f ddl/install.sql
+uninstall: ddl/uninstall.sql
+ $(VSQL) -f ddl/uninstall.sql
+
+# run examples
+test:
+ $(VSQL) -f examples/removespace.sql
+
+clean:
+ rm -rf build
+ rm -rf lib
+ rm -f vsim*
+
+##############
+# Advanced upsage: use simulator to debug and test
+##############
+
+DEBUG_DATA_PATH = $(shell pwd)/test-data
+
+# Run the simulator against the functons
+sim_test: all simulator
+ $(VALGRIND) ./vsim $(PACKAGE_LIBNAME) FunctionName $(DEBUG_DATA_PATH)/testdata.txt
+
+# build the simulator (in SIMULATOR_PATH) and simlink it here
+simulator:
+ $(MAKE) -C $(SIMULATOR_PATH)
+ ln -f -s $(SIMULATOR_PATH)/vsim
+
@@ -1,19 +1,54 @@
-***************
-** Example Vertica UDF package
-**
-** Please edit this file to include information about your actual package functions
-***************
+-------------------------------
+INTRODUCTION
+-------------------------------
-1) To build, run:
+This is a template designed to assist creating packages of extensions
+to the Vertica Analytic Database.
- cd build
- make
+You should fill out this section with a high level summary of the
+package and the functionality it provides.
-2) to install, run:
+-------------------------------
+BUILDING
+-------------------------------
-./install.sh
+To build:
-3) to uninstall, execute the following sql:
+$ make
-./uninstall.sh
+-------------------------------
+INSTALLING / UNINSTALLING
+-------------------------------
+
+Assuming vsql is in your path, just do:
+
+$ make install
+$ make uninstall
+
+Alternately, you can find the DDL that 'make install' uses in:
+ src/ddl/install.sql
+and
+ src/ddl/uninstall.sql
+
+-------------------------------
+USAGE
+-------------------------------
+
+This section should contain instructions on usage of the functions
+contained within the package. All functions should be accompanied with
+an example of use in the examples directory.
+
+-------------------------------
+PERFORMANCE
+-------------------------------
+
+This section should contain any performance metrics you may have
+measured for your package. Please include what hardware and data size
+your measurements were performed on.
+
+-------------------------------
+LICENSE
+-------------------------------
+
+Please see LICENSE.txt
@@ -1,63 +0,0 @@
-############################
-# Vertica Analytic Database
-#
-# Makefile to build package directory
-#
-# Copyright 2011 Vertica Systems, an HP Company
-############################
-
-ifdef RUN_VALGRIND
-VALGRIND=valgrind --leak-check=full
-endif
-
-
-SDK?=/opt/vertica/sdk
-VERTICA_SDK_INCLUDE = $(SDK)/include
-SIMULATOR_PATH = $(SDK)/simulator
-
-BUILD_PATH = $(shell pwd)
-THIRD_PARTY = $(shell pwd)/third-party
-THIRD_PARTY_INSTALL = $(THIRD_PARTY)/install
-THIRD_PARTY_LIB = $(THIRD_PARTY_INSTALL)/lib
-THIRD_PARTY_INCLUDE = $(THIRD_PARTY_INSTALL)/include
-DEBUG_DATA_PATH = $(shell pwd)/test-data
-
-PACKAGE_FUNCTIONS = Package.so
-PACKAGE_FUNCTIONS_LIB = $(BUILD_PATH)/../lib
-PACKAGE_FUNCTIONS_TARGET = $(PACKAGE_FUNCTIONS_LIB)/$(PACKAGE_FUNCTIONS)
-
-CXX=g++
-CXXFLAGS= -Wl,-rpath $(THIRD_PARTY_LIB) -D HAVE_LONG_LONG_INT_64 -I$(VERTICA_SDK_INCLUDE) -I$(THIRD_PARTY_INCLUDE) -g -Wall -Wno-unused-value -shared -fPIC -std=c++0x -O3 -DNDEBUG
-
-#for third party libs
-CXXINCFLAGS =
-CXXLIBFLAGS =
-
-export PATH := $(THIRD_PARTY_LIB):$(PATH)
-
-.PHONEY: $(PACKAGE_FUNCTIONS_TARGET)
-
-all: $(PACKAGE_FUNCTIONS_TARGET)
-
-
-# build package functions
-$(PACKAGE_FUNCTIONS_TARGET): src/*.cpp
- mkdir -p $(PACKAGE_FUNCTIONS_LIB)
- (cd $(THIRD_PARTY); $(MAKE) all )
- $(CXX) $(CXXFLAGS) $(CXXINCFLAGS) $(CXXLIBFLAGS) -o $@ src/*.cpp $(VERTICA_SDK_INCLUDE)/Vertica.cpp
-
-# Run the simulator against the functons
-sim_test: all simulator
- $(VALGRIND) ./vsim $(PACKAGE_FUNCTIONS_TARGET) FunctionName $(DEBUG_DATA_PATH)/testdata.txt
-
-# build the simulator (in SIMULATOR_PATH) and simlink it here
-simulator:
- $(MAKE) -C $(SIMULATOR_PATH)
- ln -f -s $(SIMULATOR_PATH)/vsim
-
-clean:
- rm -rf $(PACKAGE_FUNCTIONS_TARGET)
- rm -f ./*.so
- rm -f ./src/*.o
- rm -f vsim*
-
@@ -1,126 +0,0 @@
-#include "Vertica.h"
-#include <sstream>
-#include <map>
-
-using namespace Vertica;
-using namespace std;
-
-
-const int WIDTH = 2000;
-
-class ConnectBy : public TransformFunction
-{
- virtual void processPartition(ServerInterface &srvInterface,
- PartitionReader &input_reader,
- PartitionWriter &output_writer)
- {
- map<vint, vint> parent;
- map<vint, string> label;
- map<vint, string> separator;
-
-
- if (input_reader.getNumCols() != 4)
- vt_report_error(0, "Function only accepts 4 argument, but %zu provided", input_reader.getNumCols());
-
- do {
- parent[input_reader.getIntRef(1)] = input_reader.getIntRef(0);
- label[input_reader.getIntRef(1)] = input_reader.getStringRef(2).str();
- separator[input_reader.getIntRef(1)] = input_reader.getStringRef(3).str();
-
- srvInterface.log(" adding %s ", input_reader.getStringRef(2).str().c_str());
-
-
- } while (input_reader.next());
-
-
- srvInterface.log("1");
- // exit(0);
-
- map<vint, string> cache;
- map<vint, vint> depth;
- map<vint, string>::iterator p;
-
- for (p = label.begin(); p != label.end(); ++p) {
- if (cache.count(p->first) == 0) {
-
- string output = p->second;
- vint current_depth = 0;
- vint current = parent[p->first];
- while (current != vint_null ) {
-
- srvInterface.log("working on %lld", current);
-
- if (cache.count(current) > 0 ) {
- // Found the parent's path in the cache
- output = cache[current] + separator[current] + output;
- current_depth = depth[current] + 1ull;
- break;
- } else {
- // prepend parent label + separator
- output = label[current] + separator[current] + output;
- current = parent[current];
- current_depth = current_depth + 1ull;
- }
- }
-
- cache[p->first] = output;
- depth[p->first] = current_depth;
- }
-
- srvInterface.log("attempting to output %lld", p->first);
-
- output_writer.setInt(0,p->first);
- output_writer.setInt(1,depth[p->first]);
- VString &word = output_writer.getStringRef(2);
- word.copy(cache[p->first]);
- output_writer.next();
- }
-
-
- }
-
-
-};
-
-
-class ConnectByFactory : public TransformFunctionFactory
-{
- // Tell Vertica that we take in a row with 5 inputs (parent ID, child ID, label, separator,
- // and return a row with 2 strings (id, path)
- virtual void getPrototype(ServerInterface &srvInterface, ColumnTypes &argTypes, ColumnTypes &returnType)
- {
- argTypes.addInt();
- argTypes.addInt();
- argTypes.addVarchar();
- argTypes.addVarchar();
-
- returnType.addInt();
- returnType.addInt();
- returnType.addVarchar();
- }
-
- // Tell Vertica what our return string length will be, given the input
- // string length
- virtual void getReturnType(ServerInterface &srvInterface,
- const SizedColumnTypes &input_types,
- SizedColumnTypes &output_types)
- {
- // Error out if we're called with anything but 1 argument
- if (input_types.getColumnCount() != 4)
- vt_report_error(0, "Function only accepts 3 arguments, but %zu provided", input_types.getColumnCount());
-
-
- // Our output size will never be more than the input size
- output_types.addInt("identifier");
- output_types.addInt("depth");
- output_types.addVarchar(WIDTH, "path");
- }
-
- virtual TransformFunction *createTransformFunction(ServerInterface &srvInterface)
- { return vt_createFuncObj(srvInterface.allocator, ConnectBy); }
-
-};
-
-RegisterFactory(ConnectByFactory);
-
-
@@ -1,5 +0,0 @@
-# This makefile is for building any third-party libraries (e.g. boost)
-# that are required for this libary. See other packages for examples.
-
-all:
- mkdir -p install/lib
@@ -0,0 +1,10 @@
+-- Installaction script: defined the shared library and the appropriate entry poings
+
+select version();
+
+\set libfile '\''`pwd`'/lib/Template.so\'';
+
+CREATE LIBRARY TemplateLib as :libfile;
+CREATE FUNCTION RemoveSpace as language 'C++' name 'RemoveSpaceFactory' library TemplateLib;
+
+
@@ -0,0 +1 @@
+DROP LIBRARY TemplateLib CASCADE;
Oops, something went wrong.

0 comments on commit 467303e

Please sign in to comment.