-
Notifications
You must be signed in to change notification settings - Fork 72
Support for scalar subquery #157
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d2568de
WIP
wzheng 2573a90
Functions for encrypting/decrypting scalar values
wzheng cb1320b
WIP
wzheng 3ceb05e
Adding the Decrypt expression
wzheng 8e0b011
WIP
wzheng 1376362
Merge branch 'master' of github.com:mc2-project/opaque into scalar-su…
wzheng 4e630ed
Modified Decrypt expression to be nondeterministic
wzheng f741a52
Encrypted literal works
wzheng 0509786
WIP
wzheng e682a89
Scalar subquery unit test passes
wzheng 759b2c7
More TPC-H queries supported
wzheng f123077
Also turn on TPC-H 4
wzheng 6c7ff1b
Debug message
wzheng 4b57ad0
Add checks for block length
wzheng 0b14b3b
Add expression description
wzheng 2302f65
Change decrypt impl
wzheng f8ce981
Address comments
wzheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,3 +142,79 @@ int secs_to_tm(long long t, struct tm *tm) { | |
|
||
return 0; | ||
} | ||
|
||
// Code adapted from https://stackoverflow.com/questions/180947/base64-decode-snippet-in-c | ||
/* | ||
Copyright (C) 2004-2008 Rene Nyffenegger | ||
|
||
This source code is provided 'as-is', without any express or implied | ||
warranty. In no event will the author be held liable for any damages | ||
arising from the use of this software. | ||
|
||
Permission is granted to anyone to use this software for any purpose, | ||
including commercial applications, and to alter it and redistribute it | ||
freely, subject to the following restrictions: | ||
|
||
1. The origin of this source code must not be misrepresented; you must not | ||
claim that you wrote the original source code. If you use this source code | ||
in a product, an acknowledgment in the product documentation would be | ||
appreciated but is not required. | ||
|
||
2. Altered source versions must be plainly marked as such, and must not be | ||
misrepresented as being the original source code. | ||
|
||
3. This notice may not be removed or altered from any source distribution. | ||
|
||
Rene Nyffenegger [email protected] | ||
|
||
*/ | ||
|
||
static const std::string base64_chars = | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
"abcdefghijklmnopqrstuvwxyz" | ||
"0123456789+/"; | ||
|
||
static inline bool is_base64(unsigned char c) { | ||
return (isalnum(c) || (c == '+') || (c == '/')); | ||
} | ||
|
||
std::string ciphertext_base64_decode(const std::string &encoded_string) { | ||
int in_len = encoded_string.size(); | ||
int i = 0; | ||
int j = 0; | ||
int in_ = 0; | ||
uint8_t char_array_4[4], char_array_3[3]; | ||
std::string ret; | ||
|
||
while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { | ||
char_array_4[i++] = encoded_string[in_]; in_++; | ||
if (i ==4) { | ||
for (i = 0; i <4; i++) | ||
char_array_4[i] = base64_chars.find(char_array_4[i]); | ||
|
||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); | ||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); | ||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; | ||
|
||
for (i = 0; (i < 3); i++) | ||
ret += char_array_3[i]; | ||
i = 0; | ||
} | ||
} | ||
|
||
if (i) { | ||
for (j = i; j <4; j++) | ||
char_array_4[j] = 0; | ||
|
||
for (j = 0; j <4; j++) | ||
char_array_4[j] = base64_chars.find(char_array_4[j]); | ||
|
||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); | ||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); | ||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; | ||
|
||
for (j = 0; (j < i - 1); j++) ret += char_array_3[j]; | ||
} | ||
|
||
return ret; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/scala/edu/berkeley/cs/rise/opaque/expressions/Decrypt.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package edu.berkeley.cs.rise.opaque.expressions | ||
|
||
import edu.berkeley.cs.rise.opaque.Utils | ||
|
||
import org.apache.spark.sql.Column | ||
import org.apache.spark.sql.catalyst.InternalRow | ||
import org.apache.spark.sql.catalyst.expressions.Expression | ||
import org.apache.spark.sql.catalyst.expressions.ExpressionDescription | ||
import org.apache.spark.sql.catalyst.expressions.NullIntolerant | ||
import org.apache.spark.sql.catalyst.expressions.Nondeterministic | ||
import org.apache.spark.sql.catalyst.expressions.UnaryExpression | ||
import org.apache.spark.sql.catalyst.expressions.codegen.CodegenFallback | ||
import org.apache.spark.sql.types.DataType | ||
import org.apache.spark.sql.types.DataTypes | ||
import org.apache.spark.sql.types.StringType | ||
import org.apache.spark.unsafe.types.UTF8String | ||
|
||
object Decrypt { | ||
def decrypt(v: Column, dataType: DataType): Column = new Column(Decrypt(v.expr, dataType)) | ||
} | ||
|
||
@ExpressionDescription( | ||
usage = """ | ||
_FUNC_(child, outputDataType) - Decrypt the input evaluated expression, which should always be a string | ||
""", | ||
arguments = """ | ||
Arguments: | ||
* child - an encrypted literal of string type | ||
* outputDataType - the decrypted data type | ||
""") | ||
case class Decrypt(child: Expression, outputDataType: DataType) | ||
extends UnaryExpression with NullIntolerant with CodegenFallback with Nondeterministic { | ||
|
||
override def dataType: DataType = outputDataType | ||
|
||
protected def initializeInternal(partitionIndex: Int): Unit = { } | ||
|
||
protected override def evalInternal(input: InternalRow): Any = { | ||
val v = child.eval() | ||
nullSafeEval(v) | ||
} | ||
|
||
protected override def nullSafeEval(input: Any): Any = { | ||
// This function is implemented so that we can test against Spark; | ||
// should never be used in production because we want to keep the literal encrypted | ||
val v = input.asInstanceOf[UTF8String].toString | ||
Utils.decryptScalar(v) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe include a comment stating that this should never be evaluated on the driver?