我已阅读了几篇帖子,似乎无法找到解决方案。我有这个自定义类:
public class DBValues
{
public DateTime DB_MfgDateTime;
public string DB_PartNumber;
public string DB_LotNumber;
public string DB_BayResult;
public string DB_BrakeSwitch;
public string DB_SpeedSwitch;
public string DB_RTC;
public string DB_RFID;
public string DB_TestSpin;
public string DB_LEDs;
public int DB_LedADC;
public string DB_48Vstate;
public double DB_48V;
public string DB_12Vstate;
public double DB_12V;
public double DB_PLCV;
public double DB_OpAmpV;
public string DB_HandleUID;
public string DB_StationID;
public string DB_BayNumber;
public string DB_VerifyMfgInfo;
public DateTime DB_BuildTime;
public string DB_FWVerify;
public string DB_FWVersion;};
DBValues db = new DBValues();
在整个过程中我分配如下值:db.DB_SpeedSwitch =“PASS”;我不想从根本上改变我分配值的方式,但我想为调试目的吐出值。类似的东西:
foreach (var val in db)
{
Debug.WriteLine(val.ToString();
}
我已经尝试实现IEnumerable并创建一个新的DBValues列表,但我得到了关闭,但是我的GetEnumerator使用了OverflowException。我弄清楚为什么会这样,但不知道如何解决它。我读到了一个关于预告和收益率的回报,但这也没有成功。
public IEnumerator<DBValues> GetEnumerator()
{
//throw new NotImplementedException();
foreach (var item in ??????)
{
yield return item;
}
//return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
//throw new NotImplementedException();
return GetEnumerator();
}
需要一些帮助!
答案 0 :(得分:3)
您可以将反射用于此类目的。尝试这样的事情:
import org.apache.spark.sql.expressions.Window.partitionBy
import org.apache.spark.sql.functions.first
myDF.
select(
$"COL1",
$"BUCKET",
count($"BUCKET").over(partitionBy($"COL1").orderBy($"BUCKET")).as("ROLLING_COUNT")).
groupBy($"COL1").pivot("BUCKET").agg(first("ROLLING_COUNT")).
show()
+----+---+---+---+---+
|COL1| 0| 1| 2| 3|
+----+---+---+---+---+
| bar| 1| 2| 3| 4|
| foo| 2| 4| 5| 6|
+----+---+---+---+---+