forked from vmware/differential-datalog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQL compiler: Use interned strings (vmware#1148)
Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
- Loading branch information
Mihai Budiu
authored
Feb 11, 2022
1 parent
c4e297a
commit 327861e
Showing
21 changed files
with
379 additions
and
235 deletions.
There are no files selected for viewing
This file contains 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 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 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,51 @@ | ||
/* | ||
* Copyright (c) 2021 VMware, Inc. | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
package com.vmware.ddlog.ir; | ||
|
||
import com.facebook.presto.sql.tree.Node; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* An expression that is an interned string. | ||
*/ | ||
public class DDlogEIString extends DDlogExpression { | ||
private final String string; | ||
|
||
public DDlogEIString(@Nullable Node node, String string) { | ||
super(node, DDlogTIString.instance); | ||
if (string.startsWith("'") && string.endsWith("'")) | ||
string = string.substring(1, string.length() - 1); | ||
this.string = string; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (this.string.contains("${")) { | ||
return "i[|" + this.string + "|]"; | ||
} | ||
return "i\"" + this.string + "\""; | ||
} | ||
} |
This file contains 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,63 @@ | ||
/* | ||
* Copyright (c) 2021 VMware, Inc. | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
package com.vmware.ddlog.ir; | ||
|
||
import com.facebook.presto.sql.tree.Node; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Interned string type. | ||
*/ | ||
public class DDlogTIString extends DDlogType implements IDDlogBaseType { | ||
public static DDlogTIString instance = new DDlogTIString(null,false); | ||
|
||
private DDlogTIString(@Nullable Node node, boolean mayBeNull) { super(node, mayBeNull); } | ||
|
||
@Override | ||
public String toString() { return this.wrapOption("istring"); } | ||
|
||
@Override | ||
public DDlogType setMayBeNull(boolean mayBeNull) { | ||
if (this.mayBeNull == mayBeNull) | ||
return this; | ||
return new DDlogTIString(this.getNode(), mayBeNull); | ||
} | ||
|
||
@Override | ||
public boolean same(DDlogType type) { | ||
if (!super.same(type)) | ||
return false; | ||
return type.is(DDlogTIString.class); | ||
} | ||
|
||
/** | ||
* Given an expression with type istring unwrap the istring | ||
*/ | ||
public static DDlogExpression ival(DDlogExpression expression) { | ||
assert(expression.getType().is(DDlogTIString.class)); | ||
return new DDlogEApply(expression.node, "ival", DDlogTString.instance, true, expression); | ||
} | ||
} |
This file contains 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 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 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 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 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
Oops, something went wrong.