NABoolean SchemaName::matchDefaultPublicSchema()
{
  if (schemaName_.isNull())
    return TRUE;

  NABoolean matched = FALSE;

  // get default schema
  NAString defCat;
  NAString defSch;
  ActiveSchemaDB()->getDefaults().getCatalogAndSchema(defCat, defSch);
  ToInternalIdentifier(defCat);
  ToInternalIdentifier(defSch);

  // get public schema
  NAString publicSchema = ActiveSchemaDB()->getDefaults().getValue(PUBLIC_SCHEMA_NAME);
  ComSchemaName pubSchema(publicSchema);
  NAString pubCat = pubSchema.getCatalogNamePart().getInternalName();
  NAString pubSch = pubSchema.getSchemaNamePart().getInternalName();

  // if catalog was not specified
  NAString catName = (catalogName_.isNull()? defCat:catalogName_);
  pubCat = (pubCat.isNull()? defCat:pubCat);

  if (((catName==defCat) && (schemaName_==defSch)) ||
      ((catName==pubCat) && (schemaName_==pubSch)))
    matched = TRUE;

  return matched;
}
Example #2
0
// change literals of a cacheable query into ConstantParameters 
RelExpr* GenericUpdate::normalizeForCache(CacheWA& cwa, BindWA& bindWA)
{
  if (nodeIsNormalizedForCache()) { 
    return this; 
  }
  if (cwa.getPhase() >= CmpMain::BIND) {
    if (currOfCursorName_) {
      // do NOT parameterize the assignment clause(s) of positioned updates
      // because "update t051t22 set b = -1 where current of c1" in esqlc
      // program such as core/etest051.sql generates an assertion clause:
      // "...if_then_else(b= :hv0),return_true,return_true(raiserror())"
      // (see BindItemExpr.cpp Scan::bindUpdateCurrentOf) as part of
      // GenericUpdate::bindNode. Otherwise, the result is an error 8106.
      // The root cause is incomplete parameterization -- the update 
      // becomes "update t051t22 set b = 0-? where current of c1" but 
      // "...if_then_else(b= :hv0),return_true,return_true(raiserror())"
      // is untouched causing an error 8106 at runtime.
    }
    else {
      if (newRecExprTree_) {
        newRecExprTree_->normalizeForCache(cwa, bindWA);
      }
      else {
        newRecExpr_.normalizeForCache(cwa, bindWA);
      }
      // parameterize "set on rollback" clause for queries such as
      //   prepare s from select * from (update t042qT8 set b=7 
      //   set on rollback c=2 where a=2) as t;
      newRecBeforeExpr_.normalizeForCache(cwa, bindWA); 
    }
    if (executorPredTree_) {
      executorPredTree_->normalizeForCache(cwa, bindWA);
    }
    else {
      executorPred_.normalizeForCache(cwa, bindWA);
    }
  }

  // Solution: 10-060327-5370 and 10-060418-5903
  // Record the context-wide isolation_level_for_updates value in 
  // CacheWA when procssing an IDU stmt. Use ISOLATION_LEVEL_FOR_UPDATES 
  // if it is specified. Otherwise, use ISOLATION_LEVEL. The initial value
  // in cwa is IL_NOT_SPECIFIED_.
  if ( cwa.getIsoLvlForUpdates() == TransMode::IL_NOT_SPECIFIED_ ) {
    TransMode::IsolationLevel il;

    ActiveSchemaDB()->getDefaults().getIsolationLevel (il,
         CmpCommon::getDefault(ISOLATION_LEVEL_FOR_UPDATES));

    if ( il == TransMode::IL_NOT_SPECIFIED_ ) {
       ActiveSchemaDB()->getDefaults().getIsolationLevel (il,
            CmpCommon::getDefault(ISOLATION_LEVEL));
    }
    cwa.setIsoLvlForUpdates(il);
  }

  // replace descendants' literals into ConstantParameters
  return RelExpr::normalizeForCache(cwa, bindWA);
}
/************************************************************************
method CompilerTrackingInfo::resetMetadataCacheCounters

  Mark the current values for hits and lookups so we can
  subtract from the total on the next interval

************************************************************************/
void
CompilerTrackingInfo::resetMetadataCacheCounters()
{
  mdCacheHits_    = ActiveSchemaDB()->getNATableDB()->hits();
  mdCacheLookups_ = ActiveSchemaDB()->getNATableDB()->lookups();

  ActiveSchemaDB()->getNATableDB()->resetIntervalWaterMark();
}
Example #4
0
void HSTableDef::setNATable()
  {
    //BindWA bindWA(ActiveSchemaDB(), CmpCommon::context(), FALSE, getIsNativeHbaseOrHive());
    BindWA bindWA(ActiveSchemaDB(), CmpCommon::context(), FALSE, 
                  HSGlobalsClass::isNativeCat(*catalog_));

    CorrName corrName(*object_, STMTHEAP, *schema_, *catalog_);
    if (isVolatile())
      corrName.setIsVolatile(TRUE);
    Scan scan(corrName, NULL, REL_SCAN, STMTHEAP);
    ULng32 flagToSet = 0;  // don't turn on flag unless next 'if' is true
    if (CmpCommon::context()->sqlSession()->volatileSchemaInUse())
      flagToSet = ALLOW_VOLATILE_SCHEMA_IN_TABLE_NAME;

    // set ALLOW_VOLATILE_SCHEMA_IN_TABLE_NAME bit in Sql_ParserFlags
    // if needed, and return it to its entry value on exit
    PushAndSetSqlParserFlags savedParserFlags(flagToSet);

    scan.bindNode(&bindWA);
    if (!bindWA.errStatus())
      {
        naTbl_ = bindWA.getNATable(corrName);
        HS_ASSERT(naTbl_);
        objectType_ = naTbl_->getObjectType();
      }
  }
Int32
NAClusterInfo::numOfSMPs()
{
  Int32 result = cpuArray_.entries();

  // This is temporary patch for PARALLEL_NUM_ESPS issue. This CQD should
  // be used in many places for costing, NodeMap allocation, synthesizing
  // physProperties and so on. But currently it is used only in
  // RelRoot::createContextForAChild() creating lots of discrepansies in 
  // the code. Sept. 2006

  // Get the value as a token code, no errmsg if not a keyword.
  if ( (CmpCommon::getDefault(COMP_BOOL_136) == DF_ON) AND
       (CmpCommon::getDefault(PARALLEL_NUM_ESPS, 0) != DF_SYSTEM)
     )
  {
    // -------------------------------------------------------------------
    // A value for PARALLEL_NUM_ESPS exists.  Use it for the count of cpus
    //  but don't exceed the number of cpus available in the cluster.
    // -------------------------------------------------------------------
    result = MINOF(result, 
        (Int32)(ActiveSchemaDB()->getDefaults().getAsLong(PARALLEL_NUM_ESPS)));
  }

  return result; 

} // NAClusterInfo::numOfSMPs()  
void StmtModule::applyModuleCatalogSchema(const NAString& cat, 
                                          const NAString& sch)
{
  // apply moduleCatalog if necessary
  if (name().getCatalogName().isNull()) {
    if (!cat.isNull())
      name().setCatalogName(cat);
  }

  // apply moduleSchema if necessary
  if (name().getSchemaName().isNull()) {
    if (!sch.isNull())
      name().setSchemaName(sch);
  }

  // module catalog & schema must be non-null now. Otherwise, a fatal
  // exception can occur in mxsqlc/mxsqlco in
  //   mod_def::setModule() --> mod_def::outputModule()
  //   --> StmtModule::unparseSimple() --> 
  //   QualifiedName::getQualifiedNameAsAnsiString() -->
  //   QualifiedName::getQualifiedNameAsString() -->
  //   CMPASSERT(NOT getSchemaName().isNull());
  // as reported in genesis case 10-030708-8735.
  if (name().getCatalogName().isNull() || name().getSchemaName().isNull()) {
    const SchemaName& defcs =
      ActiveSchemaDB()->getDefaultSchema(
        SchemaDB::REFRESH_CACHE | SchemaDB::FORCE_ANSI_NAMETYPE);
    if (name().getCatalogName().isNull())
      name().setCatalogName(defcs.getCatalogName());
    if (name().getSchemaName().isNull())
      name().setSchemaName(defcs.getSchemaName());
  }
}
Example #7
0
NABoolean NARoutineCacheStatsISPIterator::getNext(NARoutineCacheStats & stats)
{
   //Only for remote tdm_arkcmp with 0 context
   if(currCacheIndex_ == -1)
   {
     ActiveSchemaDB()->getNARoutineDB()->getCacheStats(stats);
     currCacheIndex_ = -2;
     return TRUE;
   }
   
   //fetch QueryCaches of all CmpContexts with name equal to contextName_
   if(currCacheIndex_ > -1 && currCacheIndex_ < ctxInfos_.entries())
   {
      if( !ctxInfos_[currCacheIndex_]->isSameClass(contextName_.data()) //current context name is not equal to contextName_
       && contextName_.compareTo("ALL", NAString::exact)!=0) //and contextName_ is not "ALL"
      {// go to next context in ctxInfos_
          currCacheIndex_++;
          return getNext(stats);
      }
      ctxInfos_[currCacheIndex_++]->getCmpContext()->getSchemaDB()->getNARoutineDB()->getCacheStats(stats);
      return TRUE;
   }
   //all entries of all caches are fetched, we are done!
   return FALSE;
}
Example #8
0
// Note: When this method is used during query cache lookup (actually the 
// verification step), this belongs to the item in the bucket that matches
// the key, and other is the selectivity computed for an equal-predicate 
// constant in the query to be looked up. 
//
// This method is called to verify that this and other are not different
// very much.
//
// We return TRUE iff 
//  this.val_ / (1+delta)  <= other.val_ <= this.val_ * (1 + delta)
//
// where delta is 
//    the value stored in QUERY_CACHE_SELECTIVITY_TOLERANCE
//
NABoolean Selectivity::operator==(const Selectivity& other) const
{
  CostScalar delta = 
    CostScalar((ActiveSchemaDB()->getDefaults()).getAsDouble(QUERY_CACHE_SELECTIVITY_TOLERANCE)) + 1;

  return (val_ / delta <= other.val_) && (other.val_ <= val_ * delta);
}
ExScratchFileOptions *genScratchFileOptions(Generator *generator)
{
  Space *space = generator->getSpace();
  ExScratchFileOptions *result = new(space) ExScratchFileOptions;

  // ---------------------------------------------------------------------
  // Compile the defaults table entries into internal format
  // ---------------------------------------------------------------------

  NAString sDisks;
  NAString xDisks;
  NAString pDisks;
  enum DefaultConstants sEnum;
  enum DefaultConstants xEnum;
  enum DefaultConstants pEnum;
  const char *sDefaultName;
  const char *xDefaultName;
  const char *pDefaultName;

  // use two different sets of defaults, dependent on the platform

  sEnum = SCRATCH_DRIVE_LETTERS;
  xEnum = SCRATCH_DRIVE_LETTERS_EXCLUDED;
  pEnum = SCRATCH_DRIVE_LETTERS_PREFERRED;
  sDefaultName = "SCRATCH_DRIVE_LETTERS";
  xDefaultName = "SCRATCH_DRIVE_LETTERS_EXCLUDED";
  pDefaultName = "SCRATCH_DRIVE_LETTERS_PREFERRED";
 
  // look up defaults
  CmpCommon::getDefault(sEnum,sDisks,0);
  CmpCommon::getDefault(xEnum,xDisks,0);
  CmpCommon::getDefault(pEnum,pDisks,0);

  // convert into executor structures and give warnings for syntax errors
  Lng32 numEntries;
  ExScratchDiskDrive *l;

  l = genScratchDriveList(
       sDisks, numEntries, generator, sDefaultName);
  result->setSpecifiedScratchDisks(l,numEntries);

  l = genScratchDriveList(
       xDisks, numEntries, generator, xDefaultName);
  result->setExcludedScratchDisks(l,numEntries);

  l = genScratchDriveList(
       pDisks, numEntries, generator, pDefaultName);
  result->setPreferredScratchDisks(l,numEntries);

  NADefaults &defs = ActiveSchemaDB()->getDefaults(); 
  result->setScratchMgmtOption((Lng32)defs.getAsULong(SCRATCH_MGMT_OPTION));
  result->setScratchMaxOpensHash((Lng32)defs.getAsULong(SCRATCH_MAX_OPENS_HASH));
  result->setScratchMaxOpensSort((Lng32)defs.getAsULong(SCRATCH_MAX_OPENS_SORT));
  if(CmpCommon::getDefault(SCRATCH_PREALLOCATE_EXTENTS) == DF_ON)
    result->setScratchPreallocateExtents(TRUE);
  if(CmpCommon::getDefault(SCRATCH_DISK_LOGGING) == DF_ON)
    result->setScratchDiskLogging(TRUE);
  return result;
}
Example #10
0
TransMode * CmpCommon::transMode()
{
  TransMode& transMode = cmpCurrentContext->getTransMode();

  if (transMode.isolationLevel() == TransMode::IL_NOT_SPECIFIED_ &&
      ActiveSchemaDB())
    {
      // First time in, *after* CmpCommon/CmpContext/SchemaDB has been init'd
      // (Genesis 10-990224-2929); cf. SchemaDB::initPerStatement for more info.
      // Get current NADefaults setting of ISOLATION_LEVEL --
      // if invalid, use Ansi default of serializable -- then set our global.
      ActiveSchemaDB()->getDefaults().
        getIsolationLevel(transMode.isolationLevel());
      CMPASSERT(transMode.isolationLevel() != TransMode::IL_NOT_SPECIFIED_);
    }
  return &(cmpCurrentContext->getTransMode());
}
/************************************************************************
 * reset the class attribute for a new interval value
************************************************************************/
void
CompilerTrackingInfo::resetIntervalIfNeeded()
{
      Lng32 currentInterval =
           ActiveSchemaDB()->getDefaults().getAsLong(COMPILER_TRACKING_INTERVAL);

      if ((0 == prevInterval_) && (0 < currentInterval))
           resetInterval();           
}
Example #12
0
double CmpCommon::getDefaultNumeric(DefaultConstants id)
{
  float result;

  if (!ActiveSchemaDB()->getDefaults().getFloat(id, result))
    { CMPASSERT("CmpCommon::getDefaultNumeric()" == NULL); }

  return result;
}
// *****************************************************************************
// *                                                                           *
// * Function: dropOneTable                                                    *
// *                                                                           *
// *    Drops a table and all its dependent objects.                           *
// *                                                                           *
// *****************************************************************************
// *                                                                           *
// *  Parameters:                                                              *
// *                                                                           *
// *  <cliInterface>                  ExeCliInterface &               In       *
// *    is a reference to an Executor CLI interface handle.                    *
// *                                                                           *
// *  <catalogName>                   const char *                    In       *
// *    is the catalog of the table to drop.                                   *
// *                                                                           *
// *  <schemaName>                    const char *                    In       *
// *    is the schema of the table to drop.                                    *
// *                                                                           *
// *  <objectName>                    const char *                    In       *
// *    is the name of the table to drop.                                      *
// *                                                                           *
// *  <isVolatile>                    bool                            In       *
// *    is true if the object is volatile or part of a volatile schema.        *
// *                                                                           *
// *****************************************************************************
// *                                                                           *
// * Returns: bool                                                             *
// *                                                                           *
// * true: Could not drop table or one of its dependent objects.               *
// * false: Drop successful or could not set CQD for NATable cache reload.     *
// *                                                                           *
// *****************************************************************************
static bool dropOneTable(
   ExeCliInterface & cliInterface,
   const char * catalogName, 
   const char * schemaName, 
   const char * objectName,
   bool isVolatile)
   
{

char buf [1000];

bool someObjectsCouldNotBeDropped = false;

char volatileString[20] = {0};
Lng32 cliRC = 0;

   if (isVolatile)
      strcpy(volatileString,"VOLATILE");

   if (ComIsTrafodionExternalSchemaName(schemaName))
     str_sprintf(buf,"DROP EXTERNAL TABLE \"%s\" FOR \"%s\".\"%s\".\"%s\" CASCADE",
                 objectName,catalogName,schemaName,objectName);
   else
     str_sprintf(buf,"DROP %s TABLE \"%s\".\"%s\".\"%s\" CASCADE",
                 volatileString,catalogName,schemaName,objectName);
 
ULng32 savedParserFlags = Get_SqlParser_Flags(0xFFFFFFFF);

   try
   {            
      Set_SqlParser_Flags(INTERNAL_QUERY_FROM_EXEUTIL);
               
      cliRC = cliInterface.executeImmediate(buf);
   }
   catch (...)
   {
      // Restore parser flags settings to what they originally were
      Assign_SqlParser_Flags(savedParserFlags);
      
      throw;
   }
   
// Restore parser flags settings to what they originally were
   Set_SqlParser_Flags(INTERNAL_QUERY_FROM_EXEUTIL);
   
   if (cliRC < 0 && cliRC != -CAT_OBJECT_DOES_NOT_EXIST_IN_TRAFODION)
      someObjectsCouldNotBeDropped = true;
   
// remove NATable entry for this table
   CorrName cn(objectName,STMTHEAP,schemaName,catalogName);

   ActiveSchemaDB()->getNATableDB()->removeNATable(cn,
     NATableDB::REMOVE_FROM_ALL_USERS, COM_BASE_TABLE_OBJECT);

   return someObjectsCouldNotBeDropped;
   
}
/************************************************************************
 getCompilerTrackingLogFilename

 helper to get the filename from defaults

************************************************************************/
static
const char* 
getCompilerTrackingLogFilename()
{  
  const char * fname = ActiveSchemaDB()->getDefaults().
		 getValue(COMPILER_TRACKING_LOGFILE);
    
  return (*fname && stricmp(fname,"NONE") != 0) ? fname : NULL;
}
void CompilationStats::takeSnapshotOfCounters()
{      
  // metadata cache counters start point
  mdCacheHitsBegin_    = ActiveSchemaDB()->getNATableDB()->hits(); 
  mdCacheLookupsBegin_ = ActiveSchemaDB()->getNATableDB()->lookups();

  // histogram cache counters start point
  if (CURRCONTEXT_HISTCACHE)
  {
    hCacheHitsBegin_    = CURRCONTEXT_HISTCACHE->hits();
    hCacheLookupsBegin_ = CURRCONTEXT_HISTCACHE->lookups();
  }
    
  // get a snapshot of the QueryCacheStats prior to the compilation
  // this will be used to determine the qCacheStatus_ at the end  
  CURRENTQCACHE->getCompilationCacheStats(qCacheStatsBegin_);

  compileInfo_[0] = '\0';
}
Example #16
0
SP_STATUS NARoutineCacheStatStoredProcedure::sp_ProcessAction(
  SP_PROCESS_ACTION action,
  SP_ROW_DATA inputData,
  SP_EXTRACT_FUNCPTR eFunc,
  SP_ROW_DATA outputData,
  SP_FORMAT_FUNCPTR fFunc,
  SP_KEY_VALUE keys,
  SP_KEYVALUE_FUNCPTR kFunc,
  SP_PROCESS_HANDLE *spProcHandle,
  SP_HANDLE spObj,
  SP_ERROR_STRUCT *error)
{
  struct InfoStruct
  {
    ULng32 counter;
  };

  SP_STATUS status = SP_SUCCESS;
  InfoStruct *is = NULL;

  NARoutineDB * tableDB = ActiveSchemaDB()->getNARoutineActionDB();

  switch (action)
  {
  case SP_PROC_OPEN:
    is = new InfoStruct;
    is->counter = 0;
    *spProcHandle = is;
    break;

  case SP_PROC_FETCH:
    is = (InfoStruct*)(*spProcHandle);
    if (is == NULL )
    {
      status = SP_FAIL;
      break;
    }

    if (is->counter > 0) break;
    is->counter++;
    fFunc(0, outputData, sizeof(ULng32), &(tableDB->totalLookupsCount_), 0);
    fFunc(1, outputData, sizeof(ULng32), &(tableDB->totalCacheHits_), 0);
    fFunc(2, outputData, sizeof(ULng32), &(tableDB->entries_), 0);
    fFunc(3, outputData, sizeof(ULng32), &(tableDB->currentCacheSize_), 0);
    fFunc(4, outputData, sizeof(ULng32), &(tableDB->highWatermarkCache_), 0);
    fFunc(5, outputData, sizeof(ULng32), &(tableDB->maxCacheSize_), 0);
    status = SP_MOREDATA;
    break;

  case SP_PROC_CLOSE:
    delete (InfoStruct*) (*spProcHandle);
    break;
  }
  return status;
}
Example #17
0
void CmpCommon::applyDefaults(ComObjectName &nam)
{
  CMPASSERT(nam.isValid());
  if (nam.getCatalogNamePart().isEmpty()) {

    NAString dcat, dsch;
    ActiveSchemaDB()->getDefaults().getCatalogAndSchema(dcat, dsch);

    if (nam.getSchemaNamePart().isEmpty())
      nam.setSchemaNamePart(ComAnsiNamePart(dsch,CmpCommon::statementHeap()));
    nam.setCatalogNamePart(ComAnsiNamePart(dcat,CmpCommon::statementHeap()));
  }
}
// Returns total number of CPUs (including down CPUs)
Lng32 NAClusterInfo::getTotalNumberOfCPUs()
{
  Lng32 cpuCount = cpuArray_.entries();

#ifndef NDEBUG
  if ( inTestMode() ) {
    NADefaults & defs = ActiveSchemaDB()->getDefaults();
    cpuCount = (Int32)(defs.getAsLong(POS_TEST_NUM_NODES));
  }
#endif
  // 
  return cpuCount;
}
Example #19
0
// this method is temp
CostScalar MultiJoin::getChildrenDataFlow() const
{
  CostScalar childrenDataFlow(0);

  UInt32 minRecordLength = (ActiveSchemaDB()->getDefaults())\
                                       .getAsLong(COMP_INT_50);
  Int32 arity = getArity();
  for (Int32 i = 0; i < arity; i++)
  {
    childrenDataFlow +=
      child(i)->getGroupAttr()->getResultCardinalityForEmptyInput() *
      MAXOF(child(i)->getGroupAttr()->getRecordLength(), minRecordLength);
  }

  return childrenDataFlow;
}
CmpStatement::ReturnStatus
CmpStatement::process(const CmpMessageEnvs& envMessage)
{
  switch(envMessage.getOperator())
    {
    case CmpMessageEnvs::EXGLOBALS :
      {
        envs()->setEnv(envMessage.envs(), envMessage.nEnvs());

	envs()->chdir(envMessage.cwd());
        // call CLI to set the transId
        Int64 transid = (envMessage.activeTrans()) ? 
          envMessage.transId() : Int64(-1);

	const char * env; 

	env = getenv("SQLMX_REGRESS");
	if (env) 
	{ 
	  context_->setSqlmxRegress(atoi(env));

	  // turn mode_special_1 OFF during regressions run. 
	  // Special1 features cause
	  // many regressions to return mismatches due to special TD semantics.
	  // When some
	  // of the special1 features are externalized and enabled for general
	  // NEO users, then we can remove these lines. 
	  NAString value("OFF");
	  ActiveSchemaDB()->getDefaults().validateAndInsert(
	       "MODE_SPECIAL_1", value, FALSE);
	}

      }			  
      break;
    case CmpMessageEnvs::UNSETENV:
      envs()->unsetEnv(*(envMessage.envs()));
      break;
    default:
      break;
    } // end of switch(env_message.operator())

  return CmpStatement_SUCCESS;
}
ExScratchFileOptions *genScratchFileOptions(Generator *generator)
{
  Space *space = generator->getSpace();
  ExScratchFileOptions *result = new(space) ExScratchFileOptions;

  // ---------------------------------------------------------------------
  // Compile the defaults table entries into internal format
  // ---------------------------------------------------------------------

  NAString sDirs;
  
  enum DefaultConstants sEnum;
  
  const char *sDefaultName;
  
  sEnum = SCRATCH_DIRS;
  sDefaultName = "SCRATCH_DIRS";
 
  // look up defaults
  CmpCommon::getDefault(sEnum,sDirs,0);
  
  // convert into executor structures and give warnings for syntax errors
  Lng32 numEntries;
  ExScratchDiskDrive *l;

  l = genScratchDisks(sDirs, numEntries, generator, sDefaultName);
  result->setSpecifiedScratchDirs(l,numEntries);
 
  NADefaults &defs = ActiveSchemaDB()->getDefaults(); 
  result->setScratchMgmtOption((Lng32)defs.getAsULong(SCRATCH_MGMT_OPTION));
  result->setScratchMaxOpensHash((Lng32)defs.getAsULong(SCRATCH_MAX_OPENS_HASH));
  result->setScratchMaxOpensSort((Lng32)defs.getAsULong(SCRATCH_MAX_OPENS_SORT));
  if(CmpCommon::getDefault(SCRATCH_PREALLOCATE_EXTENTS) == DF_ON)
    result->setScratchPreallocateExtents(TRUE);
  if(CmpCommon::getDefault(SCRATCH_DISK_LOGGING) == DF_ON)
    result->setScratchDiskLogging(TRUE);
  return result;
}
///////////////////////////////////////////////////////////////////
// This function takes as input an array of key values, where each
// key value is in ASCII string format (the way it is stored in
// catalogs). It encodes the key values and returns the encoded
// value in the encodedKeyBuffer. 
// RETURNS: -1, if error. 0, if all Ok.
///////////////////////////////////////////////////////////////////
short encodeKeyValues(desc_struct   * column_descs,
		      desc_struct   * key_descs,
		      NAString      * inValuesArray[],          // INPUT
                      NABoolean isIndex,
		      char * encodedKeyBuffer,                  // OUTPUT
                      CollHeap * h,
		      ComDiagsArea * diagsArea)
{
  short error = 0;       // assume all will go well
  NABoolean deleteLater = FALSE;

  // set up binder/generator stuff so expressions could be generated.
  InitSchemaDB();
  CmpStatement cmpStatement(CmpCommon::context());
  ActiveSchemaDB()->createStmtTables();
  BindWA       bindWA(ActiveSchemaDB(), CmpCommon::context());
  Generator    generator(CmpCommon::context());
  ExpGenerator expGen(&generator);
  generator.appendAtEnd(); // alloc a new map table
  generator.setBindWA(&bindWA);
  generator.setExpGenerator(&expGen);
  FragmentDir * compFragDir = generator.getFragmentDir();

  // create the fragment (independent code space) for this expression
  CollIndex myFragmentId = compFragDir->pushFragment(FragmentDir::MASTER);
  
  // space where RCB will be generated
  Space * space = generator.getSpace();

  // Let's start with a list of size 4 rather than resizing continuously
  ValueIdList encodedValueIdList(4);
  desc_struct * column = column_descs;
  desc_struct * key    = key_descs;
  Int32 i = 0;

  if (inValuesArray == NULL)
    deleteLater = TRUE;

  while (key)
    {
      // for an index, keys_desc has columns in the same order as columns_desc,
      // the following for loop is not needed.
      if (!isIndex) {
      column = column_descs;
      for (Int32 j = 0; j < key->body.keys_desc.tablecolnumber; j++)
	column = column->header.next;
      }

      if (inValuesArray[i] == NULL)
	inValuesArray[i] = getMinMaxValue(column, key, FALSE, h);
      
      ItemExpr * itemExpr = buildEncodeTree(column, key, inValuesArray[i],
					    &generator, diagsArea);
      if (! itemExpr)
	return -1;

      encodedValueIdList.insert(itemExpr->getValueId());
      
      i++;
      key = key->header.next;
      if (isIndex)
        column = column->header.next;
    }
  
  // allocate a work cri desc to encode keys. It has
  // 3 entries: 0, for consts. 1, for temps. 
  // 2, for the encoded key.
  ex_cri_desc * workCriDesc = new(space) ex_cri_desc(3, space);
  short keyAtpIndex   = 2;  // where the encoded key will be built
  
  ULng32 encodedKeyLen;
  ex_expr * keExpr = 0;
  expGen.generateContiguousMoveExpr(encodedValueIdList,
				    0 /*don't add conv nodes*/,
				    0 /*atp*/, keyAtpIndex,
				    ExpTupleDesc::SQLMX_KEY_FORMAT,
				    encodedKeyLen,
				    &keExpr);

  // create a DP2 expression and initialize it with the key encode expr.
  ExpDP2Expr * keyEncodeExpr = new(space) ExpDP2Expr(keExpr,
						     workCriDesc,
						     space);
  
  keyEncodeExpr->getExpr()->fixup(0,expGen.getPCodeMode(), 
                                  (ex_tcb *)space,space, h, FALSE, NULL);

  atp_struct * workAtp = keyEncodeExpr->getWorkAtp();
  workAtp->getTupp(keyAtpIndex).setDataPointer(encodedKeyBuffer);
  
  if (keyEncodeExpr->getExpr()->eval(workAtp, 0, space) == ex_expr::EXPR_ERROR)
    error = -1;

  if (deleteLater)
    delete [] inValuesArray;

  generator.removeAll(NULL);

  return error;
}
Example #23
0
short
PhysicalFastExtract::codeGen(Generator *generator)
{
  short result = 0;
  Space *space = generator->getSpace();
  CmpContext *cmpContext = generator->currentCmpContext();

  const ULng32 downQueueMaxSize = getDefault(GEN_FE_SIZE_DOWN);
  const ULng32 upQueueMaxSize = getDefault(GEN_FE_SIZE_UP);


  const ULng32 defaultBufferSize = getDefault(GEN_FE_BUFFER_SIZE);
  const ULng32 outputBufferSize = defaultBufferSize;
  const ULng32 requestBufferSize = defaultBufferSize;
  const ULng32 replyBufferSize = defaultBufferSize;
  const ULng32 numOutputBuffers = getDefault(GEN_FE_NUM_BUFFERS);

  // used in runtime stats
  Cardinality estimatedRowCount = (Cardinality)
                       (getInputCardinality() * getEstRowsUsed()).getValue();

  Int32 numChildren = getArity();
  ex_cri_desc * givenDesc = generator->getCriDesc(Generator::DOWN);
  ComTdb * childTdb = (ComTdb*) new (space) ComTdb();
  ExplainTuple *firstExplainTuple = 0;

  // Allocate a new map table for this child.
  //
  MapTable *localMapTable = generator->appendAtEnd();
  generator->setCriDesc(givenDesc, Generator::DOWN);
  child(0)->codeGen(generator);
  childTdb = (ComTdb *)(generator->getGenObj());
  firstExplainTuple = generator->getExplainTuple();

  ComTdbFastExtract *newTdb = NULL;
  char * targetName = NULL;
  char * hiveTableName = NULL;
  char * delimiter = NULL;
  char * header = NULL;
  char * nullString = NULL;
  char * recordSeparator = NULL;
  char * hdfsHostName = NULL;
  Int32 hdfsPortNum = getHdfsPort();

  char * newDelimiter = (char *)getDelimiter().data();
  char specChar = '0';
  if (!isHiveInsert() && isSpecialChar(newDelimiter, specChar))
  {
    newDelimiter = new (cmpContext->statementHeap()) char[2];
    newDelimiter[0] = specChar;
    newDelimiter[1] = '\0';
  }

  char * newRecordSep = (char *)getRecordSeparator().data();
  specChar = '0';
  if (!isHiveInsert() && isSpecialChar(newRecordSep, specChar))
  {
    newRecordSep = new (cmpContext->statementHeap()) char[2];
    newRecordSep[0] = specChar;
    newRecordSep[1] = '\0';
  }

  targetName = AllocStringInSpace(*space, (char *)getTargetName().data());
  hdfsHostName = AllocStringInSpace(*space, (char *)getHdfsHostName().data());
  hiveTableName = AllocStringInSpace(*space, (char *)getHiveTableName().data());
  delimiter = AllocStringInSpace(*space,  newDelimiter);
  header = AllocStringInSpace(*space, (char *)getHeader().data());
  nullString = AllocStringInSpace(*space, (char *)getNullString().data());
  recordSeparator = AllocStringInSpace(*space, newRecordSep);

   result = ft_codegen(generator,
                       *this,              // RelExpr &relExpr
                       newTdb,             // ComTdbUdr *&newTdb
                       estimatedRowCount,
                       targetName,
                       hdfsHostName,
                       hdfsPortNum,
                       hiveTableName,
                       delimiter,
                       header,
                       nullString,
                       recordSeparator,
                       downQueueMaxSize,
                       upQueueMaxSize,
                       outputBufferSize,
                       requestBufferSize,
                       replyBufferSize,
                       numOutputBuffers,
                       childTdb,
                       isSequenceFile());

  if (!generator->explainDisabled())
  {
    generator->setExplainTuple(addExplainInfo(newTdb, firstExplainTuple, 0, generator));
  }

  if (getTargetType() == FILE)
    newTdb->setTargetFile(1);
  else if (getTargetType() == SOCKET)
    newTdb->setTargetSocket(1);
  else
  GenAssert(0, "Unexpected Fast Extract target type")

  if (isAppend())
    newTdb->setIsAppend(1);
  if (this->includeHeader())
    newTdb->setIncludeHeader(1);

  if (isHiveInsert())
  {
    newTdb->setIsHiveInsert(1);
    newTdb->setIncludeHeader(0);
    setOverwriteHiveTable( getOverwriteHiveTable());
  }
  else
  {
    if (includeHeader())
      newTdb->setIncludeHeader(1);
  }
  if (getCompressionType() != NONE)
  {
    if (getCompressionType() == LZO)
      newTdb->setCompressLZO(1);
    else
    GenAssert(0, "Unexpected Fast Extract compression type")
  }
     if((ActiveSchemaDB()->getDefaults()).getToken(FAST_EXTRACT_DIAGS) == DF_ON)
    	 newTdb->setPrintDiags(1);

  return result;
}
Example #24
0
static short ft_codegen(Generator *generator,
                        RelExpr &relExpr,
                        ComTdbFastExtract *&newTdb,
                        Cardinality estimatedRowCount,
                        char * targetName,
                        char * hdfsHost,
                        Int32 hdfsPort,
                        char * hiveTableName,
                        char * delimiter,
                        char * header,
                        char * nullString,
                        char * recordSeparator,
                        ULng32 downQueueMaxSize,
                        ULng32 upQueueMaxSize,
                        ULng32 outputBufferSize,
                        ULng32 requestBufferSize,
                        ULng32 replyBufferSize,
                        ULng32 numOutputBuffers,
                        ComTdb * childTdb,
                        NABoolean isSequenceFile)
{
  CmpContext *cmpContext = generator->currentCmpContext();
  Space *space = generator->getSpace();
  ExpGenerator *exp_gen = generator->getExpGenerator();
  MapTable *map_table = generator->getMapTable();
  MapTable *last_map_table = generator->getLastMapTable();
  ex_expr *input_expr = NULL;
  ex_expr *output_expr = NULL;
  ex_expr * childData_expr = NULL ;
  ex_expr * cnvChildData_expr = NULL ;
  ULng32 i;
  ULng32 requestRowLen = 0;
  ULng32 outputRowLen = 0;
  ULng32 childDataRowLen = 0;
  ULng32 cnvChildDataRowLen = 0;
  ExpTupleDesc *requestTupleDesc = NULL;

  ExpTupleDesc *outputTupleDesc = NULL;
  ExpTupleDesc *childDataTupleDesc = NULL;
  ExpTupleDesc *cnvChildDataTupleDesc = NULL;
  newTdb = NULL;

  OperatorTypeEnum relExprType = relExpr.getOperatorType();
  GenAssert(relExprType == REL_FAST_EXTRACT, "Unexpected RelExpr at FastExtract codegen")
  FastExtract * fastExtract = (FastExtract *) &relExpr;

  const Int32 workAtpNumber = 1;
  ex_cri_desc *given_desc = generator->getCriDesc(Generator::DOWN);
  ex_cri_desc *returned_desc = NULL;
  ex_cri_desc *work_cri_desc = NULL;

  returned_desc = given_desc;

  // Setup local variables related to the work ATP
  unsigned short numWorkTupps = 0;
  unsigned short childDataTuppIndex = 0;
  unsigned short cnvChildDataTuppIndex = 0;

  numWorkTupps = 3;
  childDataTuppIndex = numWorkTupps - 1 ;
  numWorkTupps ++;
  cnvChildDataTuppIndex = numWorkTupps - 1;
  work_cri_desc = new (space) ex_cri_desc(numWorkTupps, space);

  ExpTupleDesc::TupleDataFormat childReqFormat = ExpTupleDesc::SQLMX_ALIGNED_FORMAT;

  ValueIdList childDataVids;
  ValueIdList cnvChildDataVids;
  const ValueIdList& childVals = fastExtract->getSelectList();

  for (i = 0; i < childVals.entries(); i++)
  {
    ItemExpr &inputExpr = *(childVals[i].getItemExpr());
    const NAType &formalType = childVals[i].getType();
    ItemExpr *lmExpr = NULL;
    ItemExpr *lmExpr2 = NULL;
    int res;

    lmExpr = &inputExpr; //CreateCastExpr(inputExpr, *inputExpr.getValueId().getType().newCopy(), cmpContext);

    res = CreateAllCharsExpr(formalType, // [IN] Child output type
        *lmExpr, // [IN] Actual input value
        cmpContext, // [IN] Compilation context
        lmExpr2 // [OUT] Returned expression
        );

    GenAssert(res == 0 && lmExpr != NULL,
        "Error building expression tree for LM child Input value");

    lmExpr->bindNode(generator->getBindWA());
    childDataVids.insert(lmExpr->getValueId());
    if (lmExpr2)
    {
      lmExpr2->bindNode(generator->getBindWA());
      cnvChildDataVids.insert(lmExpr2->getValueId());
    }


  } // for (i = 0; i < childVals.entries(); i++)

  if (childDataVids.entries() > 0 &&
    cnvChildDataVids.entries()>0)  //-- convertedChildDataVids
  {
    exp_gen->generateContiguousMoveExpr (
      childDataVids,                         //childDataVids// [IN] source ValueIds
      TRUE,                                 // [IN] add convert nodes?
      workAtpNumber,                        // [IN] target atp number (0 or 1)
      childDataTuppIndex,                   // [IN] target tupp index
      childReqFormat,                       // [IN] target tuple data format
      childDataRowLen,                      // [OUT] target tuple length
      &childData_expr,                  // [OUT] move expression
      &childDataTupleDesc,                  // [optional OUT] target tuple desc
      ExpTupleDesc::LONG_FORMAT             // [optional IN] target desc format
      );

    exp_gen->processValIdList (
       cnvChildDataVids,                              // [IN] ValueIdList
       ExpTupleDesc::SQLARK_EXPLODED_FORMAT,  // [IN] tuple data format
       cnvChildDataRowLen,                          // [OUT] tuple length
       workAtpNumber,                                     // [IN] atp number
       cnvChildDataTuppIndex,         // [IN] index into atp
       &cnvChildDataTupleDesc,                      // [optional OUT] tuple desc
       ExpTupleDesc::LONG_FORMAT              // [optional IN] tuple desc format
       );
  }
  //
  // Add the tuple descriptor for request values to the work ATP
  //
  work_cri_desc->setTupleDescriptor(childDataTuppIndex, childDataTupleDesc);
  work_cri_desc->setTupleDescriptor(cnvChildDataTuppIndex, cnvChildDataTupleDesc);

  // We can now remove all appended map tables
  generator->removeAll(last_map_table);



  ComSInt32 maxrs = 0;
  UInt32 flags = 0;
  UInt16 numIoBuffers = (UInt16)(ActiveSchemaDB()->getDefaults()).getAsLong(FAST_EXTRACT_IO_BUFFERS);
  UInt16 ioTimeout = (UInt16)(ActiveSchemaDB()->getDefaults()).getAsLong(FAST_EXTRACT_IO_TIMEOUT_SEC);

  Int64 hdfsBufSize = (Int64)CmpCommon::getDefaultNumeric(HDFS_IO_BUFFERSIZE);
  hdfsBufSize = hdfsBufSize * 1024; // convert to bytes
  Int16 replication =  (Int16)CmpCommon::getDefaultNumeric(HDFS_REPLICATION);


  // Create a TDB
  ComTdbFastExtract *tdb = new (space) ComTdbFastExtract (
    flags,
    estimatedRowCount,
    targetName,
    hdfsHost,
    hdfsPort,
    hiveTableName,
    delimiter,
    header,
    nullString,
    recordSeparator,
    given_desc,
    returned_desc,
    work_cri_desc,
    downQueueMaxSize,
    upQueueMaxSize,
    (Lng32) numOutputBuffers,
    outputBufferSize,
    numIoBuffers,
    ioTimeout,
    input_expr,
    output_expr,
    requestRowLen,
    outputRowLen,
    childData_expr,
    childTdb,
    space,
    childDataTuppIndex,
    cnvChildDataTuppIndex,
    childDataRowLen,
    hdfsBufSize,
    replication
    );

  tdb->setSequenceFile(isSequenceFile);
  tdb->setHdfsCompressed(CmpCommon::getDefaultNumeric(TRAF_UNLOAD_HDFS_COMPRESS)!=0);

  tdb->setSkipWritingToFiles(CmpCommon::getDefault(TRAF_UNLOAD_SKIP_WRITING_TO_FILES) == DF_ON);
  tdb->setBypassLibhdfs(CmpCommon::getDefault(TRAF_UNLOAD_BYPASS_LIBHDFS) == DF_ON);
  generator->initTdbFields(tdb);

  // Generate EXPLAIN info.
  if (!generator->explainDisabled())
  {
    generator->setExplainTuple(relExpr.addExplainInfo(tdb, 0, 0, generator));
  }

  // Tell the generator about our in/out rows and the new TDB
  generator->setCriDesc(given_desc, Generator::DOWN);
  generator->setCriDesc(returned_desc, Generator::UP);
  generator->setGenObj(&relExpr, tdb);


  // Return a TDB pointer to the caller
  newTdb = tdb;

  return 0;

} // ft_codegen()
Example #25
0
NABoolean HHDFSMasterHostList::initializeWithSeaQuestNodes()
{
  NABoolean result = FALSE;
  FILE *pp;
  NAString fakeNodeNames =
    ActiveSchemaDB()->getDefaults().getValue(HIVE_USE_FAKE_SQ_NODE_NAMES);

  if (fakeNodeNames.length() <= 1)
    {
      // execute the command "sqshell -c node" and open a pipe to the output of this command.
      pp = popen("sqshell -c node", "r");
      if (pp != NULL)
        {
          // we want to add all the nodes returned by sqshell such that their HostIds
          // assigned here in class HHDFSMasterHostList matches their SeaQuest host number
          HostId nextHostId = getHosts()->entries();

          while (1)
            {
              char *line;
              char buf[1000];
              line = fgets(buf, sizeof buf, pp);
              if (line == NULL)
                {
                  // if we inserted anything without encountering an error, consider that success
                  numSQNodes_ = getHosts()->entries();
                  result = (numSQNodes_ > 0);
                  break;
                }
              char *nodeNum = strstr(line, "Node[");
              if (nodeNum)
                {
                  nodeNum += 5; // skip the matched text
                  int nodeId = atoi(nodeNum);
                  if (nodeId != nextHostId)
                    break; // out-of-sequence host ids are not supported

                  char *nodeName = strstr(nodeNum, "=");
                  if (nodeName == NULL)
                    break; // expecting "=" sign in the sqshell output
                  nodeName++;
                  char *nodeEnd = strstr(nodeName, ",");
                  if (nodeEnd == NULL)
                    break; // couldn't find the end of the node name
                  *nodeEnd = 0;

                  // resolve the found name to make it a fully qualified DNS name,
                  // like HDFS also uses it
                  struct hostent * h = gethostbyname(nodeName);
                  if (h)
                    nodeName = h->h_name;

                  HostId checkId = getHostNumInternal(nodeName);
                  if (checkId != nodeId)
                    if (checkId > nodeId)
                      break; // something must have gone wrong, this should not happen
                    else
                      {
                        // checkId < nodeId, this can happen if we have duplicate
                        // node ids. In this case, insert a dummy node to take up the
                        // number, so we stay in sync
                        sprintf(buf, "dummy.node.%d.nosite.com", nodeId);
                        HostId checkId2 = getHostNumInternal(buf);
                        if (checkId2 != nodeId)
                          break; // again, not expecting to get here
                        // remember that we mave multiple SQ nodes
                        // on the same physical node
                        hasVirtualSQNodes_ = TRUE;
                      }
                  nextHostId++;
                }
            }
          pclose(pp);
        }
    }
  else
    {
      // seed the host name list with fake SQ node names from the CQD insted
      const char delim = ',';
      const char *nodeStart = fakeNodeNames;
      const char *nodeEnd;

      do
        {
          // this is debug code, no error check, no blanks in this string!!!
          char buf[500];

          nodeEnd = strchrnul(nodeStart, delim);
          strncpy(buf, nodeStart, nodeEnd-nodeStart);
          getHostNumInternal(buf);
          nodeStart = nodeEnd+1;
        }
      while (*nodeEnd != 0);
      
      numSQNodes_ = getHosts()->entries();
      result = (numSQNodes_ > 0);
    }
  return result;
}
short
PhysSequence::codeGen(Generator *generator) 
{
  // Get a local handle on some of the generator objects.
  //
  CollHeap *wHeap = generator->wHeap();
  Space *space = generator->getSpace();
  ExpGenerator *expGen = generator->getExpGenerator();
  MapTable *mapTable = generator->getMapTable();

  // Allocate a new map table for this node. This must be done
  // before generating the code for my child so that this local
  // map table will be sandwiched between the map tables already
  // generated and the map tables generated by my offspring.
  //
  // Only the items available as output from this node will
  // be put in the local map table. Before exiting this function, all of
  // my offsprings map tables will be removed. Thus, none of the outputs 
  // from nodes below this node will be visible to nodes above it except 
  // those placed in the local map table and those that already exist in
  // my ancestors map tables. This is the standard mechanism used in the
  // generator for managing the access to item expressions.
  //
  MapTable *localMapTable = generator->appendAtEnd();

  // Since this operation doesn't modify the row on the way down the tree,
  // go ahead and generate the child subtree. Capture the given composite row
  // descriptor and the child's returned TDB and composite row descriptor.
  //
  ex_cri_desc * givenCriDesc = generator->getCriDesc(Generator::DOWN);
  child(0)->codeGen(generator);
  ComTdb *childTdb = (ComTdb*)generator->getGenObj();
  ex_cri_desc * childCriDesc = generator->getCriDesc(Generator::UP);
  ExplainTuple *childExplainTuple = generator->getExplainTuple();

  // Make all of my child's outputs map to ATP 1. The child row is only 
  // accessed in the project expression and it will be the second ATP 
  // (ATP 1) passed to this expression.
  //
  localMapTable->setAllAtp(1);

  // My returned composite row has an additional tupp.
  //
  Int32 numberTuples = givenCriDesc->noTuples() + 1;
  ex_cri_desc * returnCriDesc 
#pragma nowarn(1506)   // warning elimination 
    = new (space) ex_cri_desc(numberTuples, space);
#pragma warn(1506)  // warning elimination 

  // For now, the history buffer row looks just the return row. Later,
  // it may be useful to add an additional tupp for sequence function
  // itermediates that are not needed above this node -- thus, this
  // ATP is kept separate from the returned ATP.
  //
  const Int32 historyAtp = 0;
  const Int32 historyAtpIndex = numberTuples-1;
#pragma nowarn(1506)   // warning elimination 
  ex_cri_desc *historyCriDesc = new (space) ex_cri_desc(numberTuples, space);
#pragma warn(1506)  // warning elimination 
  ExpTupleDesc *historyDesc = 0;

  //seperate the read and retur expressions
  seperateReadAndReturnItems(wHeap);

  // The history buffer consists of items projected directly from the
  // child, the root sequence functions, the value arguments of the 
  // offset functions, and running sequence functions. These elements must 
  // be materialized in the  history buffer in order to be able to compute 
  // the outputs of this node -- the items projected directly from the child 
  // (projectValues) and the root sequence functions (sequenceFunctions).
  //
  // Compute the set of sequence function items that must be materialized
  // int the history buffer. -- sequenceItems
  //
  // Compute the set of items in the history buffer: the union of the 
  // projected values and the value arguments. -- historyIds
  //
  // Compute the set of items in the history buffer that are computed:
  // the difference between all the elements in the history buffer
  // and the projected items. -- computedHistoryIds
  //

  // KB---will need to return atp with 3 tups only 0,1 and 2 
  // 2 -->values from history buffer after ther are moved to it

 
  addCheckPartitionChangeExpr(generator, TRUE);

  ValueIdSet historyIds;

  historyIds += movePartIdsExpr(); 
  historyIds += sequencedColumns();
  
  ValueIdSet outputFromChild = child(0)->getGroupAttr()->getCharacteristicOutputs();

  getHistoryAttributes(readSeqFunctions(),outputFromChild, historyIds, TRUE, wHeap);

  // Add in the top level sequence functions.
  historyIds += readSeqFunctions();

  getHistoryAttributes(returnSeqFunctions(),outputFromChild, historyIds, TRUE, wHeap);
  // Add in the top level functions.
  historyIds += returnSeqFunctions();
  
  // Layout the work tuple format which consists of the projected
  // columns and the computed sequence functions. First, compute
  // the number of attributes in the tuple.
  //
  ULng32 numberAttributes 
    = ((NOT historyIds.isEmpty()) ? historyIds.entries() : 0);

  // Allocate an attribute pointer vector from the working heap.
  //
  Attributes **attrs = new(wHeap) Attributes*[numberAttributes];

  // Fill in the attributes vector for the history buffer including
  // adding the entries to the map table. Also, compute the value ID
  // set for the elements to project from the child row.
  //
  //??????????re-visit this function??
  computeHistoryAttributes(generator, 
                           localMapTable,
                           attrs,
                           historyIds);

  // Create the tuple descriptor for the history buffer row and
  // assign the offsets to the attributes. For now, this layout is 
  // identical to the returned row. Set the tuple descriptors for
  // the return and history rows.
  //
  ULng32 historyRecLen;
  expGen->processAttributes(numberAttributes,
                            attrs,
                            ExpTupleDesc::SQLARK_EXPLODED_FORMAT,
                            historyRecLen,
                            historyAtp,
                            historyAtpIndex,
                            &historyDesc,
                            ExpTupleDesc::SHORT_FORMAT);
  NADELETEBASIC(attrs, wHeap);
#pragma nowarn(1506)   // warning elimination 
  returnCriDesc->setTupleDescriptor(historyAtpIndex, historyDesc);
#pragma warn(1506)  // warning elimination 
#pragma nowarn(1506)   // warning elimination 
  historyCriDesc->setTupleDescriptor(historyAtpIndex, historyDesc);
#pragma warn(1506)  // warning elimination 

  // If there are any sequence function items, generate the sequence 
  // function expressions.
  //
  ex_expr * readSeqExpr = NULL;
  if(NOT readSeqFunctions().isEmpty())
    {
      ValueIdSet seqVals = readSeqFunctions();
      seqVals += sequencedColumns();
      seqVals += movePartIdsExpr(); 
      expGen->generateSequenceExpression(seqVals,
                                         readSeqExpr);
    }

  ex_expr *checkPartChangeExpr = NULL;
  if (!checkPartitionChangeExpr().isEmpty()) {
    ItemExpr * newCheckPartitionChangeTree= 
        checkPartitionChangeExpr().rebuildExprTree(ITM_AND,TRUE,TRUE);

    expGen->generateExpr(newCheckPartitionChangeTree->getValueId(), 
                         ex_expr::exp_SCAN_PRED,
                         &checkPartChangeExpr);
  }

  //unsigned long rowLength;
  ex_expr * returnExpr = NULL;
  if(NOT returnSeqFunctions().isEmpty())
  {
    expGen->generateSequenceExpression(returnSeqFunctions(),
                                         returnExpr);

  }

  // Generate expression to evaluate predicate on the output
  //
  ex_expr *postPred = 0;

  if (! selectionPred().isEmpty()) {
    ItemExpr * newPredTree = 
      selectionPred().rebuildExprTree(ITM_AND,TRUE,TRUE);

    expGen->generateExpr(newPredTree->getValueId(), ex_expr::exp_SCAN_PRED,
                         &postPred);
  }


  // Reset ATP's to zero for parent.
  //
  localMapTable->setAllAtp(0);


  // Generate expression to evaluate the cancel expression
  //
  ex_expr *cancelExpression = 0;

  if (! cancelExpr().isEmpty()) {
    ItemExpr * newCancelExprTree = 
      cancelExpr().rebuildExprTree(ITM_AND,TRUE,TRUE);

    expGen->generateExpr(newCancelExprTree->getValueId(), ex_expr::exp_SCAN_PRED,
                         &cancelExpression);
  }

  //
  //  For overflow
  //
  // ( The following are meaningless if ! unlimitedHistoryRows() ) 
  NABoolean noOverflow =  
    CmpCommon::getDefault(EXE_BMO_DISABLE_OVERFLOW) == DF_ON ;
  NABoolean logDiagnostics = 
    CmpCommon::getDefault(EXE_DIAGNOSTIC_EVENTS) == DF_ON ;
  NABoolean possibleMultipleCalls = generator->getRightSideOfFlow() ;
  short scratchTresholdPct = 
    (short) CmpCommon::getDefaultLong(SCRATCH_FREESPACE_THRESHOLD_PERCENT);
  // determione the memory usage (amount of memory as percentage from total
  // physical memory used to initialize data structures)
  unsigned short memUsagePercent =
    (unsigned short) getDefault(BMO_MEMORY_USAGE_PERCENT);
  short memPressurePct = (short)getDefault(GEN_MEM_PRESSURE_THRESHOLD);

  historyRecLen = ROUND8(historyRecLen);

  Lng32 maxNumberOfOLAPBuffers;
  Lng32 maxRowsInOLAPBuffer;
  Lng32 minNumberOfOLAPBuffers;
  Lng32 numberOfWinOLAPBuffers;
  Lng32 olapBufferSize;

  computeHistoryParams(historyRecLen,
                       maxRowsInOLAPBuffer,
                       minNumberOfOLAPBuffers,
                       numberOfWinOLAPBuffers,
                       maxNumberOfOLAPBuffers,
                       olapBufferSize);

  ComTdbSequence *sequenceTdb
    = new(space) ComTdbSequence(readSeqExpr,
                                returnExpr,
                                postPred,
                                cancelExpression,
                                getMinFollowingRows(),
#pragma nowarn(1506)   // warning elimination 
                                historyRecLen,
                                historyAtpIndex,
                                childTdb,
                                givenCriDesc,
                                returnCriDesc,
                                (queue_index)getDefault(GEN_SEQFUNC_SIZE_DOWN),
                                (queue_index)getDefault(GEN_SEQFUNC_SIZE_UP),
                                getDefault(GEN_SEQFUNC_NUM_BUFFERS),
                                getDefault(GEN_SEQFUNC_BUFFER_SIZE),
				olapBufferSize,
                                maxNumberOfOLAPBuffers,
                                numHistoryRows(),
                                getUnboundedFollowing(),
				logDiagnostics,
				possibleMultipleCalls,
				scratchTresholdPct,
				memUsagePercent,
				memPressurePct,
                                maxRowsInOLAPBuffer,
                                minNumberOfOLAPBuffers,
                                numberOfWinOLAPBuffers,
                                noOverflow,
                                checkPartChangeExpr);
#pragma warn(1506)  // warning elimination 
  generator->initTdbFields(sequenceTdb);

  // update the estimated value of HistoryRowLength with actual value
  //setEstHistoryRowLength(historyIds.getRowLength());

  double sequenceMemEst = getEstimatedRunTimeMemoryUsage(sequenceTdb);
  generator->addToTotalEstimatedMemory(sequenceMemEst);

  if(!generator->explainDisabled()) {
    Lng32 seqMemEstInKBPerCPU = (Lng32)(sequenceMemEst / 1024) ;
    seqMemEstInKBPerCPU = seqMemEstInKBPerCPU/
      (MAXOF(generator->compilerStatsInfo().dop(),1));
    generator->setOperEstimatedMemory(seqMemEstInKBPerCPU);

    generator->
      setExplainTuple(addExplainInfo(sequenceTdb,
                                     childExplainTuple,
                                     0,
                                     generator));

    generator->setOperEstimatedMemory(0);
  }

  sequenceTdb->setScratchIOVectorSize((Int16)getDefault(SCRATCH_IO_VECTOR_SIZE_HASH));
  sequenceTdb->setOverflowMode(generator->getOverflowMode());

  sequenceTdb->setBmoMinMemBeforePressureCheck((Int16)getDefault(EXE_BMO_MIN_SIZE_BEFORE_PRESSURE_CHECK_IN_MB));
  
  if(generator->getOverflowMode() == ComTdb::OFM_SSD )
    sequenceTdb->setBMOMaxMemThresholdMB((UInt16)(ActiveSchemaDB()->
				   getDefaults()).
			  getAsLong(SSD_BMO_MAX_MEM_THRESHOLD_IN_MB));
  else
    sequenceTdb->setBMOMaxMemThresholdMB((UInt16)(ActiveSchemaDB()->
				   getDefaults()).
			  getAsLong(EXE_MEMORY_AVAILABLE_IN_MB));

  // The CQD EXE_MEM_LIMIT_PER_BMO_IN_MB has precedence over the mem quota sys
  NADefaults &defs = ActiveSchemaDB()->getDefaults();
  UInt16 mmu = (UInt16)(defs.getAsDouble(EXE_MEM_LIMIT_PER_BMO_IN_MB));
  UInt16 numBMOsInFrag = (UInt16)generator->getFragmentDir()->getNumBMOs();
  if (mmu != 0)
    sequenceTdb->setMemoryQuotaMB(mmu);
  else {
    // Apply quota system if either one the following two is true:
    //   1. the memory limit feature is turned off and more than one BMOs 
    //   2. the memory limit feature is turned on
    NABoolean mlimitPerCPU = defs.getAsDouble(EXE_MEMORY_LIMIT_PER_CPU) > 0;

    if ( mlimitPerCPU || numBMOsInFrag > 1 ) {

        double memQuota = 
           computeMemoryQuota(generator->getEspLevel() == 0,
                              mlimitPerCPU,
                              generator->getBMOsMemoryLimitPerCPU().value(),
                              generator->getTotalNumBMOsPerCPU(),
                              generator->getTotalBMOsMemoryPerCPU().value(),
                              numBMOsInFrag, 
                              generator->getFragmentDir()->getBMOsMemoryUsage()
                             );
                                  
        sequenceTdb->setMemoryQuotaMB( UInt16(memQuota) );
    }
  }

  generator->setCriDesc(givenCriDesc, Generator::DOWN);
  generator->setCriDesc(returnCriDesc, Generator::UP);
  generator->setGenObj(this, sequenceTdb);

  return 0;

}
Example #27
0
// The following functions allow access to the defaults table
// in sqlcomp/NADefaults.cpp; given the id number of the default, it
// returns the value
Lng32 CmpCommon::getDefaultLong(DefaultConstants id)
{
  return ActiveSchemaDB()->getDefaults().getAsLong(id);
}
Example #28
0
DefaultToken CmpCommon::getDefault(DefaultConstants id,
				   NAString &result,
				   Int32 errOrWarn)
{
  return ActiveSchemaDB()->getDefaults().token(id, result, FALSE, errOrWarn);
}
Example #29
0
DefaultToken CmpCommon::getDefault(DefaultConstants id,
				   Int32 errOrWarn)
{
  return ActiveSchemaDB()->getDefaults().getToken(id, errOrWarn);
}
Example #30
0
NAString CmpCommon::getDefaultString(DefaultConstants id)
{
  return ActiveSchemaDB()->getDefaults().getString(id);
}