Same column names in Spark DataFrame supported, but how to select individually - non JOINed scenario
up vote
0
down vote
favorite
Given that we can see the same Col name in a dataframe below - as I noted elsewhere:
root
|-- week: string (nullable = true)
|-- dim1: integer (nullable = false)
|-- dim2: string (nullable = true)
|-- t1: integer (nullable = false)
|-- t2: integer (nullable = false)
|-- t3: integer (nullable = false)
|-- t1: integer (nullable = false)
|-- t2: integer (nullable = false)
|-- t3: integer (nullable = false)
|-- t1_diff: integer (nullable = false)
|-- t2_diff: integer (nullable = false)
and that:
df.select("t1").show(false)
returns ambiguous reference, then how can I state which one I want to select?
This is not a result of a JOIN, but just based on a Seq definition with .toDF(...) as follows:
val df = Seq(
("2016-04-02",14, null, 9784, 880, 23, 9789, 820, 45, -5, 60),
("2016-04-30",14, "FR", 9785, 13, 34, 9785, 9, 67, 90, 4),
("2016-04-16",14, "FR", 9785, 13, 34, 9785, 9, 67, -100, -123)
).toDF("week", "dim1", "dim2", "t1", "t2", "t3", "t1", "t2", "t3", "t1_diff", "t2_diff")
Somewhat inconsistent to me, and not something I would do, but I did note this, so more so out of curiosity. Seems an oversight?
apache-spark
add a comment |
up vote
0
down vote
favorite
Given that we can see the same Col name in a dataframe below - as I noted elsewhere:
root
|-- week: string (nullable = true)
|-- dim1: integer (nullable = false)
|-- dim2: string (nullable = true)
|-- t1: integer (nullable = false)
|-- t2: integer (nullable = false)
|-- t3: integer (nullable = false)
|-- t1: integer (nullable = false)
|-- t2: integer (nullable = false)
|-- t3: integer (nullable = false)
|-- t1_diff: integer (nullable = false)
|-- t2_diff: integer (nullable = false)
and that:
df.select("t1").show(false)
returns ambiguous reference, then how can I state which one I want to select?
This is not a result of a JOIN, but just based on a Seq definition with .toDF(...) as follows:
val df = Seq(
("2016-04-02",14, null, 9784, 880, 23, 9789, 820, 45, -5, 60),
("2016-04-30",14, "FR", 9785, 13, 34, 9785, 9, 67, 90, 4),
("2016-04-16",14, "FR", 9785, 13, 34, 9785, 9, 67, -100, -123)
).toDF("week", "dim1", "dim2", "t1", "t2", "t3", "t1", "t2", "t3", "t1_diff", "t2_diff")
Somewhat inconsistent to me, and not something I would do, but I did note this, so more so out of curiosity. Seems an oversight?
apache-spark
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Given that we can see the same Col name in a dataframe below - as I noted elsewhere:
root
|-- week: string (nullable = true)
|-- dim1: integer (nullable = false)
|-- dim2: string (nullable = true)
|-- t1: integer (nullable = false)
|-- t2: integer (nullable = false)
|-- t3: integer (nullable = false)
|-- t1: integer (nullable = false)
|-- t2: integer (nullable = false)
|-- t3: integer (nullable = false)
|-- t1_diff: integer (nullable = false)
|-- t2_diff: integer (nullable = false)
and that:
df.select("t1").show(false)
returns ambiguous reference, then how can I state which one I want to select?
This is not a result of a JOIN, but just based on a Seq definition with .toDF(...) as follows:
val df = Seq(
("2016-04-02",14, null, 9784, 880, 23, 9789, 820, 45, -5, 60),
("2016-04-30",14, "FR", 9785, 13, 34, 9785, 9, 67, 90, 4),
("2016-04-16",14, "FR", 9785, 13, 34, 9785, 9, 67, -100, -123)
).toDF("week", "dim1", "dim2", "t1", "t2", "t3", "t1", "t2", "t3", "t1_diff", "t2_diff")
Somewhat inconsistent to me, and not something I would do, but I did note this, so more so out of curiosity. Seems an oversight?
apache-spark
Given that we can see the same Col name in a dataframe below - as I noted elsewhere:
root
|-- week: string (nullable = true)
|-- dim1: integer (nullable = false)
|-- dim2: string (nullable = true)
|-- t1: integer (nullable = false)
|-- t2: integer (nullable = false)
|-- t3: integer (nullable = false)
|-- t1: integer (nullable = false)
|-- t2: integer (nullable = false)
|-- t3: integer (nullable = false)
|-- t1_diff: integer (nullable = false)
|-- t2_diff: integer (nullable = false)
and that:
df.select("t1").show(false)
returns ambiguous reference, then how can I state which one I want to select?
This is not a result of a JOIN, but just based on a Seq definition with .toDF(...) as follows:
val df = Seq(
("2016-04-02",14, null, 9784, 880, 23, 9789, 820, 45, -5, 60),
("2016-04-30",14, "FR", 9785, 13, 34, 9785, 9, 67, 90, 4),
("2016-04-16",14, "FR", 9785, 13, 34, 9785, 9, 67, -100, -123)
).toDF("week", "dim1", "dim2", "t1", "t2", "t3", "t1", "t2", "t3", "t1_diff", "t2_diff")
Somewhat inconsistent to me, and not something I would do, but I did note this, so more so out of curiosity. Seems an oversight?
apache-spark
apache-spark
edited Nov 17 at 14:31
asked Nov 17 at 14:18
thebluephantom
2,0832823
2,0832823
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53352067%2fsame-column-names-in-spark-dataframe-supported-but-how-to-select-individually%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown