public void addDDF(DDF ddf) throws DDFException { mDDFs.put(ddf.getUUID(), ddf); }
public boolean isPersistable() { if(this.getDDF().getUUID() == null) { return false; } return this.mPersitable; }
public void removeDDF(DDF ddf) throws DDFException { mDDFs.remove(ddf.getUUID()); if (ddf.getName() != null) { mNames.remove(ddf.getName()); } }
public synchronized void setDDFName(DDF ddf, String name) throws DDFException { if(!Strings.isNullOrEmpty(name)) { if (!Strings.isNullOrEmpty(ddf.getName())) { this.mNames.remove(ddf.getName()); } ddf.setName(name); this.mNames.put(name, ddf.getUUID()); } else { throw new DDFException(String.format("DDF's name cannot be null or empty")); } }
public synchronized void setDDFUUID(DDF ddf, UUID uuid) throws DDFException { if(this.hasDDF(uuid)) { throw new DDFException(String.format("DDF with uuid %s already exists", uuid)); } else { //remove old key UUID prevUUID = ddf.getUUID(); if(prevUUID != null) { mDDFs.remove(prevUUID); } ddf.setUUID(uuid); mDDFs.put(uuid, ddf); if(ddf.getName()!= null) { mNames.remove(ddf.getName()); mNames.put(ddf.getName(), ddf.getUUID()); } } }
public DDF sql2ddf(String sqlCommand) throws DDFException { try { // sqlCommand = sqlCommand.replace("@this", this.getTableName()); sqlCommand = sqlCommand.replace("@this", "{1}"); sqlCommand = String.format(sqlCommand, "{1}"); SQLDataSourceDescriptor sqlDS = new SQLDataSourceDescriptor(sqlCommand, null, null,null, this.getUUID().toString()); return this.getManager().sql2ddf(sqlCommand, null, sqlDS); // return this.getManager().sql2ddf(sqlCommand); } catch (Exception e) { throw new DDFException(String.format("Error executing queries for ddf %s", this.getTableName()), e); } }
public SqlResult sql(String sqlCommand, String errorMessage) throws DDFException { try { // sqlCommand = sqlCommand.replace("@this", this.getTableName()); // TODO: what is format? // return this.getManager().sql(String.format(sqlCommand, this.getTableName())); sqlCommand = sqlCommand.replace("@this", "{1}"); sqlCommand = String.format(sqlCommand, "{1}"); SQLDataSourceDescriptor sqlDS = new SQLDataSourceDescriptor(sqlCommand, null, null,null, this.getUUID().toString()); return this.getManager().sql(sqlCommand, null, sqlDS); } catch (Exception e) { throw new DDFException(String.format(errorMessage, this.getTableName()), e); } }
protected long getNumRowsImpl() throws DDFException { this.mLog.debug("get NumRows Impl called"); try { String sqlcmd = "SELECT COUNT(*) FROM {1}"; List<String> rs = this.getManager().sql(sqlcmd, new SQLDataSourceDescriptor(sqlcmd, null, null, null, this .getDDF().getUUID().toString())).getRows(); return Long.parseLong(rs.get(0)); } catch (Exception e) { throw new DDFException("Error getting NRow", e); } }
private DDF sql2ddf(String sqlCommand, String errorMessage) throws DDFException { try { return this.getManager().sql2ddf(String.format(sqlCommand, "{1}"), new SQLDataSourceDescriptor(sqlCommand, null, null, null, this .getDDF().getUUID().toString())); } catch (Exception e) { throw new DDFException(String.format(errorMessage, this.getDDF().getTableName()), e); } }
@Override public DDF agg(List<String> aggregateFunctions) throws DDFException { if (mGroupedColumns.size() > 0) { // String tableName = this.getDDF().getTableName(); String groupedColSql = Joiner.on(",").join(mGroupedColumns); String selectFuncSql = convertAggregateFunctionsToSql(aggregateFunctions.get(0)); for (int i = 1; i < aggregateFunctions.size(); i++) { selectFuncSql += "," + convertAggregateFunctionsToSql(aggregateFunctions.get(i)); } String sqlCmd = String.format("SELECT %s , %s FROM %s GROUP BY %s", selectFuncSql, groupedColSql, "{1}", groupedColSql); mLog.info("SQL Command: " + sqlCmd); try { DDF resultDDF = this.getManager().sql2ddf(sqlCmd, new SQLDataSourceDescriptor(sqlCmd, true, null,null, this.getDDF().getUUID().toString())); return resultDDF; } catch (Exception e) { e.printStackTrace(); throw new DDFException("Unable to query from " + this.getDDF().getTableName(), e); } } else { throw new DDFException("Need to set grouped columns before aggregation"); } }
@Test public void testDDFMAnager() throws DDFException { DDF ddf = this.getTestDDF(); DDFManager manager = this.getDDFManager(); manager.setDDFName(ddf, "myddf"); UUID newUUID = UUID.randomUUID(); manager.setDDFUUID(ddf, newUUID); DDF ddf1 = manager.getDDFByName(ddf.getName()); Assert.assertEquals(ddf1.getUUID(), ddf.getUUID()); Assert.assertEquals(ddf1.getUUID(), newUUID); }
@Test public void testCreateDDF() throws DDFException { Assert.assertNotNull("DDFManager cannot be null", this.getDDFManager()); DDF ddf = this.getDDFManager().newDDF(); Assert.assertNotNull("DDF cannot be null", ddf); Assert.assertNotNull(ddf.getUUID()); DDF ddf2 = this.getTestDDF(); Assert.assertNotNull("DDF cannot be null", ddf2); }
@Test(expected = DDFException.class) public void testDDFManagerSetUUID() throws DDFException { DDF ddf = this.getTestDDF(); UUID uuid = ddf.getUUID(); DDFManager manager = getDDFManager(); UUID newUUID = UUID.randomUUID(); manager.setDDFUUID(ddf, newUUID); manager.getDDF(uuid); }
public DDF transformUDF(List<String> RExps, List<String> columns) throws DDFException { String sqlCmd = String.format("SELECT %s FROM %s", RToSqlUdf(RExps, columns, this.getDDF().getSchema().getColumns()), "{1}"); DDF newddf = this.getManager().sql2ddf(sqlCmd, new SQLDataSourceDescriptor(sqlCmd, null, null, null, this.getDDF() .getUUID().toString())); if (this.getDDF().isMutable()) { return this.getDDF().updateInplace(newddf); } else { newddf.getMetaDataHandler().copyFactor(this.getDDF()); return newddf; } }
@Test public void testSimpleSparkDDFManager() throws DDFException { createTableAirline(); List<String> l = manager.sql("select * from airline", false).getRows(); Assert.assertEquals(31, l.size()); List<String> v = manager.sql("select count(*) from airline", false).getRows(); Assert.assertEquals(1, v.size()); Assert.assertEquals("31", v.get(0)); DDF ddf = manager.sql2ddf("select year, month, dayofweek, deptime, arrtime,origin, distance, arrdelay, " + "depdelay, carrierdelay, weatherdelay, nasdelay, securitydelay, lateaircraftdelay from airline", false); Assert.assertEquals(14, ddf.getSummary().length); manager.setDDFName(ddf, "myddf"); manager.addDDF(ddf); Assert.assertEquals(ddf, manager.getDDF(ddf.getUUID())); } }