Skip to content

Commit d30a5f2

Browse files
Updated SDK page and removed code. Added GitHub link.
@dphansen
1 parent 4a78f1d commit d30a5f2

1 file changed

Lines changed: 3 additions & 336 deletions

File tree

‎docs/language-extensions/how-to/extensibility-sdk-java-sql-server.md‎

Lines changed: 3 additions & 336 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: How to implement a Java program for SQL Server using the Microsoft
44
ms.prod: sql
55
ms.technology: machine-learning
66

7-
ms.date: 05/22/2019
7+
ms.date: 05/23/2019
88
ms.topic: conceptual
99
author: nelgson
1010
ms.author: negust
@@ -39,7 +39,7 @@ The third class is a helper class, which contains an implementation of a data se
3939

4040
- **PrimitiveDataset**
4141

42-
Below you will find the details and source code for each class in the Java language extension for SQL Server.
42+
Below you will find descriptions of each class in the SDK. The source code of the SDK classes is available in the following [Open Sourced on GitHub repository](https://github.com/microsoft/sql-server-language-extensions/tree/master/language-extensions/java/sdk).
4343

4444
## Class: AbstractSqlServerExtensionExecutor
4545

@@ -73,352 +73,19 @@ The init method is executed after the constructor and before the execute method.
7373
public void init(String sessionId, int taskId, int numtask) {}
7474
```
7575

76-
### AbstractSqlServerExtensionExecutor source code
77-
78-
More details can be found below in the source code:
79-
80-
```java
81-
package com.microsoft.sqlserver.javalangextension;
82-
83-
import com.microsoft.sqlserver.javalangextension.AbstractSqlServerExtensionDataset;
84-
import java.lang.UnsupportedOperationException;
85-
import java.util.LinkedHashMap;
86-
87-
/**
88-
* Abstract class containing interface used by the Java extension
89-
*/
90-
public abstract class AbstractSqlServerExtensionExecutor {
91-
/* Supported versions of the Java extension */
92-
public final int SQLSERVER_JAVA_LANG_EXTENSION_V1 = 1;
93-
94-
/* Members used by the extension to determine application specifics */
95-
protected int executorExtensionVersion;
96-
protected String executorInputDatasetClassName;
97-
protected String executorOutputDatasetClassName;
98-
99-
public AbstractSqlServerExtensionExecutor() { }
100-
101-
public void init(String sessionId, int taskId, int numTasks) {
102-
/* Default implementation of init() is no-op */
103-
}
104-
105-
public AbstractSqlServerExtensionDataset execute(AbstractSqlServerExtensionDataset input, LinkedHashMap<String, Object> params) {
106-
throw new UnsupportedOperationException("AbstractSqlServerExtensionExecutor execute() is not implemented");
107-
}
108-
109-
public void cleanup() {
110-
/* Default implementation of cleanup() is no-op */
111-
}
112-
}
113-
```
114-
11576
## Class: AbstractSqlServerExtensionDataset
11677

11778
The abstract class **AbstractSqlServerExtensionDataset** contains the interface for handling input and output data used by the Java extension.
11879

119-
Below you can find the source code for **AbstractSqlServerExtensionDataset**.
120-
121-
```java
122-
package com.microsoft.sqlserver.javalangextension;
123-
124-
import java.lang.UnsupportedOperationException;
125-
126-
/**
127-
* Abstract class containing interface for handling input and output data used by the Java
128-
* extension.
129-
*/
130-
public class AbstractSqlServerExtensionDataset {
131-
/**
132-
* Column metadata interfaces
133-
*/
134-
public void addColumnMetadata(int columnId, String columnName, int columnType, int precision, int scale) {
135-
throw new UnsupportedOperationException("addColumnMetadata is not implemented");
136-
}
137-
138-
public int getColumnCount() {
139-
throw new UnsupportedOperationException("getColumnCount is not implemented");
140-
}
141-
142-
public String getColumnName(int columnId) {
143-
throw new UnsupportedOperationException("getColumnName is not implemented");
144-
}
145-
146-
public int getColumnPrecision(int columnId) {
147-
throw new UnsupportedOperationException("getColumnPrecision is not implemented");
148-
}
149-
150-
public int getColumnScale(int columnId) {
151-
throw new UnsupportedOperationException("getColumnScale is not implemented");
152-
}
153-
154-
public int getColumnType(int columnId) {
155-
throw new UnsupportedOperationException("getColumnNullMap is not implemented");
156-
}
157-
158-
public boolean[] getColumnNullMap(int columnId) {
159-
throw new UnsupportedOperationException("getColumnNullMap is not implemented");
160-
}
161-
162-
/**
163-
* Adding column interfaces
164-
*/
165-
public void addIntColumn(int columnId, int[] rows, boolean[] nullMap) {
166-
throw new UnsupportedOperationException("addIntColumn is not implemented");
167-
}
168-
169-
public void addBooleanColumn(int columnId, boolean[] rows, boolean[] nullMap) {
170-
throw new UnsupportedOperationException("addBooleanColumn is not implemented");
171-
}
172-
173-
public void addLongColumn(int columnId, long[] rows, boolean[] nullMap) {
174-
throw new UnsupportedOperationException("addLongColumn is not implemented");
175-
}
176-
177-
public void addFloatColumn(int columnId, float[] rows, boolean[] nullMap) {
178-
throw new UnsupportedOperationException("addFloatColumn is not implemented");
179-
}
180-
181-
public void addDoubleColumn(int columnId, double[] rows, boolean[] nullMap) {
182-
throw new UnsupportedOperationException("addDoubleColumn is not implemented");
183-
}
184-
185-
public void addShortColumn(int columnId, short[] rows, boolean[] nullMap) {
186-
throw new UnsupportedOperationException("addShortColumn is not implemented");
187-
}
188-
189-
public void addStringColumn(int columnId, String[] rows) {
190-
throw new UnsupportedOperationException("addStringColumn is not implemented");
191-
}
192-
193-
public void addBinaryColumn(int columnId, byte[][] rows) {
194-
throw new UnsupportedOperationException("addBinaryColumn is not implemented");
195-
}
196-
197-
/**
198-
* Retrieving column interfaces
199-
*/
200-
public int[] getIntColumn(int columnId) {
201-
throw new UnsupportedOperationException("getIntColumn is not implemented");
202-
}
203-
204-
public long[] getLongColumn(int columnId) {
205-
throw new UnsupportedOperationException("getLongColumn is not implemented");
206-
}
207-
208-
public float[] getFloatColumn(int columnId) {
209-
throw new UnsupportedOperationException("getFloatColumn is not implemented");
210-
}
211-
212-
public short[] getShortColumn(int columnId) {
213-
throw new UnsupportedOperationException("getShortColumn is not implemented");
214-
}
215-
216-
public boolean[] getBooleanColumn(int columnId) {
217-
throw new UnsupportedOperationException("getBooleanColumn is not implemented");
218-
}
219-
220-
public double[] getDoubleColumn(int columnId) {
221-
throw new UnsupportedOperationException("getDoubleColumn is not implemented");
222-
}
223-
224-
public String[] getStringColumn(int columnId) {
225-
throw new UnsupportedOperationException("getStringColumn is not implemented");
226-
}
227-
228-
public byte[][] getBinaryColumn(int columnId) {
229-
throw new UnsupportedOperationException("getBinaryColumn is not implemented");
230-
}
231-
}
232-
```
23380

23481
## Class: PrimitiveDataset
23582

23683
The class **PrimitiveDataset** is an implementation of **AbstractSqlServerExtensionDataset** that stores simple types as primitives arrays.
23784

23885
It is provided in the SDK simply as an optional helper class. If you don't use this class, you need to implement your own class that inherits from **AbstractSqlServerExtensionDataset**.
23986

240-
Below you can find the source code for **PrimitiveDataset**.
241-
242-
```java
243-
package com.microsoft.sqlserver.javalangextension;
244-
245-
import com.microsoft.sqlserver.javalangextension.AbstractSqlServerExtensionDataset;
246-
import java.lang.IllegalArgumentException;
247-
import java.util.HashMap;
248-
import java.util.Map;
249-
import java.util.Map.Entry;
250-
251-
/**
252-
* Implementation of AbstractSqlServerExtensionDataset that stores
253-
* simple types as primitives arrays
254-
*/
255-
public class PrimitiveDataset extends AbstractSqlServerExtensionDataset {
256-
Map<Integer, String> columnNames;
257-
Map<Integer, Integer> columnTypes;
258-
Map<Integer, Integer> columnPrecisions;
259-
Map<Integer, Integer> columnScales;
260-
Map<Integer, Object> columns;
261-
Map<Integer, boolean[]> columnNullMaps;
262-
263-
public PrimitiveDataset() {
264-
columnTypes = new HashMap<>();
265-
columnNames = new HashMap<>();
266-
columnPrecisions = new HashMap<>();
267-
columnScales = new HashMap<>();
268-
columns = new HashMap<>();
269-
columnNullMaps = new HashMap<>();
270-
}
271-
272-
/**
273-
* Column metadata interfaces. Metadata is stored in a hash map, using the column ID as the key
274-
*/
275-
public void addColumnMetadata(int columnId, String columnName, int sqlType, int precision, int scale) {
276-
if (columnTypes.containsKey(columnId))
277-
{
278-
throw new IllegalArgumentException("Metadata for column ID #: " + columnId + " already exists");
279-
}
280-
281-
columnTypes.put(columnId, sqlType);
282-
columnNames.put(columnId, columnName);
283-
columnPrecisions.put(columnId, precision);
284-
columnScales.put(columnId, scale);
285-
}
286-
287-
public int getColumnCount() {
288-
return columnTypes.size();
289-
}
290-
291-
public String getColumnName(int columnId) {
292-
checkColumnMetadata(columnId);
293-
return columnNames.get(columnId);
294-
}
295-
296-
public int getColumnPrecision(int columnId) {
297-
checkColumnMetadata(columnId);
298-
return columnPrecisions.get(columnId).intValue();
299-
}
300-
301-
public int getColumnScale(int columnId) {
302-
checkColumnMetadata(columnId);
303-
return columnScales.get(columnId).intValue();
304-
}
305-
306-
public int getColumnType(int columnId) {
307-
checkColumnMetadata(columnId);
308-
return columnTypes.get(columnId).intValue();
309-
}
310-
311-
public boolean[] getColumnNullMap(int columnId) {
312-
checkColumnMetadata(columnId);
313-
return columnNullMaps.get(columnId);
314-
}
315-
316-
/**
317-
* Adding column data interfaces. Column data is stored in a hash map, using the column ID as the key and
318-
* an array of the corresponding type representing each row. Primitives cannot be null, thus null values
319-
* are represented by an additional boolean array containing a flag to indicate if that value is null.
320-
* A null indicator array indicates that there are no null values in that column.
321-
*/
322-
public void addIntColumn(int columnId, int[] rows, boolean[] nullMap) {
323-
checkColumnMetadata(columnId);
324-
columns.put(columnId, rows);
325-
columnNullMaps.put(columnId, nullMap);
326-
}
327-
328-
public void addBooleanColumn(int columnId, boolean[] rows, boolean[] nullMap) {
329-
checkColumnMetadata(columnId);
330-
columns.put(columnId, rows);
331-
columnNullMaps.put(columnId, nullMap);
332-
};
333-
334-
public void addLongColumn(int columnId, long[] rows, boolean[] nullMap) {
335-
checkColumnMetadata(columnId);
336-
columns.put(columnId, rows);
337-
columnNullMaps.put(columnId, nullMap);
338-
}
339-
340-
public void addFloatColumn(int columnId, float[] rows, boolean[] nullMap) {
341-
checkColumnMetadata(columnId);
342-
columns.put(columnId, rows);
343-
columnNullMaps.put(columnId, nullMap);
344-
}
345-
346-
public void addDoubleColumn(int columnId, double[] rows, boolean[] nullMap) {
347-
checkColumnMetadata(columnId);
348-
columns.put(columnId, rows);
349-
columnNullMaps.put(columnId, nullMap);
350-
}
351-
352-
public void addShortColumn(int columnId, short[] rows, boolean[] nullMap) {
353-
checkColumnMetadata(columnId);
354-
columns.put(columnId, rows);
355-
columnNullMaps.put(columnId, nullMap);
356-
}
357-
358-
public void addStringColumn(int columnId, String[] rows) {
359-
checkColumnMetadata(columnId);
360-
columns.put(columnId, rows);
361-
}
362-
363-
public void addBinaryColumn(int columnId, byte[][] rows) {
364-
checkColumnMetadata(columnId);
365-
columns.put(columnId, rows);
366-
}
367-
368-
/**
369-
* Retreiving column data interfaces. For primitive types, calling getColumnNullMap() for the column ID
370-
* will return the boolean array indicating null values.
371-
*/
372-
public int[] getIntColumn(int columnId) {
373-
checkColumnMetadata(columnId);
374-
return (int[])columns.get(columnId);
375-
}
376-
377-
public long[] getLongColumn(int columnId) {
378-
checkColumnMetadata(columnId);
379-
return (long[])columns.get(columnId);
380-
}
381-
382-
public float[] getFloatColumn(int columnId) {
383-
checkColumnMetadata(columnId);
384-
return (float[])columns.get(columnId);
385-
}
386-
387-
public short[] getShortColumn(int columnId) {
388-
checkColumnMetadata(columnId);
389-
return (short[])columns.get(columnId);
390-
}
391-
392-
public boolean[] getBooleanColumn(int columnId) {
393-
checkColumnMetadata(columnId);
394-
return (boolean[])columns.get(columnId);
395-
}
396-
397-
public double[] getDoubleColumn(int columnId) {
398-
checkColumnMetadata(columnId);
399-
return (double[])columns.get(columnId);
400-
}
401-
402-
public String[] getStringColumn(int columnId) {
403-
checkColumnMetadata(columnId);
404-
return (String[])columns.get(columnId);
405-
}
406-
407-
public byte[][] getBinaryColumn(int columnId) {
408-
checkColumnMetadata(columnId);
409-
return (byte[][])columns.get(columnId);
410-
}
411-
412-
private void checkColumnMetadata(int columnId)
413-
{
414-
if (!columnTypes.containsKey(columnId)) {
415-
throw new IllegalArgumentException("Metadata for column ID #: " + columnId + " does not exist");
416-
}
417-
}
418-
}
419-
```
42087

42188
## Next steps
42289

42390
+ [Tutorial: Search for a string using regular expressions (regex) in Java](../tutorials/search-for-string-using-regular-expressions-in-java.md)
424-
+ [How to call Java in SQL Server](call-java-from-sql.md)
91+
+ [How to call Java in SQL Server](call-java-from-sql.md)

0 commit comments

Comments
 (0)