@SuppressWarnings("unchecked") private DDF newDDF(Class<?>[] argTypes, Object[] argValues) throws DDFException { String className = Config.getValueWithGlobalDefault(this.getEngine(), ConfigConstant.FIELD_DDF); if (Strings.isNullOrEmpty(className)) throw new DDFException(String.format( "Cannot determine class name for [%s] %s", this.getEngine(), "DDF")); try { Constructor<DDF> cons = (Constructor<DDF>) Class.forName(className).getDeclaredConstructor(argTypes); if (cons == null) throw new DDFException("Cannot get constructor for " + className); cons.setAccessible(true); // make sure we can use it whether it's // private, protected, or public DDF ddf = cons.newInstance(argValues); if (ddf == null) throw new DDFException("Cannot instantiate a new instance of " + className); this.addDDF(ddf); return ddf; } catch (Exception e) { throw new DDFException(String.format( "While instantiating a new %s DDF of class %s with argTypes %s and argValues %s", this.getEngine(), className, Arrays.toString(argTypes), Arrays.toString(argValues)), e); } }
@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())); } }