1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-04-17 10:37:05 +03:00

clang format apply

This commit is contained in:
Leonid Fedorov 2022-01-21 16:43:49 +00:00
parent 6b6411229f
commit 04752ec546
1376 changed files with 393460 additions and 412662 deletions

View File

@ -18,5 +18,5 @@ DerivePointerAlignment: false
IndentCaseLabels: true
NamespaceIndentation: None
PointerAlignment: Left
SortIncludes: true
SortIncludes: false
Standard: Auto

View File

@ -15,12 +15,10 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
#pragma once
namespace datatypes
{
/*
A subset of SQL Conditions related to data processing.
SQLSTATE terminology is used for categories:
@ -30,36 +28,39 @@ namespace datatypes
*/
class DataCondition
{
public:
public:
enum Code
{
// Code Value SQLSTATE
S_SUCCESS = 0, // 00000
W_STRING_DATA_RIGHT_TRUNCATION = 1 << 1, // 01004
X_STRING_DATA_RIGHT_TRUNCATION = 1 << 16, // 22001
X_NUMERIC_VALUE_OUT_OF_RANGE = 1 << 17, // 22003
X_INVALID_CHARACTER_VALUE_FOR_CAST = 1 << 18, // 22018
S_SUCCESS = 0, // 00000
W_STRING_DATA_RIGHT_TRUNCATION = 1 << 1, // 01004
X_STRING_DATA_RIGHT_TRUNCATION = 1 << 16, // 22001
X_NUMERIC_VALUE_OUT_OF_RANGE = 1 << 17, // 22003
X_INVALID_CHARACTER_VALUE_FOR_CAST = 1 << 18, // 22018
};
DataCondition()
:mError(S_SUCCESS)
{ }
DataCondition(Code code)
:mError(code)
{ }
DataCondition & operator|=(Code code)
DataCondition() : mError(S_SUCCESS)
{
mError= (Code) (mError | code);
}
DataCondition(Code code) : mError(code)
{
}
DataCondition& operator|=(Code code)
{
mError = (Code)(mError | code);
return *this;
}
DataCondition operator&(Code rhs) const
{
return DataCondition((Code) (mError & rhs));
return DataCondition((Code)(mError & rhs));
}
operator Code() const
{
return mError;
}
operator Code () const { return mError; }
// Adjust a sigened integer of any size to the range [-absMaxVal , +absMaxVal]
template<typename T>
void adjustSIntXRange(T & val, T absMaxVal)
template <typename T>
void adjustSIntXRange(T& val, T absMaxVal)
{
if (val > absMaxVal)
{
@ -73,9 +74,8 @@ public:
}
}
private:
private:
Code mError;
};
} // namespace datatypes
} // namespace datatypes

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -25,13 +25,11 @@
namespace datatypes
{
// Convert a positive floating point value to
// a signed or unsigned integer with rounding
// SRC - a floating point data type (float, double, float128_t)
// DST - a signed or unsigned integer data type (int32_t, uint64_t, int128_t, etc)
template<typename SRC, typename DST>
template <typename SRC, typename DST>
DST positiveXFloatToXIntRound(SRC value, DST limit)
{
SRC tmp = value + 0.5;
@ -40,12 +38,11 @@ DST positiveXFloatToXIntRound(SRC value, DST limit)
return static_cast<DST>(tmp);
}
// Convert a negative floating point value to
// a signed integer with rounding
// SRC - a floating point data type (float, double, float128_t)
// DST - a signed integer data type (int32_t, int64_t, int128_t, etc)
template<typename SRC, typename DST>
template <typename SRC, typename DST>
DST negativeXFloatToXIntRound(SRC value, DST limit)
{
SRC tmp = value - 0.5;
@ -54,40 +51,31 @@ DST negativeXFloatToXIntRound(SRC value, DST limit)
return static_cast<DST>(tmp);
}
// Convert a floating point value to ColumnStore int64_t
// Magic values cannot be returned.
template<typename SRC>
template <typename SRC>
int64_t xFloatToMCSSInt64Round(SRC value)
{
if (value > 0)
return positiveXFloatToXIntRound<SRC, int64_t>(
value,
numeric_limits<int64_t>::max());
return positiveXFloatToXIntRound<SRC, int64_t>(value, numeric_limits<int64_t>::max());
if (value < 0)
return negativeXFloatToXIntRound<SRC, int64_t>(
value,
numeric_limits<int64_t>::min() + 2);
return negativeXFloatToXIntRound<SRC, int64_t>(value, numeric_limits<int64_t>::min() + 2);
return 0;
}
// Convert a floating point value to ColumnStore uint64_t
// Magic values cannot be returned.
template<typename SRC>
template <typename SRC>
uint64_t xFloatToMCSUInt64Round(SRC value)
{
if (value > 0)
return positiveXFloatToXIntRound<SRC, uint64_t>(
value,
numeric_limits<uint64_t>::max() - 2);
return positiveXFloatToXIntRound<SRC, uint64_t>(value, numeric_limits<uint64_t>::max() - 2);
if (value < 0)
return negativeXFloatToXIntRound<SRC, uint64_t>(value, 0);
return 0;
}
} //end of namespace datatypes
} // end of namespace datatypes
// vim:ts=2 sw=2:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -22,17 +22,21 @@
namespace datatypes
{
class TDouble
{
protected:
protected:
double mValue;
public:
TDouble(): mValue(0) { }
explicit TDouble(double value): mValue(value) { }
public:
TDouble() : mValue(0)
{
}
explicit operator double () const
explicit TDouble(double value) : mValue(value)
{
}
explicit operator double() const
{
return mValue;
}
@ -48,7 +52,6 @@ public:
}
};
} //end of namespace datatypes
} // end of namespace datatypes
// vim:ts=2 sw=2:

File diff suppressed because it is too large Load Diff

View File

@ -14,8 +14,8 @@
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.
*/
MA 02110-1301, USA.
*/
#include <iostream>
@ -24,98 +24,93 @@
namespace datatypes
{
uint8_t TSInt128::printPodParts(char* buf,
const int128_t& high,
const int128_t& mid,
const int128_t& low) const
{
char* p = buf;
// pod[0] is low 8 bytes, pod[1] is high 8 bytes
const uint64_t* high_pod = reinterpret_cast<const uint64_t*>(&high);
const uint64_t* mid_pod = reinterpret_cast<const uint64_t*>(&mid);
const uint64_t* low_pod = reinterpret_cast<const uint64_t*>(&low);
uint8_t TSInt128::printPodParts(char* buf, const int128_t& high, const int128_t& mid,
const int128_t& low) const
{
char* p = buf;
// pod[0] is low 8 bytes, pod[1] is high 8 bytes
const uint64_t* high_pod = reinterpret_cast<const uint64_t*>(&high);
const uint64_t* mid_pod = reinterpret_cast<const uint64_t*>(&mid);
const uint64_t* low_pod = reinterpret_cast<const uint64_t*>(&low);
if (high_pod[0] != 0)
{
p += sprintf(p, "%lu", high_pod[0]);
p += sprintf(p, "%019lu", mid_pod[0]);
p += sprintf(p, "%019lu", low_pod[0]);
}
else if (mid_pod[0] != 0)
{
p += sprintf(p, "%lu", mid_pod[0]);
p += sprintf(p, "%019lu", low_pod[0]);
}
else
{
p += sprintf(p, "%lu", low_pod[0]);
}
return p - buf;
if (high_pod[0] != 0)
{
p += sprintf(p, "%lu", high_pod[0]);
p += sprintf(p, "%019lu", mid_pod[0]);
p += sprintf(p, "%019lu", low_pod[0]);
}
else if (mid_pod[0] != 0)
{
p += sprintf(p, "%lu", mid_pod[0]);
p += sprintf(p, "%019lu", low_pod[0]);
}
else
{
p += sprintf(p, "%lu", low_pod[0]);
}
return p - buf;
}
// This method writes unsigned integer representation of TSInt128
uint8_t TSInt128::writeIntPart(const int128_t& x, char* buf, const uint8_t buflen) const
{
char* p = buf;
int128_t high = 0, mid = 0, low = 0;
uint64_t maxUint64divisor = 10000000000000000000ULL;
low = x % maxUint64divisor;
int128_t value = x / maxUint64divisor;
mid = value % maxUint64divisor;
high = value / maxUint64divisor;
p += printPodParts(p, high, mid, low);
uint8_t written = p - buf;
if (buflen <= written)
{
throw logging::QueryDataExcept("TSInt128::writeIntPart() char buffer overflow.", logging::formatErr);
}
// This method writes unsigned integer representation of TSInt128
uint8_t TSInt128::writeIntPart(const int128_t& x,
char* buf,
const uint8_t buflen) const
return written;
}
// conversion to std::string
std::string TSInt128::toString() const
{
if (isNull())
{
char* p = buf;
int128_t high = 0, mid = 0, low = 0;
uint64_t maxUint64divisor = 10000000000000000000ULL;
low = x % maxUint64divisor;
int128_t value = x / maxUint64divisor;
mid = value % maxUint64divisor;
high = value / maxUint64divisor;
p += printPodParts(p, high, mid, low);
uint8_t written = p - buf;
if (buflen <= written)
{
throw logging::QueryDataExcept("TSInt128::writeIntPart() char buffer overflow.",
logging::formatErr);
}
return written;
return std::string("NULL");
}
// conversion to std::string
std::string TSInt128::toString() const
if (isEmpty())
{
if (isNull())
{
return std::string("NULL");
}
return std::string("EMPTY");
}
if (isEmpty())
{
return std::string("EMPTY");
}
int128_t tempValue = s128Value;
char buf[TSInt128::MAXLENGTH16BYTES];
uint8_t left = sizeof(buf);
char* p = buf;
// sign
if (tempValue < static_cast<int128_t>(0))
{
*p++ = '-';
tempValue *= -1;
left--;
}
// integer part
// reduce the size by one to account for \0
int128_t tempValue = s128Value;
char buf[TSInt128::MAXLENGTH16BYTES];
uint8_t left = sizeof(buf);
char* p = buf;
// sign
if (tempValue < static_cast<int128_t>(0))
{
*p++ = '-';
tempValue *= -1;
left--;
p += writeIntPart(tempValue, p, left);
*p = '\0';
return std::string(buf);
}
// integer part
// reduce the size by one to account for \0
left--;
p += writeIntPart(tempValue, p, left);
*p = '\0';
std::ostream& operator<<(std::ostream& os, const TSInt128& x)
{
os << x.toString();
return os;
}
return std::string(buf);
}
} // end of namespace datatypes
std::ostream& operator<<(std::ostream& os, const TSInt128& x)
{
os << x.toString();
return os;
}
} // end of namespace datatypes
// vim:ts=2 sw=2:

View File

@ -27,100 +27,73 @@
// Inline asm has three argument lists: output, input and clobber list
#ifdef __aarch64__
#define MACRO_VALUE_PTR_128(dst, \
dst_restrictions, \
src, \
src_restrictions, \
clobb) \
::memcpy((dst), &(src), sizeof(int128_t));
#define MACRO_PTR_PTR_128(dst, \
dst_restrictions, \
src, \
src_restrictions, \
clobb) \
::memcpy((dst), (src), sizeof(int128_t));
#define MACRO_VALUE_PTR_128(dst, dst_restrictions, src, src_restrictions, clobb) \
::memcpy((dst), &(src), sizeof(int128_t));
#define MACRO_PTR_PTR_128(dst, dst_restrictions, src, src_restrictions, clobb) \
::memcpy((dst), (src), sizeof(int128_t));
#elif defined(__GNUC__) && (__GNUC___ > 7) || defined(__clang__)
#define MACRO_VALUE_PTR_128(dst, \
dst_restrictions, \
src, \
src_restrictions, \
clobb) \
__asm__ volatile("movups %1,%0" \
:dst_restrictions ( *(dst) ) \
:src_restrictions ( (src) ) \
:clobb \
);
#define MACRO_PTR_PTR_128(dst, \
dst_restrictions, \
src, \
src_restrictions, \
clobb) \
::memcpy((dst), (src), sizeof(int128_t));
#define MACRO_VALUE_PTR_128(dst, dst_restrictions, src, src_restrictions, clobb) \
__asm__ volatile("movups %1,%0" : dst_restrictions(*(dst)) : src_restrictions((src)) : clobb);
#define MACRO_PTR_PTR_128(dst, dst_restrictions, src, src_restrictions, clobb) \
::memcpy((dst), (src), sizeof(int128_t));
#else
#define MACRO_VALUE_PTR_128(dst, \
dst_restrictions, \
src, \
src_restrictions, \
clobb) \
__asm__ volatile("movups %1,%0" \
:dst_restrictions ( *(dst) ) \
:src_restrictions ( (src) ) \
:clobb \
);
#define MACRO_PTR_PTR_128(dst, \
dst_restrictions, \
src, \
src_restrictions, \
clobb) \
__asm__ volatile("movdqu %1,%%xmm0;" \
"movups %%xmm0,%0;" \
:dst_restrictions ( *(dst) ) \
:src_restrictions ( *(src) ) \
:"memory", clobb \
);
#define MACRO_VALUE_PTR_128(dst, dst_restrictions, src, src_restrictions, clobb) \
__asm__ volatile("movups %1,%0" : dst_restrictions(*(dst)) : src_restrictions((src)) : clobb);
#define MACRO_PTR_PTR_128(dst, dst_restrictions, src, src_restrictions, clobb) \
__asm__ volatile( \
"movdqu %1,%%xmm0;" \
"movups %%xmm0,%0;" \
: dst_restrictions(*(dst)) \
: src_restrictions(*(src)) \
: "memory", clobb);
#endif
namespace datatypes
{
using int128_t = __int128;
using uint128_t = unsigned __int128;
// Type traits
template <typename T>
struct is_allowed_numeric {
struct is_allowed_numeric
{
static const bool value = false;
};
template <>
struct is_allowed_numeric<int> {
struct is_allowed_numeric<int>
{
static const bool value = true;
};
template <>
struct is_allowed_numeric<int128_t> {
struct is_allowed_numeric<int128_t>
{
static const bool value = true;
};
template <typename T>
struct is_int128_t {
struct is_int128_t
{
static const bool value = false;
};
template<>
struct is_int128_t<int128_t> {
template <>
struct is_int128_t<int128_t>
{
static const bool value = true;
};
template <typename T>
struct is_uint128_t {
struct is_uint128_t
{
static const bool value = false;
};
template<>
struct is_uint128_t<uint128_t> {
template <>
struct is_uint128_t<uint128_t>
{
static const bool value = true;
};
@ -131,217 +104,222 @@ inline int128_t abs(int128_t x)
class TSInt128
{
public:
static constexpr uint8_t MAXLENGTH16BYTES = 42;
static constexpr int128_t NullValue = int128_t(0x8000000000000000LL) << 64;
static constexpr int128_t EmptyValue = (int128_t(0x8000000000000000LL) << 64) + 1;
public:
static constexpr uint8_t MAXLENGTH16BYTES = 42;
static constexpr int128_t NullValue = int128_t(0x8000000000000000LL) << 64;
static constexpr int128_t EmptyValue = (int128_t(0x8000000000000000LL) << 64) + 1;
// A variety of ctors for aligned and unaligned arguments
TSInt128(): s128Value(0) { }
// A variety of ctors for aligned and unaligned arguments
TSInt128() : s128Value(0)
{
}
// Copy ctor
TSInt128(const TSInt128& other): s128Value(other.s128Value) { }
// Copy ctor
TSInt128(const TSInt128& other) : s128Value(other.s128Value)
{
}
TSInt128& operator=(const TSInt128& other)
{
s128Value = other.s128Value;
return *this;
}
TSInt128& operator=(const TSInt128& other)
{
s128Value = other.s128Value;
return *this;
}
// aligned argument
explicit TSInt128(const int128_t& x) { s128Value = x; }
// aligned argument
explicit TSInt128(const int128_t& x)
{
s128Value = x;
}
// unaligned argument
explicit TSInt128(const int128_t* x) { assignPtrPtr(&s128Value, x); }
// unaligned argument
explicit TSInt128(const int128_t* x)
{
assignPtrPtr(&s128Value, x);
}
// unaligned argument
explicit TSInt128(const unsigned char* x) { assignPtrPtr(&s128Value, x); }
// unaligned argument
explicit TSInt128(const unsigned char* x)
{
assignPtrPtr(&s128Value, x);
}
// Method returns max length of a string representation
static constexpr uint8_t maxLength()
{
return TSInt128::MAXLENGTH16BYTES;
}
// Method returns max length of a string representation
static constexpr uint8_t maxLength()
{
return TSInt128::MAXLENGTH16BYTES;
}
// Checks if the value is NULL
inline bool isNull() const
{
return s128Value == NullValue;
}
// Checks if the value is NULL
inline bool isNull() const
{
return s128Value == NullValue;
}
// Checks if the value is Empty
inline bool isEmpty() const
{
return s128Value == EmptyValue;
}
// Checks if the value is Empty
inline bool isEmpty() const
{
return s128Value == EmptyValue;
}
// The method copies 16 bytes from one memory cell
// into another using memcpy or SIMD.
// memcpy in gcc >= 7 is replaced with SIMD instructions
template <typename D, typename S>
static inline void assignPtrPtr(D* dst, const S* src)
{
MACRO_PTR_PTR_128(dst, "=m", src, "m", "xmm0")
}
// The method copies 16 bytes from one memory cell
// into another using memcpy or SIMD.
// memcpy in gcc >= 7 is replaced with SIMD instructions
template <typename D, typename S>
static inline void assignPtrPtr(D* dst, const S* src)
{
MACRO_PTR_PTR_128(dst, "=m", src, "m", "xmm0")
}
template <typename D>
static inline void storeUnaligned(D* dst, const int128_t& src)
{
MACRO_VALUE_PTR_128(dst, "=m", src, "x", "memory")
}
template <typename D>
static inline void storeUnaligned(D* dst, const int128_t& src)
{
MACRO_VALUE_PTR_128(dst, "=m", src, "x", "memory")
}
// operators
template<typename T,
typename = std::enable_if<is_allowed_numeric<T>::value> >
inline bool operator<(const T& x) const
{
return s128Value < static_cast<int128_t>(x);
}
// operators
template <typename T, typename = std::enable_if<is_allowed_numeric<T>::value> >
inline bool operator<(const T& x) const
{
return s128Value < static_cast<int128_t>(x);
}
template<typename T,
typename = std::enable_if<is_allowed_numeric<T>::value> >
inline bool operator==(const T& x) const
{
return s128Value == static_cast<int128_t>(x);
}
template <typename T, typename = std::enable_if<is_allowed_numeric<T>::value> >
inline bool operator==(const T& x) const
{
return s128Value == static_cast<int128_t>(x);
}
inline operator double() const
{
return toDouble();
}
inline operator double() const
{
return toDouble();
}
inline double toDouble() const
{
return static_cast<double>(s128Value);
}
inline double toDouble() const
{
return static_cast<double>(s128Value);
}
inline operator long double() const
{
return toLongDouble();
}
inline operator long double() const
{
return toLongDouble();
}
inline long double toLongDouble() const
{
return static_cast<long double>(s128Value);
}
inline long double toLongDouble() const
{
return static_cast<long double>(s128Value);
}
inline operator int32_t() const
{
if (s128Value > static_cast<int128_t>(INT32_MAX))
return INT32_MAX;
if (s128Value < static_cast<int128_t>(INT32_MIN))
return INT32_MIN;
inline operator int32_t() const
{
if (s128Value > static_cast<int128_t>(INT32_MAX))
return INT32_MAX;
if (s128Value < static_cast<int128_t>(INT32_MIN))
return INT32_MIN;
return static_cast<int32_t>(s128Value);
}
return static_cast<int32_t>(s128Value);
}
inline operator uint32_t() const
{
if (s128Value > static_cast<int128_t>(UINT32_MAX))
return UINT32_MAX;
if (s128Value < 0)
return 0;
inline operator uint32_t() const
{
if (s128Value > static_cast<int128_t>(UINT32_MAX))
return UINT32_MAX;
if (s128Value < 0)
return 0;
return static_cast<uint32_t>(s128Value);
}
return static_cast<uint32_t>(s128Value);
}
inline operator int64_t() const
{
if (s128Value > static_cast<int128_t>(INT64_MAX))
return INT64_MAX;
if (s128Value < static_cast<int128_t>(INT64_MIN))
return INT64_MIN;
inline operator int64_t() const
{
if (s128Value > static_cast<int128_t>(INT64_MAX))
return INT64_MAX;
if (s128Value < static_cast<int128_t>(INT64_MIN))
return INT64_MIN;
return static_cast<int64_t>(s128Value);
}
return static_cast<int64_t>(s128Value);
}
inline operator uint64_t() const
{
if (s128Value > static_cast<int128_t>(UINT64_MAX))
return UINT64_MAX;
if (s128Value < 0)
return 0;
inline operator uint64_t() const
{
if (s128Value > static_cast<int128_t>(UINT64_MAX))
return UINT64_MAX;
if (s128Value < 0)
return 0;
return static_cast<uint64_t>(s128Value);
}
return static_cast<uint64_t>(s128Value);
}
inline operator TFloat128() const
{
return toTFloat128();
}
inline operator TFloat128() const
{
return toTFloat128();
}
// unaligned argument
inline TSInt128& operator=(const int128_t* x)
{
assignPtrPtr(&s128Value, x);
return *this;
}
// unaligned argument
inline TSInt128& operator=(const int128_t* x)
{
assignPtrPtr(&s128Value, x);
return *this;
}
inline TSInt128 operator%(const int64_t& rhs) const
{
return TSInt128(s128Value % rhs);
}
inline TSInt128 operator%(const int64_t& rhs) const
{
return TSInt128(s128Value % rhs);
}
inline TSInt128 operator%(const int128_t& rhs) const
{
return TSInt128(s128Value % rhs);
}
inline TSInt128 operator%(const int128_t& rhs) const
{
return TSInt128(s128Value % rhs);
}
inline TSInt128 operator*(const TSInt128& rhs) const
{
return TSInt128(s128Value * rhs.s128Value);
}
inline TSInt128 operator*(const TSInt128& rhs) const
{
return TSInt128(s128Value * rhs.s128Value);
}
inline TSInt128 operator+(const TSInt128& rhs) const
{
return TSInt128(s128Value + rhs.s128Value);
}
inline TSInt128 operator+(const TSInt128& rhs) const
{
return TSInt128(s128Value + rhs.s128Value);
}
inline bool operator>(const TSInt128& rhs) const
{
return s128Value > rhs.s128Value;
}
inline bool operator>(const TSInt128& rhs) const
{
return s128Value > rhs.s128Value;
}
inline bool operator<(const TSInt128& rhs) const
{
return s128Value < rhs.s128Value;
}
inline bool operator<(const TSInt128& rhs) const
{
return s128Value < rhs.s128Value;
}
inline bool operator!=(const TSInt128& rhs) const
{
return s128Value != rhs.getValue();
}
inline bool operator!=(const TSInt128& rhs) const
{
return s128Value != rhs.getValue();
}
inline TFloat128 toTFloat128() const
{
return TFloat128(s128Value);
}
inline TFloat128 toTFloat128() const
{
return TFloat128(s128Value);
}
inline const int128_t& getValue() const
{
return s128Value;
}
inline const int128_t& getValue() const
{
return s128Value;
}
// print int128_t parts represented as PODs
uint8_t printPodParts(char* buf,
const int128_t& high,
const int128_t& mid,
const int128_t& low) const;
// print int128_t parts represented as PODs
uint8_t printPodParts(char* buf, const int128_t& high, const int128_t& mid, const int128_t& low) const;
// writes integer part of dec into a buffer
uint8_t writeIntPart(const int128_t& x,
char* buf,
const uint8_t buflen) const;
// writes integer part of dec into a buffer
uint8_t writeIntPart(const int128_t& x, char* buf, const uint8_t buflen) const;
// string representation of TSInt128
std::string toString() const;
// string representation of TSInt128
std::string toString() const;
friend std::ostream& operator<<(std::ostream& os, const TSInt128& x);
friend std::ostream& operator<<(std::ostream& os, const TSInt128& x);
int128_t s128Value;
}; // end of class
int128_t s128Value;
}; // end of class
} //end of namespace datatypes
} // end of namespace datatypes
// vim:ts=2 sw=2:

View File

@ -14,162 +14,169 @@
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.
*/
MA 02110-1301, USA.
*/
#pragma once
#include "exceptclasses.h"
namespace datatypes
{
class TNullFlag
{
protected:
protected:
bool mIsNull;
public:
explicit TNullFlag(bool val) :mIsNull(val) { }
public:
explicit TNullFlag(bool val) : mIsNull(val)
{
}
bool isNull() const
{
return mIsNull;
}
};
class TUInt64
{
protected:
protected:
uint64_t mValue;
public:
TUInt64(): mValue(0) { }
explicit TUInt64(uint64_t value): mValue(value) { }
public:
TUInt64() : mValue(0)
{
}
explicit operator uint64_t () const
explicit TUInt64(uint64_t value) : mValue(value)
{
}
explicit operator uint64_t() const
{
return mValue;
}
void store(uint8_t* dst) const
{
*(uint64_t*) dst = mValue;
*(uint64_t*)dst = mValue;
}
};
class TSInt64
{
protected:
protected:
int64_t mValue;
public:
TSInt64(): mValue(0) { }
explicit TSInt64(int64_t value): mValue(value) { }
public:
TSInt64() : mValue(0)
{
}
explicit operator int64_t () const
explicit TSInt64(int64_t value) : mValue(value)
{
}
explicit operator int64_t() const
{
return mValue;
}
explicit operator uint64_t () const
explicit operator uint64_t() const
{
return mValue < 0 ? 0 : static_cast<uint64_t>(mValue);
}
};
class TUInt64Null: public TUInt64, public TNullFlag
class TUInt64Null : public TUInt64, public TNullFlag
{
public:
public:
TUInt64Null() : TNullFlag(true)
{
}
TUInt64Null(): TNullFlag(true) { }
explicit TUInt64Null(uint64_t value, bool isNull = false) : TUInt64(value), TNullFlag(isNull)
{
}
explicit TUInt64Null(uint64_t value, bool isNull = false):
TUInt64(value), TNullFlag(isNull)
{ }
explicit operator uint64_t () const
explicit operator uint64_t() const
{
idbassert(!mIsNull);
return mValue;
}
uint64_t nullSafeValue(bool & isNullRef) const
uint64_t nullSafeValue(bool& isNullRef) const
{
return (isNullRef = isNull()) ? 0 : mValue;
}
TUInt64Null operator&(const TUInt64Null &rhs) const
TUInt64Null operator&(const TUInt64Null& rhs) const
{
return TUInt64Null(mValue & rhs.mValue, mIsNull || rhs.mIsNull);
}
TUInt64Null operator|(const TUInt64Null &rhs) const
TUInt64Null operator|(const TUInt64Null& rhs) const
{
return TUInt64Null(mValue | rhs.mValue, mIsNull || rhs.mIsNull);
}
TUInt64Null operator^(const TUInt64Null &rhs) const
TUInt64Null operator^(const TUInt64Null& rhs) const
{
return TUInt64Null(mValue ^ rhs.mValue, mIsNull || rhs.mIsNull);
}
TUInt64Null MariaDBShiftLeft(const TUInt64Null &rhs) const
TUInt64Null MariaDBShiftLeft(const TUInt64Null& rhs) const
{
return TUInt64Null(rhs.mValue >= 64 ? 0 : mValue << rhs.mValue, mIsNull || rhs.mIsNull);
}
TUInt64Null MariaDBShiftRight(const TUInt64Null &rhs) const
TUInt64Null MariaDBShiftRight(const TUInt64Null& rhs) const
{
return TUInt64Null(rhs.mValue >= 64 ? 0 : mValue >> rhs.mValue, mIsNull || rhs.mIsNull);
}
};
class TSInt64Null: public TSInt64, public TNullFlag
class TSInt64Null : public TSInt64, public TNullFlag
{
public:
public:
TSInt64Null() : TNullFlag(true)
{
}
TSInt64Null(): TNullFlag(true) { }
explicit TSInt64Null(int64_t value, bool isNull = false) : TSInt64(value), TNullFlag(isNull)
{
}
explicit TSInt64Null(int64_t value, bool isNull = false):
TSInt64(value), TNullFlag(isNull)
{ }
explicit operator int64_t () const
explicit operator int64_t() const
{
idbassert(!mIsNull);
return mValue;
}
int64_t nullSafeValue(bool & isNullRef) const
int64_t nullSafeValue(bool& isNullRef) const
{
return (isNullRef = isNull()) ? 0 : mValue;
}
TSInt64Null operator&(const TSInt64Null &rhs) const
TSInt64Null operator&(const TSInt64Null& rhs) const
{
return TSInt64Null(mValue & rhs.mValue, mIsNull || rhs.mIsNull);
}
TSInt64Null operator|(const TSInt64Null &rhs) const
TSInt64Null operator|(const TSInt64Null& rhs) const
{
return TSInt64Null(mValue | rhs.mValue, mIsNull || rhs.mIsNull);
}
TSInt64Null operator^(const TSInt64Null &rhs) const
TSInt64Null operator^(const TSInt64Null& rhs) const
{
return TSInt64Null(mValue ^ rhs.mValue, mIsNull || rhs.mIsNull);
}
TSInt64Null MariaDBShiftLeft(const TUInt64Null &rhs) const
TSInt64Null MariaDBShiftLeft(const TUInt64Null& rhs) const
{
if (isNull() || rhs.isNull())
return TSInt64Null();
return TSInt64Null((uint64_t) rhs >= 64 ? 0 : mValue << (uint64_t) rhs, false);
return TSInt64Null((uint64_t)rhs >= 64 ? 0 : mValue << (uint64_t)rhs, false);
}
TSInt64Null MariaDBShiftRight(const TUInt64Null &rhs) const
TSInt64Null MariaDBShiftRight(const TUInt64Null& rhs) const
{
if (isNull() || rhs.isNull())
return TSInt64Null();
return TSInt64Null((uint64_t) rhs >= 64 ? 0 : mValue >> (uint64_t) rhs, false);
return TSInt64Null((uint64_t)rhs >= 64 ? 0 : mValue >> (uint64_t)rhs, false);
}
};
} //end of namespace datatypes
} // end of namespace datatypes
// vim:ts=2 sw=2:

View File

@ -22,17 +22,21 @@
namespace datatypes
{
class TLongDouble
{
protected:
protected:
long double mValue;
public:
TLongDouble(): mValue(0) { }
explicit TLongDouble(long double value): mValue(value) { }
public:
TLongDouble() : mValue(0)
{
}
explicit operator long double () const
explicit TLongDouble(long double value) : mValue(value)
{
}
explicit operator long double() const
{
return mValue;
}
@ -48,7 +52,6 @@ public:
}
};
} //end of namespace datatypes
} // end of namespace datatypes
// vim:ts=2 sw=2:

View File

@ -21,18 +21,24 @@
namespace datatypes
{
template <typename T>
struct numeric_limits
{
static constexpr T min() { return std::numeric_limits<T>::min(); }
static constexpr T max() { return std::numeric_limits<T>::max(); }
static constexpr T min()
{
return std::numeric_limits<T>::min();
}
static constexpr T max()
{
return std::numeric_limits<T>::max();
}
};
using int128_t = __int128;
using uint128_t = unsigned __int128;
template<> struct numeric_limits<int128_t>
template <>
struct numeric_limits<int128_t>
{
static constexpr int128_t min()
{
@ -44,7 +50,8 @@ template<> struct numeric_limits<int128_t>
}
};
template<> struct numeric_limits<uint128_t>
template <>
struct numeric_limits<uint128_t>
{
static constexpr uint128_t min()
{
@ -56,5 +63,4 @@ template<> struct numeric_limits<uint128_t>
}
};
} // namespace datatypes
} // namespace datatypes

View File

@ -15,37 +15,32 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
#pragma once
#include "conststring.h"
#include "collation.h" // class Charset
#include "collation.h" // class Charset
namespace datatypes
{
class TCharShort
{
int64_t mValue;
public:
TCharShort(int64_t value)
:mValue(value)
{ }
utils::ConstString toConstString(uint32_t width) const
{
utils::ConstString res = utils::ConstString((const char *) &mValue, width);
return res.rtrimZero();
}
static int strnncollsp(const datatypes::Charset &cs, int64_t a, int64_t b, uint32_t width)
{
datatypes::TCharShort sa(a);
datatypes::TCharShort sb(b);
return cs.strnncollsp(sa.toConstString(width),
sb.toConstString(width));
}
int64_t mValue;
public:
TCharShort(int64_t value) : mValue(value)
{
}
utils::ConstString toConstString(uint32_t width) const
{
utils::ConstString res = utils::ConstString((const char*)&mValue, width);
return res.rtrimZero();
}
static int strnncollsp(const datatypes::Charset& cs, int64_t a, int64_t b, uint32_t width)
{
datatypes::TCharShort sa(a);
datatypes::TCharShort sb(b);
return cs.strnncollsp(sa.toConstString(width), sb.toConstString(width));
}
};
} // namespace datatypes
} // namespace datatypes

View File

@ -15,32 +15,25 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
#pragma once
#include "genericparser.h"
#include "mcs_datatype.h"
namespace literal
{
using utils::ConstString;
using genericparser::Parser;
using datatypes::DataCondition;
using genericparser::Parser;
using utils::ConstString;
typedef uint32_t scale_t;
template<class A>
class Converter: public Parser,
public A
template <class A>
class Converter : public Parser, public A
{
public:
Converter(const char *str, size_t length, DataCondition & error)
:Parser(str, length),
A(&Parser::skipLeadingSpaces())
public:
Converter(const char* str, size_t length, DataCondition& error)
: Parser(str, length), A(&Parser::skipLeadingSpaces())
{
if (Parser::syntaxError())
{
@ -56,15 +49,14 @@ public:
'1e' - exponent marker was not followed by <exponent>, expect '1e1'
'1e+' - in <exponent>, <sign> was not followed by a digit, expect '1e+1'
*/
error|=(DataCondition::X_INVALID_CHARACTER_VALUE_FOR_CAST);
error |= (DataCondition::X_INVALID_CHARACTER_VALUE_FOR_CAST);
}
}
Converter(const std::string & str, DataCondition &error)
:Converter(str.data(), str.length(), error)
{ }
Converter(const std::string& str, DataCondition& error) : Converter(str.data(), str.length(), error)
{
}
};
/*
SQL Standard definition for <cast specification>
@ -143,70 +135,83 @@ Grammar
*/
//
// Terminal symbols
//
class Period: public ConstString
class Period : public ConstString
{
public:
explicit Period(Parser *p)
:ConstString(p->tokenChar('.'))
{ }
bool isNull() const { return mStr == nullptr; }
public:
explicit Period(Parser* p) : ConstString(p->tokenChar('.'))
{
}
bool isNull() const
{
return mStr == nullptr;
}
};
class ExponentMarker: public ConstString
class ExponentMarker : public ConstString
{
public:
explicit ExponentMarker(Parser *p)
:ConstString(p->tokenAnyCharOf('e', 'E'))
{ }
bool isNull() const { return mStr == nullptr; }
public:
explicit ExponentMarker(Parser* p) : ConstString(p->tokenAnyCharOf('e', 'E'))
{
}
bool isNull() const
{
return mStr == nullptr;
}
};
class Sign: public ConstString
class Sign : public ConstString
{
public:
explicit Sign(): ConstString(NULL, 0) { }
explicit Sign(const ConstString &str)
:ConstString(str)
{ }
explicit Sign(Parser *p)
:ConstString(p->tokenAnyCharOf('+', '-'))
{ }
static Sign empty(Parser *p)
public:
explicit Sign() : ConstString(NULL, 0)
{
}
explicit Sign(const ConstString& str) : ConstString(str)
{
}
explicit Sign(Parser* p) : ConstString(p->tokenAnyCharOf('+', '-'))
{
}
static Sign empty(Parser* p)
{
return Sign(p->tokStartConstString());
}
bool isNull() const { return mStr == nullptr; }
bool negative() const { return eq('-'); }
bool isNull() const
{
return mStr == nullptr;
}
bool negative() const
{
return eq('-');
}
};
class Digits: public ConstString
class Digits : public ConstString
{
public:
explicit Digits()
:ConstString(NULL, 0)
{ }
explicit Digits(const char *str, size_t length)
:ConstString(str, length)
{ }
explicit Digits(const ConstString &str)
:ConstString(str)
{ }
explicit Digits(Parser *p)
:ConstString(p->tokenDigits())
{ }
bool isNull() const { return mStr == nullptr; }
public:
explicit Digits() : ConstString(NULL, 0)
{
}
explicit Digits(const char* str, size_t length) : ConstString(str, length)
{
}
explicit Digits(const ConstString& str) : ConstString(str)
{
}
explicit Digits(Parser* p) : ConstString(p->tokenDigits())
{
}
bool isNull() const
{
return mStr == nullptr;
}
void skipLeadingZeroDigits()
{
for ( ; mLength > 0 && mStr[0] == '0'; )
for (; mLength > 0 && mStr[0] == '0';)
{
mStr++;
mLength--;
@ -214,33 +219,32 @@ public:
}
void skipTrailingZeroDigits()
{
for ( ; mLength > 0 && mStr[mLength - 1] == '0' ; )
for (; mLength > 0 && mStr[mLength - 1] == '0';)
mLength--;
}
};
//
// Non-terminal symbols
//
// <unsigned integer> ::= <digit> ...
class UnsignedInteger: public Digits
class UnsignedInteger : public Digits
{
public:
explicit UnsignedInteger()
:Digits()
{ }
explicit UnsignedInteger(const char *str, size_t length)
:Digits(str, length)
{ }
explicit UnsignedInteger(const ConstString &str)
:Digits(str)
{ }
explicit UnsignedInteger(Parser *p)
:Digits(p)
{ }
static UnsignedInteger empty(const Parser *p)
public:
explicit UnsignedInteger() : Digits()
{
}
explicit UnsignedInteger(const char* str, size_t length) : Digits(str, length)
{
}
explicit UnsignedInteger(const ConstString& str) : Digits(str)
{
}
explicit UnsignedInteger(Parser* p) : Digits(p)
{
}
static UnsignedInteger empty(const Parser* p)
{
return UnsignedInteger(p->tokStartConstString());
}
@ -249,182 +253,177 @@ public:
return UnsignedInteger(str(), length() > len ? len : length());
}
template<typename T>
T toXIntPositiveContinue(T start, DataCondition & error) const
template <typename T>
T toXIntPositiveContinue(T start, DataCondition& error) const
{
const char *e = end();
const char* e = end();
T val = start;
for (const char *s= mStr; s < e; s++)
for (const char* s = mStr; s < e; s++)
{
constexpr T cutoff = datatypes::numeric_limits<T>::max() / 10;
if (val > cutoff)
{
error|= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
error |= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
return datatypes::numeric_limits<T>::max();
}
val*= 10;
val *= 10;
T newval = val + (s[0] - '0');
if (newval < val)
{
error|= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
error |= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
return datatypes::numeric_limits<T>::max();
}
val = newval;
}
return val;
}
template<typename T>
T toXIntPositive(DataCondition & error) const
template <typename T>
T toXIntPositive(DataCondition& error) const
{
return toXIntPositiveContinue<T>(0, error);
}
template<typename T>
T toSIntNegativeContinue(T start, DataCondition & error) const
template <typename T>
T toSIntNegativeContinue(T start, DataCondition& error) const
{
const char *e = end();
const char* e = end();
T val = start;
for (const char *s= mStr; s < e; s++)
for (const char* s = mStr; s < e; s++)
{
constexpr T cutoff = datatypes::numeric_limits<T>::min() / 10;
if (val < cutoff)
{
error|= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
error |= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
return datatypes::numeric_limits<T>::min();
}
val*= 10;
val *= 10;
T newval = val - (s[0] - '0');
if (newval > val)
{
error|= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
error |= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
return datatypes::numeric_limits<T>::min();
}
val = newval;
}
return val;
}
template<typename T>
T toSIntNegative(DataCondition & error) const
template <typename T>
T toSIntNegative(DataCondition& error) const
{
return toSIntNegativeContinue<T>(0, error);
}
template<typename T>
T toXIntPositiveRoundAwayFromZeroContinue(T start, bool round, DataCondition & error) const
template <typename T>
T toXIntPositiveRoundAwayFromZeroContinue(T start, bool round, DataCondition& error) const
{
T val = toXIntPositiveContinue<T>(start, error);
if (val == datatypes::numeric_limits<T>::max() && round)
{
error|= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
error |= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
return val;
}
return val + round;
}
template<typename T>
T toXIntPositiveRoundAwayFromZero(bool round, DataCondition & error) const
template <typename T>
T toXIntPositiveRoundAwayFromZero(bool round, DataCondition& error) const
{
return toXIntPositiveRoundAwayFromZeroContinue<T>(0, round, error);
}
};
// <signed integer> := [<sign>] <unsigned integer>
class SignedInteger: public Parser::DD2OM<Sign,UnsignedInteger>
class SignedInteger : public Parser::DD2OM<Sign, UnsignedInteger>
{
public:
public:
using DD2OM::DD2OM;
bool isNull() const { return UnsignedInteger::isNull(); }
bool isNull() const
{
return UnsignedInteger::isNull();
}
template<typename T> T abs(DataCondition & error) const
template <typename T>
T abs(DataCondition& error) const
{
return toXIntPositive<T>(error);
}
template<typename T> T toSInt(DataCondition & error) const
template <typename T>
T toSInt(DataCondition& error) const
{
return negative() ?
toSIntNegative<T>(error) :
toXIntPositive<T>(error);
return negative() ? toSIntNegative<T>(error) : toXIntPositive<T>(error);
}
};
// E <signed integer>
class EExponent: public Parser::UD2MM<ExponentMarker, SignedInteger>
class EExponent : public Parser::UD2MM<ExponentMarker, SignedInteger>
{
public:
public:
using UD2MM::UD2MM;
};
// <period> <unsigned integer>
class ExactUnsignedNumericLiteralFractionAlone: public Parser::UD2MM<Period, UnsignedInteger>
class ExactUnsignedNumericLiteralFractionAlone : public Parser::UD2MM<Period, UnsignedInteger>
{
public:
public:
using UD2MM::UD2MM;
};
// <period> [ <unsigned integer> ]
class PeriodOptUnsignedInteger: public Parser::UD2MO<Period, UnsignedInteger>
class PeriodOptUnsignedInteger : public Parser::UD2MO<Period, UnsignedInteger>
{
public:
public:
using UD2MO::UD2MO;
static PeriodOptUnsignedInteger empty(Parser *p)
static PeriodOptUnsignedInteger empty(Parser* p)
{
return PeriodOptUnsignedInteger(UnsignedInteger(p->tokStartConstString()));
}
const PeriodOptUnsignedInteger & fraction() const
const PeriodOptUnsignedInteger& fraction() const
{
return *this;
}
};
// <integral unsigned integer> := <unsigned integer>
class IntegralUnsignedInteger: public UnsignedInteger
class IntegralUnsignedInteger : public UnsignedInteger
{
public:
explicit IntegralUnsignedInteger(Parser *p)
:UnsignedInteger(p)
{ }
const UnsignedInteger & integral() const
public:
explicit IntegralUnsignedInteger(Parser* p) : UnsignedInteger(p)
{
}
const UnsignedInteger& integral() const
{
return *this;
}
};
// <integral unsigned integer> [ <period> [ <unsigned integer> ] ]
class ExactUnsignedNumericLiteralIntegralOptFraction:
public Parser::DD2MO<IntegralUnsignedInteger,
PeriodOptUnsignedInteger>
class ExactUnsignedNumericLiteralIntegralOptFraction
: public Parser::DD2MO<IntegralUnsignedInteger, PeriodOptUnsignedInteger>
{
public:
public:
using DD2MO::DD2MO;
};
// A container for integral and fractional parts
class UnsignedIntegerDecimal
{
protected:
protected:
UnsignedInteger mIntegral;
UnsignedInteger mFraction;
public:
explicit UnsignedIntegerDecimal(const UnsignedInteger &intg,
const UnsignedInteger &frac)
:mIntegral(intg),
mFraction(frac)
{ }
explicit UnsignedIntegerDecimal(const ExactUnsignedNumericLiteralFractionAlone &rhs)
:mFraction(rhs)
{ }
explicit UnsignedIntegerDecimal(const ExactUnsignedNumericLiteralIntegralOptFraction &rhs)
:mIntegral(rhs.integral()),
mFraction(rhs.fraction())
{ }
public:
explicit UnsignedIntegerDecimal(const UnsignedInteger& intg, const UnsignedInteger& frac)
: mIntegral(intg), mFraction(frac)
{
}
explicit UnsignedIntegerDecimal(const ExactUnsignedNumericLiteralFractionAlone& rhs) : mFraction(rhs)
{
}
explicit UnsignedIntegerDecimal(const ExactUnsignedNumericLiteralIntegralOptFraction& rhs)
: mIntegral(rhs.integral()), mFraction(rhs.fraction())
{
}
size_t IntFracDigits() const
{
@ -442,51 +441,55 @@ public:
mFraction.skipTrailingZeroDigits();
}
template<typename T> T toXIntPositive(DataCondition & error) const
template <typename T>
T toXIntPositive(DataCondition& error) const
{
T val = mIntegral.toXIntPositive<T>(error);
return mFraction.toXIntPositiveContinue<T>(val, error);
}
template<typename T> T toXIntPositiveRoundAwayFromZero(bool roundUp, DataCondition & error) const
template <typename T>
T toXIntPositiveRoundAwayFromZero(bool roundUp, DataCondition& error) const
{
T val = mIntegral.toXIntPositive<T>(error);
return mFraction.toXIntPositiveRoundAwayFromZeroContinue<T>(val, roundUp, error);
}
template<typename T> T toXIntPositiveScaleUp(size_t scale, DataCondition & error) const
template <typename T>
T toXIntPositiveScaleUp(size_t scale, DataCondition& error) const
{
T val = toXIntPositive<T>(error);
if (val == datatypes::numeric_limits<T>::max())
return val;
for ( ; scale ; scale--)
for (; scale; scale--)
{
constexpr T cutoff = datatypes::numeric_limits<T>::max() / 10;
if (val > cutoff)
{
error|= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
error |= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
return datatypes::numeric_limits<T>::max();
}
val*= 10;
val *= 10;
}
return val;
}
template<typename T> T toXIntPositiveRound(DataCondition & error) const
template <typename T>
T toXIntPositiveRound(DataCondition& error) const
{
bool roundUp = mFraction.length() && mFraction.str()[0] >= '5';
return mIntegral.toXIntPositiveRoundAwayFromZero<T>(roundUp, error);
}
template<typename T> T toXIntPositiveRoundExp(uint64_t absExp, bool negExp,
DataCondition & error) const
template <typename T>
T toXIntPositiveRoundExp(uint64_t absExp, bool negExp, DataCondition& error) const
{
if (absExp == 0)
return toXIntPositiveRound<T>(error);
if (negExp)
{
if (mIntegral.length() == absExp) // 567.8e-3 -> 0.5678 -> 1
if (mIntegral.length() == absExp) // 567.8e-3 -> 0.5678 -> 1
return mIntegral.str()[0] >= '5' ? 1 : 0;
if (mIntegral.length() < absExp) // 123e-4 -> 0.0123
return 0;
@ -498,7 +501,7 @@ public:
}
// Positive exponent: 123.456e2
if (mFraction.length() >= absExp) // 123.456e2 -> 12345.6 -> 12346
if (mFraction.length() >= absExp) // 123.456e2 -> 12345.6 -> 12346
{
bool roundUp = mFraction.length() > absExp && mFraction.str()[absExp] >= '5';
UnsignedIntegerDecimal tmp(mIntegral, mFraction.left(absExp));
@ -509,42 +512,38 @@ public:
size_t diff = absExp - mFraction.length();
return toXIntPositiveScaleUp<T>(diff, error);
}
};
// <exact unsigned numeric literal> :=
// <period> [ <unsigned integer> ]
// | <unsigned integer> [ <period> [ <unsigned integer> ] ]
class ExactUnsignedNumericLiteral:
public Parser::Choice2<UnsignedIntegerDecimal,
ExactUnsignedNumericLiteralFractionAlone,
ExactUnsignedNumericLiteralIntegralOptFraction>
class ExactUnsignedNumericLiteral
: public Parser::Choice2<UnsignedIntegerDecimal, ExactUnsignedNumericLiteralFractionAlone,
ExactUnsignedNumericLiteralIntegralOptFraction>
{
public:
public:
using Choice2::Choice2;
};
// <unsigned numeric literal> ::= <exact numeric literal> [ E <exponent> ]
class UnsignedNumericLiteral: public Parser::DM2MO<ExactUnsignedNumericLiteral,EExponent>
class UnsignedNumericLiteral : public Parser::DM2MO<ExactUnsignedNumericLiteral, EExponent>
{
public:
public:
using DM2MO::DM2MO;
void normalize()
{
ExactUnsignedNumericLiteral::normalize();
mB.skipLeadingZeroDigits();
}
const SignedInteger & exponent() const
const SignedInteger& exponent() const
{
return mB;
}
template<typename T>
T toXIntPositiveRound(DataCondition & error) const
template <typename T>
T toXIntPositiveRound(DataCondition& error) const
{
size_t availableDigits = IntFracDigits();
if (!availableDigits)
@ -553,35 +552,36 @@ public:
return ExactUnsignedNumericLiteral::toXIntPositiveRoundExp<T>(absexp, exponent().negative(), error);
}
template<typename T>
T toPackedDecimalPositive(scale_t scale, DataCondition & error) const
template <typename T>
T toPackedDecimalPositive(scale_t scale, DataCondition& error) const
{
size_t availableDigits = IntFracDigits();
if (!availableDigits)
return 0;
int64_t exp = exponent().toSInt<int64_t>(error);
if (exp <= datatypes::numeric_limits<int64_t>::max() - scale)
exp+= scale;
exp += scale;
if (exp < 0)
{
if (exp == datatypes::numeric_limits<int64_t>::min())
exp++; // Avoid undefined behaviour in the unary minus below:
return ExactUnsignedNumericLiteral::toXIntPositiveRoundExp<T>((uint64_t) -exp, true, error);
exp++; // Avoid undefined behaviour in the unary minus below:
return ExactUnsignedNumericLiteral::toXIntPositiveRoundExp<T>((uint64_t)-exp, true, error);
}
return ExactUnsignedNumericLiteral::toXIntPositiveRoundExp<T>((uint64_t) exp, false, error);
return ExactUnsignedNumericLiteral::toXIntPositiveRoundExp<T>((uint64_t)exp, false, error);
}
};
// <signed numeric literal> ::= [ <sign> ] <unsigned numeric literal>
class SignedNumericLiteral: public Parser::DD2OM<Sign,UnsignedNumericLiteral>
class SignedNumericLiteral : public Parser::DD2OM<Sign, UnsignedNumericLiteral>
{
public:
public:
using DD2OM::DD2OM;
bool isNull() const { return UnsignedNumericLiteral::isNull(); }
bool isNull() const
{
return UnsignedNumericLiteral::isNull();
}
template<typename T>
template <typename T>
T toUIntXRound() const
{
if (negative())
@ -589,30 +589,28 @@ public:
return UnsignedNumericLiteral::toXIntPositiveRound<T>();
}
template<typename T>
T toPackedUDecimal(scale_t scale, DataCondition & error) const
template <typename T>
T toPackedUDecimal(scale_t scale, DataCondition& error) const
{
if (negative())
return 0;
return UnsignedNumericLiteral::toPackedDecimalPositive<T>(scale, error);
}
template<typename T>
T toPackedSDecimal(scale_t scale, DataCondition & error) const
template <typename T>
T toPackedSDecimal(scale_t scale, DataCondition& error) const
{
if (!negative())
return UnsignedNumericLiteral::toPackedDecimalPositive<T>(scale, error);
typedef typename datatypes::make_unsigned<T>::type UT;
UT absval = UnsignedNumericLiteral::toPackedDecimalPositive<UT>(scale, error);
if (absval >= (UT) datatypes::numeric_limits<T>::min())
if (absval >= (UT)datatypes::numeric_limits<T>::min())
{
error|= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
error |= DataCondition::X_NUMERIC_VALUE_OUT_OF_RANGE;
return datatypes::numeric_limits<T>::min();
}
return - (T) absval;
return -(T)absval;
}
};
} // namespace literal
} // namespace literal

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: altertable.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: altertable.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#define DDLPKG_DLLEXPORT
#include "ddlpkg.h"
@ -29,169 +29,139 @@ namespace ddlpackage
{
using namespace std;
AlterTableStatement::AlterTableStatement(QualifiedName* qName, AlterTableActionList* ataList):
fTableName(qName),
fActions(*ataList)
AlterTableStatement::AlterTableStatement(QualifiedName* qName, AlterTableActionList* ataList)
: fTableName(qName), fActions(*ataList)
{
delete ataList;
delete ataList;
}
AlterTableStatement::~AlterTableStatement()
{
delete fTableName;
AlterTableActionList::iterator itr;
delete fTableName;
AlterTableActionList::iterator itr;
for (itr = fActions.begin(); itr != fActions.end(); ++itr)
{
delete *itr;
}
for (itr = fActions.begin(); itr != fActions.end(); ++itr)
{
delete *itr;
}
}
std::ostream& AlterTableStatement::put(std::ostream& os) const
{
AlterTableActionList::const_iterator itr;
os << "Alter Table " << *fTableName << endl;
AlterTableActionList::const_iterator itr;
os << "Alter Table " << *fTableName << endl;
for (itr = fActions.begin(); itr != fActions.end(); ++itr)
{
os << **itr << endl;
}
for (itr = fActions.begin(); itr != fActions.end(); ++itr)
{
os << **itr << endl;
}
return os;
return os;
}
/** @brief Format to ostream. Diagnostic. */
std::ostream& AlterTableAction::put(std::ostream& os) const
{
os << "AlterTableAction put stub";
return os;
os << "AlterTableAction put stub";
return os;
}
/** @brief Invokes the virtual function put, to dispatch to subclass
ostream writers. */
ostream writers. */
std::ostream& operator<<(std::ostream& os, const AlterTableAction& ata)
{
return ata.put(os);
return ata.put(os);
}
AtaAddColumn::~AtaAddColumn()
{
delete fColumnDef;
delete fColumnDef;
}
/** @brief ostream output */
std::ostream& AtaAddColumn::put(std::ostream& os) const
{
os << "Add Column" << endl;
os << *fColumnDef << endl;
return os;
os << "Add Column" << endl;
os << *fColumnDef << endl;
return os;
}
AtaDropColumn::AtaDropColumn(std::string columnName, DDL_REFERENTIAL_ACTION dropBehavior) :
fColumnName(columnName),
fDropBehavior(dropBehavior)
AtaDropColumn::AtaDropColumn(std::string columnName, DDL_REFERENTIAL_ACTION dropBehavior)
: fColumnName(columnName), fDropBehavior(dropBehavior)
{
}
std::ostream& AtaDropColumn::put(std::ostream& os) const
{
os << "Drop Column: " << fColumnName << " "
<< ReferentialActionStrings[fDropBehavior];
return os;
os << "Drop Column: " << fColumnName << " " << ReferentialActionStrings[fDropBehavior];
return os;
}
AtaModifyColumnType::~AtaModifyColumnType()
{
delete fColumnType;
delete fColumnType;
}
std::ostream& AtaModifyColumnType::put(std::ostream& os) const
{
os << "Modify column type: " << fName << " " << *fColumnType;
os << "Modify column type: " << fName << " " << *fColumnType;
return os;
return os;
}
AtaRenameColumn::~AtaRenameColumn()
{
delete fNewType;
delete fNewType;
}
std::ostream& AtaRenameColumn::put(std::ostream& os) const
{
os << "Rename Column: " << fName << " -> " << fNewName << " (" << *fNewType << ')';
return os;
os << "Rename Column: " << fName << " -> " << fNewName << " (" << *fNewType << ')';
return os;
}
AtaSetColumnDefault::AtaSetColumnDefault(const char* colName, ColumnDefaultValue* defaultValue) :
fColumnName(colName),
fDefaultValue(defaultValue)
AtaSetColumnDefault::AtaSetColumnDefault(const char* colName, ColumnDefaultValue* defaultValue)
: fColumnName(colName), fDefaultValue(defaultValue)
{
}
AtaSetColumnDefault::~AtaSetColumnDefault()
{
delete fDefaultValue;
delete fDefaultValue;
}
std::ostream& AtaSetColumnDefault::put(std::ostream& os) const
{
os << "Set Column Default: " << fColumnName << " "
<< *fDefaultValue << endl;
return os;
os << "Set Column Default: " << fColumnName << " " << *fDefaultValue << endl;
return os;
}
AtaDropColumnDefault::AtaDropColumnDefault(const char* colName) :
fColumnName(colName)
AtaDropColumnDefault::AtaDropColumnDefault(const char* colName) : fColumnName(colName)
{
}
std::ostream& AtaDropColumnDefault::put(std::ostream& os) const
{
os << "Drop Column Default: " << fColumnName << " ";
return os;
os << "Drop Column Default: " << fColumnName << " ";
return os;
}
AtaRenameTable::AtaRenameTable(QualifiedName* qualifiedName) :
fQualifiedName(qualifiedName)
AtaRenameTable::AtaRenameTable(QualifiedName* qualifiedName) : fQualifiedName(qualifiedName)
{
}
AtaRenameTable::~AtaRenameTable()
{
delete fQualifiedName;
delete fQualifiedName;
}
std::ostream& AtaRenameTable::put(std::ostream& os) const
{
os << "Rename Table: " << *fQualifiedName << endl;
return os;
os << "Rename Table: " << *fQualifiedName << endl;
return os;
}
AtaTableComment::AtaTableComment(const char* tableComment) :
fTableComment(tableComment)
AtaTableComment::AtaTableComment(const char* tableComment) : fTableComment(tableComment)
{
}
@ -199,61 +169,54 @@ AtaTableComment::~AtaTableComment()
{
}
std::ostream& AtaTableComment::put(std::ostream& os) const
{
os << "TableComment: " << fTableComment << endl;
return os;
os << "TableComment: " << fTableComment << endl;
return os;
}
AtaAddColumns::~AtaAddColumns()
{
ColumnDefList::iterator itr;
ColumnDefList::iterator itr;
for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
delete *itr;
for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
delete *itr;
}
AtaAddColumns::AtaAddColumns(TableElementList* tableElements)
{
/* It is convenient to reuse the grammar rules for
table_element_list, and we do. So, it is possible for
there to be errant table constraint defs in the input list.
We ignore them. That is all we are doing here.
*/
ColumnDef* column;
TableElementList::const_iterator itr;
/* It is convenient to reuse the grammar rules for
table_element_list, and we do. So, it is possible for
there to be errant table constraint defs in the input list.
We ignore them. That is all we are doing here.
*/
ColumnDef* column;
TableElementList::const_iterator itr;
for (itr = tableElements->begin();
itr != tableElements->end();
++itr)
for (itr = tableElements->begin(); itr != tableElements->end(); ++itr)
{
column = dynamic_cast<ColumnDef*>(*itr);
if (0 != column)
{
column = dynamic_cast<ColumnDef*>(*itr);
if (0 != column)
{
fColumns.push_back(column);
}
fColumns.push_back(column);
}
}
delete tableElements;
delete tableElements;
}
std::ostream& AtaAddColumns::put(std::ostream& os) const
{
os << "Add Columns: " << endl;
ColumnDefList::const_iterator itr;
os << "Add Columns: " << endl;
ColumnDefList::const_iterator itr;
for (itr = fColumns.begin();
itr != fColumns.end();
++itr)
{
os << **itr << endl;
}
for (itr = fColumns.begin(); itr != fColumns.end(); ++itr)
{
os << **itr << endl;
}
return os;
return os;
}
//////////////////////////
@ -261,63 +224,52 @@ AtaDropColumns::~AtaDropColumns()
{
}
AtaDropColumns::AtaDropColumns(ColumnNameList* columnNames)
{
fColumns = *columnNames;
delete columnNames;
fColumns = *columnNames;
delete columnNames;
}
std::ostream& AtaDropColumns::put(std::ostream& os) const
{
os << "Drop Columns: " << endl;
ColumnNameList::const_iterator itr;
os << "Drop Columns: " << endl;
ColumnNameList::const_iterator itr;
for (itr = fColumns.begin();
itr != fColumns.end();
++itr)
{
os << *itr << endl;
}
for (itr = fColumns.begin(); itr != fColumns.end(); ++itr)
{
os << *itr << endl;
}
return os;
return os;
}
AtaAddTableConstraint::AtaAddTableConstraint(TableConstraintDef* tableConstraint) :
fTableConstraint(tableConstraint)
AtaAddTableConstraint::AtaAddTableConstraint(TableConstraintDef* tableConstraint)
: fTableConstraint(tableConstraint)
{
}
AtaAddTableConstraint::~AtaAddTableConstraint()
{
delete fTableConstraint;
delete fTableConstraint;
}
std::ostream& AtaAddTableConstraint::put(std::ostream& os) const
{
os << "Add Table Constraint:" << endl;
os << *fTableConstraint << endl;
return os;
os << "Add Table Constraint:" << endl;
os << *fTableConstraint << endl;
return os;
}
AtaDropTableConstraint::AtaDropTableConstraint
(const char* constraintName, DDL_REFERENTIAL_ACTION dropBehavior) :
fConstraintName(constraintName),
fDropBehavior(dropBehavior)
AtaDropTableConstraint::AtaDropTableConstraint(const char* constraintName,
DDL_REFERENTIAL_ACTION dropBehavior)
: fConstraintName(constraintName), fDropBehavior(dropBehavior)
{
}
std::ostream& AtaDropTableConstraint::put(std::ostream& os) const
{
os << "Drop Table Constraint: " << fConstraintName;
return os;
os << "Drop Table Constraint: " << fConstraintName;
return os;
}
}
} // namespace ddlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: columndef.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: columndef.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include <iostream>
#include <iomanip>
@ -30,131 +30,113 @@
namespace ddlpackage
{
using namespace std;
ColumnDef::~ColumnDef()
{
delete fType;
delete fDefaultValue;
ColumnConstraintList::iterator itr;
delete fType;
delete fDefaultValue;
ColumnConstraintList::iterator itr;
for (itr = fConstraints.begin(); itr != fConstraints.end(); ++itr)
{
delete *itr;
}
for (itr = fConstraints.begin(); itr != fConstraints.end(); ++itr)
{
delete *itr;
}
}
ColumnDef::ColumnDef(const char* name, ColumnType* columnType, ColumnConstraintList* constraints,
ColumnDefaultValue* defaultValue, const char* comment ) :
SchemaObject(name),
fType(columnType),
fDefaultValue(defaultValue)
ColumnDefaultValue* defaultValue, const char* comment)
: SchemaObject(name), fType(columnType), fDefaultValue(defaultValue)
{
if (constraints)
{
fConstraints = *constraints;
delete constraints;
}
if (constraints)
{
fConstraints = *constraints;
delete constraints;
}
if ( comment )
fComment = comment;
if (comment)
fComment = comment;
}
ostream& operator<<(ostream& os, const ColumnType& columnType)
{
os << setw(12) << left << DDLDatatypeString[columnType.fType]
<< "["
<< "L=" << setw(2) << columnType.fLength << ","
<< "P=" << setw(2) << columnType.fPrecision << ","
<< "S=" << setw(2) << columnType.fScale << ","
<< "T=" << setw(2) << columnType.fWithTimezone
<< "]";
return os;
os << setw(12) << left << DDLDatatypeString[columnType.fType] << "["
<< "L=" << setw(2) << columnType.fLength << ","
<< "P=" << setw(2) << columnType.fPrecision << ","
<< "S=" << setw(2) << columnType.fScale << ","
<< "T=" << setw(2) << columnType.fWithTimezone << "]";
return os;
}
ostream& operator<<(ostream& os, const ColumnDef& column)
{
os << "Column: " << column.fName << " " << *column.fType;
os << "Column: " << column.fName << " " << *column.fType;
if (column.fDefaultValue)
{
os << " def=";
if (column.fDefaultValue)
{
os << " def=";
if (column.fDefaultValue->fNull)
os << "NULL";
else
os << column.fDefaultValue->fValue;
}
if (column.fDefaultValue->fNull)
os << "NULL";
else
os << column.fDefaultValue->fValue;
}
os << endl << " " << column.fConstraints.size()
<< " constraints ";
os << endl << " " << column.fConstraints.size() << " constraints ";
ColumnConstraintList::const_iterator itr;
ColumnConstraintList::const_iterator itr;
for (itr = column.fConstraints.begin();
itr != column.fConstraints.end();
++itr)
{
ColumnConstraintDef* con = *itr;
os << *con;
}
for (itr = column.fConstraints.begin(); itr != column.fConstraints.end(); ++itr)
{
ColumnConstraintDef* con = *itr;
os << *con;
}
return os;
return os;
}
ostream& operator<<(ostream& os, const ColumnConstraintDef& con)
{
os << " Constraint: "
<< con.fName << " "
<< ConstraintString[con.fConstraintType] << " "
<< "defer=" << con.fDeferrable << " "
<< ConstraintAttrStrings[con.fCheckTime] << " ";
os << " Constraint: " << con.fName << " " << ConstraintString[con.fConstraintType] << " "
<< "defer=" << con.fDeferrable << " " << ConstraintAttrStrings[con.fCheckTime] << " ";
if (!con.fCheck.empty())
os << "check=" << "\"" << con.fCheck << "\"";
if (!con.fCheck.empty())
os << "check="
<< "\"" << con.fCheck << "\"";
return os;
return os;
}
std::ostream& operator<<(std::ostream& os, const ColumnDefList& clist)
{
ColumnDefList::const_iterator itr;
ColumnDefList::const_iterator itr;
for (itr = clist.begin(); itr != clist.end(); ++itr)
{
os << **itr;
}
for (itr = clist.begin(); itr != clist.end(); ++itr)
{
os << **itr;
}
return os;
return os;
}
ColumnDefaultValue::ColumnDefaultValue(const char* value) :
fNull(false)
ColumnDefaultValue::ColumnDefaultValue(const char* value) : fNull(false)
{
if (0 == value)
fNull = true;
else
fValue = value;
if (0 == value)
fNull = true;
else
fValue = value;
}
std::ostream& operator<<(std::ostream& os, const ColumnDefaultValue& defaultValue)
{
os << " def=";
os << " def=";
if (defaultValue.fNull)
os << "NULL";
else
os << defaultValue.fValue;
if (defaultValue.fNull)
os << "NULL";
else
os << defaultValue.fValue;
return os;
return os;
}
}
} // namespace ddlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: createindex.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: createindex.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include "ddlpkg.h"
@ -27,35 +27,28 @@ namespace ddlpackage
{
using namespace std;
CreateIndexStatement::CreateIndexStatement():
fIndexName(NULL),
fTableName(NULL),
fColumnNames(),
fUnique(false)
CreateIndexStatement::CreateIndexStatement()
: fIndexName(NULL), fTableName(NULL), fColumnNames(), fUnique(false)
{
}
CreateIndexStatement::CreateIndexStatement(QualifiedName* indexName, QualifiedName* tableName,
ColumnNameList* columnNames, bool unique) :
fIndexName(indexName),
fTableName(tableName),
fColumnNames(*columnNames),
fUnique(unique)
ColumnNameList* columnNames, bool unique)
: fIndexName(indexName), fTableName(tableName), fColumnNames(*columnNames), fUnique(unique)
{
delete columnNames;
delete columnNames;
}
CreateIndexStatement::~CreateIndexStatement()
{
delete fIndexName;
delete fTableName;
delete fIndexName;
delete fTableName;
}
std::ostream& CreateIndexStatement::put(std::ostream& os) const
{
os << "Create Index: " << *fIndexName << " on " << *fTableName
<< fColumnNames << endl;
return os;
os << "Create Index: " << *fIndexName << " on " << *fTableName << fColumnNames << endl;
return os;
}
}
} // namespace ddlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: createtable.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: createtable.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include <iostream>
@ -29,33 +29,28 @@
namespace ddlpackage
{
using namespace std;
CreateTableStatement::CreateTableStatement() :
fTableDef(0)
CreateTableStatement::CreateTableStatement() : fTableDef(0)
{
}
CreateTableStatement::CreateTableStatement(TableDef* tableDef) :
fTableDef(tableDef)
CreateTableStatement::CreateTableStatement(TableDef* tableDef) : fTableDef(tableDef)
{
}
CreateTableStatement::~CreateTableStatement()
{
if (fTableDef)
{
delete fTableDef;
}
if (fTableDef)
{
delete fTableDef;
}
}
/** \brief Put to ostream. */
ostream& CreateTableStatement::put(ostream& os) const
{
os << "CreateTable "
<< *fTableDef;
return os;
}
os << "CreateTable " << *fTableDef;
return os;
}
} // namespace ddlpackage

File diff suppressed because it is too large Load Diff

View File

@ -32,141 +32,132 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#pragma once
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype
{
ACTION = 258,
ADD = 259,
ALTER = 260,
AUTO_INCREMENT = 261,
BIGINT = 262,
BIT = 263,
IDB_BLOB = 264,
CASCADE = 265,
IDB_CHAR = 266,
CHARACTER = 267,
CHECK = 268,
CLOB = 269,
COLUMN = 270,
COLUMNS = 271,
COMMENT = 272,
CONSTRAINT = 273,
CONSTRAINTS = 274,
CREATE = 275,
CURRENT_USER = 276,
DATETIME = 277,
DEC = 278,
DECIMAL = 279,
DEFAULT = 280,
DEFERRABLE = 281,
DEFERRED = 282,
IDB_DELETE = 283,
DROP = 284,
ENGINE = 285,
FOREIGN = 286,
FULL = 287,
IMMEDIATE = 288,
INDEX = 289,
INITIALLY = 290,
IDB_INT = 291,
INTEGER = 292,
KEY = 293,
MATCH = 294,
MAX_ROWS = 295,
MIN_ROWS = 296,
MODIFY = 297,
NO = 298,
NOT = 299,
NULL_TOK = 300,
NUMBER = 301,
NUMERIC = 302,
ON = 303,
PARTIAL = 304,
PRECISION = 305,
PRIMARY = 306,
REFERENCES = 307,
RENAME = 308,
RESTRICT = 309,
SET = 310,
SMALLINT = 311,
TABLE = 312,
TIME = 313,
TINYINT = 314,
TO = 315,
UNIQUE = 316,
UNSIGNED = 317,
UPDATE = 318,
USER = 319,
SESSION_USER = 320,
SYSTEM_USER = 321,
VARCHAR = 322,
VARBINARY = 323,
VARYING = 324,
WITH = 325,
ZONE = 326,
DOUBLE = 327,
IDB_FLOAT = 328,
REAL = 329,
CHARSET = 330,
IDB_IF = 331,
EXISTS = 332,
CHANGE = 333,
TRUNCATE = 334,
IDENT = 335,
FCONST = 336,
SCONST = 337,
CP_SEARCH_CONDITION_TEXT = 338,
ICONST = 339,
DATE = 340
ACTION = 258,
ADD = 259,
ALTER = 260,
AUTO_INCREMENT = 261,
BIGINT = 262,
BIT = 263,
IDB_BLOB = 264,
CASCADE = 265,
IDB_CHAR = 266,
CHARACTER = 267,
CHECK = 268,
CLOB = 269,
COLUMN = 270,
COLUMNS = 271,
COMMENT = 272,
CONSTRAINT = 273,
CONSTRAINTS = 274,
CREATE = 275,
CURRENT_USER = 276,
DATETIME = 277,
DEC = 278,
DECIMAL = 279,
DEFAULT = 280,
DEFERRABLE = 281,
DEFERRED = 282,
IDB_DELETE = 283,
DROP = 284,
ENGINE = 285,
FOREIGN = 286,
FULL = 287,
IMMEDIATE = 288,
INDEX = 289,
INITIALLY = 290,
IDB_INT = 291,
INTEGER = 292,
KEY = 293,
MATCH = 294,
MAX_ROWS = 295,
MIN_ROWS = 296,
MODIFY = 297,
NO = 298,
NOT = 299,
NULL_TOK = 300,
NUMBER = 301,
NUMERIC = 302,
ON = 303,
PARTIAL = 304,
PRECISION = 305,
PRIMARY = 306,
REFERENCES = 307,
RENAME = 308,
RESTRICT = 309,
SET = 310,
SMALLINT = 311,
TABLE = 312,
TIME = 313,
TINYINT = 314,
TO = 315,
UNIQUE = 316,
UNSIGNED = 317,
UPDATE = 318,
USER = 319,
SESSION_USER = 320,
SYSTEM_USER = 321,
VARCHAR = 322,
VARBINARY = 323,
VARYING = 324,
WITH = 325,
ZONE = 326,
DOUBLE = 327,
IDB_FLOAT = 328,
REAL = 329,
CHARSET = 330,
IDB_IF = 331,
EXISTS = 332,
CHANGE = 333,
TRUNCATE = 334,
IDENT = 335,
FCONST = 336,
SCONST = 337,
CP_SEARCH_CONDITION_TEXT = 338,
ICONST = 339,
DATE = 340
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
ddlpackage::AlterTableStatement* alterTableStmt;
ddlpackage::AlterTableAction* ata;
ddlpackage::AlterTableActionList* ataList;
ddlpackage::DDL_CONSTRAINT_ATTRIBUTES cattr;
std::pair<std::string, std::string>* tableOption;
const char* columnOption;
ddlpackage::ColumnConstraintDef* columnConstraintDef;
ddlpackage::ColumnNameList* columnNameList;
ddlpackage::ColumnType* columnType;
ddlpackage::ConstraintAttributes* constraintAttributes;
ddlpackage::ColumnConstraintList* constraintList;
ddlpackage::DDL_CONSTRAINTS constraintType;
double dval;
bool flag;
int ival;
ddlpackage::QualifiedName* qualifiedName;
ddlpackage::SchemaObject* schemaObject;
ddlpackage::SqlStatement* sqlStmt;
ddlpackage::SqlStatementList* sqlStmtList;
const char* str;
ddlpackage::TableConstraintDef* tableConstraint;
ddlpackage::TableElementList* tableElementList;
ddlpackage::TableOptionMap* tableOptionMap;
ddlpackage::ColumnDefaultValue* colDefault;
ddlpackage::DDL_MATCH_TYPE matchType;
ddlpackage::DDL_REFERENTIAL_ACTION refActionCode;
ddlpackage::ReferentialAction* refAction;
ddlpackage::AlterTableStatement* alterTableStmt;
ddlpackage::AlterTableAction* ata;
ddlpackage::AlterTableActionList* ataList;
ddlpackage::DDL_CONSTRAINT_ATTRIBUTES cattr;
std::pair<std::string, std::string>* tableOption;
const char* columnOption;
ddlpackage::ColumnConstraintDef* columnConstraintDef;
ddlpackage::ColumnNameList* columnNameList;
ddlpackage::ColumnType* columnType;
ddlpackage::ConstraintAttributes* constraintAttributes;
ddlpackage::ColumnConstraintList* constraintList;
ddlpackage::DDL_CONSTRAINTS constraintType;
double dval;
bool flag;
int ival;
ddlpackage::QualifiedName* qualifiedName;
ddlpackage::SchemaObject* schemaObject;
ddlpackage::SqlStatement* sqlStmt;
ddlpackage::SqlStatementList* sqlStmtList;
const char* str;
ddlpackage::TableConstraintDef* tableConstraint;
ddlpackage::TableElementList* tableElementList;
ddlpackage::TableOptionMap* tableOptionMap;
ddlpackage::ColumnDefaultValue* colDefault;
ddlpackage::DDL_MATCH_TYPE matchType;
ddlpackage::DDL_REFERENTIAL_ACTION refActionCode;
ddlpackage::ReferentialAction* refAction;
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#define YYSTYPE_IS_TRIVIAL 1
#define yystype YYSTYPE /* obsolescent; will be withdrawn */
#define YYSTYPE_IS_DECLARED 1
extern YYSTYPE ddllval;

File diff suppressed because it is too large Load Diff

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: ddlpkg.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: ddlpkg.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include <iostream>
@ -32,167 +32,135 @@ namespace ddlpackage
{
using namespace std;
QualifiedName::QualifiedName(const char* name):
fName(name)
QualifiedName::QualifiedName(const char* name) : fName(name)
{
}
QualifiedName::QualifiedName(const char* schema, const char* name):
fName(name),
fSchema(schema)
QualifiedName::QualifiedName(const char* schema, const char* name) : fName(name), fSchema(schema)
{
}
QualifiedName::QualifiedName(const char* catalog, const char* schema, const char* name):
fCatalog(catalog),
fName(name),
fSchema(schema)
QualifiedName::QualifiedName(const char* catalog, const char* schema, const char* name)
: fCatalog(catalog), fName(name), fSchema(schema)
{
}
ostream& operator<<(ostream& os, const QualifiedName& qname)
{
if (!qname.fCatalog.empty())
os << qname.fCatalog << ".";
if (!qname.fCatalog.empty())
os << qname.fCatalog << ".";
if (!qname.fSchema.empty())
os << qname.fSchema << ".";
if (!qname.fSchema.empty())
os << qname.fSchema << ".";
os << qname.fName;
return os;
os << qname.fName;
return os;
}
ColumnType::ColumnType(int prec, int scale) :
fType(DDL_INVALID_DATATYPE),
fLength(0),
fPrecision(prec),
fScale(scale),
fWithTimezone(false),
fCharset(NULL),
fExplicitLength(false)
ColumnType::ColumnType(int prec, int scale)
: fType(DDL_INVALID_DATATYPE)
, fLength(0)
, fPrecision(prec)
, fScale(scale)
, fWithTimezone(false)
, fCharset(NULL)
, fExplicitLength(false)
{
fLength = utils::widthByPrecision(fPrecision);
fLength = utils::widthByPrecision(fPrecision);
}
ColumnType::ColumnType(int type) :
fType(type),
fLength(0),
fScale(0),
fWithTimezone(false),
fCharset(NULL),
fExplicitLength(false)
ColumnType::ColumnType(int type)
: fType(type), fLength(0), fScale(0), fWithTimezone(false), fCharset(NULL), fExplicitLength(false)
{
switch ( type )
{
case DDL_TINYINT:
case DDL_UNSIGNED_TINYINT:
fPrecision = 3;
break;
switch (type)
{
case DDL_TINYINT:
case DDL_UNSIGNED_TINYINT: fPrecision = 3; break;
case DDL_SMALLINT:
case DDL_UNSIGNED_SMALLINT:
fPrecision = 5;
break;
case DDL_SMALLINT:
case DDL_UNSIGNED_SMALLINT: fPrecision = 5; break;
case DDL_MEDINT:
fPrecision = 7;
break;
case DDL_MEDINT: fPrecision = 7; break;
case DDL_UNSIGNED_MEDINT:
fPrecision = 8;
break;
case DDL_UNSIGNED_MEDINT: fPrecision = 8; break;
case DDL_INT:
case DDL_UNSIGNED_INT:
fPrecision = 10;
break;
case DDL_INT:
case DDL_UNSIGNED_INT: fPrecision = 10; break;
case DDL_BIGINT:
fPrecision = 19;
break;
case DDL_BIGINT: fPrecision = 19; break;
case DDL_UNSIGNED_BIGINT:
fPrecision = 20;
break;
case DDL_UNSIGNED_BIGINT: fPrecision = 20; break;
default:
fPrecision = 10;
break;
}
default: fPrecision = 10; break;
}
}
ColumnConstraintDef::ColumnConstraintDef(DDL_CONSTRAINTS type) :
SchemaObject(),
fDeferrable(false),
fCheckTime(DDL_INITIALLY_IMMEDIATE),
fConstraintType(type),
fCheck("")
ColumnConstraintDef::ColumnConstraintDef(DDL_CONSTRAINTS type)
: SchemaObject(), fDeferrable(false), fCheckTime(DDL_INITIALLY_IMMEDIATE), fConstraintType(type), fCheck("")
{
}
ColumnConstraintDef::ColumnConstraintDef(const char* check) :
SchemaObject(),
fDeferrable(false),
fCheckTime(DDL_INITIALLY_IMMEDIATE),
fConstraintType(DDL_CHECK),
fCheck(check)
ColumnConstraintDef::ColumnConstraintDef(const char* check)
: SchemaObject()
, fDeferrable(false)
, fCheckTime(DDL_INITIALLY_IMMEDIATE)
, fConstraintType(DDL_CHECK)
, fCheck(check)
{
}
AtaAddColumn::AtaAddColumn(ColumnDef* columnDef) :
fColumnDef(columnDef)
AtaAddColumn::AtaAddColumn(ColumnDef* columnDef) : fColumnDef(columnDef)
{
}
ostream& operator<<(ostream& os, const ReferentialAction& ref)
{
os << "ref action: u=" << ReferentialActionStrings[ref.fOnUpdate] << " "
<< "d=" << ReferentialActionStrings[ref.fOnDelete];
return os;
os << "ref action: u=" << ReferentialActionStrings[ref.fOnUpdate] << " "
<< "d=" << ReferentialActionStrings[ref.fOnDelete];
return os;
}
void ColumnDef::convertDecimal()
{
//@Bug 2089 decimal precision default to 10 if 0 is used.
if (fType->fPrecision <= 0)
fType->fPrecision = 10;
//@Bug 2089 decimal precision default to 10 if 0 is used.
if (fType->fPrecision <= 0)
fType->fPrecision = 10;
if (fType->fPrecision == -1 || fType->fPrecision == 0)
{
fType->fType = DDL_BIGINT;
fType->fLength = 8;
fType->fScale = 0;
}
else if ((fType->fPrecision > 0) && (fType->fPrecision < 3))
{
fType->fType = DDL_TINYINT;
fType->fLength = 1;
}
if (fType->fPrecision == -1 || fType->fPrecision == 0)
{
fType->fType = DDL_BIGINT;
fType->fLength = 8;
fType->fScale = 0;
}
else if ((fType->fPrecision > 0) && (fType->fPrecision < 3))
{
fType->fType = DDL_TINYINT;
fType->fLength = 1;
}
else if (fType->fPrecision < 5 && (fType->fPrecision > 2))
{
fType->fType = DDL_SMALLINT;
fType->fLength = 2;
}
else if (fType->fPrecision > 4 && fType->fPrecision < 7)
{
fType->fType = DDL_MEDINT;
fType->fLength = 4;
}
else if (fType->fPrecision > 6 && fType->fPrecision < 10)
{
fType->fType = DDL_INT;
fType->fLength = 4;
}
else if (fType->fPrecision > 9 && fType->fPrecision < 19)
{
fType->fType = DDL_BIGINT;
fType->fLength = 8;
}
else if (fType->fPrecision > 18 && fType->fPrecision < 39)
{
fType->fType = DDL_DECIMAL;
fType->fLength = 16;
}
else if (fType->fPrecision < 5 && (fType->fPrecision > 2))
{
fType->fType = DDL_SMALLINT;
fType->fLength = 2;
}
else if (fType->fPrecision > 4 && fType->fPrecision < 7)
{
fType->fType = DDL_MEDINT;
fType->fLength = 4;
}
else if (fType->fPrecision > 6 && fType->fPrecision < 10)
{
fType->fType = DDL_INT;
fType->fLength = 4;
}
else if (fType->fPrecision > 9 && fType->fPrecision < 19)
{
fType->fType = DDL_BIGINT;
fType->fLength = 8;
}
else if (fType->fPrecision > 18 && fType->fPrecision < 39)
{
fType->fType = DDL_DECIMAL;
fType->fLength = 16;
}
}
} // end of namespace
} // namespace ddlpackage

File diff suppressed because it is too large Load Diff

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: dropindex.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: dropindex.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include "ddlpkg.h"
@ -29,18 +29,17 @@ using namespace std;
DropIndexStatement::~DropIndexStatement()
{
delete fIndexName;
delete fIndexName;
}
DropIndexStatement::DropIndexStatement(QualifiedName* qualifiedName) :
fIndexName(qualifiedName)
DropIndexStatement::DropIndexStatement(QualifiedName* qualifiedName) : fIndexName(qualifiedName)
{
}
std::ostream& DropIndexStatement::put(std::ostream& os) const
{
os << "Drop Index: " << *fIndexName << endl;
return os;
os << "Drop Index: " << *fIndexName << endl;
return os;
}
}
} // namespace ddlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: markpartition.cpp 6566 2010-04-27 18:02:51Z rdempsey $
*
*
***********************************************************************/
* $Id: markpartition.cpp 6566 2010-04-27 18:02:51Z rdempsey $
*
*
***********************************************************************/
#define DDLPKG_DLLEXPORT
#include "ddlpkg.h"
@ -29,23 +29,21 @@ using namespace std;
namespace ddlpackage
{
DropPartitionStatement::DropPartitionStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName)
DropPartitionStatement::DropPartitionStatement(QualifiedName* qualifiedName) : fTableName(qualifiedName)
{
}
ostream& DropPartitionStatement::put(ostream& os) const
{
os << "Mark partitions out of service: " << *fTableName << endl;
os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it;
os << "Mark partitions out of service: " << *fTableName << endl;
os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it;
for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
os << (*it) << " ";
for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
os << (*it) << " ";
os << endl;
return os;
os << endl;
return os;
}
}
} // namespace ddlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: droptable.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: droptable.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#define DDLPKG_DLLEXPORT
#include "ddlpkg.h"
@ -29,28 +29,26 @@ using namespace std;
namespace ddlpackage
{
DropTableStatement::DropTableStatement(QualifiedName* qualifiedName, bool cascade) :
fTableName(qualifiedName),
fCascade(cascade)
DropTableStatement::DropTableStatement(QualifiedName* qualifiedName, bool cascade)
: fTableName(qualifiedName), fCascade(cascade)
{
}
ostream& DropTableStatement::put(ostream& os) const
{
os << "Drop Table: " << *fTableName << " " << "C=" << fCascade << endl;
return os;
os << "Drop Table: " << *fTableName << " "
<< "C=" << fCascade << endl;
return os;
}
TruncTableStatement::TruncTableStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName)
TruncTableStatement::TruncTableStatement(QualifiedName* qualifiedName) : fTableName(qualifiedName)
{
}
ostream& TruncTableStatement::put(ostream& os) const
{
os << "Truncate Table: " << *fTableName << endl;
return os;
os << "Truncate Table: " << *fTableName << endl;
return os;
}
}
} // namespace ddlpackage

View File

@ -31,48 +31,47 @@ namespace po = boost::program_options;
int main(int argc, char* argv[])
{
string sqlfile;
int count;
string sqlfile;
int count;
po::options_description desc ("Allowed options");
desc.add_options ()
("help", "produce help message")
("bisond", /* po::value <string>(),*/ "Have bison produce debug output")
("count", po::value <int>(), "number of runs")
("sql", po::value < string > (), "sql file");
po::variables_map vm;
po::store (po::parse_command_line (argc, argv, desc), vm);
po::notify (vm);
po::options_description desc("Allowed options");
desc.add_options()("help", "produce help message")(
"bisond",
/* po::value <string>(),*/ "Have bison produce debug output")("count", po::value<int>(),
"number of runs")("sql",
po::value<string>(),
"sql file");
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count ("sql"))
sqlfile = vm["sql"].as <string> ();
if (vm.count("sql"))
sqlfile = vm["sql"].as<string>();
if (vm.count("count"))
count = vm["count"].as<int>();
if (vm.count("count"))
count = vm["count"].as<int>();
SqlFileParser parser;
SqlFileParser parser;
if (vm.count("bisond"))
parser.SetDebug(true);
if (vm.count ("bisond"))
parser.SetDebug(true);
parser.Parse(sqlfile);
parser.Parse(sqlfile);
if (parser.Good())
{
const ParseTree& ptree = parser.GetParseTree();
if (parser.Good())
{
const ParseTree& ptree = parser.GetParseTree();
cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " "
<< "SQL statements" << endl;
cout << ptree;
cout << endl;
}
else
{
cout << "Parser failed." << endl;
}
cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl;
cout << ptree;
cout << endl;
}
else
{
cout << "Parser failed." << endl;
}
return parser.Good() ? 0 : -1;
return parser.Good() ? 0 : -1;
}

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: markpartition.cpp 6566 2010-04-27 18:02:51Z rdempsey $
*
*
***********************************************************************/
* $Id: markpartition.cpp 6566 2010-04-27 18:02:51Z rdempsey $
*
*
***********************************************************************/
#define DDLPKG_DLLEXPORT
#include "ddlpkg.h"
@ -29,23 +29,21 @@ using namespace std;
namespace ddlpackage
{
MarkPartitionStatement::MarkPartitionStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName)
MarkPartitionStatement::MarkPartitionStatement(QualifiedName* qualifiedName) : fTableName(qualifiedName)
{
}
ostream& MarkPartitionStatement::put(ostream& os) const
{
os << "Mark partition out of service: " << *fTableName;
os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it;
os << "Mark partition out of service: " << *fTableName;
os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it;
for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
os << (*it) << " ";
for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
os << (*it) << " ";
os << endl;
return os;
os << endl;
return os;
}
}
} // namespace ddlpackage

File diff suppressed because it is too large Load Diff

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: markpartition.cpp 6566 2010-04-27 18:02:51Z rdempsey $
*
*
***********************************************************************/
* $Id: markpartition.cpp 6566 2010-04-27 18:02:51Z rdempsey $
*
*
***********************************************************************/
#define DDLPKG_DLLEXPORT
#include "ddlpkg.h"
@ -29,23 +29,21 @@ using namespace std;
namespace ddlpackage
{
RestorePartitionStatement::RestorePartitionStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName)
RestorePartitionStatement::RestorePartitionStatement(QualifiedName* qualifiedName) : fTableName(qualifiedName)
{
}
ostream& RestorePartitionStatement::put(ostream& os) const
{
os << "Mark partition out of service: " << *fTableName;
os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it;
os << "Mark partition out of service: " << *fTableName;
os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it;
for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
os << (*it) << " ";
for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
os << (*it) << " ";
os << endl;
return os;
os << endl;
return os;
}
}
} // namespace ddlpackage

File diff suppressed because it is too large Load Diff

View File

@ -17,10 +17,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: sqlparser.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: sqlparser.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include <fstream>
#include <errno.h>
@ -45,104 +45,94 @@ namespace ddlpackage
{
using namespace std;
SqlParser::SqlParser() :
fStatus(-1),
fDebug(false),
x(&fParseTree)
SqlParser::SqlParser() : fStatus(-1), fDebug(false), x(&fParseTree)
{
}
void SqlParser::SetDebug(bool debug)
{
fDebug = debug;
fDebug = debug;
}
void SqlParser::setDefaultSchema(std::string schema)
{
x.fDBSchema = schema;
x.fDBSchema = schema;
}
void SqlParser::setDefaultCharset(const CHARSET_INFO* default_charset)
{
x.default_table_charset = default_charset;
x.default_table_charset = default_charset;
}
int SqlParser::Parse(const char* sqltext)
{
ddllex_init_extra(&scanData, &x.scanner);
scanner_init(sqltext, x.scanner);
fStatus = ddlparse(&x);
return fStatus;
ddllex_init_extra(&scanData, &x.scanner);
scanner_init(sqltext, x.scanner);
fStatus = ddlparse(&x);
return fStatus;
}
const ParseTree& SqlParser::GetParseTree(void)
{
if (!Good())
{
throw logic_error("The ParseTree is invalid");
}
if (!Good())
{
throw logic_error("The ParseTree is invalid");
}
return fParseTree;
return fParseTree;
}
bool SqlParser::Good()
{
return fStatus == 0;
return fStatus == 0;
}
SqlParser::~SqlParser()
{
scanner_finish(x.scanner); // free scanner allocated memory
ddllex_destroy(x.scanner);
scanner_finish(x.scanner); // free scanner allocated memory
ddllex_destroy(x.scanner);
}
SqlFileParser::SqlFileParser() :
SqlParser()
SqlFileParser::SqlFileParser() : SqlParser()
{
}
int SqlFileParser::Parse(const string& sqlfile)
{
fStatus = -1;
fStatus = -1;
ifstream ifsql;
ifsql.open(sqlfile.c_str());
ifstream ifsql;
ifsql.open(sqlfile.c_str());
if (!ifsql.is_open())
{
perror(sqlfile.c_str());
return fStatus;
}
if (!ifsql.is_open())
{
perror(sqlfile.c_str());
return fStatus;
}
char sqlbuf[1024 * 1024];
unsigned length;
ifsql.seekg (0, ios::end);
length = ifsql.tellg();
ifsql.seekg (0, ios::beg);
char sqlbuf[1024 * 1024];
unsigned length;
ifsql.seekg(0, ios::end);
length = ifsql.tellg();
ifsql.seekg(0, ios::beg);
if (length > sizeof(sqlbuf) - 1)
{
throw length_error("SqlFileParser has file size hard limit of 16K.");
}
if (length > sizeof(sqlbuf) - 1)
{
throw length_error("SqlFileParser has file size hard limit of 16K.");
}
std::streamsize rcount;
rcount = ifsql.readsome(sqlbuf, sizeof(sqlbuf) - 1);
std::streamsize rcount;
rcount = ifsql.readsome(sqlbuf, sizeof(sqlbuf) - 1);
if (rcount < 0)
return fStatus;
if (rcount < 0)
return fStatus;
sqlbuf[rcount] = 0;
sqlbuf[rcount] = 0;
//cout << endl << sqlfile << "(" << rcount << ")" << endl;
//cout << "----------------------" << endl;
//cout << sqlbuf << endl;
// cout << endl << sqlfile << "(" << rcount << ")" << endl;
// cout << "----------------------" << endl;
// cout << sqlbuf << endl;
return SqlParser::Parse(sqlbuf);
}
return SqlParser::Parse(sqlbuf);
}
} // namespace ddlpackage

View File

@ -17,17 +17,17 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: sqlparser.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: sqlparser.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
/** @file
*
* This contains a class wrapper for the Bison parsing machinery.
*/
#include <stdexcept>
#include "collation.h" // CHARSET_INFO
#include "collation.h" // CHARSET_INFO
#include "ddlpkg.h"
#if defined(_MSC_VER) && defined(xxxDDLPKGSQLPARSER_DLLEXPORT)
@ -38,7 +38,6 @@
namespace ddlpackage
{
typedef SqlStatementList ParseTree;
/** @brief SqlParser is a class interface around the Bison parser
@ -54,7 +53,7 @@ typedef SqlStatementList ParseTree;
or
SqlFileParser parser;
parser.setDefaultSchema("tpch");
parser.setDefaultSchema("tpch");
parser.Parse(sqlFileName);
if (parser.Good()) {
@ -76,78 +75,77 @@ typedef std::vector<char*> valbuf_t;
struct scan_data
{
/* Handles to the buffer that the lexer uses internally */
char* scanbuf;
void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp
valbuf_t valbuf;
/* Handles to the buffer that the lexer uses internally */
char* scanbuf;
void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp
valbuf_t valbuf;
};
struct pass_to_bison
{
ParseTree* fParseTree;
std::string fDBSchema;
void* scanner;
const CHARSET_INFO* default_table_charset;
ParseTree* fParseTree;
std::string fDBSchema;
void* scanner;
const CHARSET_INFO* default_table_charset;
pass_to_bison(ParseTree* pt) : fParseTree(pt), scanner(NULL), default_table_charset(NULL) {};
pass_to_bison(ParseTree* pt) : fParseTree(pt), scanner(NULL), default_table_charset(NULL){};
};
class SqlParser
{
public:
EXPORT SqlParser(void);
public:
EXPORT SqlParser(void);
EXPORT virtual ~SqlParser();
EXPORT virtual ~SqlParser();
EXPORT int Parse(const char* sqltext);
EXPORT int Parse(const char* sqltext);
/** @brief Return the ParseTree if state is Good. Otherwise
* throw a logic_error.
*/
EXPORT const ParseTree& GetParseTree(void);
/** @brief Return the ParseTree if state is Good. Otherwise
* throw a logic_error.
*/
EXPORT const ParseTree& GetParseTree(void);
/** @brief Tells whether current state resulted from a good
* parse.
*/
EXPORT bool Good(void);
/** @brief Tells whether current state resulted from a good
* parse.
*/
EXPORT bool Good(void);
/** @brief Control bison debugging
*/
EXPORT void SetDebug(bool debug);
/** @brief Control bison debugging
*/
EXPORT void SetDebug(bool debug);
/** @brief Set the default schema to use if it is not
* supplied in the DDL statement
*
* @param schema the default schema
*/
EXPORT void setDefaultSchema(std::string schema);
/** @brief Set the default schema to use if it is not
* supplied in the DDL statement
*
* @param schema the default schema
*/
EXPORT void setDefaultSchema(std::string schema);
/** @brief Set the default table charset. Can be overriden by column
* or table options
*
* @param default_charset the default CHARSET_INFO pointer
*/
EXPORT void setDefaultCharset(const CHARSET_INFO* default_charset);
/** @brief Set the default table charset. Can be overriden by column
* or table options
*
* @param default_charset the default CHARSET_INFO pointer
*/
EXPORT void setDefaultCharset(const CHARSET_INFO* default_charset);
protected:
ParseTree fParseTree;
std::string fDBSchema;
int fStatus; ///< return from yyparse() stored here.
bool fDebug; ///< Turn on bison debugging.
scan_data scanData;
pass_to_bison x;
protected:
ParseTree fParseTree;
std::string fDBSchema;
int fStatus; ///< return from yyparse() stored here.
bool fDebug; ///< Turn on bison debugging.
scan_data scanData;
pass_to_bison x;
};
/** SqlFileParser is a testing device.
*/
*/
class SqlFileParser : public SqlParser
{
public:
SqlFileParser();
int Parse(const std::string& fileName);
public:
SqlFileParser();
int Parse(const std::string& fileName);
};
}
} // namespace ddlpackage
#undef EXPORT

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: sqlstatement.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: sqlstatement.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#define DDLPKG_DLLEXPORT
#include "ddlpkg.h"
@ -33,7 +33,7 @@ static uint32_t sessionID = 1;
SqlStatement::SqlStatement()
{
fSessionID = sessionID;
fSessionID = sessionID;
}
SqlStatement::~SqlStatement()
@ -42,6 +42,6 @@ SqlStatement::~SqlStatement()
ostream& operator<<(ostream& os, const SqlStatement& stmt)
{
return stmt.put(os);
}
return stmt.put(os);
}
} // namespace ddlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: sqlstatementlist.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: sqlstatementlist.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#define DDLPKG_DLLEXPORT
#include "ddlpkg.h"
@ -29,35 +29,32 @@ namespace ddlpackage
{
using namespace std;
ostream& operator<<(ostream& os, const SqlStatementList& ssl)
{
vector<SqlStatement*>::const_iterator itr;
vector<SqlStatement*>::const_iterator itr;
for (itr = ssl.fList.begin(); itr != ssl.fList.end(); ++itr)
{
SqlStatement& stmt = **itr;
os << stmt;
}
for (itr = ssl.fList.begin(); itr != ssl.fList.end(); ++itr)
{
SqlStatement& stmt = **itr;
os << stmt;
}
return os;
return os;
}
void SqlStatementList::push_back(SqlStatement* v)
{
fList.push_back(v);
fList.push_back(v);
}
SqlStatementList::~SqlStatementList()
{
vector<SqlStatement*>::iterator itr;
vector<SqlStatement*>::iterator itr;
for (itr = fList.begin(); itr != fList.end(); ++itr)
{
delete *itr;
}
for (itr = fList.begin(); itr != fList.end(); ++itr)
{
delete *itr;
}
}
}
} // namespace ddlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: tabledef.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: tabledef.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include <iostream>
#define DDLPKG_DLLEXPORT
@ -30,293 +30,252 @@ namespace ddlpackage
{
using namespace std;
TableDef::~TableDef()
{
{
ColumnDefList::iterator itr;
for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
{
ColumnDefList::iterator itr;
for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
{
delete *itr;
}
delete *itr;
}
}
{
TableConstraintDefList::iterator itr;
for (itr = fConstraints.begin(); itr != fConstraints.end(); itr++)
{
TableConstraintDefList::iterator itr;
for (itr = fConstraints.begin(); itr != fConstraints.end(); itr++)
{
delete *itr;
}
delete *itr;
}
}
delete fQualifiedName;
delete fQualifiedName;
}
TableDef::TableDef(QualifiedName* name, TableElementList* elements, TableOptionMap* options) :
fQualifiedName(name)
TableDef::TableDef(QualifiedName* name, TableElementList* elements, TableOptionMap* options)
: fQualifiedName(name)
{
if (options)
if (options)
{
fOptions = *options;
delete options;
}
ColumnDef* column;
TableConstraintDef* constraint;
/* When parsing, it is necessary to collect ColumnDefs and
TableConstraintDefs as TableElements. Here we separate
them out into separately typed lists.
*/
TableElementList::iterator itr;
for (itr = elements->begin(); itr != elements->end(); ++itr)
{
column = dynamic_cast<ColumnDef*>(*itr);
if (column)
{
fOptions = *options;
delete options;
fColumns.push_back(column);
}
ColumnDef* column;
TableConstraintDef* constraint;
/* When parsing, it is necessary to collect ColumnDefs and
TableConstraintDefs as TableElements. Here we separate
them out into separately typed lists.
*/
TableElementList::iterator itr;
for (itr = elements->begin(); itr != elements->end(); ++itr)
else
{
column = dynamic_cast<ColumnDef*>(*itr);
constraint = dynamic_cast<TableConstraintDef*>(*itr);
if (column)
{
fColumns.push_back(column);
}
else
{
constraint = dynamic_cast<TableConstraintDef*>(*itr);
if (constraint)
{
fConstraints.push_back(constraint);
}
}
if (constraint)
{
fConstraints.push_back(constraint);
}
}
}
delete elements;
delete elements;
}
/** \brief Put to ostream. */
ostream& operator<<(ostream& os, const TableDef& tableDef)
{
os << "CreateTable ";
os << "CreateTable ";
if (tableDef.fQualifiedName->fSchema != "")
//cout << tableDef.fQualifiedName->fSchema << ".";
os << tableDef.fQualifiedName->fName
<< " " << tableDef.fConstraints.size()
<< " table constraints"
<< endl;
if (tableDef.fQualifiedName->fSchema != "")
// cout << tableDef.fQualifiedName->fSchema << ".";
os << tableDef.fQualifiedName->fName << " " << tableDef.fConstraints.size() << " table constraints"
<< endl;
{
ColumnDefList::const_iterator itr;
for (itr = tableDef.fColumns.begin(); itr != tableDef.fColumns.end(); ++itr)
{
ColumnDefList::const_iterator itr;
for (itr = tableDef.fColumns.begin();
itr != tableDef.fColumns.end(); ++itr)
{
ColumnDef* col = *itr;
os << *col << endl;
}
ColumnDef* col = *itr;
os << *col << endl;
}
}
{
TableConstraintDefList::const_iterator itr;
for (itr = tableDef.fConstraints.begin(); itr != tableDef.fConstraints.end(); ++itr)
{
TableConstraintDefList::const_iterator itr;
for (itr = tableDef.fConstraints.begin();
itr != tableDef.fConstraints.end();
++itr)
{
os << (**itr);
}
os << (**itr);
}
}
pair<string, string> oval;
pair<string, string> oval;
TableOptionMap::const_iterator oitr;
os << "Table Options" << endl;
if (!tableDef.fOptions.empty())
{
TableOptionMap::const_iterator oitr;
os << "Table Options" << endl;
if (!tableDef.fOptions.empty())
for (oitr = tableDef.fOptions.begin(); oitr != tableDef.fOptions.end(); ++oitr)
{
TableOptionMap::const_iterator oitr;
for (oitr = tableDef.fOptions.begin();
oitr != tableDef.fOptions.end(); ++oitr)
{
oval = *oitr;
os << " " << oval.first << "=" << oval.second << endl;
}
oval = *oitr;
os << " " << oval.first << "=" << oval.second << endl;
}
}
return os;
return os;
}
ostream& operator<<(ostream& os, const TableConstraintDef& constraint)
{
return constraint.put(os);
return constraint.put(os);
}
std::ostream& TableConstraintDef::put(std::ostream& os) const
{
os << "No!!!" << endl;
os << "No!!!" << endl;
return os;
return os;
}
TableConstraintDef::TableConstraintDef(DDL_CONSTRAINTS cType) :
fConstraintType(cType)
TableConstraintDef::TableConstraintDef(DDL_CONSTRAINTS cType) : fConstraintType(cType)
{
}
TableConstraintDef::TableConstraintDef() :
fConstraintType(DDL_INVALID_CONSTRAINT)
TableConstraintDef::TableConstraintDef() : fConstraintType(DDL_INVALID_CONSTRAINT)
{
}
TableCheckConstraintDef::TableCheckConstraintDef(const char* check) :
TableConstraintDef(DDL_CHECK),
fCheck(check)
TableCheckConstraintDef::TableCheckConstraintDef(const char* check)
: TableConstraintDef(DDL_CHECK), fCheck(check)
{
}
std::ostream& TableCheckConstraintDef::put(std::ostream& os) const
{
os << "Constraint: "
<< ConstraintString[fConstraintType] << " ";
os << "\"" << fCheck << "\"";
os << endl;
os << "Constraint: " << ConstraintString[fConstraintType] << " ";
os << "\"" << fCheck << "\"";
os << endl;
return os;
return os;
}
TableUniqueConstraintDef::TableUniqueConstraintDef(ColumnNameList* columns) :
TableConstraintDef(DDL_UNIQUE),
fColumnNameList(*columns)
TableUniqueConstraintDef::TableUniqueConstraintDef(ColumnNameList* columns)
: TableConstraintDef(DDL_UNIQUE), fColumnNameList(*columns)
{
delete columns;
delete columns;
}
std::ostream& TableUniqueConstraintDef::put(std::ostream& os) const
{
os << "Constraint: "
<< fName << " "
<< ConstraintString[fConstraintType] << " ";
os << "Constraint: " << fName << " " << ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr;
os << "(";
ColumnNameList::const_iterator itr;
os << "(";
for (itr = fColumnNameList.begin();
itr != fColumnNameList.end();
++itr)
{
os << *itr << " ";
}
for (itr = fColumnNameList.begin(); itr != fColumnNameList.end(); ++itr)
{
os << *itr << " ";
}
os << ")";
return os;
os << ")";
return os;
}
TablePrimaryKeyConstraintDef::TablePrimaryKeyConstraintDef(ColumnNameList* columns) :
TableConstraintDef(DDL_PRIMARY_KEY),
fColumnNameList(*columns)
TablePrimaryKeyConstraintDef::TablePrimaryKeyConstraintDef(ColumnNameList* columns)
: TableConstraintDef(DDL_PRIMARY_KEY), fColumnNameList(*columns)
{
delete columns;
delete columns;
}
std::ostream& TablePrimaryKeyConstraintDef::put(std::ostream& os) const
{
os << "Constraint: "
<< fName << " "
<< ConstraintString[fConstraintType] << " ";
os << "Constraint: " << fName << " " << ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr;
os << "(";
ColumnNameList::const_iterator itr;
os << "(";
for (itr = fColumnNameList.begin();
itr != fColumnNameList.end();
++itr)
{
os << *itr << " ";
}
for (itr = fColumnNameList.begin(); itr != fColumnNameList.end(); ++itr)
{
os << *itr << " ";
}
os << ")";
os << ")";
return os;
return os;
}
TableReferencesConstraintDef::TableReferencesConstraintDef
(ColumnNameList* columns,
QualifiedName* tableName,
ColumnNameList* foreignColumns,
DDL_MATCH_TYPE matchType,
ReferentialAction* refAction) :
TableConstraintDef(DDL_REFERENCES),
fColumns(*columns),
fTableName(tableName),
fForeignColumns(*foreignColumns),
fMatchType(matchType),
fRefAction(refAction)
TableReferencesConstraintDef::TableReferencesConstraintDef(ColumnNameList* columns, QualifiedName* tableName,
ColumnNameList* foreignColumns,
DDL_MATCH_TYPE matchType,
ReferentialAction* refAction)
: TableConstraintDef(DDL_REFERENCES)
, fColumns(*columns)
, fTableName(tableName)
, fForeignColumns(*foreignColumns)
, fMatchType(matchType)
, fRefAction(refAction)
{
delete columns;
delete foreignColumns;
delete columns;
delete foreignColumns;
}
std::ostream& TableReferencesConstraintDef::put(std::ostream& os) const
{
os << "Constraint: "
<< fName << " "
<< ConstraintString[fConstraintType] << " ";
os << "Constraint: " << fName << " " << ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr;
os << "lcols (";
ColumnNameList::const_iterator itr;
os << "lcols (";
for (itr = fColumns.begin();
itr != fColumns.end();
++itr)
{
os << *itr << " ";
}
for (itr = fColumns.begin(); itr != fColumns.end(); ++itr)
{
os << *itr << " ";
}
os << ")";
os << ")";
os << " ftable=" << *fTableName;
os << " ftable=" << *fTableName;
os << " ";
os << " ";
os << "fcols (";
os << "fcols (";
for (itr = fForeignColumns.begin();
itr != fForeignColumns.end();
++itr)
{
os << *itr << " ";
}
for (itr = fForeignColumns.begin(); itr != fForeignColumns.end(); ++itr)
{
os << *itr << " ";
}
os << ")";
os << ")";
return os;
return os;
}
std::ostream& operator<<(std::ostream& os, const ColumnNameList& columnNames)
{
ColumnNameList::const_iterator itr;
os << '(';
ColumnNameList::const_iterator itr;
os << '(';
for (itr = columnNames.begin();
itr != columnNames.end();
++itr)
{
os << *itr << " ";
}
for (itr = columnNames.begin(); itr != columnNames.end(); ++itr)
{
os << *itr << " ";
}
os << ')';
return os;
os << ')';
return os;
}
TableReferencesConstraintDef::~TableReferencesConstraintDef()
{
delete fTableName;
delete fRefAction;
}
delete fTableName;
delete fRefAction;
}
} // namespace ddlpackage

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -39,122 +39,124 @@ namespace ddlpackageprocessor
*/
class AlterTableProcessor : public DDLPackageProcessor
{
public:
AlterTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process an alter table statement
*
* @param alterTableStmt the AlterTableStatement
*/
EXPORT DDLResult processPackage(ddlpackage::AlterTableStatement& alterTableStmt);
/** @brief add a physical column file
*
* @param result the result of the operation
* @param addColumn the AtaAddColumn object
* @param fTableName the QualifiedName of the table
*/
EXPORT void addColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::ColumnDef* columnDefPtr,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
public:
AlterTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm)
{
}
/** @brief process an alter table statement
*
* @param alterTableStmt the AlterTableStatement
*/
EXPORT DDLResult processPackage(ddlpackage::AlterTableStatement& alterTableStmt);
/** @brief add a physical column file
*
* @param result the result of the operation
* @param addColumn the AtaAddColumn object
* @param fTableName the QualifiedName of the table
*/
EXPORT void addColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::ColumnDef* columnDefPtr, ddlpackage::QualifiedName& fTableName,
const uint64_t uniqueId);
/** @brief drop a column
*
* @param result the result of the operation
* @param ataDropColumn the AtaDropColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumn& ataDropColumn,
/** @brief drop a column
*
* @param result the result of the operation
* @param ataDropColumn the AtaDropColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumn& ataDropColumn, ddlpackage::QualifiedName& fTableName,
const uint64_t uniqueId);
/** @brief drop columns
*
* @param result the result of the operation
* @param ataDropColumns the AtaDropColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropColumns(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumns& ataDropColumns, ddlpackage::QualifiedName& fTableName,
const uint64_t uniqueId);
/** @brief add table constraint
*
* @param result the result of the operation
* @param ataAddTableConstraint the AtaDropColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void addTableConstraint(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
DDLResult& result, ddlpackage::AtaAddTableConstraint& ataAddTableConstraint,
ddlpackage::QualifiedName& fTableName);
/** @brief set column default
*
* @param result the result of the operation
* @param ataSetColumnDefault the AtaSetColumnDefault object
* @param fTableName the QualifiedName for the table
*/
EXPORT void setColumnDefault(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
DDLResult& result, ddlpackage::AtaSetColumnDefault& ataSetColumnDefault,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief drop column default
*
* @param result the result of the operation
* @param ataDropColumnDefault the AtaDropColumnDefault object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropColumnDefault(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
DDLResult& result, ddlpackage::AtaDropColumnDefault& ataDropColumnDefault,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief drop table constraint
*
* @param result the result of the operation
* @param ataDropTableConstraint the AtaDropTableConstraint object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropTableConstraint(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
DDLResult& result,
ddlpackage::AtaDropTableConstraint& ataDropTableConstraint,
ddlpackage::QualifiedName& fTableName);
/** @brief rename a table
*
* @param result the result of the operation
* @param ataRenameTable the AtaRenameTable object
* @param fTableName the QualifiedName for the table
*/
EXPORT void renameTable(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaRenameTable& ataRenameTable, ddlpackage::QualifiedName& fTableName,
const uint64_t uniqueId);
/** @brief rename a column
*
* @param result the result of the operation
* @param ataRenameColumn the AtaRenameColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void renameColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaRenameColumn& ataRenameColumn,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief drop columns
*
* @param result the result of the operation
* @param ataDropColumns the AtaDropColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropColumns(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumns& ataDropColumns,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId );
/** @brief change a table autoincrement via a comment
*
* @param result the result of the operation
* @param ataTableComment the AtaTableComment object
* @param fTableName the QualifiedName for the table
*/
EXPORT void tableComment(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaTableComment& ataTableComment,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief add table constraint
*
* @param result the result of the operation
* @param ataAddTableConstraint the AtaDropColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void addTableConstraint(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaAddTableConstraint& ataAddTableConstraint,
ddlpackage::QualifiedName& fTableName );
std::string fTimeZone;
/** @brief set column default
*
* @param result the result of the operation
* @param ataSetColumnDefault the AtaSetColumnDefault object
* @param fTableName the QualifiedName for the table
*/
EXPORT void setColumnDefault(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaSetColumnDefault& ataSetColumnDefault,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId );
/** @brief drop column default
*
* @param result the result of the operation
* @param ataDropColumnDefault the AtaDropColumnDefault object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropColumnDefault(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumnDefault& ataDropColumnDefault,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId );
/** @brief drop table constraint
*
* @param result the result of the operation
* @param ataDropTableConstraint the AtaDropTableConstraint object
* @param fTableName the QualifiedName for the table
*/
EXPORT void dropTableConstraint(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropTableConstraint& ataDropTableConstraint,
ddlpackage::QualifiedName& fTableName );
/** @brief rename a table
*
* @param result the result of the operation
* @param ataRenameTable the AtaRenameTable object
* @param fTableName the QualifiedName for the table
*/
EXPORT void renameTable(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
DDLResult& result, ddlpackage::AtaRenameTable& ataRenameTable,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief rename a column
*
* @param result the result of the operation
* @param ataRenameColumn the AtaRenameColumn object
* @param fTableName the QualifiedName for the table
*/
EXPORT void renameColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaRenameColumn& ataRenameColumn,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief change a table autoincrement via a comment
*
* @param result the result of the operation
* @param ataTableComment the AtaTableComment object
* @param fTableName the QualifiedName for the table
*/
EXPORT void tableComment(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaTableComment& ataTableComment,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
std::string fTimeZone;
protected:
void rollBackAlter(const std::string& error, BRM::TxnID txnID, int sessionId, DDLResult& result, uint64_t uniqueId);
private:
protected:
void rollBackAlter(const std::string& error, BRM::TxnID txnID, int sessionId, DDLResult& result,
uint64_t uniqueId);
private:
};
} //namespace ddlpackageprocessor
} // namespace ddlpackageprocessor
#undef EXPORT

View File

@ -37,446 +37,451 @@ using namespace logging;
using namespace BRM;
namespace ddlpackageprocessor
{
CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage::CreateIndexStatement& createIndexStmt)
CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(
ddlpackage::CreateIndexStatement& createIndexStmt)
{
/*
get OIDs for the list & tree files
commit the current transaction
start a new transaction
create the index in the metadata
create the index on the WE
end the transaction
*/
SUMMARY_INFO("CreateIndexProcesssor::processPackage");
/*
get OIDs for the list & tree files
commit the current transaction
start a new transaction
create the index in the metadata
create the index on the WE
end the transaction
*/
SUMMARY_INFO("CreateIndexProcesssor::processPackage");
DDLResult result;
result.result = NO_ERROR;
DDLResult result;
result.result = NO_ERROR;
DETAIL_INFO(createIndexStmt);
DETAIL_INFO(createIndexStmt);
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
/*Check whether the table exists already. If not, it is assumed from primary key creating.
This is based on the assumption that Front end is already error out if the user trys to
create index on non-existing table. */
CalpontSystemCatalog::TableName tableName;
tableName.schema = (createIndexStmt.fTableName)->fSchema;
tableName.table = (createIndexStmt.fTableName)->fName;
CalpontSystemCatalog::ROPair roPair;
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog( createIndexStmt.fSessionID );
try
{
roPair = systemCatalogPtr->tableRID( tableName );
}
catch (exception& ex)
{
// store primary key name in fPKName
fPKName = createIndexStmt.fIndexName->fName;
return result;
}
catch (...)
{
return result;
}
if ( roPair.objnum < 3000 )
{
return result;
}
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
/*Check whether the table exists already. If not, it is assumed from primary key creating.
This is based on the assumption that Front end is already error out if the user trys to
create index on non-existing table. */
CalpontSystemCatalog::TableName tableName;
tableName.schema = (createIndexStmt.fTableName)->fSchema;
tableName.table = (createIndexStmt.fTableName)->fName;
CalpontSystemCatalog::ROPair roPair;
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr =
CalpontSystemCatalog::makeCalpontSystemCatalog(createIndexStmt.fSessionID);
try
{
roPair = systemCatalogPtr->tableRID(tableName);
}
catch (exception& ex)
{
// store primary key name in fPKName
fPKName = createIndexStmt.fIndexName->fName;
int err = 0;
SQLLogger logger(createIndexStmt.fSql, fDDLLoggingId, createIndexStmt.fSessionID, txnID.id);
VERBOSE_INFO("Allocating object IDs for columns");
// int oidbase = fObjectIDManager.allocOIDs(2);
// fIdxOID.listOID = oidbase;
// fIdxOID.treeOID = ++oidbase;
VERBOSE_INFO("Starting a new transaction");
ddlpackage::DDL_CONSTRAINTS type = createIndexStmt.fUnique ? ddlpackage::DDL_UNIQUE : ddlpackage::DDL_INVALID_CONSTRAINT;
VERBOSE_INFO("Writing meta data to SYSINDEX");
bool multicol = false;
if ( createIndexStmt.fColumnNames.size() > 1 )
{
multicol = true;
}
//validate index columns
CalpontSystemCatalog::TableColName tableColName;
tableColName.schema = (createIndexStmt.fTableName)->fSchema;
tableColName.table = (createIndexStmt.fTableName)->fName;
CalpontSystemCatalog::OID oid;
CalpontSystemCatalog::ColType colType;
ColumnNameList::const_iterator colIter;
int totalWidth = 0;
DDLIndexPopulator pop(&fWriteEngine, &fSessionManager, createIndexStmt.fSessionID, txnID.id, result,
fIdxOID, createIndexStmt.fColumnNames, *createIndexStmt.fTableName,
type, getDebugLevel());
if ( multicol)
{
for ( colIter = createIndexStmt.fColumnNames.begin(); colIter != createIndexStmt.fColumnNames.end(); colIter++)
{
tableColName.column = *colIter;
roPair = systemCatalogPtr->columnRID( tableColName );
oid = systemCatalogPtr->lookupOID( tableColName );
colType = systemCatalogPtr->colType (oid );
totalWidth += (pop.isDictionaryType(colType)) ? 8 : colType.colWidth;
}
if ( totalWidth > 32 )
{
stringstream ss;
ss << totalWidth;
DETAIL_INFO("Total indexed column width greater than 32: " + ss.str());
logging::Message::Args args;
logging::Message message(9);
args.add("Error creating index: ");
args.add("Total indexed column width");
args.add("greater than 32. ");
message.format( args );
result.result = CREATE_ERROR;
result.message = message;
return result;
}
}
try
{
//writeSysIndexMetaData(createIndexStmt.fSessionID, txnID.id, result, *createIndexStmt.fTableName, type, createIndexStmt.fIndexName->fName, multicol);
//fIdxOID values are set in writeSysIndexMetaData.
pop.setIdxOID(fIdxOID);
VERBOSE_INFO("Writing meta data to SYSINDEXCOL");
//writeSysIndexColMetaData(createIndexStmt.fSessionID, txnID.id, result,*createIndexStmt.fTableName, createIndexStmt.fColumnNames, createIndexStmt.fIndexName->fName );
if (createIndexStmt.fUnique)
{
VERBOSE_INFO("Writing column constraint meta data to SYSCONSTRAINT");
WriteEngine::ColStruct colStruct;
WriteEngine::ColTuple colTuple;
WriteEngine::ColStructList colStructs;
WriteEngine::ColTupleList colTuples;
WriteEngine::ColValueList colValuesList;
WriteEngine::RIDList ridList;
DDLColumn column;
CalpontSystemCatalog::TableName sysConsTableName;
sysConsTableName.schema = CALPONT_SCHEMA;
sysConsTableName.table = SYSCONSTRAINT_TABLE;
bool isNull = false;
int error = 0;
// get the columns for the SYSCONSTRAINT table
ColumnList sysConsColumns;
ColumnList::const_iterator sysCons_iterator;
getColumnsForTable(createIndexStmt.fSessionID, sysConsTableName.schema, sysConsTableName.table, sysConsColumns);
sysCons_iterator = sysConsColumns.begin();
std::string idxData;
while ( sysCons_iterator != sysConsColumns.end() )
{
column = *sysCons_iterator;
isNull = false;
if (CONSTRAINTNAME_COL == column.tableColName.column)
{
idxData = createIndexStmt.fIndexName->fName;
colTuple.data = idxData;
}
else if (SCHEMA_COL == column.tableColName.column)
{
idxData = (createIndexStmt.fTableName)->fSchema;
colTuple.data = idxData;
}
else if (TABLENAME_COL == column.tableColName.column)
{
idxData = (createIndexStmt.fTableName)->fName;
colTuple.data = idxData;
}
else if (CONSTRAINTTYPE_COL == column.tableColName.column)
{
std::string consType;
char constraint_type = getConstraintCode(type);
consType += constraint_type;
colTuple.data = consType;
}
else if (CONSTRAINTPRIM_COL == column.tableColName.column)
{
colTuple.data =column.colType.getNullValueForType();
isNull = true;
}
else if (CONSTRAINTTEXT_COL == column.tableColName.column)
{
colTuple.data = column.colType.getNullValueForType();
isNull = true;
}
else if (INDEXNAME_COL == column.tableColName.column)
{
idxData = createIndexStmt.fIndexName->fName;
colTuple.data = idxData;
}
else
{
colTuple.data = column.colType.getNullValueForType();
isNull = true;
}
colStruct.dataOid = column.oid;
colStruct.colWidth = column.colType.colWidth > 8 ? 8 : column.colType.colWidth;
colStruct.tokenFlag = false;
colStruct.tokenFlag = column.colType.colWidth > 8 ? true : false;
colStruct.colDataType = column.colType.colDataType;
if (column.colType.colWidth > 8 && !isNull)
{
colTuple.data = tokenizeData(txnID.id, result, column.colType, colTuple.data);
}
colStructs.push_back( colStruct );
colTuples.push_back( colTuple );
colValuesList.push_back( colTuples );
colTuples.pop_back();
++sysCons_iterator;
}
if (colStructs.size() != 0)
{
//fWriteEngine.setDebugLevel(WriteEngine::DEBUG_3);
//error = fWriteEngine.insertColumnRec( txnID.id, colStructs, colValuesList, ridList );
if ( error != WriteEngine::NO_ERROR )
{
return rollBackCreateIndex(errorString( "WE: Error inserting Column Record: ", error), txnID, createIndexStmt.fSessionID);
// logging::Message::Args args;
// logging::Message message(9);
// args.add("Error updating: ");
// args.add("calpont.sysconstraint");
// args.add("error number: ");
// args.add( error );
// message.format( args );
//
// result.result = CREATE_ERROR;
// result.message = message;
}
else
{
result.result = NO_ERROR;
}
}
VERBOSE_INFO("Writing column constraint meta data to SYSCONSTRAINTCOL");
WriteEngine::ColStruct colStructCol;
WriteEngine::ColTuple colTupleCol;
WriteEngine::ColStructList colStructsCol;
WriteEngine::ColTupleList colTuplesCol;
WriteEngine::ColValueList colValuesListCol;
CalpontSystemCatalog::TableName sysConsColTableName;
sysConsColTableName.schema = CALPONT_SCHEMA;
sysConsColTableName.table = SYSCONSTRAINTCOL_TABLE;
colValuesList.clear();
colTuples.clear();
isNull = false;
error = 0;
// get the columns for the SYSCONSTRAINTCOL table
ColumnList sysConsColColumns;
ColumnList::const_iterator sysConsCol_iterator;
getColumnsForTable(createIndexStmt.fSessionID, sysConsColTableName.schema, sysConsColTableName.table, sysConsColColumns);
// write sysconstraintcol
sysConsCol_iterator = sysConsColColumns.begin();
std::string colData;
while ( sysConsCol_iterator != sysConsColColumns.end() )
{
column = *sysConsCol_iterator;
isNull = false;
if (SCHEMA_COL == column.tableColName.column)
{
colData = (createIndexStmt.fTableName)->fSchema;
colTupleCol.data = colData;
}
else if (TABLENAME_COL == column.tableColName.column)
{
colData = (createIndexStmt.fTableName)->fName;
colTupleCol.data = colData;
}
else if (COLNAME_COL == column.tableColName.column)
{
colData = createIndexStmt.fColumnNames[0];
colTupleCol.data = colData;
}
else if (CONSTRAINTNAME_COL == column.tableColName.column)
{
colData = createIndexStmt.fIndexName->fName;
colTupleCol.data = colData;
}
else
{
colTupleCol.data = column.colType.getNullValueForType();
isNull = true;
}
colStructCol.dataOid = column.oid;
colStructCol.colWidth = column.colType.colWidth > 8 ? 8 : column.colType.colWidth;
colStructCol.tokenFlag = false;
colStructCol.tokenFlag = column.colType.colWidth > 8 ? true : false;
colStructCol.colDataType = column.colType.colDataType;
if (column.colType.colWidth > 8 && !isNull)
{
colTupleCol.data = tokenizeData(txnID.id, result, column.colType, colTupleCol.data);
}
colStructsCol.push_back( colStructCol );
colTuplesCol.push_back( colTupleCol );
colValuesListCol.push_back( colTuplesCol );
colTuplesCol.pop_back();
++sysConsCol_iterator;
}
if (colStructsCol.size() != 0)
{
//fWriteEngine.setDebugLevel(WriteEngine::DEBUG_3);
//error = fWriteEngine.insertColumnRec( txnID.id, colStructsCol, colValuesListCol, ridList );
if ( error != WriteEngine::NO_ERROR )
{
return rollBackCreateIndex(errorString( "WE: Error inserting Column Record: ", error), txnID, createIndexStmt.fSessionID);
/* logging::Message::Args args;
logging::Message message(9);
args.add("Error updating: ");
args.add("calpont.sysconstraintcol");
args.add("error number: ");
args.add( error );
message.format( args );
result.result = CREATE_ERROR;
result.message = message;*/
}
else
{
result.result = NO_ERROR;
}
}
}
VERBOSE_INFO("Creating index files");
err = fWriteEngine.createIndex( txnID.id, fIdxOID.treeOID, fIdxOID.listOID );
if (err)
{
return rollBackCreateIndex(errorString("Write engine failed to create the new index. ", err), txnID, createIndexStmt.fSessionID);
}
// new if BULK_LOAD close
err = pop.populateIndex(result);
if ( err )
{
return rollBackCreateIndex(errorString("Failed to populate index with current data. ", err), txnID, createIndexStmt.fSessionID);
}
// Log the DDL statement.
logging::logDDL(createIndexStmt.fSessionID, txnID.id, createIndexStmt.fSql, createIndexStmt.fOwner);
DETAIL_INFO("Commiting transaction");
err = fWriteEngine.commit( txnID.id );
if (err)
{
return rollBackCreateIndex(errorString("Failed to commit the create index transaction. ", err), txnID, createIndexStmt.fSessionID);
}
fSessionManager.committed(txnID);
// original if BULK_LOAD close }
} // try
catch (exception& ex)
{
result = rollBackCreateIndex(ex.what(), txnID, createIndexStmt.fSessionID);
}
catch (...)
{
string msg("CreateIndexProcessor::processPackage: caught unknown exception!");
result = rollBackCreateIndex(msg, txnID, createIndexStmt.fSessionID);
}
return result;
}
catch (...)
{
return result;
}
if (roPair.objnum < 3000)
{
return result;
}
fPKName = createIndexStmt.fIndexName->fName;
int err = 0;
SQLLogger logger(createIndexStmt.fSql, fDDLLoggingId, createIndexStmt.fSessionID, txnID.id);
VERBOSE_INFO("Allocating object IDs for columns");
// int oidbase = fObjectIDManager.allocOIDs(2);
// fIdxOID.listOID = oidbase;
// fIdxOID.treeOID = ++oidbase;
VERBOSE_INFO("Starting a new transaction");
ddlpackage::DDL_CONSTRAINTS type =
createIndexStmt.fUnique ? ddlpackage::DDL_UNIQUE : ddlpackage::DDL_INVALID_CONSTRAINT;
VERBOSE_INFO("Writing meta data to SYSINDEX");
bool multicol = false;
if (createIndexStmt.fColumnNames.size() > 1)
{
multicol = true;
}
// validate index columns
CalpontSystemCatalog::TableColName tableColName;
tableColName.schema = (createIndexStmt.fTableName)->fSchema;
tableColName.table = (createIndexStmt.fTableName)->fName;
CalpontSystemCatalog::OID oid;
CalpontSystemCatalog::ColType colType;
ColumnNameList::const_iterator colIter;
int totalWidth = 0;
DDLIndexPopulator pop(&fWriteEngine, &fSessionManager, createIndexStmt.fSessionID, txnID.id, result,
fIdxOID, createIndexStmt.fColumnNames, *createIndexStmt.fTableName, type,
getDebugLevel());
if (multicol)
{
for (colIter = createIndexStmt.fColumnNames.begin(); colIter != createIndexStmt.fColumnNames.end();
colIter++)
{
tableColName.column = *colIter;
roPair = systemCatalogPtr->columnRID(tableColName);
oid = systemCatalogPtr->lookupOID(tableColName);
colType = systemCatalogPtr->colType(oid);
totalWidth += (pop.isDictionaryType(colType)) ? 8 : colType.colWidth;
}
if (totalWidth > 32)
{
stringstream ss;
ss << totalWidth;
DETAIL_INFO("Total indexed column width greater than 32: " + ss.str());
logging::Message::Args args;
logging::Message message(9);
args.add("Error creating index: ");
args.add("Total indexed column width");
args.add("greater than 32. ");
message.format(args);
result.result = CREATE_ERROR;
result.message = message;
return result;
}
}
try
{
// writeSysIndexMetaData(createIndexStmt.fSessionID, txnID.id, result, *createIndexStmt.fTableName, type,
// createIndexStmt.fIndexName->fName, multicol);
// fIdxOID values are set in writeSysIndexMetaData.
pop.setIdxOID(fIdxOID);
VERBOSE_INFO("Writing meta data to SYSINDEXCOL");
// writeSysIndexColMetaData(createIndexStmt.fSessionID, txnID.id, result,*createIndexStmt.fTableName,
// createIndexStmt.fColumnNames, createIndexStmt.fIndexName->fName );
if (createIndexStmt.fUnique)
{
VERBOSE_INFO("Writing column constraint meta data to SYSCONSTRAINT");
WriteEngine::ColStruct colStruct;
WriteEngine::ColTuple colTuple;
WriteEngine::ColStructList colStructs;
WriteEngine::ColTupleList colTuples;
WriteEngine::ColValueList colValuesList;
WriteEngine::RIDList ridList;
DDLColumn column;
CalpontSystemCatalog::TableName sysConsTableName;
sysConsTableName.schema = CALPONT_SCHEMA;
sysConsTableName.table = SYSCONSTRAINT_TABLE;
bool isNull = false;
int error = 0;
// get the columns for the SYSCONSTRAINT table
ColumnList sysConsColumns;
ColumnList::const_iterator sysCons_iterator;
getColumnsForTable(createIndexStmt.fSessionID, sysConsTableName.schema, sysConsTableName.table,
sysConsColumns);
sysCons_iterator = sysConsColumns.begin();
std::string idxData;
while (sysCons_iterator != sysConsColumns.end())
{
column = *sysCons_iterator;
isNull = false;
if (CONSTRAINTNAME_COL == column.tableColName.column)
{
idxData = createIndexStmt.fIndexName->fName;
colTuple.data = idxData;
}
else if (SCHEMA_COL == column.tableColName.column)
{
idxData = (createIndexStmt.fTableName)->fSchema;
colTuple.data = idxData;
}
else if (TABLENAME_COL == column.tableColName.column)
{
idxData = (createIndexStmt.fTableName)->fName;
colTuple.data = idxData;
}
else if (CONSTRAINTTYPE_COL == column.tableColName.column)
{
std::string consType;
char constraint_type = getConstraintCode(type);
consType += constraint_type;
colTuple.data = consType;
}
else if (CONSTRAINTPRIM_COL == column.tableColName.column)
{
colTuple.data = column.colType.getNullValueForType();
isNull = true;
}
else if (CONSTRAINTTEXT_COL == column.tableColName.column)
{
colTuple.data = column.colType.getNullValueForType();
isNull = true;
}
else if (INDEXNAME_COL == column.tableColName.column)
{
idxData = createIndexStmt.fIndexName->fName;
colTuple.data = idxData;
}
else
{
colTuple.data = column.colType.getNullValueForType();
isNull = true;
}
colStruct.dataOid = column.oid;
colStruct.colWidth = column.colType.colWidth > 8 ? 8 : column.colType.colWidth;
colStruct.tokenFlag = false;
colStruct.tokenFlag = column.colType.colWidth > 8 ? true : false;
colStruct.colDataType = column.colType.colDataType;
if (column.colType.colWidth > 8 && !isNull)
{
colTuple.data = tokenizeData(txnID.id, result, column.colType, colTuple.data);
}
colStructs.push_back(colStruct);
colTuples.push_back(colTuple);
colValuesList.push_back(colTuples);
colTuples.pop_back();
++sysCons_iterator;
}
if (colStructs.size() != 0)
{
// fWriteEngine.setDebugLevel(WriteEngine::DEBUG_3);
// error = fWriteEngine.insertColumnRec( txnID.id, colStructs, colValuesList, ridList );
if (error != WriteEngine::NO_ERROR)
{
return rollBackCreateIndex(errorString("WE: Error inserting Column Record: ", error), txnID,
createIndexStmt.fSessionID);
// logging::Message::Args args;
// logging::Message message(9);
// args.add("Error updating: ");
// args.add("calpont.sysconstraint");
// args.add("error number: ");
// args.add( error );
// message.format( args );
//
// result.result = CREATE_ERROR;
// result.message = message;
}
else
{
result.result = NO_ERROR;
}
}
VERBOSE_INFO("Writing column constraint meta data to SYSCONSTRAINTCOL");
WriteEngine::ColStruct colStructCol;
WriteEngine::ColTuple colTupleCol;
WriteEngine::ColStructList colStructsCol;
WriteEngine::ColTupleList colTuplesCol;
WriteEngine::ColValueList colValuesListCol;
CalpontSystemCatalog::TableName sysConsColTableName;
sysConsColTableName.schema = CALPONT_SCHEMA;
sysConsColTableName.table = SYSCONSTRAINTCOL_TABLE;
colValuesList.clear();
colTuples.clear();
isNull = false;
error = 0;
// get the columns for the SYSCONSTRAINTCOL table
ColumnList sysConsColColumns;
ColumnList::const_iterator sysConsCol_iterator;
getColumnsForTable(createIndexStmt.fSessionID, sysConsColTableName.schema, sysConsColTableName.table,
sysConsColColumns);
// write sysconstraintcol
sysConsCol_iterator = sysConsColColumns.begin();
std::string colData;
while (sysConsCol_iterator != sysConsColColumns.end())
{
column = *sysConsCol_iterator;
isNull = false;
if (SCHEMA_COL == column.tableColName.column)
{
colData = (createIndexStmt.fTableName)->fSchema;
colTupleCol.data = colData;
}
else if (TABLENAME_COL == column.tableColName.column)
{
colData = (createIndexStmt.fTableName)->fName;
colTupleCol.data = colData;
}
else if (COLNAME_COL == column.tableColName.column)
{
colData = createIndexStmt.fColumnNames[0];
colTupleCol.data = colData;
}
else if (CONSTRAINTNAME_COL == column.tableColName.column)
{
colData = createIndexStmt.fIndexName->fName;
colTupleCol.data = colData;
}
else
{
colTupleCol.data = column.colType.getNullValueForType();
isNull = true;
}
colStructCol.dataOid = column.oid;
colStructCol.colWidth = column.colType.colWidth > 8 ? 8 : column.colType.colWidth;
colStructCol.tokenFlag = false;
colStructCol.tokenFlag = column.colType.colWidth > 8 ? true : false;
colStructCol.colDataType = column.colType.colDataType;
if (column.colType.colWidth > 8 && !isNull)
{
colTupleCol.data = tokenizeData(txnID.id, result, column.colType, colTupleCol.data);
}
colStructsCol.push_back(colStructCol);
colTuplesCol.push_back(colTupleCol);
colValuesListCol.push_back(colTuplesCol);
colTuplesCol.pop_back();
++sysConsCol_iterator;
}
if (colStructsCol.size() != 0)
{
// fWriteEngine.setDebugLevel(WriteEngine::DEBUG_3);
// error = fWriteEngine.insertColumnRec( txnID.id, colStructsCol, colValuesListCol, ridList );
if (error != WriteEngine::NO_ERROR)
{
return rollBackCreateIndex(errorString("WE: Error inserting Column Record: ", error), txnID,
createIndexStmt.fSessionID);
/* logging::Message::Args args;
logging::Message message(9);
args.add("Error updating: ");
args.add("calpont.sysconstraintcol");
args.add("error number: ");
args.add( error );
message.format( args );
result.result = CREATE_ERROR;
result.message = message;*/
}
else
{
result.result = NO_ERROR;
}
}
}
VERBOSE_INFO("Creating index files");
err = fWriteEngine.createIndex(txnID.id, fIdxOID.treeOID, fIdxOID.listOID);
if (err)
{
return rollBackCreateIndex(errorString("Write engine failed to create the new index. ", err), txnID,
createIndexStmt.fSessionID);
}
// new if BULK_LOAD close
err = pop.populateIndex(result);
if (err)
{
return rollBackCreateIndex(errorString("Failed to populate index with current data. ", err), txnID,
createIndexStmt.fSessionID);
}
// Log the DDL statement.
logging::logDDL(createIndexStmt.fSessionID, txnID.id, createIndexStmt.fSql, createIndexStmt.fOwner);
DETAIL_INFO("Commiting transaction");
err = fWriteEngine.commit(txnID.id);
if (err)
{
return rollBackCreateIndex(errorString("Failed to commit the create index transaction. ", err), txnID,
createIndexStmt.fSessionID);
}
fSessionManager.committed(txnID);
// original if BULK_LOAD close }
} // try
catch (exception& ex)
{
result = rollBackCreateIndex(ex.what(), txnID, createIndexStmt.fSessionID);
}
catch (...)
{
string msg("CreateIndexProcessor::processPackage: caught unknown exception!");
result = rollBackCreateIndex(msg, txnID, createIndexStmt.fSessionID);
}
return result;
}
string CreateIndexProcessor::errorString(const string& msg, int error)
string CreateIndexProcessor::errorString(const string& msg, int error)
{
WriteEngine::WErrorCodes ec;
return string(msg + ec.errorString(error));
WriteEngine::WErrorCodes ec;
return string(msg + ec.errorString(error));
}
CreateIndexProcessor::DDLResult CreateIndexProcessor::rollBackCreateIndex(const string& error, BRM::TxnID& txnID, int sessionId)
CreateIndexProcessor::DDLResult CreateIndexProcessor::rollBackCreateIndex(const string& error,
BRM::TxnID& txnID, int sessionId)
{
cerr << "CreatetableProcessor::processPackage: " << error << endl;
DETAIL_INFO(error);
logging::Message::Args args;
logging::Message message(1);
args.add("Create Index Failed: ");
args.add( error );
args.add("");
args.add("");
message.format( args );
DDLResult result;
result.result = CREATE_ERROR;
result.message = message;
rollBackIndex(txnID, sessionId);
return result;
cerr << "CreatetableProcessor::processPackage: " << error << endl;
DETAIL_INFO(error);
logging::Message::Args args;
logging::Message message(1);
args.add("Create Index Failed: ");
args.add(error);
args.add("");
args.add("");
message.format(args);
DDLResult result;
result.result = CREATE_ERROR;
result.message = message;
rollBackIndex(txnID, sessionId);
return result;
}
void CreateIndexProcessor::rollBackIndex(BRM::TxnID& txnID, int sessionId)
{
fWriteEngine.rollbackTran(txnID.id, sessionId);
fWriteEngine.dropIndex(txnID.id, fIdxOID.listOID, fIdxOID.treeOID);
fWriteEngine.rollbackTran(txnID.id, sessionId);
fWriteEngine.dropIndex(txnID.id, fIdxOID.listOID, fIdxOID.treeOID);
try
{
//execplan::ObjectIDManager fObjectIDManager;
//fObjectIDManager.returnOIDs(fIdxOID.treeOID, fIdxOID.listOID);
}
catch ( exception& ex )
{
try
{
// execplan::ObjectIDManager fObjectIDManager;
// fObjectIDManager.returnOIDs(fIdxOID.treeOID, fIdxOID.listOID);
}
catch (exception& ex)
{
}
catch (...)
{
}
}
catch (... )
{ }
fSessionManager.rolledback(txnID);
fSessionManager.rolledback(txnID);
}
}
} // namespace ddlpackageprocessor

View File

@ -34,19 +34,19 @@ namespace ddlpackageprocessor
*/
class CreateIndexProcessor : public DDLPackageProcessor
{
public:
/** @brief process a create index statement
*
* @param createIndexStmt the create index statement
*/
DDLResult processPackage(ddlpackage::CreateIndexStatement& createIndexStmt);
public:
/** @brief process a create index statement
*
* @param createIndexStmt the create index statement
*/
DDLResult processPackage(ddlpackage::CreateIndexStatement& createIndexStmt);
protected:
DDLResult rollBackCreateIndex(const std::string& error, BRM::TxnID& txnID, int sessionId);
void rollBackIndex(BRM::TxnID& txnID);
std::string errorString(const std::string& msg, int error);
private:
protected:
DDLResult rollBackCreateIndex(const std::string& error, BRM::TxnID& txnID, int sessionId);
void rollBackIndex(BRM::TxnID& txnID);
std::string errorString(const std::string& msg, int error);
private:
};
} //namespace ddlpackageprocessor
} // namespace ddlpackageprocessor

File diff suppressed because it is too large Load Diff

View File

@ -33,30 +33,29 @@
namespace ddlpackageprocessor
{
/** @brief specialization of a DDLPackageProcessor
* for interacting with the Write Engine
* to process create table ddl statements.
*/
class CreateTableProcessor : public DDLPackageProcessor
{
public:
public:
CreateTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm)
{
}
/** @brief process a create table statement
*
* @param createTableStmt the CreateTableStatement
*/
EXPORT DDLResult processPackage(ddlpackage::CreateTableStatement& createTableStmt);
CreateTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a create table statement
*
* @param createTableStmt the CreateTableStatement
*/
EXPORT DDLResult processPackage(ddlpackage::CreateTableStatement& createTableStmt);
protected:
void rollBackCreateTable(const std::string& error, BRM::TxnID txnID, int sessionId, ddlpackage::TableDef& tableDef, DDLResult& result);
private:
protected:
void rollBackCreateTable(const std::string& error, BRM::TxnID txnID, int sessionId,
ddlpackage::TableDef& tableDef, DDLResult& result);
private:
};
} // namespace ddlpackageprocessor
} // namespace ddlpackageprocessor
#undef EXPORT

View File

@ -51,197 +51,194 @@ using namespace messageqcpp;
namespace ddlpackageprocessor
{
bool DDLIndexPopulator::populateIndex(DDLPackageProcessor::DDLResult& result)
{
if (makeIndexStructs() )
insertIndex();
if (makeIndexStructs())
insertIndex();
result = fResult;
return NO_ERROR != fResult.result;
result = fResult;
return NO_ERROR != fResult.result;
}
bool DDLIndexPopulator::makeIndexStructs( )
bool DDLIndexPopulator::makeIndexStructs()
{
CalpontSelectExecutionPlan csep;
makeCsep(csep);
ResourceManager* rm;
CalpontSelectExecutionPlan csep;
makeCsep(csep);
ResourceManager* rm;
if (! fEC)
if (!fEC)
{
fEC = DistributedEngineComm::instance(rm);
fEC->Open();
}
SJLP jbl = joblist::JobListFactory::makeJobList(&csep, rm);
boost::shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog(fSessionID);
csc->identity(CalpontSystemCatalog::EC);
jbl->putEngineComm(fEC);
/*
ResultManager * result = jbl->GetResultManager();
result->setRunning(1);
jbl->Execute(); */
jbl->doQuery();
CalpontSystemCatalog::TableName tableName;
tableName.schema = fTable.fSchema;
tableName.table = fTable.fName;
CalpontSystemCatalog::OID tableOid = (csc->tableRID(tableName)).objnum;
CalpontSystemCatalog::NJLSysDataList sysDataList;
for (;;)
{
TableBand band;
band = jbl->projectTable(tableOid);
if (band.getRowCount() == 0)
{
fEC = DistributedEngineComm::instance(rm);
fEC->Open();
// No more bands, table is done
break;
}
SJLP jbl = joblist::JobListFactory::makeJobList(&csep, rm);
band.convertToSysDataList(sysDataList, csc);
break;
}
boost::shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog( fSessionID );
csc->identity(CalpontSystemCatalog::EC);
// size_t cnt = fColNames.size();
size_t i = 0;
vector<ColumnResult*>::const_iterator it;
vector<int>::const_iterator oid_iter;
jbl->putEngineComm(fEC);
/*
ResultManager * result = jbl->GetResultManager();
result->setRunning(1);
jbl->Execute(); */
jbl->doQuery();
for (it = sysDataList.begin(); it != sysDataList.end(); it++)
{
if (isUnique())
fUniqueColResultList.push_back(*it);
CalpontSystemCatalog::TableName tableName;
tableName.schema = fTable.fSchema;
tableName.table = fTable.fName;
CalpontSystemCatalog::OID tableOid = (csc->tableRID ( tableName )).objnum;
CalpontSystemCatalog::NJLSysDataList sysDataList;
for (;;)
for (oid_iter = fOidList.begin(); oid_iter != fOidList.end(); oid_iter++)
{
TableBand band;
band = jbl->projectTable(tableOid);
if (band.getRowCount() == 0)
{
// No more bands, table is done
break;
}
band.convertToSysDataList(sysDataList, csc);
break;
if ((*it)->ColumnOID() == *oid_iter)
{
CalpontSystemCatalog::ColType coltype = makeIdxStruct(*it, fColNames.size(), csc);
addColumnData(*it, coltype, i);
}
}
//size_t cnt = fColNames.size();
size_t i = 0;
vector<ColumnResult*>::const_iterator it;
vector<int>::const_iterator oid_iter;
for (it = sysDataList.begin(); it != sysDataList.end(); it++)
{
if (isUnique())
fUniqueColResultList.push_back(*it);
for ( oid_iter = fOidList.begin(); oid_iter != fOidList.end(); oid_iter++ )
{
if ( (*it)->ColumnOID() == *oid_iter )
{
CalpontSystemCatalog::ColType coltype = makeIdxStruct(*it, fColNames.size(), csc);
addColumnData(*it, coltype, i);
}
}
i++;
}
return (fIdxValueList.size() && NO_ERROR == fResult.result );
i++;
}
return (fIdxValueList.size() && NO_ERROR == fResult.result);
}
void DDLIndexPopulator::makeCsep(CalpontSelectExecutionPlan& csep)
void DDLIndexPopulator::makeCsep(CalpontSelectExecutionPlan& csep)
{
csep.sessionID(fSessionID);
csep.sessionID(fSessionID);
csep.txnID(fTxnID);
csep.verID(fSessionManager->verID());
csep.txnID(fTxnID);
csep.verID(fSessionManager->verID());
CalpontSelectExecutionPlan::ReturnedColumnList colList;
CalpontSelectExecutionPlan::ColumnMap colMap;
CalpontSystemCatalog::TableColName tableColName;
CalpontSystemCatalog::OID oid;
tableColName.schema = fTable.fSchema;
tableColName.table = fTable.fName;
boost::shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog(fSessionID);
string tableName(fTable.fSchema + "." + fTable.fName + ".");
CalpontSelectExecutionPlan::ReturnedColumnList colList;
CalpontSelectExecutionPlan::ColumnMap colMap;
CalpontSystemCatalog::TableColName tableColName;
CalpontSystemCatalog::OID oid;
tableColName.schema = fTable.fSchema;
tableColName.table = fTable.fName;
boost::shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog( fSessionID );
string tableName(fTable.fSchema + "." + fTable.fName + ".");
ColumnNameList::const_iterator cend = fColNames.end();
ColumnNameList::const_iterator cend = fColNames.end();
for (ColumnNameList::const_iterator cname = fColNames.begin(); cname != cend; ++cname)
{
string fullColName(tableName + *cname);
SRCP srcp(new SimpleColumn(fullColName, fSessionID));
colList.push_back(srcp);
tableColName.column = *cname;
oid = csc->lookupOID(tableColName);
fOidList.push_back(oid);
colMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(fullColName, srcp));
}
for (ColumnNameList::const_iterator cname = fColNames.begin(); cname != cend; ++cname)
{
string fullColName(tableName + *cname);
SRCP srcp(new SimpleColumn (fullColName, fSessionID));
colList.push_back(srcp);
tableColName.column = *cname;
oid = csc->lookupOID( tableColName );
fOidList.push_back( oid );
colMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(fullColName, srcp));
}
csep.columnMap (colMap);
csep.returnedCols (colList);
csep.columnMap(colMap);
csep.returnedCols(colList);
}
CalpontSystemCatalog::ColType DDLIndexPopulator::makeIdxStruct(const ColumnResult* cr, size_t cols, boost::shared_ptr<CalpontSystemCatalog> csc )
CalpontSystemCatalog::ColType DDLIndexPopulator::makeIdxStruct(const ColumnResult* cr, size_t cols,
boost::shared_ptr<CalpontSystemCatalog> csc)
{
IdxStruct idx;
idx.treeOid = fIdxOID.treeOID;
idx.listOid = fIdxOID.listOID;
idx.multiColFlag = cols > 1;
CalpontSystemCatalog::ColType coltype = csc->colType(cr->ColumnOID());
idx.idxDataType = static_cast<CalpontSystemCatalog::ColDataType>(coltype.colDataType);
IdxStruct idx;
idx.treeOid = fIdxOID.treeOID;
idx.listOid = fIdxOID.listOID;
idx.multiColFlag = cols > 1;
CalpontSystemCatalog::ColType coltype = csc->colType(cr->ColumnOID());
idx.idxDataType = static_cast<CalpontSystemCatalog::ColDataType>(coltype.colDataType);
if (isDictionaryType(coltype) )
{
idx.idxWidth = fTOKENSIZE;
idx.idxType = WR_CHAR;
}//@bug 410: index sizes are either 1, 4 or 8
else if (exeplan::isCharType(coltype))
{
if (1 == coltype.colWidth) idx.idxWidth = 1;
else idx.idxWidth = (coltype.colWidth > 4) ? 8 : 4;
if (isDictionaryType(coltype))
{
idx.idxWidth = fTOKENSIZE;
idx.idxType = WR_CHAR;
} //@bug 410: index sizes are either 1, 4 or 8
else if (exeplan::isCharType(coltype))
{
if (1 == coltype.colWidth)
idx.idxWidth = 1;
else
idx.idxWidth = (coltype.colWidth > 4) ? 8 : 4;
idx.idxType = WR_CHAR;
idx.idxType = WR_CHAR;
}
else
idx.idxWidth = coltype.colWidth;
fIdxStructList.push_back(idx);
return coltype;
}
void DDLIndexPopulator::addColumnData(const execplan::ColumnResult* cr,
const CalpontSystemCatalog::ColType colType, int added)
{
WriteEngine::IdxTupleList tupleList;
WriteEngine::IdxTuple tuple;
for (int i = 0; i < cr->dataCount(); ++i)
{
WriteEngine::IdxTuple tuple;
convertColData(cr, i, colType, tuple);
if (checkConstraints(tuple, colType, i, added))
{
tupleList.push_back(tuple);
if (!added)
fRidList.push_back(cr->GetRid(i));
}
else
idx.idxWidth = coltype.colWidth;
break;
}
fIdxStructList.push_back(idx);
return coltype;
if (tupleList.size())
fIdxValueList.push_back(tupleList);
}
void DDLIndexPopulator::addColumnData(const execplan::ColumnResult* cr, const CalpontSystemCatalog::ColType colType, int added)
void DDLIndexPopulator::convertColData(const execplan::ColumnResult* cr, int idx,
const CalpontSystemCatalog::ColType& colType,
WriteEngine::IdxTuple& tuple)
{
WriteEngine::IdxTupleList tupleList;
WriteEngine::IdxTuple tuple;
for (int i = 0; i < cr->dataCount(); ++i)
{
WriteEngine::IdxTuple tuple ;
convertColData( cr, i, colType, tuple);
if (checkConstraints( tuple, colType, i, added))
{
tupleList.push_back(tuple);
if (! added )
fRidList.push_back(cr->GetRid(i));
}
else
break;
}
if (tupleList.size())
fIdxValueList.push_back(tupleList);
if (isDictionaryType(colType))
{
/* tuple.data = tokenizeData ( colType, cr->GetStringData(idx) );*/
/* tuple.data = tokenizeData ( cr->GetRid(idx) );*/
tuple.data = convertTokenData(cr->GetStringData(idx));
}
else
tuple.data = convertData(colType, cr, idx);
}
void DDLIndexPopulator::convertColData(const execplan::ColumnResult* cr, int idx, const CalpontSystemCatalog::ColType& colType, WriteEngine::IdxTuple& tuple)
boost::any DDLIndexPopulator::convertTokenData(const std::string& data)
{
if (isDictionaryType(colType))
{
/* tuple.data = tokenizeData ( colType, cr->GetStringData(idx) );*/
/* tuple.data = tokenizeData ( cr->GetRid(idx) );*/
tuple.data = convertTokenData(cr->GetStringData(idx));
}
else tuple.data = convertData( colType, cr, idx);
}
boost::any DDLIndexPopulator::convertTokenData( const std::string& data )
{
string strData((size_t)fTOKENSIZE < data.length() ? data.substr(0, fTOKENSIZE) : data);
return strData;
string strData((size_t)fTOKENSIZE < data.length() ? data.substr(0, fTOKENSIZE) : data);
return strData;
}
#if 0
@ -269,331 +266,304 @@ bool DDLIndexPopulator::openColumnFile(WriteEngine::OID oid)
#endif
// Workaround to get original column token and not "retokenize" the string value
boost::any DDLIndexPopulator::tokenizeData( WriteEngine::RID rid )
boost::any DDLIndexPopulator::tokenizeData(WriteEngine::RID rid)
{
int64_t byteOffset = rid * fTOKENSIZE;
ByteStream::byte inbuf[fTOKENSIZE];
fColumnFile.seekg(byteOffset, ios::beg);
fColumnFile.read(reinterpret_cast<char*>(inbuf), fTOKENSIZE);
int64_t byteOffset = rid * fTOKENSIZE;
ByteStream::byte inbuf[fTOKENSIZE];
fColumnFile.seekg(byteOffset, ios::beg);
fColumnFile.read(reinterpret_cast<char*>(inbuf), fTOKENSIZE);
WriteEngine::Token token;
memcpy(&token, inbuf, fTOKENSIZE);
return token;
WriteEngine::Token token;
memcpy(&token, inbuf, fTOKENSIZE);
return token;
}
boost::any DDLIndexPopulator::tokenizeData( const execplan::CalpontSystemCatalog::ColType& colType, const std::string& data )
boost::any DDLIndexPopulator::tokenizeData(const execplan::CalpontSystemCatalog::ColType& colType,
const std::string& data)
{
WriteEngine::DctnryTuple dictTuple;
WriteEngine::DctnryTuple dictTuple;
if ( data.length() > (unsigned int)colType.colWidth )
if (data.length() > (unsigned int)colType.colWidth)
{
logError("Insert value is too large for column");
}
else
{
WriteEngine::DctnryStruct dictStruct;
dictStruct.treeOid = colType.ddn.treeOID;
dictStruct.listOid = colType.ddn.listOID;
dictStruct.dctnryOid = colType.ddn.dictOID;
dictTuple.sigValue = data.c_str();
dictTuple.sigSize = data.length();
int error = NO_ERROR;
if (NO_ERROR != (error = fWriteEngine->tokenize(fTxnID, dictStruct, dictTuple)))
{
logError("Insert value is too large for column");
logError("Tokenization failed", error);
}
else
{
WriteEngine::DctnryStruct dictStruct;
dictStruct.treeOid = colType.ddn.treeOID;
dictStruct.listOid = colType.ddn.listOID;
dictStruct.dctnryOid = colType.ddn.dictOID;
dictTuple.sigValue = data.c_str();
dictTuple.sigSize = data.length();
int error = NO_ERROR;
}
if ( NO_ERROR != (error = fWriteEngine->tokenize( fTxnID, dictStruct, dictTuple)) )
{
logError("Tokenization failed", error);
}
}
return dictTuple.token;
return dictTuple.token;
}
boost::any DDLIndexPopulator::convertData(const CalpontSystemCatalog::ColType& colType, const execplan::ColumnResult* cr, int idx )
boost::any DDLIndexPopulator::convertData(const CalpontSystemCatalog::ColType& colType,
const execplan::ColumnResult* cr, int idx)
{
uint64_t data = cr->GetData(idx);
uint64_t data = cr->GetData(idx);
switch ( colType.colDataType )
switch (colType.colDataType)
{
case CalpontSystemCatalog::BIT:
case execplan::CalpontSystemCatalog::TINYINT: return *reinterpret_cast<char*>(&data);
case execplan::CalpontSystemCatalog::SMALLINT: return *reinterpret_cast<short*>(&data);
case execplan::CalpontSystemCatalog::DATE: // @bug 375
case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::INT: return *reinterpret_cast<int*>(&data);
case execplan::CalpontSystemCatalog::DATETIME: // @bug 375
case execplan::CalpontSystemCatalog::TIME:
case execplan::CalpontSystemCatalog::TIMESTAMP:
case execplan::CalpontSystemCatalog::BIGINT: return *reinterpret_cast<long long*>(&data);
case execplan::CalpontSystemCatalog::DECIMAL:
{
case CalpontSystemCatalog::BIT:
case execplan::CalpontSystemCatalog::TINYINT:
return *reinterpret_cast<char*>(&data);
if (colType.colWidth <= CalpontSystemCatalog::FOUR_BYTE)
return *reinterpret_cast<short*>(&data);
case execplan::CalpontSystemCatalog::SMALLINT:
return *reinterpret_cast<short*>(&data);
else if (colType.colWidth <= 9)
return *reinterpret_cast<int*>(&data);
case execplan::CalpontSystemCatalog::DATE: // @bug 375
case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::INT:
return *reinterpret_cast<int*>(&data);
case execplan::CalpontSystemCatalog::DATETIME: // @bug 375
case execplan::CalpontSystemCatalog::TIME:
case execplan::CalpontSystemCatalog::TIMESTAMP:
case execplan::CalpontSystemCatalog::BIGINT:
return *reinterpret_cast<long long*>(&data);
case execplan::CalpontSystemCatalog::DECIMAL:
{
if (colType.colWidth <= CalpontSystemCatalog::FOUR_BYTE) return *reinterpret_cast<short*>(&data);
else if (colType.colWidth <= 9) return *reinterpret_cast<int*>(&data);
else return *reinterpret_cast<long long*>(&data);
}
case execplan::CalpontSystemCatalog::FLOAT:
return *reinterpret_cast<float*>(&data);
case execplan::CalpontSystemCatalog::DOUBLE:
return *reinterpret_cast<double*>(&data);
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::VARCHAR:
{
string strData(cr->GetStringData(idx) );
return *reinterpret_cast<string*>(&strData);
}
default:
break;
else
return *reinterpret_cast<long long*>(&data);
}
logError("Invalid column type");
throw std::runtime_error("Invalid data");
case execplan::CalpontSystemCatalog::FLOAT: return *reinterpret_cast<float*>(&data);
return *reinterpret_cast<long long*>(&data);
case execplan::CalpontSystemCatalog::DOUBLE: return *reinterpret_cast<double*>(&data);
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::VARCHAR:
{
string strData(cr->GetStringData(idx));
return *reinterpret_cast<string*>(&strData);
}
default: break;
}
logError("Invalid column type");
throw std::runtime_error("Invalid data");
return *reinterpret_cast<long long*>(&data);
}
void DDLIndexPopulator::insertIndex( )
void DDLIndexPopulator::insertIndex()
{
// @bug 359 use bulk load build
int rc = (1 < fIdxStructList.size()) ?
(void)0
: (void)0;
if (rc)
logError("Error inserting index values", rc );
// @bug 359 use bulk load build
int rc = (1 < fIdxStructList.size()) ? (void)0 : (void)0;
if (rc)
logError("Error inserting index values", rc);
}
bool DDLIndexPopulator::isDictionaryType(const CalpontSystemCatalog::ColType& colType)
{
return ( (CalpontSystemCatalog::CHAR == colType.colDataType && 8 < colType.colWidth )
|| (CalpontSystemCatalog::VARCHAR == colType.colDataType && 7 < colType.colWidth )
|| (CalpontSystemCatalog::DECIMAL == colType.colDataType && 18 < colType.precision ));
return ((CalpontSystemCatalog::CHAR == colType.colDataType && 8 < colType.colWidth) ||
(CalpontSystemCatalog::VARCHAR == colType.colDataType && 7 < colType.colWidth) ||
(CalpontSystemCatalog::DECIMAL == colType.colDataType && 18 < colType.precision));
}
bool DDLIndexPopulator::checkConstraints( const IdxTuple& data, const CalpontSystemCatalog::ColType& ctype, int i, int column)
bool DDLIndexPopulator::checkConstraints(const IdxTuple& data, const CalpontSystemCatalog::ColType& ctype,
int i, int column)
{
switch (fConstraint)
{
case DDL_INVALID_CONSTRAINT: return true;
switch ( fConstraint )
{
case DDL_INVALID_CONSTRAINT:
return true;
case DDL_UNIQUE:
case DDL_PRIMARY_KEY:
if ((size_t)column + 1 < fColNames.size())
return true;
case DDL_UNIQUE:
case DDL_PRIMARY_KEY:
if ((size_t)column + 1 < fColNames.size() )
return true;
return checkUnique(i, ctype);
return checkUnique( i, ctype );
case DDL_NOT_NULL: return checkNotNull(data, ctype);
case DDL_NOT_NULL:
return checkNotNull( data, ctype );
case DDL_CHECK:
return checkCheck( data, ctype );
default:
return true; //?
}
case DDL_CHECK: return checkCheck(data, ctype);
default: return true; //?
}
}
// Check if the row of data at idx is already in fUniqueColResultList
bool DDLIndexPopulator::checkUnique( int idx, const CalpontSystemCatalog::ColType& colType )
bool DDLIndexPopulator::checkUnique(int idx, const CalpontSystemCatalog::ColType& colType)
{
if (0 == idx)
return true;
if (0 == idx)
return true;
//Get row of data as each column result data at idx
size_t indexSize = fColNames.size();
vector <uint64_t> rowIntData(indexSize);
vector <string> rowStrData(indexSize);
// Get row of data as each column result data at idx
size_t indexSize = fColNames.size();
vector<uint64_t> rowIntData(indexSize);
vector<string> rowStrData(indexSize);
for (size_t i = 0; i < indexSize; ++i)
for (size_t i = 0; i < indexSize; ++i)
{
// if ( isStringType(fUniqueColResultList[i]->columnType()) )
if (isStringType(colType.colDataType))
rowStrData[i] = fUniqueColResultList[i]->GetStringData(idx);
else
rowIntData[i] = fUniqueColResultList[i]->GetData(idx);
}
// check if each value in the idx row is equal to each value in a previous row
// i is the row; j is the column.
bool unique = true;
for (int i = 0; i < idx && unique; ++i)
{
bool equal = true;
for (size_t j = 0; j < indexSize && equal; ++j)
{
//if ( isStringType(fUniqueColResultList[i]->columnType()) )
if ( isStringType(colType.colDataType) )
rowStrData[i] = fUniqueColResultList[i]->GetStringData(idx);
else
rowIntData[i] = fUniqueColResultList[i]->GetData(idx);
if (isStringType(colType.colDataType))
{
equal = fUniqueColResultList[j]->GetStringData(i) == rowStrData[j];
}
else
{
equal = (static_cast<uint64_t>(fUniqueColResultList[j]->GetData(i)) == rowIntData[j]);
}
}
//check if each value in the idx row is equal to each value in a previous row
// i is the row; j is the column.
bool unique = true;
unique = !equal;
}
for (int i = 0; i < idx && unique; ++i)
{
bool equal = true;
if (!unique)
{
stringstream ss;
ss << idx;
logError("Unique Constraint violated on row: " + ss.str());
}
for (size_t j = 0; j < indexSize && equal; ++j)
{
if ( isStringType(colType.colDataType) )
{
equal = fUniqueColResultList[j]->GetStringData(i) == rowStrData[j];
}
else
{
equal = (static_cast<uint64_t>(fUniqueColResultList[j]->GetData(i)) == rowIntData[j]);
}
}
unique = ! equal;
}
if (! unique)
{
stringstream ss;
ss << idx;
logError("Unique Constraint violated on row: " + ss.str() );
}
return unique;
return unique;
}
bool DDLIndexPopulator::checkNotNull(const IdxTuple& data, const CalpontSystemCatalog::ColType& colType)
{
any nullvalue = DDLNullValueForType(colType);
bool isNull = false;
any nullvalue = DDLNullValueForType(colType);
bool isNull = false;
switch (colType.colDataType)
{
case CalpontSystemCatalog::BIT: break;
switch ( colType.colDataType )
case execplan::CalpontSystemCatalog::TINYINT:
isNull = any_cast<char>(data.data) == any_cast<char>(nullvalue);
break;
case execplan::CalpontSystemCatalog::SMALLINT:
isNull = any_cast<short>(data.data) == any_cast<short>(nullvalue);
break;
case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::INT:
isNull = any_cast<int>(data.data) == any_cast<int>(nullvalue);
break;
case execplan::CalpontSystemCatalog::BIGINT:
isNull = any_cast<long long>(data.data) == any_cast<long long>(nullvalue);
break;
case execplan::CalpontSystemCatalog::DECIMAL:
{
case CalpontSystemCatalog::BIT:
break;
if (colType.colWidth <= CalpontSystemCatalog::FOUR_BYTE)
isNull = any_cast<short>(data.data) == any_cast<short>(nullvalue);
else if (colType.colWidth <= 9)
isNull = any_cast<int>(data.data) == any_cast<int>(nullvalue);
else if (colType.colWidth <= 18)
isNull = any_cast<long long>(data.data) == any_cast<long long>(nullvalue);
else
isNull =
compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue));
case execplan::CalpontSystemCatalog::TINYINT:
isNull = any_cast<char>(data.data) == any_cast<char>(nullvalue);
break;
case execplan::CalpontSystemCatalog::SMALLINT:
isNull = any_cast<short>(data.data) == any_cast<short>(nullvalue);
break;
case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::INT:
isNull = any_cast<int>(data.data) == any_cast<int>(nullvalue);
break;
case execplan::CalpontSystemCatalog::BIGINT:
isNull = any_cast<long long>(data.data) == any_cast<long long>(nullvalue);
break;
case execplan::CalpontSystemCatalog::DECIMAL:
{
if (colType.colWidth <= CalpontSystemCatalog::FOUR_BYTE)
isNull = any_cast<short>(data.data) == any_cast<short>(nullvalue);
else if (colType.colWidth <= 9)
isNull = any_cast<int>(data.data) == any_cast<int>(nullvalue);
else if (colType.colWidth <= 18)
isNull = any_cast<long long>(data.data) == any_cast<long long>(nullvalue);
else
isNull = compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue));
break;
}
case execplan::CalpontSystemCatalog::FLOAT:
isNull = any_cast<float>(data.data) == any_cast<float>(nullvalue);
break;
case execplan::CalpontSystemCatalog::DOUBLE:
isNull = any_cast<double>(data.data) == any_cast<double>(nullvalue);
break;
case execplan::CalpontSystemCatalog::DATE:
isNull = any_cast<int>(data.data) == any_cast<int>(nullvalue);
break;
case execplan::CalpontSystemCatalog::DATETIME:
case execplan::CalpontSystemCatalog::TIME:
case execplan::CalpontSystemCatalog::TIMESTAMP:
isNull = any_cast<long long>(data.data) == any_cast<long long>(nullvalue);
break;
case execplan::CalpontSystemCatalog::CHAR:
{
if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE)
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
else if (colType.colWidth == execplan::CalpontSystemCatalog::TWO_BYTE)
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
else if (colType.colWidth <= execplan::CalpontSystemCatalog::FOUR_BYTE)
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
else
isNull = compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue));
break;
}
case execplan::CalpontSystemCatalog::VARCHAR:
{
if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE)
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
else if (colType.colWidth < execplan::CalpontSystemCatalog::FOUR_BYTE)
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
else
isNull = compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue));
break;
}
default:
throw std::runtime_error("getNullValueForType: unkown column data type");
break;
}
if (isNull)
logError("Null value not allowed in index");
case execplan::CalpontSystemCatalog::FLOAT:
isNull = any_cast<float>(data.data) == any_cast<float>(nullvalue);
break;
return ! isNull;
case execplan::CalpontSystemCatalog::DOUBLE:
isNull = any_cast<double>(data.data) == any_cast<double>(nullvalue);
break;
case execplan::CalpontSystemCatalog::DATE:
isNull = any_cast<int>(data.data) == any_cast<int>(nullvalue);
break;
case execplan::CalpontSystemCatalog::DATETIME:
case execplan::CalpontSystemCatalog::TIME:
case execplan::CalpontSystemCatalog::TIMESTAMP:
isNull = any_cast<long long>(data.data) == any_cast<long long>(nullvalue);
break;
case execplan::CalpontSystemCatalog::CHAR:
{
if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE)
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
else if (colType.colWidth == execplan::CalpontSystemCatalog::TWO_BYTE)
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
else if (colType.colWidth <= execplan::CalpontSystemCatalog::FOUR_BYTE)
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
else
isNull =
compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue));
break;
}
case execplan::CalpontSystemCatalog::VARCHAR:
{
if (colType.colWidth == execplan::CalpontSystemCatalog::ONE_BYTE)
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
else if (colType.colWidth < execplan::CalpontSystemCatalog::FOUR_BYTE)
isNull = any_cast<string>(data.data) == any_cast<string>(nullvalue);
else
isNull =
compareToken(any_cast<WriteEngine::Token>(data.data), any_cast<WriteEngine::Token>(nullvalue));
break;
}
default: throw std::runtime_error("getNullValueForType: unkown column data type");
}
if (isNull)
logError("Null value not allowed in index");
return !isNull;
}
void DDLIndexPopulator::logError(const string& msg, int error)
void DDLIndexPopulator::logError(const string& msg, int error)
{
Message::Args args;
Message message(9);
args.add((string)__FILE__ + ": ");
args.add(msg);
Message::Args args;
Message message(9);
args.add((string)__FILE__ + ": ");
args.add(msg);
if (error)
{
args.add("Error number: ");
args.add(error);
}
if (error)
{
args.add("Error number: ");
args.add(error);
}
message.format(args);
message.format( args );
fResult.result = DDLPackageProcessor::CREATE_ERROR;
fResult.message = message;
fResult.result = DDLPackageProcessor::CREATE_ERROR;
fResult.message = message;
}
} //namespace
} // namespace ddlpackageprocessor

View File

@ -40,7 +40,6 @@
#include <boost/any.hpp>
#include <boost/tuple/tuple.hpp>
#include "joblistfactory.h"
namespace joblist
@ -50,253 +49,258 @@ class DistributedEngineComm;
namespace ddlpackageprocessor
{
/** @brief Populate an new Index
* implementation of a DDLPopulator
*/
class DDLIndexPopulator
{
public:
/** @brief constructor
*
*/
DDLIndexPopulator(WriteEngine::WriteEngineWrapper* writeEngine, execplan::SessionManager* sessionManager,
uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID,
DDLPackageProcessor::DDLResult& result, const DDLPackageProcessor::IndexOID& idxOID,
const ddlpackage::ColumnNameList& colNames, const ddlpackage::QualifiedName& table,
const ddlpackage::DDL_CONSTRAINTS constraint, const DDLPackageProcessor::DebugLevel debug)
: fWriteEngine(writeEngine)
, fSessionManager(sessionManager)
, fSessionID(sessionID)
, fTxnID(txnID)
, fResult(result)
, fIdxOID(idxOID)
, fColNames(colNames)
, fTable(table)
, fDebugLevel(debug)
, fEC(0)
, fRidList()
, fIdxStructList()
, fIdxValueList()
,
/* fTOKENSIZE(sizeof(WriteEngine::Token) ) {}*/
fConstraint(constraint)
, fUniqueColResultList()
{
}
public:
/** @brief constructor
*
*/
DDLIndexPopulator(WriteEngine::WriteEngineWrapper* writeEngine,
execplan::SessionManager* sessionManager,
uint32_t sessionID,
execplan::CalpontSystemCatalog::SCN txnID,
DDLPackageProcessor::DDLResult& result,
const DDLPackageProcessor::IndexOID& idxOID,
const ddlpackage::ColumnNameList& colNames,
const ddlpackage::QualifiedName& table,
const ddlpackage::DDL_CONSTRAINTS constraint,
const DDLPackageProcessor::DebugLevel debug):
fWriteEngine(writeEngine), fSessionManager(sessionManager),
fSessionID(sessionID), fTxnID(txnID), fResult(result),
fIdxOID(idxOID), fColNames(colNames), fTable(table), fDebugLevel(debug),
fEC(0), fRidList(), fIdxStructList(), fIdxValueList(),
/* fTOKENSIZE(sizeof(WriteEngine::Token) ) {}*/
fConstraint(constraint), fUniqueColResultList() {}
/** @brief destructor
*/
virtual ~DDLIndexPopulator(){};
/** @brief Is it required to debug
*/
const bool isDebug(const DDLPackageProcessor::DebugLevel level) const
{
return level <= fDebugLevel;
}
/** @brief destructor
*/
virtual ~DDLIndexPopulator() { };
/** @brief Get debug level
*/
const DDLPackageProcessor::DebugLevel getDebugLevel() const
{
return fDebugLevel;
}
/** @brief set distributedEngineComm pointer ( for
* loading index).
*/
void setEngineComm(joblist::DistributedEngineComm* ec)
{
fEC = ec;
}
void setIdxOID(const DDLPackageProcessor::IndexOID& idxOID)
{
fIdxOID = idxOID;
}
/** @brief Is it required to debug
*/
const bool isDebug( const DDLPackageProcessor::DebugLevel level ) const
DDLPackageProcessor::DDLResult getResult() const
{
return fResult;
}
/** @brief add data to the index from the statement
*
* populate the newly made index with data in the index columns.
* returns if there was an error.
*/
bool populateIndex(DDLPackageProcessor::DDLResult& result);
/** @brief returns if dictionary type
*
* determines if coltype is dictionary type based on type and size
*/
bool isDictionaryType(const execplan::CalpontSystemCatalog::ColType& ctype);
void setConstraint(ddlpackage::DDL_CONSTRAINTS constraint);
protected:
/** @brief make the structures to update the index
*
* builds and executes a query to retrieve all the data from the index columns
* to make the structures required by WriteEngine::updateIndex
* returns if there is data and no error
*/
bool makeIndexStructs();
/** @brief make the IdxStruct
*
* Fills in the values from the column result and calpont system catalog for
* the WriteEngine::IdxStruct
*/
execplan::CalpontSystemCatalog::ColType makeIdxStruct(
const execplan::ColumnResult* cr, size_t cols, boost::shared_ptr<execplan::CalpontSystemCatalog> csc);
/** @brief add the column result data to the value list
*
* Check contraints on each data item and adds it to a tuple list.
* Adds the rid to the rid list if it is the first column (not been added)
* Adds the completed tuple list to the fValueList
*/
void addColumnData(const execplan::ColumnResult* cr, const execplan::CalpontSystemCatalog::ColType ctype,
int added);
/** @brief insert data into index.
*
* updates the index with the data using the appropriate write engine method
* based on multi column. Sets result to error if there is one.
*/
void insertIndex();
private:
DDLIndexPopulator(const DDLIndexPopulator&);
void operator=(const DDLIndexPopulator&);
/** @brief makes Calpont Select Execution Plan
*
* builds csep to select data from all columns from fColNames
*/
void makeCsep(execplan::CalpontSelectExecutionPlan& csep);
/** @brief return if ColumnResult string type
*
* Uses same logic as ColumnResult from type to return getStringData (true)
* or getData (false).
*/
bool isStringType(int type) const
{
return (type == execplan::CalpontSystemCatalog::CHAR || type == execplan::CalpontSystemCatalog::VARCHAR ||
type == execplan::CalpontSystemCatalog::FLOAT || type == execplan::CalpontSystemCatalog::DOUBLE ||
type == execplan::CalpontSystemCatalog::UFLOAT ||
type == execplan::CalpontSystemCatalog::UDOUBLE);
}
/** @brief converts column result data
*
* Converts or tokenizes data, depending on column type
*/
void convertColData(const execplan::ColumnResult* cr, int idx,
const execplan::CalpontSystemCatalog::ColType& cType, WriteEngine::IdxTuple& tuple);
/** @brief converts non token data to its original type
*/
boost::any convertData(const execplan::CalpontSystemCatalog::ColType& colType,
const execplan::ColumnResult* cr, int idx);
/** @brief returns token for string data
*
* There are two methods, the one using the rid is a workaround.
* Use the method that passes string data when WriteEngine::tokenize is
* able to return an existing token for a string. The rid method reads
* the column file directly.
*/
boost::any tokenizeData(const execplan::CalpontSystemCatalog::ColType& colType, const std::string& data);
boost::any tokenizeData(WriteEngine::RID rid);
/** @brief convert token data
*
* Indexes will use the first 8 bytes of a token type value instead
* of a token.
*/
boost::any convertTokenData(const std::string& data);
/** @brief opens the column file for the oid
*
* This method is needed only as long as the class is using the rid
* tokenizeData method. The fColumnFile and this method are no longer
* needed when the WriteEngine::tokenize method can be used.
*/
// bool openColumnFile(WriteEngine::OID oid);
/** @brief returns if data violated its constraint
*
* checks data according to contraint in coltype and sets result to error
* if constraint violated. Returns if no error.
*/
bool checkConstraints(const WriteEngine::IdxTuple& data,
const execplan::CalpontSystemCatalog::ColType& ctype, int i, int column);
/** @brief returns if data not null
*
* Returns false if data is null and sets result to error
*/
bool checkNotNull(const WriteEngine::IdxTuple& data, const execplan::CalpontSystemCatalog::ColType& ctype);
/** @brief returns if data is not unique
*
* Returns false if data row is found more than once in columns and sets result to error
*/
bool checkUnique(int i, const execplan::CalpontSystemCatalog::ColType& colType);
bool checkCheck(const WriteEngine::IdxTuple& data,
const execplan::CalpontSystemCatalog::ColType& ctype) const
{
return true;
}
bool isUnique()
{
return ddlpackage::DDL_PRIMARY_KEY == fConstraint || ddlpackage::DDL_UNIQUE == fConstraint;
}
/** @brief logs error and message
*
* Updates result with message and sets it to CREATE_ERROR
*/
void logError(const std::string& msg, int error = 0);
bool compareToken(const WriteEngine::Token& first, const WriteEngine::Token& second) const
{
return (first.op == second.op && first.fbo == second.fbo && first.spare == second.spare);
}
WriteEngine::WriteEngineWrapper* fWriteEngine;
execplan::SessionManager* fSessionManager;
uint32_t fSessionID;
execplan::CalpontSystemCatalog::SCN fTxnID;
DDLPackageProcessor::DDLResult fResult;
DDLPackageProcessor::IndexOID fIdxOID;
ddlpackage::ColumnNameList fColNames;
ddlpackage::QualifiedName fTable;
DDLPackageProcessor::DebugLevel fDebugLevel;
joblist::DistributedEngineComm* fEC;
WriteEngine::RIDList fRidList;
WriteEngine::IdxStructList fIdxStructList;
WriteEngine::IdxValueList fIdxValueList;
ddlpackage::DDL_CONSTRAINTS fConstraint;
std::vector<execplan::ColumnResult*> fUniqueColResultList;
std::vector<int> fOidList;
std::ifstream fColumnFile;
static const int fTOKENSIZE = 8;
struct DDLNullValueForType : DDLPackageProcessor
{
DDLNullValueForType(const execplan::CalpontSystemCatalog::ColType& ctype)
: DDLPackageProcessor(), fType(ctype)
{
return level <= fDebugLevel;
}
/** @brief Get debug level
*/
const DDLPackageProcessor::DebugLevel getDebugLevel() const
boost::any operator()(execplan::CalpontSystemCatalog::ColType& ctype)
{
return fDebugLevel;
return ctype.getNullValueForType();
}
/** @brief set distributedEngineComm pointer ( for
* loading index).
*/
void setEngineComm(joblist::DistributedEngineComm* ec)
{
fEC = ec;
}
void setIdxOID(const DDLPackageProcessor::IndexOID& idxOID)
{
fIdxOID = idxOID;
}
DDLPackageProcessor::DDLResult getResult() const
{
return fResult;
}
/** @brief add data to the index from the statement
*
* populate the newly made index with data in the index columns.
* returns if there was an error.
*/
bool populateIndex(DDLPackageProcessor::DDLResult& result);
/** @brief returns if dictionary type
*
* determines if coltype is dictionary type based on type and size
*/
bool isDictionaryType(const execplan::CalpontSystemCatalog::ColType& ctype);
void setConstraint(ddlpackage::DDL_CONSTRAINTS constraint);
protected:
/** @brief make the structures to update the index
*
* builds and executes a query to retrieve all the data from the index columns
* to make the structures required by WriteEngine::updateIndex
* returns if there is data and no error
*/
bool makeIndexStructs();
/** @brief make the IdxStruct
*
* Fills in the values from the column result and calpont system catalog for
* the WriteEngine::IdxStruct
*/
execplan::CalpontSystemCatalog::ColType makeIdxStruct(const execplan::ColumnResult* cr, size_t cols, boost::shared_ptr<execplan::CalpontSystemCatalog> csc );
/** @brief add the column result data to the value list
*
* Check contraints on each data item and adds it to a tuple list.
* Adds the rid to the rid list if it is the first column (not been added)
* Adds the completed tuple list to the fValueList
*/
void addColumnData(const execplan::ColumnResult* cr, const execplan::CalpontSystemCatalog::ColType ctype, int added);
/** @brief insert data into index.
*
* updates the index with the data using the appropriate write engine method
* based on multi column. Sets result to error if there is one.
*/
void insertIndex();
private:
DDLIndexPopulator(const DDLIndexPopulator& );
void operator=(const DDLIndexPopulator& );
/** @brief makes Calpont Select Execution Plan
*
* builds csep to select data from all columns from fColNames
*/
void makeCsep(execplan::CalpontSelectExecutionPlan& csep);
/** @brief return if ColumnResult string type
*
* Uses same logic as ColumnResult from type to return getStringData (true)
* or getData (false).
*/
bool isStringType(int type) const
{
return (type == execplan::CalpontSystemCatalog::CHAR
|| type == execplan::CalpontSystemCatalog::VARCHAR
|| type == execplan::CalpontSystemCatalog::FLOAT
|| type == execplan::CalpontSystemCatalog::DOUBLE
|| type == execplan::CalpontSystemCatalog::UFLOAT
|| type == execplan::CalpontSystemCatalog::UDOUBLE );
}
/** @brief converts column result data
*
* Converts or tokenizes data, depending on column type
*/
void convertColData(const execplan::ColumnResult* cr, int idx, const execplan::CalpontSystemCatalog::ColType& cType, WriteEngine::IdxTuple& tuple);
/** @brief converts non token data to its original type
*/
boost::any convertData(const execplan::CalpontSystemCatalog::ColType& colType, const execplan::ColumnResult* cr, int idx );
/** @brief returns token for string data
*
* There are two methods, the one using the rid is a workaround.
* Use the method that passes string data when WriteEngine::tokenize is
* able to return an existing token for a string. The rid method reads
* the column file directly.
*/
boost::any tokenizeData( const execplan::CalpontSystemCatalog::ColType& colType, const std::string& data );
boost::any tokenizeData( WriteEngine::RID rid );
/** @brief convert token data
*
* Indexes will use the first 8 bytes of a token type value instead
* of a token.
*/
boost::any convertTokenData( const std::string& data );
/** @brief opens the column file for the oid
*
* This method is needed only as long as the class is using the rid
* tokenizeData method. The fColumnFile and this method are no longer
* needed when the WriteEngine::tokenize method can be used.
*/
//bool openColumnFile(WriteEngine::OID oid);
/** @brief returns if data violated its constraint
*
* checks data according to contraint in coltype and sets result to error
* if constraint violated. Returns if no error.
*/
bool checkConstraints(const WriteEngine::IdxTuple& data, const execplan::CalpontSystemCatalog::ColType& ctype, int i, int column);
/** @brief returns if data not null
*
* Returns false if data is null and sets result to error
*/
bool checkNotNull(const WriteEngine::IdxTuple& data, const execplan::CalpontSystemCatalog::ColType& ctype);
/** @brief returns if data is not unique
*
* Returns false if data row is found more than once in columns and sets result to error
*/
bool checkUnique(int i, const execplan::CalpontSystemCatalog::ColType& colType );
bool checkCheck( const WriteEngine::IdxTuple& data, const execplan::CalpontSystemCatalog::ColType& ctype) const
{
return true;
}
bool isUnique()
{
return ddlpackage::DDL_PRIMARY_KEY == fConstraint || ddlpackage::DDL_UNIQUE == fConstraint;
}
/** @brief logs error and message
*
* Updates result with message and sets it to CREATE_ERROR
*/
void logError(const std::string& msg, int error = 0);
bool compareToken(const WriteEngine::Token& first, const WriteEngine::Token& second) const
{
return (first.op == second.op && first.fbo == second.fbo && first.spare == second.spare);
}
WriteEngine::WriteEngineWrapper* fWriteEngine;
execplan::SessionManager* fSessionManager;
uint32_t fSessionID;
execplan::CalpontSystemCatalog::SCN fTxnID;
DDLPackageProcessor::DDLResult fResult;
DDLPackageProcessor::IndexOID fIdxOID;
ddlpackage::ColumnNameList fColNames;
ddlpackage::QualifiedName fTable;
DDLPackageProcessor::DebugLevel fDebugLevel;
joblist::DistributedEngineComm* fEC;
WriteEngine::RIDList fRidList;
WriteEngine::IdxStructList fIdxStructList;
WriteEngine::IdxValueList fIdxValueList;
ddlpackage::DDL_CONSTRAINTS fConstraint;
std::vector<execplan::ColumnResult*> fUniqueColResultList;
std::vector<int> fOidList;
std::ifstream fColumnFile;
static const int fTOKENSIZE = 8;
struct DDLNullValueForType : DDLPackageProcessor
{
DDLNullValueForType(const execplan::CalpontSystemCatalog::ColType& ctype)
: DDLPackageProcessor(), fType(ctype) {}
boost::any operator()(execplan::CalpontSystemCatalog::ColType& ctype)
{
return ctype.getNullValueForType();
}
const execplan::CalpontSystemCatalog::ColType& fType;
};
const execplan::CalpontSystemCatalog::ColType& fType;
};
};
}
#endif //DDLPINDEXPOPULATOR_H
} // namespace ddlpackageprocessor
#endif // DDLPINDEXPOPULATOR_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: ddlpackageprocessorfactory.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: ddlpackageprocessorfactory.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include "ddlpackageprocessorfactory.h"
#include "ddlpackage.h"
#include "alterpackageprocessor.h"
@ -30,29 +30,21 @@ using namespace ddlpackage;
namespace ddlpackageprocessor
{
DDLPackageProcessor* DDLPackageProcessorFactory::
makePackageProcessor(int packageType, ddlpackage::CalpontDDLPackage& cpackage)
DDLPackageProcessor* DDLPackageProcessorFactory::makePackageProcessor(int packageType,
ddlpackage::CalpontDDLPackage& cpackage)
{
DDLPackageProcessor* ddlProcPtr = 0;
DDLPackageProcessor* ddlProcPtr = 0;
switch ( packageType )
{
case DDL_CREATE:
ddlProcPtr = new CreatePackageProcessor();
break;
switch (packageType)
{
case DDL_CREATE: ddlProcPtr = new CreatePackageProcessor(); break;
case DDL_ALTER:
ddlProcPtr = new AlterPackageProcessor();
break;
case DDL_ALTER: ddlProcPtr = new AlterPackageProcessor(); break;
case DDL_DROP:
ddlProcPtr = new DropPackageProcessor();
break;
case DDL_DROP: ddlProcPtr = new DropPackageProcessor(); break;
}
}
return ddlProcPtr;
return ddlProcPtr;
}
} // namespace ddlpackageprocessor
} // namespace ddlpackageprocessor

View File

@ -16,40 +16,33 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: ddlpackageprocessorfactory.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: ddlpackageprocessorfactory.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
/** @file */
#pragma once
#include <string>
#include "ddlpkg.h"
#include "ddlpackageprocessor.h"
namespace ddlpackageprocessor
{
/** @brief create a ddlPackageProcessor object from a CalpontddlPackage object
*
*/
class DDLPackageProcessorFactory
{
public:
/** @brief static ddlPackageProcessor constructor method
*
* @param packageType the ddl Package type
* @param cpackage the CalpontddlPackage from which the ddlPackageProcessor is constructed
*/
static DDLPackageProcessor* makePackageProcessor(int packageType, ddlpackage::CalpontDDLPackage& cpackage);
public:
/** @brief static ddlPackageProcessor constructor method
*
* @param packageType the ddl Package type
* @param cpackage the CalpontddlPackage from which the ddlPackageProcessor is constructed
*/
static DDLPackageProcessor*
makePackageProcessor( int packageType, ddlpackage::CalpontDDLPackage& cpackage );
protected:
private:
protected:
private:
};
}
} // namespace ddlpackageprocessor

View File

@ -30,85 +30,85 @@ using namespace logging;
namespace ddlpackageprocessor
{
DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(ddlpackage::DropIndexStatement& dropIndexStmt)
DropIndexProcessor::DDLResult DropIndexProcessor::processPackage(
ddlpackage::DropIndexStatement& dropIndexStmt)
{
SUMMARY_INFO("DropIndexProcessor::processPackage");
SUMMARY_INFO("DropIndexProcessor::processPackage");
boost::shared_ptr<CalpontSystemCatalog> sysCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog( dropIndexStmt.fSessionID );
CalpontSystemCatalog::IndexName indexName;
CalpontSystemCatalog::IndexOID indexOID;
boost::shared_ptr<CalpontSystemCatalog> sysCatalogPtr =
CalpontSystemCatalog::makeCalpontSystemCatalog(dropIndexStmt.fSessionID);
CalpontSystemCatalog::IndexName indexName;
CalpontSystemCatalog::IndexOID indexOID;
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
DDLResult result;
result.result = NO_ERROR;
DDLResult result;
result.result = NO_ERROR;
int err = 0;
int err = 0;
VERBOSE_INFO(dropIndexStmt);
VERBOSE_INFO(dropIndexStmt);
SQLLogger logger(dropIndexStmt.fSql, fDDLLoggingId, dropIndexStmt.fSessionID, txnID.id);
SQLLogger logger(dropIndexStmt.fSql, fDDLLoggingId, dropIndexStmt.fSessionID, txnID.id);
indexName.schema = dropIndexStmt.fIndexName->fSchema;
indexName.index = dropIndexStmt.fIndexName->fName;
//Look up table name from indexname. Oracle will error out if same constraintname or indexname exists.
CalpontSystemCatalog::TableName tableName = sysCatalogPtr->lookupTableForIndex (dropIndexStmt.fIndexName->fName, dropIndexStmt.fIndexName->fSchema );
indexName.table = tableName.table;
indexOID = sysCatalogPtr->lookupIndexNbr(indexName);
indexName.schema = dropIndexStmt.fIndexName->fSchema;
indexName.index = dropIndexStmt.fIndexName->fName;
// Look up table name from indexname. Oracle will error out if same constraintname or indexname exists.
CalpontSystemCatalog::TableName tableName =
sysCatalogPtr->lookupTableForIndex(dropIndexStmt.fIndexName->fName, dropIndexStmt.fIndexName->fSchema);
indexName.table = tableName.table;
indexOID = sysCatalogPtr->lookupIndexNbr(indexName);
VERBOSE_INFO("Removing the SYSINDEX meta data");
removeSysIndexMetaData(dropIndexStmt.fSessionID, txnID.id, result, *dropIndexStmt.fIndexName);
VERBOSE_INFO("Removing the SYSINDEX meta data");
removeSysIndexMetaData(dropIndexStmt.fSessionID, txnID.id, result, *dropIndexStmt.fIndexName);
if (result.result != NO_ERROR)
{
DETAIL_INFO("writeSysIndexMetaData failed");
goto rollback;
}
if (result.result != NO_ERROR)
{
DETAIL_INFO("writeSysIndexMetaData failed");
goto rollback;
}
VERBOSE_INFO("Removing the SYSINDEXCOL meta data");
removeSysIndexColMetaData(dropIndexStmt.fSessionID, txnID.id, result, *dropIndexStmt.fIndexName);
VERBOSE_INFO("Removing the SYSINDEXCOL meta data");
removeSysIndexColMetaData(dropIndexStmt.fSessionID, txnID.id, result, *dropIndexStmt.fIndexName);
if (result.result != NO_ERROR)
{
DETAIL_INFO("writeSysIndexMetaData failed");
goto rollback;
}
if (result.result != NO_ERROR)
{
DETAIL_INFO("writeSysIndexMetaData failed");
goto rollback;
}
VERBOSE_INFO("Removing the index files");
err = fWriteEngine.dropIndex(txnID.id, indexOID.objnum, indexOID.listOID);
VERBOSE_INFO("Removing the index files");
err = fWriteEngine.dropIndex(txnID.id, indexOID.objnum, indexOID.listOID);
if (err)
{
DETAIL_INFO("WriteEngine dropIndex failed");
goto rollback;
}
if (err)
{
DETAIL_INFO("WriteEngine dropIndex failed");
goto rollback;
}
// Log the DDL statement
logging::logDDL(dropIndexStmt.fSessionID, txnID.id, dropIndexStmt.fSql, dropIndexStmt.fOwner);
// Log the DDL statement
logging::logDDL(dropIndexStmt.fSessionID, txnID.id, dropIndexStmt.fSql, dropIndexStmt.fOwner);
// register the changes
err = fWriteEngine.commit(txnID.id);
// register the changes
err = fWriteEngine.commit( txnID.id );
if (err)
{
DETAIL_INFO("Failed to commit the drop index transaction");
goto rollback;
}
if (err)
{
DETAIL_INFO("Failed to commit the drop index transaction");
goto rollback;
}
fSessionManager.committed(txnID);
//fObjectIDManager.returnOID(indexOID.objnum);
//fObjectIDManager.returnOID(indexOID.listOID);
return result;
fSessionManager.committed(txnID);
// fObjectIDManager.returnOID(indexOID.objnum);
// fObjectIDManager.returnOID(indexOID.listOID);
return result;
rollback:
fWriteEngine.rollbackTran(txnID.id, dropIndexStmt.fSessionID);
fSessionManager.rolledback(txnID);
return result;
fWriteEngine.rollbackTran(txnID.id, dropIndexStmt.fSessionID);
fSessionManager.rolledback(txnID);
return result;
}
} // namespace ddlpackageprocessor
} // namespace ddlpackageprocessor

View File

@ -33,17 +33,15 @@ namespace ddlpackageprocessor
*/
class DropIndexProcessor : public DDLPackageProcessor
{
public:
/** @brief process a drop index statement
*
* @param dropIndexStmt the drop index statement
*/
DDLResult processPackage(ddlpackage::DropIndexStatement& dropIndexStmt);
protected:
private:
public:
/** @brief process a drop index statement
*
* @param dropIndexStmt the drop index statement
*/
DDLResult processPackage(ddlpackage::DropIndexStatement& dropIndexStmt);
protected:
private:
};
} //namespace ddlpackageprocessor
} // namespace ddlpackageprocessor

View File

@ -37,344 +37,344 @@ using namespace oam;
namespace ddlpackageprocessor
{
DropPartitionProcessor::DDLResult DropPartitionProcessor::processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt)
DropPartitionProcessor::DDLResult DropPartitionProcessor::processPackage(
ddlpackage::DropPartitionStatement& dropPartitionStmt)
{
SUMMARY_INFO("DropPartitionProcessor::processPackage");
SUMMARY_INFO("DropPartitionProcessor::processPackage");
DDLResult result;
result.result = NO_ERROR;
std::string err;
VERBOSE_INFO(dropPartitionStmt);
DDLResult result;
result.result = NO_ERROR;
std::string err;
VERBOSE_INFO(dropPartitionStmt);
// Commit current transaction.
// all DDL statements cause an implicit commit
VERBOSE_INFO("Getting current txnID");
// Commit current transaction.
// all DDL statements cause an implicit commit
VERBOSE_INFO("Getting current txnID");
int rc = 0;
rc = fDbrm->isReadWrite();
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
int rc = 0;
rc = fDbrm->isReadWrite();
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
if (rc != 0 )
if (rc != 0)
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unable to execute the statement due to DBRM is read only");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
std::vector<CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList;
execplan::CalpontSystemCatalog::ROPair roPair;
uint32_t processID = 0;
uint64_t uniqueID = 0;
uint32_t sessionID = dropPartitionStmt.fSessionID;
std::string processName("DDLProc");
uint64_t uniqueId = 0;
// Bug 5070. Added exception handling
try
{
uniqueId = fDbrm->getUnique64();
}
catch (std::exception& ex)
{
logging::Message::Args args;
logging::Message message(9);
args.add(ex.what());
message.format(args);
result.result = ALTER_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unknown error occured while getting unique number.");
message.format(args);
result.result = ALTER_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
string stmt = dropPartitionStmt.fSql + "|" + dropPartitionStmt.fTableName->fSchema + "|";
SQLLogger logger(stmt, fDDLLoggingId, sessionID, txnID.id);
try
{
// check table lock
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr =
CalpontSystemCatalog::makeCalpontSystemCatalog(dropPartitionStmt.fSessionID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(dropPartitionStmt.fSessionID);
CalpontSystemCatalog::TableName tableName;
tableName.schema = dropPartitionStmt.fTableName->fSchema;
tableName.table = dropPartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID(tableName);
//@Bug 3054 check for system catalog
if (roPair.objnum < 3000)
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unable to execute the statement due to DBRM is read only");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
}
int i = 0;
processID = ::getpid();
oam::OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
std::vector <CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList;
execplan::CalpontSystemCatalog::ROPair roPair;
uint32_t processID = 0;
uint64_t uniqueID = 0;
uint32_t sessionID = dropPartitionStmt.fSessionID;
std::string processName("DDLProc");
uint64_t uniqueId = 0;
//Bug 5070. Added exception handling
try
for (unsigned i = 0; i < pmList.size(); i++)
{
uniqueId = fDbrm->getUnique64();
pms.push_back((uint32_t)pmList[i]);
}
catch (std::exception& ex)
{
logging::Message::Args args;
logging::Message message(9);
args.add(ex.what());
message.format(args);
result.result = ALTER_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
catch ( ... )
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unknown error occured while getting unique number.");
message.format(args);
result.result = ALTER_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
string stmt = dropPartitionStmt.fSql + "|" + dropPartitionStmt.fTableName->fSchema + "|";
SQLLogger logger(stmt, fDDLLoggingId, sessionID, txnID.id);
try
{
//check table lock
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(dropPartitionStmt.fSessionID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(dropPartitionStmt.fSessionID);
CalpontSystemCatalog::TableName tableName;
tableName.schema = dropPartitionStmt.fTableName->fSchema;
tableName.table = dropPartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID( tableName );
//@Bug 3054 check for system catalog
if ( roPair.objnum < 3000 )
{
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
}
int i = 0;
processID = ::getpid();
oam::OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
for (unsigned i = 0; i < pmList.size(); i++)
{
pms.push_back((uint32_t)pmList[i]);
}
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
// no need to release lock. dbrm un-hold the lock
fSessionManager.rolledback(txnID);
return result;
}
if ( uniqueID == 0 )
{
int waitPeriod = 10;
int sleepTime = 100; // sleep 100 milliseconds between checks
int numTries = 10; // try 10 times per second
waitPeriod = Config::getWaitPeriod();
numTries = waitPeriod * 10;
struct timespec rm_ts;
rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++)
{
#ifdef _MSC_VER
Sleep(rm_ts.tv_sec * 1000);
#else
struct timespec abs_ts;
do
{
abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec;
}
while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif
// reset
sessionID = dropPartitionStmt.fSessionID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
processID = ::getpid();
processName = "DDLProc";
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if (uniqueID > 0)
break;
}
if (i >= numTries) //error out
{
result.result = DROP_ERROR;
logging::Message::Args args;
string strOp("drop partition");
args.add(strOp);
args.add(processName);
args.add((uint64_t)processID);
args.add((uint64_t)sessionID);
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
fSessionManager.rolledback(txnID);
return result;
}
}
// 1. Get the OIDs for the columns
// 2. Get the OIDs for the dictionaries
// 3. Save the OIDs to a log file
// 4. Disable the extents from extentmap for the partition
// 5. Remove the column and dictionary files for the partition
// 6. Flush PrimProc Cache
// 7. Remove the extents from extentmap for the partition
CalpontSystemCatalog::TableName userTableName;
userTableName.schema = dropPartitionStmt.fTableName->fSchema;
userTableName.table = dropPartitionStmt.fTableName->fName;
tableColRidList = systemCatalogPtr->columnRIDs( userTableName );
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
for ( unsigned i = 0; i < tableColRidList.size(); i++ )
{
if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum );
}
for ( unsigned i = 0; i < dictOIDList.size(); i++ )
{
if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID );
}
//Mark the partition disabled from extent map
string emsg;
rc = fDbrm->markPartitionForDeletion( oidList, dropPartitionStmt.fPartitions, emsg);
if (rc != 0 && rc != BRM::ERR_PARTITION_DISABLED &&
rc != BRM::ERR_INVALID_OP_LAST_PARTITION &&
rc != BRM::ERR_NOT_EXIST_PARTITION)
{
throw std::runtime_error(emsg);
}
set<BRM::LogicalPartition> markedPartitions;
set<BRM::LogicalPartition> outOfServicePartitions;
// only log partitions that are successfully marked disabled.
rc = fDbrm->getOutOfServicePartitions(oidList[0], outOfServicePartitions);
if (rc != 0)
{
string errorMsg;
BRM::errString(rc, errorMsg);
ostringstream oss;
oss << "getOutOfServicePartitions failed due to " << errorMsg;
throw std::runtime_error(oss.str());
}
set<BRM::LogicalPartition>::iterator it;
for (it = dropPartitionStmt.fPartitions.begin(); it != dropPartitionStmt.fPartitions.end(); ++it)
{
if (outOfServicePartitions.find(*it) != outOfServicePartitions.end())
markedPartitions.insert(*it);
}
//Save the oids to a file
createWritePartitionLogFile( roPair.objnum, markedPartitions, oidList, uniqueId);
VERBOSE_INFO("Removing files");
removePartitionFiles( oidList, markedPartitions, uniqueId );
//Flush PrimProc cache for those lbids
rc = cacheutils::flushPartition( oidList, markedPartitions );
//Remove the partition from extent map
emsg.clear();
rc = fDbrm->deletePartition( oidList, dropPartitionStmt.fPartitions, emsg);
if ( rc != 0 )
throw std::runtime_error(emsg);
}
catch (exception& ex)
{
cerr << "DropPartitionProcessor::processPackage: " << ex.what() << endl;
logging::Message::Args args;
logging::Message message(ex.what());
if (rc == BRM::ERR_TABLE_NOT_LOCKED)
result.result = USER_ERROR;
else if (rc == BRM::ERR_NOT_EXIST_PARTITION || rc == BRM::ERR_INVALID_OP_LAST_PARTITION)
result.result = PARTITION_WARNING;
else if (rc == BRM::ERR_NO_PARTITION_PERFORMED)
result.result = WARN_NO_PARTITION;
else
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
cerr << "DropPartitionProcessor::processPackage: caught unknown exception!" << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Drop partition failed: ");
args.add( "encountered unkown exception" );
args.add("");
args.add("");
message.format( args );
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
// Log the DDL statement
logging::logDDL(dropPartitionStmt.fSessionID, txnID.id, dropPartitionStmt.fSql, dropPartitionStmt.fOwner);
//Remove the log file
//release the transaction
try
{
fDbrm->releaseTableLock(uniqueID);
deleteLogFile(DROPPART_LOG, roPair.objnum, uniqueId);
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID,
(int32_t*)&txnID.id, BRM::LOADING);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
// no need to release lock. dbrm un-hold the lock
fSessionManager.rolledback(txnID);
return result;
}
fSessionManager.committed(txnID);
if (uniqueID == 0)
{
int waitPeriod = 10;
int sleepTime = 100; // sleep 100 milliseconds between checks
int numTries = 10; // try 10 times per second
waitPeriod = Config::getWaitPeriod();
numTries = waitPeriod * 10;
struct timespec rm_ts;
rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++)
{
#ifdef _MSC_VER
Sleep(rm_ts.tv_sec * 1000);
#else
struct timespec abs_ts;
do
{
abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec;
} while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif
// reset
sessionID = dropPartitionStmt.fSessionID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
processID = ::getpid();
processName = "DDLProc";
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID,
(int32_t*)&txnID.id, BRM::LOADING);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if (uniqueID > 0)
break;
}
if (i >= numTries) // error out
{
result.result = DROP_ERROR;
logging::Message::Args args;
string strOp("drop partition");
args.add(strOp);
args.add(processName);
args.add((uint64_t)processID);
args.add((uint64_t)sessionID);
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
fSessionManager.rolledback(txnID);
return result;
}
}
// 1. Get the OIDs for the columns
// 2. Get the OIDs for the dictionaries
// 3. Save the OIDs to a log file
// 4. Disable the extents from extentmap for the partition
// 5. Remove the column and dictionary files for the partition
// 6. Flush PrimProc Cache
// 7. Remove the extents from extentmap for the partition
CalpontSystemCatalog::TableName userTableName;
userTableName.schema = dropPartitionStmt.fTableName->fSchema;
userTableName.table = dropPartitionStmt.fTableName->fName;
tableColRidList = systemCatalogPtr->columnRIDs(userTableName);
dictOIDList = systemCatalogPtr->dictOIDs(userTableName);
// Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
for (unsigned i = 0; i < tableColRidList.size(); i++)
{
if (tableColRidList[i].objnum > 3000)
oidList.push_back(tableColRidList[i].objnum);
}
for (unsigned i = 0; i < dictOIDList.size(); i++)
{
if (dictOIDList[i].dictOID > 3000)
oidList.push_back(dictOIDList[i].dictOID);
}
// Mark the partition disabled from extent map
string emsg;
rc = fDbrm->markPartitionForDeletion(oidList, dropPartitionStmt.fPartitions, emsg);
if (rc != 0 && rc != BRM::ERR_PARTITION_DISABLED && rc != BRM::ERR_INVALID_OP_LAST_PARTITION &&
rc != BRM::ERR_NOT_EXIST_PARTITION)
{
throw std::runtime_error(emsg);
}
set<BRM::LogicalPartition> markedPartitions;
set<BRM::LogicalPartition> outOfServicePartitions;
// only log partitions that are successfully marked disabled.
rc = fDbrm->getOutOfServicePartitions(oidList[0], outOfServicePartitions);
if (rc != 0)
{
string errorMsg;
BRM::errString(rc, errorMsg);
ostringstream oss;
oss << "getOutOfServicePartitions failed due to " << errorMsg;
throw std::runtime_error(oss.str());
}
set<BRM::LogicalPartition>::iterator it;
for (it = dropPartitionStmt.fPartitions.begin(); it != dropPartitionStmt.fPartitions.end(); ++it)
{
if (outOfServicePartitions.find(*it) != outOfServicePartitions.end())
markedPartitions.insert(*it);
}
// Save the oids to a file
createWritePartitionLogFile(roPair.objnum, markedPartitions, oidList, uniqueId);
VERBOSE_INFO("Removing files");
removePartitionFiles(oidList, markedPartitions, uniqueId);
// Flush PrimProc cache for those lbids
rc = cacheutils::flushPartition(oidList, markedPartitions);
// Remove the partition from extent map
emsg.clear();
rc = fDbrm->deletePartition(oidList, dropPartitionStmt.fPartitions, emsg);
if (rc != 0)
throw std::runtime_error(emsg);
}
catch (exception& ex)
{
cerr << "DropPartitionProcessor::processPackage: " << ex.what() << endl;
logging::Message::Args args;
logging::Message message(ex.what());
if (rc == BRM::ERR_TABLE_NOT_LOCKED)
result.result = USER_ERROR;
else if (rc == BRM::ERR_NOT_EXIST_PARTITION || rc == BRM::ERR_INVALID_OP_LAST_PARTITION)
result.result = PARTITION_WARNING;
else if (rc == BRM::ERR_NO_PARTITION_PERFORMED)
result.result = WARN_NO_PARTITION;
else
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
cerr << "DropPartitionProcessor::processPackage: caught unknown exception!" << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Drop partition failed: ");
args.add("encountered unkown exception");
args.add("");
args.add("");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
// Log the DDL statement
logging::logDDL(dropPartitionStmt.fSessionID, txnID.id, dropPartitionStmt.fSql, dropPartitionStmt.fOwner);
// Remove the log file
// release the transaction
try
{
fDbrm->releaseTableLock(uniqueID);
deleteLogFile(DROPPART_LOG, roPair.objnum, uniqueId);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
fSessionManager.committed(txnID);
return result;
}
}
} // namespace ddlpackageprocessor

View File

@ -39,20 +39,19 @@ namespace ddlpackageprocessor
*/
class DropPartitionProcessor : public DDLPackageProcessor
{
public:
DropPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a drop table statement
*
* @param dropTableStmt the drop table statement
*/
EXPORT DDLResult processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt);
protected:
private:
public:
DropPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm)
{
}
/** @brief process a drop table statement
*
* @param dropTableStmt the drop table statement
*/
EXPORT DDLResult processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt);
protected:
private:
};
} // namespace ddlpackageprocessor
} // namespace ddlpackageprocessor
#undef EXPORT

File diff suppressed because it is too large Load Diff

View File

@ -39,18 +39,18 @@ namespace ddlpackageprocessor
*/
class DropTableProcessor : public DDLPackageProcessor
{
public:
DropTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a drop table statement
*
* @param dropTableStmt the drop table statement
*/
EXPORT DDLResult processPackage(ddlpackage::DropTableStatement& dropTableStmt);
protected:
private:
public:
DropTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm)
{
}
/** @brief process a drop table statement
*
* @param dropTableStmt the drop table statement
*/
EXPORT DDLResult processPackage(ddlpackage::DropTableStatement& dropTableStmt);
protected:
private:
};
/** @brief specialization of a DDLPacakageProcessor
@ -59,21 +59,20 @@ private:
*/
class TruncTableProcessor : public DDLPackageProcessor
{
public:
TruncTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a truncate table statement
*
* @param truncTableStmt the truncate table statement
*/
EXPORT DDLResult processPackage(ddlpackage::TruncTableStatement& truncTableStmt);
protected:
private:
public:
TruncTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm)
{
}
/** @brief process a truncate table statement
*
* @param truncTableStmt the truncate table statement
*/
EXPORT DDLResult processPackage(ddlpackage::TruncTableStatement& truncTableStmt);
protected:
private:
};
} // namespace ddlpackageprocessor
} // namespace ddlpackageprocessor
#undef EXPORT

View File

@ -34,264 +34,266 @@ using namespace oam;
namespace ddlpackageprocessor
{
MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpackage::MarkPartitionStatement& markPartitionStmt)
MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(
ddlpackage::MarkPartitionStatement& markPartitionStmt)
{
SUMMARY_INFO("RestorePartitionProcessor::processPackage");
SUMMARY_INFO("RestorePartitionProcessor::processPackage");
DDLResult result;
result.result = NO_ERROR;
std::string err;
VERBOSE_INFO(markPartitionStmt);
DDLResult result;
result.result = NO_ERROR;
std::string err;
VERBOSE_INFO(markPartitionStmt);
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
int rc = 0;
rc = fDbrm->isReadWrite();
int rc = 0;
rc = fDbrm->isReadWrite();
if (rc != 0 )
if (rc != 0)
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unable to execute the statement due to DBRM is read only");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
std::vector<CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList;
std::string processName("DDLProc");
string stmt = markPartitionStmt.fSql + "|" + markPartitionStmt.fTableName->fSchema + "|";
SQLLogger logger(stmt, fDDLLoggingId, markPartitionStmt.fSessionID, txnID.id);
uint32_t processID = 0;
uint64_t uniqueID = 0;
uint32_t sessionID = markPartitionStmt.fSessionID;
execplan::CalpontSystemCatalog::ROPair roPair;
try
{
// check table lock
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr =
CalpontSystemCatalog::makeCalpontSystemCatalog(markPartitionStmt.fSessionID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(markPartitionStmt.fSessionID);
CalpontSystemCatalog::TableName tableName;
tableName.schema = markPartitionStmt.fTableName->fSchema;
tableName.table = markPartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID(tableName);
//@Bug 3054 check for system catalog
if (roPair.objnum < 3000)
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unable to execute the statement due to DBRM is read only");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
}
std::vector <CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList;
std::string processName("DDLProc");
int i = 0;
processID = ::getpid();
oam::OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
string stmt = markPartitionStmt.fSql + "|" + markPartitionStmt.fTableName->fSchema + "|";
SQLLogger logger(stmt, fDDLLoggingId, markPartitionStmt.fSessionID, txnID.id);
uint32_t processID = 0;
uint64_t uniqueID = 0;
uint32_t sessionID = markPartitionStmt.fSessionID;
execplan::CalpontSystemCatalog::ROPair roPair;
for (unsigned i = 0; i < pmList.size(); i++)
{
pms.push_back((uint32_t)pmList[i]);
}
try
{
//check table lock
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(markPartitionStmt.fSessionID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(markPartitionStmt.fSessionID);
CalpontSystemCatalog::TableName tableName;
tableName.schema = markPartitionStmt.fTableName->fSchema;
tableName.table = markPartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID( tableName );
//@Bug 3054 check for system catalog
if ( roPair.objnum < 3000 )
{
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
}
int i = 0;
processID = ::getpid();
oam::OamCache* oamcache = OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
for (unsigned i = 0; i < pmList.size(); i++)
{
pms.push_back((uint32_t)pmList[i]);
}
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if ( uniqueID == 0 )
{
int waitPeriod = 10;
int sleepTime = 100; // sleep 100 milliseconds between checks
int numTries = 10; // try 10 times per second
waitPeriod = Config::getWaitPeriod();
numTries = waitPeriod * 10;
struct timespec rm_ts;
rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++)
{
#ifdef _MSC_VER
Sleep(rm_ts.tv_sec * 1000);
#else
struct timespec abs_ts;
do
{
abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec;
}
while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif
// reset
sessionID = markPartitionStmt.fSessionID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
processID = ::getpid();
processName = "DDLProc";
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if (uniqueID > 0)
break;
}
if (i >= numTries) //error out
{
result.result = DROP_ERROR;
logging::Message::Args args;
args.add(processName);
args.add((uint64_t)processID);
args.add((uint64_t)sessionID);
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
fSessionManager.rolledback(txnID);
return result;
}
}
// 1. Get the OIDs for the columns
// 2. Get the OIDs for the dictionaries
// 3. Save the OIDs to a log file
// 4. Remove the extents from extentmap
// 5. Flush PrimProc Cache
// 6. Remove the column and dictionary files for the partition
CalpontSystemCatalog::TableName userTableName;
userTableName.schema = markPartitionStmt.fTableName->fSchema;
userTableName.table = markPartitionStmt.fTableName->fName;
tableColRidList = systemCatalogPtr->columnRIDs( userTableName );
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
for ( unsigned i = 0; i < tableColRidList.size(); i++ )
{
if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum );
}
for ( unsigned i = 0; i < dictOIDList.size(); i++ )
{
if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID );
}
//Remove the partition from extent map
string emsg;
rc = fDbrm->markPartitionForDeletion( oidList, markPartitionStmt.fPartitions, emsg);
if ( rc != 0 )
{
throw std::runtime_error(emsg);
}
}
catch (exception& ex)
{
logging::Message::Args args;
logging::Message message(ex.what());
if (rc == BRM::ERR_TABLE_NOT_LOCKED)
result.result = USER_ERROR;
else if (rc == BRM::ERR_PARTITION_DISABLED || rc == BRM::ERR_INVALID_OP_LAST_PARTITION ||
rc == BRM::ERR_NOT_EXIST_PARTITION)
result.result = PARTITION_WARNING;
else if (rc == BRM::ERR_NO_PARTITION_PERFORMED)
result.result = WARN_NO_PARTITION;
else
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
//cerr << "MarkPartitionProcessor::processPackage: caught unknown exception!" << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Disable partition failed: ");
args.add( "encountered unkown exception" );
args.add("");
args.add("");
message.format( args );
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
// Log the DDL statement
logging::logDDL(markPartitionStmt.fSessionID, 0, markPartitionStmt.fSql, markPartitionStmt.fOwner);
try
{
fDbrm->releaseTableLock(uniqueID);
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID,
(int32_t*)&txnID.id, BRM::LOADING);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
fSessionManager.committed(txnID);
if (uniqueID == 0)
{
int waitPeriod = 10;
int sleepTime = 100; // sleep 100 milliseconds between checks
int numTries = 10; // try 10 times per second
waitPeriod = Config::getWaitPeriod();
numTries = waitPeriod * 10;
struct timespec rm_ts;
rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++)
{
#ifdef _MSC_VER
Sleep(rm_ts.tv_sec * 1000);
#else
struct timespec abs_ts;
do
{
abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec;
} while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif
// reset
sessionID = markPartitionStmt.fSessionID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
processID = ::getpid();
processName = "DDLProc";
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID,
(int32_t*)&txnID.id, BRM::LOADING);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if (uniqueID > 0)
break;
}
if (i >= numTries) // error out
{
result.result = DROP_ERROR;
logging::Message::Args args;
args.add(processName);
args.add((uint64_t)processID);
args.add((uint64_t)sessionID);
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
fSessionManager.rolledback(txnID);
return result;
}
}
// 1. Get the OIDs for the columns
// 2. Get the OIDs for the dictionaries
// 3. Save the OIDs to a log file
// 4. Remove the extents from extentmap
// 5. Flush PrimProc Cache
// 6. Remove the column and dictionary files for the partition
CalpontSystemCatalog::TableName userTableName;
userTableName.schema = markPartitionStmt.fTableName->fSchema;
userTableName.table = markPartitionStmt.fTableName->fName;
tableColRidList = systemCatalogPtr->columnRIDs(userTableName);
dictOIDList = systemCatalogPtr->dictOIDs(userTableName);
// Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
for (unsigned i = 0; i < tableColRidList.size(); i++)
{
if (tableColRidList[i].objnum > 3000)
oidList.push_back(tableColRidList[i].objnum);
}
for (unsigned i = 0; i < dictOIDList.size(); i++)
{
if (dictOIDList[i].dictOID > 3000)
oidList.push_back(dictOIDList[i].dictOID);
}
// Remove the partition from extent map
string emsg;
rc = fDbrm->markPartitionForDeletion(oidList, markPartitionStmt.fPartitions, emsg);
if (rc != 0)
{
throw std::runtime_error(emsg);
}
}
catch (exception& ex)
{
logging::Message::Args args;
logging::Message message(ex.what());
if (rc == BRM::ERR_TABLE_NOT_LOCKED)
result.result = USER_ERROR;
else if (rc == BRM::ERR_PARTITION_DISABLED || rc == BRM::ERR_INVALID_OP_LAST_PARTITION ||
rc == BRM::ERR_NOT_EXIST_PARTITION)
result.result = PARTITION_WARNING;
else if (rc == BRM::ERR_NO_PARTITION_PERFORMED)
result.result = WARN_NO_PARTITION;
else
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
// cerr << "MarkPartitionProcessor::processPackage: caught unknown exception!" << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Disable partition failed: ");
args.add("encountered unkown exception");
args.add("");
args.add("");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
// Log the DDL statement
logging::logDDL(markPartitionStmt.fSessionID, 0, markPartitionStmt.fSql, markPartitionStmt.fOwner);
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
fSessionManager.committed(txnID);
return result;
}
}
} // namespace ddlpackageprocessor

View File

@ -33,29 +33,26 @@
namespace ddlpackageprocessor
{
/** @brief specialization of a DDLPackageProcessor
* for interacting with the Write Engine
* to process create table ddl statements.
*/
class MarkPartitionProcessor : public DDLPackageProcessor
{
public:
MarkPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a create table statement
*
* @param createTableStmt the CreateTableStatement
*/
EXPORT DDLResult processPackage(ddlpackage::MarkPartitionStatement& MarkPartitionStmt);
protected:
private:
public:
MarkPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm)
{
}
/** @brief process a create table statement
*
* @param createTableStmt the CreateTableStatement
*/
EXPORT DDLResult processPackage(ddlpackage::MarkPartitionStatement& MarkPartitionStmt);
protected:
private:
};
} // namespace ddlpackageprocessor
} // namespace ddlpackageprocessor
#undef EXPORT

File diff suppressed because it is too large Load Diff

View File

@ -6,9 +6,9 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -34,263 +34,266 @@ using namespace WriteEngine;
namespace ddlpackageprocessor
{
RestorePartitionProcessor::DDLResult RestorePartitionProcessor::processPackage(ddlpackage::RestorePartitionStatement& restorePartitionStmt)
RestorePartitionProcessor::DDLResult RestorePartitionProcessor::processPackage(
ddlpackage::RestorePartitionStatement& restorePartitionStmt)
{
SUMMARY_INFO("RestorePartitionProcessor::processPackage");
SUMMARY_INFO("RestorePartitionProcessor::processPackage");
DDLResult result;
result.result = NO_ERROR;
std::string err;
VERBOSE_INFO(restorePartitionStmt);
DDLResult result;
result.result = NO_ERROR;
std::string err;
VERBOSE_INFO(restorePartitionStmt);
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
BRM::TxnID txnID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
int rc = 0;
rc = fDbrm->isReadWrite();
int rc = 0;
rc = fDbrm->isReadWrite();
if (rc != 0 )
if (rc != 0)
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unable to execute the statement due to DBRM is read only");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
}
std::vector<CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList;
std::string processName("DDLProc");
string stmt = restorePartitionStmt.fSql + "|" + restorePartitionStmt.fTableName->fSchema + "|";
SQLLogger logger(stmt, fDDLLoggingId, restorePartitionStmt.fSessionID, txnID.id);
uint32_t processID = 0;
uint64_t uniqueID = 0;
uint32_t sessionID = restorePartitionStmt.fSessionID;
execplan::CalpontSystemCatalog::ROPair roPair;
try
{
// check table lock
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr =
CalpontSystemCatalog::makeCalpontSystemCatalog(restorePartitionStmt.fSessionID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(restorePartitionStmt.fSessionID);
CalpontSystemCatalog::TableName tableName;
tableName.schema = restorePartitionStmt.fTableName->fSchema;
tableName.table = restorePartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID(tableName);
//@Bug 3054 check for system catalog
if (roPair.objnum < 3000)
{
logging::Message::Args args;
logging::Message message(9);
args.add("Unable to execute the statement due to DBRM is read only");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
fSessionManager.rolledback(txnID);
return result;
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
}
std::vector <CalpontSystemCatalog::OID> oidList;
CalpontSystemCatalog::RIDList tableColRidList;
CalpontSystemCatalog::DictOIDList dictOIDList;
std::string processName("DDLProc");
int i = 0;
processID = ::getpid();
oam::OamCache* oamcache = oam::OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
string stmt = restorePartitionStmt.fSql + "|" + restorePartitionStmt.fTableName->fSchema + "|";
SQLLogger logger(stmt, fDDLLoggingId, restorePartitionStmt.fSessionID, txnID.id);
uint32_t processID = 0;
uint64_t uniqueID = 0;
uint32_t sessionID = restorePartitionStmt.fSessionID;
execplan::CalpontSystemCatalog::ROPair roPair;
for (unsigned i = 0; i < pmList.size(); i++)
{
pms.push_back((uint32_t)pmList[i]);
}
try
{
//check table lock
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(restorePartitionStmt.fSessionID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
systemCatalogPtr->sessionID(restorePartitionStmt.fSessionID);
CalpontSystemCatalog::TableName tableName;
tableName.schema = restorePartitionStmt.fTableName->fSchema;
tableName.table = restorePartitionStmt.fTableName->fName;
roPair = systemCatalogPtr->tableRID( tableName );
//@Bug 3054 check for system catalog
if ( roPair.objnum < 3000 )
{
throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
}
int i = 0;
processID = ::getpid();
oam::OamCache* oamcache = oam::OamCache::makeOamCache();
std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
for (unsigned i = 0; i < pmList.size(); i++)
{
pms.push_back((uint32_t)pmList[i]);
}
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if ( uniqueID == 0 )
{
int waitPeriod = 10;
int sleepTime = 100; // sleep 100 milliseconds between checks
int numTries = 10; // try 10 times per second
waitPeriod = Config::getWaitPeriod();
numTries = waitPeriod * 10;
struct timespec rm_ts;
rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++)
{
#ifdef _MSC_VER
Sleep(rm_ts.tv_sec * 1000);
#else
struct timespec abs_ts;
do
{
abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec;
}
while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif
// reset
sessionID = restorePartitionStmt.fSessionID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
processID = ::getpid();
processName = "DDLProc";
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID, (int32_t*)&txnID.id, BRM::LOADING );
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if (uniqueID > 0)
break;
}
if (i >= numTries) //error out
{
result.result = DROP_ERROR;
logging::Message::Args args;
string strOp("restore partition");
args.add(strOp);
args.add(processName);
args.add((uint64_t)processID);
args.add((uint64_t)sessionID);
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
fSessionManager.rolledback(txnID);
return result;
}
}
// 1. Get the OIDs for the columns
// 2. Get the OIDs for the dictionaries
// 3. Save the OIDs to a log file
// 4. Remove the extents from extentmap
// 5. Flush PrimProc Cache
// 6. Remove the column and dictionary files for the partition
CalpontSystemCatalog::TableName userTableName;
userTableName.schema = restorePartitionStmt.fTableName->fSchema;
userTableName.table = restorePartitionStmt.fTableName->fName;
tableColRidList = systemCatalogPtr->columnRIDs( userTableName );
dictOIDList = systemCatalogPtr->dictOIDs( userTableName );
//Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
for ( unsigned i = 0; i < tableColRidList.size(); i++ )
{
if ( tableColRidList[i].objnum > 3000 )
oidList.push_back( tableColRidList[i].objnum );
}
for ( unsigned i = 0; i < dictOIDList.size(); i++ )
{
if ( dictOIDList[i].dictOID > 3000 )
oidList.push_back( dictOIDList[i].dictOID );
}
//Remove the partition from extent map
string emsg;
rc = fDbrm->restorePartition( oidList, restorePartitionStmt.fPartitions, emsg);
if ( rc != 0 )
{
throw std::runtime_error(emsg);
}
}
catch (exception& ex)
{
logging::Message::Args args;
logging::Message message(ex.what());
if (( rc == BRM::ERR_NOT_EXIST_PARTITION) || (rc == BRM::ERR_INVALID_OP_LAST_PARTITION) ||
(rc == BRM::ERR_PARTITION_DISABLED) || (rc == BRM::ERR_TABLE_NOT_LOCKED))
result.result = USER_ERROR;
else if (rc == BRM::ERR_PARTITION_ENABLED)
result.result = PARTITION_WARNING;
else
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
//cerr << "RestorePartitionProcessor::processPackage: caught unknown exception!" << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Enable partition: ");
args.add( "encountered unkown exception" );
args.add("");
args.add("");
message.format( args );
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
// Log the DDL statement
logging::logDDL(restorePartitionStmt.fSessionID, txnID.id, restorePartitionStmt.fSql, restorePartitionStmt.fOwner);
try
{
fDbrm->releaseTableLock(uniqueID);
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID,
(int32_t*)&txnID.id, BRM::LOADING);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
fSessionManager.committed(txnID);
if (uniqueID == 0)
{
int waitPeriod = 10;
int sleepTime = 100; // sleep 100 milliseconds between checks
int numTries = 10; // try 10 times per second
waitPeriod = Config::getWaitPeriod();
numTries = waitPeriod * 10;
struct timespec rm_ts;
rm_ts.tv_sec = sleepTime / 1000;
rm_ts.tv_nsec = sleepTime % 1000 * 1000000;
for (; i < numTries; i++)
{
#ifdef _MSC_VER
Sleep(rm_ts.tv_sec * 1000);
#else
struct timespec abs_ts;
do
{
abs_ts.tv_sec = rm_ts.tv_sec;
abs_ts.tv_nsec = rm_ts.tv_nsec;
} while (nanosleep(&abs_ts, &rm_ts) < 0);
#endif
// reset
sessionID = restorePartitionStmt.fSessionID;
txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid;
processID = ::getpid();
processName = "DDLProc";
try
{
uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID,
(int32_t*)&txnID.id, BRM::LOADING);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
if (uniqueID > 0)
break;
}
if (i >= numTries) // error out
{
result.result = DROP_ERROR;
logging::Message::Args args;
string strOp("restore partition");
args.add(strOp);
args.add(processName);
args.add((uint64_t)processID);
args.add((uint64_t)sessionID);
result.message = Message(IDBErrorInfo::instance()->errorMsg(ERR_TABLE_LOCKED, args));
fSessionManager.rolledback(txnID);
return result;
}
}
// 1. Get the OIDs for the columns
// 2. Get the OIDs for the dictionaries
// 3. Save the OIDs to a log file
// 4. Remove the extents from extentmap
// 5. Flush PrimProc Cache
// 6. Remove the column and dictionary files for the partition
CalpontSystemCatalog::TableName userTableName;
userTableName.schema = restorePartitionStmt.fTableName->fSchema;
userTableName.table = restorePartitionStmt.fTableName->fName;
tableColRidList = systemCatalogPtr->columnRIDs(userTableName);
dictOIDList = systemCatalogPtr->dictOIDs(userTableName);
// Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format
for (unsigned i = 0; i < tableColRidList.size(); i++)
{
if (tableColRidList[i].objnum > 3000)
oidList.push_back(tableColRidList[i].objnum);
}
for (unsigned i = 0; i < dictOIDList.size(); i++)
{
if (dictOIDList[i].dictOID > 3000)
oidList.push_back(dictOIDList[i].dictOID);
}
// Remove the partition from extent map
string emsg;
rc = fDbrm->restorePartition(oidList, restorePartitionStmt.fPartitions, emsg);
if (rc != 0)
{
throw std::runtime_error(emsg);
}
}
catch (exception& ex)
{
logging::Message::Args args;
logging::Message message(ex.what());
if ((rc == BRM::ERR_NOT_EXIST_PARTITION) || (rc == BRM::ERR_INVALID_OP_LAST_PARTITION) ||
(rc == BRM::ERR_PARTITION_DISABLED) || (rc == BRM::ERR_TABLE_NOT_LOCKED))
result.result = USER_ERROR;
else if (rc == BRM::ERR_PARTITION_ENABLED)
result.result = PARTITION_WARNING;
else
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
catch (...)
{
// cerr << "RestorePartitionProcessor::processPackage: caught unknown exception!" << endl;
logging::Message::Args args;
logging::Message message(1);
args.add("Enable partition: ");
args.add("encountered unkown exception");
args.add("");
args.add("");
message.format(args);
result.result = DROP_ERROR;
result.message = message;
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
}
fSessionManager.rolledback(txnID);
return result;
}
// Log the DDL statement
logging::logDDL(restorePartitionStmt.fSessionID, txnID.id, restorePartitionStmt.fSql,
restorePartitionStmt.fOwner);
try
{
fDbrm->releaseTableLock(uniqueID);
}
catch (std::exception&)
{
result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID);
return result;
}
fSessionManager.committed(txnID);
return result;
}
}
} // namespace ddlpackageprocessor

View File

@ -39,20 +39,19 @@ namespace ddlpackageprocessor
*/
class RestorePartitionProcessor : public DDLPackageProcessor
{
public:
RestorePartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {}
/** @brief process a drop table statement
*
* @param dropTableStmt the drop table statement
*/
EXPORT DDLResult processPackage(ddlpackage::RestorePartitionStatement& RestorePartitionStmt);
protected:
private:
public:
RestorePartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm)
{
}
/** @brief process a drop table statement
*
* @param dropTableStmt the drop table statement
*/
EXPORT DDLResult processPackage(ddlpackage::RestorePartitionStatement& RestorePartitionStmt);
protected:
private:
};
} // namespace ddlpackageprocessor
} // namespace ddlpackageprocessor
#undef EXPORT

File diff suppressed because it is too large Load Diff

View File

@ -46,183 +46,183 @@ namespace dmlpackage
{
boost::mutex CalpontDMLFactory::fParserLock;
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackage(dmlpackage::VendorDMLStatement& vpackage,
std::string defaultSchema /*= ""*/)
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackage(
dmlpackage::VendorDMLStatement& vpackage, std::string defaultSchema /*= ""*/)
{
CalpontDMLPackage* packagePtr = 0;
CalpontDMLPackage* packagePtr = 0;
try
try
{
std::string dmlStatement = vpackage.get_DMLStatement();
//@Bug 2680. DMLParser is not thread safe.
boost::mutex::scoped_lock lk(fParserLock);
DMLParser parser;
if (defaultSchema.size())
{
std::string dmlStatement = vpackage.get_DMLStatement();
//@Bug 2680. DMLParser is not thread safe.
boost::mutex::scoped_lock lk(fParserLock);
DMLParser parser;
if (defaultSchema.size())
{
parser.setDefaultSchema(defaultSchema);
}
parser.parse(dmlStatement.c_str());
if (parser.good())
{
const ParseTree& ptree = parser.getParseTree();
SqlStatement* statementPtr = ptree[0];
int dmlStatementType = statementPtr->getStatementType();
switch (dmlStatementType)
{
case DML_INSERT:
packagePtr = new InsertDMLPackage(statementPtr->getSchemaName(), statementPtr->getTableName(),
ptree.fSqlText, vpackage.get_SessionID() );
packagePtr->set_SQLStatement(dmlStatement);
(void)packagePtr->buildFromSqlStatement(*statementPtr);
break;
case DML_UPDATE:
packagePtr = new UpdateDMLPackage(statementPtr->getSchemaName(), statementPtr->getTableName(),
ptree.fSqlText, vpackage.get_SessionID() );
packagePtr->set_SQLStatement(dmlStatement);
(void)packagePtr->buildFromSqlStatement(*statementPtr);
break;
case DML_DELETE:
packagePtr = new DeleteDMLPackage(statementPtr->getSchemaName(), statementPtr->getTableName(),
ptree.fSqlText, vpackage.get_SessionID() );
packagePtr->set_SQLStatement(dmlStatement);
(void)packagePtr->buildFromSqlStatement(*statementPtr);
break;
case DML_COMMAND:
packagePtr = new CommandDMLPackage(ptree.fSqlText, vpackage.get_SessionID());
(void)packagePtr->buildFromSqlStatement(*statementPtr);
break;
default:
cerr << "makeCalpontDMLPackage: invalid statement type" << endl;
break;
}
}
}
catch (std::exception& ex)
{
cerr << "makeCalpontDMLPackage:" << ex.what() << endl;
}
catch (...)
{
cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl;
parser.setDefaultSchema(defaultSchema);
}
return packagePtr;
parser.parse(dmlStatement.c_str());
if (parser.good())
{
const ParseTree& ptree = parser.getParseTree();
SqlStatement* statementPtr = ptree[0];
int dmlStatementType = statementPtr->getStatementType();
switch (dmlStatementType)
{
case DML_INSERT:
packagePtr = new InsertDMLPackage(statementPtr->getSchemaName(), statementPtr->getTableName(),
ptree.fSqlText, vpackage.get_SessionID());
packagePtr->set_SQLStatement(dmlStatement);
(void)packagePtr->buildFromSqlStatement(*statementPtr);
break;
case DML_UPDATE:
packagePtr = new UpdateDMLPackage(statementPtr->getSchemaName(), statementPtr->getTableName(),
ptree.fSqlText, vpackage.get_SessionID());
packagePtr->set_SQLStatement(dmlStatement);
(void)packagePtr->buildFromSqlStatement(*statementPtr);
break;
case DML_DELETE:
packagePtr = new DeleteDMLPackage(statementPtr->getSchemaName(), statementPtr->getTableName(),
ptree.fSqlText, vpackage.get_SessionID());
packagePtr->set_SQLStatement(dmlStatement);
(void)packagePtr->buildFromSqlStatement(*statementPtr);
break;
case DML_COMMAND:
packagePtr = new CommandDMLPackage(ptree.fSqlText, vpackage.get_SessionID());
(void)packagePtr->buildFromSqlStatement(*statementPtr);
break;
default: cerr << "makeCalpontDMLPackage: invalid statement type" << endl; break;
}
}
}
catch (std::exception& ex)
{
cerr << "makeCalpontDMLPackage:" << ex.what() << endl;
}
catch (...)
{
cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl;
}
return packagePtr;
}
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromBuffer(dmlpackage::VendorDMLStatement& vpackage)
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromBuffer(
dmlpackage::VendorDMLStatement& vpackage)
{
CalpontDMLPackage* packagePtr = 0;
CalpontDMLPackage* packagePtr = 0;
try
try
{
int dmlStatementType = vpackage.get_DMLStatementType();
switch (dmlStatementType)
{
int dmlStatementType = vpackage.get_DMLStatementType();
case DML_INSERT:
packagePtr = new InsertDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(),
vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer(), vpackage.get_Columns(),
vpackage.get_Rows());
break;
switch (dmlStatementType)
{
case DML_INSERT:
packagePtr = new InsertDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer
(), vpackage.get_Columns(), vpackage.get_Rows());
break;
case DML_UPDATE:
packagePtr = new UpdateDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(),
vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer(), vpackage.get_Columns(),
vpackage.get_Rows());
break;
case DML_UPDATE:
packagePtr = new UpdateDMLPackage(vpackage.get_SchemaName(),
vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer
(), vpackage.get_Columns(), vpackage.get_Rows());
break;
case DML_DELETE:
packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(),
vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer(), vpackage.get_Columns(),
vpackage.get_Rows());
break;
case DML_DELETE:
packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(),
vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer
(), vpackage.get_Columns(), vpackage.get_Rows());
break;
case DML_COMMAND:
packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID());
case DML_COMMAND:
packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID() );
break;
break;
default:
cerr << "makeCalpontDMLPackage: invalid statement type" << endl;
break;
}
}
catch (std::exception& ex)
{
cerr << "makeCalpontDMLPackage:" << ex.what() << endl;
}
catch (...)
{
cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl;
default: cerr << "makeCalpontDMLPackage: invalid statement type" << endl; break;
}
}
catch (std::exception& ex)
{
cerr << "makeCalpontDMLPackage:" << ex.what() << endl;
}
catch (...)
{
cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl;
}
return packagePtr;
return packagePtr;
}
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage)
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackageFromMysqlBuffer(
dmlpackage::VendorDMLStatement& vpackage)
{
CalpontDMLPackage* packagePtr = 0;
CalpontDMLPackage* packagePtr = 0;
try
try
{
int dmlStatementType = vpackage.get_DMLStatementType();
switch (dmlStatementType)
{
int dmlStatementType = vpackage.get_DMLStatementType();
case DML_INSERT:
packagePtr = new InsertDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(),
vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromMysqlBuffer(vpackage.get_ColNames(), vpackage.get_values(),
vpackage.get_Columns(), vpackage.get_Rows(),
vpackage.get_nullValues());
break;
switch (dmlStatementType)
{
case DML_INSERT:
packagePtr = new InsertDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromMysqlBuffer(vpackage.get_ColNames(), vpackage.get_values(), vpackage.get_Columns(), vpackage.get_Rows(), vpackage.get_nullValues());
break;
case DML_COMMAND:
packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID());
break;
case DML_COMMAND:
packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID() );
break;
case DML_DELETE:
packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(),
vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromMysqlBuffer(vpackage.get_ColNames(), vpackage.get_values(),
vpackage.get_Columns(), vpackage.get_Rows(),
vpackage.get_nullValues());
break;
case DML_DELETE:
packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(),
vpackage.get_DMLStatement(), vpackage.get_SessionID() );
(void)packagePtr->buildFromMysqlBuffer(vpackage.get_ColNames(), vpackage.get_values(), vpackage.get_Columns(), vpackage.get_Rows(), vpackage.get_nullValues());
break;
default:
cerr << "makeCalpontDMLPackage: invalid statement type" << endl;
break;
}
}
catch (std::exception& ex)
{
cerr << "makeCalpontDMLPackage:" << ex.what() << endl;
}
catch (...)
{
cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl;
default: cerr << "makeCalpontDMLPackage: invalid statement type" << endl; break;
}
}
catch (std::exception& ex)
{
cerr << "makeCalpontDMLPackage:" << ex.what() << endl;
}
catch (...)
{
cerr << "makeCalpontDMLPackage: caught unknown exception!" << endl;
}
return packagePtr;
return packagePtr;
}
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontUpdatePackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage, dmlpackage::UpdateSqlStatement& updateStmt)
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontUpdatePackageFromMysqlBuffer(
dmlpackage::VendorDMLStatement& vpackage, dmlpackage::UpdateSqlStatement& updateStmt)
{
CalpontDMLPackage* packagePtr = new UpdateDMLPackage((updateStmt.fNamePtr)->fSchema, (updateStmt.fNamePtr)->fName,
vpackage.get_DMLStatement(), vpackage.get_SessionID() );
UpdateDMLPackage* updatePkgPtr = dynamic_cast<UpdateDMLPackage*>(packagePtr);
updatePkgPtr->buildUpdateFromMysqlBuffer(updateStmt);
packagePtr = dynamic_cast<CalpontDMLPackage*>(updatePkgPtr);
return packagePtr;
CalpontDMLPackage* packagePtr =
new UpdateDMLPackage((updateStmt.fNamePtr)->fSchema, (updateStmt.fNamePtr)->fName,
vpackage.get_DMLStatement(), vpackage.get_SessionID());
UpdateDMLPackage* updatePkgPtr = dynamic_cast<UpdateDMLPackage*>(packagePtr);
updatePkgPtr->buildUpdateFromMysqlBuffer(updateStmt);
packagePtr = dynamic_cast<CalpontDMLPackage*>(updatePkgPtr);
return packagePtr;
}
} //namespace dmlpackage
} // namespace dmlpackage

View File

@ -35,39 +35,38 @@
#endif
namespace dmlpackage
{
class CalpontDMLFactory
{
/** @brief a concrete implementation responsible for creating
* the proper concrete realization of a CalpontDMLPackage
* given a VendorDMLStatement.
*/
public:
/** @brief a concrete implementation responsible for creating
* the proper concrete realization of a CalpontDMLPackage
* given a VendorDMLStatement.
*/
public:
/** @brief factory method
*
* @param vpackage the VendorDMLStatement
* @param defaultSchema the default schema to be used for DML statements
*/
EXPORT static dmlpackage::CalpontDMLPackage* makeCalpontDMLPackage(dmlpackage::VendorDMLStatement& vpackage,
std::string defaultSchema = "");
/** @brief factory method
*
* @param vpackage the VendorDMLStatement
* @param defaultSchema the default schema to be used for DML statements
*/
EXPORT static dmlpackage::CalpontDMLPackage* makeCalpontDMLPackage (dmlpackage::VendorDMLStatement& vpackage,
std::string defaultSchema = "" );
/** @brief old factory method!
*
* @param vpackage the VendorDMLStatement
*/
EXPORT static dmlpackage::CalpontDMLPackage* makeCalpontDMLPackageFromBuffer(
dmlpackage::VendorDMLStatement& vpackage);
/** @brief old factory method!
*
* @param vpackage the VendorDMLStatement
*/
EXPORT static dmlpackage::CalpontDMLPackage* makeCalpontDMLPackageFromBuffer(dmlpackage::VendorDMLStatement& vpackage);
EXPORT static dmlpackage::CalpontDMLPackage* makeCalpontDMLPackageFromMysqlBuffer(
dmlpackage::VendorDMLStatement& vpackage);
static dmlpackage::CalpontDMLPackage* makeCalpontUpdatePackageFromMysqlBuffer(
dmlpackage::VendorDMLStatement& vpackage, dmlpackage::UpdateSqlStatement& updateStmt);
EXPORT static dmlpackage::CalpontDMLPackage* makeCalpontDMLPackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage);
static dmlpackage::CalpontDMLPackage* makeCalpontUpdatePackageFromMysqlBuffer(dmlpackage::VendorDMLStatement& vpackage, dmlpackage::UpdateSqlStatement& updateStmt);
protected:
private:
static boost::mutex fParserLock;
protected:
private:
static boost::mutex fParserLock;
};
}
} // namespace dmlpackage
#undef EXPORT

View File

@ -31,59 +31,75 @@ namespace dmlpackage
*/
CalpontDMLPackage::CalpontDMLPackage()
: fPlan(new messageqcpp::ByteStream()),
fTable(0), fHasFilter(0), fLogging(true), fIsInsertSelect(false),
fIsBatchInsert(false), fIsCacheInsert(false), fIsAutocommitOn(false), fIsWarnToError(false), fTableOid(0)
: fPlan(new messageqcpp::ByteStream())
, fTable(0)
, fHasFilter(0)
, fLogging(true)
, fIsInsertSelect(false)
, fIsBatchInsert(false)
, fIsCacheInsert(false)
, fIsAutocommitOn(false)
, fIsWarnToError(false)
, fTableOid(0)
{
}
CalpontDMLPackage::CalpontDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID )
: fSchemaName(schemaName), fTableName( tableName ), fDMLStatement( dmlStatement ),
fSessionID(sessionID), fPlan(new messageqcpp::ByteStream()), fTable(0), fHasFilter(false), fLogging(true), fIsInsertSelect(false),
fIsBatchInsert(false), fIsCacheInsert(false), fIsAutocommitOn(false), fIsWarnToError(false), fTableOid(0)
CalpontDMLPackage::CalpontDMLPackage(std::string schemaName, std::string tableName, std::string dmlStatement,
int sessionID)
: fSchemaName(schemaName)
, fTableName(tableName)
, fDMLStatement(dmlStatement)
, fSessionID(sessionID)
, fPlan(new messageqcpp::ByteStream())
, fTable(0)
, fHasFilter(false)
, fLogging(true)
, fIsInsertSelect(false)
, fIsBatchInsert(false)
, fIsCacheInsert(false)
, fIsAutocommitOn(false)
, fIsWarnToError(false)
, fTableOid(0)
{
}
CalpontDMLPackage::~CalpontDMLPackage()
{
if ( 0 != fTable )
delete fTable;
if (0 != fTable)
delete fTable;
}
/*
* strip off whitespaces from a string
*/
std::string CalpontDMLPackage::StripLeadingWhitespace( std::string value )
std::string CalpontDMLPackage::StripLeadingWhitespace(std::string value)
{
for (;;)
for (;;)
{
string::size_type pos = value.find(' ', 0);
if (pos == 0)
{
string::size_type pos = value.find (' ', 0);
if (pos == 0)
{
value = value.substr (pos + 1, 10000);
}
else
{
// no more whitespace
break;
}
value = value.substr(pos + 1, 10000);
}
else
{
// no more whitespace
break;
}
}
return value;
return value;
}
void CalpontDMLPackage::initializeTable()
{
if (0 == fTable)
{
fTable = new DMLTable();
fTable->set_SchemaName(fSchemaName);
fTable->set_TableName(fTableName);
}
if (0 == fTable)
{
fTable = new DMLTable();
fTable->set_SchemaName(fSchemaName);
fTable->set_TableName(fTableName);
}
}
} // namespace dmlpackage
} // namespace dmlpackage

View File

@ -40,356 +40,354 @@ namespace dmlpackage
*/
class CalpontDMLPackage
{
public:
/** @brief ctor
*/
CalpontDMLPackage();
public:
/** @brief ctor
*/
CalpontDMLPackage();
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session id
*/
CalpontDMLPackage(std::string schemaName, std::string tableName, std::string dmlStatement, int sessionID);
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session id
*/
CalpontDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID );
/** @brief dtor
*/
virtual ~CalpontDMLPackage();
/** @brief dtor
*/
virtual ~CalpontDMLPackage();
/** @brief write a CalpontDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
virtual int write(messageqcpp::ByteStream& bytestream) = 0;
/** @brief write a CalpontDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
virtual int write( messageqcpp::ByteStream& bytestream ) = 0;
/** @brief read a CalpontDMLPackage from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
virtual int read(messageqcpp::ByteStream& bytestream) = 0;
/** @brief read a CalpontDMLPackage from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
virtual int read( messageqcpp::ByteStream& bytestream ) = 0;
/** @brief build a CalpontDMLPackage from a string buffer
*
* @param buffer the row buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
virtual int buildFromBuffer(std::string& buffer, int columns, int rows) = 0;
/** @brief build a CalpontDMLPackage from a string buffer
*
* @param buffer the row buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
virtual int buildFromBuffer( std::string& buffer, int columns, int rows ) = 0;
/** @brief build a CalpontDMLPackage from a parsed SqlStatement
*
* @param sqlStatement the parsed SqlStatement
*/
virtual int buildFromSqlStatement(SqlStatement& sqlStatement) = 0;
/** @brief build a CalpontDMLPackage from a parsed SqlStatement
*
* @param sqlStatement the parsed SqlStatement
*/
virtual int buildFromSqlStatement( SqlStatement& sqlStatement ) = 0;
/** @brief build a CalpontDMLPackage from valuelist built from mysql table fields
*
* @param tableValuesMap the value list for each column in the table
* @param colNameList the column name for each column
* @param columns number of columns in the table
* @param rows number of rows to be touched
*/
virtual int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns,
int rows, NullValuesBitset& nullValues) = 0;
/** @brief build a CalpontDMLPackage from valuelist built from mysql table fields
*
* @param tableValuesMap the value list for each column in the table
* @param colNameList the column name for each column
* @param columns number of columns in the table
* @param rows number of rows to be touched
*/
virtual int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues) = 0;
/** @brief get the table object
*/
DMLTable* get_Table()
{
return fTable;
}
/** @brief get the table object
*/
DMLTable* get_Table()
{
return fTable;
}
/** @brief set the DML statement (the parsed statement)
*
* @param statement the dml statement to set
*/
void set_DMLStatement(const std::string& statement)
{
fDMLStatement = statement;
}
/** @brief set the DML statement (the parsed statement)
*
* @param statement the dml statement to set
*/
void set_DMLStatement( const std::string& statement )
{
fDMLStatement = statement;
}
/** @brief get the DML statement (the parsed statement)
*/
const std::string get_DMLStatement() const
{
return fDMLStatement;
}
/** @brief get the DML statement (the parsed statement)
*/
const std::string get_DMLStatement() const
{
return fDMLStatement;
}
/** @brief set the SQL statement (the original SQL statement)
*
* @param statement the SQL statement to set (the original SQL statement with quotes)
*/
void set_SQLStatement(const std::string& statement)
{
fSQLStatement = statement;
}
/** @brief set the SQL statement (the original SQL statement)
*
* @param statement the SQL statement to set (the original SQL statement with quotes)
*/
void set_SQLStatement( const std::string& statement )
{
fSQLStatement = statement;
}
/** @brief get the SQL statement (the original SQL statement)
*/
const std::string get_SQLStatement() const
{
return fSQLStatement;
}
/** @brief get the SQL statement (the original SQL statement)
*/
const std::string get_SQLStatement() const
{
return fSQLStatement;
}
/** @brief get the logging flag
*/
bool get_Logging() const
{
return fLogging;
}
/** @brief get the logging flag
*/
bool get_Logging() const
{
return fLogging;
}
/** @brief set the logging flag
*
* @param logging the logging flag to set
*/
void set_Logging(bool logging)
{
fLogging = logging;
}
/** @brief set the logging flag
*
* @param logging the logging flag to set
*/
void set_Logging( bool logging )
{
fLogging = logging;
}
/** @brief get the logending flag
*/
bool get_Logending() const
{
return fLogending;
}
/** @brief get the logending flag
*/
bool get_Logending() const
{
return fLogending;
}
/** @brief set the logending flag
*
* @param logending the logending flag to set
*/
void set_Logending(bool logending)
{
fLogending = logending;
}
/** @brief set the logending flag
*
* @param logending the logending flag to set
*/
void set_Logending( bool logending )
{
fLogending = logending;
}
/** @brief get the isFromCol flag
*/
bool get_IsFromCol() const
{
return fIsFromCol;
}
/** @brief get the isFromCol flag
*/
bool get_IsFromCol() const
{
return fIsFromCol;
}
/** @brief set the update column from column flag
*
* @param logging the logging flag to set
*/
void set_IsFromCol(bool isFromCol)
{
fIsFromCol = isFromCol;
}
/** @brief set the Table name
*
* @param tableName the name to set
*/
void set_TableName(std::string& tableName)
{
fTableName = tableName;
/** @brief set the update column from column flag
*
* @param logging the logging flag to set
*/
void set_IsFromCol ( bool isFromCol )
{
fIsFromCol = isFromCol;
}
/** @brief set the Table name
*
* @param tableName the name to set
*/
void set_TableName( std::string& tableName )
{
fTableName = tableName;
if (fTable != 0)
fTable->set_TableName(tableName);
}
if (fTable != 0)
fTable->set_TableName(tableName);
}
/** @brief get the Table name
*/
const std::string get_TableName() const
{
return fTableName;
}
/** @brief get the Table name
*/
const std::string get_TableName() const
{
return fTableName;
}
/** @brief set the Schema name
*
* @param the schema to set
*/
void set_SchemaName(std::string& schemaName)
{
fSchemaName = schemaName;
/** @brief set the Schema name
*
* @param the schema to set
*/
void set_SchemaName( std::string& schemaName )
{
fSchemaName = schemaName;
if (fTable != 0)
fTable->set_SchemaName(schemaName);
}
if (fTable != 0)
fTable->set_SchemaName(schemaName);
}
/** @brief get the Schema name
*/
const std::string get_SchemaName() const
{
return fSchemaName;
}
/** @brief get the Schema name
*/
const std::string get_SchemaName() const
{
return fSchemaName;
}
/** @brief set the timezone
*
* @param the timezone to set
*/
void set_TimeZone(const std::string& timeZone)
{
fTimeZone = timeZone;
}
/** @brief set the timezone
*
* @param the timezone to set
*/
void set_TimeZone( const std::string& timeZone )
{
fTimeZone = timeZone;
}
/** @brief get the timezone
*/
const std::string get_TimeZone() const
{
return fTimeZone;
}
/** @brief get the timezone
*/
const std::string get_TimeZone() const
{
return fTimeZone;
}
/** @brief does this dml statement have a filter
*/
bool HasFilter() const
{
return fHasFilter;
}
void HasFilter(bool hasFilter)
{
fHasFilter = hasFilter;
}
/** @brief does this dml statement have a filter
*/
bool HasFilter() const
{
return fHasFilter;
}
void HasFilter( bool hasFilter)
{
fHasFilter = hasFilter;
}
/** @brief get the filter statement
*/
const std::string get_QueryString() const
{
return fQueryString;
}
/** @brief get the filter statement
*/
const std::string get_QueryString() const
{
return fQueryString;
}
/** @brief set the sessionID associated with this package
*/
void set_SessionID(int sessionID)
{
fSessionID = sessionID;
}
/** @brief set the sessionID associated with this package
*/
void set_SessionID( int sessionID )
{
fSessionID = sessionID;
}
/** @brief get the sessionID associated with this package
*/
int get_SessionID() const
{
return fSessionID;
}
/** @brief get the sessionID associated with this package
*/
int get_SessionID() const
{
return fSessionID;
}
/** @brief set the transaction ID associated with this package
*/
void set_TxnID(execplan::CalpontSystemCatalog::SCN txnID)
{
fTxnId = txnID;
}
/** @brief set the transaction ID associated with this package
*/
void set_TxnID( execplan::CalpontSystemCatalog::SCN txnID )
{
fTxnId = txnID;
}
/** @brief get the transaction ID associated with this package
*/
execplan::CalpontSystemCatalog::SCN get_TxnID() const
{
return fTxnId;
}
/** @brief set the chunkmanager associated with this package
*/
void set_ChunkManager(WriteEngine::ChunkManager* cm)
{
fCM = cm;
}
/** @brief get the transaction ID associated with this package
*/
execplan::CalpontSystemCatalog::SCN get_TxnID() const
{
return fTxnId;
}
/** @brief set the chunkmanager associated with this package
*/
void set_ChunkManager( WriteEngine::ChunkManager* cm )
{
fCM = cm;
}
/** @brief get the chunkmanager associated with this package
*/
WriteEngine::ChunkManager* get_ChunkManager() const
{
return fCM;
}
/** @brief get the chunkmanager associated with this package
*/
WriteEngine::ChunkManager* get_ChunkManager() const
{
return fCM;
}
/** @brief get the ExecutionPlan associated with this package
*/
boost::shared_ptr<messageqcpp::ByteStream> get_ExecutionPlan()
{
return fPlan;
}
/** @brief get the ExecutionPlan associated with this package
*/
boost::shared_ptr<messageqcpp::ByteStream> get_ExecutionPlan()
{
return fPlan;
}
bool get_isInsertSelect()
{
return fIsInsertSelect;
}
void set_isInsertSelect(const bool isInsertSelect)
{
fIsInsertSelect = isInsertSelect;
}
bool get_isInsertSelect()
{
return fIsInsertSelect;
}
void set_isInsertSelect( const bool isInsertSelect )
{
fIsInsertSelect = isInsertSelect;
}
bool get_isBatchInsert()
{
return fIsBatchInsert;
}
void set_isBatchInsert(const bool isBatchInsert)
{
fIsBatchInsert = isBatchInsert;
}
bool get_isBatchInsert()
{
return fIsBatchInsert;
}
void set_isBatchInsert( const bool isBatchInsert )
{
fIsBatchInsert = isBatchInsert;
}
bool get_isCacheInsert()
{
return fIsCacheInsert;
}
void set_isCacheInsert(const bool isCacheInsert)
{
fIsCacheInsert = isCacheInsert;
}
bool get_isCacheInsert()
{
return fIsCacheInsert;
}
void set_isCacheInsert( const bool isCacheInsert )
{
fIsCacheInsert = isCacheInsert;
}
bool get_isAutocommitOn()
{
return fIsAutocommitOn;
}
void set_isAutocommitOn(const bool isAutocommitOn)
{
fIsAutocommitOn = isAutocommitOn;
}
bool get_isAutocommitOn()
{
return fIsAutocommitOn;
}
void set_isAutocommitOn( const bool isAutocommitOn )
{
fIsAutocommitOn = isAutocommitOn;
}
bool get_isWarnToError()
{
return fIsWarnToError;
}
void set_isWarnToError(const bool isWarnToError)
{
fIsWarnToError = isWarnToError;
}
bool get_isWarnToError()
{
return fIsWarnToError;
}
void set_isWarnToError( const bool isWarnToError )
{
fIsWarnToError = isWarnToError;
}
uint32_t getTableOid()
{
return fTableOid;
}
void setTableOid(const uint32_t tableOid)
{
fTableOid = tableOid;
}
uint32_t getTableOid()
{
return fTableOid;
}
void setTableOid( const uint32_t tableOid )
{
fTableOid = tableOid;
}
void uuid(const boost::uuids::uuid& uuid)
{
fUuid = uuid;
}
const boost::uuids::uuid& uuid() const
{
return fUuid;
}
void uuid(const boost::uuids::uuid& uuid)
{
fUuid = uuid;
}
const boost::uuids::uuid& uuid() const
{
return fUuid;
}
protected:
void initializeTable();
protected:
void initializeTable();
std::string fSchemaName;
std::string fTimeZone;
std::string fTableName;
std::string fDMLStatement;
std::string fSQLStatement;
std::string fQueryString;
int fSessionID;
boost::uuids::uuid fUuid;
execplan::CalpontSystemCatalog::SCN fTxnId;
boost::shared_ptr<messageqcpp::ByteStream> fPlan;
DMLTable* fTable;
bool fHasFilter;
bool fLogging;
bool fLogending;
bool fIsFromCol;
std::string StripLeadingWhitespace( std::string value );
bool fIsInsertSelect;
bool fIsBatchInsert;
bool fIsCacheInsert;
bool fIsAutocommitOn;
bool fIsWarnToError;
uint32_t fTableOid;
WriteEngine::ChunkManager* fCM;
std::string fSchemaName;
std::string fTimeZone;
std::string fTableName;
std::string fDMLStatement;
std::string fSQLStatement;
std::string fQueryString;
int fSessionID;
boost::uuids::uuid fUuid;
execplan::CalpontSystemCatalog::SCN fTxnId;
boost::shared_ptr<messageqcpp::ByteStream> fPlan;
DMLTable* fTable;
bool fHasFilter;
bool fLogging;
bool fLogending;
bool fIsFromCol;
std::string StripLeadingWhitespace(std::string value);
bool fIsInsertSelect;
bool fIsBatchInsert;
bool fIsCacheInsert;
bool fIsAutocommitOn;
bool fIsWarnToError;
uint32_t fTableOid;
WriteEngine::ChunkManager* fCM;
};
}
} // namespace dmlpackage

View File

@ -31,70 +31,72 @@ using namespace std;
#undef COMMANDDMLPKG_DLLEXPORT
namespace dmlpackage
{
CommandDMLPackage::CommandDMLPackage()
{}
{
}
CommandDMLPackage::CommandDMLPackage( std::string dmlStatement, int sessionID)
: CalpontDMLPackage( "", "", dmlStatement, sessionID)
{}
CommandDMLPackage::CommandDMLPackage(std::string dmlStatement, int sessionID)
: CalpontDMLPackage("", "", dmlStatement, sessionID)
{
}
CommandDMLPackage::~CommandDMLPackage()
{}
{
}
int CommandDMLPackage::write(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
int retval = 1;
messageqcpp::ByteStream::byte package_type = DML_COMMAND;
bytestream << package_type;
messageqcpp::ByteStream::byte package_type = DML_COMMAND;
bytestream << package_type;
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id;
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id;
bytestream << fUuid;
bytestream << fUuid;
bytestream << fDMLStatement;
bytestream << fSQLStatement; // for cleartablelock, this is table lockID
bytestream << (uint8_t)fLogging;
bytestream << fSchemaName;
bytestream << fTimeZone;
bytestream << fTableName;
bytestream << fTableOid;
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsAutocommitOn);
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsBatchInsert);
return retval;
bytestream << fDMLStatement;
bytestream << fSQLStatement; // for cleartablelock, this is table lockID
bytestream << (uint8_t)fLogging;
bytestream << fSchemaName;
bytestream << fTimeZone;
bytestream << fTableName;
bytestream << fTableOid;
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsAutocommitOn);
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsBatchInsert);
return retval;
}
int CommandDMLPackage::read(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
int retval = 1;
messageqcpp::ByteStream::quadbyte session_id;
bytestream >> session_id;
fSessionID = session_id;
bytestream >> fUuid;
messageqcpp::ByteStream::quadbyte session_id;
bytestream >> session_id;
fSessionID = session_id;
bytestream >> fUuid;
bytestream >> fDMLStatement;
bytestream >> fSQLStatement; // for cleartablelock, this is table lockID
uint8_t logging;
bytestream >> logging;
fLogging = (logging != 0);
bytestream >> fSchemaName;
bytestream >> fTimeZone;
bytestream >> fTableName;
bytestream >> fTableOid;
bytestream >> reinterpret_cast< messageqcpp::ByteStream::byte&>(fIsAutocommitOn);
bytestream >> reinterpret_cast< messageqcpp::ByteStream::byte&>(fIsBatchInsert);
return retval;
bytestream >> fDMLStatement;
bytestream >> fSQLStatement; // for cleartablelock, this is table lockID
uint8_t logging;
bytestream >> logging;
fLogging = (logging != 0);
bytestream >> fSchemaName;
bytestream >> fTimeZone;
bytestream >> fTableName;
bytestream >> fTableOid;
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsAutocommitOn);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsBatchInsert);
return retval;
}
int CommandDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
{
CommandSqlStatement& cmdStmt = dynamic_cast<CommandSqlStatement&>(sqlStatement);
fDMLStatement = cmdStmt.fCommandText;
CommandSqlStatement& cmdStmt = dynamic_cast<CommandSqlStatement&>(sqlStatement);
fDMLStatement = cmdStmt.fCommandText;
return 1;
return 1;
}
} // namespace dmlpackage
} // namespace dmlpackage

View File

@ -40,63 +40,60 @@ namespace dmlpackage
*/
class CommandDMLPackage : public CalpontDMLPackage
{
public:
/** @brief ctor
*/
EXPORT CommandDMLPackage();
public:
/** @brief ctor
*/
EXPORT CommandDMLPackage();
/** @brief ctor
*/
EXPORT CommandDMLPackage(std::string dmlStatement, int sessionID);
/** @brief ctor
*/
EXPORT CommandDMLPackage( std::string dmlStatement, int sessionID );
/** @brief dtor
*/
EXPORT virtual ~CommandDMLPackage();
/** @brief dtor
*/
EXPORT virtual ~CommandDMLPackage();
/** @brief write a CommandDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief write a CommandDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief read CommandDMLPackage from bytestream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief do nothing
*
* @param buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
inline int buildFromBuffer(std::string& buffer, int columns = 0, int rows = 0)
{
return 1;
};
/** @brief read CommandDMLPackage from bytestream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief do nothing
*
* @param buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
inline int buildFromBuffer(std::string& buffer, int columns = 0, int rows = 0)
{
return 1;
};
/** @brief build a CommandDMLPackage from a CommandSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a CommandDMLPackage from a CommandSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param colNameList, tableValuesMap
* @param rows the number of rows in the buffer
*/
int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues)
{
return 1;
};
protected:
private:
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param colNameList, tableValuesMap
* @param rows the number of rows in the buffer
*/
int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows,
NullValuesBitset& nullValues)
{
return 1;
};
protected:
private:
};
}
} // namespace dmlpackage
#undef EXPORT

View File

@ -32,107 +32,109 @@ using namespace std;
namespace dmlpackage
{
DeleteDMLPackage::DeleteDMLPackage()
{}
{
}
DeleteDMLPackage::DeleteDMLPackage(std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID)
: CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID )
{}
DeleteDMLPackage::DeleteDMLPackage(std::string schemaName, std::string tableName, std::string dmlStatement,
int sessionID)
: CalpontDMLPackage(schemaName, tableName, dmlStatement, sessionID)
{
}
DeleteDMLPackage::~DeleteDMLPackage()
{}
{
}
int DeleteDMLPackage::write(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
int retval = 1;
messageqcpp::ByteStream::byte package_type = DML_DELETE;
bytestream << package_type;
messageqcpp::ByteStream::byte package_type = DML_DELETE;
bytestream << package_type;
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id;
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id;
/* if(fPlan != 0)
fHasFilter = true;
else
fHasFilter = false;
*/
messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter;
bytestream << hasFilter;
/* if(fPlan != 0)
fHasFilter = true;
else
fHasFilter = false;
*/
messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter;
bytestream << hasFilter;
bytestream << fUuid;
bytestream << fUuid;
bytestream << fDMLStatement;
bytestream << fSQLStatement;
bytestream << fSchemaName;
bytestream << fTimeZone;
bytestream << fDMLStatement;
bytestream << fSQLStatement;
bytestream << fSchemaName;
bytestream << fTimeZone;
if (fTable != 0)
{
retval = fTable->write(bytestream);
}
if (fTable != 0)
{
retval = fTable->write(bytestream);
}
if (fHasFilter)
{
bytestream += *(fPlan.get());
}
if (fHasFilter)
{
bytestream += *(fPlan.get());
}
return retval;
return retval;
}
/**
*
*/
int DeleteDMLPackage::read(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
int retval = 1;
messageqcpp::ByteStream::quadbyte session_id;
messageqcpp::ByteStream::quadbyte hasFilter;
messageqcpp::ByteStream::quadbyte session_id;
messageqcpp::ByteStream::quadbyte hasFilter;
bytestream >> session_id;
fSessionID = session_id;
bytestream >> session_id;
fSessionID = session_id;
bytestream >> hasFilter;
fHasFilter = (hasFilter != 0);
bytestream >> hasFilter;
fHasFilter = (hasFilter != 0);
bytestream >> fUuid;
bytestream >> fUuid;
std::string dmlStatement;
bytestream >> fDMLStatement;
bytestream >> fSQLStatement;
bytestream >> fSchemaName;
bytestream >> fTimeZone;
std::string dmlStatement;
bytestream >> fDMLStatement;
bytestream >> fSQLStatement;
bytestream >> fSchemaName;
bytestream >> fTimeZone;
fTable = new DMLTable();
retval = fTable->read(bytestream);
fTable = new DMLTable();
retval = fTable->read(bytestream);
if (fHasFilter)
{
fPlan.reset(new messageqcpp::ByteStream(bytestream));
}
if (fHasFilter)
{
fPlan.reset(new messageqcpp::ByteStream(bytestream));
}
return retval;
return retval;
}
int DeleteDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
{
int retval = 1;
int retval = 1;
DeleteSqlStatement& deleteStmt = dynamic_cast<DeleteSqlStatement&>(sqlStatement);
DeleteSqlStatement& deleteStmt = dynamic_cast<DeleteSqlStatement&>(sqlStatement);
initializeTable();
initializeTable();
if (0 != deleteStmt.fWhereClausePtr)
{
fHasFilter = true;
fQueryString = deleteStmt.getQueryString();
}
if (0 != deleteStmt.fWhereClausePtr)
{
fHasFilter = true;
fQueryString = deleteStmt.getQueryString();
}
// else all rows are deleted
// else all rows are deleted
return retval;
return retval;
}
/**
@ -141,84 +143,83 @@ int DeleteDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
int DeleteDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows)
{
#ifdef DML_PACKAGE_DEBUG
//cout << "The data buffer received: " << buffer << endl;
// cout << "The data buffer received: " << buffer << endl;
#endif
int retval = 1;
int retval = 1;
initializeTable();
initializeTable();
std::vector<std::string> dataList;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(":");
tokenizer tokens(buffer, sep);
std::vector<std::string> dataList;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(":");
tokenizer tokens(buffer, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{
dataList.push_back(StripLeadingWhitespace(*tok_iter));
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{
dataList.push_back(StripLeadingWhitespace(*tok_iter));
}
}
int n = 0;
int n = 0;
for (int i = 0; i < rows; i++)
{
//get a new row
Row aRow;
//Row *aRowPtr = new Row();
//std::string colName;
//std::string colValue;
//get row ID from the buffer
std::string rowid = dataList[n++];
aRow.set_RowID(atoll(rowid.c_str()));
//aRowPtr->set_RowID(atol(rowid.c_str()));
for (int i = 0; i < rows; i++)
{
// get a new row
Row aRow;
// Row *aRowPtr = new Row();
// std::string colName;
// std::string colValue;
// get row ID from the buffer
std::string rowid = dataList[n++];
aRow.set_RowID(atoll(rowid.c_str()));
// aRowPtr->set_RowID(atol(rowid.c_str()));
#ifdef DML_PACKAGE_DEBUG
//cout << "The row ID is " << rowid << endl;
// cout << "The row ID is " << rowid << endl;
#endif
/*
for (int j = 0; j < columns; j++)
{
//Build a column list
colName = dataList[n++];
colValue = dataList[n++];
#ifdef DML_PACKAGE_DEBUG
cout << "The column data: " << colName << " " << colValue << endl;
#endif
DMLColumn* aColumn = new DMLColumn(colName, colValue);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
fTable->get_RowList().push_back(aRowPtr);
*/
/*
for (int j = 0; j < columns; j++)
{
//Build a column list
colName = dataList[n++];
colValue = dataList[n++];
#ifdef DML_PACKAGE_DEBUG
cout << "The column data: " << colName << " " << colValue << endl;
#endif
DMLColumn* aColumn = new DMLColumn(colName, colValue);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
fTable->get_RowList().push_back(aRowPtr);
*/
}
return retval;
return retval;
}
int DeleteDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues )
int DeleteDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap,
int columns, int rows, NullValuesBitset& nullValues)
{
int retval = 1;
int retval = 1;
initializeTable();
//The row already built from MySql parser.
/* Row *aRowPtr = new Row();
std::string colName;
std::vector<std::string> colValList;
for (int j = 0; j < columns; j++)
{
//Build a column list
colName = colNameList[j];
initializeTable();
// The row already built from MySql parser.
/* Row *aRowPtr = new Row();
std::string colName;
std::vector<std::string> colValList;
for (int j = 0; j < columns; j++)
{
//Build a column list
colName = colNameList[j];
colValList = tableValuesMap[j];
colValList = tableValuesMap[j];
DMLColumn* aColumn = new DMLColumn(colName, colValList, false);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
fTable->get_RowList().push_back(aRowPtr); */
return retval;
DMLColumn* aColumn = new DMLColumn(colName, colValList, false);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
fTable->get_RowList().push_back(aRowPtr); */
return retval;
}
} // namespace dmlpackage
} // namespace dmlpackage

View File

@ -40,65 +40,61 @@ namespace dmlpackage
*/
class DeleteDMLPackage : public CalpontDMLPackage
{
public:
/** @brief ctor
*/
EXPORT DeleteDMLPackage();
public:
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session ID
*/
EXPORT DeleteDMLPackage(std::string schemaName, std::string tableName, std::string dmlStatement,
int sessionID);
/** @brief ctor
*/
EXPORT DeleteDMLPackage();
/** @brief dtor
*/
EXPORT virtual ~DeleteDMLPackage();
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session ID
*/
EXPORT DeleteDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID );
/** @brief write a DeleteDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief dtor
*/
EXPORT virtual ~DeleteDMLPackage();
/** @brief read a DeleteDMLPackage from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief write a DeleteDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief build a DeleteDMLPackage from a string buffer
*
* @param buffer [rowId, columnName, colValue]
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromBuffer(std::string& buffer, int columns, int rows);
/** @brief read a DeleteDMLPackage from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief build a DeleteDMLPackage from a string buffer
*
* @param buffer [rowId, columnName, colValue]
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromBuffer(std::string& buffer, int columns, int rows);
/** @brief build a DeleteDMLPackage from a parsed DeleteSqlStatement
*
* @param sqlStatement the parsed DeleteSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param colNameList, tableValuesMap
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues);
protected:
private:
/** @brief build a DeleteDMLPackage from a parsed DeleteSqlStatement
*
* @param sqlStatement the parsed DeleteSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param colNameList, tableValuesMap
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns,
int rows, NullValuesBitset& nullValues);
protected:
private:
};
}
} // namespace dmlpackage
#undef EXPORT

File diff suppressed because it is too large Load Diff

View File

@ -32,150 +32,141 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#pragma once
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype
{
NAME = 258,
STRING = 259,
INTNUM = 260,
APPROXNUM = 261,
SELECT = 262,
ALL = 263,
DISTINCT = 264,
NULLX = 265,
USER = 266,
INDICATOR = 267,
AMMSC = 268,
PARAMETER = 269,
ANY = 270,
SOME = 271,
OR = 272,
AND = 273,
NOT = 274,
COMPARISON = 275,
UMINUS = 276,
AS = 277,
ASC = 278,
AUTHORIZATION = 279,
BETWEEN = 280,
BY = 281,
CHARACTER = 282,
CHECK = 283,
CLOSE = 284,
COMMIT = 285,
CONTINUE = 286,
CREATE = 287,
CURRENT = 288,
CURSOR = 289,
IDB_DECIMAL = 290,
DECLARE = 291,
DEFAULT = 292,
DELETE = 293,
DESC = 294,
IDB_DOUBLE = 295,
ESCAPE = 296,
EXISTS = 297,
FETCH = 298,
IDB_FLOAT = 299,
FOR = 300,
FOREIGN = 301,
FOUND = 302,
FROM = 303,
GOTO = 304,
GRANT = 305,
IDB_GROUP = 306,
HAVING = 307,
IN = 308,
INSERT = 309,
INTEGER = 310,
INTO = 311,
IS = 312,
KEY = 313,
LANGUAGE = 314,
LIKE = 315,
NUMERIC = 316,
OF = 317,
ON = 318,
OPEN = 319,
OPTION = 320,
ORDER = 321,
PRECISION = 322,
PRIMARY = 323,
PRIVILEGES = 324,
PROCEDURE = 325,
PUBLIC = 326,
REAL = 327,
REFERENCES = 328,
ROLLBACK = 329,
SCHEMA = 330,
SET = 331,
SMALLINT = 332,
SQLCODE = 333,
SQLERROR = 334,
TABLE = 335,
TO = 336,
UNION = 337,
UNIQUE = 338,
UPDATE = 339,
VALUES = 340,
VIEW = 341,
WHENEVER = 342,
WHERE = 343,
WITH = 344,
WORK = 345
NAME = 258,
STRING = 259,
INTNUM = 260,
APPROXNUM = 261,
SELECT = 262,
ALL = 263,
DISTINCT = 264,
NULLX = 265,
USER = 266,
INDICATOR = 267,
AMMSC = 268,
PARAMETER = 269,
ANY = 270,
SOME = 271,
OR = 272,
AND = 273,
NOT = 274,
COMPARISON = 275,
UMINUS = 276,
AS = 277,
ASC = 278,
AUTHORIZATION = 279,
BETWEEN = 280,
BY = 281,
CHARACTER = 282,
CHECK = 283,
CLOSE = 284,
COMMIT = 285,
CONTINUE = 286,
CREATE = 287,
CURRENT = 288,
CURSOR = 289,
IDB_DECIMAL = 290,
DECLARE = 291,
DEFAULT = 292,
DELETE = 293,
DESC = 294,
IDB_DOUBLE = 295,
ESCAPE = 296,
EXISTS = 297,
FETCH = 298,
IDB_FLOAT = 299,
FOR = 300,
FOREIGN = 301,
FOUND = 302,
FROM = 303,
GOTO = 304,
GRANT = 305,
IDB_GROUP = 306,
HAVING = 307,
IN = 308,
INSERT = 309,
INTEGER = 310,
INTO = 311,
IS = 312,
KEY = 313,
LANGUAGE = 314,
LIKE = 315,
NUMERIC = 316,
OF = 317,
ON = 318,
OPEN = 319,
OPTION = 320,
ORDER = 321,
PRECISION = 322,
PRIMARY = 323,
PRIVILEGES = 324,
PROCEDURE = 325,
PUBLIC = 326,
REAL = 327,
REFERENCES = 328,
ROLLBACK = 329,
SCHEMA = 330,
SET = 331,
SMALLINT = 332,
SQLCODE = 333,
SQLERROR = 334,
TABLE = 335,
TO = 336,
UNION = 337,
UNIQUE = 338,
UPDATE = 339,
VALUES = 340,
VIEW = 341,
WHENEVER = 342,
WHERE = 343,
WITH = 344,
WORK = 345
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
int intval;
double floatval;
char* strval;
int subtok;
dmlpackage::SqlStatementList* sqlStmtList;
dmlpackage::SqlStatement* sqlStmt;
dmlpackage::TableName* tblName;
dmlpackage::ColumnNameList* colNameList;
dmlpackage::ValuesOrQuery* valsOrQuery;
dmlpackage::ValuesList* valsList;
dmlpackage::QuerySpec* querySpec;
dmlpackage::TableNameList* tableNameList;
dmlpackage::TableExpression* tableExpression;
dmlpackage::WhereClause* whereClause;
dmlpackage::SearchCondition* searchCondition;
dmlpackage::ExistanceTestPredicate* existPredicate;
dmlpackage::AllOrAnyPredicate* allOrAnyPredicate;
dmlpackage::InPredicate* inPredicate;
dmlpackage::NullTestPredicate* nullTestPredicate;
dmlpackage::LikePredicate* likePredicate;
dmlpackage::BetweenPredicate* betweenPredicate;
dmlpackage::ComparisonPredicate* comparisonPredicate;
dmlpackage::Predicate* predicate;
dmlpackage::FromClause* fromClause;
dmlpackage::SelectFilter* selectFilter;
dmlpackage::GroupByClause* groupByClause;
dmlpackage::HavingClause* havingClause;
dmlpackage::Escape* escape;
dmlpackage::AtomList* atomList;
dmlpackage::ColumnAssignment* colAssignment;
dmlpackage::ColumnAssignmentList* colAssignmentList;
int intval;
double floatval;
char* strval;
int subtok;
dmlpackage::SqlStatementList* sqlStmtList;
dmlpackage::SqlStatement* sqlStmt;
dmlpackage::TableName* tblName;
dmlpackage::ColumnNameList* colNameList;
dmlpackage::ValuesOrQuery* valsOrQuery;
dmlpackage::ValuesList* valsList;
dmlpackage::QuerySpec* querySpec;
dmlpackage::TableNameList* tableNameList;
dmlpackage::TableExpression* tableExpression;
dmlpackage::WhereClause* whereClause;
dmlpackage::SearchCondition* searchCondition;
dmlpackage::ExistanceTestPredicate* existPredicate;
dmlpackage::AllOrAnyPredicate* allOrAnyPredicate;
dmlpackage::InPredicate* inPredicate;
dmlpackage::NullTestPredicate* nullTestPredicate;
dmlpackage::LikePredicate* likePredicate;
dmlpackage::BetweenPredicate* betweenPredicate;
dmlpackage::ComparisonPredicate* comparisonPredicate;
dmlpackage::Predicate* predicate;
dmlpackage::FromClause* fromClause;
dmlpackage::SelectFilter* selectFilter;
dmlpackage::GroupByClause* groupByClause;
dmlpackage::HavingClause* havingClause;
dmlpackage::Escape* escape;
dmlpackage::AtomList* atomList;
dmlpackage::ColumnAssignment* colAssignment;
dmlpackage::ColumnAssignmentList* colAssignmentList;
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#define YYSTYPE_IS_TRIVIAL 1
#define yystype YYSTYPE /* obsolescent; will be withdrawn */
#define YYSTYPE_IS_DECLARED 1
extern YYSTYPE dmllval;

File diff suppressed because it is too large Load Diff

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: dmlcolumn.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: dmlcolumn.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#define DMLPKGCOLUMN_DLLEXPORT
#include "dmlcolumn.h"
@ -31,95 +31,93 @@
namespace dmlpackage
{
DMLColumn::DMLColumn()
{}
DMLColumn::DMLColumn(std::string name, std::string value, bool isFromCol, uint32_t funcScale, bool isNULL)
{
fName = name;
fData = value;
if (( strcasecmp(value.c_str(), "NULL") == 0) || (value.length() == 0) )
{
isNULL = true;
}
fisNULL = isNULL;
fIsFromCol = isFromCol;
fFuncScale = funcScale;
}
DMLColumn::DMLColumn(std::string name, std::vector<std::string>& valueList, bool isFromCol, uint32_t funcScale, bool isNULL)
DMLColumn::DMLColumn(std::string name, std::string value, bool isFromCol, uint32_t funcScale, bool isNULL)
{
fName = name;
fColValuesList = valueList;
fisNULL = isNULL;
fIsFromCol = isFromCol;
fFuncScale = funcScale;
fName = name;
fData = value;
if ((strcasecmp(value.c_str(), "NULL") == 0) || (value.length() == 0))
{
isNULL = true;
}
fisNULL = isNULL;
fIsFromCol = isFromCol;
fFuncScale = funcScale;
}
DMLColumn::DMLColumn(std::string name, std::vector<std::string>& valueList, bool isFromCol,
uint32_t funcScale, bool isNULL)
{
fName = name;
fColValuesList = valueList;
fisNULL = isNULL;
fIsFromCol = isFromCol;
fFuncScale = funcScale;
}
DMLColumn::~DMLColumn()
{}
{
}
int DMLColumn::read(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
bytestream >> fName;
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL);
uint32_t vectorSize;
bytestream >> vectorSize;
int retval = 1;
bytestream >> fName;
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL);
uint32_t vectorSize;
bytestream >> vectorSize;
if (vectorSize > 0 )
if (vectorSize > 0)
{
for (uint32_t i = 0; i < vectorSize; i++)
{
for ( uint32_t i = 0; i < vectorSize; i++ )
{
std::string dataStr;
bytestream >> dataStr;
// if ( !fisNULL && (dataStr.length() == 0 ))
// dataStr = (char) 0;
fColValuesList.push_back( dataStr);
}
std::string dataStr;
bytestream >> dataStr;
// if ( !fisNULL && (dataStr.length() == 0 ))
// dataStr = (char) 0;
fColValuesList.push_back(dataStr);
}
else
bytestream >> fData; //deprecated.
}
else
bytestream >> fData; // deprecated.
if ( (fColValuesList.size() < 1) && (fColValuesList.size() > 0) ) //deprecated.
fData = fColValuesList[0] ; //deprecated.
if ((fColValuesList.size() < 1) && (fColValuesList.size() > 0)) // deprecated.
fData = fColValuesList[0]; // deprecated.
//bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsFromCol);
bytestream >> (uint32_t&) fFuncScale;
return retval;
// bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fisNULL);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsFromCol);
bytestream >> (uint32_t&)fFuncScale;
return retval;
}
int DMLColumn::write(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
bytestream << fName;
bytestream << static_cast<uint8_t>(fisNULL);
uint32_t vectorSize = fColValuesList.size();
bytestream << vectorSize;
int retval = 1;
bytestream << fName;
bytestream << static_cast<uint8_t>(fisNULL);
uint32_t vectorSize = fColValuesList.size();
bytestream << vectorSize;
if (vectorSize > 0 )
if (vectorSize > 0)
{
for (uint32_t i = 0; i < vectorSize; i++)
{
for ( uint32_t i = 0; i < vectorSize; i++ )
{
bytestream << fColValuesList[i];
}
bytestream << fColValuesList[i];
}
else
bytestream << fData; //deprecated.
}
else
bytestream << fData; // deprecated.
//bytestream << static_cast<uint8_t>(fisNULL);
bytestream << static_cast<uint8_t>(fIsFromCol);
bytestream << (uint32_t)fFuncScale;
return retval;
// bytestream << static_cast<uint8_t>(fisNULL);
bytestream << static_cast<uint8_t>(fIsFromCol);
bytestream << (uint32_t)fFuncScale;
return retval;
}
} //namespace dmlpackage
} // namespace dmlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: dmlcolumn.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: dmlcolumn.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
/** @file */
#pragma once
@ -38,132 +38,128 @@
namespace dmlpackage
{
/** @brief concrete implementation of a DMLObject
* Specifically for representing a database column
*/
* Specifically for representing a database column
*/
class DMLColumn : public DMLObject
{
public:
/** @brief ctor
*/
EXPORT DMLColumn();
public:
/** @brief ctor
*/
EXPORT DMLColumn();
/** @brief ctor
*/
/** @brief ctor
*/
EXPORT DMLColumn(std::string name, std::string value, bool isFromCol = false, uint32_t funcScale = 0,
bool isNULL = false);
/** @brief new ctor
* isNUll is currently not in use. It supposed to indicate whether each value is null or not.
*/
EXPORT DMLColumn(std::string name, std::string value, bool isFromCol = false, uint32_t funcScale = 0, bool isNULL = false);
/** @brief new ctor
* isNUll is currently not in use. It supposed to indicate whether each value is null or not.
*/
EXPORT DMLColumn(std::string name, std::vector<std::string>& valueList, bool isFromCol = false,
uint32_t funcScale = 0, bool isNULL = false);
EXPORT DMLColumn(std::string name, std::vector<std::string>& valueList, bool isFromCol = false, uint32_t funcScale = 0, bool isNULL = false );
/** @brief dtor
*/
EXPORT ~DMLColumn();
/** @brief dtor
*/
EXPORT ~DMLColumn();
/** @brief read a DMLColumn from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief read a DMLColumn from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief write a DML column to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief write a DML column to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief get the data for the column
*/
const std::string get_Data() const
{
return fData;
}
/** @brief get the data for the column
*/
const std::string get_Data() const
{
return fData;
}
const std::vector<std::string>& get_DataVector() const
{
return fColValuesList;
}
/** @brief get the data for the column
*/
bool get_isnull() const
{
return fisNULL;
}
/** @brief get the fIsFromCol data for the column
*/
bool get_isFromCol() const
{
return fIsFromCol;
}
/** @brief get the fFuncScale data for the column
*/
uint32_t get_funcScale() const
{
return fFuncScale;
}
/** @brief get the column name
*/
const std::string get_Name() const
{
return fName;
}
/** @brief set the column name
*/
EXPORT void set_Name(std::string name)
{
boost::algorithm::to_lower(name);
fName = name;
}
/** @brief set the NULL flag
*/
void set_isnull(bool isNULL)
{
fisNULL = isNULL;
}
/** @brief set the fIsFromCol flag
*/
void set_isFromCol(bool isFromCol)
{
fIsFromCol = isFromCol;
}
/** @brief set the fFuncScale
*/
void set_funcScale(uint32_t funcScale)
{
fFuncScale = funcScale;
}
void set_Data(std::string data)
{
fData = data;
}
const std::vector<std::string>& get_DataVector() const
{
return fColValuesList;
}
/** @brief get the data for the column
*/
bool get_isnull() const
{
return fisNULL;
}
/** @brief get the fIsFromCol data for the column
*/
bool get_isFromCol() const
{
return fIsFromCol;
}
/** @brief get the fFuncScale data for the column
*/
uint32_t get_funcScale() const
{
return fFuncScale;
}
/** @brief get the column name
*/
const std::string get_Name() const
{
return fName;
}
/** @brief set the column name
*/
EXPORT void set_Name( std::string name)
{
boost::algorithm::to_lower(name);
fName = name;
}
/** @brief set the NULL flag
*/
void set_isnull( bool isNULL)
{
fisNULL = isNULL;
}
/** @brief set the fIsFromCol flag
*/
void set_isFromCol( bool isFromCol)
{
fIsFromCol = isFromCol;
}
/** @brief set the fFuncScale
*/
void set_funcScale( uint32_t funcScale)
{
fFuncScale = funcScale;
}
void set_Data ( std::string data)
{
fData = data;
}
void set_DataVector ( std::vector<std::string>& dataVec)
{
fColValuesList = dataVec;
}
protected:
private:
std::string fName;
std::string fData;
std::vector<std::string> fColValuesList;
bool fisNULL;
bool fIsFromCol;
uint32_t fFuncScale;
void set_DataVector(std::vector<std::string>& dataVec)
{
fColValuesList = dataVec;
}
protected:
private:
std::string fName;
std::string fData;
std::vector<std::string> fColValuesList;
bool fisNULL;
bool fIsFromCol;
uint32_t fFuncScale;
};
/** @brief a vector of DMLColumns
*/
typedef std::vector<DMLColumn*>ColumnList;
*/
typedef std::vector<DMLColumn*> ColumnList;
}
} // namespace dmlpackage
#undef EXPORT

View File

@ -16,24 +16,20 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: dmlobject.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: dmlobject.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include "dmlobject.h"
namespace dmlpackage
{
DMLObject::DMLObject()
{
}
DMLObject::~DMLObject()
{
}
} // namespace dmlpackage
} // namespace dmlpackage

View File

@ -16,55 +16,47 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: dmlobject.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: dmlobject.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
/** @file */
#pragma once
#include <string>
#include"bytestream.h"
#include "bytestream.h"
namespace dmlpackage
{
/** @brief an abstract class that represents
* a database object to be inserted, updated or
* deleted by a DML statement
*/
* a database object to be inserted, updated or
* deleted by a DML statement
*/
class DMLObject
{
public:
/** @brief ctor
*/
DMLObject();
public:
/** @brief dtor
*/
virtual ~DMLObject();
/** @brief ctor
*/
DMLObject();
/** @brief read a DMLObject from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
virtual int read(messageqcpp::ByteStream& bytestream) = 0;
/** @brief dtor
*/
virtual ~DMLObject();
/** @brief read a DMLObject from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
virtual int read(messageqcpp::ByteStream& bytestream) = 0;
/** @brief write a DMLObject to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
virtual int write(messageqcpp::ByteStream& bytestream) = 0;
protected:
private:
/** @brief write a DMLObject to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
virtual int write(messageqcpp::ByteStream& bytestream) = 0;
protected:
private:
};
}
} // namespace dmlpackage

View File

@ -27,10 +27,9 @@
namespace dmlpackage
{
#define DML_DEBUG 0 // debug flag 0 for off, 1 for on
#define DML_DEBUG 0 // debug flag 0 for off, 1 for on
const std::string nullValue = "nvl";
//const size_t maxThreads = 100;
//const size_t queueSize = 200;
} // namespace dmlpackage
// const size_t maxThreads = 100;
// const size_t queueSize = 200;
} // namespace dmlpackage

View File

@ -54,118 +54,116 @@ valbuf_t get_valbuffer(void);
void free_copybuffer();
void set_defaultSchema(std::string schema);
DMLParser::DMLParser() :
fStatus(-1), fDebug(false)
{}
DMLParser::DMLParser() : fStatus(-1), fDebug(false)
{
}
DMLParser::~DMLParser()
{
scanner_finish(scanner);
dmllex_destroy(scanner);
scanner_finish(scanner);
dmllex_destroy(scanner);
}
void DMLParser::setDebug(bool debug)
{
fDebug = true;
fDebug = true;
}
int DMLParser::parse(const char* dmltext)
{
dmllex_init_extra(&scanData, &scanner);
scanner_init(dmltext, scanner);
grammar_init(&fParseTree, fDebug);
fStatus = dmlparse(scanner);
dmllex_init_extra(&scanData, &scanner);
scanner_init(dmltext, scanner);
grammar_init(&fParseTree, fDebug);
fStatus = dmlparse(scanner);
if (fStatus == 0)
if (fStatus == 0)
{
char* str;
valbuf_t valueBuffer = get_valbuffer();
for (unsigned int i = 0; i < valueBuffer.size(); i++)
{
char* str;
valbuf_t valueBuffer = get_valbuffer();
str = valueBuffer[i];
for (unsigned int i = 0; i < valueBuffer.size(); i++)
{
str = valueBuffer[i];
if (str)
{
if (i > 0)
fParseTree.fSqlText += " ";
if (str)
{
if (i > 0)
fParseTree.fSqlText += " ";
fParseTree.fSqlText += str;
}
}
fParseTree.fSqlText += str;
}
}
}
free_copybuffer();
return fStatus;
free_copybuffer();
return fStatus;
}
const ParseTree& DMLParser::getParseTree()
{
if (!good())
{
throw logic_error("The ParseTree is invalid");
}
return fParseTree;
if (!good())
{
throw logic_error("The ParseTree is invalid");
}
return fParseTree;
}
bool DMLParser::good()
{
return fStatus == 0;
return fStatus == 0;
}
void DMLParser::setDefaultSchema(std::string schema)
{
set_defaultSchema(schema);
set_defaultSchema(schema);
}
DMLFileParser::DMLFileParser()
: DMLParser()
{}
DMLFileParser::DMLFileParser() : DMLParser()
{
}
int DMLFileParser::parse(const string& fileName)
{
fStatus = -1;
fStatus = -1;
ifstream ifdml;
ifdml.open(fileName.c_str());
ifstream ifdml;
ifdml.open(fileName.c_str());
if (!ifdml.is_open())
{
perror(fileName.c_str());
return fStatus;
}
if (!ifdml.is_open())
{
perror(fileName.c_str());
return fStatus;
}
char dmlbuf[1024 * 1024];
unsigned length;
ifdml.seekg(0, ios::end);
length = ifdml.tellg();
ifdml.seekg(0, ios::beg);
char dmlbuf[1024 * 1024];
unsigned length;
ifdml.seekg(0, ios::end);
length = ifdml.tellg();
ifdml.seekg(0, ios::beg);
if (length > sizeof(dmlbuf) - 1)
{
throw length_error("DMLFileParser has file size hard limit of 16K.");
}
if (length > sizeof(dmlbuf) - 1)
{
throw length_error("DMLFileParser has file size hard limit of 16K.");
}
std::streamsize rcount;
rcount = ifdml.readsome(dmlbuf, sizeof(dmlbuf) - 1);
std::streamsize rcount;
rcount = ifdml.readsome(dmlbuf, sizeof(dmlbuf) - 1);
if (rcount < 0)
return fStatus;
if (rcount < 0)
return fStatus;
dmlbuf[rcount] = 0;
dmlbuf[rcount] = 0;
// cout << endl << fileName << "(" << rcount << ")" << endl;
//cout << "-----------------------------" << endl;
//cout << dmlbuf << endl;
// cout << endl << fileName << "(" << rcount << ")" << endl;
// cout << "-----------------------------" << endl;
// cout << dmlbuf << endl;
return DMLParser::parse(dmlbuf);
return DMLParser::parse(dmlbuf);
}
void end_sql(void)
{
} /* end_sql */
} /* end_sql */
} // dmlpackage
} // namespace dmlpackage

View File

@ -32,7 +32,6 @@ namespace dmlpackage
{
typedef std::vector<char*> valbuf_t;
typedef SqlStatementList ParseTree;
// instance data for the parser
@ -40,55 +39,54 @@ typedef std::vector<char*> valbuf_t;
struct scan_data
{
/* Handles to the buffer that the lexer uses internally */
char* scanbuf;
void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp
valbuf_t valbuf;
/* Handles to the buffer that the lexer uses internally */
char* scanbuf;
void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp
valbuf_t valbuf;
};
/** @brief BISON parser wrapper class
*/
class DMLParser
{
public:
/** @brief ctor
*/
DMLParser();
public:
/** @brief ctor
*/
DMLParser();
/** @brief dtor
*/
virtual ~DMLParser();
/** @brief dtor
*/
virtual ~DMLParser();
/** @brief parse the supplied dml statement
*
* @param dmltext the dml statement to parse
*/
int parse(const char* dmltext);
/** @brief parse the supplied dml statement
*
* @param dmltext the dml statement to parse
*/
int parse(const char* dmltext);
/** @brief get the parse tree
*/
const ParseTree& getParseTree();
/** @brief get the parse tree
*/
const ParseTree& getParseTree();
void setDefaultSchema(std::string schema);
void setDefaultSchema(std::string schema);
/** @brief was the parse successful
*/
bool good();
/** @brief was the parse successful
*/
bool good();
/** @brief put the parser in debug mode so as to dump
* diagnostic information
*/
void setDebug(bool debug);
/** @brief put the parser in debug mode so as to dump
* diagnostic information
*/
void setDebug(bool debug);
protected:
ParseTree fParseTree;
int fStatus;
bool fDebug;
void* scanner; // yyscan_t * needed for re-entrant flex scanner
scan_data scanData;
private:
protected:
ParseTree fParseTree;
int fStatus;
bool fDebug;
void* scanner; // yyscan_t * needed for re-entrant flex scanner
scan_data scanData;
private:
};
/** @brief specialization of the DMLParser class
@ -97,22 +95,21 @@ private:
*/
class DMLFileParser : public DMLParser
{
public:
/** @brief ctor
*/
DMLFileParser();
public:
/** @brief ctor
*/
DMLFileParser();
/** @brief parse the dml statement contained in the
* supplied file
*
* @param fileName the fully qualified file name to open
* and parse the contents of
*/
int parse(const std::string& fileName);
/** @brief parse the dml statement contained in the
* supplied file
*
* @param fileName the fully qualified file name to open
* and parse the contents of
*/
int parse(const std::string& fileName);
protected:
private:
protected:
private:
};
}
} // namespace dmlpackage

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: dmltable.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: dmltable.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include "dmltable.h"
using namespace std;
@ -27,93 +27,91 @@ using namespace std;
namespace dmlpackage
{
DMLTable::DMLTable()
{}
{
}
DMLTable::~DMLTable()
{
try
{
RowList::iterator it = fRows.begin();
try
while (it != fRows.end())
{
RowList::iterator it = fRows.begin();
while (it != fRows.end())
{
delete *it;
it++;
}
delete *it;
it++;
}
catch (...)
{
cout << "failed to delete the table rows" << endl;
}
}
catch (...)
{
cout << "failed to delete the table rows" << endl;
}
}
int DMLTable::read(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
int retval = 1;
// read the table name
bytestream >> fName;
// read the table name
bytestream >> fName;
// read the schema name
bytestream >> fSchema;
// read the schema name
bytestream >> fSchema;
messageqcpp::ByteStream::quadbyte rowNum;
bytestream >> rowNum;
messageqcpp::ByteStream::quadbyte rowNum;
bytestream >> rowNum;
for (unsigned int i = 0; i < rowNum; i++)
{
Row* aRow = new Row();
retval = aRow->read(bytestream);
fRows.push_back(aRow);
}
for (unsigned int i = 0; i < rowNum; i++)
{
Row* aRow = new Row();
retval = aRow->read(bytestream);
fRows.push_back(aRow);
}
return retval;
return retval;
}
void DMLTable::readMetaData(messageqcpp::ByteStream& bytestream)
{
// read the table name
bytestream >> fName;
// read the table name
bytestream >> fName;
// read the schema name
bytestream >> fSchema;
// read the schema name
bytestream >> fSchema;
}
void DMLTable::readRowData(messageqcpp::ByteStream& bytestream)
{
messageqcpp::ByteStream::quadbyte rowNum;
bytestream >> rowNum;
messageqcpp::ByteStream::quadbyte rowNum;
bytestream >> rowNum;
for (unsigned int i = 0; i < rowNum; i++)
{
Row* aRow = new Row();
aRow->read(bytestream);
fRows.push_back(aRow);
}
for (unsigned int i = 0; i < rowNum; i++)
{
Row* aRow = new Row();
aRow->read(bytestream);
fRows.push_back(aRow);
}
}
int DMLTable::write(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
//write table name and schma name to the bytestream
bytestream << fName;
bytestream << fSchema;
messageqcpp::ByteStream::quadbyte rowNum;
rowNum = fRows.size();
bytestream << rowNum;
//write the row list
RowList::iterator rowListPtr;
rowListPtr = fRows.begin();
int retval = 1;
// write table name and schma name to the bytestream
bytestream << fName;
bytestream << fSchema;
messageqcpp::ByteStream::quadbyte rowNum;
rowNum = fRows.size();
bytestream << rowNum;
// write the row list
RowList::iterator rowListPtr;
rowListPtr = fRows.begin();
for (; rowListPtr != fRows.end(); ++rowListPtr)
{
retval = (*rowListPtr)->write(bytestream);
}
for (; rowListPtr != fRows.end(); ++rowListPtr)
{
retval = (*rowListPtr)->write(bytestream);
}
return retval;
return retval;
}
} // namespace dmlpackage
} // namespace dmlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: dmltable.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: dmltable.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
/** @file */
#pragma once
@ -33,95 +33,86 @@
namespace dmlpackage
{
/** @brief concrete implementation of a DMLObject
* Specifically for representing a database table
*/
* Specifically for representing a database table
*/
class DMLTable : public DMLObject
{
public:
/** @brief ctor
*/
DMLTable();
public:
/** @brief dtor
*/
~DMLTable();
/** @brief ctor
*/
DMLTable();
/** @brief get the schema name
*/
inline const std::string get_SchemaName() const
{
return fSchema;
}
/** @brief dtor
*/
~DMLTable();
/** @brief set the schema name
*/
inline void set_SchemaName(std::string& sName)
{
fSchema = sName;
}
/** @brief get the schema name
*/
inline const std::string get_SchemaName() const
{
return fSchema;
}
/** @brief get the table name
*/
inline const std::string get_TableName() const
{
return fName;
}
/** @brief set the schema name
*/
inline void set_SchemaName( std::string& sName )
{
fSchema = sName;
}
/** @brief set the table name
*/
inline void set_TableName(std::string& tName)
{
fName = tName;
}
/** @brief get the table name
*/
inline const std::string get_TableName() const
{
return fName;
}
/** @brief get the row list
*/
inline RowList& get_RowList()
{
return fRows;
}
/** @brief set the table name
*/
inline void set_TableName( std::string& tName )
{
fName = tName;
}
/** @brief read a DMLTable from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
int read(messageqcpp::ByteStream& bytestream);
/** @brief get the row list
*/
inline RowList& get_RowList()
{
return fRows;
}
/** @brief read a DMLTable metadata from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
void readMetaData(messageqcpp::ByteStream& bytestream);
/** @brief read a DMLTable from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
int read(messageqcpp::ByteStream& bytestream);
/** @brief read a DMLTable row data from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
void readRowData(messageqcpp::ByteStream& bytestream);
/** @brief write a DMLTable to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
int write(messageqcpp::ByteStream& bytestream);
/** @brief read a DMLTable metadata from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
void readMetaData(messageqcpp::ByteStream& bytestream);
/** @brief read a DMLTable row data from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
void readRowData(messageqcpp::ByteStream& bytestream);
/** @brief write a DMLTable to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
int write(messageqcpp::ByteStream& bytestream);
protected:
private:
std::string fName;
RowList fRows;
std::string fSchema;
/*Copy and copy assignment constructor */
DMLTable(const DMLTable&);
DMLTable& operator=(const DMLTable&);
protected:
private:
std::string fName;
RowList fRows;
std::string fSchema;
/*Copy and copy assignment constructor */
DMLTable(const DMLTable&);
DMLTable& operator=(const DMLTable&);
};
} // namespace dmlpackage

View File

@ -32,52 +32,54 @@ using namespace dmlpackage;
int main(int argc, char* argv[])
{
string sqlfile;
int count;
string sqlfile;
int count;
po::options_description desc ("Allowed options");
desc.add_options ()
("help", "produce help message")
("bisond", /* po::value <string>(),*/ "Have bison produce debug output")
("count", po::value <int>(), "number of runs")
("sql", po::value < string > (), "sql file");
po::variables_map vm;
po::store (po::parse_command_line (argc, argv, desc), vm);
po::notify (vm);
po::options_description desc("Allowed options");
desc.add_options()("help", "produce help message")(
"bisond",
/* po::value <string>(),*/ "Have bison produce debug output")("count", po::value<int>(),
"number of runs")("sql",
po::value<string>(),
"sql file");
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count ("sql"))
sqlfile = vm["sql"].as <string> ();
if (vm.count("sql"))
sqlfile = vm["sql"].as<string>();
if (vm.count("count"))
count = vm["count"].as<int>();
if (vm.count("count"))
count = vm["count"].as<int>();
DMLFileParser parser;
DMLFileParser parser;
if (vm.count ("bisond"))
parser.setDebug(true);
if (vm.count("bisond"))
parser.setDebug(true);
parser.parse(sqlfile);
parser.parse(sqlfile);
if (parser.good())
{
const ParseTree& ptree = parser.getParseTree();
if (parser.good())
{
const ParseTree& ptree = parser.getParseTree();
cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl;
cout << ptree.fSqlText << endl;
cout << ptree;
cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " "
<< "SQL statements" << endl;
cout << ptree.fSqlText << endl;
cout << ptree;
SqlStatement* statementPtr = ptree[0];
SqlStatement* statementPtr = ptree[0];
if (statementPtr)
cout << statementPtr->getQueryString();
if (statementPtr)
cout << statementPtr->getQueryString();
cout << endl;
}
else
{
cout << "Parser failed." << endl;
}
cout << endl;
}
else
{
cout << "Parser failed." << endl;
}
return parser.good() ? 0 : -1;
return parser.good() ? 0 : -1;
}

View File

@ -35,273 +35,270 @@ using namespace std;
namespace dmlpackage
{
InsertDMLPackage::InsertDMLPackage()
{}
{
}
InsertDMLPackage::InsertDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID )
: CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID )
{}
InsertDMLPackage::InsertDMLPackage(std::string schemaName, std::string tableName, std::string dmlStatement,
int sessionID)
: CalpontDMLPackage(schemaName, tableName, dmlStatement, sessionID)
{
}
InsertDMLPackage::~InsertDMLPackage()
{}
{
}
int InsertDMLPackage::write(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
int retval = 1;
messageqcpp::ByteStream::byte package_type = DML_INSERT;
bytestream << package_type;
messageqcpp::ByteStream::byte package_type = DML_INSERT;
bytestream << package_type;
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id;
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id;
bytestream << fUuid;
bytestream << fUuid;
bytestream << fDMLStatement;
bytestream << fDMLStatement;
bytestream << fSchemaName;
bytestream << fTimeZone;
bytestream << (uint8_t)fLogging;
bytestream << (uint8_t)fLogending;
bytestream << fDMLStatement;
bytestream << fDMLStatement;
bytestream << fSchemaName;
bytestream << fTimeZone;
bytestream << (uint8_t)fLogging;
bytestream << (uint8_t)fLogending;
bytestream << fTableOid;
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsInsertSelect);
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsBatchInsert);
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsCacheInsert);
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsAutocommitOn);
bytestream << fTableOid;
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsInsertSelect);
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsBatchInsert);
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsCacheInsert);
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsAutocommitOn);
if (fTable != 0)
{
retval = fTable->write(bytestream);
}
if (fTable != 0)
{
retval = fTable->write(bytestream);
}
return retval;
return retval;
}
int InsertDMLPackage::read(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
int retval = 1;
messageqcpp::ByteStream::quadbyte session_id;
bytestream >> session_id;
fSessionID = session_id;
bytestream >> fUuid;
messageqcpp::ByteStream::quadbyte session_id;
bytestream >> session_id;
fSessionID = session_id;
bytestream >> fUuid;
std::string dmlStatement;
bytestream >> fDMLStatement;
bytestream >> fSQLStatement;
bytestream >> fSchemaName;
bytestream >> fTimeZone;
uint8_t logging;
bytestream >> logging;
fLogging = (logging != 0);
uint8_t logending;
bytestream >> logending;
fLogending = (logending != 0);
std::string dmlStatement;
bytestream >> fDMLStatement;
bytestream >> fSQLStatement;
bytestream >> fSchemaName;
bytestream >> fTimeZone;
uint8_t logging;
bytestream >> logging;
fLogging = (logging != 0);
uint8_t logending;
bytestream >> logending;
fLogending = (logending != 0);
bytestream >> fTableOid;
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsInsertSelect);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsBatchInsert);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsCacheInsert);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsAutocommitOn);
bytestream >> fTableOid;
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsInsertSelect);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsBatchInsert);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsCacheInsert);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsAutocommitOn);
fTable = new DMLTable();
retval = fTable->read(bytestream);
return retval;
fTable = new DMLTable();
retval = fTable->read(bytestream);
return retval;
}
void InsertDMLPackage::readMetaData(messageqcpp::ByteStream& bytestream)
{
messageqcpp::ByteStream::quadbyte session_id;
bytestream >> session_id;
fSessionID = session_id;
bytestream >> fUuid;
messageqcpp::ByteStream::quadbyte session_id;
bytestream >> session_id;
fSessionID = session_id;
bytestream >> fUuid;
std::string dmlStatement;
bytestream >> fDMLStatement;
bytestream >> fSQLStatement;
bytestream >> fSchemaName;
bytestream >> fTimeZone;
uint8_t logging;
bytestream >> logging;
fLogging = (logging != 0);
uint8_t logending;
bytestream >> logending;
fLogending = (logending != 0);
std::string dmlStatement;
bytestream >> fDMLStatement;
bytestream >> fSQLStatement;
bytestream >> fSchemaName;
bytestream >> fTimeZone;
uint8_t logging;
bytestream >> logging;
fLogging = (logging != 0);
uint8_t logending;
bytestream >> logending;
fLogending = (logending != 0);
bytestream >> fTableOid;
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsInsertSelect);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsBatchInsert);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsCacheInsert);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsAutocommitOn);
bytestream >> fTableOid;
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsInsertSelect);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsBatchInsert);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsCacheInsert);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsAutocommitOn);
fTable = new DMLTable();
fTable->readMetaData(bytestream);
fTable = new DMLTable();
fTable->readMetaData(bytestream);
}
// Has to be called after InsertDMLPackage::readMetaData()
void InsertDMLPackage::readRowData(messageqcpp::ByteStream& bytestream)
{
fTable->readRowData(bytestream);
fTable->readRowData(bytestream);
}
int InsertDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows)
{
#ifdef DML_PACKAGE_DEBUG
// cout << "The data buffer received: " << buffer << endl;
// cout << "The data buffer received: " << buffer << endl;
#endif
int retval = 1;
int retval = 1;
initializeTable();
initializeTable();
std::vector<std::string> dataList;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(",");
tokenizer tokens(buffer, sep);
std::vector<std::string> dataList;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(",");
tokenizer tokens(buffer, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{
dataList.push_back(StripLeadingWhitespace(*tok_iter));
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{
dataList.push_back(StripLeadingWhitespace(*tok_iter));
}
}
int n = 0;
int n = 0;
for (int i = 0; i < rows; i++)
{
//get a new row
Row* aRowPtr = new Row();
std::string colName;
std::string colValue;
for (int j = 0; j < columns; j++)
{
//Build a column list
colName = dataList[n];
n++;
colValue = dataList[n];
n++;
#ifdef DML_PACKAGE_DEBUG
//cout << "The column data: " << colName << " " << colValue << endl;
#endif
DMLColumn* aColumn = new DMLColumn(colName, colValue, false);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
fTable->get_RowList().push_back(aRowPtr);
}
return retval;
}
int InsertDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues )
{
int retval = 1;
initializeTable();
for (int i = 0; i < rows; i++)
{
// get a new row
Row* aRowPtr = new Row();
std::string colName;
std::vector<std::string> colValList;
std::string colValue;
for (int j = 0; j < columns; j++)
{
//Build a column list
colName = colNameList[j];
colValList = tableValuesMap[j];
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
(aRowPtr->get_ColumnList()).push_back(aColumn);
// Build a column list
colName = dataList[n];
n++;
colValue = dataList[n];
n++;
#ifdef DML_PACKAGE_DEBUG
// cout << "The column data: " << colName << " " << colValue << endl;
#endif
DMLColumn* aColumn = new DMLColumn(colName, colValue, false);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
// build a row list for a table
fTable->get_RowList().push_back(aRowPtr);
aRowPtr = NULL;
delete aRowPtr;
return retval;
}
return retval;
}
int InsertDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap,
int columns, int rows, NullValuesBitset& nullValues)
{
int retval = 1;
initializeTable();
Row* aRowPtr = new Row();
std::string colName;
std::vector<std::string> colValList;
for (int j = 0; j < columns; j++)
{
// Build a column list
colName = colNameList[j];
colValList = tableValuesMap[j];
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
// build a row list for a table
fTable->get_RowList().push_back(aRowPtr);
aRowPtr = NULL;
delete aRowPtr;
return retval;
}
int InsertDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
{
int retval = 1;
int retval = 1;
InsertSqlStatement& insertStmt = dynamic_cast<InsertSqlStatement&>(sqlStatement);
InsertSqlStatement& insertStmt = dynamic_cast<InsertSqlStatement&>(sqlStatement);
if (!insertStmt.fValuesOrQueryPtr)
throw runtime_error("insertStmt.fValuesOrQueryPtr == NULL");
if (!insertStmt.fValuesOrQueryPtr)
throw runtime_error("insertStmt.fValuesOrQueryPtr == NULL");
initializeTable();
bool isNULL = false;
initializeTable();
bool isNULL = false;
// only if we don't have a select statement
if (0 == insertStmt.fValuesOrQueryPtr->fQuerySpecPtr)
{
ColumnNameList columnNameList = insertStmt.fColumnList;
// only if we don't have a select statement
if (0 == insertStmt.fValuesOrQueryPtr->fQuerySpecPtr)
if (columnNameList.size())
{
ValuesList valuesList = insertStmt.fValuesOrQueryPtr->fValuesList;
ColumnNameList columnNameList = insertStmt.fColumnList;
if (columnNameList.size() != valuesList.size())
{
throw logic_error("Column names and values count mismatch!");
}
if (columnNameList.size())
{
Row* aRow = new Row();
ValuesList valuesList = insertStmt.fValuesOrQueryPtr->fValuesList;
if (columnNameList.size() != valuesList.size())
{
throw logic_error("Column names and values count mismatch!");
}
Row* aRow = new Row();
for (unsigned int i = 0; i < columnNameList.size(); i++)
{
DMLColumn* aColumn = new DMLColumn(columnNameList[i], valuesList[i], isNULL);
(aRow->get_ColumnList()).push_back(aColumn);
}
fTable->get_RowList().push_back(aRow);
}
else
{
ValuesList valuesList = insertStmt.fValuesOrQueryPtr->fValuesList;
ValuesList::const_iterator iter = valuesList.begin();
Row* aRow = new Row();
std::string colName = "";
std::string colValue;
while (iter != valuesList.end())
{
colValue = *iter;
if ( strcasecmp(colValue.c_str(), "NULL") == 0)
{
isNULL = true;
}
else
{
isNULL = false;
}
DMLColumn* aColumn = new DMLColumn(colName, colValue, isNULL);
(aRow->get_ColumnList()).push_back(aColumn);
++iter;
}
fTable->get_RowList().push_back(aRow);
}
for (unsigned int i = 0; i < columnNameList.size(); i++)
{
DMLColumn* aColumn = new DMLColumn(columnNameList[i], valuesList[i], isNULL);
(aRow->get_ColumnList()).push_back(aColumn);
}
fTable->get_RowList().push_back(aRow);
}
else
{
fHasFilter = true;
fQueryString = insertStmt.getQueryString();
}
ValuesList valuesList = insertStmt.fValuesOrQueryPtr->fValuesList;
ValuesList::const_iterator iter = valuesList.begin();
Row* aRow = new Row();
std::string colName = "";
std::string colValue;
return retval;
while (iter != valuesList.end())
{
colValue = *iter;
if (strcasecmp(colValue.c_str(), "NULL") == 0)
{
isNULL = true;
}
else
{
isNULL = false;
}
DMLColumn* aColumn = new DMLColumn(colName, colValue, isNULL);
(aRow->get_ColumnList()).push_back(aColumn);
++iter;
}
fTable->get_RowList().push_back(aRow);
}
}
else
{
fHasFilter = true;
fQueryString = insertStmt.getQueryString();
}
return retval;
}
} // namespace dmlpackage

View File

@ -36,88 +36,85 @@
namespace dmlpackage
{
/** @brief concrete implementation of a CalpontDMLPackage
* Specifically for representing INSERT DML Statements
*/
* Specifically for representing INSERT DML Statements
*/
class InsertDMLPackage : public CalpontDMLPackage
{
public:
/** @brief ctor
*/
EXPORT InsertDMLPackage();
public:
/** @brief ctor
*/
EXPORT InsertDMLPackage();
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the table name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session id
*/
EXPORT InsertDMLPackage(std::string schemaName, std::string tableName, std::string dmlStatement,
int sessionID);
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the table name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session id
*/
EXPORT InsertDMLPackage(std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID );
/** @brief dtor
*/
EXPORT virtual ~InsertDMLPackage();
/** @brief dtor
*/
EXPORT virtual ~InsertDMLPackage();
/** @brief write a InsertDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief write a InsertDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief read InsertDMLPackage from bytestream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief read InsertDMLPackage from bytestream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief read InsertDMLPackage metadata from bytestream
*
* @param bytestream the ByteStream to read from
*/
EXPORT void readMetaData(messageqcpp::ByteStream& bytestream);
/** @brief read InsertDMLPackage metadata from bytestream
*
* @param bytestream the ByteStream to read from
*/
EXPORT void readMetaData(messageqcpp::ByteStream& bytestream);
/** @brief read InsertDMLPackage row data from bytestream
*
* @param bytestream the ByteStream to read from
*/
EXPORT void readRowData(messageqcpp::ByteStream& bytestream);
/** @brief read InsertDMLPackage row data from bytestream
*
* @param bytestream the ByteStream to read from
*/
EXPORT void readRowData(messageqcpp::ByteStream& bytestream);
/** @brief build a InsertDMLPackage from a string buffer
*
* @param buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromBuffer(std::string& buffer, int columns, int rows);
/** @brief build a InsertDMLPackage from a string buffer
*
* @param buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromBuffer(std::string& buffer, int columns, int rows);
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param tableValuesMap the value list for each column in the table
* @param colNameList the column name for each column
* @param columns number of columns in the table
* @param rows number of rows to be touched
*/
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns,
int rows, NullValuesBitset& nullValues);
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param tableValuesMap the value list for each column in the table
* @param colNameList the column name for each column
* @param columns number of columns in the table
* @param rows number of rows to be touched
*/
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues);
/** @brief build a InsertDMLPackage from a InsertSqlStatement
*
* @param sqlStmt the InsertSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a InsertDMLPackage from a InsertSqlStatement
*
* @param sqlStmt the InsertSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief Dump the InsertDMLPackage for debugging purposes
*/
EXPORT void Dump();
protected:
private:
/** @brief Dump the InsertDMLPackage for debugging purposes
*/
EXPORT void Dump();
protected:
private:
};
}
} // namespace dmlpackage
#undef EXPORT

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: mysqldmlstatement.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: mysqldmlstatement.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include "mysqldmlstatement.h"
/**
@ -28,4 +28,3 @@
/**
* Methods
*/

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: mysqldmlstatement.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: mysqldmlstatement.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
/** @file */
#pragma once
#include <string>
@ -32,14 +32,12 @@ namespace dmlpackage
*/
class MySQLDMLStatement : public VendorDMLStatement
{
public:
MySQLDMLStatement() : VendorDMLStatement("", 0)
{
}
public:
MySQLDMLStatement() : VendorDMLStatement("", 0) {}
protected:
private:
protected:
private:
};
}
} // namespace dmlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: oracledmlstatement.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: oracledmlstatement.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include "oracledmlstatement.h"
/**
@ -28,5 +28,3 @@
/**
* Methods
*/

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: oracledmlstatement.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: oracledmlstatement.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
/** @file */
#pragma once
@ -33,14 +33,12 @@ namespace dmlpackage
*/
class OracleDMLStatement : public VendorDMLStatement
{
public:
OracleDMLStatement() : VendorDMLStatement("", 0)
{
}
public:
OracleDMLStatement() : VendorDMLStatement("", 0) {}
protected:
private:
protected:
private:
};
}
} // namespace dmlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: row.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: row.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include <limits>
#define DMLPKGROW_DLLEXPORT
@ -28,83 +28,78 @@
namespace dmlpackage
{
Row::Row()
: fRowID(std::numeric_limits<WriteEngine::RID>::max())
{}
Row::Row() : fRowID(std::numeric_limits<WriteEngine::RID>::max())
{
}
Row::~Row()
{
for ( unsigned int i = 0; i < fColumnList.size(); i++)
{
delete fColumnList[i];
}
for (unsigned int i = 0; i < fColumnList.size(); i++)
{
delete fColumnList[i];
}
fColumnList.clear();
fColumnList.clear();
}
Row::Row(const Row& row)
{
for (unsigned int i = 0; i < row.fColumnList.size(); i++)
{
const DMLColumn* aColumn = row.get_ColumnAt(i);
DMLColumn* newColumn = new DMLColumn(aColumn->get_Name(), aColumn->get_Data());
fColumnList.push_back(newColumn);
}
for (unsigned int i = 0; i < row.fColumnList.size(); i++)
{
const DMLColumn* aColumn = row.get_ColumnAt(i);
DMLColumn* newColumn = new DMLColumn(aColumn->get_Name(), aColumn->get_Data());
fColumnList.push_back(newColumn);
}
fRowID = row.fRowID;
fRowID = row.fRowID;
}
int Row::read(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
messageqcpp::ByteStream::octbyte rowID;
bytestream >> rowID;
set_RowID(rowID);
messageqcpp::ByteStream::quadbyte col_count;
bytestream >> col_count;
int retval = 1;
messageqcpp::ByteStream::octbyte rowID;
bytestream >> rowID;
set_RowID(rowID);
messageqcpp::ByteStream::quadbyte col_count;
bytestream >> col_count;
for (unsigned int i = 0; i < col_count; i++)
{
DMLColumn* aColumn = new DMLColumn();
retval = aColumn->read(bytestream);
fColumnList.push_back(aColumn);
}
for (unsigned int i = 0; i < col_count; i++)
{
DMLColumn* aColumn = new DMLColumn();
retval = aColumn->read(bytestream);
fColumnList.push_back(aColumn);
}
return retval;
return retval;
}
int Row::write(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
messageqcpp::ByteStream::octbyte rowID = fRowID;
bytestream << rowID;
ColumnList::iterator colListPtr;
colListPtr = fColumnList.begin();
messageqcpp::ByteStream::quadbyte col_count = fColumnList.size();
bytestream << col_count;
int retval = 1;
messageqcpp::ByteStream::octbyte rowID = fRowID;
bytestream << rowID;
ColumnList::iterator colListPtr;
colListPtr = fColumnList.begin();
messageqcpp::ByteStream::quadbyte col_count = fColumnList.size();
bytestream << col_count;
for (; colListPtr != fColumnList.end(); ++colListPtr)
{
retval = (*colListPtr)->write(bytestream);
}
for (; colListPtr != fColumnList.end(); ++colListPtr)
{
retval = (*colListPtr)->write(bytestream);
}
return retval;
return retval;
}
const DMLColumn* Row::get_ColumnAt( unsigned int index ) const
const DMLColumn* Row::get_ColumnAt(unsigned int index) const
{
const DMLColumn* columnPtr = 0;
const DMLColumn* columnPtr = 0;
if ( index < fColumnList.size() )
{
columnPtr = fColumnList[index];
}
if (index < fColumnList.size())
{
columnPtr = fColumnList[index];
}
return columnPtr;
return columnPtr;
}
} // namespace dmlpackage
} // namespace dmlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/***********************************************************************
* $Id: row.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
* $Id: row.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
/** @file */
#pragma once
@ -38,84 +38,79 @@
namespace dmlpackage
{
/** @brief concrete implementation of a DMLObject
* Specifically for representing a table row
*/
* Specifically for representing a table row
*/
class Row : public DMLObject
{
public:
public:
/** @brief ctor
*/
EXPORT Row();
/** @brief ctor
*/
EXPORT Row();
/** @brief dtor
*/
EXPORT ~Row();
/** @brief dtor
*/
EXPORT ~Row();
/** @brief copy constructor
*/
EXPORT Row(const Row&);
/** @brief copy constructor
*/
EXPORT Row(const Row&);
/** @brief read a Row from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief read a Row from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief write a Row to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief write a Row to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief get the list of columns in the row
*/
inline ColumnList& get_ColumnList()
{
return fColumnList;
}
/** @brief get the list of columns in the row
*/
inline ColumnList& get_ColumnList()
{
return fColumnList;
}
/** @brief get the row id
*/
inline WriteEngine::RID get_RowID() const
{
return fRowID;
}
/** @brief get the row id
*/
inline WriteEngine::RID get_RowID() const
{
return fRowID;
}
/** @brief set the row id
*/
inline void set_RowID(WriteEngine::RID rowId)
{
fRowID = rowId;
}
/** @brief set the row id
*/
inline void set_RowID(WriteEngine::RID rowId)
{
fRowID = rowId;
}
/** @brief get the number of columns
*/
inline unsigned int get_NumberOfColumns() const
{
return static_cast<unsigned int>(fColumnList.size());
}
/** @brief get the number of columns
*/
inline unsigned int get_NumberOfColumns() const
{
return static_cast<unsigned int>(fColumnList.size());
}
/** @brief get the column at the specified index
*
* @param index the index of the column to get
*/
EXPORT const DMLColumn* get_ColumnAt( unsigned int index ) const;
protected:
private:
WriteEngine::RID fRowID;
ColumnList fColumnList;
Row& operator=(const Row&);
/** @brief get the column at the specified index
*
* @param index the index of the column to get
*/
EXPORT const DMLColumn* get_ColumnAt(unsigned int index) const;
protected:
private:
WriteEngine::RID fRowID;
ColumnList fColumnList;
Row& operator=(const Row&);
};
/** @brief a vector of Rows
*/
typedef std::vector<Row*>RowList;
}
*/
typedef std::vector<Row*> RowList;
} // namespace dmlpackage
#undef EXPORT

View File

@ -43,351 +43,345 @@ using namespace messageqcpp;
bool parse_file(char* fileName)
{
DMLFileParser parser;
parser.parse(fileName);
bool good = parser.good();
DMLFileParser parser;
parser.parse(fileName);
bool good = parser.good();
if (good)
{
const ParseTree& ptree = parser.getParseTree();
if (good)
{
const ParseTree& ptree = parser.getParseTree();
cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl;
cout << ptree.fSqlText << endl;
cout << ptree;
cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " "
<< "SQL statements" << endl;
cout << ptree.fSqlText << endl;
cout << ptree;
SqlStatement* statementPtr = ptree[0];
SqlStatement* statementPtr = ptree[0];
if (statementPtr)
cout << statementPtr->getQueryString();
if (statementPtr)
cout << statementPtr->getQueryString();
cout << endl;
}
cout << endl;
}
return good;
return good;
}
class DMLParserTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( DMLParserTest );
CPPUNIT_TEST( test_i01 );
CPPUNIT_TEST( test_i02 );
CPPUNIT_TEST( test_i03 );
CPPUNIT_TEST( test_i04 );
CPPUNIT_TEST( test_u01 );
CPPUNIT_TEST( test_u02 );
CPPUNIT_TEST( test_d01 );
CPPUNIT_TEST( test_d02 );
CPPUNIT_TEST( test_d03 );
CPPUNIT_TEST( test_d04 );
CPPUNIT_TEST_SUITE_END();
CPPUNIT_TEST_SUITE(DMLParserTest);
CPPUNIT_TEST(test_i01);
CPPUNIT_TEST(test_i02);
CPPUNIT_TEST(test_i03);
CPPUNIT_TEST(test_i04);
CPPUNIT_TEST(test_u01);
CPPUNIT_TEST(test_u02);
CPPUNIT_TEST(test_d01);
CPPUNIT_TEST(test_d02);
CPPUNIT_TEST(test_d03);
CPPUNIT_TEST(test_d04);
CPPUNIT_TEST_SUITE_END();
private:
private:
public:
void setUp()
{
}
public:
void setUp() {}
void tearDown()
{
}
void tearDown() {}
void test_i01()
{
CPPUNIT_ASSERT(parse_file("sql/i01.sql"));
}
void test_i01()
{
CPPUNIT_ASSERT(parse_file("sql/i01.sql"));
}
void test_i02()
{
CPPUNIT_ASSERT(parse_file("sql/i02.sql"));
}
void test_i02()
{
CPPUNIT_ASSERT(parse_file("sql/i02.sql"));
}
void test_i03()
{
CPPUNIT_ASSERT(parse_file("sql/i03.sql"));
}
void test_i03()
{
CPPUNIT_ASSERT(parse_file("sql/i03.sql"));
}
void test_i04()
{
CPPUNIT_ASSERT(parse_file("sql/i04.sql"));
}
void test_i04()
{
CPPUNIT_ASSERT(parse_file("sql/i04.sql"));
}
void test_u01()
{
CPPUNIT_ASSERT(parse_file("sql/u01.sql"));
}
void test_u01()
{
CPPUNIT_ASSERT(parse_file("sql/u01.sql"));
}
void test_u02()
{
CPPUNIT_ASSERT(parse_file("sql/u02.sql"));
}
void test_u02()
{
CPPUNIT_ASSERT(parse_file("sql/u02.sql"));
}
void test_d01()
{
CPPUNIT_ASSERT(parse_file("sql/d01.sql"));
}
void test_d01()
{
CPPUNIT_ASSERT(parse_file("sql/d01.sql"));
}
void test_d02()
{
CPPUNIT_ASSERT(parse_file("sql/d02.sql"));
}
void test_d02()
{
CPPUNIT_ASSERT(parse_file("sql/d02.sql"));
}
void test_d03()
{
CPPUNIT_ASSERT(parse_file("sql/d03.sql"));
}
void test_d03()
{
CPPUNIT_ASSERT(parse_file("sql/d03.sql"));
}
void test_d04()
{
CPPUNIT_ASSERT(parse_file("sql/d04.sql"));
}
void test_d04()
{
CPPUNIT_ASSERT(parse_file("sql/d04.sql"));
}
};
class DMLTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(DMLTest);
// CPPUNIT_TEST( test_direct_insert );
// CPPUNIT_TEST( test_query_insert );
CPPUNIT_TEST(test_direct_update);
// CPPUNIT_TEST( test_query_update );
// CPPUNIT_TEST( test_delete_all );
// CPPUNIT_TEST( test_delete_query );
// CPPUNIT_TEST( test_commit );
// CPPUNIT_TEST( test_rollback );
CPPUNIT_TEST_SUITE_END();
CPPUNIT_TEST_SUITE( DMLTest );
// CPPUNIT_TEST( test_direct_insert );
// CPPUNIT_TEST( test_query_insert );
CPPUNIT_TEST( test_direct_update );
// CPPUNIT_TEST( test_query_update );
// CPPUNIT_TEST( test_delete_all );
// CPPUNIT_TEST( test_delete_query );
// CPPUNIT_TEST( test_commit );
// CPPUNIT_TEST( test_rollback );
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp()
{
}
private:
public:
void setUp() {}
void tearDown()
{
}
void tearDown() {}
void test_direct_insert()
{
ByteStream bytestream;
std::string dmlStatement = "INSERT INTO tpch.supplier (supplier_id, supplier_name) VALUES(24553, 'IBM');";
cout << dmlStatement << endl;
void test_direct_insert()
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT(0 != pDMLPackage);
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_insert_object(bytestream);
}
void test_query_insert()
{
ByteStream bytestream;
std::string dmlStatement =
"INSERT INTO supplier (supplier_id, supplier_name) SELECT account_no, name FROM customers WHERE city "
"= 'Newark';";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT(0 != pDMLPackage);
if (pDMLPackage->HasFilter())
{
ByteStream bytestream;
std::string dmlStatement = "INSERT INTO tpch.supplier (supplier_id, supplier_name) VALUES(24553, 'IBM');";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_insert_object(bytestream);
cout << "This INSERT statement has a filter:" << endl;
cout << pDMLPackage->get_QueryString() << endl;
}
void test_query_insert()
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_insert_object(bytestream);
}
void write_DML_object(ByteStream& bs, CalpontDMLPackage* pDMLPackage)
{
pDMLPackage->write(bs);
}
void read_insert_object(ByteStream& bs)
{
ByteStream::byte package_type;
bs >> package_type;
CPPUNIT_ASSERT(DML_INSERT == package_type);
InsertDMLPackage* pObject = new InsertDMLPackage();
pObject->read(bs);
delete pObject;
}
void test_delete_all()
{
ByteStream bytestream;
std::string dmlStatement = "DELETE FROM tpch.part;";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT(0 != pDMLPackage);
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_delete_object(bytestream);
}
void test_delete_query()
{
ByteStream bytestream;
std::string dmlStatement = "DELETE FROM tpch.supplier WHERE supplier_name = 'IBM';";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT(0 != pDMLPackage);
if (pDMLPackage->HasFilter())
{
ByteStream bytestream;
std::string dmlStatement = "INSERT INTO supplier (supplier_id, supplier_name) SELECT account_no, name FROM customers WHERE city = 'Newark';";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
if ( pDMLPackage->HasFilter() )
{
cout << "This INSERT statement has a filter:" << endl;
cout << pDMLPackage->get_QueryString() << endl;
}
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_insert_object(bytestream);
cout << "This DELETE statement has a filter:" << endl;
cout << pDMLPackage->get_QueryString() << endl;
}
void write_DML_object( ByteStream& bs, CalpontDMLPackage* pDMLPackage )
{
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_delete_object(bytestream);
}
pDMLPackage->write( bs );
void read_delete_object(ByteStream& bs)
{
ByteStream::byte package_type;
bs >> package_type;
CPPUNIT_ASSERT(DML_DELETE == package_type);
DeleteDMLPackage* pObject = new DeleteDMLPackage();
pObject->read(bs);
delete pObject;
}
void test_direct_update()
{
ByteStream bytestream;
std::string dmlStatement = "UPDATE tpch.part SET p_partno = 1, p_name = 'joe' where p_partno=2;";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT(0 != pDMLPackage);
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_update_object(bytestream);
}
void test_query_update()
{
ByteStream bytestream;
std::string dmlStatement =
"UPDATE tpch.supplier SET supplier_name='joe',supplier_state='ca' WHERE EXISTS ( SELECT "
"customer.name FROM customers WHERE customers.customer_id = supplier.supplier_id);";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT(0 != pDMLPackage);
if (pDMLPackage->HasFilter())
{
cout << "This UPDATE statement has a filter:" << endl;
cout << pDMLPackage->get_QueryString() << endl;
}
void read_insert_object( ByteStream& bs )
{
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_update_object(bytestream);
}
ByteStream::byte package_type;
bs >> package_type;
void read_update_object(ByteStream& bs)
{
ByteStream::byte package_type;
bs >> package_type;
CPPUNIT_ASSERT( DML_INSERT == package_type );
CPPUNIT_ASSERT(DML_UPDATE == package_type);
InsertDMLPackage* pObject = new InsertDMLPackage();
UpdateDMLPackage* pObject = new UpdateDMLPackage();
pObject->read( bs );
pObject->read(bs);
delete pObject;
delete pObject;
}
}
void test_commit()
{
ByteStream bytestream;
std::string dmlStatement = "COMMIT;";
cout << dmlStatement << endl;
void test_delete_all()
{
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT(0 != pDMLPackage);
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_command_object(bytestream);
}
ByteStream bytestream;
std::string dmlStatement = "DELETE FROM tpch.part;";
void test_rollback()
{
ByteStream bytestream;
std::string dmlStatement = "ROLLBACK;";
cout << dmlStatement << endl;
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT(0 != pDMLPackage);
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_command_object(bytestream);
}
VendorDMLStatement dmlStmt(dmlStatement, 1);
void read_command_object(ByteStream& bs)
{
ByteStream::byte package_type;
bs >> package_type;
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_delete_object(bytestream);
}
CPPUNIT_ASSERT(DML_COMMAND == package_type);
void test_delete_query()
{
ByteStream bytestream;
std::string dmlStatement = "DELETE FROM tpch.supplier WHERE supplier_name = 'IBM';";
CommandDMLPackage* pObject = new CommandDMLPackage();
cout << dmlStatement << endl;
pObject->read(bs);
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
if (pDMLPackage->HasFilter())
{
cout << "This DELETE statement has a filter:" << endl;
cout << pDMLPackage->get_QueryString() << endl;
}
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_delete_object(bytestream);
}
void read_delete_object( ByteStream& bs )
{
ByteStream::byte package_type;
bs >> package_type;
CPPUNIT_ASSERT( DML_DELETE == package_type );
DeleteDMLPackage* pObject = new DeleteDMLPackage();
pObject->read( bs );
delete pObject;
}
void test_direct_update()
{
ByteStream bytestream;
std::string dmlStatement = "UPDATE tpch.part SET p_partno = 1, p_name = 'joe' where p_partno=2;";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_update_object(bytestream);
}
void test_query_update()
{
ByteStream bytestream;
std::string dmlStatement = "UPDATE tpch.supplier SET supplier_name='joe',supplier_state='ca' WHERE EXISTS ( SELECT customer.name FROM customers WHERE customers.customer_id = supplier.supplier_id);";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
if (pDMLPackage->HasFilter())
{
cout << "This UPDATE statement has a filter:" << endl;
cout << pDMLPackage->get_QueryString() << endl;
}
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_update_object(bytestream);
}
void read_update_object( ByteStream& bs )
{
ByteStream::byte package_type;
bs >> package_type;
CPPUNIT_ASSERT( DML_UPDATE == package_type );
UpdateDMLPackage* pObject = new UpdateDMLPackage();
pObject->read( bs );
delete pObject;
}
void test_commit()
{
ByteStream bytestream;
std::string dmlStatement = "COMMIT;";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_command_object(bytestream);
}
void test_rollback()
{
ByteStream bytestream;
std::string dmlStatement = "ROLLBACK;";
cout << dmlStatement << endl;
VendorDMLStatement dmlStmt(dmlStatement, 1);
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackage(dmlStmt);
CPPUNIT_ASSERT( 0 != pDMLPackage );
write_DML_object(bytestream, pDMLPackage);
delete pDMLPackage;
read_command_object(bytestream);
}
void read_command_object( ByteStream& bs )
{
ByteStream::byte package_type;
bs >> package_type;
CPPUNIT_ASSERT( DML_COMMAND == package_type );
CommandDMLPackage* pObject = new CommandDMLPackage();
pObject->read( bs );
delete pObject;
}
delete pObject;
}
};
//CPPUNIT_TEST_SUITE_REGISTRATION( DMLParserTest );
CPPUNIT_TEST_SUITE_REGISTRATION( DMLTest );
// CPPUNIT_TEST_SUITE_REGISTRATION( DMLParserTest );
CPPUNIT_TEST_SUITE_REGISTRATION(DMLTest);
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
int main( int argc, char** argv)
int main(int argc, char** argv)
{
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false );
return (wasSuccessful ? 0 : 1);
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest(registry.makeTest());
bool wasSuccessful = runner.run("", false);
return (wasSuccessful ? 0 : 1);
}

View File

@ -32,129 +32,130 @@ using namespace std;
namespace dmlpackage
{
UpdateDMLPackage::UpdateDMLPackage()
{}
{
}
UpdateDMLPackage::UpdateDMLPackage(std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID)
: CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID)
{}
UpdateDMLPackage::UpdateDMLPackage(std::string schemaName, std::string tableName, std::string dmlStatement,
int sessionID)
: CalpontDMLPackage(schemaName, tableName, dmlStatement, sessionID)
{
}
UpdateDMLPackage::~UpdateDMLPackage()
{}
{
}
int UpdateDMLPackage::write(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
messageqcpp::ByteStream::byte package_type = DML_UPDATE;
bytestream << package_type;
int retval = 1;
messageqcpp::ByteStream::byte package_type = DML_UPDATE;
bytestream << package_type;
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id;
/*
if(fPlan != 0)
fHasFilter = true;
else
fHasFilter = false;
*/
messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter;
bytestream << hasFilter;
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id;
/*
if(fPlan != 0)
fHasFilter = true;
else
fHasFilter = false;
*/
messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter;
bytestream << hasFilter;
bytestream << fUuid;
bytestream << fUuid;
bytestream << fDMLStatement;
bytestream << fSQLStatement;
bytestream << fSchemaName;
bytestream << fTimeZone;
bytestream << (uint8_t)fIsFromCol;
bytestream << fDMLStatement;
bytestream << fSQLStatement;
bytestream << fSchemaName;
bytestream << fTimeZone;
bytestream << (uint8_t)fIsFromCol;
if (fTable != 0)
{
retval = fTable->write(bytestream);
}
if (fTable != 0)
{
retval = fTable->write(bytestream);
}
if (fHasFilter)
{
bytestream += *(fPlan.get());
}
if (fHasFilter)
{
bytestream += *(fPlan.get());
}
return retval;
return retval;
}
/**
*
*/
int UpdateDMLPackage::read(messageqcpp::ByteStream& bytestream)
{
int retval = 1;
int retval = 1;
messageqcpp::ByteStream::quadbyte session_id;
messageqcpp::ByteStream::quadbyte hasFilter;
messageqcpp::ByteStream::quadbyte session_id;
messageqcpp::ByteStream::quadbyte hasFilter;
bytestream >> session_id;
fSessionID = session_id;
bytestream >> session_id;
fSessionID = session_id;
bytestream >> hasFilter;
fHasFilter = (hasFilter != 0);
bytestream >> hasFilter;
fHasFilter = (hasFilter != 0);
bytestream >> fUuid;
bytestream >> fUuid;
std::string dmlStatement;
bytestream >> fDMLStatement;
bytestream >> fSQLStatement;
bytestream >> fSchemaName;
bytestream >> fTimeZone;
uint8_t isFromCol;
bytestream >> isFromCol;
fIsFromCol = (isFromCol != 0);
fTable = new DMLTable();
retval = fTable->read(bytestream);
std::string dmlStatement;
bytestream >> fDMLStatement;
bytestream >> fSQLStatement;
bytestream >> fSchemaName;
bytestream >> fTimeZone;
uint8_t isFromCol;
bytestream >> isFromCol;
fIsFromCol = (isFromCol != 0);
fTable = new DMLTable();
retval = fTable->read(bytestream);
if (fHasFilter)
{
fPlan.reset(new messageqcpp::ByteStream(bytestream));
}
if (fHasFilter)
{
fPlan.reset(new messageqcpp::ByteStream(bytestream));
}
return retval;
return retval;
}
int UpdateDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
{
int retval = 1;
int retval = 1;
UpdateSqlStatement& updateStmt = dynamic_cast<UpdateSqlStatement&>(sqlStatement);
UpdateSqlStatement& updateStmt = dynamic_cast<UpdateSqlStatement&>(sqlStatement);
if (!updateStmt.fColAssignmentListPtr)
throw runtime_error("updateStmt.fColAssignmentPtr == NULL");
if (!updateStmt.fColAssignmentListPtr)
throw runtime_error("updateStmt.fColAssignmentPtr == NULL");
initializeTable();
initializeTable();
// Since there is no filter, all rows are updated
// Since there is no filter, all rows are updated
// Push one row always and let the filter happen on the proc side.
Row* rowPtr = new Row();
ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin();
// Push one row always and let the filter happen on the proc side.
Row* rowPtr = new Row();
ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin();
while (iter != updateStmt.fColAssignmentListPtr->end())
{
ColumnAssignment* colaPtr = *iter;
DMLColumn* colPtr = new DMLColumn(colaPtr->fColumn, colaPtr->fScalarExpression);
rowPtr->get_ColumnList().push_back(colPtr);
while (iter != updateStmt.fColAssignmentListPtr->end())
{
ColumnAssignment* colaPtr = *iter;
DMLColumn* colPtr = new DMLColumn(colaPtr->fColumn, colaPtr->fScalarExpression);
rowPtr->get_ColumnList().push_back(colPtr);
++iter;
}
++iter;
}
fTable->get_RowList().push_back(rowPtr);
fTable->get_RowList().push_back(rowPtr);
if (0 != updateStmt.fWhereClausePtr)
{
// We need to filter the rows...get row ids
fHasFilter = true;
fQueryString = updateStmt.getQueryString();
}
if (0 != updateStmt.fWhereClausePtr)
{
// We need to filter the rows...get row ids
fHasFilter = true;
fQueryString = updateStmt.getQueryString();
}
return retval;
return retval;
}
/**
@ -163,109 +164,108 @@ int UpdateDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
int UpdateDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows)
{
#ifdef DML_PACKAGE_DEBUG
//cout << "The data buffer received: " << buffer << endl;
// cout << "The data buffer received: " << buffer << endl;
#endif
int retval = 1;
int retval = 1;
initializeTable();
initializeTable();
std::vector<std::string> dataList;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(":,");
tokenizer tokens(buffer, sep);
std::vector<std::string> dataList;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(":,");
tokenizer tokens(buffer, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{
dataList.push_back(StripLeadingWhitespace(*tok_iter));
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{
dataList.push_back(StripLeadingWhitespace(*tok_iter));
}
}
int n = 0;
int n = 0;
for (int i = 0; i < rows; i++)
{
//get a new row
Row* aRowPtr = new Row();
std::string colName;
std::string colValue;
//get row ID from the buffer
std::string rowid = dataList[n++];
aRowPtr->set_RowID(atoll(rowid.c_str()));
#ifdef DML_PACKAGE_DEBUG
//cout << "The row ID is " << rowid << endl;
#endif
for (int j = 0; j < columns; j++)
{
//Build a column list
colName = dataList[n++];
colValue = dataList[n++];
#ifdef DML_PACKAGE_DEBUG
//cout << "The column data: " << colName << " " << colValue << endl;
#endif
DMLColumn* aColumn = new DMLColumn(colName, colValue);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
fTable->get_RowList().push_back(aRowPtr);
}
return retval;
}
int UpdateDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues )
{
int retval = 1;
initializeTable();
for (int i = 0; i < rows; i++)
{
// get a new row
Row* aRowPtr = new Row();
std::string colName;
std::vector<std::string> colValList;
std::string colValue;
// get row ID from the buffer
std::string rowid = dataList[n++];
aRowPtr->set_RowID(atoll(rowid.c_str()));
#ifdef DML_PACKAGE_DEBUG
// cout << "The row ID is " << rowid << endl;
#endif
for (int j = 0; j < columns; j++)
{
//Build a column list
colName = colNameList[j];
// Build a column list
colName = dataList[n++];
colValue = dataList[n++];
#ifdef DML_PACKAGE_DEBUG
colValList = tableValuesMap[j];
// cout << "The column data: " << colName << " " << colValue << endl;
#endif
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
(aRowPtr->get_ColumnList()).push_back(aColumn);
DMLColumn* aColumn = new DMLColumn(colName, colValue);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
//build a row list for a table
// build a row list for a table
fTable->get_RowList().push_back(aRowPtr);
return retval;
}
}
void UpdateDMLPackage::buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStmt)
return retval;
}
int UpdateDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap,
int columns, int rows, NullValuesBitset& nullValues)
{
int retval = 1;
if (!updateStmt.fColAssignmentListPtr)
throw runtime_error("updateStmt.fColAssignmentPtr == NULL");
initializeTable();
Row* aRowPtr = new Row();
std::string colName;
std::vector<std::string> colValList;
initializeTable();
for (int j = 0; j < columns; j++)
{
// Build a column list
colName = colNameList[j];
// Since there is no filter, all rows are updated
colValList = tableValuesMap[j];
// Push one row always and let the filter happen on the proc side.
Row* rowPtr = new Row();
ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin();
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
(aRowPtr->get_ColumnList()).push_back(aColumn);
}
while (iter != updateStmt.fColAssignmentListPtr->end())
{
ColumnAssignment* colaPtr = *iter;
DMLColumn* colPtr = new DMLColumn(colaPtr->fColumn, colaPtr->fScalarExpression, colaPtr->fFromCol, colaPtr->fFuncScale,
colaPtr->fIsNull);
rowPtr->get_ColumnList().push_back(colPtr);
++iter;
}
fTable->get_RowList().push_back(rowPtr);
// build a row list for a table
fTable->get_RowList().push_back(aRowPtr);
return retval;
}
} // namespace dmlpackage
void UpdateDMLPackage::buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStmt)
{
if (!updateStmt.fColAssignmentListPtr)
throw runtime_error("updateStmt.fColAssignmentPtr == NULL");
initializeTable();
// Since there is no filter, all rows are updated
// Push one row always and let the filter happen on the proc side.
Row* rowPtr = new Row();
ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin();
while (iter != updateStmt.fColAssignmentListPtr->end())
{
ColumnAssignment* colaPtr = *iter;
DMLColumn* colPtr = new DMLColumn(colaPtr->fColumn, colaPtr->fScalarExpression, colaPtr->fFromCol,
colaPtr->fFuncScale, colaPtr->fIsNull);
rowPtr->get_ColumnList().push_back(colPtr);
++iter;
}
fTable->get_RowList().push_back(rowPtr);
}
} // namespace dmlpackage

View File

@ -40,67 +40,63 @@ namespace dmlpackage
*/
class UpdateDMLPackage : public CalpontDMLPackage
{
public:
/** @brief ctor
*/
EXPORT UpdateDMLPackage();
public:
/** @brief ctor
*/
EXPORT UpdateDMLPackage();
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session ID
*/
EXPORT UpdateDMLPackage(std::string schemaName, std::string tableName, std::string dmlStatement,
int sessionID);
/** @brief ctor
*
* @param schemaName the schema of the table being operated on
* @param tableName the name of the table being operated on
* @param dmlStatement the dml statement
* @param sessionID the session ID
*/
EXPORT UpdateDMLPackage( std::string schemaName, std::string tableName,
std::string dmlStatement, int sessionID );
/** @brief dtor
*/
EXPORT virtual ~UpdateDMLPackage();
/** @brief dtor
*/
EXPORT virtual ~UpdateDMLPackage();
/** @brief write a UpdateDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief write a UpdateDMLPackage to a ByteStream
*
* @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief read a UpdateDMLPackage from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief read a UpdateDMLPackage from a ByteStream
*
* @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief build a UpdateDMLPackage from a string buffer
*
* @param buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromBuffer(std::string& buffer, int columns, int rows);
/** @brief build a UpdateDMLPackage from a string buffer
*
* @param buffer
* @param columns the number of columns in the buffer
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromBuffer(std::string& buffer, int columns, int rows);
/** @brief build a UpdateDMLPackage from a parsed UpdateSqlStatement
*
* @param sqlStatement the parsed UpdateSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a UpdateDMLPackage from a parsed UpdateSqlStatement
*
* @param sqlStatement the parsed UpdateSqlStatement
*/
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param colNameList, tableValuesMap
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns, int rows, NullValuesBitset& nullValues);
void buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStmt );
protected:
private:
/** @brief build a InsertDMLPackage from MySQL buffer
*
* @param colNameList, tableValuesMap
* @param rows the number of rows in the buffer
*/
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns,
int rows, NullValuesBitset& nullValues);
void buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStmt);
protected:
private:
};
}
} // namespace dmlpackage
#undef EXPORT

View File

@ -29,31 +29,56 @@ using namespace std;
namespace dmlpackage
{
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int sessionID)
: fDMLStatement(dmlstatement), fSessionID(sessionID), fLogging(true), fLogending(true)
{}
: fDMLStatement(dmlstatement), fSessionID(sessionID), fLogging(true), fLogending(true)
{
}
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, int sessionID)
: fDMLStatement(dmlstatement), fDMLStatementType(stmttype), fSessionID(sessionID), fLogging(true), fLogending(true)
{}
: fDMLStatement(dmlstatement)
, fDMLStatementType(stmttype)
, fSessionID(sessionID)
, fLogging(true)
, fLogending(true)
{
}
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype,
std::string tName, std::string schema,
int rows, int columns, std::string buf,
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName,
std::string schema, int rows, int columns, std::string buf,
int sessionID)
: fDMLStatement(dmlstatement), fDMLStatementType(stmttype),
fTableName(tName), fSchema(schema), fRows(rows), fColumns(columns),
fDataBuffer(buf), fSessionID(sessionID), fLogging(true), fLogending(true)
{}
: fDMLStatement(dmlstatement)
, fDMLStatementType(stmttype)
, fTableName(tName)
, fSchema(schema)
, fRows(rows)
, fColumns(columns)
, fDataBuffer(buf)
, fSessionID(sessionID)
, fLogging(true)
, fLogending(true)
{
}
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName, std::string schema, int rows, int columns,
ColNameList& colNameList, TableValuesMap& tableValuesMap, NullValuesBitset& nullValues, int sessionID)
: fDMLStatement(dmlstatement), fDMLStatementType(stmttype),
fTableName(tName), fSchema(schema), fRows(rows), fColumns(columns),
fColNameList(colNameList), fTableValuesMap(tableValuesMap), fNullValues(nullValues), fSessionID(sessionID), fLogging(true), fLogending(true)
{}
VendorDMLStatement::VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName,
std::string schema, int rows, int columns, ColNameList& colNameList,
TableValuesMap& tableValuesMap, NullValuesBitset& nullValues,
int sessionID)
: fDMLStatement(dmlstatement)
, fDMLStatementType(stmttype)
, fTableName(tName)
, fSchema(schema)
, fRows(rows)
, fColumns(columns)
, fColNameList(colNameList)
, fTableValuesMap(tableValuesMap)
, fNullValues(nullValues)
, fSessionID(sessionID)
, fLogging(true)
, fLogending(true)
{
}
VendorDMLStatement::~VendorDMLStatement()
{}
{
}
} // namespace dmlpackage

View File

@ -45,207 +45,203 @@ typedef std::bitset<4096> NullValuesBitset;
*/
class VendorDMLStatement
{
public:
/** @brief ctor
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int sessionID);
public:
/** @brief ctor
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int sessionID);
/** @brief ctor
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int stmttype, int sessionID);
/** @brief ctor
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int stmttype, int sessionID);
/** @brief old ctor!
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName, std::string schema,
int rows, int columns, std::string buf, int sessionID);
/** @brief old ctor!
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName,
std::string schema, int rows, int columns, std::string buf,
int sessionID);
/** @brief ctor for mysql
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName, std::string schema,
int rows, int columns, ColNameList& colNameList, TableValuesMap& tableValuesMap,
NullValuesBitset& nullValues, int sessionID);
/** @brief ctor for mysql
*/
EXPORT VendorDMLStatement(std::string dmlstatement, int stmttype, std::string tName, std::string schema, int rows, int columns,
ColNameList& colNameList, TableValuesMap& tableValuesMap, NullValuesBitset& nullValues, int sessionID);
/** @brief destructor
*/
EXPORT ~VendorDMLStatement();
/** @brief destructor
*/
EXPORT ~VendorDMLStatement();
/** @brief Get the table name
*/
inline std::string get_TableName() const
{
return fTableName;
}
/** @brief Get the table name
*/
inline std::string get_TableName() const
{
return fTableName;
}
/** @brief Set the table name
*/
inline void set_TableName(std::string value)
{
fTableName = value;
}
/** @brief Set the table name
*/
inline void set_TableName( std::string value )
{
fTableName = value;
}
/** @brief Get the schema name
*/
inline std::string get_SchemaName() const
{
return fSchema;
}
/** @brief Get the schema name
*/
inline std::string get_SchemaName() const
{
return fSchema;
}
/** @brief Set the schema name
*/
inline void set_SchemaName(std::string value)
{
fSchema = value;
}
/** @brief Set the schema name
*/
inline void set_SchemaName( std::string value )
{
fSchema = value;
}
/** @brief Get the DML statVendorDMLStatement classement type
*/
inline int get_DMLStatementType() const
{
return fDMLStatementType;
}
/** @brief Get the DML statVendorDMLStatement classement type
*/
inline int get_DMLStatementType() const
{
return fDMLStatementType;
}
/** @brief Set the DML statement type
*/
inline void set_DMLStatementType(int value)
{
fDMLStatementType = value;
}
/** @brief Set the DML statement type
*/
inline void set_DMLStatementType( int value )
{
fDMLStatementType = value;
}
/** @brief Get the DML statement
*/
inline const std::string get_DMLStatement() const
{
return fDMLStatement;
}
/** @brief Get the DML statement
*/
inline const std::string get_DMLStatement() const
{
return fDMLStatement;
}
/** @brief Set the DML statVendorDMLStatement classement
*/
inline void set_DMLStatement(std::string dmlStatement)
{
fDMLStatement = dmlStatement;
}
/** @brief Set the DML statVendorDMLStatement classement
*/
inline void set_DMLStatement( std::string dmlStatement )
{
fDMLStatement = dmlStatement;
}
/** @brief Get the number of rows
*/
inline int get_Rows() const
{
return fRows;
}
/** @brief Get the number of rows
*/
inline int get_Rows() const
{
return fRows;
}
/** @brief Set the number of rows
*/
inline void set_Rows(int value)
{
fRows = value;
}
/** @brief Set the number of rows
*/
inline void set_Rows( int value )
{
fRows = value;
}
/** @brief Get the number of columns
*/
inline int get_Columns() const
{
return fColumns;
}
/** @brief Get the number of columns
*/
inline int get_Columns() const
{
return fColumns;
}
/** @brief Set the number of columns
*/
inline void set_Columns(int value)
{
fColumns = value;
}
/** @brief Set the number of columns
*/
inline void set_Columns( int value )
{
fColumns = value;
}
/** @brief Get the data buffer
*/
inline std::string& get_DataBuffer()
{
return fDataBuffer;
}
/** @brief Get the data buffer
*/
inline std::string& get_DataBuffer()
{
return fDataBuffer;
}
/** @brief Set the data buffer
*/
inline void set_DataBuffer(std::string value)
{
fDataBuffer = value;
}
/** @brief Get the session ID
*/
inline int get_SessionID()
{
return fSessionID;
}
/** @brief Set the data buffer
*/
inline void set_DataBuffer( std::string value )
{
fDataBuffer = value;
}
/** @brief Get the session ID
*/
inline int get_SessionID()
{
return fSessionID;
}
inline NullValuesBitset& get_nullValues()
{
return fNullValues;
}
inline NullValuesBitset& get_nullValues()
{
return fNullValues;
}
/** @brief Set the session ID
*/
inline void set_SessionID(int value)
{
fSessionID = value;
}
/** @brief Set the session ID
*/
inline void set_SessionID( int value )
{
fSessionID = value;
}
inline ColNameList& get_ColNames()
{
return fColNameList;
}
inline TableValuesMap& get_values()
{
return fTableValuesMap;
}
/** @brief get the logging flag
*/
inline bool get_Logging() const
{
return fLogging;
}
inline ColNameList& get_ColNames()
{
return fColNameList;
}
inline TableValuesMap& get_values()
{
return fTableValuesMap;
}
/** @brief get the logging flag
*/
inline bool get_Logging() const
{
return fLogging;
}
/** @brief set the logging flag
*
* @param logging the logging flag to set
*/
inline void set_Logging(bool logging)
{
fLogging = logging;
}
/** @brief set the logging flag
*
* @param logging the logging flag to set
*/
inline void set_Logging( bool logging )
{
fLogging = logging;
}
/** @brief get the logging flag
*/
inline bool get_Logending() const
{
return fLogending;
}
/** @brief get the logging flag
*/
inline bool get_Logending() const
{
return fLogending;
}
/** @brief set the logending flag
*
* @param logending the logending flag to set
*/
inline void set_Logending( bool logending )
{
fLogending = logending;
}
protected:
private:
std::string fDMLStatement;
int fDMLStatementType;
std::string fTableName;
std::string fSchema;
int fRows;
int fColumns;
std::string fDataBuffer;
ColNameList fColNameList;
TableValuesMap fTableValuesMap;
NullValuesBitset fNullValues;
int fSessionID;
bool fLogging;
bool fLogending;
/** @brief set the logending flag
*
* @param logending the logending flag to set
*/
inline void set_Logending(bool logending)
{
fLogending = logending;
}
protected:
private:
std::string fDMLStatement;
int fDMLStatementType;
std::string fTableName;
std::string fSchema;
int fRows;
int fColumns;
std::string fDataBuffer;
ColNameList fColNameList;
TableValuesMap fTableValuesMap;
NullValuesBitset fNullValues;
int fSessionID;
bool fLogging;
bool fLogending;
};
}
} // namespace dmlpackage
#undef EXPORT

Some files were not shown because too many files have changed in this diff Show More