Ejemplo n.º 1
0
 public function testGetIntervalsStringWithInvalidData()
 {
     $interval = new Interval('2014-01-01T00:00:00-0000', '2015-01-01T04:20:00-0700');
     $interval->intervalStart = '2014-01-01T00:00:00-0000';
     $this->setExpectedException('DruidFamiliar\\Exception\\UnexpectedTypeException', "intervalStart");
     $interval->getIntervalsString();
 }
Ejemplo n.º 2
0
 /**
  * Fetch data.
  *
  * @return array|mixed
  * @throws \Exception
  */
 public function fetch()
 {
     if (!$this->intervals) {
         throw new RuntimeException('Fetch ingestion interval not configured.');
     }
     if ($this->host == '' || $this->user == '' || !$this->db) {
         throw new RuntimeException('Database configuration not configured.');
     }
     if (!$this->pass) {
         $this->pass = '';
     }
     $mysqli = $this->getMysqli($this->host, $this->user, $this->pass, $this->db);
     $rows = array();
     // Check connection
     if ($mysqli->connect_errno) {
         throw new \Exception(sprintf("Connect failed: %s\n", $mysqli->connect_error));
     }
     if ($this->output) {
         $this->output->info("Connected to MySQL Database at " . $this->host);
         $this->output->debug("Connected to MySQL Database at " . $this->host . " as user " . $this->user . " using db " . $this->db);
     }
     $preparedQuery = $this->prepareQuery($this->query, $this->intervals->getStart(), $this->intervals->getEnd());
     if ($this->output) {
         $this->output->debug("Prepared query:\n\n" . $preparedQuery . "\n\n");
     }
     // Select queries return a resultset
     if ($result = $mysqli->query($preparedQuery, MYSQLI_USE_RESULT)) {
         if ($this->output) {
             $this->output->info("Iterating mysql result set...");
         }
         while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
             $rows[] = $this->processRow($row);
         }
         if ($this->output) {
             $this->output->info("Finished iterating mysql result set.");
         }
         /* free result set */
         $result->close();
     } else {
         throw new \Exception('Query did not return result set.');
     }
     $mysqli->close();
     if ($this->output) {
         $this->output->info("Successfully closed MySQL Connection.");
     }
     return $rows;
 }