You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
the begginning
This commit is contained in:
85
utils/windowfunction/Makefile
Executable file
85
utils/windowfunction/Makefile
Executable file
@ -0,0 +1,85 @@
|
||||
#******************************************************************************************
|
||||
# $Id: Makefile 3821 2013-05-17 23:58:16Z xlou $
|
||||
#
|
||||
# Copyright (C) 2009-2013 Calpont Corporation
|
||||
# All rights reserved
|
||||
#*****************************************************************************************/
|
||||
include ../../rules.mak
|
||||
.PHONY: install clean test docs coverage leakcheck
|
||||
|
||||
PROGRAM=libwindowfunction.so
|
||||
VERSION=1.0.0
|
||||
LIBRARY=$(PROGRAM).$(VERSION)
|
||||
|
||||
CPPFLAGS= -I. -I$(EXPORT_ROOT)/include -I/usr/include/libxml2
|
||||
CXXFLAGS+=$(DEBUG_FLAGS) -Wall -fpic
|
||||
|
||||
TLIBS=-L. -L$(EXPORT_ROOT)/lib
|
||||
GLIBS=-L$(EXPORT_ROOT)/lib
|
||||
|
||||
LLIBS=-L$(CALPONT_LIBRARY_PATH) -lwindowfunction
|
||||
|
||||
SRCS=\
|
||||
framebound.cpp \
|
||||
frameboundrange.cpp \
|
||||
frameboundrow.cpp \
|
||||
idborderby.cpp \
|
||||
windowframe.cpp \
|
||||
windowfunction.cpp \
|
||||
windowfunctiontype.cpp \
|
||||
wf_count.cpp \
|
||||
wf_lead_lag.cpp \
|
||||
wf_min_max.cpp \
|
||||
wf_nth_value.cpp \
|
||||
wf_ntile.cpp \
|
||||
wf_percentile.cpp \
|
||||
wf_ranking.cpp \
|
||||
wf_row_number.cpp \
|
||||
wf_stats.cpp \
|
||||
wf_sum_avg.cpp
|
||||
|
||||
LINCLUDES=\
|
||||
framebound.h \
|
||||
frameboundrange.h \
|
||||
frameboundrow.h \
|
||||
idborderby.h \
|
||||
windowframe.h \
|
||||
windowfunction.h \
|
||||
windowfunctiontype.h
|
||||
|
||||
OBJS=$(SRCS:.cpp=.o)
|
||||
|
||||
$(LIBRARY): $(OBJS)
|
||||
$(LINK.cpp) -shared -o $(LIBRARY) $(OBJS)
|
||||
rm -f $(PROGRAM)
|
||||
ln -s $(LIBRARY) $(PROGRAM)
|
||||
|
||||
install: bootstrap $(LIBRARY)
|
||||
umask 002; \
|
||||
mkdir -p $(INSTALL_ROOT_LIB) $(INSTALL_ROOT_INCLUDE); \
|
||||
pushd $(INSTALL_ROOT_LIB) >/dev/null; \
|
||||
rm -f $(LIBRARY) $(PROGRAM); \
|
||||
ln -s $(LIBRARY) $(PROGRAM); \
|
||||
popd >/dev/null; \
|
||||
$(INSTALL) $(LIBRARY) $(INSTALL_ROOT_LIB)
|
||||
|
||||
bootstrap:
|
||||
$(INSTALL) $(LINCLUDES) $(INSTALL_ROOT_INCLUDE)
|
||||
|
||||
clean:
|
||||
rm -rf $(PROGRAM) $(LIBRARY) $(OBJS)
|
||||
rm -rf *~ *.o *.d* *-gcov* *.gcov
|
||||
rm -rf html config.tag
|
||||
|
||||
docs:
|
||||
doxygen $(EXPORT_ROOT)/etc/Doxyfile
|
||||
|
||||
%.d: %.cpp
|
||||
@set -e; rm -f $@; \
|
||||
$(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
|
||||
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
|
||||
rm -f $@.$$$$
|
||||
|
||||
ifndef BOOTSTRAP
|
||||
-include $(SRCS:.cpp=.d) tdriver.d
|
||||
endif
|
63
utils/windowfunction/Makefile.am
Normal file
63
utils/windowfunction/Makefile.am
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright (C) 2014 InfiniDB, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; version 2 of
|
||||
# the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
|
||||
# $Id: Makefile.am 3821 2013-05-17 23:58:16Z xlou $
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
AM_CPPFLAGS = $(idb_common_includes) $(idb_cppflags)
|
||||
AM_CFLAGS = $(idb_cflags)
|
||||
AM_CXXFLAGS = $(idb_cxxflags)
|
||||
AM_LDFLAGS = -version-info 1:0:0 $(idb_ldflags)
|
||||
lib_LTLIBRARIES = libwindowfunction.la
|
||||
libwindowfunction_la_SOURCES = \
|
||||
framebound.cpp \
|
||||
frameboundrange.cpp \
|
||||
frameboundrow.cpp \
|
||||
idborderby.cpp \
|
||||
windowframe.cpp \
|
||||
windowfunction.cpp \
|
||||
windowfunctiontype.cpp \
|
||||
wf_count.cpp \
|
||||
wf_lead_lag.cpp \
|
||||
wf_min_max.cpp \
|
||||
wf_nth_value.cpp \
|
||||
wf_ntile.cpp \
|
||||
wf_percentile.cpp \
|
||||
wf_ranking.cpp \
|
||||
wf_row_number.cpp \
|
||||
wf_stats.cpp \
|
||||
wf_sum_avg.cpp
|
||||
|
||||
include_HEADERS = \
|
||||
framebound.h \
|
||||
frameboundrange.h \
|
||||
frameboundrow.h \
|
||||
idborderby.h \
|
||||
windowframe.h \
|
||||
windowfunction.h \
|
||||
windowfunctiontype.h
|
||||
|
||||
test:
|
||||
|
||||
coverage:
|
||||
|
||||
leakcheck:
|
||||
|
||||
docs:
|
||||
|
||||
bootstrap: install-data-am
|
||||
|
590
utils/windowfunction/Makefile.in
Normal file
590
utils/windowfunction/Makefile.in
Normal file
@ -0,0 +1,590 @@
|
||||
# Makefile.in generated by automake 1.9.6 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
# Copyright (C) 2014 InfiniDB, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; version 2 of
|
||||
# the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
|
||||
# $Id: Makefile.am 3821 2013-05-17 23:58:16Z xlou $
|
||||
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
top_builddir = ../..
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
INSTALL = @INSTALL@
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
subdir = utils/windowfunction
|
||||
DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
|
||||
$(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/compilerflags.m4 \
|
||||
$(top_srcdir)/m4/functions.m4 $(top_srcdir)/m4/install.m4 \
|
||||
$(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||
am__vpath_adj = case $$p in \
|
||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
*) f=$$p;; \
|
||||
esac;
|
||||
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
|
||||
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"
|
||||
libLTLIBRARIES_INSTALL = $(INSTALL)
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
libwindowfunction_la_LIBADD =
|
||||
am_libwindowfunction_la_OBJECTS = framebound.lo frameboundrange.lo \
|
||||
frameboundrow.lo idborderby.lo windowframe.lo \
|
||||
windowfunction.lo windowfunctiontype.lo wf_count.lo \
|
||||
wf_lead_lag.lo wf_min_max.lo wf_nth_value.lo wf_ntile.lo \
|
||||
wf_percentile.lo wf_ranking.lo wf_row_number.lo wf_stats.lo \
|
||||
wf_sum_avg.lo
|
||||
libwindowfunction_la_OBJECTS = $(am_libwindowfunction_la_OBJECTS)
|
||||
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
|
||||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
LTCXXCOMPILE = $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) \
|
||||
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
|
||||
$(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
CXXLD = $(CXX)
|
||||
CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \
|
||||
$(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
SOURCES = $(libwindowfunction_la_SOURCES)
|
||||
DIST_SOURCES = $(libwindowfunction_la_SOURCES)
|
||||
includeHEADERS_INSTALL = $(INSTALL_HEADER)
|
||||
HEADERS = $(include_HEADERS)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
ALLOCA = @ALLOCA@
|
||||
AMDEP_FALSE = @AMDEP_FALSE@
|
||||
AMDEP_TRUE = @AMDEP_TRUE@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CXX = @CXX@
|
||||
CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
ECHO = @ECHO@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
F77 = @F77@
|
||||
FFLAGS = @FFLAGS@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LEX = @LEX@
|
||||
LEXLIB = @LEXLIB@
|
||||
LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
POW_LIB = @POW_LIB@
|
||||
RANLIB = @RANLIB@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
XML2_CONFIG = @XML2_CONFIG@
|
||||
XML_CPPFLAGS = @XML_CPPFLAGS@
|
||||
XML_LIBS = @XML_LIBS@
|
||||
YACC = @YACC@
|
||||
ac_ct_AR = @ac_ct_AR@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_F77 = @ac_ct_F77@
|
||||
ac_ct_RANLIB = @ac_ct_RANLIB@
|
||||
ac_ct_STRIP = @ac_ct_STRIP@
|
||||
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
|
||||
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
|
||||
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
|
||||
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
datadir = @datadir@
|
||||
etcdir = @etcdir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
idb_brm_libs = @idb_brm_libs@
|
||||
idb_cflags = @idb_cflags@
|
||||
idb_common_includes = @idb_common_includes@
|
||||
idb_common_ldflags = @idb_common_ldflags@
|
||||
idb_common_libs = @idb_common_libs@
|
||||
idb_cppflags = @idb_cppflags@
|
||||
idb_cxxflags = @idb_cxxflags@
|
||||
idb_exec_libs = @idb_exec_libs@
|
||||
idb_ldflags = @idb_ldflags@
|
||||
idb_oam_libs = @idb_oam_libs@
|
||||
idb_write_libs = @idb_write_libs@
|
||||
idbinstall = @idbinstall@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localdir = @localdir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
march_flags = @march_flags@
|
||||
mibdir = @mibdir@
|
||||
mkdir_p = @mkdir_p@
|
||||
mysqldir = @mysqldir@
|
||||
netsnmp_libs = @netsnmp_libs@
|
||||
netsnmpagntdir = @netsnmpagntdir@
|
||||
netsnmpdir = @netsnmpdir@
|
||||
netsnmplibrdir = @netsnmplibrdir@
|
||||
netsnmpmachdir = @netsnmpmachdir@
|
||||
netsnmpsysdir = @netsnmpsysdir@
|
||||
oldincludedir = @oldincludedir@
|
||||
postdir = @postdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
sbindir = @sbindir@
|
||||
sharedir = @sharedir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
toolsdir = @toolsdir@
|
||||
AM_CPPFLAGS = $(idb_common_includes) $(idb_cppflags)
|
||||
AM_CFLAGS = $(idb_cflags)
|
||||
AM_CXXFLAGS = $(idb_cxxflags)
|
||||
AM_LDFLAGS = -version-info 1:0:0 $(idb_ldflags)
|
||||
lib_LTLIBRARIES = libwindowfunction.la
|
||||
libwindowfunction_la_SOURCES = \
|
||||
framebound.cpp \
|
||||
frameboundrange.cpp \
|
||||
frameboundrow.cpp \
|
||||
idborderby.cpp \
|
||||
windowframe.cpp \
|
||||
windowfunction.cpp \
|
||||
windowfunctiontype.cpp \
|
||||
wf_count.cpp \
|
||||
wf_lead_lag.cpp \
|
||||
wf_min_max.cpp \
|
||||
wf_nth_value.cpp \
|
||||
wf_ntile.cpp \
|
||||
wf_percentile.cpp \
|
||||
wf_ranking.cpp \
|
||||
wf_row_number.cpp \
|
||||
wf_stats.cpp \
|
||||
wf_sum_avg.cpp
|
||||
|
||||
include_HEADERS = \
|
||||
framebound.h \
|
||||
frameboundrange.h \
|
||||
frameboundrow.h \
|
||||
idborderby.h \
|
||||
windowframe.h \
|
||||
windowfunction.h \
|
||||
windowfunctiontype.h
|
||||
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .cpp .lo .o .obj
|
||||
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
|
||||
&& exit 0; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu utils/windowfunction/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --gnu utils/windowfunction/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
|
||||
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
f=$(am__strip_dir) \
|
||||
echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
|
||||
$(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-libLTLIBRARIES:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
p=$(am__strip_dir) \
|
||||
echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
|
||||
$(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
|
||||
done
|
||||
|
||||
clean-libLTLIBRARIES:
|
||||
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
|
||||
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
|
||||
test "$$dir" != "$$p" || dir=.; \
|
||||
echo "rm -f \"$${dir}/so_locations\""; \
|
||||
rm -f "$${dir}/so_locations"; \
|
||||
done
|
||||
libwindowfunction.la: $(libwindowfunction_la_OBJECTS) $(libwindowfunction_la_DEPENDENCIES)
|
||||
$(CXXLINK) -rpath $(libdir) $(libwindowfunction_la_LDFLAGS) $(libwindowfunction_la_OBJECTS) $(libwindowfunction_la_LIBADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/framebound.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/frameboundrange.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/frameboundrow.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/idborderby.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wf_count.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wf_lead_lag.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wf_min_max.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wf_nth_value.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wf_ntile.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wf_percentile.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wf_ranking.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wf_row_number.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wf_stats.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wf_sum_avg.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/windowframe.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/windowfunction.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/windowfunctiontype.Plo@am__quote@
|
||||
|
||||
.cpp.o:
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
|
||||
|
||||
.cpp.obj:
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
|
||||
.cpp.lo:
|
||||
@am__fastdepCXX_TRUE@ if $(LTCXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $<
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
|
||||
distclean-libtool:
|
||||
-rm -f libtool
|
||||
uninstall-info-am:
|
||||
install-includeHEADERS: $(include_HEADERS)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(includedir)" || $(mkdir_p) "$(DESTDIR)$(includedir)"
|
||||
@list='$(include_HEADERS)'; for p in $$list; do \
|
||||
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
|
||||
f=$(am__strip_dir) \
|
||||
echo " $(includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includedir)/$$f'"; \
|
||||
$(includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includedir)/$$f"; \
|
||||
done
|
||||
|
||||
uninstall-includeHEADERS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(include_HEADERS)'; for p in $$list; do \
|
||||
f=$(am__strip_dir) \
|
||||
echo " rm -f '$(DESTDIR)$(includedir)/$$f'"; \
|
||||
rm -f "$(DESTDIR)$(includedir)/$$f"; \
|
||||
done
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$tags $$unique; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$tags $$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& cd $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) $$here
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
|
||||
list='$(DISTFILES)'; for file in $$list; do \
|
||||
case $$file in \
|
||||
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
|
||||
esac; \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
|
||||
dir="/$$dir"; \
|
||||
$(mkdir_p) "$(distdir)$$dir"; \
|
||||
else \
|
||||
dir=''; \
|
||||
fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
|
||||
fi; \
|
||||
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: Makefile $(LTLIBRARIES) $(HEADERS)
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"; do \
|
||||
test -z "$$dir" || $(mkdir_p) "$$dir"; \
|
||||
done
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
|
||||
mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am: install-includeHEADERS
|
||||
|
||||
install-exec-am: install-libLTLIBRARIES
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-man:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
|
||||
mostlyclean-libtool
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-includeHEADERS uninstall-info-am \
|
||||
uninstall-libLTLIBRARIES
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
|
||||
clean-libLTLIBRARIES clean-libtool ctags distclean \
|
||||
distclean-compile distclean-generic distclean-libtool \
|
||||
distclean-tags distdir dvi dvi-am html html-am info info-am \
|
||||
install install-am install-data install-data-am install-exec \
|
||||
install-exec-am install-includeHEADERS install-info \
|
||||
install-info-am install-libLTLIBRARIES install-man \
|
||||
install-strip installcheck installcheck-am installdirs \
|
||||
maintainer-clean maintainer-clean-generic mostlyclean \
|
||||
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
|
||||
pdf pdf-am ps ps-am tags uninstall uninstall-am \
|
||||
uninstall-includeHEADERS uninstall-info-am \
|
||||
uninstall-libLTLIBRARIES
|
||||
|
||||
|
||||
test:
|
||||
|
||||
coverage:
|
||||
|
||||
leakcheck:
|
||||
|
||||
docs:
|
||||
|
||||
bootstrap: install-data-am
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
88
utils/windowfunction/framebound.cpp
Normal file
88
utils/windowfunction/framebound.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: framebound.cpp 3828 2013-05-22 17:58:14Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include "idberrorinfo.h"
|
||||
#include "errorids.h"
|
||||
#include "exceptclasses.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "framebound.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
int64_t FrameBound::getBound(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
if (fBoundType == WF__UNBOUNDED_PRECEDING)
|
||||
return b;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
const string FrameBound::toString() const
|
||||
{
|
||||
ostringstream oss;
|
||||
switch (fBoundType)
|
||||
{
|
||||
case WF__UNBOUNDED_PRECEDING:
|
||||
oss << "unbound preceding";
|
||||
break;
|
||||
case WF__UNBOUNDED_FOLLOWING:
|
||||
oss << "unbound following";
|
||||
break;
|
||||
case WF__CONSTANT_PRECEDING:
|
||||
oss << "constant preceding";
|
||||
break;
|
||||
case WF__CONSTANT_FOLLOWING:
|
||||
oss << "constant following";
|
||||
break;
|
||||
case WF__EXPRESSION_PRECEDING:
|
||||
oss << "expression preceding";
|
||||
break;
|
||||
case WF__EXPRESSION_FOLLOWING:
|
||||
oss << "expression following";
|
||||
break;
|
||||
case WF__CURRENT_ROW:
|
||||
default:
|
||||
oss << "current row";
|
||||
break;
|
||||
}
|
||||
oss << endl;
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
127
utils/windowfunction/framebound.h
Normal file
127
utils/windowfunction/framebound.h
Normal file
@ -0,0 +1,127 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: framebound.h 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_FRAMEBOUND_H
|
||||
#define UTILS_FRAMEBOUND_H
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "rowgroup.h"
|
||||
#include "windowfunctionstep.h"
|
||||
|
||||
|
||||
namespace ordering
|
||||
{
|
||||
// forward reference
|
||||
class EqualCompData;
|
||||
};
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
const int WF__UNBOUNDED_PRECEDING = 0;
|
||||
const int WF__CONSTANT_PRECEDING = 1;
|
||||
const int WF__EXPRESSION_PRECEDING = 2;
|
||||
const int WF__CURRENT_ROW = 3;
|
||||
const int WF__UNBOUNDED_FOLLOWING = 4;
|
||||
const int WF__CONSTANT_FOLLOWING = 5;
|
||||
const int WF__EXPRESSION_FOLLOWING = 6;
|
||||
|
||||
|
||||
const int WF__BOUND_ALL = -1; // unbounded - unbounded
|
||||
const int WF__BOUND_ROLLING = -2; // unbounded - current row
|
||||
|
||||
/** @brief class FrameBound
|
||||
*
|
||||
*/
|
||||
class FrameBound
|
||||
{
|
||||
public:
|
||||
/** @brief FrameBound constructor
|
||||
* @param t, frame type
|
||||
*/
|
||||
FrameBound(int t = 0) : fBoundType(t), fStart(true) {};
|
||||
|
||||
/** @brief FrameBound destructor
|
||||
*/
|
||||
virtual ~FrameBound() {};
|
||||
|
||||
/** @brief clone
|
||||
*/
|
||||
virtual FrameBound* clone()
|
||||
{ return new FrameBound(*this); }
|
||||
|
||||
/** @brief virtual void getBound
|
||||
* @param b: partition start position
|
||||
* @param e: partition end position
|
||||
* @param c: current position
|
||||
* @return : frame position
|
||||
*/
|
||||
virtual int64_t getBound(int64_t b, int64_t e, int64_t c);
|
||||
|
||||
virtual const std::string toString() const;
|
||||
|
||||
void setRowData(const boost::shared_ptr<std::vector<joblist::RowPosition> >& d) {fRowData = d;}
|
||||
void setRowMetaData(const rowgroup::RowGroup& g, const rowgroup::Row& r)
|
||||
{ fRowGroup = g; fRow = r; }
|
||||
|
||||
int64_t boundType() const { return fBoundType; }
|
||||
void boundType(int64_t t) { fBoundType = t; }
|
||||
|
||||
bool start() const { return fStart; }
|
||||
void start(bool s) { fStart = s; }
|
||||
|
||||
const boost::shared_ptr<ordering::EqualCompData>& peer() const { return fPeer; }
|
||||
void peer(const boost::shared_ptr<ordering::EqualCompData>& p) { fPeer = p; }
|
||||
|
||||
// for string table
|
||||
void setCallback(joblist::WindowFunctionStep* step) { fStep = step; }
|
||||
rowgroup::Row::Pointer getPointer(joblist::RowPosition& r)
|
||||
{ return fStep->getPointer(r, fRowGroup, fRow); }
|
||||
|
||||
protected:
|
||||
// boundary type
|
||||
int64_t fBoundType;
|
||||
bool fStart;
|
||||
|
||||
// data
|
||||
boost::shared_ptr<std::vector<joblist::RowPosition> > fRowData;
|
||||
|
||||
// row meta data
|
||||
rowgroup::RowGroup fRowGroup;
|
||||
rowgroup::Row fRow;
|
||||
|
||||
// functor for peer checking
|
||||
boost::shared_ptr<ordering::EqualCompData> fPeer;
|
||||
|
||||
// pointer back to step
|
||||
joblist::WindowFunctionStep* fStep;
|
||||
};
|
||||
|
||||
|
||||
extern std::map<int, std::string> colType2String;
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_FRAMEBOUND_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
368
utils/windowfunction/frameboundrange.cpp
Normal file
368
utils/windowfunction/frameboundrange.cpp
Normal file
@ -0,0 +1,368 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: frameboundrange.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include "idberrorinfo.h"
|
||||
#include "errorids.h"
|
||||
#include "exceptclasses.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "frameboundrange.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
int64_t FrameBoundRange::getBound(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
if (fStart)
|
||||
{
|
||||
while (c > b)
|
||||
{
|
||||
if (!fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(c-1))))
|
||||
break;
|
||||
|
||||
c--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (c < e)
|
||||
{
|
||||
if (!fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(c+1))))
|
||||
break;
|
||||
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
const string FrameBoundRange::toString() const
|
||||
{
|
||||
return FrameBound::toString();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
int64_t FrameBoundConstantRange<T>::getBound(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
// set row data
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
getValue(fValue, fIndex[2]);
|
||||
|
||||
// make sure the expr is not negative
|
||||
validate();
|
||||
|
||||
// calculate the offset, and move
|
||||
if (fIsZero)
|
||||
c = FrameBoundRange::getBound(b, e, c);
|
||||
else if (fBoundType < WF__CURRENT_ROW)
|
||||
c -= getPrecedingOffset(c, b);
|
||||
else
|
||||
c += getFollowingOffset(c, e);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
int64_t FrameBoundConstantRange<T>::getPrecedingOffset(int64_t c, int64_t b)
|
||||
{
|
||||
// test each row to find the bound
|
||||
bool next = true;
|
||||
int64_t i = c;
|
||||
int64_t j = 0;
|
||||
|
||||
for (i--, j++; i >= b && next; i--, j++)
|
||||
{
|
||||
// set row data, get order by column value
|
||||
fRow.setData(getPointer(fRowData->at(i)));
|
||||
ValueType<T> v;
|
||||
getValue(v, fIndex[0]);
|
||||
if (v.fIsNull)
|
||||
{
|
||||
next = fValue.fIsNull; // let null = null
|
||||
}
|
||||
else if (fValue.fIsNull)
|
||||
{
|
||||
next = false;
|
||||
}
|
||||
else if (fAsc && v.fValue < fValue.fValue)
|
||||
{
|
||||
next = false;
|
||||
}
|
||||
else if (!fAsc && v.fValue > fValue.fValue)
|
||||
{
|
||||
next = false;
|
||||
}
|
||||
else if (!fStart && v.fValue == fValue.fValue)
|
||||
{
|
||||
next = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!next)
|
||||
{
|
||||
if (fStart)
|
||||
j -= 2;
|
||||
else
|
||||
j -= 1;
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
int64_t FrameBoundConstantRange<T>::getFollowingOffset(int64_t c, int64_t e)
|
||||
{
|
||||
// test each row to find the bound
|
||||
bool next = true;
|
||||
int64_t i = c;
|
||||
int64_t j = 0;
|
||||
|
||||
for (i++, j++; i <= e && next; i++, j++)
|
||||
{
|
||||
// set row data, get order by column value
|
||||
fRow.setData(getPointer(fRowData->at(i)));
|
||||
ValueType<T> v;
|
||||
getValue(v, fIndex[0]);
|
||||
if (v.fIsNull)
|
||||
{
|
||||
next = fValue.fIsNull; // let null = null
|
||||
}
|
||||
else if (fValue.fIsNull)
|
||||
{
|
||||
next = false;
|
||||
}
|
||||
else if (fAsc && v.fValue > fValue.fValue)
|
||||
{
|
||||
next = false;
|
||||
}
|
||||
else if (!fAsc && v.fValue < fValue.fValue)
|
||||
{
|
||||
next = false;
|
||||
}
|
||||
else if (fStart && v.fValue == fValue.fValue)
|
||||
{
|
||||
next = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!next)
|
||||
{
|
||||
if (fStart)
|
||||
j -= 1;
|
||||
else
|
||||
j -= 2;
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void FrameBoundConstantRange<T>::getValue(ValueType<T>& v, int64_t i)
|
||||
{
|
||||
v.fIsNull = fRow.isNullValue(i);
|
||||
if (!v.fIsNull)
|
||||
v.fValue = fRow.getIntField(i);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
T FrameBoundConstantRange<T>::getValueByType(int64_t i)
|
||||
{
|
||||
T t;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
template<> int64_t FrameBoundConstantRange<int64_t>::getValueByType(int64_t i)
|
||||
{
|
||||
return fRow.getIntField(i);
|
||||
}
|
||||
|
||||
|
||||
template<> uint64_t FrameBoundConstantRange<uint64_t>::getValueByType(int64_t i)
|
||||
{
|
||||
uint64_t v = fRow.getUintField(i);
|
||||
|
||||
// convert date to datetime, [refer to treenode.h]
|
||||
if (fRow.getColType(fIndex[0]) == execplan::CalpontSystemCatalog::DATE && i == 0)
|
||||
v = v << 32;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
template<> double FrameBoundConstantRange<double>::getValueByType(int64_t i)
|
||||
{
|
||||
return fRow.getDoubleField(i);
|
||||
}
|
||||
|
||||
|
||||
template<> float FrameBoundConstantRange<float>::getValueByType(int64_t i)
|
||||
{
|
||||
return fRow.getFloatField(i);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
const string FrameBoundConstantRange<T>::toString() const
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << fValue.fValue << " " << FrameBound::toString();
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
int64_t FrameBoundExpressionRange<T>::getPrecedingOffset(int64_t c, int64_t b)
|
||||
{
|
||||
return FrameBoundConstantRange<T>::getPrecedingOffset(c, b);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
int64_t FrameBoundExpressionRange<T>::getFollowingOffset(int64_t c, int64_t e)
|
||||
{
|
||||
return FrameBoundConstantRange<T>::getFollowingOffset(c, e);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void FrameBoundExpressionRange<T>::validate()
|
||||
{
|
||||
bool invalid = false;
|
||||
ostringstream oss;
|
||||
|
||||
if (this->fRow.isNullValue(this->fIndex[1]))
|
||||
{
|
||||
invalid = true;
|
||||
oss << "NULL";
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (this->fRow.getColType(this->fIndex[1]))
|
||||
{
|
||||
case execplan::CalpontSystemCatalog::TINYINT:
|
||||
case execplan::CalpontSystemCatalog::SMALLINT:
|
||||
case execplan::CalpontSystemCatalog::MEDINT:
|
||||
case execplan::CalpontSystemCatalog::INT:
|
||||
case execplan::CalpontSystemCatalog::BIGINT:
|
||||
case execplan::CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
int64_t tmp = this->fRow.getIntField(this->fIndex[1]);
|
||||
this->fIsZero = (tmp == 0);
|
||||
if (tmp < 0)
|
||||
{
|
||||
invalid = true;
|
||||
oss << tmp;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::DOUBLE:
|
||||
case execplan::CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
double tmp = this->fRow.getDoubleField(this->fIndex[1]);
|
||||
this->fIsZero = (tmp == 0.0);
|
||||
if (tmp < 0)
|
||||
{
|
||||
invalid = true;
|
||||
oss << tmp;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::FLOAT:
|
||||
case execplan::CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
float tmp = this->fRow.getFloatField(this->fIndex[1]);
|
||||
this->fIsZero = (tmp == 0.0);
|
||||
if (tmp < 0)
|
||||
{
|
||||
invalid = true;
|
||||
oss << tmp;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case execplan::CalpontSystemCatalog::UTINYINT:
|
||||
case execplan::CalpontSystemCatalog::USMALLINT:
|
||||
case execplan::CalpontSystemCatalog::UMEDINT:
|
||||
case execplan::CalpontSystemCatalog::UINT:
|
||||
case execplan::CalpontSystemCatalog::UBIGINT:
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
default:
|
||||
{
|
||||
int64_t tmp = this->fRow.getIntField(this->fIndex[1]);
|
||||
this->fIsZero = (tmp == 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (invalid)
|
||||
{
|
||||
oss << " (expr)";
|
||||
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ERR_WF_BOUND_OUT_OF_RANGE, oss.str()),
|
||||
ERR_WF_BOUND_OUT_OF_RANGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
const string FrameBoundExpressionRange<T>::toString() const
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << " value_expr " << FrameBound::toString();
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
template class FrameBoundConstantRange<int64_t>;
|
||||
template class FrameBoundConstantRange<uint64_t>;
|
||||
template class FrameBoundConstantRange<double>;
|
||||
template class FrameBoundConstantRange<float>;
|
||||
|
||||
template class FrameBoundExpressionRange<int64_t>;
|
||||
template class FrameBoundExpressionRange<double>;
|
||||
template class FrameBoundExpressionRange<float>;
|
||||
template class FrameBoundExpressionRange<uint64_t>;
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
208
utils/windowfunction/frameboundrange.h
Normal file
208
utils/windowfunction/frameboundrange.h
Normal file
@ -0,0 +1,208 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: frameboundrange.h 3868 2013-06-06 22:13:05Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_FRAMEBOUNDRANGE_H
|
||||
#define UTILS_FRAMEBOUNDRANGE_H
|
||||
|
||||
|
||||
#include "framebound.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
/** @brief class FrameBoundRange
|
||||
*
|
||||
*/
|
||||
class FrameBoundRange : public FrameBound
|
||||
{
|
||||
public:
|
||||
/** @brief FrameBoundRange constructor
|
||||
* @param t, frame type
|
||||
* @param a, order by sort spec: asc | desc
|
||||
* @param n, order by sort spec: null first | null last
|
||||
* @param v, order by column data type
|
||||
*/
|
||||
FrameBoundRange(int t = 0, bool a = true, bool n = true)
|
||||
: FrameBound(t), fAsc(a), fNullFirst(n), fIsZero(false) {};
|
||||
|
||||
/** @brief FrameBoundRange destructor
|
||||
*/
|
||||
virtual ~FrameBoundRange() {};
|
||||
|
||||
/** @brief clone
|
||||
*/
|
||||
virtual FrameBound* clone() { return NULL; } // abstract class
|
||||
|
||||
/** @brief virtual void getBound
|
||||
*/
|
||||
int64_t getBound(int64_t, int64_t, int64_t);
|
||||
|
||||
const std::string toString() const;
|
||||
|
||||
void setTupleId(std::vector<uint64_t> ids) { fTupleId = ids; }
|
||||
std::vector<uint64_t> getTupleId() const { return fTupleId; }
|
||||
|
||||
void setIndex(vector<int> idx) { fIndex = idx; }
|
||||
const std::vector<int>& getIndex() const { return fIndex; }
|
||||
|
||||
void isZero(bool z) { fIsZero = z; }
|
||||
bool isZero() const { return fIsZero; }
|
||||
|
||||
protected:
|
||||
|
||||
// for range calculation
|
||||
// data, row meta data, order by column index, ascending | descending
|
||||
// [0]: order by; [1]: interval; [2]: [0] +/- [1]
|
||||
std::vector<uint64_t> fTupleId;
|
||||
std::vector<int> fIndex;
|
||||
|
||||
// order by sort specification
|
||||
bool fAsc;
|
||||
bool fNullFirst;
|
||||
|
||||
// in case expr evaluates to 0
|
||||
bool fIsZero;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** @brief struct ValueType
|
||||
*
|
||||
*/
|
||||
template<typename T>
|
||||
struct ValueType
|
||||
{
|
||||
T fValue;
|
||||
bool fIsNull;
|
||||
|
||||
// constructor
|
||||
ValueType() : fValue(0), fIsNull(false) {}
|
||||
};
|
||||
|
||||
|
||||
/** @brief class FrameBoundConstantRange
|
||||
*
|
||||
*/
|
||||
template<typename T>
|
||||
class FrameBoundConstantRange : public FrameBoundRange
|
||||
{
|
||||
public:
|
||||
/** @brief FrameBoundConstant constructor
|
||||
* @param t, frame type
|
||||
* @param a, order by sort spec: asc | desc
|
||||
* @param n, order by sort spec: null first | null last
|
||||
* @param c, constant value. !! caller need to check NULL or negative value !!
|
||||
*/
|
||||
FrameBoundConstantRange(int t = 0, bool a = true, bool n = true, void* c = NULL)
|
||||
: FrameBoundRange(t, a, n)
|
||||
{
|
||||
fValue.fIsNull = (c == NULL);
|
||||
if (!fValue.fIsNull)
|
||||
fValue.fValue = *((T*) c);
|
||||
};
|
||||
|
||||
/** @brief FrameBoundConstantRange destructor
|
||||
*/
|
||||
virtual ~FrameBoundConstantRange() {};
|
||||
|
||||
/** @brief clone
|
||||
*/
|
||||
virtual FrameBound* clone()
|
||||
{ return new FrameBoundConstantRange(*this); }
|
||||
|
||||
/** @brief virtual void getBound
|
||||
*/
|
||||
int64_t getBound(int64_t, int64_t, int64_t);
|
||||
|
||||
const std::string toString() const;
|
||||
|
||||
protected:
|
||||
|
||||
// find the range offset
|
||||
// i: partition upper bound
|
||||
// j: current row
|
||||
// k: partition lower bound
|
||||
virtual int64_t getPrecedingOffset(int64_t j, int64_t i);
|
||||
virtual int64_t getFollowingOffset(int64_t j, int64_t k);
|
||||
|
||||
// validate value is not negative
|
||||
virtual void validate() {}
|
||||
|
||||
// get value at fIndex[x]
|
||||
void getValue(ValueType<T>&, int64_t);
|
||||
T getValueByType(int64_t);
|
||||
|
||||
// order by column value type
|
||||
ValueType<T> fValue;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** @brief class FrameBoundExpressionRange
|
||||
*
|
||||
*/
|
||||
template<typename T>
|
||||
class FrameBoundExpressionRange : public FrameBoundConstantRange<T>
|
||||
{
|
||||
public:
|
||||
/** @brief FrameBoundExpressionRange constructor
|
||||
* @param t, frame type
|
||||
* @param a, order by sort spec: asc | desc
|
||||
* @param n, order by sort spec: null first | null last
|
||||
*/
|
||||
FrameBoundExpressionRange(int t = 0, bool a = true, bool n = true) :
|
||||
FrameBoundConstantRange<T>(t, a, n) {};
|
||||
|
||||
/** @brief FrameBoundExpressionRange destructor
|
||||
*/
|
||||
virtual ~FrameBoundExpressionRange() {};
|
||||
|
||||
/** @brief clone
|
||||
*/
|
||||
virtual FrameBound* clone()
|
||||
{ return new FrameBoundExpressionRange(*this); }
|
||||
|
||||
/** @brief virtual void getBound
|
||||
*/
|
||||
// int64_t getBound(int64_t, int64_t, int64_t);
|
||||
|
||||
const std::string toString() const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
// virtual in FrameBoundRange
|
||||
int64_t getPrecedingOffset(int64_t j, int64_t i);
|
||||
int64_t getFollowingOffset(int64_t j, int64_t k);
|
||||
|
||||
// validate the expression is not negative
|
||||
void validate();
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_FRAMEBOUNDRANGE_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
154
utils/windowfunction/frameboundrow.cpp
Normal file
154
utils/windowfunction/frameboundrow.cpp
Normal file
@ -0,0 +1,154 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: frameboundrow.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include "idberrorinfo.h"
|
||||
#include "errorids.h"
|
||||
#include "exceptclasses.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "treenode.h"
|
||||
#include "frameboundrow.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
int64_t FrameBoundRow::getBound(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
const string FrameBoundRow::toString() const
|
||||
{
|
||||
return FrameBound::toString();
|
||||
}
|
||||
|
||||
|
||||
int64_t FrameBoundConstantRow::getBound(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
if (fBoundType < WF__CURRENT_ROW)
|
||||
{
|
||||
if (fOffset <= (c - b))
|
||||
c -= fOffset;
|
||||
else
|
||||
c = b - (!fStart ? 1 : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fOffset <= (e - c))
|
||||
c += fOffset;
|
||||
else
|
||||
c = e + (fStart ? 1 : 0);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
const string FrameBoundConstantRow::toString() const
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << fOffset << " " << FrameBound::toString();
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
int64_t FrameBoundExpressionRow<T>::getBound(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
// set row data
|
||||
// get expression int value
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
|
||||
if (fRow.isNullValue(fExprIdx))
|
||||
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ERR_WF_BOUND_OUT_OF_RANGE, "NULL"),
|
||||
ERR_WF_BOUND_OUT_OF_RANGE);
|
||||
|
||||
getOffset();
|
||||
|
||||
if (fOffset < 0)
|
||||
{
|
||||
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ERR_WF_BOUND_OUT_OF_RANGE, fOffset),
|
||||
ERR_WF_BOUND_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
return FrameBoundConstantRow::getBound(b, e, c);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
const string FrameBoundExpressionRow<T>::toString() const
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "value_expr " << FrameBound::toString();
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
template<typename T> void FrameBoundExpressionRow<T>::getOffset()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<> void FrameBoundExpressionRow<int64_t>::getOffset()
|
||||
{
|
||||
fOffset = fRow.getIntField(fExprIdx);
|
||||
}
|
||||
|
||||
|
||||
template<> void FrameBoundExpressionRow<uint64_t>::getOffset()
|
||||
{
|
||||
fOffset = fRow.getUintField(fExprIdx);
|
||||
}
|
||||
|
||||
|
||||
template<> void FrameBoundExpressionRow<double>::getOffset()
|
||||
{
|
||||
fOffset = (int64_t) fRow.getDoubleField(fExprIdx);
|
||||
}
|
||||
|
||||
|
||||
template<> void FrameBoundExpressionRow<float>::getOffset()
|
||||
{
|
||||
fOffset = (int64_t) fRow.getFloatField(fExprIdx);
|
||||
}
|
||||
|
||||
|
||||
template class FrameBoundExpressionRow<int64_t>;
|
||||
template class FrameBoundExpressionRow<double>;
|
||||
template class FrameBoundExpressionRow<float>;
|
||||
template class FrameBoundExpressionRow<uint64_t>;
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
152
utils/windowfunction/frameboundrow.h
Normal file
152
utils/windowfunction/frameboundrow.h
Normal file
@ -0,0 +1,152 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: frameboundrow.h 3868 2013-06-06 22:13:05Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_FRAMEBOUNDROW_H
|
||||
#define UTILS_FRAMEBOUNDROW_H
|
||||
|
||||
|
||||
#include "framebound.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
/** @brief class FrameBoundRow
|
||||
*
|
||||
*/
|
||||
class FrameBoundRow : public FrameBound
|
||||
{
|
||||
public:
|
||||
/** @brief FrameBoundRow constructor
|
||||
* @param t, frame type
|
||||
*/
|
||||
FrameBoundRow(int t = 0) : FrameBound(t) {};
|
||||
|
||||
/** @brief FrameBoundRow destructor
|
||||
*/
|
||||
virtual ~FrameBoundRow() {};
|
||||
|
||||
/** @brief clone
|
||||
*/
|
||||
virtual FrameBound* clone()
|
||||
{ return new FrameBoundRow(*this); }
|
||||
|
||||
/** @brief virtual void getBound
|
||||
*/
|
||||
int64_t getBound(int64_t, int64_t, int64_t);
|
||||
|
||||
const std::string toString() const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** @brief class FrameBoundConstantRow
|
||||
*
|
||||
*/
|
||||
class FrameBoundConstantRow : public FrameBoundRow
|
||||
{
|
||||
public:
|
||||
/** @brief FrameBoundConstant constructor
|
||||
* @param t, frame type
|
||||
* @param c, constant value. !! caller need to check NULL or negative value !!
|
||||
*/
|
||||
FrameBoundConstantRow(int t = 0, int c = 0) : FrameBoundRow(t), fOffset(c) {};
|
||||
|
||||
/** @brief FrameBoundConstantRow destructor
|
||||
*/
|
||||
virtual ~FrameBoundConstantRow() {};
|
||||
|
||||
/** @brief clone
|
||||
*/
|
||||
virtual FrameBound* clone()
|
||||
{ return new FrameBoundConstantRow(*this); }
|
||||
|
||||
/** @brief virtual void getBound
|
||||
*/
|
||||
int64_t getBound(int64_t, int64_t, int64_t);
|
||||
|
||||
const std::string toString() const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// constant offset
|
||||
int64_t fOffset;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** @brief class FrameBoundExpressionRow
|
||||
*
|
||||
*/
|
||||
template<typename T>
|
||||
class FrameBoundExpressionRow : public FrameBoundConstantRow
|
||||
{
|
||||
public:
|
||||
/** @brief FrameBoundExpressionRow constructor
|
||||
* @param t, frame type
|
||||
*/
|
||||
FrameBoundExpressionRow(int t, uint64_t id = -1, int idx = -1) :
|
||||
FrameBoundConstantRow(t), fExprTupleId(id), fExprIdx(idx) {};
|
||||
|
||||
/** @brief FrameBoundExpressionRow destructor
|
||||
*/
|
||||
virtual ~FrameBoundExpressionRow() {};
|
||||
|
||||
/** @brief clone
|
||||
*/
|
||||
virtual FrameBound* clone()
|
||||
{ return new FrameBoundExpressionRow<T>(*this); }
|
||||
|
||||
/** @brief virtual void getBound
|
||||
*/
|
||||
int64_t getBound(int64_t, int64_t, int64_t);
|
||||
|
||||
const std::string toString() const;
|
||||
|
||||
void setExprTupleId(int id) { fExprTupleId = id; }
|
||||
uint64_t getExprTupleId() const { return fExprTupleId; }
|
||||
|
||||
void setExprIndex(int i) { fExprIdx = i; }
|
||||
uint64_t getExprIndex() const { return fExprIdx; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void getOffset();
|
||||
|
||||
// id and index in row
|
||||
uint64_t fExprTupleId;
|
||||
int fExprIdx;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_FRAMEBOUNDROW_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
466
utils/windowfunction/idborderby.cpp
Normal file
466
utils/windowfunction/idborderby.cpp
Normal file
@ -0,0 +1,466 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: idborderby.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
#include <iostream>
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <stack>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_array.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "errorids.h"
|
||||
#include "exceptclasses.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "calpontsystemcatalog.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "resourcemanager.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "idborderby.h"
|
||||
|
||||
|
||||
namespace ordering
|
||||
{
|
||||
|
||||
int IntCompare::operator()(IdbCompare* l, Row::Pointer r1, Row::Pointer r2)
|
||||
{
|
||||
l->row1().setData(r1);
|
||||
l->row2().setData(r2);
|
||||
|
||||
bool b1 = l->row1().isNullValue(fSpec.fIndex);
|
||||
bool b2 = l->row2().isNullValue(fSpec.fIndex);
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if (b1 == true || b2 == true)
|
||||
{
|
||||
if (b1 == false && b2 == true)
|
||||
ret = fSpec.fNf;
|
||||
else if (b1 == true && b2 == false)
|
||||
ret = -fSpec.fNf;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t v1 = l->row1().getIntField(fSpec.fIndex);
|
||||
int64_t v2 = l->row2().getIntField(fSpec.fIndex);
|
||||
|
||||
if (v1 > v2)
|
||||
ret = fSpec.fAsc;
|
||||
else if (v1 < v2)
|
||||
ret = -fSpec.fAsc;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int UintCompare::operator()(IdbCompare* l, Row::Pointer r1, Row::Pointer r2)
|
||||
{
|
||||
l->row1().setData(r1);
|
||||
l->row2().setData(r2);
|
||||
|
||||
bool b1 = l->row1().isNullValue(fSpec.fIndex);
|
||||
bool b2 = l->row2().isNullValue(fSpec.fIndex);
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if (b1 == true || b2 == true)
|
||||
{
|
||||
if (b1 == false && b2 == true)
|
||||
ret = fSpec.fNf;
|
||||
else if (b1 == true && b2 == false)
|
||||
ret = -fSpec.fNf;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t v1 = l->row1().getUintField(fSpec.fIndex);
|
||||
uint64_t v2 = l->row2().getUintField(fSpec.fIndex);
|
||||
|
||||
if (v1 > v2)
|
||||
ret = fSpec.fAsc;
|
||||
else if (v1 < v2)
|
||||
ret = -fSpec.fAsc;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int StringCompare::operator()(IdbCompare* l, Row::Pointer r1, Row::Pointer r2)
|
||||
{
|
||||
l->row1().setData(r1);
|
||||
l->row2().setData(r2);
|
||||
|
||||
bool b1 = l->row1().isNullValue(fSpec.fIndex);
|
||||
bool b2 = l->row2().isNullValue(fSpec.fIndex);
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if (b1 == true || b2 == true)
|
||||
{
|
||||
if (b1 == false && b2 == true)
|
||||
ret = fSpec.fNf;
|
||||
else if (b1 == true && b2 == false)
|
||||
ret = -fSpec.fNf;
|
||||
}
|
||||
else
|
||||
{
|
||||
string v1 = l->row1().getStringField(fSpec.fIndex);
|
||||
string v2 = l->row2().getStringField(fSpec.fIndex);
|
||||
|
||||
if (v1 > v2)
|
||||
ret = fSpec.fAsc;
|
||||
else if (v1 < v2)
|
||||
ret = -fSpec.fAsc;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int DoubleCompare::operator()(IdbCompare* l, Row::Pointer r1, Row::Pointer r2)
|
||||
{
|
||||
l->row1().setData(r1);
|
||||
l->row2().setData(r2);
|
||||
|
||||
bool b1 = l->row1().isNullValue(fSpec.fIndex);
|
||||
bool b2 = l->row2().isNullValue(fSpec.fIndex);
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if (b1 == true || b2 == true)
|
||||
{
|
||||
if (b1 == false && b2 == true)
|
||||
ret = fSpec.fNf;
|
||||
else if (b1 == true && b2 == false)
|
||||
ret = -fSpec.fNf;
|
||||
}
|
||||
else
|
||||
{
|
||||
double v1 = l->row1().getDoubleField(fSpec.fIndex);
|
||||
double v2 = l->row2().getDoubleField(fSpec.fIndex);
|
||||
|
||||
if (v1 > v2)
|
||||
ret = fSpec.fAsc;
|
||||
else if (v1 < v2)
|
||||
ret = -fSpec.fAsc;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int FloatCompare::operator()(IdbCompare* l, Row::Pointer r1, Row::Pointer r2)
|
||||
{
|
||||
l->row1().setData(r1);
|
||||
l->row2().setData(r2);
|
||||
|
||||
bool b1 = l->row1().isNullValue(fSpec.fIndex);
|
||||
bool b2 = l->row2().isNullValue(fSpec.fIndex);
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if (b1 == true || b2 == true)
|
||||
{
|
||||
if (b1 == false && b2 == true)
|
||||
ret = fSpec.fNf;
|
||||
else if (b1 == true && b2 == false)
|
||||
ret = -fSpec.fNf;
|
||||
}
|
||||
else
|
||||
{
|
||||
float v1 = l->row1().getFloatField(fSpec.fIndex);
|
||||
float v2 = l->row2().getFloatField(fSpec.fIndex);
|
||||
|
||||
if (v1 > v2)
|
||||
ret = fSpec.fAsc;
|
||||
else if (v1 < v2)
|
||||
ret = -fSpec.fAsc;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool CompareRule::less(Row::Pointer r1, Row::Pointer r2)
|
||||
{
|
||||
for (vector<Compare*>::iterator i = fCompares.begin(); i != fCompares.end(); i++)
|
||||
{
|
||||
int c = ((*(*i))(fIdbCompare, r1, r2));
|
||||
|
||||
if (c < 0)
|
||||
return true;
|
||||
else if (c > 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CompareRule::compileRules(const std::vector<IdbSortSpec>& spec, const rowgroup::RowGroup& rg)
|
||||
{
|
||||
const vector<CalpontSystemCatalog::ColDataType>& types = rg.getColTypes();
|
||||
for (vector<IdbSortSpec>::const_iterator i = spec.begin(); i != spec.end(); i++)
|
||||
{
|
||||
switch (types[i->fIndex])
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
Compare* c = new IntCompare(*i);
|
||||
fCompares.push_back(c);
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
{
|
||||
Compare* c = new UintCompare(*i);
|
||||
fCompares.push_back(c);
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::CHAR:
|
||||
case CalpontSystemCatalog::VARCHAR:
|
||||
{
|
||||
Compare* c = new StringCompare(*i);
|
||||
fCompares.push_back(c);
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
Compare* c = new DoubleCompare(*i);
|
||||
fCompares.push_back(c);
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
Compare* c = new FloatCompare(*i);
|
||||
fCompares.push_back(c);
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::DATE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
{
|
||||
Compare* c = new UintCompare(*i);
|
||||
fCompares.push_back(c);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void IdbCompare::initialize(const RowGroup& rg)
|
||||
{
|
||||
fRowGroup = rg;
|
||||
fRowGroup.initRow(&fRow1);
|
||||
fRowGroup.initRow(&fRow2);
|
||||
}
|
||||
|
||||
|
||||
void IdbCompare::setStringTable(bool b)
|
||||
{
|
||||
fRowGroup.setUseStringTable(b);
|
||||
fRowGroup.initRow(&fRow1);
|
||||
fRowGroup.initRow(&fRow2);
|
||||
}
|
||||
|
||||
|
||||
// OrderByData class implementation
|
||||
OrderByData::OrderByData(const std::vector<IdbSortSpec>& spec, const rowgroup::RowGroup& rg)
|
||||
{
|
||||
IdbCompare::initialize(rg);
|
||||
fRule.compileRules(spec, rg);
|
||||
fRule.fIdbCompare = this;
|
||||
}
|
||||
|
||||
|
||||
// IdbOrderBy class implementation
|
||||
IdbOrderBy::IdbOrderBy() :
|
||||
fDistinct(false), fMemSize(0), fRowsPerRG(8192), fErrorCode(0), fRm(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IdbOrderBy::~IdbOrderBy()
|
||||
{
|
||||
if (fRm)
|
||||
fRm->returnMemory(fMemSize, fSessionMemLimit);
|
||||
|
||||
// delete compare objects
|
||||
vector<Compare*>::iterator i = fRule.fCompares.begin();
|
||||
while (i != fRule.fCompares.end())
|
||||
delete *i++;
|
||||
}
|
||||
|
||||
|
||||
void IdbOrderBy::initialize(const RowGroup& rg)
|
||||
{
|
||||
// initialize rows
|
||||
IdbCompare::initialize(rg);
|
||||
|
||||
uint64_t newSize = fRowsPerRG * rg.getRowSize();
|
||||
if (!fRm->getMemory(newSize, fSessionMemLimit))
|
||||
{
|
||||
cerr << IDBErrorInfo::instance()->errorMsg(fErrorCode)
|
||||
<< " @" << __FILE__ << ":" << __LINE__;
|
||||
throw IDBExcept(fErrorCode);
|
||||
}
|
||||
fMemSize += newSize;
|
||||
fData.reinit(fRowGroup, fRowsPerRG);
|
||||
fRowGroup.setData(&fData);
|
||||
fRowGroup.resetRowGroup(0);
|
||||
fRowGroup.initRow(&fRow0);
|
||||
fRowGroup.getRow(0, &fRow0);
|
||||
|
||||
// set compare functors
|
||||
fRule.compileRules(fOrderByCond, fRowGroup);
|
||||
|
||||
fRowGroup.initRow(&row1);
|
||||
fRowGroup.initRow(&row2);
|
||||
if (fDistinct)
|
||||
{
|
||||
fDistinctMap.reset(new DistinctMap_t(10, Hasher(this, getKeyLength()), Eq(this, getKeyLength())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool IdbOrderBy::getData(RGData& data)
|
||||
{
|
||||
if (fDataQueue.empty())
|
||||
return false;
|
||||
|
||||
data = fDataQueue.front();
|
||||
fDataQueue.pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool EqualCompData::operator()(Row::Pointer a, Row::Pointer b)
|
||||
{
|
||||
bool eq = true;
|
||||
fRow1.setData(a);
|
||||
fRow2.setData(b);
|
||||
|
||||
for (vector<uint64_t>::const_iterator i = fIndex.begin(); i != fIndex.end() && eq; i++)
|
||||
{
|
||||
CalpontSystemCatalog::ColDataType type = fRow1.getColType(*i);
|
||||
switch (type)
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::DATE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
{
|
||||
// equal compare. ignore sign and null
|
||||
eq = (fRow1.getUintField(*i) == fRow2.getUintField(*i));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::CHAR:
|
||||
case CalpontSystemCatalog::VARCHAR:
|
||||
{
|
||||
eq = (fRow1.getStringField(*i) == fRow2.getStringField(*i));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
eq = (fRow1.getDoubleField(*i) == fRow2.getDoubleField(*i));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
eq = (fRow1.getFloatField(*i) == fRow2.getFloatField(*i));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
eq = false;
|
||||
uint64_t ec = ERR_WF_UNKNOWN_COL_TYPE;
|
||||
cerr << IDBErrorInfo::instance()->errorMsg(ec, type)
|
||||
<< " @" << __FILE__ << ":" << __LINE__;
|
||||
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ec, type), ec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return eq;
|
||||
}
|
||||
|
||||
uint64_t IdbOrderBy::Hasher::operator()(const Row::Pointer &p) const
|
||||
{
|
||||
Row &row = ts->row1;
|
||||
row.setPointer(p);
|
||||
uint64_t ret = row.hash(colCount);
|
||||
//cout << "hash(): returning " << ret << " for row: " << row.toString() << endl;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool IdbOrderBy::Eq::operator()(const Row::Pointer &d1, const Row::Pointer &d2) const
|
||||
{
|
||||
Row &r1 = ts->row1, &r2 = ts->row2;
|
||||
r1.setPointer(d1);
|
||||
r2.setPointer(d2);
|
||||
bool ret = r1.equals(r2, colCount);
|
||||
//cout << "equals(): returning " << (int) ret << " for r1: " << r1.toString() << " r2: " << r2.toString()
|
||||
// << endl;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// vim:ts=4 sw=4:
|
||||
|
263
utils/windowfunction/idborderby.h
Normal file
263
utils/windowfunction/idborderby.h
Normal file
@ -0,0 +1,263 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: idborderby.h 4012 2013-07-24 21:04:45Z pleblanc $
|
||||
|
||||
|
||||
/** @file */
|
||||
|
||||
#ifndef IDB_ORDER_BY_H
|
||||
#define IDB_ORDER_BY_H
|
||||
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <boost/shared_array.hpp>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <unordered_set>
|
||||
#else
|
||||
#include <tr1/unordered_set>
|
||||
#endif
|
||||
|
||||
#include "rowgroup.h"
|
||||
#include "hasher.h"
|
||||
#include "stlpoolallocator.h"
|
||||
|
||||
|
||||
// forward reference
|
||||
namespace joblist
|
||||
{
|
||||
class ResourceManager;
|
||||
}
|
||||
|
||||
|
||||
namespace ordering
|
||||
{
|
||||
|
||||
|
||||
// forward reference
|
||||
class IdbCompare;
|
||||
|
||||
// order by specification
|
||||
struct IdbSortSpec
|
||||
{
|
||||
int fIndex;
|
||||
int fAsc; // <ordering specification> ::= ASC | DESC
|
||||
int fNf; // <null ordering> ::= NULLS FIRST | NULLS LAST
|
||||
|
||||
IdbSortSpec() : fIndex(-1), fAsc(1), fNf(1) {}
|
||||
IdbSortSpec(int i, bool b) : fIndex(i), fAsc(b ? 1 : -1), fNf(fAsc) {}
|
||||
IdbSortSpec(int i, bool b, bool n) : fIndex(i), fAsc(b ? 1 : -1), fNf(n ? 1 : -1) {}
|
||||
};
|
||||
|
||||
|
||||
// compare functor for different datatypes
|
||||
// cannot use template because Row's getXxxField method.
|
||||
class Compare
|
||||
{
|
||||
public:
|
||||
Compare(const IdbSortSpec& spec) : fSpec(spec) {}
|
||||
virtual ~Compare() {}
|
||||
|
||||
virtual int operator()(IdbCompare*, rowgroup::Row::Pointer, rowgroup::Row::Pointer) = 0;
|
||||
|
||||
protected:
|
||||
IdbSortSpec fSpec;
|
||||
};
|
||||
|
||||
|
||||
class IntCompare : public Compare
|
||||
{
|
||||
public:
|
||||
IntCompare(const IdbSortSpec& spec) : Compare(spec) {}
|
||||
|
||||
int operator()(IdbCompare*, rowgroup::Row::Pointer, rowgroup::Row::Pointer);
|
||||
};
|
||||
|
||||
|
||||
class UintCompare : public Compare
|
||||
{
|
||||
public:
|
||||
UintCompare(const IdbSortSpec& spec) : Compare(spec) {}
|
||||
|
||||
int operator()(IdbCompare*, rowgroup::Row::Pointer, rowgroup::Row::Pointer);
|
||||
};
|
||||
|
||||
|
||||
class StringCompare : public Compare
|
||||
{
|
||||
public:
|
||||
StringCompare(const IdbSortSpec& spec) : Compare(spec) {}
|
||||
|
||||
int operator()(IdbCompare*, rowgroup::Row::Pointer, rowgroup::Row::Pointer);
|
||||
};
|
||||
|
||||
|
||||
class DoubleCompare : public Compare
|
||||
{
|
||||
public:
|
||||
DoubleCompare(const IdbSortSpec& spec) : Compare(spec) {}
|
||||
|
||||
int operator()(IdbCompare*, rowgroup::Row::Pointer, rowgroup::Row::Pointer);
|
||||
};
|
||||
|
||||
|
||||
class FloatCompare : public Compare
|
||||
{
|
||||
public:
|
||||
FloatCompare(const IdbSortSpec& spec) : Compare(spec) {}
|
||||
|
||||
int operator()(IdbCompare*, rowgroup::Row::Pointer, rowgroup::Row::Pointer);
|
||||
};
|
||||
|
||||
|
||||
class CompareRule
|
||||
{
|
||||
public:
|
||||
CompareRule(IdbCompare* c = NULL) : fIdbCompare(c) {}
|
||||
|
||||
|
||||
bool less(rowgroup::Row::Pointer r1, rowgroup::Row::Pointer r2);
|
||||
|
||||
void compileRules(const std::vector<IdbSortSpec>&, const rowgroup::RowGroup&);
|
||||
|
||||
std::vector<Compare*> fCompares;
|
||||
IdbCompare* fIdbCompare;
|
||||
};
|
||||
|
||||
|
||||
class IdbCompare
|
||||
{
|
||||
public:
|
||||
IdbCompare() {};
|
||||
virtual ~IdbCompare() {};
|
||||
|
||||
virtual void initialize(const rowgroup::RowGroup&);
|
||||
void setStringTable(bool b);
|
||||
|
||||
rowgroup::Row& row1() { return fRow1; }
|
||||
rowgroup::Row& row2() { return fRow2; }
|
||||
|
||||
protected:
|
||||
rowgroup::RowGroup fRowGroup;
|
||||
rowgroup::Row fRow1;
|
||||
rowgroup::Row fRow2;
|
||||
};
|
||||
|
||||
|
||||
class OrderByRow
|
||||
{
|
||||
public:
|
||||
OrderByRow(const rowgroup::Row& r, CompareRule& c) : fData(r.getPointer()), fRule(&c) {}
|
||||
|
||||
bool operator < (const OrderByRow& rhs) const { return fRule->less(fData, rhs.fData); }
|
||||
|
||||
rowgroup::Row::Pointer fData;
|
||||
CompareRule* fRule;
|
||||
};
|
||||
|
||||
|
||||
class EqualCompData : public IdbCompare
|
||||
{
|
||||
public:
|
||||
EqualCompData(std::vector<uint64_t>& v) : fIndex(v) {}
|
||||
EqualCompData(std::vector<uint64_t>& v, const rowgroup::RowGroup& rg) :
|
||||
fIndex(v) { initialize(rg); }
|
||||
|
||||
~EqualCompData() {};
|
||||
|
||||
bool operator()(rowgroup::Row::Pointer, rowgroup::Row::Pointer);
|
||||
|
||||
//protected:
|
||||
std::vector<uint64_t> fIndex;
|
||||
};
|
||||
|
||||
|
||||
class OrderByData : public IdbCompare
|
||||
{
|
||||
public:
|
||||
OrderByData(const std::vector<IdbSortSpec>&, const rowgroup::RowGroup&);
|
||||
virtual ~OrderByData() {};
|
||||
|
||||
bool operator() (rowgroup::Row::Pointer p1, rowgroup::Row::Pointer p2) { return fRule.less(p1, p2); }
|
||||
const CompareRule& rule() const { return fRule; }
|
||||
|
||||
protected:
|
||||
CompareRule fRule;
|
||||
};
|
||||
|
||||
|
||||
// base classs for order by clause used in IDB
|
||||
class IdbOrderBy : public IdbCompare
|
||||
{
|
||||
public:
|
||||
IdbOrderBy();
|
||||
virtual ~IdbOrderBy();
|
||||
|
||||
virtual void initialize(const rowgroup::RowGroup&);
|
||||
virtual void processRow(const rowgroup::Row&) = 0;
|
||||
virtual uint64_t getKeyLength() const = 0;
|
||||
virtual const std::string toString() const = 0;
|
||||
|
||||
bool getData(rowgroup::RGData& data);
|
||||
|
||||
void distinct(bool b) { fDistinct = b; }
|
||||
bool distinct() const { return fDistinct; }
|
||||
|
||||
protected:
|
||||
std::vector<IdbSortSpec> fOrderByCond;
|
||||
std::priority_queue<OrderByRow> fOrderByQueue;
|
||||
rowgroup::Row fRow0;
|
||||
CompareRule fRule;
|
||||
|
||||
rowgroup::RGData fData;
|
||||
std::queue<rowgroup::RGData> fDataQueue;
|
||||
|
||||
struct Hasher {
|
||||
IdbOrderBy *ts;
|
||||
utils::Hasher_r h;
|
||||
uint32_t colCount;
|
||||
Hasher(IdbOrderBy *t, uint32_t c) : ts(t), colCount(c) { }
|
||||
uint64_t operator()(const rowgroup::Row::Pointer &) const;
|
||||
};
|
||||
struct Eq {
|
||||
IdbOrderBy *ts;
|
||||
uint32_t colCount;
|
||||
Eq(IdbOrderBy *t, uint32_t c) : ts(t), colCount(c) { }
|
||||
bool operator()(const rowgroup::Row::Pointer &, const rowgroup::Row::Pointer &) const;
|
||||
};
|
||||
|
||||
typedef std::tr1::unordered_set<rowgroup::Row::Pointer, Hasher, Eq,
|
||||
utils::STLPoolAllocator<rowgroup::Row::Pointer> > DistinctMap_t;
|
||||
boost::scoped_ptr<DistinctMap_t> fDistinctMap;
|
||||
rowgroup::Row row1, row2; // scratch space for Hasher & Eq
|
||||
|
||||
bool fDistinct;
|
||||
uint64_t fMemSize;
|
||||
uint64_t fRowsPerRG;
|
||||
uint64_t fErrorCode;
|
||||
joblist::ResourceManager* fRm;
|
||||
boost::shared_ptr<int64_t> fSessionMemLimit;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // IDB_ORDER_BY_H
|
||||
|
158
utils/windowfunction/wf_count.cpp
Normal file
158
utils/windowfunction/wf_count.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_count.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "joblisttypes.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "wf_count.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_count<T>::makeFunction(int id, const string& name, int ct)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
switch (ct)
|
||||
{
|
||||
case CalpontSystemCatalog::CHAR:
|
||||
case CalpontSystemCatalog::VARCHAR:
|
||||
case CalpontSystemCatalog::VARBINARY:
|
||||
{
|
||||
func.reset(new WF_count<string>(id, name));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
func.reset(new WF_count<int64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
WindowFunctionType* WF_count<T>::clone() const
|
||||
{
|
||||
return new WF_count(*this);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_count<T>::resetData()
|
||||
{
|
||||
fCount = 0;
|
||||
fSet.clear();
|
||||
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_count<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
if ((fFrameUnit == WF__FRAME_ROWS) ||
|
||||
(fPrev == -1) ||
|
||||
(!fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(fPrev)))))
|
||||
{
|
||||
// for unbounded - current row special handling
|
||||
if (fPrev >= b && fPrev < c)
|
||||
b = c;
|
||||
else if (fPrev <= e && fPrev > c)
|
||||
e = c;
|
||||
|
||||
// for count(*), the column is optimized out, index[1] does not exist.
|
||||
uint64_t colIn = (fFunctionId == WF__COUNT_ASTERISK) ? 0 : fFieldIndex[1];
|
||||
for (int64_t i = b; i <= e; i++)
|
||||
{
|
||||
if (i % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
if (fFunctionId == WF__COUNT_ASTERISK)
|
||||
{
|
||||
fCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(i)));
|
||||
if (fRow.isNullValue(colIn) == true)
|
||||
continue;
|
||||
|
||||
if (fFunctionId != WF__COUNT_DISTINCT)
|
||||
{
|
||||
fCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
T valIn;
|
||||
getValue(colIn, valIn);
|
||||
if (fSet.find(valIn) == fSet.end())
|
||||
{
|
||||
fCount++;
|
||||
|
||||
if (fFunctionId == WF__COUNT_DISTINCT)
|
||||
fSet.insert(valIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setValue(CalpontSystemCatalog::BIGINT, b, e, c, &fCount);
|
||||
|
||||
fPrev = c;
|
||||
}
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_count<int64_t>::makeFunction(int, const string&, int);
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
57
utils/windowfunction/wf_count.h
Normal file
57
utils/windowfunction/wf_count.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_count.h 3868 2013-06-06 22:13:05Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WF_COUNT_H
|
||||
#define UTILS_WF_COUNT_H
|
||||
|
||||
#include <set>
|
||||
#include "windowfunctiontype.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
class WF_count : public WindowFunctionType
|
||||
{
|
||||
public:
|
||||
WF_count(int id, const std::string& name) : WindowFunctionType(id, name) {resetData();}
|
||||
|
||||
// pure virtual in base
|
||||
void operator()(int64_t b, int64_t e, int64_t c);
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
|
||||
protected:
|
||||
|
||||
uint64_t fCount;
|
||||
std::set<T> fSet;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WF_COUNT_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
||||
|
273
utils/windowfunction/wf_lead_lag.cpp
Normal file
273
utils/windowfunction/wf_lead_lag.cpp
Normal file
@ -0,0 +1,273 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_lead_lag.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "joblisttypes.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "constantcolumn.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "wf_lead_lag.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_lead_lag<T>::makeFunction(int id, const string& name, int ct)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
switch (ct)
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_lead_lag<int64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
case CalpontSystemCatalog::DATE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
{
|
||||
func.reset(new WF_lead_lag<uint64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
func.reset(new WF_lead_lag<double>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
func.reset(new WF_lead_lag<float>(id, name));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
func.reset(new WF_lead_lag<string>(id, name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
WindowFunctionType* WF_lead_lag<T>::clone() const
|
||||
{
|
||||
return new WF_lead_lag<T>(*this);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_lead_lag<T>::resetData()
|
||||
{
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_lead_lag<T>::parseParms(const std::vector<execplan::SRCP>& parms)
|
||||
{
|
||||
// lead | lag
|
||||
fLead = 1;
|
||||
if (fFunctionId == WF__LAG)
|
||||
fLead = -1;
|
||||
|
||||
// parms[0]: value-expr
|
||||
// skip
|
||||
|
||||
// parms[1]: offset
|
||||
ConstantColumn* cc = dynamic_cast<ConstantColumn*>(parms[1].get());
|
||||
if (cc != NULL)
|
||||
{
|
||||
fOffsetNull = false;
|
||||
fOffset = cc->getIntVal(fRow, fOffsetNull) * fLead; // row not used, no need to setData.
|
||||
}
|
||||
|
||||
// parms[2]: default value
|
||||
cc = dynamic_cast<ConstantColumn*>(parms[2].get());
|
||||
if (cc != NULL)
|
||||
{
|
||||
fDefNull = false;
|
||||
getConstValue(cc, fDefault, fDefNull);
|
||||
}
|
||||
|
||||
// parms[3]: respect null | ignore null
|
||||
cc = dynamic_cast<ConstantColumn*>(parms[3].get());
|
||||
idbassert(cc != NULL);
|
||||
bool isNull = false; // dummy, harded coded
|
||||
fRespectNulls = (cc->getIntVal(fRow, isNull) > 0);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_lead_lag<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
uint64_t colIn = fFieldIndex[1];
|
||||
bool isNull = true;
|
||||
for (int64_t c = b; c <= e; c++)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
// get offset if not constant
|
||||
int64_t idx = fFieldIndex[2];
|
||||
if (idx != -1)
|
||||
{
|
||||
double tmp = 0.0; // use double to cover all column types
|
||||
fOffsetNull = fRow.isNullValue(idx);
|
||||
if (!fOffsetNull)
|
||||
{
|
||||
implicit2T(idx, tmp, 0);
|
||||
|
||||
if (tmp > e) // prevent integer overflow
|
||||
tmp = e + 1;
|
||||
else if (tmp + e < 0)
|
||||
tmp += e - 1;
|
||||
|
||||
fOffset = (int64_t) tmp;
|
||||
fOffset *= fLead;
|
||||
}
|
||||
}
|
||||
|
||||
// get default if not constant
|
||||
idx = fFieldIndex[3];
|
||||
if (idx != -1)
|
||||
{
|
||||
fDefNull = fRow.isNullValue(idx);
|
||||
if (!fDefNull)
|
||||
implicit2T(idx, fDefault, (int) fRow.getScale(idx));
|
||||
}
|
||||
|
||||
int64_t o = c + fOffset;
|
||||
if (o < b || o > e || fOffsetNull) // out of bound
|
||||
{
|
||||
T* v = (fDefNull) ? NULL : &fDefault;
|
||||
setValue(fRow.getColType(fFieldIndex[0]), b, e, c, v);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fRespectNulls == false && fRow.isNullValue(colIn) == true)
|
||||
{
|
||||
if(fOffset > 0)
|
||||
{
|
||||
while (++o < e)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(o)));
|
||||
if (fRow.isNullValue(colIn) == false)
|
||||
break;
|
||||
}
|
||||
|
||||
if (o <= e)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(o)));
|
||||
getValue(colIn, fValue);
|
||||
isNull = fRow.isNullValue(colIn);
|
||||
}
|
||||
}
|
||||
else if (fOffset < 0)
|
||||
{
|
||||
while (--o > b)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(o)));
|
||||
if (fRow.isNullValue(colIn) == false)
|
||||
break;
|
||||
}
|
||||
|
||||
if (o >= b)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(o)));
|
||||
getValue(colIn, fValue);
|
||||
isNull = fRow.isNullValue(colIn);
|
||||
}
|
||||
}
|
||||
|
||||
T* v = NULL;
|
||||
if (!isNull)
|
||||
v = &fValue;
|
||||
else if (!fDefNull)
|
||||
v = &fDefault;
|
||||
|
||||
setValue(fRow.getColType(fFieldIndex[0]), b, e, c, v);
|
||||
}
|
||||
else
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(o)));
|
||||
getValue(colIn, fValue);
|
||||
isNull = fRow.isNullValue(colIn);
|
||||
|
||||
T* v = NULL;
|
||||
if (!isNull)
|
||||
v = &fValue;
|
||||
else if (!fDefNull)
|
||||
v = &fDefault;
|
||||
setValue(fRow.getColType(fFieldIndex[0]), b, e, c, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_lead_lag<int64_t>::makeFunction(int, const string&, int);
|
||||
|
||||
template void WF_lead_lag<int64_t>::parseParms(const std::vector<execplan::SRCP>&);
|
||||
template void WF_lead_lag<uint64_t>::parseParms(const std::vector<execplan::SRCP>&);
|
||||
template void WF_lead_lag<float>::parseParms(const std::vector<execplan::SRCP>&);
|
||||
template void WF_lead_lag<double>::parseParms(const std::vector<execplan::SRCP>&);
|
||||
template void WF_lead_lag<string>::parseParms(const std::vector<execplan::SRCP>&);
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
62
utils/windowfunction/wf_lead_lag.h
Normal file
62
utils/windowfunction/wf_lead_lag.h
Normal file
@ -0,0 +1,62 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_lead_lag.h 3868 2013-06-06 22:13:05Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WF_LEAD_LAG_H
|
||||
#define UTILS_WF_LEAD_LAG_H
|
||||
|
||||
#include "windowfunctiontype.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
class WF_lead_lag : public WindowFunctionType
|
||||
{
|
||||
public:
|
||||
WF_lead_lag(int id, const std::string& name) : WindowFunctionType(id, name) {resetData();}
|
||||
|
||||
// pure virtual in base
|
||||
void operator()(int64_t b, int64_t e, int64_t c);
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
void parseParms(const std::vector<execplan::SRCP>&);
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
|
||||
protected:
|
||||
T fValue;
|
||||
T fDefault;
|
||||
int64_t fOffset;
|
||||
int64_t fLead;
|
||||
bool fOffsetNull;
|
||||
bool fDefNull;
|
||||
bool fRespectNulls; // respect null | ignore null
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WF_LEAD_LAG_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
||||
|
164
utils/windowfunction/wf_min_max.cpp
Normal file
164
utils/windowfunction/wf_min_max.cpp
Normal file
@ -0,0 +1,164 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_min_max.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "joblisttypes.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "wf_min_max.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_min_max<T>::makeFunction(int id, const string& name, int ct)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
switch (ct)
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_min_max<int64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
case CalpontSystemCatalog::DATE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
{
|
||||
func.reset(new WF_min_max<uint64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
func.reset(new WF_min_max<double>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
func.reset(new WF_min_max<float>(id, name));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
func.reset(new WF_min_max<string>(id, name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
WindowFunctionType* WF_min_max<T>::clone() const
|
||||
{
|
||||
return new WF_min_max<T>(*this);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_min_max<T>::resetData()
|
||||
{
|
||||
fCount = 0;
|
||||
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_min_max<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
// for unbounded - current row special handling
|
||||
if (fPrev >= b && fPrev < c)
|
||||
b = c;
|
||||
else if (fPrev <= e && fPrev > c)
|
||||
e = c;
|
||||
|
||||
uint64_t colIn = fFieldIndex[1];
|
||||
for (int64_t i = b; i <= e; i++)
|
||||
{
|
||||
if (i % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(i)));
|
||||
if (fRow.isNullValue(colIn) == true)
|
||||
continue;
|
||||
|
||||
T valIn;
|
||||
getValue(colIn, valIn);
|
||||
if ((fCount == 0) ||
|
||||
(valIn < fValue && fFunctionId == WF__MIN) ||
|
||||
(valIn > fValue && fFunctionId == WF__MAX))
|
||||
{
|
||||
fValue = valIn;
|
||||
}
|
||||
|
||||
fCount++;
|
||||
}
|
||||
|
||||
T* v = ((fCount > 0) ? &fValue : NULL);
|
||||
setValue(fRow.getColType(fFieldIndex[0]), b, e, c, v);
|
||||
|
||||
fPrev = c;
|
||||
}
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_min_max<int64_t>::makeFunction(int, const string&, int);
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
55
utils/windowfunction/wf_min_max.h
Normal file
55
utils/windowfunction/wf_min_max.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_min_max.h 3868 2013-06-06 22:13:05Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WF_MIN_MAX_H
|
||||
#define UTILS_WF_MIN_MAX_H
|
||||
|
||||
#include "windowfunctiontype.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
class WF_min_max : public WindowFunctionType
|
||||
{
|
||||
public:
|
||||
WF_min_max(int id, const std::string& name) : WindowFunctionType(id, name) {resetData();}
|
||||
|
||||
// pure virtual in base
|
||||
void operator()(int64_t b, int64_t e, int64_t c);
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
|
||||
protected:
|
||||
T fValue;
|
||||
uint64_t fCount;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WF_MIN_MAX_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
||||
|
253
utils/windowfunction/wf_nth_value.cpp
Normal file
253
utils/windowfunction/wf_nth_value.cpp
Normal file
@ -0,0 +1,253 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_nth_value.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "joblisttypes.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "constantcolumn.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "wf_nth_value.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_nth_value<T>::makeFunction(int id, const string& name, int ct)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
switch (ct)
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_nth_value<int64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
case CalpontSystemCatalog::DATE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
{
|
||||
func.reset(new WF_nth_value<uint64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
func.reset(new WF_nth_value<double>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
func.reset(new WF_nth_value<float>(id, name));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
func.reset(new WF_nth_value<string>(id, name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
WindowFunctionType* WF_nth_value<T>::clone() const
|
||||
{
|
||||
return new WF_nth_value<T>(*this);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_nth_value<T>::resetData()
|
||||
{
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_nth_value<T>::parseParms(const std::vector<execplan::SRCP>& parms)
|
||||
{
|
||||
// parms[0]: value-expr
|
||||
// skip
|
||||
|
||||
// parms[1]: nth value
|
||||
ConstantColumn* cc = dynamic_cast<ConstantColumn*>(parms[1].get());
|
||||
if (cc != NULL)
|
||||
{
|
||||
fNthNull = false;
|
||||
fNth = cc->getIntVal(fRow, fNthNull); // row not used, no need to setData.
|
||||
if (fNth <= 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << fNth;
|
||||
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ERR_WF_ARG_OUT_OF_RANGE,
|
||||
oss.str()), ERR_WF_ARG_OUT_OF_RANGE);
|
||||
}
|
||||
}
|
||||
|
||||
// parms[2]: from first | from last
|
||||
bool isNull = false;
|
||||
cc = dynamic_cast<ConstantColumn*>(parms[2].get());
|
||||
idbassert(cc != NULL);
|
||||
fFromFirst = (cc->getIntVal(fRow, isNull) > 0);
|
||||
|
||||
// parms[3]: respect null | ignore null
|
||||
cc = dynamic_cast<ConstantColumn*>(parms[3].get());
|
||||
idbassert(cc != NULL);
|
||||
fRespectNulls = (cc->getIntVal(fRow, isNull) > 0);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_nth_value<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
int64_t s = b;
|
||||
int64_t t = e;
|
||||
if (c != WF__BOUND_ALL)
|
||||
s = t = c;
|
||||
|
||||
for (int64_t c = s; c <= t; c++)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
int64_t idx = fFieldIndex[2];
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
if (idx != -1)
|
||||
{
|
||||
double tmp = 1.0;
|
||||
fNthNull = fRow.isNullValue(idx);
|
||||
if (!fNthNull)
|
||||
{
|
||||
implicit2T(idx, tmp, 0);
|
||||
if (tmp <= 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << tmp;
|
||||
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ERR_WF_ARG_OUT_OF_RANGE,
|
||||
oss.str()), ERR_WF_ARG_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
if (tmp > e) // prevent integer overflow
|
||||
tmp = e + 1;
|
||||
|
||||
fNth = (int64_t) tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool isNull = true;
|
||||
if ((!fNthNull) && ((b + fNth - 1) <= e))
|
||||
{
|
||||
uint64_t colIn = fFieldIndex[1];
|
||||
if (fFromFirst)
|
||||
{
|
||||
int64_t k = b;
|
||||
fRow.setData(getPointer(fRowData->at(k)));
|
||||
if (fRespectNulls == false && fRow.isNullValue(colIn) == true)
|
||||
{
|
||||
while (++k < e)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(k)));
|
||||
if (fRow.isNullValue(colIn) == false)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t n = k + fNth - 1;
|
||||
if (n <= e)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(n)));
|
||||
getValue(colIn, fValue);
|
||||
isNull = fRow.isNullValue(colIn);
|
||||
}
|
||||
}
|
||||
else // from last
|
||||
{
|
||||
int64_t k = e;
|
||||
fRow.setData(getPointer(fRowData->at(k)));
|
||||
if (fRespectNulls == false && fRow.isNullValue(colIn) == true)
|
||||
{
|
||||
while (--k > b)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(k)));
|
||||
if (fRow.isNullValue(colIn) == false)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t n = k - fNth + 1;
|
||||
if (n >= b)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(n)));
|
||||
getValue(colIn, fValue);
|
||||
isNull = fRow.isNullValue(colIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T* v = (isNull) ? NULL : &fValue;
|
||||
setValue(fRow.getColType(fFieldIndex[0]), b, e, c, v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_nth_value<int64_t>::makeFunction(int, const string&, int);
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
60
utils/windowfunction/wf_nth_value.h
Normal file
60
utils/windowfunction/wf_nth_value.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_nth_value.h 3868 2013-06-06 22:13:05Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WF_NTH_VALUE_H
|
||||
#define UTILS_WF_NTH_VALUE_H
|
||||
|
||||
#include "windowfunctiontype.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
class WF_nth_value : public WindowFunctionType
|
||||
{
|
||||
public:
|
||||
WF_nth_value(int id, const std::string& name) : WindowFunctionType(id, name) {resetData();}
|
||||
|
||||
// pure virtual in base
|
||||
void operator()(int64_t b, int64_t e, int64_t c);
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
void parseParms(const std::vector<execplan::SRCP>&);
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
|
||||
protected:
|
||||
T fValue;
|
||||
int64_t fNth;
|
||||
bool fNthNull;
|
||||
bool fFromFirst; // from first | from last
|
||||
bool fRespectNulls; // respect null | ignore null
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WF_NTH_VALUE_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
||||
|
162
utils/windowfunction/wf_ntile.cpp
Normal file
162
utils/windowfunction/wf_ntile.cpp
Normal file
@ -0,0 +1,162 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_ntile.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "joblisttypes.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "constantcolumn.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "wf_ntile.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
boost::shared_ptr<WindowFunctionType> WF_ntile::makeFunction(int id, const string& name, int ct)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func(new WF_ntile(id, name));
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
WindowFunctionType* WF_ntile::clone() const
|
||||
{
|
||||
return new WF_ntile(*this);
|
||||
}
|
||||
|
||||
|
||||
void WF_ntile::resetData()
|
||||
{
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
|
||||
void WF_ntile::parseParms(const std::vector<execplan::SRCP>& parms)
|
||||
{
|
||||
// parms[0]: nt
|
||||
ConstantColumn* cc = dynamic_cast<ConstantColumn*>(parms[0].get());
|
||||
if (cc != NULL)
|
||||
{
|
||||
fNtileNull = false;
|
||||
fNtile = cc->getIntVal(fRow, fNtileNull); // row not used, no need to setData.
|
||||
if (!fNtileNull && fNtile <= 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << fNtile;
|
||||
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ERR_WF_ARG_OUT_OF_RANGE,
|
||||
oss.str()), ERR_WF_ARG_OUT_OF_RANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WF_ntile::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
int64_t idx = fFieldIndex[1];
|
||||
if (idx != -1)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(b)));
|
||||
if (idx != -1)
|
||||
{
|
||||
double tmp = 1.0;
|
||||
fNtileNull = fRow.isNullValue(idx);
|
||||
if (!fNtileNull)
|
||||
implicit2T(idx, tmp, 0);
|
||||
|
||||
if (!fNtileNull && tmp <= 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << tmp;
|
||||
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ERR_WF_ARG_OUT_OF_RANGE,
|
||||
oss.str()), ERR_WF_ARG_OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
if (tmp > e) // prevent integer overflow
|
||||
tmp = e + 1;
|
||||
|
||||
fNtile = (int64_t) tmp;
|
||||
}
|
||||
}
|
||||
|
||||
c = b;
|
||||
if (!fNtileNull)
|
||||
{
|
||||
int64_t rowPerBucket = (e - b + 1) / fNtile;
|
||||
int64_t n = rowPerBucket * fNtile;
|
||||
int64_t x = (e-b+1) - n; // extra
|
||||
int64_t y = 0;
|
||||
int64_t z = 0;
|
||||
|
||||
while (c <= e)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
y = rowPerBucket + ((x-- > 0) ? 1 : 0);
|
||||
z++;
|
||||
for (int64_t i = 0; i < y && c <= e; i++)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(c++)));
|
||||
setIntValue(fFieldIndex[0], z);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (c <= e)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(c++)));
|
||||
setIntValue(fFieldIndex[0], joblist::BIGINTNULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
57
utils/windowfunction/wf_ntile.h
Normal file
57
utils/windowfunction/wf_ntile.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_ntile.h 3868 2013-06-06 22:13:05Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WF_NTILE_H
|
||||
#define UTILS_WF_NTILE_H
|
||||
|
||||
#include <set>
|
||||
#include "windowfunctiontype.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
class WF_ntile : public WindowFunctionType
|
||||
{
|
||||
public:
|
||||
WF_ntile(int id, const std::string& name) : WindowFunctionType(id, name) {resetData();}
|
||||
|
||||
// pure virtual in base
|
||||
void operator()(int64_t b, int64_t e, int64_t c);
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
void parseParms(const std::vector<execplan::SRCP>&);
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
|
||||
protected:
|
||||
|
||||
uint64_t fNtile;
|
||||
bool fNtileNull;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WF_NTILE_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
||||
|
344
utils/windowfunction/wf_percentile.cpp
Normal file
344
utils/windowfunction/wf_percentile.cpp
Normal file
@ -0,0 +1,344 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_percentile.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/scoped_array.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "joblisttypes.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "constantcolumn.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "wf_percentile.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_percentile<T>::makeFunction(int id, const string& name, int ct)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
if (id == WF__PERCENTILE_DISC)
|
||||
{
|
||||
switch (ct)
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_percentile<int64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
case CalpontSystemCatalog::DATE:
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
{
|
||||
func.reset(new WF_percentile<uint64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
func.reset(new WF_percentile<double>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
func.reset(new WF_percentile<float>(id, name));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (id == WF__PERCENTILE_DISC)
|
||||
{
|
||||
func.reset(new WF_percentile<string>(id, name));
|
||||
}
|
||||
else
|
||||
{
|
||||
string errStr = name + "(" + colType2String[ct] + ")";
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_INVALID_PARM_TYPE, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_INVALID_PARM_TYPE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (ct)
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
func.reset(new WF_percentile<double>(id, name));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
string errStr = name + "(" + colType2String[ct] + ")";
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_INVALID_PARM_TYPE, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_INVALID_PARM_TYPE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
WindowFunctionType* WF_percentile<T>::clone() const
|
||||
{
|
||||
return new WF_percentile(*this);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_percentile<T>::resetData()
|
||||
{
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_percentile<T>::parseParms(const std::vector<execplan::SRCP>& parms)
|
||||
{
|
||||
// parms[0]: nve
|
||||
ConstantColumn* cc = dynamic_cast<ConstantColumn*>(parms[0].get());
|
||||
if (cc != NULL)
|
||||
{
|
||||
fNveNull = false;
|
||||
fNve = cc->getDoubleVal(fRow, fNveNull); // row not used, no need to setData.
|
||||
if (!fNveNull && (fNve < 0 || fNve > 1))
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << fNve;
|
||||
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ERR_WF_ARG_OUT_OF_RANGE,
|
||||
oss.str()), ERR_WF_ARG_OUT_OF_RANGE);
|
||||
}
|
||||
}
|
||||
|
||||
// workaround for the within group order by column index
|
||||
idbassert(fPeer->fIndex.size() > 0);
|
||||
fFieldIndex.push_back(fPeer->fIndex[0]);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_percentile<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
int64_t idx = fFieldIndex[1];
|
||||
fRow.setData(getPointer(fRowData->at(b)));
|
||||
if (idx != -1)
|
||||
{
|
||||
if (idx != -1)
|
||||
{
|
||||
fNveNull = fRow.isNullValue(idx);
|
||||
implicit2T(idx, fNve, 0);
|
||||
if (!fNveNull && (fNve < 0 || fNve > 1))
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << fNve;
|
||||
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ERR_WF_ARG_OUT_OF_RANGE,
|
||||
oss.str()), ERR_WF_ARG_OUT_OF_RANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fNveNull)
|
||||
{
|
||||
for (c = b; c <= e; c++)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
setValue(fRow.getColType(fFieldIndex[0]), b, e, c, (T*) NULL);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
idx = fFieldIndex[2];
|
||||
int64_t rank = 0;
|
||||
int64_t dups = 0;
|
||||
int64_t b1 = -1;
|
||||
int64_t e1 = -1;
|
||||
scoped_array<int64_t> rk(new int64_t[e - b + 1]);
|
||||
for (c = b; c <= e; c++)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
if (fRow.isNullValue(idx))
|
||||
continue;
|
||||
|
||||
// ignore nulls
|
||||
if (b1 == -1)
|
||||
b1 = c;
|
||||
e1 = c;
|
||||
|
||||
if (fFunctionId == WF__PERCENTILE_DISC)
|
||||
{
|
||||
// need cume_rank
|
||||
if (c != b &&
|
||||
fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(c-1))))
|
||||
{
|
||||
dups++;
|
||||
}
|
||||
else
|
||||
{
|
||||
rank++;
|
||||
rank += dups;
|
||||
dups = 0;
|
||||
}
|
||||
|
||||
rk[c-b] = rank;
|
||||
}
|
||||
}
|
||||
|
||||
T* p = NULL;
|
||||
T v;
|
||||
int ct = (fFunctionId == WF__PERCENTILE_CONT) ?
|
||||
CalpontSystemCatalog::DOUBLE : fRow.getColType(idx);
|
||||
if (b1 != -1)
|
||||
{
|
||||
double cnt = (e1 - b1 + 1);
|
||||
if (fFunctionId == WF__PERCENTILE_CONT)
|
||||
{
|
||||
// @bug5820, this "rn" is the normalized row number, not the real row number.
|
||||
// Using real row number here will introduce a small calculation error in double result.
|
||||
double rn = fNve * (cnt - 1);
|
||||
double crn = ceil(rn);
|
||||
double frn = floor(rn);
|
||||
double vd = 0;
|
||||
if (crn == rn && rn == frn)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at((size_t) rn + (size_t) b1)));
|
||||
implicit2T(idx, vd, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
double cv = 0.0, fv = 0.0;
|
||||
fRow.setData(getPointer(fRowData->at((size_t) frn + (size_t) b1)));
|
||||
implicit2T(idx, fv, 0);
|
||||
fRow.setData(getPointer(fRowData->at((size_t) crn + (size_t) b1)));
|
||||
implicit2T(idx, cv, 0);
|
||||
vd = (crn - rn) * fv + (rn - frn) * cv;
|
||||
}
|
||||
|
||||
v = *(reinterpret_cast<T*>(&vd));
|
||||
p = &v;
|
||||
}
|
||||
else // (fFunctionId == WF__PERCENTILE_DISC)
|
||||
{
|
||||
int prevRank = ++rank + dups;
|
||||
double cumeDist = 1;
|
||||
fRow.setData(getPointer(fRowData->at(e1)));
|
||||
for (c = e1; c >= b1; c--)
|
||||
{
|
||||
int currRank = rk[c-b];
|
||||
if (currRank != prevRank)
|
||||
{
|
||||
cumeDist = ((double) (prevRank-1)) / cnt;
|
||||
if (cumeDist < fNve)
|
||||
break;
|
||||
|
||||
prevRank = currRank;
|
||||
}
|
||||
}
|
||||
|
||||
c++;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
getValue(idx, v);
|
||||
|
||||
p = &v;
|
||||
}
|
||||
}
|
||||
|
||||
for (c = b; c <= e; c++)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
setValue(ct, b, e, c, p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_percentile<int64_t>::makeFunction(int, const string&, int);
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
58
utils/windowfunction/wf_percentile.h
Normal file
58
utils/windowfunction/wf_percentile.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_percentile.h 3868 2013-06-06 22:13:05Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WF_PERCENTILE_H
|
||||
#define UTILS_WF_PERCENTILE_H
|
||||
|
||||
#include <set>
|
||||
#include "windowfunctiontype.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
class WF_percentile : public WindowFunctionType
|
||||
{
|
||||
public:
|
||||
WF_percentile(int id, const std::string& name) : WindowFunctionType(id, name) {resetData();}
|
||||
|
||||
// pure virtual in base
|
||||
void operator()(int64_t b, int64_t e, int64_t c);
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
void parseParms(const std::vector<execplan::SRCP>&);
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
|
||||
protected:
|
||||
|
||||
double fNve;
|
||||
bool fNveNull;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WF_PERCENTILE_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
||||
|
150
utils/windowfunction/wf_ranking.cpp
Normal file
150
utils/windowfunction/wf_ranking.cpp
Normal file
@ -0,0 +1,150 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_ranking.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "joblisttypes.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "wf_ranking.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
boost::shared_ptr<WindowFunctionType> WF_ranking::makeFunction(int id, const string& name, int ct)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func(new WF_ranking(id, name));
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
WindowFunctionType* WF_ranking::clone() const
|
||||
{
|
||||
return new WF_ranking(*this);
|
||||
}
|
||||
|
||||
|
||||
void WF_ranking::resetData()
|
||||
{
|
||||
fRank = 0;
|
||||
fDups = 0;
|
||||
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
|
||||
void WF_ranking::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
// one row handling
|
||||
if (fPartition.first == fPartition.second)
|
||||
{
|
||||
fRow.setData(getPointer(fRowData->at(fPartition.first)));
|
||||
int64_t r = (fFunctionId == WF__PERCENT_RANK) ? 0 : 1;
|
||||
if (fFunctionId == WF__RANK || fFunctionId == WF__DENSE_RANK)
|
||||
setIntValue(fFieldIndex[0], r);
|
||||
else
|
||||
setDoubleValue(fFieldIndex[0], r);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// more than one row, e > b
|
||||
b = fPartition.first;
|
||||
e = fPartition.second;
|
||||
double n1 = e - b; // count(*) - 1, n will not be 0.
|
||||
for (c = b; c <= e; c++)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
if (c != b &&
|
||||
fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(c-1))))
|
||||
{
|
||||
fDups++;
|
||||
}
|
||||
else
|
||||
{
|
||||
fRank++;
|
||||
if (fFunctionId != WF__DENSE_RANK)
|
||||
fRank += fDups;
|
||||
fDups = 0;
|
||||
}
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
if (fFunctionId != WF__PERCENT_RANK)
|
||||
setIntValue(fFieldIndex[0], fRank);
|
||||
else
|
||||
setDoubleValue(fFieldIndex[0], (fRank-1)/n1);
|
||||
}
|
||||
|
||||
// Two-pass, need to find peers.
|
||||
if (fFunctionId == WF__CUME_DIST)
|
||||
{
|
||||
int prevRank = ++fRank + fDups; // hypothetical row at (e+1)
|
||||
double n0 = (e - b + 1); // count(*)
|
||||
double cumeDist = 1;
|
||||
fRow.setData(getPointer(fRowData->at(e)));
|
||||
for (c = e; c >= b; c--)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
int currRank = getIntValue(fFieldIndex[0]);
|
||||
if (currRank != prevRank)
|
||||
{
|
||||
cumeDist = ((double) (prevRank-1)) / n0;
|
||||
prevRank = currRank;
|
||||
}
|
||||
|
||||
setDoubleValue(fFieldIndex[0], cumeDist);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
56
utils/windowfunction/wf_ranking.h
Normal file
56
utils/windowfunction/wf_ranking.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_ranking.h 3868 2013-06-06 22:13:05Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WF_RANKING_H
|
||||
#define UTILS_WF_RANKING_H
|
||||
|
||||
#include <set>
|
||||
#include "windowfunctiontype.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
class WF_ranking : public WindowFunctionType
|
||||
{
|
||||
public:
|
||||
WF_ranking(int id, const std::string& name) : WindowFunctionType(id, name) {resetData();}
|
||||
|
||||
// pure virtual in base
|
||||
void operator()(int64_t b, int64_t e, int64_t c);
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
|
||||
protected:
|
||||
|
||||
uint64_t fRank;
|
||||
uint64_t fDups;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WF_RANKING_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
||||
|
96
utils/windowfunction/wf_row_number.cpp
Normal file
96
utils/windowfunction/wf_row_number.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_row_number.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "joblisttypes.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "wf_row_number.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
boost::shared_ptr<WindowFunctionType> WF_row_number::makeFunction(int id, const string& name, int ct)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func(new WF_row_number(id, name));
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
WindowFunctionType* WF_row_number::clone() const
|
||||
{
|
||||
return new WF_row_number(*this);
|
||||
}
|
||||
|
||||
|
||||
void WF_row_number::resetData()
|
||||
{
|
||||
fRowNumber= 0;
|
||||
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
|
||||
void WF_row_number::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
b = fPartition.first;
|
||||
e = fPartition.second;
|
||||
for (c = b; c <= e; c++)
|
||||
{
|
||||
if (c % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(c)));
|
||||
fRowNumber++;
|
||||
|
||||
setIntValue(fFieldIndex[0], fRowNumber);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
55
utils/windowfunction/wf_row_number.h
Normal file
55
utils/windowfunction/wf_row_number.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_row_number.h 3868 2013-06-06 22:13:05Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WF_ROW_NUMBER_H
|
||||
#define UTILS_WF_ROW_NUMBER_H
|
||||
|
||||
#include <set>
|
||||
#include "windowfunctiontype.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
class WF_row_number : public WindowFunctionType
|
||||
{
|
||||
public:
|
||||
WF_row_number(int id, const std::string& name) : WindowFunctionType(id, name) {resetData();}
|
||||
|
||||
// pure virtual in base
|
||||
void operator()(int64_t b, int64_t e, int64_t c);
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
|
||||
protected:
|
||||
|
||||
uint64_t fRowNumber;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WF_ROW_NUMBER_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
||||
|
210
utils/windowfunction/wf_stats.cpp
Normal file
210
utils/windowfunction/wf_stats.cpp
Normal file
@ -0,0 +1,210 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_stats.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "joblisttypes.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "wf_stats.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_stats<T>::makeFunction(int id, const string& name, int ct)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
switch (ct)
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_stats<int64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
func.reset(new WF_stats<uint64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
func.reset(new WF_stats<double>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
func.reset(new WF_stats<float>(id, name));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
string errStr = name + "(" + colType2String[ct] + ")";
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_INVALID_PARM_TYPE, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_INVALID_PARM_TYPE);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
WindowFunctionType* WF_stats<T>::clone() const
|
||||
{
|
||||
return new WF_stats<T>(*this);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_stats<T>::resetData()
|
||||
{
|
||||
fSum1 = 0;
|
||||
fSum2 = 0;
|
||||
fCount = 0;
|
||||
fStats = 0.0;
|
||||
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_stats<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
if ((fFrameUnit == WF__FRAME_ROWS) ||
|
||||
(fPrev == -1) ||
|
||||
(!fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(fPrev)))))
|
||||
{
|
||||
// for unbounded - current row special handling
|
||||
if (fPrev >= b && fPrev < c)
|
||||
b = c;
|
||||
else if (fPrev <= e && fPrev > c)
|
||||
e = c;
|
||||
|
||||
uint64_t colIn = fFieldIndex[1];
|
||||
for (int64_t i = b; i <= e; i++)
|
||||
{
|
||||
if (i % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(i)));
|
||||
if (fRow.isNullValue(colIn) == true)
|
||||
continue;
|
||||
|
||||
T valIn;
|
||||
getValue(colIn, valIn);
|
||||
long double val = (long double) valIn;
|
||||
|
||||
fSum1 += val;
|
||||
fSum2 += val * val;
|
||||
fCount++;
|
||||
}
|
||||
|
||||
if ((fCount > 0) &&
|
||||
!(fCount == 1 && (fFunctionId == WF__STDDEV_SAMP || fFunctionId == WF__VAR_SAMP)))
|
||||
{
|
||||
int scale = fRow.getScale(colIn);
|
||||
long double factor = pow(10.0, scale);
|
||||
if (scale != 0) // adjust the scale if necessary
|
||||
{
|
||||
fSum1 /= factor;
|
||||
fSum2 /= factor*factor;
|
||||
}
|
||||
|
||||
long double stat = fSum1 * fSum1 / fCount;
|
||||
stat = fSum2 - stat;
|
||||
|
||||
if (fFunctionId == WF__STDDEV_POP)
|
||||
stat = sqrt(stat / fCount);
|
||||
else if (fFunctionId == WF__STDDEV_SAMP)
|
||||
stat = sqrt(stat / (fCount - 1));
|
||||
else if (fFunctionId == WF__VAR_POP)
|
||||
stat = stat / fCount;
|
||||
else if (fFunctionId == WF__VAR_SAMP)
|
||||
stat = stat / (fCount - 1);
|
||||
|
||||
fStats = (double) stat;
|
||||
}
|
||||
}
|
||||
|
||||
if (fCount == 0)
|
||||
{
|
||||
setValue(CalpontSystemCatalog::DOUBLE, b, e, c, (double*) NULL);
|
||||
}
|
||||
else if (fCount == 1 && (fFunctionId == WF__STDDEV_SAMP || fFunctionId == WF__VAR_SAMP))
|
||||
{
|
||||
setValue(CalpontSystemCatalog::DOUBLE, b, e, c, (double*) NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
setValue(CalpontSystemCatalog::DOUBLE, b, e, c, &fStats);
|
||||
}
|
||||
|
||||
fPrev = c;
|
||||
}
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_stats<int64_t>::makeFunction(int, const string&, int);
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
57
utils/windowfunction/wf_stats.h
Normal file
57
utils/windowfunction/wf_stats.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_stats.h 3868 2013-06-06 22:13:05Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WF_STATS_H
|
||||
#define UTILS_WF_STATS_H
|
||||
|
||||
#include "windowfunctiontype.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
class WF_stats : public WindowFunctionType
|
||||
{
|
||||
public:
|
||||
WF_stats(int id, const std::string& name) : WindowFunctionType(id, name) {resetData();}
|
||||
|
||||
// pure virtual in base
|
||||
void operator()(int64_t b, int64_t e, int64_t c);
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
|
||||
protected:
|
||||
long double fSum1;
|
||||
long double fSum2;
|
||||
uint64_t fCount;
|
||||
double fStats;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WF_STATS_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
||||
|
291
utils/windowfunction/wf_sum_avg.cpp
Normal file
291
utils/windowfunction/wf_sum_avg.cpp
Normal file
@ -0,0 +1,291 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_sum_avg.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "joblisttypes.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "wf_sum_avg.h"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
void checkSumLimit(T sum, T val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void checkSumLimit<int64_t>(int64_t sum, int64_t val)
|
||||
{
|
||||
if (((sum >= 0) && ((numeric_limits<int64_t>::max() - sum) < val)) ||
|
||||
((sum < 0) && ((numeric_limits<int64_t>::min() - sum) > val)))
|
||||
{
|
||||
string errStr = "SUM(int):";
|
||||
|
||||
ostringstream oss;
|
||||
oss << sum << "+" << val;
|
||||
if (sum > 0)
|
||||
oss << " > " << numeric_limits<uint64_t>::max();
|
||||
else
|
||||
oss << " < " << numeric_limits<uint64_t>::min();
|
||||
errStr += oss.str();
|
||||
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_OVERFLOW, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_OVERFLOW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void checkSumLimit<uint64_t>(uint64_t sum, uint64_t val)
|
||||
{
|
||||
if ((sum >= 0) && ((numeric_limits<uint64_t>::max() - sum) < val))
|
||||
{
|
||||
string errStr = "SUM(unsigned):";
|
||||
|
||||
ostringstream oss;
|
||||
oss << sum << "+" << val << " > " << numeric_limits<uint64_t>::max();
|
||||
errStr += oss.str();
|
||||
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_OVERFLOW, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_OVERFLOW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
T calculateAvg(T sum, uint64_t count, int s)
|
||||
{
|
||||
T avg = ((long double) sum) / count;
|
||||
return avg;
|
||||
}
|
||||
|
||||
|
||||
long double avgWithLimit(long double sum, uint64_t count, int scale, long double u, long double l)
|
||||
{
|
||||
long double factor = pow(10.0, scale);
|
||||
long double avg = sum / count;
|
||||
avg *= factor;
|
||||
avg += (avg < 0) ? (-0.5) : (0.5);
|
||||
if (avg > u || avg < l)
|
||||
{
|
||||
string errStr = string("AVG") + (l < 0 ? "(int):" : "(unsign)");
|
||||
ostringstream oss;
|
||||
oss << avg;
|
||||
errStr += oss.str();
|
||||
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_OVERFLOW, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_OVERFLOW);
|
||||
}
|
||||
|
||||
return avg;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
int64_t calculateAvg<int64_t>(int64_t sum, uint64_t count, int scale)
|
||||
{
|
||||
int64_t t = (int64_t) avgWithLimit(sum, count, scale,
|
||||
numeric_limits<int64_t>::max(), numeric_limits<int64_t>::min());
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
uint64_t calculateAvg<uint64_t>(uint64_t sum, uint64_t count, int scale)
|
||||
{
|
||||
uint64_t t = (uint64_t) avgWithLimit(sum, count, scale, numeric_limits<uint64_t>::max(), 0);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<WindowFunctionType> WF_sum_avg<T>::makeFunction(int id, const string& name, int ct)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> func;
|
||||
switch (ct)
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
func.reset(new WF_sum_avg<int64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
func.reset(new WF_sum_avg<uint64_t>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
func.reset(new WF_sum_avg<double>(id, name));
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
func.reset(new WF_sum_avg<float>(id, name));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
string errStr = name + "(" + colType2String[ct] + ")";
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_INVALID_PARM_TYPE, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_INVALID_PARM_TYPE);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
WindowFunctionType* WF_sum_avg<T>::clone() const
|
||||
{
|
||||
return new WF_sum_avg<T>(*this);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_sum_avg<T>::resetData()
|
||||
{
|
||||
fAvg = 0;
|
||||
fSum = 0;
|
||||
fCount = 0;
|
||||
fSet.clear();
|
||||
|
||||
WindowFunctionType::resetData();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WF_sum_avg<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
uint64_t colOut = fFieldIndex[0];
|
||||
|
||||
if ((fFrameUnit == WF__FRAME_ROWS) ||
|
||||
(fPrev == -1) ||
|
||||
(!fPeer->operator()(getPointer(fRowData->at(c)), getPointer(fRowData->at(fPrev)))))
|
||||
{
|
||||
// for unbounded - current row special handling
|
||||
if (fPrev >= b && fPrev < c)
|
||||
b = c;
|
||||
else if (fPrev <= e && fPrev > c)
|
||||
e = c;
|
||||
|
||||
uint64_t colIn = fFieldIndex[1];
|
||||
int scale = fRow.getScale(colOut) - fRow.getScale(colIn);
|
||||
for (int64_t i = b; i <= e; i++)
|
||||
{
|
||||
if (i % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer(fRowData->at(i)));
|
||||
if (fRow.isNullValue(colIn) == true)
|
||||
continue;
|
||||
|
||||
T valIn;
|
||||
getValue(colIn, valIn);
|
||||
checkSumLimit(fSum, valIn);
|
||||
|
||||
if ((!fDistinct) || (fSet.find(valIn) == fSet.end()))
|
||||
{
|
||||
fSum += valIn;
|
||||
fCount++;
|
||||
|
||||
if (fDistinct)
|
||||
fSet.insert(valIn);
|
||||
}
|
||||
}
|
||||
|
||||
if ((fCount > 0) && (fFunctionId == WF__AVG || fFunctionId == WF__AVG_DISTINCT))
|
||||
fAvg = (T) calculateAvg(fSum, fCount, scale);
|
||||
}
|
||||
|
||||
T* v = NULL;
|
||||
if (fCount > 0)
|
||||
{
|
||||
if (fFunctionId == WF__AVG || fFunctionId == WF__AVG_DISTINCT)
|
||||
v = &fAvg;
|
||||
else
|
||||
v = &fSum;
|
||||
}
|
||||
setValue(fRow.getColType(colOut), b, e, c, v);
|
||||
|
||||
fPrev = c;
|
||||
}
|
||||
|
||||
|
||||
template
|
||||
boost::shared_ptr<WindowFunctionType> WF_sum_avg<int64_t>::makeFunction(int, const string&, int);
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
60
utils/windowfunction/wf_sum_avg.h
Normal file
60
utils/windowfunction/wf_sum_avg.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: wf_sum_avg.h 3868 2013-06-06 22:13:05Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WF_SUM_AVG_H
|
||||
#define UTILS_WF_SUM_AVG_H
|
||||
|
||||
#include <set>
|
||||
#include "windowfunctiontype.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
template<typename T>
|
||||
class WF_sum_avg : public WindowFunctionType
|
||||
{
|
||||
public:
|
||||
WF_sum_avg(int id, const std::string& name) :
|
||||
WindowFunctionType(id, name), fDistinct(id != WF__SUM && id != WF__AVG) {resetData();}
|
||||
|
||||
// pure virtual in base
|
||||
void operator()(int64_t b, int64_t e, int64_t c);
|
||||
WindowFunctionType* clone() const;
|
||||
void resetData();
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeFunction(int, const string&, int);
|
||||
|
||||
protected:
|
||||
T fAvg;
|
||||
T fSum;
|
||||
uint64_t fCount;
|
||||
bool fDistinct;
|
||||
std::set<T> fSet;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WF_SUM_AVG_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
||||
|
90
utils/windowfunction/windowframe.cpp
Normal file
90
utils/windowfunction/windowframe.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: windowframe.cpp 3821 2013-05-17 23:58:16Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "windowframe.h"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
string UnitStr[] = {"ROWS", "RANGE"};
|
||||
}
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
|
||||
pair<uint64_t, uint64_t> WindowFrame::getWindow(int64_t b, int64_t e, int64_t c)
|
||||
{
|
||||
int64_t upper = fUpper->getBound(b, e, c);
|
||||
int64_t lower = fLower->getBound(b, e, c);
|
||||
|
||||
// case 1 || case 2 || case 3
|
||||
if ((upper > lower) || (upper < b && lower < b) || (upper > e && lower > e))
|
||||
{
|
||||
// construct an empty window
|
||||
upper = b+1;
|
||||
lower = b;
|
||||
}
|
||||
|
||||
if (upper < b) // case 2, lower >= b
|
||||
{
|
||||
upper = b;
|
||||
}
|
||||
|
||||
if (lower > e) // case 3, upper <= e
|
||||
{
|
||||
lower = e;
|
||||
}
|
||||
|
||||
return make_pair(upper, lower);
|
||||
}
|
||||
|
||||
|
||||
const string WindowFrame::toString() const
|
||||
{
|
||||
string ret(UnitStr[fUnit]);
|
||||
ret = ret + " between " + fUpper->toString() + " and " + fLower->toString();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
100
utils/windowfunction/windowframe.h
Normal file
100
utils/windowfunction/windowframe.h
Normal file
@ -0,0 +1,100 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: windowframe.h 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WINDOWFRAME_H
|
||||
#define UTILS_WINDOWFRAME_H
|
||||
|
||||
#include <utility> // std::pair, std::make_pair
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include "framebound.h"
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
const int64_t WF__FRAME_ROWS = 0;
|
||||
const int64_t WF__FRAME_RANGE = 1;
|
||||
|
||||
|
||||
/** @brief class WindowFrame
|
||||
*
|
||||
*/
|
||||
class WindowFrame
|
||||
{
|
||||
public:
|
||||
/** @brief WindowFrame constructor
|
||||
*/
|
||||
WindowFrame(int64_t t, boost::shared_ptr<FrameBound>& u, boost::shared_ptr<FrameBound>& l) :
|
||||
fUnit(t), fUpper(u), fLower(l)
|
||||
{}
|
||||
|
||||
/** @brief WindowFrame copy constructor
|
||||
*/
|
||||
WindowFrame(const WindowFrame& rhs) :
|
||||
fUnit(rhs.fUnit),
|
||||
fUpper(rhs.fUpper->clone()),
|
||||
fLower(rhs.fLower->clone())
|
||||
{}
|
||||
|
||||
/** @brief WindowFrame destructor
|
||||
*/
|
||||
virtual ~WindowFrame() {};
|
||||
|
||||
/** @brief clone
|
||||
*/
|
||||
virtual WindowFrame* clone() { return new WindowFrame(*this); };
|
||||
|
||||
/** @brief virtual void getWindow
|
||||
*/
|
||||
std::pair<uint64_t, uint64_t> getWindow(int64_t, int64_t, int64_t);
|
||||
|
||||
const std::string toString() const;
|
||||
|
||||
/** @brief set methods
|
||||
*/
|
||||
void setRowMetaData(const rowgroup::RowGroup& g, const rowgroup::Row& r)
|
||||
{ fUpper->setRowMetaData(g, r); fLower->setRowMetaData(g, r); }
|
||||
void setRowData(boost::shared_ptr<std::vector<joblist::RowPosition> >& d)
|
||||
{ fUpper->setRowData(d); fLower->setRowData(d); }
|
||||
void setCallback(joblist::WindowFunctionStep* s)
|
||||
{ fUpper->setCallback(s); fLower->setCallback(s); }
|
||||
|
||||
int64_t unit() const { return fUnit; }
|
||||
void unit(int64_t t) { fUnit = t; }
|
||||
const boost::shared_ptr<FrameBound>& upper() const { return fUpper; }
|
||||
void upper(const boost::shared_ptr<FrameBound>& u) { fUpper = u; }
|
||||
const boost::shared_ptr<FrameBound>& lower() const { return fLower; }
|
||||
void lower(const boost::shared_ptr<FrameBound>& l) { fLower = l; }
|
||||
|
||||
protected:
|
||||
|
||||
// type
|
||||
int64_t fUnit;
|
||||
|
||||
// data
|
||||
boost::shared_ptr<FrameBound> fUpper;
|
||||
boost::shared_ptr<FrameBound> fLower;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WINDOWFRAME_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
240
utils/windowfunction/windowfunction.cpp
Normal file
240
utils/windowfunction/windowfunction.cpp
Normal file
@ -0,0 +1,240 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: windowfunction.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "windowfunctiontype.h"
|
||||
#include "framebound.h"
|
||||
#include "windowframe.h"
|
||||
#include "windowfunction.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
WindowFunction::WindowFunction(boost::shared_ptr<WindowFunctionType>& f,
|
||||
boost::shared_ptr<ordering::EqualCompData>& p,
|
||||
boost::shared_ptr<OrderByData>& o,
|
||||
boost::shared_ptr<WindowFrame>& w,
|
||||
const RowGroup& g,
|
||||
const Row& r) :
|
||||
fFunctionType(f), fPartitionBy(p), fOrderBy(o), fFrame(w), fRowGroup(g), fRow(r)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
WindowFunction::~WindowFunction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void WindowFunction::operator()()
|
||||
{
|
||||
try
|
||||
{
|
||||
fRowData.reset(new vector<RowPosition>(fStep->getRowData()));
|
||||
|
||||
if (fOrderBy->rule().fCompares.size() > 0)
|
||||
sort(fRowData->begin(), fRowData->size());
|
||||
|
||||
// get partitions
|
||||
if (fPartitionBy.get() != NULL && !fStep->cancelled())
|
||||
{
|
||||
int64_t i = 0;
|
||||
int64_t j = 1;
|
||||
int64_t rowCnt = fRowData->size();
|
||||
for (j = 1; j < rowCnt; j++)
|
||||
{
|
||||
if ((*(fPartitionBy.get()))
|
||||
(getPointer((*fRowData)[j-1]), getPointer((*fRowData)[j])))
|
||||
continue;
|
||||
|
||||
fPartition.push_back(make_pair(i, j-1));
|
||||
i = j;
|
||||
}
|
||||
fPartition.push_back(make_pair(i, j-1));
|
||||
}
|
||||
else
|
||||
{
|
||||
fPartition.push_back(make_pair(0, fRowData->size()));
|
||||
}
|
||||
|
||||
// compute partition by partition
|
||||
int64_t uft = fFrame->upper()->boundType();
|
||||
int64_t lft = fFrame->lower()->boundType();
|
||||
bool upperUbnd = (uft == WF__UNBOUNDED_PRECEDING || uft == WF__UNBOUNDED_FOLLOWING);
|
||||
bool lowerUbnd = (lft == WF__UNBOUNDED_PRECEDING || lft == WF__UNBOUNDED_FOLLOWING);
|
||||
bool upperCnrw = (uft == WF__CURRENT_ROW);
|
||||
bool lowerCnrw = (lft == WF__CURRENT_ROW);
|
||||
fFunctionType->setRowData(fRowData);
|
||||
fFunctionType->setRowMetaData(fRowGroup,fRow);
|
||||
fFrame->setRowData(fRowData);
|
||||
fFrame->setRowMetaData(fRowGroup, fRow);
|
||||
for (uint64_t k = 0; k < fPartition.size() && !fStep->cancelled(); k++)
|
||||
{
|
||||
fFunctionType->resetData();
|
||||
fFunctionType->partition(fPartition[k]);
|
||||
|
||||
int64_t begin = fPartition[k].first;
|
||||
int64_t end = fPartition[k].second;
|
||||
if (upperUbnd && lowerUbnd)
|
||||
{
|
||||
fFunctionType->operator()(begin, end, WF__BOUND_ALL);
|
||||
}
|
||||
else if (upperUbnd && lowerCnrw)
|
||||
{
|
||||
if (fFrame->unit() == WF__FRAME_ROWS)
|
||||
{
|
||||
for (int64_t i = begin; i <= end && !fStep->cancelled(); i++)
|
||||
{
|
||||
fFunctionType->operator()(begin, i, i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int64_t i = begin; i <= end && !fStep->cancelled(); i++)
|
||||
{
|
||||
pair<int64_t, int64_t> w = fFrame->getWindow(begin, end, i);
|
||||
int64_t j = i;
|
||||
if (w.second > i)
|
||||
j = w.second;
|
||||
fFunctionType->operator()(begin, j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (upperCnrw && lowerUbnd)
|
||||
{
|
||||
if (fFrame->unit() == WF__FRAME_ROWS)
|
||||
{
|
||||
for (int64_t i = end; i >= begin && !fStep->cancelled(); i--)
|
||||
{
|
||||
fFunctionType->operator()(i, end, i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int64_t i = end; i >= begin && !fStep->cancelled(); i--)
|
||||
{
|
||||
pair<int64_t, int64_t> w = fFrame->getWindow(begin, end, i);
|
||||
int64_t j = i;
|
||||
if (w.first < i)
|
||||
j = w.first;
|
||||
fFunctionType->operator()(j, end, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int64_t i = begin; i <= end && !fStep->cancelled(); i++)
|
||||
{
|
||||
pair<int64_t, int64_t> w = fFrame->getWindow(begin, end, i);
|
||||
fFunctionType->resetData();
|
||||
fFunctionType->operator()(w.first, w.second, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IDBExcept& iex)
|
||||
{
|
||||
fStep->handleException(iex.what(), iex.errorCode());
|
||||
}
|
||||
catch(const std::exception& ex)
|
||||
{
|
||||
fStep->handleException(ex.what(), logging::ERR_EXECUTE_WINDOW_FUNCTION);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
fStep->handleException("unknow exception", logging::ERR_EXECUTE_WINDOW_FUNCTION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WindowFunction::setCallback(joblist::WindowFunctionStep* step, int id)
|
||||
{
|
||||
fStep = step;
|
||||
fId = id;
|
||||
fFunctionType->setCallback(step);
|
||||
fFrame->setCallback(step);
|
||||
}
|
||||
|
||||
|
||||
const Row& WindowFunction::getRow() const
|
||||
{
|
||||
return fRow;
|
||||
}
|
||||
|
||||
|
||||
void WindowFunction::sort(std::vector<RowPosition>::iterator v, uint64_t n)
|
||||
{
|
||||
// recursive function termination condition.
|
||||
if (n < 2 || fStep->cancelled())
|
||||
return;
|
||||
|
||||
RowPosition p = *(v + n/2); // pivot value
|
||||
vector<RowPosition>::iterator l = v; // low address
|
||||
vector<RowPosition>::iterator h = v + (n - 1); // high address
|
||||
while (l <= h && !(fStep->cancelled()))
|
||||
{
|
||||
// Can use while here, but need check boundary and cancel status.
|
||||
if (fOrderBy->operator()(getPointer(*l), getPointer(p)))
|
||||
{
|
||||
l++;
|
||||
}
|
||||
else if (fOrderBy->operator()(getPointer(p), getPointer(*h)))
|
||||
{
|
||||
h--;
|
||||
}
|
||||
else
|
||||
{
|
||||
RowPosition t = *l; // temp value for swap
|
||||
*l++ = *h;
|
||||
*h-- = t;
|
||||
}
|
||||
}
|
||||
|
||||
sort(v, distance(v, h) + 1);
|
||||
sort(l, distance(l, v) + n);
|
||||
}
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
125
utils/windowfunction/windowfunction.h
Normal file
125
utils/windowfunction/windowfunction.h
Normal file
@ -0,0 +1,125 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: windowfunction.h 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WINDOWFUNCTION_H
|
||||
#define UTILS_WINDOWFUNCTION_H
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include "rowgroup.h"
|
||||
#include "windowfunctionstep.h"
|
||||
|
||||
namespace ordering
|
||||
{
|
||||
// forward reference
|
||||
class EqualCompData;
|
||||
class OrderByData;
|
||||
};
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
// forward reference
|
||||
class WindowFunctionType;
|
||||
class WindowFrame;
|
||||
|
||||
|
||||
/** @brief class WindowFunction
|
||||
*
|
||||
*/
|
||||
class WindowFunction
|
||||
{
|
||||
public:
|
||||
/** @brief WindowFunction constructor
|
||||
* @param f: shared pointer to a WindowFuncitonType
|
||||
* @param p: shared pointer to equal compare functor
|
||||
* @param o: shared pointer to order by functor
|
||||
* @param w: shared pointer to window specification
|
||||
* @param r: row meta data
|
||||
*/
|
||||
WindowFunction(boost::shared_ptr<WindowFunctionType>& f,
|
||||
boost::shared_ptr<ordering::EqualCompData>& p,
|
||||
boost::shared_ptr<ordering::OrderByData>& o,
|
||||
boost::shared_ptr<WindowFrame>& w,
|
||||
const rowgroup::RowGroup& g,
|
||||
const rowgroup::Row& r);
|
||||
|
||||
/** @brief WindowFunction destructor
|
||||
*/
|
||||
virtual ~WindowFunction();
|
||||
|
||||
/** @brief virtual void Run method
|
||||
*/
|
||||
void operator()();
|
||||
|
||||
const std::string toString() const;
|
||||
|
||||
void setCallback(joblist::WindowFunctionStep*, int);
|
||||
const rowgroup::Row& getRow() const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// cancellable sort function
|
||||
void sort(std::vector<joblist::RowPosition>::iterator, uint64_t);
|
||||
|
||||
// special window frames
|
||||
void processUnboundedWindowFrame1();
|
||||
void processUnboundedWindowFrame2();
|
||||
void processUnboundedWindowFrame3();
|
||||
void processExprWindowFrame();
|
||||
|
||||
// for string table
|
||||
rowgroup::Row::Pointer getPointer(joblist::RowPosition& r)
|
||||
{ return fStep->getPointer(r, fRowGroup, fRow); }
|
||||
|
||||
// function type
|
||||
boost::shared_ptr<WindowFunctionType> fFunctionType;
|
||||
|
||||
// window clause
|
||||
boost::shared_ptr<ordering::EqualCompData> fPartitionBy;
|
||||
boost::shared_ptr<ordering::OrderByData> fOrderBy;
|
||||
boost::shared_ptr<WindowFrame> fFrame;
|
||||
std::vector<std::pair<int64_t, int64_t> > fPartition;
|
||||
|
||||
// data
|
||||
boost::shared_ptr<std::vector<joblist::RowPosition> > fRowData;
|
||||
|
||||
// row meta data
|
||||
rowgroup::RowGroup fRowGroup;
|
||||
rowgroup::Row fRow;
|
||||
|
||||
// pointer back to step
|
||||
joblist::WindowFunctionStep* fStep;
|
||||
int fId;
|
||||
|
||||
friend class joblist::WindowFunctionStep;
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WINDOWFUNCTION_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
571
utils/windowfunction/windowfunctiontype.cpp
Normal file
571
utils/windowfunction/windowfunctiontype.cpp
Normal file
@ -0,0 +1,571 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: windowfunctiontype.cpp 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
//#define NDEBUG
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/assign/list_of.hpp> // for map_list_of()
|
||||
#include <boost/algorithm/string/case_conv.hpp> // for to_upper_copy
|
||||
using namespace boost;
|
||||
|
||||
#include "loggingid.h"
|
||||
#include "errorcodes.h"
|
||||
#include "idberrorinfo.h"
|
||||
using namespace logging;
|
||||
|
||||
#include "idborderby.h"
|
||||
using namespace ordering;
|
||||
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "constantcolumn.h"
|
||||
#include "dataconvert.h" // int64_t IDB_pow[19]
|
||||
using namespace execplan;
|
||||
|
||||
#include "windowfunctionstep.h"
|
||||
using namespace joblist;
|
||||
|
||||
#include "windowframe.h"
|
||||
#include "windowfunctiontype.h"
|
||||
#include "wf_count.h"
|
||||
#include "wf_lead_lag.h"
|
||||
#include "wf_min_max.h"
|
||||
#include "wf_nth_value.h"
|
||||
#include "wf_ntile.h"
|
||||
#include "wf_percentile.h"
|
||||
#include "wf_ranking.h"
|
||||
#include "wf_row_number.h"
|
||||
#include "wf_stats.h"
|
||||
#include "wf_sum_avg.h"
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
map<int, string> colType2String = assign::map_list_of
|
||||
(CalpontSystemCatalog::BIT, "BIT")
|
||||
(CalpontSystemCatalog::TINYINT, "TINYINT")
|
||||
(CalpontSystemCatalog::CHAR, "CHAR")
|
||||
(CalpontSystemCatalog::SMALLINT, "SMALLINT")
|
||||
(CalpontSystemCatalog::DECIMAL, "DECIMAL")
|
||||
(CalpontSystemCatalog::MEDINT, "MEDINT")
|
||||
(CalpontSystemCatalog::INT, "INT")
|
||||
(CalpontSystemCatalog::FLOAT, "FLOAT")
|
||||
(CalpontSystemCatalog::DATE, "DATE")
|
||||
(CalpontSystemCatalog::BIGINT, "BIGINT")
|
||||
(CalpontSystemCatalog::DOUBLE, "DOUBLE")
|
||||
(CalpontSystemCatalog::DATETIME, "DATETIME")
|
||||
(CalpontSystemCatalog::VARCHAR, "VARCHAR")
|
||||
(CalpontSystemCatalog::VARBINARY, "VARBINARY")
|
||||
(CalpontSystemCatalog::CLOB, "CLOB")
|
||||
(CalpontSystemCatalog::BLOB, "BLOB")
|
||||
(CalpontSystemCatalog::UTINYINT, "UNSIGNED TINYINT")
|
||||
(CalpontSystemCatalog::USMALLINT, "UNSIGNED SMALLINT")
|
||||
(CalpontSystemCatalog::UDECIMAL, "UNSIGNED DECIMAL")
|
||||
(CalpontSystemCatalog::UMEDINT, "UNSIGNED MEDINT")
|
||||
(CalpontSystemCatalog::UINT, "UNSIGNED INT")
|
||||
(CalpontSystemCatalog::UFLOAT, "UNSIGNED FLOAT")
|
||||
(CalpontSystemCatalog::UBIGINT, "UNSIGNED BIGINT")
|
||||
(CalpontSystemCatalog::UDOUBLE, "UNSIGNED DOUBLE")
|
||||
(CalpontSystemCatalog::LONGDOUBLE, "INTERNAL LONG DOUBLE")
|
||||
(CalpontSystemCatalog::STRINT, "INTERNAL SHORT STRING")
|
||||
;
|
||||
|
||||
|
||||
// function name to function id convert
|
||||
map<string, int> WindowFunctionType::windowFunctionId = assign::map_list_of
|
||||
(string("COUNT(*)"), WF__COUNT_ASTERISK)
|
||||
(string("COUNT"), WF__COUNT)
|
||||
(string("SUM"), WF__SUM)
|
||||
(string("AVG"), WF__AVG)
|
||||
(string("MIN"), WF__MIN)
|
||||
(string("MAX"), WF__MAX)
|
||||
(string("COUNT_DISTINCT"), WF__COUNT_DISTINCT)
|
||||
(string("SUM_DISTINCT"), WF__SUM_DISTINCT)
|
||||
(string("AVG_DISTINCT"), WF__AVG_DISTINCT)
|
||||
(string("MIN_DISTINCT"), WF__MIN)
|
||||
(string("MAX_DISTINCT"), WF__MAX)
|
||||
(string("STD"), WF__STDDEV_POP)
|
||||
(string("STDDEV"), WF__STDDEV_POP)
|
||||
(string("STDDEV_POP"), WF__STDDEV_POP)
|
||||
(string("STDDEV_SAMP"), WF__STDDEV_SAMP)
|
||||
(string("VARIANCE"), WF__VAR_POP)
|
||||
(string("VAR_POP"), WF__VAR_POP)
|
||||
(string("VAR_SAMP"), WF__VAR_SAMP)
|
||||
(string("ROW_NUMBER"), WF__ROW_NUMBER)
|
||||
(string("RANK"), WF__RANK)
|
||||
(string("PERCENT_RANK"), WF__PERCENT_RANK)
|
||||
(string("DENSE_RANK"), WF__DENSE_RANK)
|
||||
(string("CUME_DIST"), WF__CUME_DIST)
|
||||
(string("FIRST_VALUE"), WF__FIRST_VALUE)
|
||||
(string("LAST_VALUE"), WF__LAST_VALUE)
|
||||
(string("NTH_VALUE"), WF__NTH_VALUE)
|
||||
(string("LAG"), WF__LAG)
|
||||
(string("LEAD"), WF__LEAD)
|
||||
(string("NTILE"), WF__NTILE)
|
||||
(string("MEDIAN"), WF__PERCENTILE_CONT)
|
||||
(string("PERCENTILE"), WF__PERCENTILE_CONT)
|
||||
(string("PERCENTILE_CONT"), WF__PERCENTILE_CONT)
|
||||
(string("PERCENTILE_DISC"), WF__PERCENTILE_DISC)
|
||||
(string("REGR_SLOPE"), WF__REGR_SLOPE)
|
||||
(string("REGR_INTERCEPT"), WF__REGR_INTERCEPT)
|
||||
(string("REGR_COUNT"), WF__REGR_COUNT)
|
||||
(string("REGR_R2"), WF__REGR_R2)
|
||||
(string("REGR_AVGX"), WF__REGR_AVGX)
|
||||
(string("REGR_AVGY"), WF__REGR_AVGY)
|
||||
(string("REGR_SXX"), WF__REGR_SXX)
|
||||
(string("REGR_SXY"), WF__REGR_SXY)
|
||||
(string("REGR_SYY"), WF__REGR_SYY)
|
||||
;
|
||||
|
||||
boost::shared_ptr<WindowFunctionType>
|
||||
WindowFunctionType::makeWindowFunction(const string& name, int ct)
|
||||
{
|
||||
boost::shared_ptr<WindowFunctionType> af;
|
||||
int functionId = windowFunctionId[algorithm::to_upper_copy(name)];
|
||||
switch (functionId)
|
||||
{
|
||||
case WF__COUNT_ASTERISK:
|
||||
case WF__COUNT:
|
||||
case WF__COUNT_DISTINCT:
|
||||
af = WF_count<int64_t>::makeFunction(functionId, name, ct);
|
||||
break;
|
||||
case WF__MIN:
|
||||
case WF__MAX:
|
||||
af = WF_min_max<int64_t>::makeFunction(functionId, name, ct);
|
||||
break;
|
||||
case WF__SUM:
|
||||
case WF__AVG:
|
||||
case WF__SUM_DISTINCT:
|
||||
case WF__AVG_DISTINCT:
|
||||
af = WF_sum_avg<int64_t>::makeFunction(functionId, name, ct);
|
||||
break;
|
||||
case WF__STDDEV_POP:
|
||||
case WF__STDDEV_SAMP:
|
||||
case WF__VAR_POP:
|
||||
case WF__VAR_SAMP:
|
||||
af = WF_stats<int64_t>::makeFunction(functionId, name, ct);
|
||||
break;
|
||||
case WF__ROW_NUMBER:
|
||||
af = WF_row_number::makeFunction(functionId, name, ct);
|
||||
break;
|
||||
case WF__RANK:
|
||||
case WF__DENSE_RANK:
|
||||
case WF__PERCENT_RANK:
|
||||
case WF__CUME_DIST:
|
||||
af = WF_ranking::makeFunction(functionId, name, ct);
|
||||
break;
|
||||
case WF__FIRST_VALUE:
|
||||
case WF__LAST_VALUE:
|
||||
case WF__NTH_VALUE:
|
||||
af = WF_nth_value<int64_t>::makeFunction(functionId, name, ct);
|
||||
break;
|
||||
case WF__LEAD:
|
||||
case WF__LAG:
|
||||
af = WF_lead_lag<int64_t>::makeFunction(functionId, name, ct);
|
||||
break;
|
||||
case WF__NTILE:
|
||||
af = WF_ntile::makeFunction(functionId, name, ct);
|
||||
break;
|
||||
case WF__PERCENTILE_CONT:
|
||||
case WF__PERCENTILE_DISC:
|
||||
af = WF_percentile<int64_t>::makeFunction(functionId, name, ct);
|
||||
break;
|
||||
case WF__REGR_SLOPE:
|
||||
case WF__REGR_INTERCEPT:
|
||||
case WF__REGR_COUNT:
|
||||
case WF__REGR_R2:
|
||||
case WF__REGR_AVGX:
|
||||
case WF__REGR_AVGY:
|
||||
case WF__REGR_SXX:
|
||||
case WF__REGR_SXY:
|
||||
case WF__REGR_SYY:
|
||||
case WF__UNDEFINED:
|
||||
default:
|
||||
throw IDBExcept(IDBErrorInfo::instance()->errorMsg(ERR_WF_NOT_SUPPORT, name),
|
||||
ERR_WF_NOT_SUPPORT);
|
||||
break;
|
||||
}
|
||||
|
||||
return af;
|
||||
}
|
||||
|
||||
|
||||
const string WindowFunctionType::toString() const
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Window Function Id: " << fFunctionId << ", field indices: ";
|
||||
for (uint64_t i = 0; i < fFieldIndex.size(); i++)
|
||||
oss << fFieldIndex[i] << " ";
|
||||
oss << endl;
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
template<typename T> void WindowFunctionType::getValue(uint64_t i, T& t)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::getValue<int64_t>(uint64_t i, int64_t& t)
|
||||
{
|
||||
t = fRow.getIntField(i);
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::getValue<uint64_t>(uint64_t i, uint64_t& t)
|
||||
{
|
||||
t = fRow.getUintField(i);
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::getValue<double>(uint64_t i, double& t)
|
||||
{
|
||||
t = fRow.getDoubleField(i);
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::getValue<float>(uint64_t i, float& t)
|
||||
{
|
||||
t = fRow.getFloatField(i);
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::getValue<string>(uint64_t i, string& t)
|
||||
{
|
||||
t = fRow.getStringField(i);
|
||||
}
|
||||
|
||||
|
||||
template<typename T> void WindowFunctionType::setValue(uint64_t i, T& t)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::setValue<int64_t>(uint64_t i, int64_t& t)
|
||||
{
|
||||
fRow.setIntField(t, i);
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::setValue<uint64_t>(uint64_t i, uint64_t& t)
|
||||
{
|
||||
fRow.setUintField(t, i);
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::setValue<double>(uint64_t i, double& t)
|
||||
{
|
||||
fRow.setDoubleField(t, i);
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::setValue<float>(uint64_t i, float& t)
|
||||
{
|
||||
fRow.setFloatField(t, i);
|
||||
}
|
||||
|
||||
|
||||
template<> void WindowFunctionType::setValue<string>(uint64_t i, string& t)
|
||||
{
|
||||
fRow.setStringField(t, i);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WindowFunctionType::setValue(int ct, int64_t b, int64_t e, int64_t c, T* v)
|
||||
{
|
||||
if (c != WF__BOUND_ALL)
|
||||
b = e = c;
|
||||
|
||||
uint64_t i = fFieldIndex[0];
|
||||
if (v == NULL)
|
||||
v = (T*) getNullValueByType(ct, i);
|
||||
|
||||
for (int64_t j = b; j <= e; j++)
|
||||
{
|
||||
if (j % 1000 == 0 && fStep->cancelled())
|
||||
break;
|
||||
|
||||
fRow.setData(getPointer((*fRowData)[j]));
|
||||
setValue(i, *v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WindowFunctionType::implicit2T(uint64_t i, T& t, int s)
|
||||
{
|
||||
int ct = fRow.getColType(i);
|
||||
int pw = 0;
|
||||
switch (ct)
|
||||
{
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
{
|
||||
t = (T) fRow.getIntField(i);
|
||||
pw = s - fRow.getScale(i); // pw is difference of scales, will be in [-18, 18]
|
||||
if (pw > 0)
|
||||
t *= IDB_pow[pw];
|
||||
else if (pw < 0)
|
||||
t /= IDB_pow[-pw];
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
t = (T) fRow.getUintField(i);
|
||||
pw = s - fRow.getScale(i); // pw is difference of scales, will be in [-18, 18]
|
||||
if (pw > 0)
|
||||
t *= IDB_pow[pw];
|
||||
else if (pw < 0)
|
||||
t /= IDB_pow[-pw];
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
{
|
||||
if (s == 0)
|
||||
t = (T) fRow.getDoubleField(i);
|
||||
else
|
||||
t = (T) (fRow.getDoubleField(i) * IDB_pow[s]); // s is scale, [0, 18]
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
{
|
||||
if (s == 0)
|
||||
t = (T) fRow.getFloatField(i);
|
||||
else
|
||||
t = (T) (fRow.getFloatField(i) * IDB_pow[s]); // s is scale, [0, 18]
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::CHAR:
|
||||
case CalpontSystemCatalog::VARCHAR:
|
||||
default:
|
||||
{
|
||||
string errStr = fFunctionName + "(" + colType2String[ct] + ")";
|
||||
errStr = IDBErrorInfo::instance()->errorMsg(ERR_WF_INVALID_PARM_TYPE, errStr);
|
||||
cerr << errStr << endl;
|
||||
throw IDBExcept(errStr, ERR_WF_INVALID_PARM_TYPE);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::implicit2T<string>(uint64_t i, string& t, int)
|
||||
{
|
||||
t = fRow.getStringField(i);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void WindowFunctionType::getConstValue(ConstantColumn* cc, T& t, bool& b)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<int64_t>(ConstantColumn* cc, int64_t& t, bool& b)
|
||||
{
|
||||
t = cc->getIntVal(fRow, b);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<uint64_t>(ConstantColumn* cc, uint64_t& t, bool& b)
|
||||
{
|
||||
t = cc->getUintVal(fRow, b);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<double>(ConstantColumn* cc, double& t, bool& b)
|
||||
{
|
||||
t = cc->getDoubleVal(fRow, b);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<float>(ConstantColumn* cc, float& t, bool& b)
|
||||
{
|
||||
t = cc->getFloatVal(fRow, b);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
void WindowFunctionType::getConstValue<string>(ConstantColumn* cc, string& t, bool& b)
|
||||
{
|
||||
t = cc->getStrVal(fRow, b);
|
||||
}
|
||||
|
||||
|
||||
template void WindowFunctionType::implicit2T<int64_t>(uint64_t, int64_t&, int);
|
||||
template void WindowFunctionType::implicit2T<uint64_t>(uint64_t, uint64_t&, int);
|
||||
template void WindowFunctionType::implicit2T<float>(uint64_t, float&, int);
|
||||
template void WindowFunctionType::implicit2T<double>(uint64_t, double&, int);
|
||||
|
||||
template void WindowFunctionType::setValue<int64_t>(int, int64_t, int64_t, int64_t, int64_t*);
|
||||
template void WindowFunctionType::setValue<uint64_t>(int, int64_t, int64_t, int64_t, uint64_t*);
|
||||
template void WindowFunctionType::setValue<float>(int, int64_t, int64_t, int64_t, float*);
|
||||
template void WindowFunctionType::setValue<double>(int, int64_t, int64_t, int64_t, double*);
|
||||
template void WindowFunctionType::setValue<string>(int, int64_t, int64_t, int64_t, string*);
|
||||
|
||||
|
||||
|
||||
void* WindowFunctionType::getNullValueByType(int ct, int pos)
|
||||
{
|
||||
static uint64_t bigIntNull = joblist::BIGINTNULL;
|
||||
static uint64_t intNull = joblist::INTNULL;
|
||||
static uint64_t smallIntNull = joblist::SMALLINTNULL;
|
||||
static uint64_t tinyIntNull = joblist::TINYINTNULL;
|
||||
static uint64_t ubigIntNull = joblist::UBIGINTNULL;
|
||||
static uint64_t uintNull = joblist::UINTNULL;
|
||||
static uint64_t usmallIntNull = joblist::USMALLINTNULL;
|
||||
static uint64_t utinyIntNull = joblist::UTINYINTNULL;
|
||||
static uint64_t floatNull = joblist::FLOATNULL;
|
||||
static uint64_t doubleNull = joblist::DOUBLENULL;
|
||||
static uint64_t dateNull = joblist::DATENULL;
|
||||
static uint64_t datetimeNull = joblist::DATETIMENULL;
|
||||
static uint64_t char1Null = joblist::CHAR1NULL;
|
||||
static uint64_t char2Null = joblist::CHAR2NULL;
|
||||
static uint64_t char4Null = joblist::CHAR4NULL;
|
||||
static uint64_t char8Null = joblist::CHAR8NULL;
|
||||
static string stringNull("");
|
||||
|
||||
void* v = NULL;
|
||||
switch (ct) {
|
||||
case CalpontSystemCatalog::TINYINT:
|
||||
v = &tinyIntNull;
|
||||
break;
|
||||
case CalpontSystemCatalog::SMALLINT:
|
||||
v = &smallIntNull;
|
||||
break;
|
||||
case CalpontSystemCatalog::MEDINT:
|
||||
case CalpontSystemCatalog::INT:
|
||||
v = &intNull;
|
||||
break;
|
||||
case CalpontSystemCatalog::BIGINT:
|
||||
v = &bigIntNull;
|
||||
break;
|
||||
case CalpontSystemCatalog::DATE:
|
||||
v = &dateNull;
|
||||
break;
|
||||
case CalpontSystemCatalog::DATETIME:
|
||||
v = &datetimeNull;
|
||||
break;
|
||||
case CalpontSystemCatalog::FLOAT:
|
||||
case CalpontSystemCatalog::UFLOAT:
|
||||
v = &floatNull;
|
||||
break;
|
||||
case CalpontSystemCatalog::DOUBLE:
|
||||
case CalpontSystemCatalog::UDOUBLE:
|
||||
v = &doubleNull;
|
||||
break;
|
||||
case CalpontSystemCatalog::CHAR:
|
||||
case CalpontSystemCatalog::VARCHAR: {
|
||||
uint64_t len = fRow.getColumnWidth(pos);
|
||||
switch (len) {
|
||||
case 1:
|
||||
v = &char1Null;
|
||||
break;
|
||||
case 2:
|
||||
v = &char2Null;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
v = &char4Null;
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
v = &char8Null;
|
||||
break;
|
||||
default:
|
||||
v = &stringNull;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::DECIMAL:
|
||||
case CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
uint64_t len = fRow.getColumnWidth(pos);
|
||||
switch (len) {
|
||||
case 1:
|
||||
v = &tinyIntNull;
|
||||
break;
|
||||
case 2:
|
||||
v = &smallIntNull;
|
||||
break;
|
||||
case 4:
|
||||
v = &intNull;
|
||||
break;
|
||||
default:
|
||||
v = &bigIntNull;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CalpontSystemCatalog::UTINYINT:
|
||||
v = &utinyIntNull;
|
||||
break;
|
||||
case CalpontSystemCatalog::USMALLINT:
|
||||
v = &usmallIntNull;
|
||||
break;
|
||||
case CalpontSystemCatalog::UMEDINT:
|
||||
case CalpontSystemCatalog::UINT:
|
||||
v = &uintNull;
|
||||
break;
|
||||
case CalpontSystemCatalog::UBIGINT:
|
||||
v = &ubigIntNull;
|
||||
break;
|
||||
case CalpontSystemCatalog::LONGDOUBLE:
|
||||
case CalpontSystemCatalog::VARBINARY:
|
||||
default:
|
||||
std::ostringstream oss;
|
||||
oss << "not supported data type: " << colType2String[ct];
|
||||
throw logic_error(oss.str());
|
||||
break;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
} //namespace
|
||||
// vim:ts=4 sw=4:
|
||||
|
214
utils/windowfunction/windowfunctiontype.h
Normal file
214
utils/windowfunction/windowfunctiontype.h
Normal file
@ -0,0 +1,214 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
// $Id: windowfunctiontype.h 3932 2013-06-25 16:08:10Z xlou $
|
||||
|
||||
|
||||
#ifndef UTILS_WINDOWFUNCTIONTYPE_H
|
||||
#define UTILS_WINDOWFUNCTIONTYPE_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "returnedcolumn.h"
|
||||
#include "rowgroup.h"
|
||||
#include "windowframe.h"
|
||||
|
||||
|
||||
namespace ordering
|
||||
{
|
||||
// forward reference
|
||||
class EqualCompData;
|
||||
};
|
||||
|
||||
namespace execplan
|
||||
{
|
||||
// forward reference
|
||||
class ConstantColumn;
|
||||
};
|
||||
|
||||
namespace joblist
|
||||
{
|
||||
// forward reference
|
||||
class WindowFunctionStep;
|
||||
};
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
|
||||
// forward reference
|
||||
class WindowFunctionType;
|
||||
class IdbOrderBy;
|
||||
class WindowFrame;
|
||||
|
||||
const int WF__UNDEFINED = 0;
|
||||
const int WF__COUNT_ASTERISK = 1;
|
||||
const int WF__COUNT = 2;
|
||||
const int WF__SUM = 3;
|
||||
const int WF__AVG = 4;
|
||||
const int WF__MIN = 5;
|
||||
const int WF__MAX = 6;
|
||||
const int WF__COUNT_DISTINCT = 7;
|
||||
const int WF__SUM_DISTINCT = 8;
|
||||
const int WF__AVG_DISTINCT = 9;
|
||||
const int WF__STDDEV_POP = 10;
|
||||
const int WF__STDDEV_SAMP = 11;
|
||||
const int WF__VAR_POP = 12;
|
||||
const int WF__VAR_SAMP = 13;
|
||||
|
||||
const int WF__ROW_NUMBER = 14;
|
||||
const int WF__RANK = 15;
|
||||
const int WF__PERCENT_RANK = 16;
|
||||
const int WF__DENSE_RANK = 17;
|
||||
const int WF__CUME_DIST = 18;
|
||||
|
||||
const int WF__FIRST_VALUE = 19;
|
||||
const int WF__LAST_VALUE = 20;
|
||||
const int WF__NTH_VALUE = 21;
|
||||
const int WF__LAG = 22;
|
||||
const int WF__LEAD = 23;
|
||||
const int WF__NTILE = 24;
|
||||
const int WF__PERCENTILE_CONT = 25;
|
||||
const int WF__PERCENTILE_DISC = 26;
|
||||
|
||||
const int WF__REGR_SLOPE = 27;
|
||||
const int WF__REGR_INTERCEPT = 28;
|
||||
const int WF__REGR_COUNT = 29;
|
||||
const int WF__REGR_R2 = 30;
|
||||
const int WF__REGR_AVGX = 31;
|
||||
const int WF__REGR_AVGY = 32;
|
||||
const int WF__REGR_SXX = 33;
|
||||
const int WF__REGR_SXY = 34;
|
||||
const int WF__REGR_SYY = 35;
|
||||
|
||||
|
||||
|
||||
/** @brief class WindowFunction
|
||||
*
|
||||
*/
|
||||
class WindowFunctionType
|
||||
{
|
||||
public:
|
||||
// @brief WindowFunctionType constructor
|
||||
WindowFunctionType(int id = 0, const std::string& name = "") :
|
||||
fFunctionId(id), fFunctionName(name), fFrameUnit(0) {};
|
||||
|
||||
// use default copy construct
|
||||
//WindowFunctionType(const WindowFunctionType&);
|
||||
|
||||
// @brief WindowFunctionType destructor
|
||||
virtual ~WindowFunctionType() {};
|
||||
|
||||
// @brief virtual operator(begin, end, current, data, row)
|
||||
virtual void operator()(int64_t, int64_t, int64_t) = 0;
|
||||
|
||||
// @brief virtual clone()
|
||||
virtual WindowFunctionType* clone() const = 0;
|
||||
|
||||
// @brief virtual resetData()
|
||||
virtual void resetData() { fPrev = -1; }
|
||||
|
||||
// @brief virtual parseParms()
|
||||
virtual void parseParms(const std::vector<execplan::SRCP>&) {}
|
||||
|
||||
// @brief virtual display method
|
||||
virtual const std::string toString() const;
|
||||
|
||||
// @brief access methods
|
||||
int64_t functionId() const { return fFunctionId; }
|
||||
void functionId(int id) { fFunctionId = id; }
|
||||
const std::vector<int64_t>& fieldIndex() const { return fFieldIndex; }
|
||||
void fieldIndex(const std::vector<int64_t>& v) { fFieldIndex = v; }
|
||||
void setRowMetaData(const rowgroup::RowGroup& g, const rowgroup::Row& r)
|
||||
{ fRowGroup = g; fRow = r; }
|
||||
void setRowData(const boost::shared_ptr<std::vector<joblist::RowPosition> >& d) {fRowData = d;}
|
||||
int64_t frameUnit() const { return fFrameUnit; }
|
||||
void frameUnit(int u) { fFrameUnit = u; }
|
||||
std::pair<int64_t, int64_t> partition() const { return fPartition; }
|
||||
void partition(std::pair<int64_t, int64_t>& p) { fPartition = p; }
|
||||
const boost::shared_ptr<ordering::EqualCompData>& peer() const { return fPeer; }
|
||||
void peer(const boost::shared_ptr<ordering::EqualCompData>& p) { fPeer = p; }
|
||||
void setCallback(joblist::WindowFunctionStep* step) { fStep = step; }
|
||||
|
||||
static boost::shared_ptr<WindowFunctionType> makeWindowFunction(const std::string&, int ct);
|
||||
|
||||
protected:
|
||||
|
||||
static std::map<std::string, int> windowFunctionId;
|
||||
|
||||
// utility methods
|
||||
template<typename T> void getValue(uint64_t, T&);
|
||||
template<typename T> void setValue(int, int64_t, int64_t, int64_t, T* = NULL);
|
||||
template<typename T> void setValue(uint64_t, T&);
|
||||
template<typename T> void implicit2T(uint64_t, T&, int);
|
||||
template<typename T> void getConstValue(execplan::ConstantColumn*, T&, bool&);
|
||||
|
||||
virtual void* getNullValueByType(int, int);
|
||||
|
||||
int64_t getIntValue(uint64_t i) { return fRow.getIntField(i); }
|
||||
double getDoubleValue(uint64_t i) { return fRow.getDoubleField(i); }
|
||||
void setIntValue(int64_t i, int64_t v) { fRow.setIntField(v, i); }
|
||||
void setDoubleValue(int64_t i, double v) { fRow.setDoubleField(v, i); }
|
||||
|
||||
|
||||
// for string table
|
||||
rowgroup::Row::Pointer getPointer(joblist::RowPosition& r)
|
||||
{ return fStep->getPointer(r, fRowGroup, fRow); }
|
||||
|
||||
// function type
|
||||
int64_t fFunctionId;
|
||||
std::string fFunctionName;
|
||||
|
||||
// output and input field indices: [0] - output
|
||||
std::vector<int64_t> fFieldIndex;
|
||||
|
||||
// row meta data
|
||||
rowgroup::RowGroup fRowGroup;
|
||||
rowgroup::Row fRow;
|
||||
|
||||
// data set
|
||||
boost::shared_ptr<std::vector<joblist::RowPosition> > fRowData;
|
||||
|
||||
// frame unit ( ROWS | RANGE )
|
||||
int64_t fFrameUnit;
|
||||
|
||||
// partition
|
||||
std::pair<int64_t, int64_t> fPartition;
|
||||
|
||||
// functor for peer checking
|
||||
boost::shared_ptr<ordering::EqualCompData> fPeer;
|
||||
int64_t fPrev;
|
||||
|
||||
// for checking if query is cancelled
|
||||
joblist::WindowFunctionStep* fStep;
|
||||
|
||||
};
|
||||
|
||||
|
||||
extern std::map<int, std::string> colType2String;
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // UTILS_WINDOWFUNCTIONTYPE_H
|
||||
|
||||
// vim:ts=4 sw=4:
|
||||
|
Reference in New Issue
Block a user