Merge.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file Merge.cpp
22  */
23 
24 #include "../common/progress/TaskProgress.h"
25 #include "../core/logger/Logger.h"
26 #include "../core/translator/Translator.h"
27 #include "../dataaccess/dataset/DataSet.h"
28 #include "../dataaccess/dataset/DataSetAdapter.h"
29 #include "../dataaccess/dataset/DataSetType.h"
30 #include "../dataaccess/dataset/DataSetTypeConverter.h"
31 #include "../dataaccess/dataset/ObjectIdSet.h"
32 #include "../dataaccess/datasource/DataSource.h"
33 #include "../dataaccess/datasource/DataSourceInfo.h"
34 #include "../dataaccess/datasource/DataSourceInfoManager.h"
35 #include "../dataaccess/datasource/DataSourceCapabilities.h"
36 #include "../dataaccess/datasource/DataSourceTransactor.h"
37 #include "../dataaccess/query_h.h"
38 #include "../dataaccess/utils/Utils.h"
39 
40 #include "../datatype/Property.h"
41 #include "../datatype/SimpleData.h"
42 #include "../datatype/StringProperty.h"
43 
44 #include "../geometry/Geometry.h"
45 #include "../geometry/GeometryCollection.h"
46 #include "../geometry/GeometryProperty.h"
47 #include "../geometry/MultiLineString.h"
48 #include "../geometry/MultiPoint.h"
49 #include "../geometry/MultiPolygon.h"
50 #include "../geometry/Utils.h"
51 
52 #include "../memory/DataSet.h"
53 #include "../memory/DataSetItem.h"
54 
55 #include "AlgorithmParams.h"
56 #include "ComplexData.h"
57 #include "Merge.h"
58 #include "Utils.h"
59 
60 // BOOST
61 #include <boost/lexical_cast.hpp>
62 #include <boost/uuid/random_generator.hpp>
63 #include <boost/uuid/uuid_io.hpp>
64 
65 // STL
66 #include <time.h>
67 
68 const int BLOCKSIZE = 10000;
69 
71 : m_targetDst(nullptr),
72  m_targetDs(nullptr),
73  m_originDst(nullptr),
74  m_originDs(nullptr),
75  m_outDsetName(""),
76  m_isUpdate(false),
77  m_targetSRID(0)
78 {
79 }
80 
82 {
83  clock_t tStart = clock();
84  TE_LOG_INFO(TE_TR("Merge (memory) operation started"));
85 
87 
88  m_targetSource = mainParams->getInputParams()[0].m_inputDataSource;
89  m_targetDst = mainParams->getInputParams()[0].m_inputDataSetType;
90  m_targetDs = mainParams->getInputParams()[0].m_inputDataSet;
91 
92  m_originSource = mainParams->getInputParams()[1].m_inputDataSource;
93  m_originDst = mainParams->getInputParams()[1].m_inputDataSetType;
94  m_originDs = mainParams->getInputParams()[1].m_inputDataSet;
95 
96  m_outDsetName = mainParams->getOutputDataSetName();
97  m_outDsrc = mainParams->getOutputDataSource();
98 
99  m_isUpdate = isUpdate(mainParams->getSpecificParams());
100 
101  TE_LOG_INFO(TE_TR("Operation Output: ") + (m_isUpdate?TE_TR("Update"):TE_TR("New Layer")));
102 
104 
105  m_targetSRID = gpInput->getSRID();
106 
108 
109  ///////////////////////////////////////////////////////////////////////////////////////////////
110 
111  std::unique_ptr<te::da::DataSourceTransactor> transactor;
112 
113  try {
114 
115  std::unique_ptr<te::da::DataSetType> dst;
116 
117  te::common::TaskProgress task("Merging...");
118  task.useTimer(true);
119  if (m_isUpdate)
120  {
121  task.setTotalSteps((int)m_originDs->size());
122  }
123  else
124  {
125  task.setTotalSteps((int)m_targetDs->size() + (int)m_originDs->size());
126  }
127 
128 
129  //task.setTotalSteps((int)(m_selectedAttVec.size() * vectorMap.size()));
130 
131  if (m_isUpdate)
132  {
133  transactor = m_targetSource->getTransactor();
134 
135  updateInputDst(transactor.get());
136 
137  std::unique_ptr<te::da::DataSetType> aux = transactor->getDataSetType(m_targetDst->getName());
138 
139  std::unique_ptr<te::da::DataSetTypeConverter> targetConverter(new te::da::DataSetTypeConverter(aux.release(), m_targetSource->getCapabilities(), m_targetSource->getEncoding()));
141 
142  te::da::DataSetType* dtClone = dynamic_cast<te::da::DataSetType*>(targetConverter->getResult()->clone());
143 
144  dst.reset(dtClone);
145  }
146  else
147  {
148  dst = getOutputDataSetType(mainParams);
149 
150  transactor = m_outDsrc->getTransactor();
151  }
152 
154  int pkMax = -1;
155  std::size_t pkPos=std::string::npos;
156  int pkType=-1;
157  std::string pkName;
158 
159  if (s == AUTOINCREMENT)
160  {
161  te::dt::Property* pkProp = dst->getPrimaryKey()->getProperties()[0];
162  pkName = pkProp->getName();
163 
164  TE_LOG_INFO(TE_TR("Operation strategy: ") + TE_TR("AUTOINCREMENT"));
165  }
166  else if (s == TRYGETMAX)
167  {
168  te::dt::Property* pkProp = dst->getPrimaryKey()->getProperties()[0];
169  pkMax = tryGetMax();
170  pkPos = dst->getPropertyPosition(pkProp);
171  pkType = getPropertyType(pkProp);
172 
173  TE_LOG_INFO(TE_TR("Operation strategy: ") + TE_TR("TRYGETMAX"));
174  }
175  else
176  {
177  TE_LOG_INFO(TE_TR("Operation strategy: ") + TE_TR("PUREMERGE"));
178  }
179 
180  te::mem::DataSet* ds = new te::mem::DataSet(dst.get());
181 
185 
186  std::size_t fgPos = m_targetDst->getPropertyPosition(fgGrop);
187  std::size_t sgPos = m_originDst->getPropertyPosition(sgGrop);
188  std::size_t outgPos = dst->getPropertyPosition(outgGrop);
189 
190  transactor->begin();
191  TE_LOG_INFO(TE_TR("Transaction Begin"));
192 
193  int count = 0;
194 
197 
198  std::map<std::string, std::string> op;
199 
200  bool isDtCreated = false; // When the operation is not a update operation
201 
202  if (!m_isUpdate)
203  {
204  TE_LOG_INFO(TE_TR("Start iterating Target Layer"));
205  int targetCount = 0;
206  while (m_targetDs->moveNext())
207  {
208  if (!task.isActive())
209  {
210  std::string msg = TE_TR("Operation canceled by the user");
211  transactor->rollBack();
212  throw te::common::Exception(msg, 1);
213  }
214 
215  task.pulse();
217 
218  for (std::size_t i = 0; i < m_properties.size(); ++i)
219  {
220  if (m_properties[i].first.empty() || m_targetDs->isNull(m_properties[i].first))
221  continue;
222 
223  if (!m_properties[i].first.empty())
224  {
225  if (isPrimaryKeyProperty(dst.get(), m_properties[i].first))
226  {
227  if (s != AUTOINCREMENT)
228  {
229  if (s == PUREMERGE)
230  {
231  item->setValue(m_properties[i].first, m_targetDs->getValue(m_properties[i].first).release());
232  }
233  else if (s == TRYGETMAX)
234  {
235  item->setValue(m_properties[i].first, m_targetDs->getValue(m_properties[i].first).release());
236  }
237  }
238  }
239  else
240  {
241  item->setValue(m_properties[i].first, m_targetDs->getValue(m_properties[i].first).release());
242  }
243  }
244  }
245 
246  item->setGeometry(outgPos, m_targetDs->getGeometry(fgPos).release());
247 
248  ds->add(item);
249 
250  if (count == 0)
251  {
252  if (s == AUTOINCREMENT)
253  {
254  std::vector<std::string> pkNameVec;
255  pkNameVec.push_back(pkName);
256 
257  std::unique_ptr<te::da::DataSet> adaptDs = te::da::HideColumns(ds, dst.get(), pkNameVec);
258 
259  transactor->createDataSet(dst.get(), op);
260  transactor->add(dst->getName(), adaptDs.get(), op);
261 
262  isDtCreated = true;
263 
264  }
265  else
266  {
267  transactor->createDataSet(dst.get(), op);
268  transactor->add(dst->getName(), ds, op);
269 
270  isDtCreated = true;
271  }
272 
273  delete ds;
274 
275  ds = new te::mem::DataSet(dst.get());
276  }
277 
278  if ((count % BLOCKSIZE) == 0)
279  {
280  TE_LOG_INFO(TE_TR(" Target Layer Iterating Count: ") + std::to_string(targetCount));
281 
282  if (!isDtCreated)
283  {
284  transactor->createDataSet(dst.get(), op);
285  isDtCreated = true;
286  }
287 
288  if (s == AUTOINCREMENT)
289  {
290  std::vector<std::string> pkNameVec;
291  pkNameVec.push_back(pkName);
292 
293  std::unique_ptr<te::da::DataSet> adaptDs = te::da::HideColumns(ds, dst.get(), pkNameVec);
294 
295  transactor->add(dst->getName(), adaptDs.get(), op);
296  }
297  else
298  {
299  transactor->add(dst->getName(), ds, op);
300  }
301 
302  delete ds;
303 
304  ds = new te::mem::DataSet(dst.get());
305  }
306 
307  ++count;
308  ++targetCount;
309  }
310  TE_LOG_INFO(TE_TR(" Target Layer Iterating Count: ") + std::to_string(targetCount));
311  TE_LOG_INFO(TE_TR("Target Layer iterating finished"));
312  }
313 
314  if (m_isUpdate)
315  isDtCreated = true;
316 
317  int originCount = 0;
318  TE_LOG_INFO(TE_TR("Start iterating Origin Layer"));
319  while (m_originDs->moveNext() || m_originDs->isEmpty())
320  {
321  if (!task.isActive())
322  {
323  std::string msg = TE_TR("Operation canceled by the user");
324  transactor->rollBack();
325  throw te::common::Exception(msg, 1);
326  }
327 
328  task.pulse();
330 
331  if (s == TRYGETMAX)
332  {
333  ++pkMax;
334 
335  if (pkType == te::dt::INT16_TYPE)
336  {
337  item->setInt16(pkPos, pkMax);
338  }
339  else if (pkType == te::dt::INT32_TYPE)
340  {
341  item->setInt32(pkPos, pkMax);
342  }
343  else
344  {
345  item->setInt64(pkPos, pkMax);
346  }
347  }
348 
349  for (std::size_t i = 0; i < m_properties.size(); ++i)
350  {
351  if (!m_properties[i].second.empty())
352  {
353  if (m_originDs->isNull(m_properties[i].second))
354  continue;
355 
356  if (!m_properties[i].first.empty())
357  {
358  if (s != TRYGETMAX && isPrimaryKeyProperty(dst.get(), m_properties[i].first))
359  {
360  if (s != AUTOINCREMENT)
361  {
362  if (s == PUREMERGE)
363  {
364  item->setValue(m_properties[i].first, m_originDs->getValue(m_properties[i].second).release());
365  }
366  }
367  }
368  else
369  {
370  if(!isPrimaryKeyProperty(dst.get(), m_properties[i].first))
371  item->setValue(m_properties[i].first, m_originDs->getValue(m_properties[i].second).release());
372  }
373  }
374  else
375  {
376  item->setValue(m_properties[i].second, m_originDs->getValue(m_properties[i].second).release());
377  }
378  }
379  }
380 
381  std::unique_ptr<te::gm::Geometry> geom = m_originDs->getGeometry(sgPos);
382 
383  if (fgGrop->getSRID() != sgGrop->getSRID())
384  {
385  geom->transform(fgGrop->getSRID());
386  }
387 
388  item->setGeometry(outgPos, geom.release());
389 
390  ds->add(item);
391 
392  if ((count % BLOCKSIZE) == 0)
393  {
394 
395  TE_LOG_INFO(" "+TE_TR("Origin Layer Iterating Count: ") + std::to_string(originCount));
396 
397  if (!isDtCreated)
398  {
399  transactor->createDataSet(dst.get(), op);
400  isDtCreated = true;
401  }
402 
403  if (s == AUTOINCREMENT)
404  {
405  std::vector<std::string> pkNameVec;
406  pkNameVec.push_back(pkName);
407 
408  std::unique_ptr<te::da::DataSet> adaptDs = te::da::HideColumns(ds, dst.get(), pkNameVec);
409 
410  transactor->add(dst->getName(), adaptDs.get(), op);
411  }
412  else
413  {
414  transactor->add(dst->getName(), ds, op);
415  }
416 
417  delete ds;
418 
419  ds = new te::mem::DataSet(dst.get());
420  }
421 
422  ++count;
423  ++originCount;
424  }
425  TE_LOG_INFO(" "+TE_TR("Origin Layer Iterating Count: ") + std::to_string(originCount));
426  TE_LOG_INFO(TE_TR("Origin Layer iterating finished"));
427  TE_LOG_INFO(TE_TR("Total Count: ") + std::to_string(count));
428 
429  if (ds)
430  {
431  if (!isDtCreated)
432  {
433  transactor->createDataSet(dst.get(), op);
434  isDtCreated = true;
435  }
436 
437  if (s == AUTOINCREMENT)
438  {
439  std::vector<std::string> pkNameVec;
440  pkNameVec.push_back(pkName);
441 
442  std::unique_ptr<te::da::DataSet> adaptDs = te::da::HideColumns(ds, dst.get(), pkNameVec);
443 
444  transactor->add(dst->getName(), adaptDs.get(), op);
445  }
446  else
447  {
448  transactor->add(dst->getName(), ds, op);
449  }
450 
451  delete ds;
452  }
453 
454  TE_LOG_INFO(TE_TR("Transaction Commit"));
455  transactor->commit();
456 
457  }
458  catch (const te::common::Exception& e)
459  {
460  if (e.code() == 1)
461  {
462  TE_LOG_INFO(e.what());
463  }
464  else
465  {
466  TE_LOG_ERROR(TE_TR("Exception: ") + e.what());
467  }
468 
469  TE_LOG_INFO(TE_TR("Transaction RollBack"));
470  transactor->rollBack();
471  throw;
472  }
473  catch (std::exception& e)
474  {
475  TE_LOG_ERROR(TE_TR("Exception: ") + e.what());
476  TE_LOG_INFO(TE_TR("Transaction RollBack"));
477  transactor->rollBack();
478  throw;
479  }
480 
481  int seconds = (clock() - tStart) / CLOCKS_PER_SEC;
482  int hours, minutes;
483  minutes = seconds / 60;
484  hours = minutes / 60;
485  std::string timeStr = std::to_string(int(hours)) + ":" + std::to_string(int(minutes % 60)) + ":" + std::to_string(int(seconds % 60));
486  TE_LOG_INFO(TE_TR("Merge (memory) operation finished") +" - " +TE_TR("Time Spent: ") + timeStr);
487  return true;
488 }
489 
490 bool te::vp::Merge::isUpdate(const std::map<std::string, te::dt::AbstractData*>& specificParams)
491 {
492  std::map<std::string, te::dt::AbstractData*>::const_iterator it = specificParams.begin();
493 
494  bool isUpdate = false;
495 
496  while (it != specificParams.end())
497  {
498  if (it->first != "ISUPDATE")
499  {
500  ++it;
501  continue;
502  }
503 
504  te::dt::AbstractData* abData = it->second;
505 
506  te::vp::ComplexData<bool>* cd = dynamic_cast<te::vp::ComplexData<bool>* >(abData);
507 
508  if (cd)
509  isUpdate = cd->getValue();
510 
511  ++it;
512  }
513 
514  return isUpdate;
515 }
516 
517 std::vector<std::pair<std::string, std::string> > te::vp::Merge::getPropNames(const std::map<std::string, te::dt::AbstractData*>& specificParams)
518 {
519  std::map<std::string, te::dt::AbstractData*>::const_iterator it = specificParams.begin();
520 
521  std::vector<std::pair<std::string, std::string> > propNames;
522 
523  while (it != specificParams.end())
524  {
525  if (it->first != "ATTRIBUTES")
526  {
527  ++it;
528  continue;
529  }
530 
531  te::dt::AbstractData* abData = it->second;
532 
534 
535  if (cd)
536  propNames = cd->getValue();
537 
538  ++it;
539  }
540 
541  return propNames;
542 }
543 
544 std::unique_ptr<te::da::DataSetType> te::vp::Merge::getOutputDataSetType(
545  te::vp::AlgorithmParams* /*mainParams*/)
546 {
547  std::unique_ptr<te::da::DataSetType> dt(new te::da::DataSetType(m_outDsetName));
548 
549  for (std::size_t i = 0; i < m_properties.size(); ++i)
550  {
551  std::string fp = m_properties[i].first;
552  std::string sp = m_properties[i].second;
553 
554  if (fp.empty() && sp.empty())
555  {
556  continue;
557  }
558 
561 
562  te::dt::Property* newProp = nullptr;
563 
564  if ((!fp.empty()) && (!sp.empty()))
565  {
566  te::dt::SimpleProperty* fSimpleProp = dynamic_cast<te::dt::SimpleProperty*>(fProp);
567  te::dt::SimpleProperty* sSimpleProp = dynamic_cast<te::dt::SimpleProperty*>(sProp);
568 
569  if (fSimpleProp->isRequired() != sSimpleProp->isRequired())
570  {
571  newProp = fProp->clone();
572 
573  te::dt::SimpleProperty* newSimpleProp = dynamic_cast<te::dt::SimpleProperty*>(newProp);
574 
575  newSimpleProp->setRequired(false);
576  }
577  else
578  {
579  newProp = fProp->clone();
580  }
581  }
582  else if (!fp.empty())
583  {
584  newProp = fProp->clone();
585 
586  te::dt::SimpleProperty* newSimpleProp = dynamic_cast<te::dt::SimpleProperty*>(newProp);
587 
588  newSimpleProp->setRequired(false);
589  }
590  else if (!sp.empty())
591  {
592  newProp = sProp->clone();
593 
594  te::dt::SimpleProperty* newSimpleProp = dynamic_cast<te::dt::SimpleProperty*>(newProp);
595 
596  newSimpleProp->setRequired(false);
597  newSimpleProp->setAutoNumber(false);
598  }
599  else
600  {
601  throw te::common::Exception(TE_TR("An unexpected error occurred during the output dataset creation!"));
602  }
603 
604  dt->add(newProp);
605  }
606 
607  if (m_outDsrc->getType() != "OGR")
608  {
610 
611  std::vector<te::dt::Property*> pkProp = pk->getProperties();
612 
613  te::da::PrimaryKey* newPk = new te::da::PrimaryKey(dt->getName() + "_pk");
614 
615  for (std::size_t i = 0; i < pkProp.size(); ++i)
616  {
617  newPk->add(dt->getProperty(pkProp[i]->getName()));
618  }
619 
620  dt->setPrimaryKey(newPk);
621  }
622 
623  dt->add(te::da::GetFirstSpatialProperty(m_targetDst)->clone());
624 
625  return dt;
626 }
627 
629 {
631 
632  if ((m_outDsrc && m_outDsrc->getType() == "OGR") || m_targetSource->getType() == "OGR")
633  return PUREMERGE;
634 
635  if (targetPk)
636  {
637  std::vector<te::dt::Property*> targetProps = targetPk->getProperties();
638 
639  if (targetProps.size() > 1)
640  {
641  return PUREMERGE;
642  }
643  else
644  {
645  te::dt::Property* prop = targetProps[0];
646 
647  if ((prop->getType() != te::dt::INT16_TYPE) && (prop->getType() != te::dt::INT32_TYPE) && (prop->getType() != te::dt::INT64_TYPE))
648  {
649  return PUREMERGE;
650  }
651  else
652  {
653  te::dt::SimpleProperty* simpleProp = dynamic_cast<te::dt::SimpleProperty*>(prop);
654 
655  if (simpleProp)
656  {
657  if (simpleProp->isAutoNumber())
658  {
659  return AUTOINCREMENT;
660  }
661  else
662  {
663  return TRYGETMAX;
664  }
665  }
666  else
667  {
668  throw te::common::Exception(TE_TR("Merge error: Property type invalid."));
669  }
670 
671  }
672  }
673  }
674  else
675  return PUREMERGE;
676 
677 }
678 
680 {
682 
684 
685  te::da::From pFrom;
686  pFrom.push_back(pFromItem);
687 
688  te::da::PropertyName pName(pkProp->getName());
689 
690  te::da::Max fMax(pName);
691 
692  te::da::Field* pField = new te::da::Field(fMax);
693 
694  te::da::Fields pFields;
695  pFields.push_back(pField);
696 
697  te::da::Select pSelect(pFields, pFrom);
698 
699  std::unique_ptr<te::da::DataSet> result = m_targetSource->query(pSelect);
700 
701  result->moveFirst();
702 
703  std::string maxStr = result->getAsString(0);
704 
705  int maxInt = boost::lexical_cast<int>(maxStr);
706 
707  return maxInt;
708 }
709 
710 bool te::vp::Merge::isPrimaryKeyProperty(const te::da::DataSetType* dst, const std::string& p)
711 {
712  te::da::PrimaryKey* pk = dst->getPrimaryKey();
713  if (!pk)
714  return false;
715 
716  std::vector<te::dt::Property*> props = pk->getProperties();
717 
718  for (std::size_t i = 0; i < props.size(); ++i)
719  {
720  if (props[i]->getName() == p)
721  return true;
722  }
723 
724  return false;
725 }
726 
728 {
730  std::vector<te::dt::Property*> pkProps = pk->getProperties();
731  std::vector<std::string> pkPropsNames;
732 
733  for (auto i : pkProps)
734  {
735  pkPropsNames.push_back(i->getName());
736  }
737 
738  for (std::size_t i = 0; i < m_properties.size(); ++i)
739  {
740  if (std::find(pkPropsNames.begin(), pkPropsNames.end(), m_properties[i].first) != pkPropsNames.end())
741  continue;
742 
743  std::string fp = m_properties[i].first;
744  std::string sp = m_properties[i].second;
745 
746  if (fp.empty() && sp.empty())
747  {
748  continue;
749  }
750 
753 
754  te::dt::Property* newProp = nullptr;
755 
756  if ((!fp.empty()) && (!sp.empty()))
757  {
758  te::dt::SimpleProperty* fSimpleProp = dynamic_cast<te::dt::SimpleProperty*>(fProp);
759  te::dt::SimpleProperty* sSimpleProp = dynamic_cast<te::dt::SimpleProperty*>(sProp);
760 
761  if (fSimpleProp->isRequired() != sSimpleProp->isRequired())
762  {
763  te::dt::Property* auxProp = fSimpleProp->clone();
764  te::dt::SimpleProperty* auxSimpleProp = dynamic_cast<te::dt::SimpleProperty*>(auxProp);
765  auxSimpleProp->setRequired(false);
766 
767  transactor->changePropertyDefinition(m_targetDst->getName(), fProp->getName(), auxSimpleProp);
768  }
769  }
770  else if (!fp.empty())
771  {
772  te::dt::SimpleProperty* fSimpleProp = dynamic_cast<te::dt::SimpleProperty*>(fProp);
773 
774  if (fSimpleProp->isRequired())
775  {
776  te::dt::Property* auxProp = fSimpleProp->clone();
777  te::dt::SimpleProperty* auxSimpleProp = dynamic_cast<te::dt::SimpleProperty*>(auxProp);
778  auxSimpleProp->setRequired(false);
779 
780  transactor->changePropertyDefinition(m_targetDst->getName(), fProp->getName(), auxSimpleProp);
781  }
782  }
783  else if (!sp.empty())
784  {
785  newProp = sProp->clone();
786 
787  te::dt::SimpleProperty* newSimpleProp = dynamic_cast<te::dt::SimpleProperty*>(newProp);
788 
789  newSimpleProp->setRequired(false);
790  newSimpleProp->setAutoNumber(false);
791 
792  transactor->addProperty(m_targetDst->getName(), newProp);
793  }
794  else
795  {
796  throw te::common::Exception(TE_TR("An unexpected error occurred during the output dataset update!"));
797  }
798  }
799 }
800 
802 {
803  if (p->getType() == te::dt::INT16_TYPE || p->getType() == te::dt::UINT16_TYPE)
804  return te::dt::INT16_TYPE;
805  else if (p->getType() == te::dt::INT32_TYPE || p->getType() == te::dt::UINT32_TYPE)
806  return te::dt::INT32_TYPE;
807  else if (p->getType() == te::dt::INT64_TYPE || p->getType() == te::dt::UINT64_TYPE)
808  return te::dt::INT64_TYPE;
809  else
810  throw; //Throw!!!
811 
812 }
813 
815 {
816  return true;
817 }
bool executeQuery(te::vp::AlgorithmParams *mainParams)
Definition: Merge.cpp:814
virtual std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
Property * getProperty(std::size_t i) const
It returns the i-th property.
te::da::DataSourcePtr m_originSource
Definition: Merge.h:102
Geometric property.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
An abstract class that models a source of data in a query.
Definition: FromItem.h:50
The Field class can be used to model an expression that takes part of the output items of a SELECT...
An atomic property like an integer or double.
bool isPrimaryKeyProperty(const te::da::DataSetType *dst, const std::string &p)
Definition: Merge.cpp:710
A class that models the name of a dataset used in a From clause.
Definition: DataSetName.h:43
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
std::vector< std::pair< std::string, std::string > > getPropNames(const std::map< std::string, te::dt::AbstractData * > &specificParams)
Definition: Merge.cpp:517
A class that models the name of any property of an object.
A class that models the description of a dataset.
Definition: DataSetType.h:72
MergeStrategy checkStrategy()
Definition: Merge.cpp:628
virtual const char * what() const
It outputs the exception message.
std::vector< std::pair< std::string, std::string > > m_properties
Definition: Merge.h:113
void useTimer(bool flag)
Used to define if task use progress timer information.
te::da::DataSetType * m_originDst
Definition: Merge.h:103
te::da::DataSourcePtr m_targetSource
Definition: Merge.h:99
void updateInputDst(te::da::DataSourceTransactor *transactor)
Definition: Merge.cpp:727
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
PrimaryKey * getPrimaryKey() const
It returns the primary key associated to the dataset type.
Definition: DataSetType.h:214
std::vector< te::vp::InputParams > getInputParams()
std::string m_outDsetName
Definition: Merge.h:107
const int BLOCKSIZE
Definition: Merge.cpp:68
static te::dt::Date ds(2010, 01, 01)
void setInt16(std::size_t i, boost::int16_t value)
It sets the value of the i-th property.
virtual void changePropertyDefinition(const std::string &datasetName, const std::string &propName, te::dt::Property *newProp)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
Algorithm Parameters.
virtual Property * clone() const =0
It returns a clone of the object.
#define TE_LOG_INFO(message)
Use this tag in order to log a message to the TerraLib default logger with the INFO level...
Definition: Logger.h:315
It models a property definition.
Definition: Property.h:59
bool isActive() const
Verify if the task is active.
T getValue() const
It returns the associated value.
Definition: ComplexData.h:129
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
Definition: PrimaryKey.h:109
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
void setTotalSteps(int value)
Set the task total stepes.
TEDATAACCESSEXPORT std::unique_ptr< te::da::DataSet > HideColumns(te::da::DataSet *ds, te::da::DataSetType *dst, const std::vector< std::string > &columns)
It hide columns of a DataSet using DataSetAdapter.
An converter for DataSetType.
bool m_isUpdate
Definition: Merge.h:109
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
virtual std::size_t size() const =0
It returns the collection size, if it is known.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
virtual int code() const
It gets the exception code.
int m_targetSRID
Definition: Merge.h:111
virtual void addProperty(const std::string &datasetName, te::dt::Property *p)=0
It adds a new property to the dataset schema.
virtual bool isEmpty() const =0
It returns true if the collection is empty.
A template for complex data types.
Definition: ComplexData.h:52
te::da::DataSet * m_targetDs
Definition: Merge.h:101
int getSRID() const
It returns the spatial reference system identifier associated to this property.
const std::string & getOutputDataSetName()
void DataSet()
static te::dt::TimeDuration dt(20, 30, 50, 11)
te::da::DataSourcePtr m_outDsrc
Definition: Merge.h:106
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
Definition: Fields.h:37
te::gm::Polygon * p
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
std::unique_ptr< te::da::DataSetType > getOutputDataSetType(te::vp::AlgorithmParams *mainParams)
Definition: Merge.cpp:544
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
te::da::DataSourcePtr getOutputDataSource()
bool isRequired() const
It returns true if the attribute is required, otherwise it returns false.
const std::map< std::string, te::dt::AbstractData * > & getSpecificParams()
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
Utility functions for the data access module.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
te::da::DataSetType * m_targetDst
Definition: Merge.h:100
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
Definition: From.h:37
int getType() const
It returns the property data type.
Definition: Property.h:161
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
virtual Property * clone() const
It returns a clone of the object.
virtual std::unique_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
void setRequired(bool r)
It tells if the property is required or not.
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
Definition: Logger.h:337
TEVPEXPORT void ValidateAlgorithmParams(AlgorithmParams *mainParams, Strategy st)
std::size_t getPropertyPosition(const std::string &name) const
It returns the property position based on its name.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
bool executeMemory(te::vp::AlgorithmParams *mainParams)
Definition: Merge.cpp:81
void setInt64(std::size_t i, boost::int64_t value)
It sets the value of the i-th property.
bool isAutoNumber() const
It returns true if the attribute is an autonumber, otherwise it returns false.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
TEDATAACCESSEXPORT te::dt::Property * GetFirstSpatialProperty(const DataSetType *dt)
int getPropertyType(const te::dt::Property *p)
Definition: Merge.cpp:801
Max statistical function.
Definition: Max.h:46
int tryGetMax()
Definition: Merge.cpp:679
bool isUpdate(const std::map< std::string, te::dt::AbstractData * > &specificParams)
Definition: Merge.cpp:490
te::da::DataSet * m_originDs
Definition: Merge.h:104
const std::string & getName() const
It returns the property name.
Definition: Property.h:127