-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathPlanBuilderBaseImpl.java
More file actions
212 lines (185 loc) · 6.92 KB
/
Copy pathPlanBuilderBaseImpl.java
File metadata and controls
212 lines (185 loc) · 6.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
package com.marklogic.client.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.marklogic.client.DatabaseClientFactory.HandleFactoryRegistry;
import com.marklogic.client.expression.PlanBuilder;
import com.marklogic.client.io.Format;
import com.marklogic.client.io.StringHandle;
import com.marklogic.client.io.marker.AbstractWriteHandle;
import com.marklogic.client.type.*;
abstract class PlanBuilderBaseImpl extends PlanBuilder {
final static PlanBuilderSubImpl pb = new PlanBuilderSubImpl();
private HandleFactoryRegistry handleRegistry;
PlanBuilderBaseImpl() {
super(
CtsExprImpl.cts, FnExprImpl.fn, GeoExprImpl.geo, JsonExprImpl.json, MapExprImpl.map,
MathExprImpl.math, RdfExprImpl.rdf, SemExprImpl.sem, SpellExprImpl.spell,
SqlExprImpl.sql, VecExprImpl.vec, XdmpExprImpl.xdmp, XsExprImpl.xs, RdtExprImpl.rdt
);
}
HandleFactoryRegistry getHandleRegistry() {
return handleRegistry;
}
void setHandleRegistry(HandleFactoryRegistry handleRegistry) {
this.handleRegistry = handleRegistry;
}
public PlanColumn exprCol(String column) {
return col(column);
}
static BaseTypeImpl.Literal literal(Object value) {
return new BaseTypeImpl.Literal(value);
}
@Override
public PlanSearchOptions searchOptions() {
return new PlanSearchOptionsImpl(this);
}
static class PlanSearchOptionsImpl implements PlanSearchOptions {
private PlanBuilderBaseImpl pb;
private XsFloatVal qualityWeight;
private ScoreMethod scoreMethod;
private XsDoubleVal bm25LengthWeight;
private Fragment fragment;
PlanSearchOptionsImpl(PlanBuilderBaseImpl pb) {
this.pb = pb;
}
PlanSearchOptionsImpl(PlanBuilderBaseImpl pb, XsFloatVal qualityWeight,
ScoreMethod scoreMethod, XsDoubleVal bm25LengthWeight,
Fragment fragment) {
this(pb);
this.qualityWeight = qualityWeight;
this.scoreMethod = scoreMethod;
this.bm25LengthWeight = bm25LengthWeight;
this.fragment = fragment;
}
@Override
public XsFloatVal getQualityWeight() {
return qualityWeight;
}
@Override
public ScoreMethod getScoreMethod() {
return scoreMethod;
}
@Override
public XsDoubleVal getBm25LengthWeight() {
return bm25LengthWeight;
}
@Override
public Fragment getFragment() {
return fragment;
}
@Override
public PlanSearchOptions withQualityWeight(float qualityWeight) {
return withQualityWeight(pb.xs.floatVal(qualityWeight));
}
@Override
public PlanSearchOptions withQualityWeight(XsFloatVal qualityWeight) {
return new PlanSearchOptionsImpl(pb, qualityWeight, getScoreMethod(), getBm25LengthWeight(), getFragment());
}
@Override
public PlanSearchOptions withScoreMethod(ScoreMethod scoreMethod) {
return new PlanSearchOptionsImpl(pb, getQualityWeight(), scoreMethod, getBm25LengthWeight(), getFragment());
}
@Override
public PlanSearchOptions withBm25LengthWeight(double bm25LengthWeight) {
return new PlanSearchOptionsImpl(pb, getQualityWeight(), getScoreMethod(), pb.xs.doubleVal(bm25LengthWeight), getFragment());
}
@Override
public PlanSearchOptions withFragment(Fragment fragment) {
return new PlanSearchOptionsImpl(pb, getQualityWeight(), getScoreMethod(), getBm25LengthWeight(), fragment);
}
Map<String,Object> makeMap() {
if (qualityWeight == null && scoreMethod == null && bm25LengthWeight == null && fragment == null) return null;
Map<String, Object> map = new HashMap<>();
if (qualityWeight != null) {
map.put("qualityWeight", qualityWeight);
}
if (scoreMethod != null) {
map.put("scoreMethod", scoreMethod.name().toLowerCase());
}
if (bm25LengthWeight != null) {
map.put("bm25LengthWeight", bm25LengthWeight);
}
if (fragment != null) {
map.put("fragment", fragment.name().toLowerCase());
}
return map;
}
}
static class PlanParamBase extends BaseTypeImpl.BaseCallImpl<XsValueImpl.StringValImpl> implements PlanParamExpr {
String name = null;
PlanParamBase(String name) {
super("op", "param", new XsValueImpl.StringValImpl[]{new XsValueImpl.StringValImpl(name)});
if (name == null) {
throw new IllegalArgumentException("cannot define parameter with null name");
}
this.name = name;
}
public String getName() {
return name;
}
}
interface RequestPlan {
Map<PlanParamBase,BaseTypeImpl.ParamBinder> getParams();
AbstractWriteHandle getHandle();
List<ContentParam> getContentParams();
}
static abstract class PlanBaseImpl
extends BaseTypeImpl.BaseChainImpl<BaseTypeImpl.BaseArgImpl>
implements PlanBuilder.Plan, RequestPlan, BaseTypeImpl.BaseArgImpl {
final static CtsExprImpl cts = CtsExprImpl.cts;
final static FnExprImpl fn = FnExprImpl.fn;
final static JsonExprImpl json = JsonExprImpl.json;
final static MapExprImpl map = MapExprImpl.map;
final static MathExprImpl math = MathExprImpl.math;
final static RdfExprImpl rdf = RdfExprImpl.rdf;
final static SemExprImpl sem = SemExprImpl.sem;
final static SpellExprImpl spell = SpellExprImpl.spell;
final static SqlExprImpl sql = SqlExprImpl.sql;
final static XdmpExprImpl xdmp = XdmpExprImpl.xdmp;
final static XsExprImpl xs = XsExprImpl.xs;
final static PlanBuilderSubImpl pb = PlanBuilderBaseImpl.pb;
private HandleFactoryRegistry handleRegistry;
PlanBaseImpl(PlanBaseImpl prior, String fnPrefix, String fnName, Object[] fnArgs) {
super(prior, fnPrefix, fnName, BaseTypeImpl.convertList(fnArgs));
if (prior != null) {
setHandleRegistry(prior.getHandleRegistry());
}
}
HandleFactoryRegistry getHandleRegistry() {
return handleRegistry;
}
void setHandleRegistry(HandleFactoryRegistry handleRegistry) {
this.handleRegistry = handleRegistry;
}
@Override
public AbstractWriteHandle getHandle() {
// TODO: maybe serialize plan to JSON using JSON writer?
return new StringHandle(getAst()).withFormat(Format.JSON);
}
String getAst() {
StringBuilder strb = new StringBuilder();
strb.append("{\"$optic\":");
return exportAst(strb).append("}").toString();
}
public PlanColumn col(String column) {
return pb.col(column);
}
public PlanColumn exprCol(String column) {
return pb.exprCol(column);
}
}
static class PlanCallImpl extends BaseTypeImpl.ServerExpressionCallImpl {
PlanCallImpl(String fnPrefix, String fnName, Object[] fnArgs) {
super(fnPrefix, fnName, fnArgs);
}
}
static class PlanSeqListImpl extends BaseTypeImpl.ServerExpressionListImpl {
PlanSeqListImpl(Object[] items) {
super(items);
}
}
}