@Override public void setFactorLevels(String columnName, Factor<?> factor) throws DDFException { Column c = this.getColumn(columnName); Factor<?> f = c.getOptionalFactor(); if(factor.getLevelCounts() != null) { f.setLevelCounts(factor.getLevelCounts()); } if(factor.getLevels() != null) { f.setLevels(factor.getLevels(), false); } }
public Map<String, Integer> getLevelMap() throws DDFException { if (mLevelMap == null) mLevelMap = this.computeLevelMap(); return mLevelMap; }
List<String> levels = new ArrayList(currentColumn.getOptionalFactor().getLevels()); currentColumn.getOptionalFactor().setLevels(levels, true); Map<String, Integer> currentColumnFactor = currentColumn.getOptionalFactor().getLevelMap(); Iterator<String> iterator = currentColumnFactor.keySet() .iterator();
Assert.assertEquals(2, newddf.getSchemaHandler().getColumn("dayofweek").getOptionalFactor().getLevelMap().size()); Assert.assertEquals(2, newddf2.getSchemaHandler().getColumn("dayofweek").getOptionalFactor().getLevelMap().size()); Assert.assertTrue(ddf1.getSchemaHandler().getColumn("month").getOptionalFactor().getLevelMap().get("[2,4]") > 0); Assert.assertEquals(ddf1.getSchemaHandler().getColumn("month").getOptionalFactor().getLevelCounts().get("[2,4]"), 6, 0); Assert.assertFalse(Strings.isNullOrEmpty(newddf.sql("select dayofweek from @this", "").getRows().get(0))); Assert.assertFalse(Strings.isNullOrEmpty(ddf1.sql("select month from @this", "").getRows().get(0))); mi = mi.setFactor(col.getOptionalFactor().getLevelMap()); Assert.assertTrue(mi.hasFactor());
@Test public void testReservedFactor() throws DDFException { ddf.setAsFactor("year"); ddf.setAsFactor("month"); Assert.assertTrue(ddf.getSchema() != null); System.out.println(">>>>> column class = " + ddf.getColumn("year").getColumnClass()); System.out.println(">>>>> column class = " + ddf.getColumn("month").getColumnClass()); Assert.assertTrue(ddf.getColumn("year").getColumnClass() == Schema.ColumnClass.FACTOR); Assert.assertTrue(ddf.getColumn("month").getColumnClass() == Schema.ColumnClass.FACTOR); ddf.setMutable(true); ddf = ddf.Transform.transformUDF("test123= round(distance/2, 2)"); Assert.assertEquals(31, ddf.getNumRows()); Assert.assertEquals(9, ddf.getNumColumns()); Assert.assertEquals("test123", ddf.getColumnName(8)); Assert.assertEquals(9, ddf.VIEWS.head(1).get(0).split("\\t").length); System.out.println(">>>>> column class = " + ddf.getColumn("year").getColumnClass()); System.out.println(">>>>> column class = " + ddf.getColumn("month").getColumnClass()); Assert.assertTrue(ddf.getColumn("year").getColumnClass() == Schema.ColumnClass.FACTOR); Assert.assertTrue(ddf.getColumn("month").getColumnClass() == Schema.ColumnClass.FACTOR); Assert.assertTrue(ddf.getColumn("year").getOptionalFactor().getLevels().size() > 0); Assert.assertTrue(ddf.getColumn("month").getOptionalFactor().getLevels().size() > 0); System.out.println(">>>>>>>>>>>>> " + ddf.getSchema().getColumns()); }
/** * Typically, levels are automatically computed from the data, but in some rare instances, the user may want to * specify the levels explicitly, e.g., when the data column does not contain all the levels desired. * * @param levels * @param isOrdered a flag indicating whether the levels actually have "less than" and "greater than" left-to-right order * meaning * @throws DDFException */ public void setLevels(List<String> levels, boolean isOrdered) throws DDFException { this.setLevels(levels, null, isOrdered); }
/** * Similar to setLevels(levels, isOrdered), * * @param levels * @param codes * @param isOrdered a flag indicating whether the levels actually have "less than" and "greater than" left-to-right order * meaning * @throws DDFException */ public void setLevels(List<String> levels, List<Integer> codes, boolean isOrdered) throws DDFException { if (levels == null || levels.isEmpty()) throw new DDFException("Levels cannot be null or empty"); if (codes != null && codes.size() != levels.size()) throw new DDFException(String.format( "The number of levels is %d which does not match the number of codes %d", levels.size(), codes.size())); if (mLevelMap == null) mLevelMap = this.instantiateSynchronizedLevelMap(); if (codes == null) { // Auto-create a 1-based level-code map codes = new ArrayList<Integer>(); for (int i = 1; i <= levels.size(); i++) { codes.add(i); } } Iterator<String> levelIter = levels.iterator(); Iterator<Integer> codeIter = codes.iterator(); while (levelIter.hasNext()) { mLevelMap.put(levelIter.next(), codeIter.next()); } this.mLevels = new ArrayList<String>(levels); this.setOrdered(isOrdered); }
public static MetaInfo[] generateMetaInfo(Schema schema) throws DDFException { List<Column> columns = schema.getColumns(); MetaInfo[] metaInfo = new MetaInfo[columns.size()]; for (int i = 0; i < columns.size(); i++) { metaInfo[i] = new MetaInfo(columns.get(i).getName(), columns.get(i).getType().toString().toLowerCase()); if (columns.get(i).getColumnClass() == ColumnClass.FACTOR) { metaInfo[i] = metaInfo[i].setFactor(columns.get(i).getOptionalFactor().getLevelMap()); } } return metaInfo; }
switch (column.getType()) { case DOUBLE: factor = new Factor<Double>(this.getDDF(), columnName); break; case FLOAT: factor = new Factor<Float>(this.getDDF(), columnName); break; case INT: factor = new Factor<Integer>(this.getDDF(), columnName); break; case BIGINT: factor = new Factor<Long>(this.getDDF(), columnName); break; case BOOLEAN: factor = new Factor<Boolean>(this.getDDF(), columnName); break; case STRING: factor = new Factor<String>(this.getDDF(), columnName); break; case TIMESTAMP: factor = new Factor<Timestamp>(this.getDDF(), columnName); break; case BLOB: default: factor = new Factor<Object>(this.getDDF(), columnName); break;
public void setLevels(List<String> levels) throws DDFException { this.setLevels(levels, null, false); // with default values for level codes and isOrdered }
Factor<?> colFactor = col.getOptionalFactor(); if (colFactor == null || colFactor.getLevelCounts() == null || colFactor.getLevels() == null) { if (colFactor == null) { colFactor = this.setAsFactor(col.getName()); Factor<?> factor = column.getOptionalFactor(); List<String> levels = new ArrayList<String>(levelCounts.keySet()); factor.setLevelCounts(levelCounts); factor.setLevels(levels, false);