Esempio n. 1
0
 /**
  * {@inheritdoc}
  *
  * @todo Possible optimization by pre-compiling the expression on init
  */
 public function transform(RowInterface $row)
 {
     $data = $row->getArray();
     $data['utils'] = $this->utils;
     $output = $this->language->evaluate($this->expression, $data);
     $row->set($this->outputColumn->getName(), $output);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function extract(RowInterface $row)
 {
     $data = $this->stmt->fetch(PDO::FETCH_ASSOC);
     foreach ($data as $key => $value) {
         $row->set($key, $value);
     }
 }
Esempio n. 3
0
 public function transform(RowInterface $row)
 {
     $original = $row->get($this->inputColumnName);
     $existing = $row->get($this->outputColumnName);
     if ($this->override || !$existing) {
         $row->set($this->outputColumnName, $original);
     }
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function transform(RowInterface $row)
 {
     $purchased = $row->get($this->purchasedColumnName);
     $sold = $row->get($this->soldColumnName);
     if ($purchased > 0) {
         $score = round(100 * $sold / $purchased);
     } else {
         $score = 0;
     }
     $row->set($this->outputColumn->getName(), $score);
 }
Esempio n. 5
0
 public function transform(RowInterface $row)
 {
     // var_dump($this->inputColumnName);die;
     $original = $row->get($this->inputColumnName);
     $values = explode($this->delimiter, $original);
     if (count($values) == count($this->outputColumnNames)) {
         foreach ($this->outputColumnNames as $i => $col) {
             $row->set($col['name'], $values[$i]);
         }
     }
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function load(RowInterface $row)
 {
     if ($this->row++ == 0) {
         foreach ($this->columns as $column) {
             $this->output->write(sprintf("%s\t", $column->getAlias()));
         }
     }
     foreach ($this->columns as $column) {
         $this->output->write(sprintf("%s\t", $row->get($column->getAlias())));
     }
     $this->output->writeln('');
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function extract(RowInterface $row)
 {
     $filename = $this->fileNames[$this->index++];
     $json = file_get_contents($filename);
     $data = json_decode($json, true);
     if (is_null($data)) {
         // @todo Pass to logger
         echo sprintf("File '%s' content is not valid json. Skipping...", $filename);
         return;
     }
     foreach ($this->columns as $column) {
         $value = null;
         if (isset($data[$column->getName()])) {
             $value = $data[$column->getName()];
         }
         $row->set($column->getAlias(), $value);
     }
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function load(RowInterface $row)
 {
     $sql = 'INSERT INTO ' . $this->tablename;
     $sql .= ' (';
     foreach ($this->columns as $column) {
         $sql .= $column->getAlias() . ', ';
     }
     $sql = rtrim($sql, ', ');
     $sql .= ') VALUES (';
     $values = array();
     foreach ($this->columns as $column) {
         $values[] = $row->get($column->getAlias());
         $sql .= '?, ';
     }
     $sql = rtrim($sql, ', ');
     $sql .= ');';
     $this->stmt = $this->pdo->prepare($sql);
     if (!$this->stmt->execute($values)) {
         throw new \Exception(sprintf("Query '%s' failed with values %s.", $sql, implode(', ', $values)));
     }
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function extract(RowInterface $row)
 {
     $data = $this->csv->fgetcsv();
     if ($data[0] === null) {
         return;
     }
     $c = 0;
     foreach ($this->columns as $column) {
         $value = null;
         if (isset($data[$c])) {
             $value = $data[$c];
         }
         $row->set($column->getAlias(), $value);
         $c++;
     }
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function extract(RowInterface $row)
 {
     $interval = sprintf('P%sD', $this->interval);
     $this->day->add(new DateInterval($interval));
     $row->set('date', (int) $this->day->format('Ymd'));
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  */
 public function transform(RowInterface $row)
 {
     $datestring = $row->get($this->dateColumnName);
     $date = new DateTime($datestring);
     $quarter = ceil($date->format('n') / 3);
     $weekday = 'Y';
     if ($date->format('N') == 6 || $date->format('N') == 7) {
         $weekday = 'N';
     }
     $row->set('year', (int) $date->format('Y'));
     $row->set('month', (int) $date->format('m'));
     $row->set('weekday', (int) $date->format('N'));
     $row->set('weekdayname', $date->format('l'));
     $row->set('weekdayflag', $weekday);
     $row->set('weeknumber', (int) $date->format('W'));
     $row->set('yearmonth', (int) $date->format('Ym'));
     $row->set('quarter', (int) $quarter);
     $row->set('yearquarter', sprintf("%s%s", (int) $date->format('Y'), $quarter));
     $row->set('yearquartermonth', sprintf("%s%s%s", (int) $date->format('Y'), $quarter, $date->format('m')));
 }