Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pattern matching in PayloadHelper.cs to improve readability #1003

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 10 additions & 38 deletions src/csharp/Microsoft.Spark/Interop/Ipc/PayloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,6 @@ internal static byte[] GetTypeId(Type type)
case TypeCode.Double:
return s_doubleTypeId;
case TypeCode.Object:
if (typeof(IJvmObjectReferenceProvider).IsAssignableFrom(type))
{
return s_jvmObjectTypeId;
}

if (type == typeof(byte[]))
{
return s_byteArrayTypeId;
}

if (type == typeof(int[]) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be included in the switch expression ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a super long logical expression that would not fit well into that format
Screenshot 2021-12-08 at 01 28 40

type == typeof(long[]) ||
Expand All @@ -343,36 +334,17 @@ internal static byte[] GetTypeId(Type type)
return s_arrayTypeId;
}

if (IsDictionary(type))
{
return s_dictionaryTypeId;
}

if (typeof(IEnumerable<IJvmObjectReferenceProvider>).IsAssignableFrom(type))
{
return s_arrayTypeId;
}

if (typeof(IEnumerable<GenericRow>).IsAssignableFrom(type))
{
return s_rowArrTypeId;
}

if (typeof(IEnumerable<object>).IsAssignableFrom(type))
return type switch
{
return s_objectArrTypeId;
}

if (typeof(Date).IsAssignableFrom(type))
{
return s_dateTypeId;
}

if (typeof(Timestamp).IsAssignableFrom(type))
{
return s_timestampTypeId;
}
break;
_ when typeof(IJvmObjectReferenceProvider).IsAssignableFrom(type) => s_jvmObjectTypeId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some of these lines are too long. Can you check https://github.com/dotnet/spark/blob/main/docs/coding-guidelines/csharp-coding-style.md ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is exactly at the limit
Screenshot 2021-12-08 at 01 23 42

_ when type == typeof(byte[]) => s_byteArrayTypeId,
_ when IsDictionary(type) => s_dictionaryTypeId,
_ when typeof(IEnumerable<IJvmObjectReferenceProvider>).IsAssignableFrom(type) => s_arrayTypeId,
_ when typeof(IEnumerable<GenericRow>).IsAssignableFrom(type) => s_rowArrTypeId,
_ when typeof(IEnumerable<object>).IsAssignableFrom(type) => s_objectArrTypeId,
_ when typeof(Date).IsAssignableFrom(type) => s_dateTypeId,
_ when typeof(Timestamp).IsAssignableFrom(type) => s_timestampTypeId,
};
}

// TODO: Support other types.
Expand Down