1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-04-18 21:44:02 +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 IndentCaseLabels: true
NamespaceIndentation: None NamespaceIndentation: None
PointerAlignment: Left PointerAlignment: Left
SortIncludes: true SortIncludes: false
Standard: Auto Standard: Auto

View File

@ -15,12 +15,10 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */ MA 02110-1301, USA. */
#pragma once #pragma once
namespace datatypes namespace datatypes
{ {
/* /*
A subset of SQL Conditions related to data processing. A subset of SQL Conditions related to data processing.
SQLSTATE terminology is used for categories: SQLSTATE terminology is used for categories:
@ -30,36 +28,39 @@ namespace datatypes
*/ */
class DataCondition class DataCondition
{ {
public: public:
enum Code enum Code
{ {
// Code Value SQLSTATE // Code Value SQLSTATE
S_SUCCESS = 0, // 00000 S_SUCCESS = 0, // 00000
W_STRING_DATA_RIGHT_TRUNCATION = 1 << 1, // 01004 W_STRING_DATA_RIGHT_TRUNCATION = 1 << 1, // 01004
X_STRING_DATA_RIGHT_TRUNCATION = 1 << 16, // 22001 X_STRING_DATA_RIGHT_TRUNCATION = 1 << 16, // 22001
X_NUMERIC_VALUE_OUT_OF_RANGE = 1 << 17, // 22003 X_NUMERIC_VALUE_OUT_OF_RANGE = 1 << 17, // 22003
X_INVALID_CHARACTER_VALUE_FOR_CAST = 1 << 18, // 22018 X_INVALID_CHARACTER_VALUE_FOR_CAST = 1 << 18, // 22018
}; };
DataCondition() DataCondition() : mError(S_SUCCESS)
:mError(S_SUCCESS)
{ }
DataCondition(Code code)
:mError(code)
{ }
DataCondition & operator|=(Code code)
{ {
mError= (Code) (mError | code); }
DataCondition(Code code) : mError(code)
{
}
DataCondition& operator|=(Code code)
{
mError = (Code)(mError | code);
return *this; return *this;
} }
DataCondition operator&(Code rhs) const 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] // Adjust a sigened integer of any size to the range [-absMaxVal , +absMaxVal]
template<typename T> template <typename T>
void adjustSIntXRange(T & val, T absMaxVal) void adjustSIntXRange(T& val, T absMaxVal)
{ {
if (val > absMaxVal) if (val > absMaxVal)
{ {
@ -73,9 +74,8 @@ public:
} }
} }
private: private:
Code mError; 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 namespace datatypes
{ {
// Convert a positive floating point value to // Convert a positive floating point value to
// a signed or unsigned integer with rounding // a signed or unsigned integer with rounding
// SRC - a floating point data type (float, double, float128_t) // 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) // 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) DST positiveXFloatToXIntRound(SRC value, DST limit)
{ {
SRC tmp = value + 0.5; SRC tmp = value + 0.5;
@ -40,12 +38,11 @@ DST positiveXFloatToXIntRound(SRC value, DST limit)
return static_cast<DST>(tmp); return static_cast<DST>(tmp);
} }
// Convert a negative floating point value to // Convert a negative floating point value to
// a signed integer with rounding // a signed integer with rounding
// SRC - a floating point data type (float, double, float128_t) // SRC - a floating point data type (float, double, float128_t)
// DST - a signed integer data type (int32_t, int64_t, int128_t, etc) // 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) DST negativeXFloatToXIntRound(SRC value, DST limit)
{ {
SRC tmp = value - 0.5; SRC tmp = value - 0.5;
@ -54,40 +51,31 @@ DST negativeXFloatToXIntRound(SRC value, DST limit)
return static_cast<DST>(tmp); return static_cast<DST>(tmp);
} }
// Convert a floating point value to ColumnStore int64_t // Convert a floating point value to ColumnStore int64_t
// Magic values cannot be returned. // Magic values cannot be returned.
template<typename SRC> template <typename SRC>
int64_t xFloatToMCSSInt64Round(SRC value) int64_t xFloatToMCSSInt64Round(SRC value)
{ {
if (value > 0) if (value > 0)
return positiveXFloatToXIntRound<SRC, int64_t>( return positiveXFloatToXIntRound<SRC, int64_t>(value, numeric_limits<int64_t>::max());
value,
numeric_limits<int64_t>::max());
if (value < 0) if (value < 0)
return negativeXFloatToXIntRound<SRC, int64_t>( return negativeXFloatToXIntRound<SRC, int64_t>(value, numeric_limits<int64_t>::min() + 2);
value,
numeric_limits<int64_t>::min() + 2);
return 0; return 0;
} }
// Convert a floating point value to ColumnStore uint64_t // Convert a floating point value to ColumnStore uint64_t
// Magic values cannot be returned. // Magic values cannot be returned.
template<typename SRC> template <typename SRC>
uint64_t xFloatToMCSUInt64Round(SRC value) uint64_t xFloatToMCSUInt64Round(SRC value)
{ {
if (value > 0) if (value > 0)
return positiveXFloatToXIntRound<SRC, uint64_t>( return positiveXFloatToXIntRound<SRC, uint64_t>(value, numeric_limits<uint64_t>::max() - 2);
value,
numeric_limits<uint64_t>::max() - 2);
if (value < 0) if (value < 0)
return negativeXFloatToXIntRound<SRC, uint64_t>(value, 0); return negativeXFloatToXIntRound<SRC, uint64_t>(value, 0);
return 0; return 0;
} }
} // end of namespace datatypes
} //end of namespace datatypes
// vim:ts=2 sw=2: // 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 namespace datatypes
{ {
class TDouble class TDouble
{ {
protected: protected:
double mValue; 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; return mValue;
} }
@ -48,7 +52,6 @@ public:
} }
}; };
} // end of namespace datatypes
} //end of namespace datatypes
// vim:ts=2 sw=2: // 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 You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. MA 02110-1301, USA.
*/ */
#include <iostream> #include <iostream>
@ -24,98 +24,93 @@
namespace datatypes namespace datatypes
{ {
uint8_t TSInt128::printPodParts(char* buf, uint8_t TSInt128::printPodParts(char* buf, const int128_t& high, const int128_t& mid,
const int128_t& high, const int128_t& low) const
const int128_t& mid, {
const int128_t& low) const char* p = buf;
{ // pod[0] is low 8 bytes, pod[1] is high 8 bytes
char* p = buf; const uint64_t* high_pod = reinterpret_cast<const uint64_t*>(&high);
// pod[0] is low 8 bytes, pod[1] is high 8 bytes const uint64_t* mid_pod = reinterpret_cast<const uint64_t*>(&mid);
const uint64_t* high_pod = reinterpret_cast<const uint64_t*>(&high); const uint64_t* low_pod = reinterpret_cast<const uint64_t*>(&low);
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) if (high_pod[0] != 0)
{ {
p += sprintf(p, "%lu", high_pod[0]); p += sprintf(p, "%lu", high_pod[0]);
p += sprintf(p, "%019lu", mid_pod[0]); p += sprintf(p, "%019lu", mid_pod[0]);
p += sprintf(p, "%019lu", low_pod[0]); p += sprintf(p, "%019lu", low_pod[0]);
} }
else if (mid_pod[0] != 0) else if (mid_pod[0] != 0)
{ {
p += sprintf(p, "%lu", mid_pod[0]); p += sprintf(p, "%lu", mid_pod[0]);
p += sprintf(p, "%019lu", low_pod[0]); p += sprintf(p, "%019lu", low_pod[0]);
} }
else else
{ {
p += sprintf(p, "%lu", low_pod[0]); p += sprintf(p, "%lu", low_pod[0]);
} }
return p - buf; 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 return written;
uint8_t TSInt128::writeIntPart(const int128_t& x, }
char* buf,
const uint8_t buflen) const // conversion to std::string
std::string TSInt128::toString() const
{
if (isNull())
{ {
char* p = buf; return std::string("NULL");
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;
} }
// conversion to std::string if (isEmpty())
std::string TSInt128::toString() const
{ {
if (isNull()) return std::string("EMPTY");
{ }
return std::string("NULL");
}
if (isEmpty()) int128_t tempValue = s128Value;
{ char buf[TSInt128::MAXLENGTH16BYTES];
return std::string("EMPTY"); uint8_t left = sizeof(buf);
} char* p = buf;
// sign
int128_t tempValue = s128Value; if (tempValue < static_cast<int128_t>(0))
char buf[TSInt128::MAXLENGTH16BYTES]; {
uint8_t left = sizeof(buf); *p++ = '-';
char* p = buf; tempValue *= -1;
// sign
if (tempValue < static_cast<int128_t>(0))
{
*p++ = '-';
tempValue *= -1;
left--;
}
// integer part
// reduce the size by one to account for \0
left--; 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) return std::string(buf);
{ }
os << x.toString();
return os;
}
} // 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: // vim:ts=2 sw=2:

View File

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

View File

@ -14,162 +14,169 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. MA 02110-1301, USA.
*/ */
#pragma once #pragma once
#include "exceptclasses.h" #include "exceptclasses.h"
namespace datatypes namespace datatypes
{ {
class TNullFlag class TNullFlag
{ {
protected: protected:
bool mIsNull; bool mIsNull;
public:
explicit TNullFlag(bool val) :mIsNull(val) { } public:
explicit TNullFlag(bool val) : mIsNull(val)
{
}
bool isNull() const bool isNull() const
{ {
return mIsNull; return mIsNull;
} }
}; };
class TUInt64 class TUInt64
{ {
protected: protected:
uint64_t mValue; 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; return mValue;
} }
void store(uint8_t* dst) const void store(uint8_t* dst) const
{ {
*(uint64_t*) dst = mValue; *(uint64_t*)dst = mValue;
} }
}; };
class TSInt64 class TSInt64
{ {
protected: protected:
int64_t mValue; 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; return mValue;
} }
explicit operator uint64_t () const explicit operator uint64_t() const
{ {
return mValue < 0 ? 0 : static_cast<uint64_t>(mValue); 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): explicit operator uint64_t() const
TUInt64(value), TNullFlag(isNull)
{ }
explicit operator uint64_t () const
{ {
idbassert(!mIsNull); idbassert(!mIsNull);
return mValue; return mValue;
} }
uint64_t nullSafeValue(bool & isNullRef) const uint64_t nullSafeValue(bool& isNullRef) const
{ {
return (isNullRef = isNull()) ? 0 : mValue; 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); 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); 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); 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); 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); 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): explicit operator int64_t() const
TSInt64(value), TNullFlag(isNull)
{ }
explicit operator int64_t () const
{ {
idbassert(!mIsNull); idbassert(!mIsNull);
return mValue; return mValue;
} }
int64_t nullSafeValue(bool & isNullRef) const int64_t nullSafeValue(bool& isNullRef) const
{ {
return (isNullRef = isNull()) ? 0 : mValue; 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); 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); 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); return TSInt64Null(mValue ^ rhs.mValue, mIsNull || rhs.mIsNull);
} }
TSInt64Null MariaDBShiftLeft(const TUInt64Null &rhs) const TSInt64Null MariaDBShiftLeft(const TUInt64Null& rhs) const
{ {
if (isNull() || rhs.isNull()) if (isNull() || rhs.isNull())
return TSInt64Null(); 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()) if (isNull() || rhs.isNull())
return TSInt64Null(); 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: // vim:ts=2 sw=2:

View File

@ -22,17 +22,21 @@
namespace datatypes namespace datatypes
{ {
class TLongDouble class TLongDouble
{ {
protected: protected:
long double mValue; 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; return mValue;
} }
@ -48,7 +52,6 @@ public:
} }
}; };
} // end of namespace datatypes
} //end of namespace datatypes
// vim:ts=2 sw=2: // vim:ts=2 sw=2:

View File

@ -21,18 +21,24 @@
namespace datatypes namespace datatypes
{ {
template <typename T> template <typename T>
struct numeric_limits struct numeric_limits
{ {
static constexpr T min() { return std::numeric_limits<T>::min(); } static constexpr T min()
static constexpr T max() { return std::numeric_limits<T>::max(); } {
return std::numeric_limits<T>::min();
}
static constexpr T max()
{
return std::numeric_limits<T>::max();
}
}; };
using int128_t = __int128; using int128_t = __int128;
using uint128_t = unsigned __int128; using uint128_t = unsigned __int128;
template<> struct numeric_limits<int128_t> template <>
struct numeric_limits<int128_t>
{ {
static constexpr int128_t min() 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() 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, Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */ MA 02110-1301, USA. */
#pragma once #pragma once
#include "conststring.h" #include "conststring.h"
#include "collation.h" // class Charset #include "collation.h" // class Charset
namespace datatypes namespace datatypes
{ {
class TCharShort class TCharShort
{ {
int64_t mValue; int64_t mValue;
public:
TCharShort(int64_t value) public:
:mValue(value) TCharShort(int64_t value) : mValue(value)
{ } {
utils::ConstString toConstString(uint32_t width) const }
{ utils::ConstString toConstString(uint32_t width) const
utils::ConstString res = utils::ConstString((const char *) &mValue, width); {
return res.rtrimZero(); 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) }
{ static int strnncollsp(const datatypes::Charset& cs, int64_t a, int64_t b, uint32_t width)
datatypes::TCharShort sa(a); {
datatypes::TCharShort sb(b); datatypes::TCharShort sa(a);
return cs.strnncollsp(sa.toConstString(width), datatypes::TCharShort sb(b);
sb.toConstString(width)); 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, Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */ MA 02110-1301, USA. */
#pragma once #pragma once
#include "genericparser.h" #include "genericparser.h"
#include "mcs_datatype.h" #include "mcs_datatype.h"
namespace literal namespace literal
{ {
using utils::ConstString;
using genericparser::Parser;
using datatypes::DataCondition; using datatypes::DataCondition;
using genericparser::Parser;
using utils::ConstString;
typedef uint32_t scale_t; typedef uint32_t scale_t;
template <class A>
class Converter : public Parser, public A
template<class A>
class Converter: public Parser,
public A
{ {
public: public:
Converter(const char *str, size_t length, DataCondition & error) Converter(const char* str, size_t length, DataCondition& error)
:Parser(str, length), : Parser(str, length), A(&Parser::skipLeadingSpaces())
A(&Parser::skipLeadingSpaces())
{ {
if (Parser::syntaxError()) if (Parser::syntaxError())
{ {
@ -56,15 +49,14 @@ public:
'1e' - exponent marker was not followed by <exponent>, expect '1e1' '1e' - exponent marker was not followed by <exponent>, expect '1e1'
'1e+' - in <exponent>, <sign> was not followed by a digit, expect '1e+1' '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(const std::string& str, DataCondition& error) : Converter(str.data(), str.length(), error)
:Converter(str.data(), str.length(), error) {
{ } }
}; };
/* /*
SQL Standard definition for <cast specification> SQL Standard definition for <cast specification>
@ -143,70 +135,83 @@ Grammar
*/ */
// //
// Terminal symbols // Terminal symbols
// //
class Period: public ConstString class Period : public ConstString
{ {
public: public:
explicit Period(Parser *p) explicit Period(Parser* p) : ConstString(p->tokenChar('.'))
:ConstString(p->tokenChar('.')) {
{ } }
bool isNull() const { return mStr == nullptr; } bool isNull() const
{
return mStr == nullptr;
}
}; };
class ExponentMarker : public ConstString
class ExponentMarker: public ConstString
{ {
public: public:
explicit ExponentMarker(Parser *p) explicit ExponentMarker(Parser* p) : ConstString(p->tokenAnyCharOf('e', 'E'))
:ConstString(p->tokenAnyCharOf('e', 'E')) {
{ } }
bool isNull() const { return mStr == nullptr; } bool isNull() const
{
return mStr == nullptr;
}
}; };
class Sign : public ConstString
class Sign: public ConstString
{ {
public: public:
explicit Sign(): ConstString(NULL, 0) { } explicit Sign() : ConstString(NULL, 0)
explicit Sign(const ConstString &str) {
:ConstString(str) }
{ } explicit Sign(const ConstString& str) : ConstString(str)
explicit Sign(Parser *p) {
:ConstString(p->tokenAnyCharOf('+', '-')) }
{ } explicit Sign(Parser* p) : ConstString(p->tokenAnyCharOf('+', '-'))
static Sign empty(Parser *p) {
}
static Sign empty(Parser* p)
{ {
return Sign(p->tokStartConstString()); return Sign(p->tokStartConstString());
} }
bool isNull() const { return mStr == nullptr; } bool isNull() const
bool negative() const { return eq('-'); } {
return mStr == nullptr;
}
bool negative() const
{
return eq('-');
}
}; };
class Digits : public ConstString
class Digits: public ConstString
{ {
public: public:
explicit Digits() explicit Digits() : ConstString(NULL, 0)
:ConstString(NULL, 0) {
{ } }
explicit Digits(const char *str, size_t length) explicit Digits(const char* str, size_t length) : ConstString(str, length)
:ConstString(str, length) {
{ } }
explicit Digits(const ConstString &str) explicit Digits(const ConstString& str) : ConstString(str)
:ConstString(str) {
{ } }
explicit Digits(Parser *p) explicit Digits(Parser* p) : ConstString(p->tokenDigits())
:ConstString(p->tokenDigits()) {
{ } }
bool isNull() const { return mStr == nullptr; } bool isNull() const
{
return mStr == nullptr;
}
void skipLeadingZeroDigits() void skipLeadingZeroDigits()
{ {
for ( ; mLength > 0 && mStr[0] == '0'; ) for (; mLength > 0 && mStr[0] == '0';)
{ {
mStr++; mStr++;
mLength--; mLength--;
@ -214,33 +219,32 @@ public:
} }
void skipTrailingZeroDigits() void skipTrailingZeroDigits()
{ {
for ( ; mLength > 0 && mStr[mLength - 1] == '0' ; ) for (; mLength > 0 && mStr[mLength - 1] == '0';)
mLength--; mLength--;
} }
}; };
// //
// Non-terminal symbols // Non-terminal symbols
// //
// <unsigned integer> ::= <digit> ... // <unsigned integer> ::= <digit> ...
class UnsignedInteger: public Digits class UnsignedInteger : public Digits
{ {
public: public:
explicit UnsignedInteger() explicit UnsignedInteger() : Digits()
:Digits() {
{ } }
explicit UnsignedInteger(const char *str, size_t length) explicit UnsignedInteger(const char* str, size_t length) : Digits(str, length)
:Digits(str, length) {
{ } }
explicit UnsignedInteger(const ConstString &str) explicit UnsignedInteger(const ConstString& str) : Digits(str)
:Digits(str) {
{ } }
explicit UnsignedInteger(Parser *p) explicit UnsignedInteger(Parser* p) : Digits(p)
:Digits(p) {
{ } }
static UnsignedInteger empty(const Parser *p) static UnsignedInteger empty(const Parser* p)
{ {
return UnsignedInteger(p->tokStartConstString()); return UnsignedInteger(p->tokStartConstString());
} }
@ -249,182 +253,177 @@ public:
return UnsignedInteger(str(), length() > len ? len : length()); return UnsignedInteger(str(), length() > len ? len : length());
} }
template<typename T> template <typename T>
T toXIntPositiveContinue(T start, DataCondition & error) const T toXIntPositiveContinue(T start, DataCondition& error) const
{ {
const char *e = end(); const char* e = end();
T val = start; 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; constexpr T cutoff = datatypes::numeric_limits<T>::max() / 10;
if (val > cutoff) 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(); return datatypes::numeric_limits<T>::max();
} }
val*= 10; val *= 10;
T newval = val + (s[0] - '0'); T newval = val + (s[0] - '0');
if (newval < val) 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(); return datatypes::numeric_limits<T>::max();
} }
val = newval; val = newval;
} }
return val; return val;
} }
template<typename T> template <typename T>
T toXIntPositive(DataCondition & error) const T toXIntPositive(DataCondition& error) const
{ {
return toXIntPositiveContinue<T>(0, error); return toXIntPositiveContinue<T>(0, error);
} }
template<typename T> template <typename T>
T toSIntNegativeContinue(T start, DataCondition & error) const T toSIntNegativeContinue(T start, DataCondition& error) const
{ {
const char *e = end(); const char* e = end();
T val = start; 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; constexpr T cutoff = datatypes::numeric_limits<T>::min() / 10;
if (val < cutoff) 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(); return datatypes::numeric_limits<T>::min();
} }
val*= 10; val *= 10;
T newval = val - (s[0] - '0'); T newval = val - (s[0] - '0');
if (newval > val) 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(); return datatypes::numeric_limits<T>::min();
} }
val = newval; val = newval;
} }
return val; return val;
} }
template<typename T> template <typename T>
T toSIntNegative(DataCondition & error) const T toSIntNegative(DataCondition& error) const
{ {
return toSIntNegativeContinue<T>(0, error); return toSIntNegativeContinue<T>(0, error);
} }
template<typename T> template <typename T>
T toXIntPositiveRoundAwayFromZeroContinue(T start, bool round, DataCondition & error) const T toXIntPositiveRoundAwayFromZeroContinue(T start, bool round, DataCondition& error) const
{ {
T val = toXIntPositiveContinue<T>(start, error); T val = toXIntPositiveContinue<T>(start, error);
if (val == datatypes::numeric_limits<T>::max() && round) 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;
} }
return val + round; return val + round;
} }
template<typename T> template <typename T>
T toXIntPositiveRoundAwayFromZero(bool round, DataCondition & error) const T toXIntPositiveRoundAwayFromZero(bool round, DataCondition& error) const
{ {
return toXIntPositiveRoundAwayFromZeroContinue<T>(0, round, error); return toXIntPositiveRoundAwayFromZeroContinue<T>(0, round, error);
} }
}; };
// <signed integer> := [<sign>] <unsigned integer> // <signed integer> := [<sign>] <unsigned integer>
class SignedInteger: public Parser::DD2OM<Sign,UnsignedInteger> class SignedInteger : public Parser::DD2OM<Sign, UnsignedInteger>
{ {
public: public:
using DD2OM::DD2OM; 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); return toXIntPositive<T>(error);
} }
template<typename T> T toSInt(DataCondition & error) const template <typename T>
T toSInt(DataCondition& error) const
{ {
return negative() ? return negative() ? toSIntNegative<T>(error) : toXIntPositive<T>(error);
toSIntNegative<T>(error) :
toXIntPositive<T>(error);
} }
}; };
// E <signed integer> // E <signed integer>
class EExponent: public Parser::UD2MM<ExponentMarker, SignedInteger> class EExponent : public Parser::UD2MM<ExponentMarker, SignedInteger>
{ {
public: public:
using UD2MM::UD2MM; using UD2MM::UD2MM;
}; };
// <period> <unsigned integer> // <period> <unsigned integer>
class ExactUnsignedNumericLiteralFractionAlone: public Parser::UD2MM<Period, UnsignedInteger> class ExactUnsignedNumericLiteralFractionAlone : public Parser::UD2MM<Period, UnsignedInteger>
{ {
public: public:
using UD2MM::UD2MM; using UD2MM::UD2MM;
}; };
// <period> [ <unsigned integer> ] // <period> [ <unsigned integer> ]
class PeriodOptUnsignedInteger: public Parser::UD2MO<Period, UnsignedInteger> class PeriodOptUnsignedInteger : public Parser::UD2MO<Period, UnsignedInteger>
{ {
public: public:
using UD2MO::UD2MO; using UD2MO::UD2MO;
static PeriodOptUnsignedInteger empty(Parser *p) static PeriodOptUnsignedInteger empty(Parser* p)
{ {
return PeriodOptUnsignedInteger(UnsignedInteger(p->tokStartConstString())); return PeriodOptUnsignedInteger(UnsignedInteger(p->tokStartConstString()));
} }
const PeriodOptUnsignedInteger & fraction() const const PeriodOptUnsignedInteger& fraction() const
{ {
return *this; return *this;
} }
}; };
// <integral unsigned integer> := <unsigned integer> // <integral unsigned integer> := <unsigned integer>
class IntegralUnsignedInteger: public UnsignedInteger class IntegralUnsignedInteger : public UnsignedInteger
{ {
public: public:
explicit IntegralUnsignedInteger(Parser *p) explicit IntegralUnsignedInteger(Parser* p) : UnsignedInteger(p)
:UnsignedInteger(p) {
{ } }
const UnsignedInteger & integral() const const UnsignedInteger& integral() const
{ {
return *this; return *this;
} }
}; };
// <integral unsigned integer> [ <period> [ <unsigned integer> ] ] // <integral unsigned integer> [ <period> [ <unsigned integer> ] ]
class ExactUnsignedNumericLiteralIntegralOptFraction: class ExactUnsignedNumericLiteralIntegralOptFraction
public Parser::DD2MO<IntegralUnsignedInteger, : public Parser::DD2MO<IntegralUnsignedInteger, PeriodOptUnsignedInteger>
PeriodOptUnsignedInteger>
{ {
public: public:
using DD2MO::DD2MO; using DD2MO::DD2MO;
}; };
// A container for integral and fractional parts // A container for integral and fractional parts
class UnsignedIntegerDecimal class UnsignedIntegerDecimal
{ {
protected: protected:
UnsignedInteger mIntegral; UnsignedInteger mIntegral;
UnsignedInteger mFraction; UnsignedInteger mFraction;
public:
explicit UnsignedIntegerDecimal(const UnsignedInteger &intg, public:
const UnsignedInteger &frac) explicit UnsignedIntegerDecimal(const UnsignedInteger& intg, const UnsignedInteger& frac)
:mIntegral(intg), : mIntegral(intg), mFraction(frac)
mFraction(frac) {
{ } }
explicit UnsignedIntegerDecimal(const ExactUnsignedNumericLiteralFractionAlone &rhs) explicit UnsignedIntegerDecimal(const ExactUnsignedNumericLiteralFractionAlone& rhs) : mFraction(rhs)
:mFraction(rhs) {
{ } }
explicit UnsignedIntegerDecimal(const ExactUnsignedNumericLiteralIntegralOptFraction &rhs) explicit UnsignedIntegerDecimal(const ExactUnsignedNumericLiteralIntegralOptFraction& rhs)
:mIntegral(rhs.integral()), : mIntegral(rhs.integral()), mFraction(rhs.fraction())
mFraction(rhs.fraction()) {
{ } }
size_t IntFracDigits() const size_t IntFracDigits() const
{ {
@ -442,51 +441,55 @@ public:
mFraction.skipTrailingZeroDigits(); mFraction.skipTrailingZeroDigits();
} }
template<typename T> T toXIntPositive(DataCondition & error) const template <typename T>
T toXIntPositive(DataCondition& error) const
{ {
T val = mIntegral.toXIntPositive<T>(error); T val = mIntegral.toXIntPositive<T>(error);
return mFraction.toXIntPositiveContinue<T>(val, 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); T val = mIntegral.toXIntPositive<T>(error);
return mFraction.toXIntPositiveRoundAwayFromZeroContinue<T>(val, roundUp, 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); T val = toXIntPositive<T>(error);
if (val == datatypes::numeric_limits<T>::max()) if (val == datatypes::numeric_limits<T>::max())
return val; return val;
for ( ; scale ; scale--) for (; scale; scale--)
{ {
constexpr T cutoff = datatypes::numeric_limits<T>::max() / 10; constexpr T cutoff = datatypes::numeric_limits<T>::max() / 10;
if (val > cutoff) 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(); return datatypes::numeric_limits<T>::max();
} }
val*= 10; val *= 10;
} }
return val; 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'; bool roundUp = mFraction.length() && mFraction.str()[0] >= '5';
return mIntegral.toXIntPositiveRoundAwayFromZero<T>(roundUp, error); return mIntegral.toXIntPositiveRoundAwayFromZero<T>(roundUp, error);
} }
template<typename T> T toXIntPositiveRoundExp(uint64_t absExp, bool negExp, template <typename T>
DataCondition & error) const T toXIntPositiveRoundExp(uint64_t absExp, bool negExp, DataCondition& error) const
{ {
if (absExp == 0) if (absExp == 0)
return toXIntPositiveRound<T>(error); return toXIntPositiveRound<T>(error);
if (negExp) 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; return mIntegral.str()[0] >= '5' ? 1 : 0;
if (mIntegral.length() < absExp) // 123e-4 -> 0.0123 if (mIntegral.length() < absExp) // 123e-4 -> 0.0123
return 0; return 0;
@ -498,7 +501,7 @@ public:
} }
// Positive exponent: 123.456e2 // 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'; bool roundUp = mFraction.length() > absExp && mFraction.str()[absExp] >= '5';
UnsignedIntegerDecimal tmp(mIntegral, mFraction.left(absExp)); UnsignedIntegerDecimal tmp(mIntegral, mFraction.left(absExp));
@ -509,42 +512,38 @@ public:
size_t diff = absExp - mFraction.length(); size_t diff = absExp - mFraction.length();
return toXIntPositiveScaleUp<T>(diff, error); return toXIntPositiveScaleUp<T>(diff, error);
} }
}; };
// <exact unsigned numeric literal> := // <exact unsigned numeric literal> :=
// <period> [ <unsigned integer> ] // <period> [ <unsigned integer> ]
// | <unsigned integer> [ <period> [ <unsigned integer> ] ] // | <unsigned integer> [ <period> [ <unsigned integer> ] ]
class ExactUnsignedNumericLiteral: class ExactUnsignedNumericLiteral
public Parser::Choice2<UnsignedIntegerDecimal, : public Parser::Choice2<UnsignedIntegerDecimal, ExactUnsignedNumericLiteralFractionAlone,
ExactUnsignedNumericLiteralFractionAlone, ExactUnsignedNumericLiteralIntegralOptFraction>
ExactUnsignedNumericLiteralIntegralOptFraction>
{ {
public: public:
using Choice2::Choice2; using Choice2::Choice2;
}; };
// <unsigned numeric literal> ::= <exact numeric literal> [ E <exponent> ] // <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; using DM2MO::DM2MO;
void normalize() void normalize()
{ {
ExactUnsignedNumericLiteral::normalize(); ExactUnsignedNumericLiteral::normalize();
mB.skipLeadingZeroDigits(); mB.skipLeadingZeroDigits();
} }
const SignedInteger & exponent() const const SignedInteger& exponent() const
{ {
return mB; return mB;
} }
template<typename T> template <typename T>
T toXIntPositiveRound(DataCondition & error) const T toXIntPositiveRound(DataCondition& error) const
{ {
size_t availableDigits = IntFracDigits(); size_t availableDigits = IntFracDigits();
if (!availableDigits) if (!availableDigits)
@ -553,35 +552,36 @@ public:
return ExactUnsignedNumericLiteral::toXIntPositiveRoundExp<T>(absexp, exponent().negative(), error); return ExactUnsignedNumericLiteral::toXIntPositiveRoundExp<T>(absexp, exponent().negative(), error);
} }
template<typename T> template <typename T>
T toPackedDecimalPositive(scale_t scale, DataCondition & error) const T toPackedDecimalPositive(scale_t scale, DataCondition& error) const
{ {
size_t availableDigits = IntFracDigits(); size_t availableDigits = IntFracDigits();
if (!availableDigits) if (!availableDigits)
return 0; return 0;
int64_t exp = exponent().toSInt<int64_t>(error); int64_t exp = exponent().toSInt<int64_t>(error);
if (exp <= datatypes::numeric_limits<int64_t>::max() - scale) if (exp <= datatypes::numeric_limits<int64_t>::max() - scale)
exp+= scale; exp += scale;
if (exp < 0) if (exp < 0)
{ {
if (exp == datatypes::numeric_limits<int64_t>::min()) if (exp == datatypes::numeric_limits<int64_t>::min())
exp++; // Avoid undefined behaviour in the unary minus below: 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, 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> // <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; using DD2OM::DD2OM;
bool isNull() const { return UnsignedNumericLiteral::isNull(); } bool isNull() const
{
return UnsignedNumericLiteral::isNull();
}
template<typename T> template <typename T>
T toUIntXRound() const T toUIntXRound() const
{ {
if (negative()) if (negative())
@ -589,30 +589,28 @@ public:
return UnsignedNumericLiteral::toXIntPositiveRound<T>(); return UnsignedNumericLiteral::toXIntPositiveRound<T>();
} }
template<typename T> template <typename T>
T toPackedUDecimal(scale_t scale, DataCondition & error) const T toPackedUDecimal(scale_t scale, DataCondition& error) const
{ {
if (negative()) if (negative())
return 0; return 0;
return UnsignedNumericLiteral::toPackedDecimalPositive<T>(scale, error); return UnsignedNumericLiteral::toPackedDecimalPositive<T>(scale, error);
} }
template<typename T> template <typename T>
T toPackedSDecimal(scale_t scale, DataCondition & error) const T toPackedSDecimal(scale_t scale, DataCondition& error) const
{ {
if (!negative()) if (!negative())
return UnsignedNumericLiteral::toPackedDecimalPositive<T>(scale, error); return UnsignedNumericLiteral::toPackedDecimalPositive<T>(scale, error);
typedef typename datatypes::make_unsigned<T>::type UT; typedef typename datatypes::make_unsigned<T>::type UT;
UT absval = UnsignedNumericLiteral::toPackedDecimalPositive<UT>(scale, error); 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 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. */ 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 #define DDLPKG_DLLEXPORT
#include "ddlpkg.h" #include "ddlpkg.h"
@ -29,169 +29,139 @@ namespace ddlpackage
{ {
using namespace std; using namespace std;
AlterTableStatement::AlterTableStatement(QualifiedName* qName, AlterTableActionList* ataList): AlterTableStatement::AlterTableStatement(QualifiedName* qName, AlterTableActionList* ataList)
fTableName(qName), : fTableName(qName), fActions(*ataList)
fActions(*ataList)
{ {
delete ataList; delete ataList;
} }
AlterTableStatement::~AlterTableStatement() AlterTableStatement::~AlterTableStatement()
{ {
delete fTableName; delete fTableName;
AlterTableActionList::iterator itr; AlterTableActionList::iterator itr;
for (itr = fActions.begin(); itr != fActions.end(); ++itr) for (itr = fActions.begin(); itr != fActions.end(); ++itr)
{ {
delete *itr; delete *itr;
} }
} }
std::ostream& AlterTableStatement::put(std::ostream& os) const std::ostream& AlterTableStatement::put(std::ostream& os) const
{ {
AlterTableActionList::const_iterator itr; AlterTableActionList::const_iterator itr;
os << "Alter Table " << *fTableName << endl; os << "Alter Table " << *fTableName << endl;
for (itr = fActions.begin(); itr != fActions.end(); ++itr) for (itr = fActions.begin(); itr != fActions.end(); ++itr)
{ {
os << **itr << endl; os << **itr << endl;
} }
return os; return os;
} }
/** @brief Format to ostream. Diagnostic. */ /** @brief Format to ostream. Diagnostic. */
std::ostream& AlterTableAction::put(std::ostream& os) const std::ostream& AlterTableAction::put(std::ostream& os) const
{ {
os << "AlterTableAction put stub"; os << "AlterTableAction put stub";
return os; return os;
} }
/** @brief Invokes the virtual function put, to dispatch to subclass /** @brief Invokes the virtual function put, to dispatch to subclass
ostream writers. */ ostream writers. */
std::ostream& operator<<(std::ostream& os, const AlterTableAction& ata) std::ostream& operator<<(std::ostream& os, const AlterTableAction& ata)
{ {
return ata.put(os); return ata.put(os);
} }
AtaAddColumn::~AtaAddColumn() AtaAddColumn::~AtaAddColumn()
{ {
delete fColumnDef; delete fColumnDef;
} }
/** @brief ostream output */ /** @brief ostream output */
std::ostream& AtaAddColumn::put(std::ostream& os) const std::ostream& AtaAddColumn::put(std::ostream& os) const
{ {
os << "Add Column" << endl; os << "Add Column" << endl;
os << *fColumnDef << endl; os << *fColumnDef << endl;
return os; 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 std::ostream& AtaDropColumn::put(std::ostream& os) const
{ {
os << "Drop Column: " << fColumnName << " " os << "Drop Column: " << fColumnName << " " << ReferentialActionStrings[fDropBehavior];
<< ReferentialActionStrings[fDropBehavior]; return os;
return os;
} }
AtaModifyColumnType::~AtaModifyColumnType() AtaModifyColumnType::~AtaModifyColumnType()
{ {
delete fColumnType; delete fColumnType;
} }
std::ostream& AtaModifyColumnType::put(std::ostream& os) const 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() AtaRenameColumn::~AtaRenameColumn()
{ {
delete fNewType; delete fNewType;
} }
std::ostream& AtaRenameColumn::put(std::ostream& os) const std::ostream& AtaRenameColumn::put(std::ostream& os) const
{ {
os << "Rename Column: " << fName << " -> " << fNewName << " (" << *fNewType << ')'; os << "Rename Column: " << fName << " -> " << fNewName << " (" << *fNewType << ')';
return os; 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() AtaSetColumnDefault::~AtaSetColumnDefault()
{ {
delete fDefaultValue; delete fDefaultValue;
} }
std::ostream& AtaSetColumnDefault::put(std::ostream& os) const std::ostream& AtaSetColumnDefault::put(std::ostream& os) const
{ {
os << "Set Column Default: " << fColumnName << " " os << "Set Column Default: " << fColumnName << " " << *fDefaultValue << endl;
<< *fDefaultValue << endl; return os;
return os;
} }
AtaDropColumnDefault::AtaDropColumnDefault(const char* colName) : fColumnName(colName)
AtaDropColumnDefault::AtaDropColumnDefault(const char* colName) :
fColumnName(colName)
{ {
} }
std::ostream& AtaDropColumnDefault::put(std::ostream& os) const std::ostream& AtaDropColumnDefault::put(std::ostream& os) const
{ {
os << "Drop Column Default: " << fColumnName << " "; os << "Drop Column Default: " << fColumnName << " ";
return os; return os;
} }
AtaRenameTable::AtaRenameTable(QualifiedName* qualifiedName) : fQualifiedName(qualifiedName)
AtaRenameTable::AtaRenameTable(QualifiedName* qualifiedName) :
fQualifiedName(qualifiedName)
{ {
} }
AtaRenameTable::~AtaRenameTable() AtaRenameTable::~AtaRenameTable()
{ {
delete fQualifiedName; delete fQualifiedName;
} }
std::ostream& AtaRenameTable::put(std::ostream& os) const std::ostream& AtaRenameTable::put(std::ostream& os) const
{ {
os << "Rename Table: " << *fQualifiedName << endl; os << "Rename Table: " << *fQualifiedName << endl;
return os; 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 std::ostream& AtaTableComment::put(std::ostream& os) const
{ {
os << "TableComment: " << fTableComment << endl; os << "TableComment: " << fTableComment << endl;
return os; return os;
} }
AtaAddColumns::~AtaAddColumns() AtaAddColumns::~AtaAddColumns()
{ {
ColumnDefList::iterator itr; ColumnDefList::iterator itr;
for (itr = fColumns.begin(); itr != fColumns.end(); itr++) for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
delete *itr; delete *itr;
} }
AtaAddColumns::AtaAddColumns(TableElementList* tableElements) AtaAddColumns::AtaAddColumns(TableElementList* tableElements)
{ {
/* It is convenient to reuse the grammar rules for /* It is convenient to reuse the grammar rules for
table_element_list, and we do. So, it is possible for table_element_list, and we do. So, it is possible for
there to be errant table constraint defs in the input list. there to be errant table constraint defs in the input list.
We ignore them. That is all we are doing here. We ignore them. That is all we are doing here.
*/ */
ColumnDef* column; ColumnDef* column;
TableElementList::const_iterator itr; TableElementList::const_iterator itr;
for (itr = tableElements->begin(); for (itr = tableElements->begin(); itr != tableElements->end(); ++itr)
itr != tableElements->end(); {
++itr) column = dynamic_cast<ColumnDef*>(*itr);
if (0 != column)
{ {
column = dynamic_cast<ColumnDef*>(*itr); fColumns.push_back(column);
if (0 != column)
{
fColumns.push_back(column);
}
} }
}
delete tableElements; delete tableElements;
} }
std::ostream& AtaAddColumns::put(std::ostream& os) const std::ostream& AtaAddColumns::put(std::ostream& os) const
{ {
os << "Add Columns: " << endl; os << "Add Columns: " << endl;
ColumnDefList::const_iterator itr; ColumnDefList::const_iterator itr;
for (itr = fColumns.begin(); for (itr = fColumns.begin(); itr != fColumns.end(); ++itr)
itr != fColumns.end(); {
++itr) os << **itr << endl;
{ }
os << **itr << endl;
}
return os; return os;
} }
////////////////////////// //////////////////////////
@ -261,63 +224,52 @@ AtaDropColumns::~AtaDropColumns()
{ {
} }
AtaDropColumns::AtaDropColumns(ColumnNameList* columnNames) AtaDropColumns::AtaDropColumns(ColumnNameList* columnNames)
{ {
fColumns = *columnNames; fColumns = *columnNames;
delete columnNames; delete columnNames;
} }
std::ostream& AtaDropColumns::put(std::ostream& os) const std::ostream& AtaDropColumns::put(std::ostream& os) const
{ {
os << "Drop Columns: " << endl; os << "Drop Columns: " << endl;
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
for (itr = fColumns.begin(); for (itr = fColumns.begin(); itr != fColumns.end(); ++itr)
itr != fColumns.end(); {
++itr) os << *itr << endl;
{ }
os << *itr << endl;
}
return os; return os;
} }
AtaAddTableConstraint::AtaAddTableConstraint(TableConstraintDef* tableConstraint)
: fTableConstraint(tableConstraint)
AtaAddTableConstraint::AtaAddTableConstraint(TableConstraintDef* tableConstraint) :
fTableConstraint(tableConstraint)
{ {
} }
AtaAddTableConstraint::~AtaAddTableConstraint() AtaAddTableConstraint::~AtaAddTableConstraint()
{ {
delete fTableConstraint; delete fTableConstraint;
} }
std::ostream& AtaAddTableConstraint::put(std::ostream& os) const std::ostream& AtaAddTableConstraint::put(std::ostream& os) const
{ {
os << "Add Table Constraint:" << endl; os << "Add Table Constraint:" << endl;
os << *fTableConstraint << endl; os << *fTableConstraint << endl;
return os; 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 std::ostream& AtaDropTableConstraint::put(std::ostream& os) const
{ {
os << "Drop Table Constraint: " << fConstraintName; os << "Drop Table Constraint: " << fConstraintName;
return os; return os;
} }
} } // namespace ddlpackage

View File

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

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */ 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" #include "ddlpkg.h"
@ -27,35 +27,28 @@ namespace ddlpackage
{ {
using namespace std; using namespace std;
CreateIndexStatement::CreateIndexStatement(): CreateIndexStatement::CreateIndexStatement()
fIndexName(NULL), : fIndexName(NULL), fTableName(NULL), fColumnNames(), fUnique(false)
fTableName(NULL),
fColumnNames(),
fUnique(false)
{ {
} }
CreateIndexStatement::CreateIndexStatement(QualifiedName* indexName, QualifiedName* tableName, CreateIndexStatement::CreateIndexStatement(QualifiedName* indexName, QualifiedName* tableName,
ColumnNameList* columnNames, bool unique) : ColumnNameList* columnNames, bool unique)
fIndexName(indexName), : fIndexName(indexName), fTableName(tableName), fColumnNames(*columnNames), fUnique(unique)
fTableName(tableName),
fColumnNames(*columnNames),
fUnique(unique)
{ {
delete columnNames; delete columnNames;
} }
CreateIndexStatement::~CreateIndexStatement() CreateIndexStatement::~CreateIndexStatement()
{ {
delete fIndexName; delete fIndexName;
delete fTableName; delete fTableName;
} }
std::ostream& CreateIndexStatement::put(std::ostream& os) const std::ostream& CreateIndexStatement::put(std::ostream& os) const
{ {
os << "Create Index: " << *fIndexName << " on " << *fTableName os << "Create Index: " << *fIndexName << " on " << *fTableName << fColumnNames << endl;
<< fColumnNames << endl; return os;
return os;
} }
} } // namespace ddlpackage

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */ 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 #define DDLPKG_DLLEXPORT
#include "ddlpkg.h" #include "ddlpkg.h"
@ -29,23 +29,21 @@ using namespace std;
namespace ddlpackage namespace ddlpackage
{ {
DropPartitionStatement::DropPartitionStatement(QualifiedName* qualifiedName) : fTableName(qualifiedName)
DropPartitionStatement::DropPartitionStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName)
{ {
} }
ostream& DropPartitionStatement::put(ostream& os) const ostream& DropPartitionStatement::put(ostream& os) const
{ {
os << "Mark partitions out of service: " << *fTableName << endl; os << "Mark partitions out of service: " << *fTableName << endl;
os << " partitions: "; os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it; set<BRM::LogicalPartition>::const_iterator it;
for (it = fPartitions.begin(); it != fPartitions.end(); ++it) for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
os << (*it) << " "; os << (*it) << " ";
os << endl; os << endl;
return os; return os;
} }
} } // namespace ddlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */ 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 #define DDLPKG_DLLEXPORT
#include "ddlpkg.h" #include "ddlpkg.h"
@ -29,28 +29,26 @@ using namespace std;
namespace ddlpackage namespace ddlpackage
{ {
DropTableStatement::DropTableStatement(QualifiedName* qualifiedName, bool cascade)
DropTableStatement::DropTableStatement(QualifiedName* qualifiedName, bool cascade) : : fTableName(qualifiedName), fCascade(cascade)
fTableName(qualifiedName),
fCascade(cascade)
{ {
} }
ostream& DropTableStatement::put(ostream& os) const ostream& DropTableStatement::put(ostream& os) const
{ {
os << "Drop Table: " << *fTableName << " " << "C=" << fCascade << endl; os << "Drop Table: " << *fTableName << " "
return os; << "C=" << fCascade << endl;
return os;
} }
TruncTableStatement::TruncTableStatement(QualifiedName* qualifiedName) : TruncTableStatement::TruncTableStatement(QualifiedName* qualifiedName) : fTableName(qualifiedName)
fTableName(qualifiedName)
{ {
} }
ostream& TruncTableStatement::put(ostream& os) const ostream& TruncTableStatement::put(ostream& os) const
{ {
os << "Truncate Table: " << *fTableName << endl; os << "Truncate Table: " << *fTableName << endl;
return os; return os;
} }
} } // namespace ddlpackage

View File

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

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */ 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 #define DDLPKG_DLLEXPORT
#include "ddlpkg.h" #include "ddlpkg.h"
@ -29,23 +29,21 @@ using namespace std;
namespace ddlpackage namespace ddlpackage
{ {
MarkPartitionStatement::MarkPartitionStatement(QualifiedName* qualifiedName) : fTableName(qualifiedName)
MarkPartitionStatement::MarkPartitionStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName)
{ {
} }
ostream& MarkPartitionStatement::put(ostream& os) const ostream& MarkPartitionStatement::put(ostream& os) const
{ {
os << "Mark partition out of service: " << *fTableName; os << "Mark partition out of service: " << *fTableName;
os << " partitions: "; os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it; set<BRM::LogicalPartition>::const_iterator it;
for (it = fPartitions.begin(); it != fPartitions.end(); ++it) for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
os << (*it) << " "; os << (*it) << " ";
os << endl; os << endl;
return os; return os;
} }
} } // namespace ddlpackage

File diff suppressed because it is too large Load Diff

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */ 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 #define DDLPKG_DLLEXPORT
#include "ddlpkg.h" #include "ddlpkg.h"
@ -29,23 +29,21 @@ using namespace std;
namespace ddlpackage namespace ddlpackage
{ {
RestorePartitionStatement::RestorePartitionStatement(QualifiedName* qualifiedName) : fTableName(qualifiedName)
RestorePartitionStatement::RestorePartitionStatement(QualifiedName* qualifiedName) :
fTableName(qualifiedName)
{ {
} }
ostream& RestorePartitionStatement::put(ostream& os) const ostream& RestorePartitionStatement::put(ostream& os) const
{ {
os << "Mark partition out of service: " << *fTableName; os << "Mark partition out of service: " << *fTableName;
os << " partitions: "; os << " partitions: ";
set<BRM::LogicalPartition>::const_iterator it; set<BRM::LogicalPartition>::const_iterator it;
for (it = fPartitions.begin(); it != fPartitions.end(); ++it) for (it = fPartitions.begin(); it != fPartitions.end(); ++it)
os << (*it) << " "; os << (*it) << " ";
os << endl; os << endl;
return os; return os;
} }
} } // namespace ddlpackage

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */ 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 #define DDLPKG_DLLEXPORT
#include "ddlpkg.h" #include "ddlpkg.h"
@ -33,7 +33,7 @@ static uint32_t sessionID = 1;
SqlStatement::SqlStatement() SqlStatement::SqlStatement()
{ {
fSessionID = sessionID; fSessionID = sessionID;
} }
SqlStatement::~SqlStatement() SqlStatement::~SqlStatement()
@ -42,6 +42,6 @@ SqlStatement::~SqlStatement()
ostream& operator<<(ostream& os, const SqlStatement& stmt) 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. */ 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 #define DDLPKG_DLLEXPORT
#include "ddlpkg.h" #include "ddlpkg.h"
@ -29,35 +29,32 @@ namespace ddlpackage
{ {
using namespace std; using namespace std;
ostream& operator<<(ostream& os, const SqlStatementList& ssl) 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) for (itr = ssl.fList.begin(); itr != ssl.fList.end(); ++itr)
{ {
SqlStatement& stmt = **itr; SqlStatement& stmt = **itr;
os << stmt; os << stmt;
} }
return os; return os;
} }
void SqlStatementList::push_back(SqlStatement* v) void SqlStatementList::push_back(SqlStatement* v)
{ {
fList.push_back(v); fList.push_back(v);
} }
SqlStatementList::~SqlStatementList() SqlStatementList::~SqlStatementList()
{ {
vector<SqlStatement*>::iterator itr; vector<SqlStatement*>::iterator itr;
for (itr = fList.begin(); itr != fList.end(); ++itr) for (itr = fList.begin(); itr != fList.end(); ++itr)
{ {
delete *itr; delete *itr;
} }
} }
} } // namespace ddlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */ 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> #include <iostream>
#define DDLPKG_DLLEXPORT #define DDLPKG_DLLEXPORT
@ -30,293 +30,252 @@ namespace ddlpackage
{ {
using namespace std; using namespace std;
TableDef::~TableDef() TableDef::~TableDef()
{ {
{
ColumnDefList::iterator itr;
for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
{ {
ColumnDefList::iterator itr; delete *itr;
for (itr = fColumns.begin(); itr != fColumns.end(); itr++)
{
delete *itr;
}
} }
}
{
TableConstraintDefList::iterator itr;
for (itr = fConstraints.begin(); itr != fConstraints.end(); itr++)
{ {
TableConstraintDefList::iterator itr; delete *itr;
for (itr = fConstraints.begin(); itr != fConstraints.end(); itr++)
{
delete *itr;
}
} }
}
delete fQualifiedName; delete fQualifiedName;
} }
TableDef::TableDef(QualifiedName* name, TableElementList* elements, TableOptionMap* options)
TableDef::TableDef(QualifiedName* name, TableElementList* elements, TableOptionMap* options) : : fQualifiedName(name)
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; fColumns.push_back(column);
delete options;
} }
else
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); constraint = dynamic_cast<TableConstraintDef*>(*itr);
if (column) if (constraint)
{ {
fColumns.push_back(column); fConstraints.push_back(constraint);
} }
else
{
constraint = dynamic_cast<TableConstraintDef*>(*itr);
if (constraint)
{
fConstraints.push_back(constraint);
}
}
} }
}
delete elements; delete elements;
} }
/** \brief Put to ostream. */ /** \brief Put to ostream. */
ostream& operator<<(ostream& os, const TableDef& tableDef) ostream& operator<<(ostream& os, const TableDef& tableDef)
{ {
os << "CreateTable "; os << "CreateTable ";
if (tableDef.fQualifiedName->fSchema != "") if (tableDef.fQualifiedName->fSchema != "")
//cout << tableDef.fQualifiedName->fSchema << "."; // cout << tableDef.fQualifiedName->fSchema << ".";
os << tableDef.fQualifiedName->fName os << tableDef.fQualifiedName->fName << " " << tableDef.fConstraints.size() << " table constraints"
<< " " << tableDef.fConstraints.size() << endl;
<< " table constraints"
<< endl;
{
ColumnDefList::const_iterator itr;
for (itr = tableDef.fColumns.begin(); itr != tableDef.fColumns.end(); ++itr)
{ {
ColumnDefList::const_iterator itr; ColumnDef* col = *itr;
os << *col << endl;
for (itr = tableDef.fColumns.begin();
itr != tableDef.fColumns.end(); ++itr)
{
ColumnDef* col = *itr;
os << *col << endl;
}
} }
}
{
TableConstraintDefList::const_iterator itr;
for (itr = tableDef.fConstraints.begin(); itr != tableDef.fConstraints.end(); ++itr)
{ {
TableConstraintDefList::const_iterator itr; os << (**itr);
for (itr = tableDef.fConstraints.begin();
itr != tableDef.fConstraints.end();
++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; 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; oval = *oitr;
os << " " << oval.first << "=" << oval.second << endl;
for (oitr = tableDef.fOptions.begin();
oitr != tableDef.fOptions.end(); ++oitr)
{
oval = *oitr;
os << " " << oval.first << "=" << oval.second << endl;
}
} }
}
return os; return os;
} }
ostream& operator<<(ostream& os, const TableConstraintDef& constraint) ostream& operator<<(ostream& os, const TableConstraintDef& constraint)
{ {
return constraint.put(os); return constraint.put(os);
} }
std::ostream& TableConstraintDef::put(std::ostream& os) const 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() : TableConstraintDef::TableConstraintDef() : fConstraintType(DDL_INVALID_CONSTRAINT)
fConstraintType(DDL_INVALID_CONSTRAINT)
{ {
} }
TableCheckConstraintDef::TableCheckConstraintDef(const char* check) : TableCheckConstraintDef::TableCheckConstraintDef(const char* check)
TableConstraintDef(DDL_CHECK), : TableConstraintDef(DDL_CHECK), fCheck(check)
fCheck(check)
{ {
} }
std::ostream& TableCheckConstraintDef::put(std::ostream& os) const std::ostream& TableCheckConstraintDef::put(std::ostream& os) const
{ {
os << "Constraint: " os << "Constraint: " << ConstraintString[fConstraintType] << " ";
<< ConstraintString[fConstraintType] << " "; os << "\"" << fCheck << "\"";
os << "\"" << fCheck << "\""; os << endl;
os << endl;
return os; return os;
} }
TableUniqueConstraintDef::TableUniqueConstraintDef(ColumnNameList* columns)
TableUniqueConstraintDef::TableUniqueConstraintDef(ColumnNameList* columns) : : TableConstraintDef(DDL_UNIQUE), fColumnNameList(*columns)
TableConstraintDef(DDL_UNIQUE),
fColumnNameList(*columns)
{ {
delete columns; delete columns;
} }
std::ostream& TableUniqueConstraintDef::put(std::ostream& os) const std::ostream& TableUniqueConstraintDef::put(std::ostream& os) const
{ {
os << "Constraint: " os << "Constraint: " << fName << " " << ConstraintString[fConstraintType] << " ";
<< fName << " "
<< ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
os << "("; os << "(";
for (itr = fColumnNameList.begin(); for (itr = fColumnNameList.begin(); itr != fColumnNameList.end(); ++itr)
itr != fColumnNameList.end(); {
++itr) os << *itr << " ";
{ }
os << *itr << " ";
}
os << ")"; os << ")";
return os; return os;
} }
TablePrimaryKeyConstraintDef::TablePrimaryKeyConstraintDef(ColumnNameList* columns) : TablePrimaryKeyConstraintDef::TablePrimaryKeyConstraintDef(ColumnNameList* columns)
TableConstraintDef(DDL_PRIMARY_KEY), : TableConstraintDef(DDL_PRIMARY_KEY), fColumnNameList(*columns)
fColumnNameList(*columns)
{ {
delete columns; delete columns;
} }
std::ostream& TablePrimaryKeyConstraintDef::put(std::ostream& os) const std::ostream& TablePrimaryKeyConstraintDef::put(std::ostream& os) const
{ {
os << "Constraint: " os << "Constraint: " << fName << " " << ConstraintString[fConstraintType] << " ";
<< fName << " "
<< ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
os << "("; os << "(";
for (itr = fColumnNameList.begin(); for (itr = fColumnNameList.begin(); itr != fColumnNameList.end(); ++itr)
itr != fColumnNameList.end(); {
++itr) os << *itr << " ";
{ }
os << *itr << " ";
}
os << ")"; os << ")";
return os; return os;
} }
TableReferencesConstraintDef::TableReferencesConstraintDef TableReferencesConstraintDef::TableReferencesConstraintDef(ColumnNameList* columns, QualifiedName* tableName,
(ColumnNameList* columns, ColumnNameList* foreignColumns,
QualifiedName* tableName, DDL_MATCH_TYPE matchType,
ColumnNameList* foreignColumns, ReferentialAction* refAction)
DDL_MATCH_TYPE matchType, : TableConstraintDef(DDL_REFERENCES)
ReferentialAction* refAction) : , fColumns(*columns)
TableConstraintDef(DDL_REFERENCES), , fTableName(tableName)
fColumns(*columns), , fForeignColumns(*foreignColumns)
fTableName(tableName), , fMatchType(matchType)
fForeignColumns(*foreignColumns), , fRefAction(refAction)
fMatchType(matchType),
fRefAction(refAction)
{ {
delete columns; delete columns;
delete foreignColumns; delete foreignColumns;
} }
std::ostream& TableReferencesConstraintDef::put(std::ostream& os) const std::ostream& TableReferencesConstraintDef::put(std::ostream& os) const
{ {
os << "Constraint: " os << "Constraint: " << fName << " " << ConstraintString[fConstraintType] << " ";
<< fName << " "
<< ConstraintString[fConstraintType] << " ";
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
os << "lcols ("; os << "lcols (";
for (itr = fColumns.begin(); for (itr = fColumns.begin(); itr != fColumns.end(); ++itr)
itr != fColumns.end(); {
++itr) os << *itr << " ";
{ }
os << *itr << " ";
}
os << ")"; os << ")";
os << " ftable=" << *fTableName; os << " ftable=" << *fTableName;
os << " "; os << " ";
os << "fcols ("; os << "fcols (";
for (itr = fForeignColumns.begin(); for (itr = fForeignColumns.begin(); itr != fForeignColumns.end(); ++itr)
itr != fForeignColumns.end(); {
++itr) os << *itr << " ";
{ }
os << *itr << " ";
}
os << ")"; os << ")";
return os; return os;
} }
std::ostream& operator<<(std::ostream& os, const ColumnNameList& columnNames) std::ostream& operator<<(std::ostream& os, const ColumnNameList& columnNames)
{ {
ColumnNameList::const_iterator itr; ColumnNameList::const_iterator itr;
os << '('; os << '(';
for (itr = columnNames.begin(); for (itr = columnNames.begin(); itr != columnNames.end(); ++itr)
itr != columnNames.end(); {
++itr) os << *itr << " ";
{ }
os << *itr << " ";
}
os << ')'; os << ')';
return os; return os;
} }
TableReferencesConstraintDef::~TableReferencesConstraintDef() TableReferencesConstraintDef::~TableReferencesConstraintDef()
{ {
delete fTableName; delete fTableName;
delete fRefAction; 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 class AlterTableProcessor : public DDLPackageProcessor
{ {
public: public:
AlterTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {} AlterTableProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm)
/** @brief process an alter table statement {
* }
* @param alterTableStmt the AlterTableStatement /** @brief process an alter table statement
*/ *
EXPORT DDLResult processPackage(ddlpackage::AlterTableStatement& alterTableStmt); * @param alterTableStmt the AlterTableStatement
/** @brief add a physical column file */
* EXPORT DDLResult processPackage(ddlpackage::AlterTableStatement& alterTableStmt);
* @param result the result of the operation /** @brief add a physical column file
* @param addColumn the AtaAddColumn object *
* @param fTableName the QualifiedName of the table * @param result the result of the operation
*/ * @param addColumn the AtaAddColumn object
EXPORT void addColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result, * @param fTableName the QualifiedName of the table
ddlpackage::ColumnDef* columnDefPtr, */
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId); 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 /** @brief drop a column
* *
* @param result the result of the operation * @param result the result of the operation
* @param ataDropColumn the AtaDropColumn object * @param ataDropColumn the AtaDropColumn object
* @param fTableName the QualifiedName for the table * @param fTableName the QualifiedName for the table
*/ */
EXPORT void dropColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result, EXPORT void dropColumn(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumn& ataDropColumn, 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); ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief drop columns /** @brief change a table autoincrement via a comment
* *
* @param result the result of the operation * @param result the result of the operation
* @param ataDropColumns the AtaDropColumn object * @param ataTableComment the AtaTableComment object
* @param fTableName the QualifiedName for the table * @param fTableName the QualifiedName for the table
*/ */
EXPORT void dropColumns(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result, EXPORT void tableComment(uint32_t sessionID, execplan::CalpontSystemCatalog::SCN txnID, DDLResult& result,
ddlpackage::AtaDropColumns& ataDropColumns, ddlpackage::AtaTableComment& ataTableComment,
ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId ); ddlpackage::QualifiedName& fTableName, const uint64_t uniqueId);
/** @brief add table constraint std::string fTimeZone;
*
* @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 protected:
* void rollBackAlter(const std::string& error, BRM::TxnID txnID, int sessionId, DDLResult& result,
* @param result the result of the operation uint64_t uniqueId);
* @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:
private:
}; };
} //namespace ddlpackageprocessor } // namespace ddlpackageprocessor
#undef EXPORT #undef EXPORT

View File

@ -37,446 +37,451 @@ using namespace logging;
using namespace BRM; using namespace BRM;
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(
CreateIndexProcessor::DDLResult CreateIndexProcessor::processPackage(ddlpackage::CreateIndexStatement& createIndexStmt) ddlpackage::CreateIndexStatement& createIndexStmt)
{ {
/* /*
get OIDs for the list & tree files get OIDs for the list & tree files
commit the current transaction commit the current transaction
start a new transaction start a new transaction
create the index in the metadata create the index in the metadata
create the index on the WE create the index on the WE
end the transaction end the transaction
*/ */
SUMMARY_INFO("CreateIndexProcesssor::processPackage"); SUMMARY_INFO("CreateIndexProcesssor::processPackage");
DDLResult result; DDLResult result;
result.result = NO_ERROR; result.result = NO_ERROR;
DETAIL_INFO(createIndexStmt); DETAIL_INFO(createIndexStmt);
BRM::TxnID txnID; BRM::TxnID txnID;
txnID.id = fTxnid.id; txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid; txnID.valid = fTxnid.valid;
/*Check whether the table exists already. If not, it is assumed from primary key creating. /*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 This is based on the assumption that Front end is already error out if the user trys to
create index on non-existing table. */ create index on non-existing table. */
CalpontSystemCatalog::TableName tableName; CalpontSystemCatalog::TableName tableName;
tableName.schema = (createIndexStmt.fTableName)->fSchema; tableName.schema = (createIndexStmt.fTableName)->fSchema;
tableName.table = (createIndexStmt.fTableName)->fName; tableName.table = (createIndexStmt.fTableName)->fName;
CalpontSystemCatalog::ROPair roPair; CalpontSystemCatalog::ROPair roPair;
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog( createIndexStmt.fSessionID ); 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;
}
try
{
roPair = systemCatalogPtr->tableRID(tableName);
}
catch (exception& ex)
{
// store primary key name in fPKName
fPKName = createIndexStmt.fIndexName->fName; 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; 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; WriteEngine::WErrorCodes ec;
return string(msg + ec.errorString(error)); return string(msg + ec.errorString(error));
} }
CreateIndexProcessor::DDLResult CreateIndexProcessor::rollBackCreateIndex(const string& error,
CreateIndexProcessor::DDLResult CreateIndexProcessor::rollBackCreateIndex(const string& error, BRM::TxnID& txnID, int sessionId) BRM::TxnID& txnID, int sessionId)
{ {
cerr << "CreatetableProcessor::processPackage: " << error << endl; cerr << "CreatetableProcessor::processPackage: " << error << endl;
DETAIL_INFO(error); DETAIL_INFO(error);
logging::Message::Args args; logging::Message::Args args;
logging::Message message(1); logging::Message message(1);
args.add("Create Index Failed: "); args.add("Create Index Failed: ");
args.add( error ); args.add(error);
args.add(""); args.add("");
args.add(""); args.add("");
message.format( args ); message.format(args);
DDLResult result; DDLResult result;
result.result = CREATE_ERROR; result.result = CREATE_ERROR;
result.message = message; result.message = message;
rollBackIndex(txnID, sessionId); rollBackIndex(txnID, sessionId);
return result; return result;
} }
void CreateIndexProcessor::rollBackIndex(BRM::TxnID& txnID, int sessionId) void CreateIndexProcessor::rollBackIndex(BRM::TxnID& txnID, int sessionId)
{ {
fWriteEngine.rollbackTran(txnID.id, sessionId); fWriteEngine.rollbackTran(txnID.id, sessionId);
fWriteEngine.dropIndex(txnID.id, fIdxOID.listOID, fIdxOID.treeOID); fWriteEngine.dropIndex(txnID.id, fIdxOID.listOID, fIdxOID.treeOID);
try try
{ {
//execplan::ObjectIDManager fObjectIDManager; // execplan::ObjectIDManager fObjectIDManager;
//fObjectIDManager.returnOIDs(fIdxOID.treeOID, fIdxOID.listOID); // fObjectIDManager.returnOIDs(fIdxOID.treeOID, fIdxOID.listOID);
} }
catch ( exception& ex ) catch (exception& ex)
{ {
}
catch (...)
{
}
} fSessionManager.rolledback(txnID);
catch (... )
{ }
fSessionManager.rolledback(txnID);
} }
} // namespace ddlpackageprocessor
}

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -40,7 +40,6 @@
#include <boost/any.hpp> #include <boost/any.hpp>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include "joblistfactory.h" #include "joblistfactory.h"
namespace joblist namespace joblist
@ -50,253 +49,258 @@ class DistributedEngineComm;
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
/** @brief Populate an new Index /** @brief Populate an new Index
* implementation of a DDLPopulator * implementation of a DDLPopulator
*/ */
class DDLIndexPopulator 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 destructor
/** @brief constructor */
* virtual ~DDLIndexPopulator(){};
*/
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 Is it required to debug
*/
const bool isDebug(const DDLPackageProcessor::DebugLevel level) const
{
return level <= fDebugLevel;
}
/** @brief destructor /** @brief Get debug level
*/ */
virtual ~DDLIndexPopulator() { }; 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 DDLPackageProcessor::DDLResult getResult() const
*/ {
const bool isDebug( const DDLPackageProcessor::DebugLevel level ) 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;
} }
boost::any operator()(execplan::CalpontSystemCatalog::ColType& ctype)
/** @brief Get debug level
*/
const DDLPackageProcessor::DebugLevel getDebugLevel() const
{ {
return fDebugLevel; return ctype.getNullValueForType();
} }
const execplan::CalpontSystemCatalog::ColType& fType;
};
/** @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;
};
}; };
} } // namespace ddlpackageprocessor
#endif //DDLPINDEXPOPULATOR_H #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. */ 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 "ddlpackageprocessorfactory.h"
#include "ddlpackage.h" #include "ddlpackage.h"
#include "alterpackageprocessor.h" #include "alterpackageprocessor.h"
@ -30,29 +30,21 @@ using namespace ddlpackage;
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
DDLPackageProcessor* DDLPackageProcessorFactory::makePackageProcessor(int packageType,
DDLPackageProcessor* DDLPackageProcessorFactory:: ddlpackage::CalpontDDLPackage& cpackage)
makePackageProcessor(int packageType, ddlpackage::CalpontDDLPackage& cpackage)
{ {
DDLPackageProcessor* ddlProcPtr = 0; DDLPackageProcessor* ddlProcPtr = 0;
switch ( packageType ) switch (packageType)
{ {
case DDL_CREATE: case DDL_CREATE: ddlProcPtr = new CreatePackageProcessor(); break;
ddlProcPtr = new CreatePackageProcessor();
break;
case DDL_ALTER: case DDL_ALTER: ddlProcPtr = new AlterPackageProcessor(); break;
ddlProcPtr = new AlterPackageProcessor();
break;
case DDL_DROP: case DDL_DROP: ddlProcPtr = new DropPackageProcessor(); break;
ddlProcPtr = new DropPackageProcessor(); }
break;
} return ddlProcPtr;
return ddlProcPtr;
} }
} // namespace ddlpackageprocessor } // namespace ddlpackageprocessor

View File

@ -16,40 +16,33 @@
MA 02110-1301, USA. */ 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 */ /** @file */
#pragma once #pragma once
#include <string> #include <string>
#include "ddlpkg.h" #include "ddlpkg.h"
#include "ddlpackageprocessor.h" #include "ddlpackageprocessor.h"
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
/** @brief create a ddlPackageProcessor object from a CalpontddlPackage object /** @brief create a ddlPackageProcessor object from a CalpontddlPackage object
* *
*/ */
class DDLPackageProcessorFactory 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: protected:
private:
/** @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:
}; };
} } // namespace ddlpackageprocessor

View File

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

View File

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

View File

@ -37,344 +37,344 @@ using namespace oam;
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
DropPartitionProcessor::DDLResult DropPartitionProcessor::processPackage(
DropPartitionProcessor::DDLResult DropPartitionProcessor::processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt) ddlpackage::DropPartitionStatement& dropPartitionStmt)
{ {
SUMMARY_INFO("DropPartitionProcessor::processPackage"); SUMMARY_INFO("DropPartitionProcessor::processPackage");
DDLResult result; DDLResult result;
result.result = NO_ERROR; result.result = NO_ERROR;
std::string err; std::string err;
VERBOSE_INFO(dropPartitionStmt); VERBOSE_INFO(dropPartitionStmt);
// Commit current transaction. // Commit current transaction.
// all DDL statements cause an implicit commit // all DDL statements cause an implicit commit
VERBOSE_INFO("Getting current txnID"); VERBOSE_INFO("Getting current txnID");
int rc = 0; int rc = 0;
rc = fDbrm->isReadWrite(); rc = fDbrm->isReadWrite();
BRM::TxnID txnID; BRM::TxnID txnID;
txnID.id = fTxnid.id; txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid; 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; throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
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;
} }
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; for (unsigned i = 0; i < pmList.size(); i++)
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(); 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 try
{ {
//check table lock uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID,
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(dropPartitionStmt.fSessionID); (int32_t*)&txnID.id, BRM::LOADING);
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);
} }
catch (std::exception&) catch (std::exception&)
{ {
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID); // no need to release lock. dbrm un-hold the lock
return result; 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; 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 class DropPartitionProcessor : public DDLPackageProcessor
{ {
public: public:
DropPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {} DropPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm)
/** @brief process a drop table statement {
* }
* @param dropTableStmt the drop table statement /** @brief process a drop table statement
*/ *
EXPORT DDLResult processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt); * @param dropTableStmt the drop table statement
*/
protected: EXPORT DDLResult processPackage(ddlpackage::DropPartitionStatement& dropPartitionStmt);
private:
protected:
private:
}; };
} // namespace ddlpackageprocessor } // namespace ddlpackageprocessor
#undef EXPORT #undef EXPORT

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -34,264 +34,266 @@ using namespace oam;
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(
MarkPartitionProcessor::DDLResult MarkPartitionProcessor::processPackage(ddlpackage::MarkPartitionStatement& markPartitionStmt) ddlpackage::MarkPartitionStatement& markPartitionStmt)
{ {
SUMMARY_INFO("RestorePartitionProcessor::processPackage"); SUMMARY_INFO("RestorePartitionProcessor::processPackage");
DDLResult result; DDLResult result;
result.result = NO_ERROR; result.result = NO_ERROR;
std::string err; std::string err;
VERBOSE_INFO(markPartitionStmt); VERBOSE_INFO(markPartitionStmt);
BRM::TxnID txnID; BRM::TxnID txnID;
txnID.id = fTxnid.id; txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid; txnID.valid = fTxnid.valid;
int rc = 0; int rc = 0;
rc = fDbrm->isReadWrite(); 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; throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
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; int i = 0;
CalpontSystemCatalog::RIDList tableColRidList; processID = ::getpid();
CalpontSystemCatalog::DictOIDList dictOIDList; oam::OamCache* oamcache = OamCache::makeOamCache();
std::string processName("DDLProc"); std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
string stmt = markPartitionStmt.fSql + "|" + markPartitionStmt.fTableName->fSchema + "|"; for (unsigned i = 0; i < pmList.size(); i++)
SQLLogger logger(stmt, fDDLLoggingId, markPartitionStmt.fSessionID, txnID.id); {
pms.push_back((uint32_t)pmList[i]);
uint32_t processID = 0; }
uint64_t uniqueID = 0;
uint32_t sessionID = markPartitionStmt.fSessionID;
execplan::CalpontSystemCatalog::ROPair roPair;
try try
{ {
//check table lock uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID,
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(markPartitionStmt.fSessionID); (int32_t*)&txnID.id, BRM::LOADING);
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);
} }
catch (std::exception&) catch (std::exception&)
{ {
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; 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; 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 namespace ddlpackageprocessor
{ {
/** @brief specialization of a DDLPackageProcessor /** @brief specialization of a DDLPackageProcessor
* for interacting with the Write Engine * for interacting with the Write Engine
* to process create table ddl statements. * to process create table ddl statements.
*/ */
class MarkPartitionProcessor : public DDLPackageProcessor class MarkPartitionProcessor : public DDLPackageProcessor
{ {
public: public:
MarkPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {} MarkPartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm)
/** @brief process a create table statement {
* }
* @param createTableStmt the CreateTableStatement /** @brief process a create table statement
*/ *
EXPORT DDLResult processPackage(ddlpackage::MarkPartitionStatement& MarkPartitionStmt); * @param createTableStmt the CreateTableStatement
*/
protected: EXPORT DDLResult processPackage(ddlpackage::MarkPartitionStatement& MarkPartitionStmt);
private:
protected:
private:
}; };
} // namespace ddlpackageprocessor } // namespace ddlpackageprocessor
#undef EXPORT #undef EXPORT

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -34,263 +34,266 @@ using namespace WriteEngine;
namespace ddlpackageprocessor namespace ddlpackageprocessor
{ {
RestorePartitionProcessor::DDLResult RestorePartitionProcessor::processPackage(
RestorePartitionProcessor::DDLResult RestorePartitionProcessor::processPackage(ddlpackage::RestorePartitionStatement& restorePartitionStmt) ddlpackage::RestorePartitionStatement& restorePartitionStmt)
{ {
SUMMARY_INFO("RestorePartitionProcessor::processPackage"); SUMMARY_INFO("RestorePartitionProcessor::processPackage");
DDLResult result; DDLResult result;
result.result = NO_ERROR; result.result = NO_ERROR;
std::string err; std::string err;
VERBOSE_INFO(restorePartitionStmt); VERBOSE_INFO(restorePartitionStmt);
BRM::TxnID txnID; BRM::TxnID txnID;
txnID.id = fTxnid.id; txnID.id = fTxnid.id;
txnID.valid = fTxnid.valid; txnID.valid = fTxnid.valid;
int rc = 0; int rc = 0;
rc = fDbrm->isReadWrite(); 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; throw std::runtime_error("Drop partition cannot be operated on Calpont system catalog.");
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; int i = 0;
CalpontSystemCatalog::RIDList tableColRidList; processID = ::getpid();
CalpontSystemCatalog::DictOIDList dictOIDList; oam::OamCache* oamcache = oam::OamCache::makeOamCache();
std::string processName("DDLProc"); std::vector<int> pmList = oamcache->getModuleIds();
std::vector<uint32_t> pms;
string stmt = restorePartitionStmt.fSql + "|" + restorePartitionStmt.fTableName->fSchema + "|"; for (unsigned i = 0; i < pmList.size(); i++)
SQLLogger logger(stmt, fDDLLoggingId, restorePartitionStmt.fSessionID, txnID.id); {
pms.push_back((uint32_t)pmList[i]);
uint32_t processID = 0; }
uint64_t uniqueID = 0;
uint32_t sessionID = restorePartitionStmt.fSessionID;
execplan::CalpontSystemCatalog::ROPair roPair;
try try
{ {
//check table lock uniqueID = fDbrm->getTableLock(pms, roPair.objnum, &processName, &processID, (int32_t*)&sessionID,
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(restorePartitionStmt.fSessionID); (int32_t*)&txnID.id, BRM::LOADING);
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);
} }
catch (std::exception&) catch (std::exception&)
{ {
result.result = DROP_ERROR; result.result = DROP_ERROR;
result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE); result.message = IDBErrorInfo::instance()->errorMsg(ERR_HARD_FAILURE);
fSessionManager.rolledback(txnID); fSessionManager.rolledback(txnID);
return result; 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; 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 class RestorePartitionProcessor : public DDLPackageProcessor
{ {
public: public:
RestorePartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm) {} RestorePartitionProcessor(BRM::DBRM* aDbrm) : DDLPackageProcessor(aDbrm)
/** @brief process a drop table statement {
* }
* @param dropTableStmt the drop table statement /** @brief process a drop table statement
*/ *
EXPORT DDLResult processPackage(ddlpackage::RestorePartitionStatement& RestorePartitionStmt); * @param dropTableStmt the drop table statement
*/
protected: EXPORT DDLResult processPackage(ddlpackage::RestorePartitionStatement& RestorePartitionStmt);
private:
protected:
private:
}; };
} // namespace ddlpackageprocessor } // namespace ddlpackageprocessor
#undef EXPORT #undef EXPORT

File diff suppressed because it is too large Load Diff

View File

@ -46,183 +46,183 @@ namespace dmlpackage
{ {
boost::mutex CalpontDMLFactory::fParserLock; boost::mutex CalpontDMLFactory::fParserLock;
dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackage(dmlpackage::VendorDMLStatement& vpackage, dmlpackage::CalpontDMLPackage* CalpontDMLFactory::makeCalpontDMLPackage(
std::string defaultSchema /*= ""*/) 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(); parser.setDefaultSchema(defaultSchema);
//@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;
} }
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_UPDATE:
{ packagePtr = new UpdateDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(),
case DML_INSERT: vpackage.get_DMLStatement(), vpackage.get_SessionID());
packagePtr = new InsertDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID()); (void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer(), vpackage.get_Columns(),
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer vpackage.get_Rows());
(), vpackage.get_Columns(), vpackage.get_Rows()); break;
break;
case DML_UPDATE: case DML_DELETE:
packagePtr = new UpdateDMLPackage(vpackage.get_SchemaName(), packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(),
vpackage.get_TableName(), vpackage.get_DMLStatement(), vpackage.get_SessionID()); vpackage.get_DMLStatement(), vpackage.get_SessionID());
(void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer (void)packagePtr->buildFromBuffer(vpackage.get_DataBuffer(), vpackage.get_Columns(),
(), vpackage.get_Columns(), vpackage.get_Rows()); vpackage.get_Rows());
break; break;
case DML_DELETE: case DML_COMMAND:
packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(), packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID());
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: break;
packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID() );
break; default: cerr << "makeCalpontDMLPackage: invalid statement type" << endl; 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;
} }
}
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_COMMAND:
{ packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID());
case DML_INSERT: break;
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: case DML_DELETE:
packagePtr = new CommandDMLPackage(vpackage.get_DMLStatement(), vpackage.get_SessionID() ); packagePtr = new DeleteDMLPackage(vpackage.get_SchemaName(), vpackage.get_TableName(),
break; 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: default: cerr << "makeCalpontDMLPackage: invalid statement type" << endl; break;
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;
} }
}
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, CalpontDMLPackage* packagePtr =
vpackage.get_DMLStatement(), vpackage.get_SessionID() ); new UpdateDMLPackage((updateStmt.fNamePtr)->fSchema, (updateStmt.fNamePtr)->fName,
UpdateDMLPackage* updatePkgPtr = dynamic_cast<UpdateDMLPackage*>(packagePtr); vpackage.get_DMLStatement(), vpackage.get_SessionID());
updatePkgPtr->buildUpdateFromMysqlBuffer(updateStmt); UpdateDMLPackage* updatePkgPtr = dynamic_cast<UpdateDMLPackage*>(packagePtr);
packagePtr = dynamic_cast<CalpontDMLPackage*>(updatePkgPtr); updatePkgPtr->buildUpdateFromMysqlBuffer(updateStmt);
return packagePtr; packagePtr = dynamic_cast<CalpontDMLPackage*>(updatePkgPtr);
return packagePtr;
} }
} //namespace dmlpackage } // namespace dmlpackage

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */ 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 */ /** @file */
#pragma once #pragma once
@ -38,132 +38,128 @@
namespace dmlpackage namespace dmlpackage
{ {
/** @brief concrete implementation of a DMLObject /** @brief concrete implementation of a DMLObject
* Specifically for representing a database column * Specifically for representing a database column
*/ */
class DMLColumn : public DMLObject class DMLColumn : public DMLObject
{ {
public:
/** @brief ctor
*/
EXPORT DMLColumn();
public: /** @brief ctor
/** @brief ctor */
*/
EXPORT DMLColumn();
/** @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); EXPORT DMLColumn(std::string name, std::vector<std::string>& valueList, bool isFromCol = false,
/** @brief new ctor uint32_t funcScale = 0, bool isNULL = false);
* 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 ); /** @brief dtor
*/
EXPORT ~DMLColumn();
/** @brief dtor /** @brief read a DMLColumn from a ByteStream
*/ *
EXPORT ~DMLColumn(); * @param bytestream the ByteStream to read from
*/
EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief read a DMLColumn from a ByteStream /** @brief write a DML column to a ByteStream
* *
* @param bytestream the ByteStream to read from * @param bytestream the ByteStream to write to
*/ */
EXPORT int read(messageqcpp::ByteStream& bytestream); EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief write a DML column to a ByteStream /** @brief get the data for the column
* */
* @param bytestream the ByteStream to write to const std::string get_Data() const
*/ {
EXPORT int write(messageqcpp::ByteStream& bytestream); return fData;
}
/** @brief get the data for the column const std::vector<std::string>& get_DataVector() const
*/ {
const std::string get_Data() const return fColValuesList;
{ }
return fData;
}
/** @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 void set_DataVector(std::vector<std::string>& dataVec)
{ {
return fColValuesList; fColValuesList = dataVec;
} }
/** @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;
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 /** @brief a vector of DMLColumns
*/ */
typedef std::vector<DMLColumn*>ColumnList; typedef std::vector<DMLColumn*> ColumnList;
} } // namespace dmlpackage
#undef EXPORT #undef EXPORT

View File

@ -16,24 +16,20 @@
MA 02110-1301, USA. */ 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" #include "dmlobject.h"
namespace dmlpackage namespace dmlpackage
{ {
DMLObject::DMLObject() DMLObject::DMLObject()
{ {
} }
DMLObject::~DMLObject() DMLObject::~DMLObject()
{ {
} }
} // namespace dmlpackage } // namespace dmlpackage

View File

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

View File

@ -27,10 +27,9 @@
namespace dmlpackage 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 std::string nullValue = "nvl";
//const size_t maxThreads = 100; // const size_t maxThreads = 100;
//const size_t queueSize = 200; // const size_t queueSize = 200;
} // namespace dmlpackage } // namespace dmlpackage

View File

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

View File

@ -32,7 +32,6 @@ namespace dmlpackage
{ {
typedef std::vector<char*> valbuf_t; typedef std::vector<char*> valbuf_t;
typedef SqlStatementList ParseTree; typedef SqlStatementList ParseTree;
// instance data for the parser // instance data for the parser
@ -40,55 +39,54 @@ typedef std::vector<char*> valbuf_t;
struct scan_data struct scan_data
{ {
/* Handles to the buffer that the lexer uses internally */ /* Handles to the buffer that the lexer uses internally */
char* scanbuf; char* scanbuf;
void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp
valbuf_t valbuf; valbuf_t valbuf;
}; };
/** @brief BISON parser wrapper class /** @brief BISON parser wrapper class
*/ */
class DMLParser class DMLParser
{ {
public: public:
/** @brief ctor /** @brief ctor
*/ */
DMLParser(); DMLParser();
/** @brief dtor /** @brief dtor
*/ */
virtual ~DMLParser(); virtual ~DMLParser();
/** @brief parse the supplied dml statement /** @brief parse the supplied dml statement
* *
* @param dmltext the dml statement to parse * @param dmltext the dml statement to parse
*/ */
int parse(const char* dmltext); int parse(const char* dmltext);
/** @brief get the parse tree /** @brief get the parse tree
*/ */
const ParseTree& getParseTree(); const ParseTree& getParseTree();
void setDefaultSchema(std::string schema); void setDefaultSchema(std::string schema);
/** @brief was the parse successful /** @brief was the parse successful
*/ */
bool good(); bool good();
/** @brief put the parser in debug mode so as to dump /** @brief put the parser in debug mode so as to dump
* diagnostic information * diagnostic information
*/ */
void setDebug(bool debug); void setDebug(bool debug);
protected: protected:
ParseTree fParseTree; ParseTree fParseTree;
int fStatus; int fStatus;
bool fDebug; bool fDebug;
void* scanner; // yyscan_t * needed for re-entrant flex scanner void* scanner; // yyscan_t * needed for re-entrant flex scanner
scan_data scanData; scan_data scanData;
private:
private:
}; };
/** @brief specialization of the DMLParser class /** @brief specialization of the DMLParser class
@ -97,22 +95,21 @@ private:
*/ */
class DMLFileParser : public DMLParser class DMLFileParser : public DMLParser
{ {
public: public:
/** @brief ctor /** @brief ctor
*/ */
DMLFileParser(); DMLFileParser();
/** @brief parse the dml statement contained in the /** @brief parse the dml statement contained in the
* supplied file * supplied file
* *
* @param fileName the fully qualified file name to open * @param fileName the fully qualified file name to open
* and parse the contents of * and parse the contents of
*/ */
int parse(const std::string& fileName); int parse(const std::string& fileName);
protected: protected:
private:
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. */ 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" #include "dmltable.h"
using namespace std; using namespace std;
@ -27,93 +27,91 @@ using namespace std;
namespace dmlpackage namespace dmlpackage
{ {
DMLTable::DMLTable() DMLTable::DMLTable()
{} {
}
DMLTable::~DMLTable() DMLTable::~DMLTable()
{ {
try
{
RowList::iterator it = fRows.begin();
try while (it != fRows.end())
{ {
RowList::iterator it = fRows.begin(); delete *it;
it++;
while (it != fRows.end())
{
delete *it;
it++;
}
} }
catch (...) }
{ catch (...)
cout << "failed to delete the table rows" << endl; {
} cout << "failed to delete the table rows" << endl;
}
} }
int DMLTable::read(messageqcpp::ByteStream& bytestream) int DMLTable::read(messageqcpp::ByteStream& bytestream)
{ {
int retval = 1; int retval = 1;
// read the table name // read the table name
bytestream >> fName; bytestream >> fName;
// read the schema name // read the schema name
bytestream >> fSchema; bytestream >> fSchema;
messageqcpp::ByteStream::quadbyte rowNum; messageqcpp::ByteStream::quadbyte rowNum;
bytestream >> rowNum; bytestream >> rowNum;
for (unsigned int i = 0; i < rowNum; i++) for (unsigned int i = 0; i < rowNum; i++)
{ {
Row* aRow = new Row(); Row* aRow = new Row();
retval = aRow->read(bytestream); retval = aRow->read(bytestream);
fRows.push_back(aRow); fRows.push_back(aRow);
} }
return retval; return retval;
} }
void DMLTable::readMetaData(messageqcpp::ByteStream& bytestream) void DMLTable::readMetaData(messageqcpp::ByteStream& bytestream)
{ {
// read the table name // read the table name
bytestream >> fName; bytestream >> fName;
// read the schema name // read the schema name
bytestream >> fSchema; bytestream >> fSchema;
} }
void DMLTable::readRowData(messageqcpp::ByteStream& bytestream) void DMLTable::readRowData(messageqcpp::ByteStream& bytestream)
{ {
messageqcpp::ByteStream::quadbyte rowNum; messageqcpp::ByteStream::quadbyte rowNum;
bytestream >> rowNum; bytestream >> rowNum;
for (unsigned int i = 0; i < rowNum; i++) for (unsigned int i = 0; i < rowNum; i++)
{ {
Row* aRow = new Row(); Row* aRow = new Row();
aRow->read(bytestream); aRow->read(bytestream);
fRows.push_back(aRow); fRows.push_back(aRow);
} }
} }
int DMLTable::write(messageqcpp::ByteStream& bytestream) int DMLTable::write(messageqcpp::ByteStream& bytestream)
{ {
int retval = 1; int retval = 1;
//write table name and schma name to the bytestream // write table name and schma name to the bytestream
bytestream << fName; bytestream << fName;
bytestream << fSchema; bytestream << fSchema;
messageqcpp::ByteStream::quadbyte rowNum; messageqcpp::ByteStream::quadbyte rowNum;
rowNum = fRows.size(); rowNum = fRows.size();
bytestream << rowNum; bytestream << rowNum;
//write the row list // write the row list
RowList::iterator rowListPtr; RowList::iterator rowListPtr;
rowListPtr = fRows.begin(); rowListPtr = fRows.begin();
for (; rowListPtr != fRows.end(); ++rowListPtr) for (; rowListPtr != fRows.end(); ++rowListPtr)
{ {
retval = (*rowListPtr)->write(bytestream); retval = (*rowListPtr)->write(bytestream);
} }
return retval; return retval;
} }
} // namespace dmlpackage } // namespace dmlpackage

View File

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

View File

@ -32,52 +32,54 @@ using namespace dmlpackage;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
string sqlfile; string sqlfile;
int count; int count;
po::options_description desc ("Allowed options"); po::options_description desc("Allowed options");
desc.add_options () desc.add_options()("help", "produce help message")(
("help", "produce help message") "bisond",
("bisond", /* po::value <string>(),*/ "Have bison produce debug output") /* po::value <string>(),*/ "Have bison produce debug output")("count", po::value<int>(),
("count", po::value <int>(), "number of runs") "number of runs")("sql",
("sql", po::value < string > (), "sql file"); po::value<string>(),
po::variables_map vm; "sql file");
po::store (po::parse_command_line (argc, argv, desc), vm); po::variables_map vm;
po::notify (vm); po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count ("sql")) if (vm.count("sql"))
sqlfile = vm["sql"].as <string> (); sqlfile = vm["sql"].as<string>();
if (vm.count("count")) if (vm.count("count"))
count = vm["count"].as<int>(); count = vm["count"].as<int>();
DMLFileParser parser; DMLFileParser parser;
if (vm.count ("bisond")) if (vm.count("bisond"))
parser.setDebug(true); parser.setDebug(true);
parser.parse(sqlfile); parser.parse(sqlfile);
if (parser.good()) if (parser.good())
{ {
const ParseTree& ptree = parser.getParseTree(); const ParseTree& ptree = parser.getParseTree();
cout << "Parser succeeded." << endl; cout << "Parser succeeded." << endl;
cout << ptree.fList.size() << " " << "SQL statements" << endl; cout << ptree.fList.size() << " "
cout << ptree.fSqlText << endl; << "SQL statements" << endl;
cout << ptree; cout << ptree.fSqlText << endl;
cout << ptree;
SqlStatement* statementPtr = ptree[0]; SqlStatement* statementPtr = ptree[0];
if (statementPtr) if (statementPtr)
cout << statementPtr->getQueryString(); cout << statementPtr->getQueryString();
cout << endl; cout << endl;
} }
else else
{ {
cout << "Parser failed." << endl; 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 namespace dmlpackage
{ {
InsertDMLPackage::InsertDMLPackage() InsertDMLPackage::InsertDMLPackage()
{} {
}
InsertDMLPackage::InsertDMLPackage( std::string schemaName, std::string tableName, InsertDMLPackage::InsertDMLPackage(std::string schemaName, std::string tableName, std::string dmlStatement,
std::string dmlStatement, int sessionID ) int sessionID)
: CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID ) : CalpontDMLPackage(schemaName, tableName, dmlStatement, sessionID)
{} {
}
InsertDMLPackage::~InsertDMLPackage() InsertDMLPackage::~InsertDMLPackage()
{} {
}
int InsertDMLPackage::write(messageqcpp::ByteStream& bytestream) int InsertDMLPackage::write(messageqcpp::ByteStream& bytestream)
{ {
int retval = 1; int retval = 1;
messageqcpp::ByteStream::byte package_type = DML_INSERT; messageqcpp::ByteStream::byte package_type = DML_INSERT;
bytestream << package_type; bytestream << package_type;
messageqcpp::ByteStream::quadbyte session_id = fSessionID; messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id; bytestream << session_id;
bytestream << fUuid; bytestream << fUuid;
bytestream << fDMLStatement; bytestream << fDMLStatement;
bytestream << fDMLStatement; bytestream << fDMLStatement;
bytestream << fSchemaName; bytestream << fSchemaName;
bytestream << fTimeZone; bytestream << fTimeZone;
bytestream << (uint8_t)fLogging; bytestream << (uint8_t)fLogging;
bytestream << (uint8_t)fLogending; bytestream << (uint8_t)fLogending;
bytestream << fTableOid; bytestream << fTableOid;
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsInsertSelect); bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsInsertSelect);
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsBatchInsert); bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsBatchInsert);
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsCacheInsert); bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsCacheInsert);
bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsAutocommitOn); bytestream << static_cast<messageqcpp::ByteStream::byte>(fIsAutocommitOn);
if (fTable != 0) if (fTable != 0)
{ {
retval = fTable->write(bytestream); retval = fTable->write(bytestream);
} }
return retval; return retval;
} }
int InsertDMLPackage::read(messageqcpp::ByteStream& bytestream) int InsertDMLPackage::read(messageqcpp::ByteStream& bytestream)
{ {
int retval = 1; int retval = 1;
messageqcpp::ByteStream::quadbyte session_id; messageqcpp::ByteStream::quadbyte session_id;
bytestream >> session_id; bytestream >> session_id;
fSessionID = session_id; fSessionID = session_id;
bytestream >> fUuid; bytestream >> fUuid;
std::string dmlStatement; std::string dmlStatement;
bytestream >> fDMLStatement; bytestream >> fDMLStatement;
bytestream >> fSQLStatement; bytestream >> fSQLStatement;
bytestream >> fSchemaName; bytestream >> fSchemaName;
bytestream >> fTimeZone; bytestream >> fTimeZone;
uint8_t logging; uint8_t logging;
bytestream >> logging; bytestream >> logging;
fLogging = (logging != 0); fLogging = (logging != 0);
uint8_t logending; uint8_t logending;
bytestream >> logending; bytestream >> logending;
fLogending = (logending != 0); fLogending = (logending != 0);
bytestream >> fTableOid; bytestream >> fTableOid;
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsInsertSelect); bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsInsertSelect);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsBatchInsert); bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsBatchInsert);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsCacheInsert); bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsCacheInsert);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsAutocommitOn); bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsAutocommitOn);
fTable = new DMLTable(); fTable = new DMLTable();
retval = fTable->read(bytestream); retval = fTable->read(bytestream);
return retval; return retval;
} }
void InsertDMLPackage::readMetaData(messageqcpp::ByteStream& bytestream) void InsertDMLPackage::readMetaData(messageqcpp::ByteStream& bytestream)
{ {
messageqcpp::ByteStream::quadbyte session_id; messageqcpp::ByteStream::quadbyte session_id;
bytestream >> session_id; bytestream >> session_id;
fSessionID = session_id; fSessionID = session_id;
bytestream >> fUuid; bytestream >> fUuid;
std::string dmlStatement; std::string dmlStatement;
bytestream >> fDMLStatement; bytestream >> fDMLStatement;
bytestream >> fSQLStatement; bytestream >> fSQLStatement;
bytestream >> fSchemaName; bytestream >> fSchemaName;
bytestream >> fTimeZone; bytestream >> fTimeZone;
uint8_t logging; uint8_t logging;
bytestream >> logging; bytestream >> logging;
fLogging = (logging != 0); fLogging = (logging != 0);
uint8_t logending; uint8_t logending;
bytestream >> logending; bytestream >> logending;
fLogending = (logending != 0); fLogending = (logending != 0);
bytestream >> fTableOid; bytestream >> fTableOid;
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsInsertSelect); bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsInsertSelect);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsBatchInsert); bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsBatchInsert);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsCacheInsert); bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsCacheInsert);
bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsAutocommitOn); bytestream >> reinterpret_cast<messageqcpp::ByteStream::byte&>(fIsAutocommitOn);
fTable = new DMLTable(); fTable = new DMLTable();
fTable->readMetaData(bytestream); fTable->readMetaData(bytestream);
} }
// Has to be called after InsertDMLPackage::readMetaData() // Has to be called after InsertDMLPackage::readMetaData()
void InsertDMLPackage::readRowData(messageqcpp::ByteStream& bytestream) void InsertDMLPackage::readRowData(messageqcpp::ByteStream& bytestream)
{ {
fTable->readRowData(bytestream); fTable->readRowData(bytestream);
} }
int InsertDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows) int InsertDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows)
{ {
#ifdef DML_PACKAGE_DEBUG #ifdef DML_PACKAGE_DEBUG
// cout << "The data buffer received: " << buffer << endl; // cout << "The data buffer received: " << buffer << endl;
#endif #endif
int retval = 1; int retval = 1;
initializeTable(); initializeTable();
std::vector<std::string> dataList; std::vector<std::string> dataList;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer; typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(","); boost::char_separator<char> sep(",");
tokenizer tokens(buffer, sep); tokenizer tokens(buffer, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{ {
dataList.push_back(StripLeadingWhitespace(*tok_iter)); dataList.push_back(StripLeadingWhitespace(*tok_iter));
}
} int n = 0;
int n = 0; for (int i = 0; i < rows; i++)
{
for (int i = 0; i < rows; i++) // get a new row
{
//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();
Row* aRowPtr = new Row(); Row* aRowPtr = new Row();
std::string colName; std::string colName;
std::vector<std::string> colValList; std::string colValue;
for (int j = 0; j < columns; j++) for (int j = 0; j < columns; j++)
{ {
//Build a column list // Build a column list
colName = colNameList[j]; colName = dataList[n];
n++;
colValList = tableValuesMap[j]; colValue = dataList[n];
n++;
DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]); #ifdef DML_PACKAGE_DEBUG
(aRowPtr->get_ColumnList()).push_back(aColumn); // 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); 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 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) initializeTable();
throw runtime_error("insertStmt.fValuesOrQueryPtr == NULL"); bool isNULL = false;
initializeTable(); // only if we don't have a select statement
bool isNULL = false; if (0 == insertStmt.fValuesOrQueryPtr->fQuerySpecPtr)
{
ColumnNameList columnNameList = insertStmt.fColumnList;
// only if we don't have a select statement if (columnNameList.size())
if (0 == insertStmt.fValuesOrQueryPtr->fQuerySpecPtr)
{ {
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; for (unsigned int i = 0; i < columnNameList.size(); i++)
{
if (columnNameList.size() != valuesList.size()) DMLColumn* aColumn = new DMLColumn(columnNameList[i], valuesList[i], isNULL);
{ (aRow->get_ColumnList()).push_back(aColumn);
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);
}
fTable->get_RowList().push_back(aRow);
} }
else else
{ {
fHasFilter = true; ValuesList valuesList = insertStmt.fValuesOrQueryPtr->fValuesList;
fQueryString = insertStmt.getQueryString(); 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 } // namespace dmlpackage

View File

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

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */ 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" #include "mysqldmlstatement.h"
/** /**
@ -28,4 +28,3 @@
/** /**
* Methods * Methods
*/ */

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */ 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 */ /** @file */
#pragma once #pragma once
#include <string> #include <string>
@ -32,14 +32,12 @@ namespace dmlpackage
*/ */
class MySQLDMLStatement : public VendorDMLStatement class MySQLDMLStatement : public VendorDMLStatement
{ {
public:
MySQLDMLStatement() : VendorDMLStatement("", 0)
{
}
public: protected:
MySQLDMLStatement() : VendorDMLStatement("", 0) {} private:
protected:
private:
}; };
} } // namespace dmlpackage

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */ 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" #include "oracledmlstatement.h"
/** /**
@ -28,5 +28,3 @@
/** /**
* Methods * Methods
*/ */

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */ 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 */ /** @file */
#pragma once #pragma once
@ -33,14 +33,12 @@ namespace dmlpackage
*/ */
class OracleDMLStatement : public VendorDMLStatement class OracleDMLStatement : public VendorDMLStatement
{ {
public:
OracleDMLStatement() : VendorDMLStatement("", 0)
{
}
public: protected:
OracleDMLStatement() : VendorDMLStatement("", 0) {} private:
protected:
private:
}; };
} } // namespace dmlpackage

View File

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

View File

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

View File

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

View File

@ -32,129 +32,130 @@ using namespace std;
namespace dmlpackage namespace dmlpackage
{ {
UpdateDMLPackage::UpdateDMLPackage() UpdateDMLPackage::UpdateDMLPackage()
{} {
}
UpdateDMLPackage::UpdateDMLPackage(std::string schemaName, std::string tableName, UpdateDMLPackage::UpdateDMLPackage(std::string schemaName, std::string tableName, std::string dmlStatement,
std::string dmlStatement, int sessionID) int sessionID)
: CalpontDMLPackage( schemaName, tableName, dmlStatement, sessionID) : CalpontDMLPackage(schemaName, tableName, dmlStatement, sessionID)
{} {
}
UpdateDMLPackage::~UpdateDMLPackage() UpdateDMLPackage::~UpdateDMLPackage()
{} {
}
int UpdateDMLPackage::write(messageqcpp::ByteStream& bytestream) int UpdateDMLPackage::write(messageqcpp::ByteStream& bytestream)
{ {
int retval = 1; int retval = 1;
messageqcpp::ByteStream::byte package_type = DML_UPDATE; messageqcpp::ByteStream::byte package_type = DML_UPDATE;
bytestream << package_type; bytestream << package_type;
messageqcpp::ByteStream::quadbyte session_id = fSessionID; messageqcpp::ByteStream::quadbyte session_id = fSessionID;
bytestream << session_id; bytestream << session_id;
/* /*
if(fPlan != 0) if(fPlan != 0)
fHasFilter = true; fHasFilter = true;
else else
fHasFilter = false; fHasFilter = false;
*/ */
messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter; messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter;
bytestream << hasFilter; bytestream << hasFilter;
bytestream << fUuid; bytestream << fUuid;
bytestream << fDMLStatement; bytestream << fDMLStatement;
bytestream << fSQLStatement; bytestream << fSQLStatement;
bytestream << fSchemaName; bytestream << fSchemaName;
bytestream << fTimeZone; bytestream << fTimeZone;
bytestream << (uint8_t)fIsFromCol; bytestream << (uint8_t)fIsFromCol;
if (fTable != 0) if (fTable != 0)
{ {
retval = fTable->write(bytestream); retval = fTable->write(bytestream);
} }
if (fHasFilter) if (fHasFilter)
{ {
bytestream += *(fPlan.get()); bytestream += *(fPlan.get());
} }
return retval; return retval;
} }
/** /**
* *
*/ */
int UpdateDMLPackage::read(messageqcpp::ByteStream& bytestream) int UpdateDMLPackage::read(messageqcpp::ByteStream& bytestream)
{ {
int retval = 1; int retval = 1;
messageqcpp::ByteStream::quadbyte session_id; messageqcpp::ByteStream::quadbyte session_id;
messageqcpp::ByteStream::quadbyte hasFilter; messageqcpp::ByteStream::quadbyte hasFilter;
bytestream >> session_id; bytestream >> session_id;
fSessionID = session_id; fSessionID = session_id;
bytestream >> hasFilter; bytestream >> hasFilter;
fHasFilter = (hasFilter != 0); fHasFilter = (hasFilter != 0);
bytestream >> fUuid; bytestream >> fUuid;
std::string dmlStatement; std::string dmlStatement;
bytestream >> fDMLStatement; bytestream >> fDMLStatement;
bytestream >> fSQLStatement; bytestream >> fSQLStatement;
bytestream >> fSchemaName; bytestream >> fSchemaName;
bytestream >> fTimeZone; bytestream >> fTimeZone;
uint8_t isFromCol; uint8_t isFromCol;
bytestream >> isFromCol; bytestream >> isFromCol;
fIsFromCol = (isFromCol != 0); fIsFromCol = (isFromCol != 0);
fTable = new DMLTable(); fTable = new DMLTable();
retval = fTable->read(bytestream); retval = fTable->read(bytestream);
if (fHasFilter) if (fHasFilter)
{ {
fPlan.reset(new messageqcpp::ByteStream(bytestream)); fPlan.reset(new messageqcpp::ByteStream(bytestream));
} }
return retval; return retval;
} }
int UpdateDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement) 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) initializeTable();
throw runtime_error("updateStmt.fColAssignmentPtr == NULL");
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. while (iter != updateStmt.fColAssignmentListPtr->end())
Row* rowPtr = new Row(); {
ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin(); ColumnAssignment* colaPtr = *iter;
DMLColumn* colPtr = new DMLColumn(colaPtr->fColumn, colaPtr->fScalarExpression);
rowPtr->get_ColumnList().push_back(colPtr);
while (iter != updateStmt.fColAssignmentListPtr->end()) ++iter;
{ }
ColumnAssignment* colaPtr = *iter;
DMLColumn* colPtr = new DMLColumn(colaPtr->fColumn, colaPtr->fScalarExpression);
rowPtr->get_ColumnList().push_back(colPtr);
++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) return retval;
{
// We need to filter the rows...get row ids
fHasFilter = true;
fQueryString = updateStmt.getQueryString();
}
return retval;
} }
/** /**
@ -163,109 +164,108 @@ int UpdateDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
int UpdateDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows) int UpdateDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows)
{ {
#ifdef DML_PACKAGE_DEBUG #ifdef DML_PACKAGE_DEBUG
//cout << "The data buffer received: " << buffer << endl; // cout << "The data buffer received: " << buffer << endl;
#endif #endif
int retval = 1; int retval = 1;
initializeTable(); initializeTable();
std::vector<std::string> dataList; std::vector<std::string> dataList;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer; typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(":,"); boost::char_separator<char> sep(":,");
tokenizer tokens(buffer, sep); tokenizer tokens(buffer, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
{ {
dataList.push_back(StripLeadingWhitespace(*tok_iter)); dataList.push_back(StripLeadingWhitespace(*tok_iter));
}
} int n = 0;
int n = 0; for (int i = 0; i < rows; i++)
{
for (int i = 0; i < rows; i++) // get a new row
{
//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();
Row* aRowPtr = new Row(); Row* aRowPtr = new Row();
std::string colName; 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++) for (int j = 0; j < columns; j++)
{ {
//Build a column list // Build a column list
colName = colNameList[j]; 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]); DMLColumn* aColumn = new DMLColumn(colName, colValue);
(aRowPtr->get_ColumnList()).push_back(aColumn); (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); 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) initializeTable();
throw runtime_error("updateStmt.fColAssignmentPtr == NULL"); 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. DMLColumn* aColumn = new DMLColumn(colName, colValList, false, 0, nullValues[j]);
Row* rowPtr = new Row(); (aRowPtr->get_ColumnList()).push_back(aColumn);
ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin(); }
while (iter != updateStmt.fColAssignmentListPtr->end()) // build a row list for a table
{ fTable->get_RowList().push_back(aRowPtr);
ColumnAssignment* colaPtr = *iter; return retval;
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
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 class UpdateDMLPackage : public CalpontDMLPackage
{ {
public:
/** @brief ctor
*/
EXPORT UpdateDMLPackage();
public: /** @brief ctor
/** @brief ctor *
*/ * @param schemaName the schema of the table being operated on
EXPORT UpdateDMLPackage(); * @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 /** @brief dtor
* */
* @param schemaName the schema of the table being operated on EXPORT virtual ~UpdateDMLPackage();
* @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 /** @brief write a UpdateDMLPackage to a ByteStream
*/ *
EXPORT virtual ~UpdateDMLPackage(); * @param bytestream the ByteStream to write to
*/
EXPORT int write(messageqcpp::ByteStream& bytestream);
/** @brief write a UpdateDMLPackage to a ByteStream /** @brief read a UpdateDMLPackage from a ByteStream
* *
* @param bytestream the ByteStream to write to * @param bytestream the ByteStream to read from
*/ */
EXPORT int write(messageqcpp::ByteStream& bytestream); EXPORT int read(messageqcpp::ByteStream& bytestream);
/** @brief read a UpdateDMLPackage from a ByteStream /** @brief build a UpdateDMLPackage from a string buffer
* *
* @param bytestream the ByteStream to read from * @param buffer
*/ * @param columns the number of columns in the buffer
EXPORT int read(messageqcpp::ByteStream& bytestream); * @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 /** @brief build a UpdateDMLPackage from a parsed UpdateSqlStatement
* *
* @param buffer * @param sqlStatement the parsed UpdateSqlStatement
* @param columns the number of columns in the buffer */
* @param rows the number of rows in the buffer EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement);
*/
EXPORT int buildFromBuffer(std::string& buffer, int columns, int rows);
/** @brief build a UpdateDMLPackage from a parsed UpdateSqlStatement /** @brief build a InsertDMLPackage from MySQL buffer
* *
* @param sqlStatement the parsed UpdateSqlStatement * @param colNameList, tableValuesMap
*/ * @param rows the number of rows in the buffer
EXPORT int buildFromSqlStatement(SqlStatement& sqlStatement); */
EXPORT int buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap, int columns,
/** @brief build a InsertDMLPackage from MySQL buffer int rows, NullValuesBitset& nullValues);
* void buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStmt);
* @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:
protected:
private:
}; };
} } // namespace dmlpackage
#undef EXPORT #undef EXPORT

View File

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

View File

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

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