Skip to content

Commit bde169c

Browse files
authored
[Improvement][Spark] Complement the error messages of spark SDK (#278)
1 parent 3463072 commit bde169c

12 files changed

Lines changed: 134 additions & 49 deletions

File tree

spark/src/main/scala/com/alibaba/graphar/EdgeInfo.scala

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ class EdgeInfo() {
7575
return str
7676
}
7777
}
78-
throw new IllegalArgumentException
78+
throw new IllegalArgumentException(
79+
"adj list type not found: " + AdjListType.AdjListTypeToString(
80+
adj_list_type
81+
)
82+
)
7983
}
8084

8185
/**
@@ -95,7 +99,11 @@ class EdgeInfo() {
9599
return adj_list.getFile_type_in_gar
96100
}
97101
}
98-
throw new IllegalArgumentException
102+
throw new IllegalArgumentException(
103+
"adj list type not found: " + AdjListType.AdjListTypeToString(
104+
adj_list_type
105+
)
106+
)
99107
}
100108

101109
/**
@@ -117,7 +125,11 @@ class EdgeInfo() {
117125
return adj_list.getProperty_groups
118126
}
119127
}
120-
throw new IllegalArgumentException
128+
throw new IllegalArgumentException(
129+
"adj list type not found: " + AdjListType.AdjListTypeToString(
130+
adj_list_type
131+
)
132+
)
121133
}
122134

123135
/**
@@ -213,10 +225,18 @@ class EdgeInfo() {
213225
return pg
214226
}
215227
}
228+
throw new IllegalArgumentException(
229+
"property group not found: " + property_name + " in adj list type: " + AdjListType
230+
.AdjListTypeToString(
231+
adj_list_type
232+
)
233+
)
216234
}
217235
}
218236
}
219-
throw new IllegalArgumentException
237+
throw new IllegalArgumentException(
238+
"adj list type or property group not found."
239+
)
220240
}
221241

222242
/**
@@ -245,7 +265,7 @@ class EdgeInfo() {
245265
}
246266
}
247267
}
248-
throw new IllegalArgumentException
268+
throw new IllegalArgumentException("property not found: " + property_name)
249269
}
250270

251271
/**
@@ -275,7 +295,7 @@ class EdgeInfo() {
275295
}
276296
}
277297
}
278-
throw new IllegalArgumentException
298+
throw new IllegalArgumentException("property not found: " + property_name)
279299
}
280300

281301
/** Get Primary key of edge info. */
@@ -337,7 +357,11 @@ class EdgeInfo() {
337357
*/
338358
def getVerticesNumFilePath(adj_list_type: AdjListType.Value): String = {
339359
if (containAdjList(adj_list_type) == false) {
340-
throw new IllegalArgumentException
360+
throw new IllegalArgumentException(
361+
"adj list type not found: " + AdjListType.AdjListTypeToString(
362+
adj_list_type
363+
)
364+
)
341365
}
342366
val str: String = prefix + getAdjListPrefix(adj_list_type) + "vertex_count"
343367
return str
@@ -354,7 +378,11 @@ class EdgeInfo() {
354378
*/
355379
def getEdgesNumPathPrefix(adj_list_type: AdjListType.Value): String = {
356380
if (containAdjList(adj_list_type) == false) {
357-
throw new IllegalArgumentException
381+
throw new IllegalArgumentException(
382+
"adj list type not found: " + AdjListType.AdjListTypeToString(
383+
adj_list_type
384+
)
385+
)
358386
}
359387
val str: String = prefix + getAdjListPrefix(adj_list_type) + "edge_count"
360388
return str
@@ -376,7 +404,11 @@ class EdgeInfo() {
376404
adj_list_type: AdjListType.Value
377405
): String = {
378406
if (containAdjList(adj_list_type) == false) {
379-
throw new IllegalArgumentException
407+
throw new IllegalArgumentException(
408+
"adj list type not found: " + AdjListType.AdjListTypeToString(
409+
adj_list_type
410+
)
411+
)
380412
}
381413
val str: String = prefix + getAdjListPrefix(adj_list_type) + "edge_count" +
382414
chunk_index.toString()
@@ -400,7 +432,11 @@ class EdgeInfo() {
400432
adj_list_type: AdjListType.Value
401433
): String = {
402434
if (containAdjList(adj_list_type) == false) {
403-
throw new IllegalArgumentException
435+
throw new IllegalArgumentException(
436+
"adj list type not found: " + AdjListType.AdjListTypeToString(
437+
adj_list_type
438+
)
439+
)
404440
}
405441
val str: String =
406442
prefix + getAdjListPrefix(adj_list_type) + "offset/chunk" +
@@ -419,7 +455,11 @@ class EdgeInfo() {
419455
*/
420456
def getOffsetPathPrefix(adj_list_type: AdjListType.Value): String = {
421457
if (containAdjList(adj_list_type) == false) {
422-
throw new IllegalArgumentException
458+
throw new IllegalArgumentException(
459+
"adj list type not found: " + AdjListType.AdjListTypeToString(
460+
adj_list_type
461+
)
462+
)
423463
}
424464
return prefix + getAdjListPrefix(adj_list_type) + "offset/"
425465
}
@@ -503,7 +543,7 @@ class EdgeInfo() {
503543
chunk_index: Long
504544
): String = {
505545
if (containPropertyGroup(property_group, adj_list_type) == false)
506-
throw new IllegalArgumentException
546+
throw new IllegalArgumentException("property group not found.")
507547
var str: String = property_group.getPrefix
508548
if (str == "") {
509549
val properties = property_group.getProperties
@@ -540,7 +580,7 @@ class EdgeInfo() {
540580
vertex_chunk_index: Long
541581
): String = {
542582
if (containPropertyGroup(property_group, adj_list_type) == false)
543-
throw new IllegalArgumentException
583+
throw new IllegalArgumentException("property group not found.")
544584
var str: String = property_group.getPrefix
545585
if (str == "") {
546586
val properties = property_group.getProperties
@@ -573,7 +613,7 @@ class EdgeInfo() {
573613
adj_list_type: AdjListType.Value
574614
): String = {
575615
if (containPropertyGroup(property_group, adj_list_type) == false)
576-
throw new IllegalArgumentException
616+
throw new IllegalArgumentException("property group not found.")
577617
var str: String = property_group.getPrefix
578618
if (str == "") {
579619
val properties = property_group.getProperties

spark/src/main/scala/com/alibaba/graphar/GraphInfo.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ object GarType extends Enumeration {
6363
case GarType.DOUBLE => "double"
6464
case GarType.STRING => "string"
6565
case GarType.ARRAY => "array"
66-
case _ => throw new IllegalArgumentException
66+
case _ => throw new IllegalArgumentException("Unknown data type")
6767
}
6868

6969
/**
@@ -82,7 +82,7 @@ object GarType extends Enumeration {
8282
case "double" => GarType.DOUBLE
8383
case "string" => GarType.STRING
8484
case "array" => GarType.ARRAY
85-
case _ => throw new IllegalArgumentException
85+
case _ => throw new IllegalArgumentException("Unknown data type: " + str)
8686
}
8787
}
8888

@@ -105,7 +105,7 @@ object FileType extends Enumeration {
105105
case FileType.CSV => "csv"
106106
case FileType.PARQUET => "parquet"
107107
case FileType.ORC => "orc"
108-
case _ => throw new IllegalArgumentException
108+
case _ => throw new IllegalArgumentException("Unknown file type")
109109
}
110110

111111
/**
@@ -120,7 +120,7 @@ object FileType extends Enumeration {
120120
case "csv" => FileType.CSV
121121
case "parquet" => FileType.PARQUET
122122
case "orc" => FileType.ORC
123-
case _ => throw new IllegalArgumentException
123+
case _ => throw new IllegalArgumentException("Unknown file type: " + str)
124124
}
125125

126126
}
@@ -155,7 +155,7 @@ object AdjListType extends Enumeration {
155155
case AdjListType.unordered_by_dest => "unordered_by_dest"
156156
case AdjListType.ordered_by_source => "ordered_by_source"
157157
case AdjListType.ordered_by_dest => "ordered_by_dest"
158-
case _ => throw new IllegalArgumentException
158+
case _ => throw new IllegalArgumentException("Unknown adjList type")
159159
}
160160

161161
/** String to adjList type in gar */
@@ -164,7 +164,7 @@ object AdjListType extends Enumeration {
164164
case "unordered_by_dest" => AdjListType.unordered_by_dest
165165
case "ordered_by_source" => AdjListType.ordered_by_source
166166
case "ordered_by_dest" => AdjListType.ordered_by_dest
167-
case _ => throw new IllegalArgumentException
167+
case _ => throw new IllegalArgumentException("Unknown adjList type: " + str)
168168
}
169169
}
170170

spark/src/main/scala/com/alibaba/graphar/VertexInfo.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class VertexInfo() {
9393
}
9494
}
9595
}
96-
throw new IllegalArgumentException
96+
throw new IllegalArgumentException("Property not found: " + property_name)
9797
}
9898

9999
/**
@@ -117,7 +117,7 @@ class VertexInfo() {
117117
}
118118
}
119119
}
120-
throw new IllegalArgumentException
120+
throw new IllegalArgumentException("Property not found: " + property_name)
121121
}
122122

123123
/**
@@ -141,7 +141,7 @@ class VertexInfo() {
141141
}
142142
}
143143
}
144-
throw new IllegalArgumentException
144+
throw new IllegalArgumentException("Property not found: " + property_name)
145145
}
146146

147147
/**
@@ -205,7 +205,7 @@ class VertexInfo() {
205205
*/
206206
def getFilePath(property_group: PropertyGroup, chunk_index: Long): String = {
207207
if (containPropertyGroup(property_group) == false) {
208-
throw new IllegalArgumentException
208+
throw new IllegalArgumentException("Property group not found.")
209209
}
210210
var str: String = ""
211211
if (property_group.getPrefix == "") {
@@ -234,7 +234,7 @@ class VertexInfo() {
234234
*/
235235
def getPathPrefix(property_group: PropertyGroup): String = {
236236
if (containPropertyGroup(property_group) == false) {
237-
throw new IllegalArgumentException
237+
throw new IllegalArgumentException("Property group not found.")
238238
}
239239
var str: String = ""
240240
if (property_group.getPrefix == "") {

spark/src/main/scala/com/alibaba/graphar/datasources/GarScan.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ case class GarScan(
7272
case "csv" => createCSVReaderFactory()
7373
case "orc" => createOrcReaderFactory()
7474
case "parquet" => createParquetReaderFactory()
75-
case _ => throw new IllegalArgumentException
75+
case _ =>
76+
throw new IllegalArgumentException("Invalid format name: " + formatName)
7677
}
7778

7879
// Create the reader factory for the CSV format.
@@ -269,7 +270,8 @@ case class GarScan(
269270
case "csv" => super.hashCode()
270271
case "orc" => getClass.hashCode()
271272
case "parquet" => getClass.hashCode()
272-
case _ => throw new IllegalArgumentException
273+
case _ =>
274+
throw new IllegalArgumentException("Invalid format name: " + formatName)
273275
}
274276

275277
/** Get the description string of the object. */

spark/src/main/scala/com/alibaba/graphar/datasources/GarScanBuilder.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ case class GarScanBuilder(
5555
case "csv" => Array.empty[Filter]
5656
case "orc" => pushedOrcFilters
5757
case "parquet" => pushedParquetFilters
58-
case _ => throw new IllegalArgumentException
58+
case _ =>
59+
throw new IllegalArgumentException("Invalid format name: " + formatName)
5960
}
6061

6162
private lazy val pushedParquetFilters: Array[Filter] = {
@@ -87,7 +88,8 @@ case class GarScanBuilder(
8788
case "orc" => sparkSession.sessionState.conf.nestedSchemaPruningEnabled
8889
case "parquet" =>
8990
sparkSession.sessionState.conf.nestedSchemaPruningEnabled
90-
case _ => throw new IllegalArgumentException
91+
case _ =>
92+
throw new IllegalArgumentException("Invalid format name: " + formatName)
9193
}
9294

9395
/** Build the file scan for GarDataSource. */

spark/src/main/scala/com/alibaba/graphar/datasources/GarTable.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ case class GarTable(
8181
OrcUtils.inferSchema(sparkSession, files, options.asScala.toMap)
8282
case "parquet" =>
8383
ParquetUtils.inferSchema(sparkSession, options.asScala.toMap, files)
84-
case _ => throw new IllegalArgumentException
84+
case _ =>
85+
throw new IllegalArgumentException("Invalid format name: " + formatName)
8586
}
8687

8788
/** Construct a new write builder according to the actual file format. */
@@ -93,7 +94,8 @@ case class GarTable(
9394
new OrcWriteBuilder(paths, formatName, supportsDataType, info)
9495
case "parquet" =>
9596
new ParquetWriteBuilder(paths, formatName, supportsDataType, info)
96-
case _ => throw new IllegalArgumentException
97+
case _ =>
98+
throw new IllegalArgumentException("Invalid format name: " + formatName)
9799
}
98100

99101
/**

spark/src/main/scala/com/alibaba/graphar/graph/GraphTransformer.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ object GraphTransformer {
5959
// load source vertex info
6060
val label = dest_vertex_info.getLabel()
6161
if (!sourceVertexInfosMap.contains(label)) {
62-
throw new IllegalArgumentException
62+
throw new IllegalArgumentException(
63+
"vertex info of " + label + " not found in graph info."
64+
)
6365
}
6466
val source_vertex_info = sourceVertexInfosMap(label)
6567
// read vertex chunks from the source graph
@@ -105,7 +107,9 @@ object GraphTransformer {
105107
// load source edge info
106108
val key = dest_edge_info.getConcatKey()
107109
if (!sourceEdgeInfosMap.contains(key)) {
108-
throw new IllegalArgumentException
110+
throw new IllegalArgumentException(
111+
"edge info of " + key + " not found in graph info."
112+
)
109113
}
110114
val source_edge_info = sourceEdgeInfosMap(key)
111115
var has_loaded = false
@@ -146,7 +150,9 @@ object GraphTransformer {
146150
dest_edge_info.getDst_label
147151
}
148152
if (!sourceVertexInfosMap.contains(vertex_label)) {
149-
throw new IllegalArgumentException
153+
throw new IllegalArgumentException(
154+
"vertex info of " + vertex_label + " not found in graph info."
155+
)
150156
}
151157
val vertex_info = sourceVertexInfosMap(vertex_label)
152158
val reader = new VertexReader(source_prefix, vertex_info, spark)

spark/src/main/scala/com/alibaba/graphar/graph/GraphWriter.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class GraphWriter() {
4747
primaryKey: String = ""
4848
): Unit = {
4949
if (vertices.exists(_._1 == label)) {
50-
throw new IllegalArgumentException
50+
throw new IllegalArgumentException(
51+
"Vertex data of label " + label + " has been put."
52+
)
5153
}
5254
vertices += label -> df
5355
vertexNums += label -> df.count
@@ -63,7 +65,9 @@ class GraphWriter() {
6365
*/
6466
def PutEdgeData(relation: (String, String, String), df: DataFrame): Unit = {
6567
if (edges.exists(_._1 == relation)) {
66-
throw new IllegalArgumentException
68+
throw new IllegalArgumentException(
69+
"Edge data of relation " + relation + " has been put."
70+
)
6771
}
6872
edges += relation -> df
6973
}
@@ -195,7 +199,7 @@ class GraphWriter() {
195199
case (key, df) => {
196200
edge_schemas += key -> new StructType(
197201
df.schema.drop(2).toArray
198-
) // drop the src, dst fileds
202+
) // drop the src, dst fields
199203
}
200204
}
201205
val graph_info = Utils.generateGraphInfo(

0 commit comments

Comments
 (0)